id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
18,000
|
akretion/ooor
|
lib/ooor/type_casting.rb
|
Ooor.TypeCasting.cast_association
|
def cast_association(k)
if self.class.one2many_associations[k]
if @loaded_associations[k]
v = @loaded_associations[k].select {|i| i.changed?}
v = @associations[k] if v.empty?
else
v = @associations[k]
end
cast_o2m_association(v)
elsif self.class.many2many_associations[k]
v = @associations[k]
[[6, false, (v || []).map {|i| i.is_a?(Base) ? i.id : i}]]
elsif self.class.many2one_associations[k]
v = @associations[k] # TODO support for nested
cast_m2o_association(v)
end
end
|
ruby
|
def cast_association(k)
if self.class.one2many_associations[k]
if @loaded_associations[k]
v = @loaded_associations[k].select {|i| i.changed?}
v = @associations[k] if v.empty?
else
v = @associations[k]
end
cast_o2m_association(v)
elsif self.class.many2many_associations[k]
v = @associations[k]
[[6, false, (v || []).map {|i| i.is_a?(Base) ? i.id : i}]]
elsif self.class.many2one_associations[k]
v = @associations[k] # TODO support for nested
cast_m2o_association(v)
end
end
|
[
"def",
"cast_association",
"(",
"k",
")",
"if",
"self",
".",
"class",
".",
"one2many_associations",
"[",
"k",
"]",
"if",
"@loaded_associations",
"[",
"k",
"]",
"v",
"=",
"@loaded_associations",
"[",
"k",
"]",
".",
"select",
"{",
"|",
"i",
"|",
"i",
".",
"changed?",
"}",
"v",
"=",
"@associations",
"[",
"k",
"]",
"if",
"v",
".",
"empty?",
"else",
"v",
"=",
"@associations",
"[",
"k",
"]",
"end",
"cast_o2m_association",
"(",
"v",
")",
"elsif",
"self",
".",
"class",
".",
"many2many_associations",
"[",
"k",
"]",
"v",
"=",
"@associations",
"[",
"k",
"]",
"[",
"[",
"6",
",",
"false",
",",
"(",
"v",
"||",
"[",
"]",
")",
".",
"map",
"{",
"|",
"i",
"|",
"i",
".",
"is_a?",
"(",
"Base",
")",
"?",
"i",
".",
"id",
":",
"i",
"}",
"]",
"]",
"elsif",
"self",
".",
"class",
".",
"many2one_associations",
"[",
"k",
"]",
"v",
"=",
"@associations",
"[",
"k",
"]",
"# TODO support for nested",
"cast_m2o_association",
"(",
"v",
")",
"end",
"end"
] |
talk OpenERP cryptic associations API
|
[
"talk",
"OpenERP",
"cryptic",
"associations",
"API"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/type_casting.rb#L163-L179
|
18,001
|
akretion/ooor
|
lib/ooor/base.rb
|
Ooor.Base.on_change
|
def on_change(on_change_method, field_name, field_value, *args)
# NOTE: OpenERP doesn't accept context systematically in on_change events unfortunately
ids = self.id ? [id] : []
result = self.class.object_service(:execute, self.class.openerp_model, on_change_method, ids, *args)
load_on_change_result(result, field_name, field_value)
end
|
ruby
|
def on_change(on_change_method, field_name, field_value, *args)
# NOTE: OpenERP doesn't accept context systematically in on_change events unfortunately
ids = self.id ? [id] : []
result = self.class.object_service(:execute, self.class.openerp_model, on_change_method, ids, *args)
load_on_change_result(result, field_name, field_value)
end
|
[
"def",
"on_change",
"(",
"on_change_method",
",",
"field_name",
",",
"field_value",
",",
"*",
"args",
")",
"# NOTE: OpenERP doesn't accept context systematically in on_change events unfortunately",
"ids",
"=",
"self",
".",
"id",
"?",
"[",
"id",
"]",
":",
"[",
"]",
"result",
"=",
"self",
".",
"class",
".",
"object_service",
"(",
":execute",
",",
"self",
".",
"class",
".",
"openerp_model",
",",
"on_change_method",
",",
"ids",
",",
"args",
")",
"load_on_change_result",
"(",
"result",
",",
"field_name",
",",
"field_value",
")",
"end"
] |
Generic OpenERP on_change method
|
[
"Generic",
"OpenERP",
"on_change",
"method"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/base.rb#L100-L105
|
18,002
|
akretion/ooor
|
lib/ooor/base.rb
|
Ooor.Base.wkf_action
|
def wkf_action(action, context={}, reload=true)
self.class.object_service(:exec_workflow, self.class.openerp_model, action, self.id, context)
reload_fields if reload
end
|
ruby
|
def wkf_action(action, context={}, reload=true)
self.class.object_service(:exec_workflow, self.class.openerp_model, action, self.id, context)
reload_fields if reload
end
|
[
"def",
"wkf_action",
"(",
"action",
",",
"context",
"=",
"{",
"}",
",",
"reload",
"=",
"true",
")",
"self",
".",
"class",
".",
"object_service",
"(",
":exec_workflow",
",",
"self",
".",
"class",
".",
"openerp_model",
",",
"action",
",",
"self",
".",
"id",
",",
"context",
")",
"reload_fields",
"if",
"reload",
"end"
] |
wrapper for OpenERP exec_workflow Business Process Management engine
|
[
"wrapper",
"for",
"OpenERP",
"exec_workflow",
"Business",
"Process",
"Management",
"engine"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/base.rb#L108-L111
|
18,003
|
akretion/ooor
|
lib/ooor/persistence.rb
|
Ooor.Persistence.load
|
def load(attributes)
self.class.reload_fields_definition(false)
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
@associations ||= {}
@attributes ||= {}
@loaded_associations = {}
attributes.each do |key, value|
self.send "#{key}=", value if self.respond_to?("#{key}=")
end
self
end
|
ruby
|
def load(attributes)
self.class.reload_fields_definition(false)
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
@associations ||= {}
@attributes ||= {}
@loaded_associations = {}
attributes.each do |key, value|
self.send "#{key}=", value if self.respond_to?("#{key}=")
end
self
end
|
[
"def",
"load",
"(",
"attributes",
")",
"self",
".",
"class",
".",
"reload_fields_definition",
"(",
"false",
")",
"raise",
"ArgumentError",
",",
"\"expected an attributes Hash, got #{attributes.inspect}\"",
"unless",
"attributes",
".",
"is_a?",
"(",
"Hash",
")",
"@associations",
"||=",
"{",
"}",
"@attributes",
"||=",
"{",
"}",
"@loaded_associations",
"=",
"{",
"}",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"self",
".",
"send",
"\"#{key}=\"",
",",
"value",
"if",
"self",
".",
"respond_to?",
"(",
"\"#{key}=\"",
")",
"end",
"self",
"end"
] |
Flushes the current object and loads the +attributes+ Hash
containing the attributes and the associations into the current object
|
[
"Flushes",
"the",
"current",
"object",
"and",
"loads",
"the",
"+",
"attributes",
"+",
"Hash",
"containing",
"the",
"attributes",
"and",
"the",
"associations",
"into",
"the",
"current",
"object"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/persistence.rb#L86-L96
|
18,004
|
akretion/ooor
|
lib/ooor/persistence.rb
|
Ooor.Persistence.copy
|
def copy(defaults={}, context={})
self.class.find(rpc_execute('copy', id, defaults, context), context: context)
end
|
ruby
|
def copy(defaults={}, context={})
self.class.find(rpc_execute('copy', id, defaults, context), context: context)
end
|
[
"def",
"copy",
"(",
"defaults",
"=",
"{",
"}",
",",
"context",
"=",
"{",
"}",
")",
"self",
".",
"class",
".",
"find",
"(",
"rpc_execute",
"(",
"'copy'",
",",
"id",
",",
"defaults",
",",
"context",
")",
",",
"context",
":",
"context",
")",
"end"
] |
OpenERP copy method, load persisted copied Object
|
[
"OpenERP",
"copy",
"method",
"load",
"persisted",
"copied",
"Object"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/persistence.rb#L225-L227
|
18,005
|
akretion/ooor
|
lib/ooor/persistence.rb
|
Ooor.Persistence.perform_validations
|
def perform_validations(options={}) # :nodoc:
if options.is_a?(Hash)
options[:validate] == false || valid?(options[:context])
else
valid?
end
end
|
ruby
|
def perform_validations(options={}) # :nodoc:
if options.is_a?(Hash)
options[:validate] == false || valid?(options[:context])
else
valid?
end
end
|
[
"def",
"perform_validations",
"(",
"options",
"=",
"{",
"}",
")",
"# :nodoc:",
"if",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"[",
":validate",
"]",
"==",
"false",
"||",
"valid?",
"(",
"options",
"[",
":context",
"]",
")",
"else",
"valid?",
"end",
"end"
] |
Real validations happens on OpenERP side, only pre-validations can happen here eventually
|
[
"Real",
"validations",
"happens",
"on",
"OpenERP",
"side",
"only",
"pre",
"-",
"validations",
"can",
"happen",
"here",
"eventually"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/persistence.rb#L250-L256
|
18,006
|
rspec/rspec-activemodel-mocks
|
lib/rspec/active_model/mocks/mocks.rb
|
RSpec::ActiveModel::Mocks.Mocks.stub_model
|
def stub_model(model_class, stubs={})
model_class.new.tap do |m|
m.extend ActiveModelStubExtensions
if defined?(ActiveRecord) && model_class < ActiveRecord::Base && model_class.primary_key
m.extend ActiveRecordStubExtensions
primary_key = model_class.primary_key.to_sym
stubs = {primary_key => next_id}.merge(stubs)
stubs = {:persisted? => !!stubs[primary_key]}.merge(stubs)
else
stubs = {:id => next_id}.merge(stubs)
stubs = {:persisted? => !!stubs[:id]}.merge(stubs)
end
stubs = {:blank? => false}.merge(stubs)
stubs.each do |message, return_value|
if m.respond_to?("#{message}=")
m.__send__("#{message}=", return_value)
else
RSpec::Mocks.allow_message(m, message).and_return(return_value)
end
end
yield m if block_given?
end
end
|
ruby
|
def stub_model(model_class, stubs={})
model_class.new.tap do |m|
m.extend ActiveModelStubExtensions
if defined?(ActiveRecord) && model_class < ActiveRecord::Base && model_class.primary_key
m.extend ActiveRecordStubExtensions
primary_key = model_class.primary_key.to_sym
stubs = {primary_key => next_id}.merge(stubs)
stubs = {:persisted? => !!stubs[primary_key]}.merge(stubs)
else
stubs = {:id => next_id}.merge(stubs)
stubs = {:persisted? => !!stubs[:id]}.merge(stubs)
end
stubs = {:blank? => false}.merge(stubs)
stubs.each do |message, return_value|
if m.respond_to?("#{message}=")
m.__send__("#{message}=", return_value)
else
RSpec::Mocks.allow_message(m, message).and_return(return_value)
end
end
yield m if block_given?
end
end
|
[
"def",
"stub_model",
"(",
"model_class",
",",
"stubs",
"=",
"{",
"}",
")",
"model_class",
".",
"new",
".",
"tap",
"do",
"|",
"m",
"|",
"m",
".",
"extend",
"ActiveModelStubExtensions",
"if",
"defined?",
"(",
"ActiveRecord",
")",
"&&",
"model_class",
"<",
"ActiveRecord",
"::",
"Base",
"&&",
"model_class",
".",
"primary_key",
"m",
".",
"extend",
"ActiveRecordStubExtensions",
"primary_key",
"=",
"model_class",
".",
"primary_key",
".",
"to_sym",
"stubs",
"=",
"{",
"primary_key",
"=>",
"next_id",
"}",
".",
"merge",
"(",
"stubs",
")",
"stubs",
"=",
"{",
":persisted?",
"=>",
"!",
"!",
"stubs",
"[",
"primary_key",
"]",
"}",
".",
"merge",
"(",
"stubs",
")",
"else",
"stubs",
"=",
"{",
":id",
"=>",
"next_id",
"}",
".",
"merge",
"(",
"stubs",
")",
"stubs",
"=",
"{",
":persisted?",
"=>",
"!",
"!",
"stubs",
"[",
":id",
"]",
"}",
".",
"merge",
"(",
"stubs",
")",
"end",
"stubs",
"=",
"{",
":blank?",
"=>",
"false",
"}",
".",
"merge",
"(",
"stubs",
")",
"stubs",
".",
"each",
"do",
"|",
"message",
",",
"return_value",
"|",
"if",
"m",
".",
"respond_to?",
"(",
"\"#{message}=\"",
")",
"m",
".",
"__send__",
"(",
"\"#{message}=\"",
",",
"return_value",
")",
"else",
"RSpec",
"::",
"Mocks",
".",
"allow_message",
"(",
"m",
",",
"message",
")",
".",
"and_return",
"(",
"return_value",
")",
"end",
"end",
"yield",
"m",
"if",
"block_given?",
"end",
"end"
] |
Creates an instance of `Model` with `to_param` stubbed using a
generated value that is unique to each object. If `Model` is an
`ActiveRecord` model, it is prohibited from accessing the database.
For each key in `stubs`, if the model has a matching attribute
(determined by `respond_to?`) it is simply assigned the submitted values.
If the model does not have a matching attribute, the key/value pair is
assigned as a stub return value using RSpec's mocking/stubbing
framework.
<tt>persisted?</tt> is overridden to return the result of !id.nil?
This means that by default persisted? will return true. If you want
the object to behave as a new record, sending it `as_new_record` will
set the id to nil. You can also explicitly set :id => nil, in which
case persisted? will return false, but using `as_new_record` makes the
example a bit more descriptive.
While you can use stub_model in any example (model, view, controller,
helper), it is especially useful in view examples, which are
inherently more state-based than interaction-based.
@example
stub_model(Person)
stub_model(Person).as_new_record
stub_model(Person, :to_param => 37)
stub_model(Person) {|person| person.first_name = "David"}
|
[
"Creates",
"an",
"instance",
"of",
"Model",
"with",
"to_param",
"stubbed",
"using",
"a",
"generated",
"value",
"that",
"is",
"unique",
"to",
"each",
"object",
".",
"If",
"Model",
"is",
"an",
"ActiveRecord",
"model",
"it",
"is",
"prohibited",
"from",
"accessing",
"the",
"database",
"."
] |
0338d50039cad672bbe695fff5591da1ba849308
|
https://github.com/rspec/rspec-activemodel-mocks/blob/0338d50039cad672bbe695fff5591da1ba849308/lib/rspec/active_model/mocks/mocks.rb#L243-L267
|
18,007
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.stop
|
def stop(reason)
if @pid
begin
Process.kill('KILL', @pid)
Process.waitpid(@pid)
rescue Errno::ESRCH, Errno::ECHILD
end
end
@log.info "Killing pid: #{@pid.to_s}. Reason: #{reason}"
@pid = nil
end
|
ruby
|
def stop(reason)
if @pid
begin
Process.kill('KILL', @pid)
Process.waitpid(@pid)
rescue Errno::ESRCH, Errno::ECHILD
end
end
@log.info "Killing pid: #{@pid.to_s}. Reason: #{reason}"
@pid = nil
end
|
[
"def",
"stop",
"(",
"reason",
")",
"if",
"@pid",
"begin",
"Process",
".",
"kill",
"(",
"'KILL'",
",",
"@pid",
")",
"Process",
".",
"waitpid",
"(",
"@pid",
")",
"rescue",
"Errno",
"::",
"ESRCH",
",",
"Errno",
"::",
"ECHILD",
"end",
"end",
"@log",
".",
"info",
"\"Killing pid: #{@pid.to_s}. Reason: #{reason}\"",
"@pid",
"=",
"nil",
"end"
] |
Stop the child process by issuing a kill -9.
We then call waitpid() with the pid, which waits for that particular
child and reaps it.
kill() can set errno to ESRCH if, for some reason, the file
is gone; regardless the final outcome of this method
will be to set our @pid variable to nil.
Technically, kill() can also fail with EPERM or EINVAL (wherein
the signal isn't sent); but we have permissions, and
we're not doing anything invalid here.
|
[
"Stop",
"the",
"child",
"process",
"by",
"issuing",
"a",
"kill",
"-",
"9",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L96-L106
|
18,008
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.mentos
|
def mentos(method, args=[], kwargs={}, original_code=nil)
# Open the pipe if necessary
start unless alive?
begin
# Timeout requests that take too long.
# Invalid MENTOS_TIMEOUT results in just using default.
timeout_time = Integer(ENV["MENTOS_TIMEOUT"]) rescue 8
Timeout::timeout(timeout_time) do
# For sanity checking on both sides of the pipe when highlighting, we prepend and
# append an id. mentos checks that these are 8 character ids and that they match.
# It then returns the id's back to Rubyland.
id = (0...8).map{65.+(rand(25)).chr}.join
code = add_ids(original_code, id) if original_code
# Add metadata to the header and generate it.
if code
bytesize = code.bytesize
else
bytesize = 0
end
kwargs.freeze
kwargs = kwargs.merge("fd" => @out.to_i, "id" => id, "bytes" => bytesize)
out_header = MultiJson.dump(:method => method, :args => args, :kwargs => kwargs)
# Get the size of the header itself and write that.
bits = get_fixed_bits_from_header(out_header)
@in.write(bits)
# mentos is now waiting for the header, and, potentially, code.
write_data(out_header, code)
check_for_error
# mentos will now return data to us. First it sends the header.
header = get_header
# Now handle the header, any read any more data required.
res = handle_header_and_return(header, id)
# Finally, return what we got.
return_result(res, method)
end
rescue Timeout::Error
# If we timeout, we need to clear out the pipe and start over.
@log.error "Timeout on a mentos #{method} call"
stop "Timeout on mentos #{method} call."
end
rescue Errno::EPIPE, EOFError
stop "EPIPE"
raise MentosError, "EPIPE"
end
|
ruby
|
def mentos(method, args=[], kwargs={}, original_code=nil)
# Open the pipe if necessary
start unless alive?
begin
# Timeout requests that take too long.
# Invalid MENTOS_TIMEOUT results in just using default.
timeout_time = Integer(ENV["MENTOS_TIMEOUT"]) rescue 8
Timeout::timeout(timeout_time) do
# For sanity checking on both sides of the pipe when highlighting, we prepend and
# append an id. mentos checks that these are 8 character ids and that they match.
# It then returns the id's back to Rubyland.
id = (0...8).map{65.+(rand(25)).chr}.join
code = add_ids(original_code, id) if original_code
# Add metadata to the header and generate it.
if code
bytesize = code.bytesize
else
bytesize = 0
end
kwargs.freeze
kwargs = kwargs.merge("fd" => @out.to_i, "id" => id, "bytes" => bytesize)
out_header = MultiJson.dump(:method => method, :args => args, :kwargs => kwargs)
# Get the size of the header itself and write that.
bits = get_fixed_bits_from_header(out_header)
@in.write(bits)
# mentos is now waiting for the header, and, potentially, code.
write_data(out_header, code)
check_for_error
# mentos will now return data to us. First it sends the header.
header = get_header
# Now handle the header, any read any more data required.
res = handle_header_and_return(header, id)
# Finally, return what we got.
return_result(res, method)
end
rescue Timeout::Error
# If we timeout, we need to clear out the pipe and start over.
@log.error "Timeout on a mentos #{method} call"
stop "Timeout on mentos #{method} call."
end
rescue Errno::EPIPE, EOFError
stop "EPIPE"
raise MentosError, "EPIPE"
end
|
[
"def",
"mentos",
"(",
"method",
",",
"args",
"=",
"[",
"]",
",",
"kwargs",
"=",
"{",
"}",
",",
"original_code",
"=",
"nil",
")",
"# Open the pipe if necessary",
"start",
"unless",
"alive?",
"begin",
"# Timeout requests that take too long.",
"# Invalid MENTOS_TIMEOUT results in just using default.",
"timeout_time",
"=",
"Integer",
"(",
"ENV",
"[",
"\"MENTOS_TIMEOUT\"",
"]",
")",
"rescue",
"8",
"Timeout",
"::",
"timeout",
"(",
"timeout_time",
")",
"do",
"# For sanity checking on both sides of the pipe when highlighting, we prepend and",
"# append an id. mentos checks that these are 8 character ids and that they match.",
"# It then returns the id's back to Rubyland.",
"id",
"=",
"(",
"0",
"...",
"8",
")",
".",
"map",
"{",
"65",
".",
"+",
"(",
"rand",
"(",
"25",
")",
")",
".",
"chr",
"}",
".",
"join",
"code",
"=",
"add_ids",
"(",
"original_code",
",",
"id",
")",
"if",
"original_code",
"# Add metadata to the header and generate it.",
"if",
"code",
"bytesize",
"=",
"code",
".",
"bytesize",
"else",
"bytesize",
"=",
"0",
"end",
"kwargs",
".",
"freeze",
"kwargs",
"=",
"kwargs",
".",
"merge",
"(",
"\"fd\"",
"=>",
"@out",
".",
"to_i",
",",
"\"id\"",
"=>",
"id",
",",
"\"bytes\"",
"=>",
"bytesize",
")",
"out_header",
"=",
"MultiJson",
".",
"dump",
"(",
":method",
"=>",
"method",
",",
":args",
"=>",
"args",
",",
":kwargs",
"=>",
"kwargs",
")",
"# Get the size of the header itself and write that.",
"bits",
"=",
"get_fixed_bits_from_header",
"(",
"out_header",
")",
"@in",
".",
"write",
"(",
"bits",
")",
"# mentos is now waiting for the header, and, potentially, code.",
"write_data",
"(",
"out_header",
",",
"code",
")",
"check_for_error",
"# mentos will now return data to us. First it sends the header.",
"header",
"=",
"get_header",
"# Now handle the header, any read any more data required.",
"res",
"=",
"handle_header_and_return",
"(",
"header",
",",
"id",
")",
"# Finally, return what we got.",
"return_result",
"(",
"res",
",",
"method",
")",
"end",
"rescue",
"Timeout",
"::",
"Error",
"# If we timeout, we need to clear out the pipe and start over.",
"@log",
".",
"error",
"\"Timeout on a mentos #{method} call\"",
"stop",
"\"Timeout on mentos #{method} call.\"",
"end",
"rescue",
"Errno",
"::",
"EPIPE",
",",
"EOFError",
"stop",
"\"EPIPE\"",
"raise",
"MentosError",
",",
"\"EPIPE\"",
"end"
] |
Our 'rpc'-ish request to mentos. Requires a method name, and then optional
args, kwargs, code.
|
[
"Our",
"rpc",
"-",
"ish",
"request",
"to",
"mentos",
".",
"Requires",
"a",
"method",
"name",
"and",
"then",
"optional",
"args",
"kwargs",
"code",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L245-L299
|
18,009
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.handle_header_and_return
|
def handle_header_and_return(header, id)
if header
header = header_to_json(header)
bytes = header[:bytes]
# Read more bytes (the actual response body)
res = @out.read(bytes.to_i)
if header[:method] == "highlight"
# Make sure we have a result back; else consider this an error.
if res.nil?
@log.warn "No highlight result back from mentos."
stop "No highlight result back from mentos."
raise MentosError, "No highlight result back from mentos."
end
# Remove the newline from Python
res = res[0..-2]
@log.info "Highlight in process."
# Get the id's
start_id = res[0..7]
end_id = res[-8..-1]
# Sanity check.
if not (start_id == id and end_id == id)
@log.error "ID's did not match. Aborting."
stop "ID's did not match. Aborting."
raise MentosError, "ID's did not match. Aborting."
else
# We're good. Remove the padding
res = res[10..-11]
@log.info "Highlighting complete."
res
end
end
res
else
@log.error "No header data back."
stop "No header data back."
raise MentosError, "No header received back."
end
end
|
ruby
|
def handle_header_and_return(header, id)
if header
header = header_to_json(header)
bytes = header[:bytes]
# Read more bytes (the actual response body)
res = @out.read(bytes.to_i)
if header[:method] == "highlight"
# Make sure we have a result back; else consider this an error.
if res.nil?
@log.warn "No highlight result back from mentos."
stop "No highlight result back from mentos."
raise MentosError, "No highlight result back from mentos."
end
# Remove the newline from Python
res = res[0..-2]
@log.info "Highlight in process."
# Get the id's
start_id = res[0..7]
end_id = res[-8..-1]
# Sanity check.
if not (start_id == id and end_id == id)
@log.error "ID's did not match. Aborting."
stop "ID's did not match. Aborting."
raise MentosError, "ID's did not match. Aborting."
else
# We're good. Remove the padding
res = res[10..-11]
@log.info "Highlighting complete."
res
end
end
res
else
@log.error "No header data back."
stop "No header data back."
raise MentosError, "No header received back."
end
end
|
[
"def",
"handle_header_and_return",
"(",
"header",
",",
"id",
")",
"if",
"header",
"header",
"=",
"header_to_json",
"(",
"header",
")",
"bytes",
"=",
"header",
"[",
":bytes",
"]",
"# Read more bytes (the actual response body)",
"res",
"=",
"@out",
".",
"read",
"(",
"bytes",
".",
"to_i",
")",
"if",
"header",
"[",
":method",
"]",
"==",
"\"highlight\"",
"# Make sure we have a result back; else consider this an error.",
"if",
"res",
".",
"nil?",
"@log",
".",
"warn",
"\"No highlight result back from mentos.\"",
"stop",
"\"No highlight result back from mentos.\"",
"raise",
"MentosError",
",",
"\"No highlight result back from mentos.\"",
"end",
"# Remove the newline from Python",
"res",
"=",
"res",
"[",
"0",
"..",
"-",
"2",
"]",
"@log",
".",
"info",
"\"Highlight in process.\"",
"# Get the id's",
"start_id",
"=",
"res",
"[",
"0",
"..",
"7",
"]",
"end_id",
"=",
"res",
"[",
"-",
"8",
"..",
"-",
"1",
"]",
"# Sanity check.",
"if",
"not",
"(",
"start_id",
"==",
"id",
"and",
"end_id",
"==",
"id",
")",
"@log",
".",
"error",
"\"ID's did not match. Aborting.\"",
"stop",
"\"ID's did not match. Aborting.\"",
"raise",
"MentosError",
",",
"\"ID's did not match. Aborting.\"",
"else",
"# We're good. Remove the padding",
"res",
"=",
"res",
"[",
"10",
"..",
"-",
"11",
"]",
"@log",
".",
"info",
"\"Highlighting complete.\"",
"res",
"end",
"end",
"res",
"else",
"@log",
".",
"error",
"\"No header data back.\"",
"stop",
"\"No header data back.\"",
"raise",
"MentosError",
",",
"\"No header received back.\"",
"end",
"end"
] |
Based on the header we receive, determine if we need
to read more bytes, and read those bytes if necessary.
Then, do a sanity check with the ids.
Returns a result — either highlighted text or metadata.
|
[
"Based",
"on",
"the",
"header",
"we",
"receive",
"determine",
"if",
"we",
"need",
"to",
"read",
"more",
"bytes",
"and",
"read",
"those",
"bytes",
"if",
"necessary",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L327-L369
|
18,010
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.get_header
|
def get_header
begin
size = @out.read(33)
size = size[0..-2]
# Sanity check the size
if not size_check(size)
@log.error "Size returned from mentos.py invalid."
stop "Size returned from mentos.py invalid."
raise MentosError, "Size returned from mentos.py invalid."
end
# Read the amount of bytes we should be expecting. We first
# convert the string of bits into an integer.
header_bytes = size.to_s.to_i(2) + 1
@log.info "Size in: #{size.to_s} (#{header_bytes.to_s})"
@out.read(header_bytes)
rescue
@log.error "Failed to get header."
stop "Failed to get header."
raise MentosError, "Failed to get header."
end
end
|
ruby
|
def get_header
begin
size = @out.read(33)
size = size[0..-2]
# Sanity check the size
if not size_check(size)
@log.error "Size returned from mentos.py invalid."
stop "Size returned from mentos.py invalid."
raise MentosError, "Size returned from mentos.py invalid."
end
# Read the amount of bytes we should be expecting. We first
# convert the string of bits into an integer.
header_bytes = size.to_s.to_i(2) + 1
@log.info "Size in: #{size.to_s} (#{header_bytes.to_s})"
@out.read(header_bytes)
rescue
@log.error "Failed to get header."
stop "Failed to get header."
raise MentosError, "Failed to get header."
end
end
|
[
"def",
"get_header",
"begin",
"size",
"=",
"@out",
".",
"read",
"(",
"33",
")",
"size",
"=",
"size",
"[",
"0",
"..",
"-",
"2",
"]",
"# Sanity check the size",
"if",
"not",
"size_check",
"(",
"size",
")",
"@log",
".",
"error",
"\"Size returned from mentos.py invalid.\"",
"stop",
"\"Size returned from mentos.py invalid.\"",
"raise",
"MentosError",
",",
"\"Size returned from mentos.py invalid.\"",
"end",
"# Read the amount of bytes we should be expecting. We first",
"# convert the string of bits into an integer.",
"header_bytes",
"=",
"size",
".",
"to_s",
".",
"to_i",
"(",
"2",
")",
"+",
"1",
"@log",
".",
"info",
"\"Size in: #{size.to_s} (#{header_bytes.to_s})\"",
"@out",
".",
"read",
"(",
"header_bytes",
")",
"rescue",
"@log",
".",
"error",
"\"Failed to get header.\"",
"stop",
"\"Failed to get header.\"",
"raise",
"MentosError",
",",
"\"Failed to get header.\"",
"end",
"end"
] |
Read the header via the pipe.
Returns a header.
|
[
"Read",
"the",
"header",
"via",
"the",
"pipe",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L401-L423
|
18,011
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.return_result
|
def return_result(res, method)
unless method == :lexer_name_for || method == :highlight || method == :css
res = MultiJson.load(res, :symbolize_keys => true)
end
res = res.rstrip if res.class == String
res
end
|
ruby
|
def return_result(res, method)
unless method == :lexer_name_for || method == :highlight || method == :css
res = MultiJson.load(res, :symbolize_keys => true)
end
res = res.rstrip if res.class == String
res
end
|
[
"def",
"return_result",
"(",
"res",
",",
"method",
")",
"unless",
"method",
"==",
":lexer_name_for",
"||",
"method",
"==",
":highlight",
"||",
"method",
"==",
":css",
"res",
"=",
"MultiJson",
".",
"load",
"(",
"res",
",",
":symbolize_keys",
"=>",
"true",
")",
"end",
"res",
"=",
"res",
".",
"rstrip",
"if",
"res",
".",
"class",
"==",
"String",
"res",
"end"
] |
Return the final result for the API. Return Ruby objects for the methods that
want them, text otherwise.
|
[
"Return",
"the",
"final",
"result",
"for",
"the",
"API",
".",
"Return",
"Ruby",
"objects",
"for",
"the",
"methods",
"that",
"want",
"them",
"text",
"otherwise",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L427-L433
|
18,012
|
tmm1/pygments.rb
|
lib/pygments/popen.rb
|
Pygments.Popen.header_to_json
|
def header_to_json(header)
@log.info "[In header: #{header} "
header = MultiJson.load(header, :symbolize_keys => true)
if header[:error]
# Raise this as a Ruby exception of the MentosError class.
# Stop so we don't leave the pipe in an inconsistent state.
@log.error "Failed to convert header to JSON."
stop header[:error]
raise MentosError, header[:error]
else
header
end
end
|
ruby
|
def header_to_json(header)
@log.info "[In header: #{header} "
header = MultiJson.load(header, :symbolize_keys => true)
if header[:error]
# Raise this as a Ruby exception of the MentosError class.
# Stop so we don't leave the pipe in an inconsistent state.
@log.error "Failed to convert header to JSON."
stop header[:error]
raise MentosError, header[:error]
else
header
end
end
|
[
"def",
"header_to_json",
"(",
"header",
")",
"@log",
".",
"info",
"\"[In header: #{header} \"",
"header",
"=",
"MultiJson",
".",
"load",
"(",
"header",
",",
":symbolize_keys",
"=>",
"true",
")",
"if",
"header",
"[",
":error",
"]",
"# Raise this as a Ruby exception of the MentosError class.",
"# Stop so we don't leave the pipe in an inconsistent state.",
"@log",
".",
"error",
"\"Failed to convert header to JSON.\"",
"stop",
"header",
"[",
":error",
"]",
"raise",
"MentosError",
",",
"header",
"[",
":error",
"]",
"else",
"header",
"end",
"end"
] |
Convert a text header into JSON for easy access.
|
[
"Convert",
"a",
"text",
"header",
"into",
"JSON",
"for",
"easy",
"access",
"."
] |
926d1adad88c22f92010a0f284d2dcc10213ec1e
|
https://github.com/tmm1/pygments.rb/blob/926d1adad88c22f92010a0f284d2dcc10213ec1e/lib/pygments/popen.rb#L436-L449
|
18,013
|
pboling/flag_shih_tzu
|
lib/flag_shih_tzu.rb
|
FlagShihTzu.ClassMethods.sql_in_for_flag
|
def sql_in_for_flag(flag, colmn)
val = flag_mapping[colmn][flag]
flag_value_range_for_column(colmn).select { |bits| bits & val == val }
end
|
ruby
|
def sql_in_for_flag(flag, colmn)
val = flag_mapping[colmn][flag]
flag_value_range_for_column(colmn).select { |bits| bits & val == val }
end
|
[
"def",
"sql_in_for_flag",
"(",
"flag",
",",
"colmn",
")",
"val",
"=",
"flag_mapping",
"[",
"colmn",
"]",
"[",
"flag",
"]",
"flag_value_range_for_column",
"(",
"colmn",
")",
".",
"select",
"{",
"|",
"bits",
"|",
"bits",
"&",
"val",
"==",
"val",
"}",
"end"
] |
returns an array of integers suitable for a SQL IN statement.
|
[
"returns",
"an",
"array",
"of",
"integers",
"suitable",
"for",
"a",
"SQL",
"IN",
"statement",
"."
] |
07a5b8b817d456d1a663581d4bbce37834a1795c
|
https://github.com/pboling/flag_shih_tzu/blob/07a5b8b817d456d1a663581d4bbce37834a1795c/lib/flag_shih_tzu.rb#L429-L432
|
18,014
|
Dynflow/dynflow
|
lib/dynflow/action/format.rb
|
Dynflow.Action::Format.input_format
|
def input_format(&block)
case
when block && !@input_format_block
@input_format_block = block
when !block && @input_format_block
return @input_format ||= Apipie::Params::Description.define(&@input_format_block)
when block && @input_format_block
raise "The input_format has already been defined in #{self.class}"
when !block && !@input_format_block
if superclass.respond_to? :input_format
superclass.input_format
else
raise "The input_format has not been defined yet in #{self.class}"
end
end
end
|
ruby
|
def input_format(&block)
case
when block && !@input_format_block
@input_format_block = block
when !block && @input_format_block
return @input_format ||= Apipie::Params::Description.define(&@input_format_block)
when block && @input_format_block
raise "The input_format has already been defined in #{self.class}"
when !block && !@input_format_block
if superclass.respond_to? :input_format
superclass.input_format
else
raise "The input_format has not been defined yet in #{self.class}"
end
end
end
|
[
"def",
"input_format",
"(",
"&",
"block",
")",
"case",
"when",
"block",
"&&",
"!",
"@input_format_block",
"@input_format_block",
"=",
"block",
"when",
"!",
"block",
"&&",
"@input_format_block",
"return",
"@input_format",
"||=",
"Apipie",
"::",
"Params",
"::",
"Description",
".",
"define",
"(",
"@input_format_block",
")",
"when",
"block",
"&&",
"@input_format_block",
"raise",
"\"The input_format has already been defined in #{self.class}\"",
"when",
"!",
"block",
"&&",
"!",
"@input_format_block",
"if",
"superclass",
".",
"respond_to?",
":input_format",
"superclass",
".",
"input_format",
"else",
"raise",
"\"The input_format has not been defined yet in #{self.class}\"",
"end",
"end",
"end"
] |
we don't evaluate tbe block immediatelly, but postpone it till all the
action classes are loaded, because we can use them to reference output format
|
[
"we",
"don",
"t",
"evaluate",
"tbe",
"block",
"immediatelly",
"but",
"postpone",
"it",
"till",
"all",
"the",
"action",
"classes",
"are",
"loaded",
"because",
"we",
"can",
"use",
"them",
"to",
"reference",
"output",
"format"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/action/format.rb#L10-L25
|
18,015
|
Dynflow/dynflow
|
lib/dynflow/serializable.rb
|
Dynflow.Serializable.recursive_to_hash
|
def recursive_to_hash(*values)
if values.size == 1
value = values.first
case value
when String, Numeric, Symbol, TrueClass, FalseClass, NilClass, Time
value
when Hash
value.inject({}) { |h, (k, v)| h.update k => recursive_to_hash(v) }
when Array
value.map { |v| recursive_to_hash v }
else
value.to_hash
end
else
values.all? { |v| Type! v, Hash, NilClass }
recursive_to_hash(values.compact.reduce { |h, v| h.merge v })
end
end
|
ruby
|
def recursive_to_hash(*values)
if values.size == 1
value = values.first
case value
when String, Numeric, Symbol, TrueClass, FalseClass, NilClass, Time
value
when Hash
value.inject({}) { |h, (k, v)| h.update k => recursive_to_hash(v) }
when Array
value.map { |v| recursive_to_hash v }
else
value.to_hash
end
else
values.all? { |v| Type! v, Hash, NilClass }
recursive_to_hash(values.compact.reduce { |h, v| h.merge v })
end
end
|
[
"def",
"recursive_to_hash",
"(",
"*",
"values",
")",
"if",
"values",
".",
"size",
"==",
"1",
"value",
"=",
"values",
".",
"first",
"case",
"value",
"when",
"String",
",",
"Numeric",
",",
"Symbol",
",",
"TrueClass",
",",
"FalseClass",
",",
"NilClass",
",",
"Time",
"value",
"when",
"Hash",
"value",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"h",
",",
"(",
"k",
",",
"v",
")",
"|",
"h",
".",
"update",
"k",
"=>",
"recursive_to_hash",
"(",
"v",
")",
"}",
"when",
"Array",
"value",
".",
"map",
"{",
"|",
"v",
"|",
"recursive_to_hash",
"v",
"}",
"else",
"value",
".",
"to_hash",
"end",
"else",
"values",
".",
"all?",
"{",
"|",
"v",
"|",
"Type!",
"v",
",",
"Hash",
",",
"NilClass",
"}",
"recursive_to_hash",
"(",
"values",
".",
"compact",
".",
"reduce",
"{",
"|",
"h",
",",
"v",
"|",
"h",
".",
"merge",
"v",
"}",
")",
"end",
"end"
] |
recursively traverses hash-array structure and converts all to hashes
accepts more hashes which are then merged
|
[
"recursively",
"traverses",
"hash",
"-",
"array",
"structure",
"and",
"converts",
"all",
"to",
"hashes",
"accepts",
"more",
"hashes",
"which",
"are",
"then",
"merged"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/serializable.rb#L39-L56
|
18,016
|
Dynflow/dynflow
|
lib/dynflow/action/with_sub_plans.rb
|
Dynflow.Action::WithSubPlans.trigger
|
def trigger(action_class, *args)
if uses_concurrency_control
trigger_with_concurrency_control(action_class, *args)
else
world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) }
end
end
|
ruby
|
def trigger(action_class, *args)
if uses_concurrency_control
trigger_with_concurrency_control(action_class, *args)
else
world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) }
end
end
|
[
"def",
"trigger",
"(",
"action_class",
",",
"*",
"args",
")",
"if",
"uses_concurrency_control",
"trigger_with_concurrency_control",
"(",
"action_class",
",",
"args",
")",
"else",
"world",
".",
"trigger",
"{",
"world",
".",
"plan_with_options",
"(",
"action_class",
":",
"action_class",
",",
"args",
":",
"args",
",",
"caller_action",
":",
"self",
")",
"}",
"end",
"end"
] |
Helper for creating sub plans
|
[
"Helper",
"for",
"creating",
"sub",
"plans"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/action/with_sub_plans.rb#L79-L85
|
18,017
|
Dynflow/dynflow
|
lib/dynflow/action/with_bulk_sub_plans.rb
|
Dynflow.Action::WithBulkSubPlans.current_batch
|
def current_batch
start_position = output[:planned_count]
size = start_position + batch_size > total_count ? total_count - start_position : batch_size
batch(start_position, size)
end
|
ruby
|
def current_batch
start_position = output[:planned_count]
size = start_position + batch_size > total_count ? total_count - start_position : batch_size
batch(start_position, size)
end
|
[
"def",
"current_batch",
"start_position",
"=",
"output",
"[",
":planned_count",
"]",
"size",
"=",
"start_position",
"+",
"batch_size",
">",
"total_count",
"?",
"total_count",
"-",
"start_position",
":",
"batch_size",
"batch",
"(",
"start_position",
",",
"size",
")",
"end"
] |
Returns the items in the current batch
|
[
"Returns",
"the",
"items",
"in",
"the",
"current",
"batch"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/action/with_bulk_sub_plans.rb#L49-L53
|
18,018
|
Dynflow/dynflow
|
lib/dynflow/execution_plan/dependency_graph.rb
|
Dynflow.ExecutionPlan::DependencyGraph.add_dependencies
|
def add_dependencies(step, action)
action.required_step_ids.each do |required_step_id|
@graph[step.id] << required_step_id
end
end
|
ruby
|
def add_dependencies(step, action)
action.required_step_ids.each do |required_step_id|
@graph[step.id] << required_step_id
end
end
|
[
"def",
"add_dependencies",
"(",
"step",
",",
"action",
")",
"action",
".",
"required_step_ids",
".",
"each",
"do",
"|",
"required_step_id",
"|",
"@graph",
"[",
"step",
".",
"id",
"]",
"<<",
"required_step_id",
"end",
"end"
] |
adds dependencies to graph that +step+ has based
on the steps referenced in its +input+
|
[
"adds",
"dependencies",
"to",
"graph",
"that",
"+",
"step",
"+",
"has",
"based",
"on",
"the",
"steps",
"referenced",
"in",
"its",
"+",
"input",
"+"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/execution_plan/dependency_graph.rb#L10-L14
|
18,019
|
Dynflow/dynflow
|
lib/dynflow/world.rb
|
Dynflow.World.reload!
|
def reload!
# TODO what happens with newly loaded classes
@action_classes = @action_classes.map do |klass|
begin
Utils.constantize(klass.to_s)
rescue NameError
nil # ignore missing classes
end
end.compact
middleware.clear_cache!
calculate_subscription_index
end
|
ruby
|
def reload!
# TODO what happens with newly loaded classes
@action_classes = @action_classes.map do |klass|
begin
Utils.constantize(klass.to_s)
rescue NameError
nil # ignore missing classes
end
end.compact
middleware.clear_cache!
calculate_subscription_index
end
|
[
"def",
"reload!",
"# TODO what happens with newly loaded classes",
"@action_classes",
"=",
"@action_classes",
".",
"map",
"do",
"|",
"klass",
"|",
"begin",
"Utils",
".",
"constantize",
"(",
"klass",
".",
"to_s",
")",
"rescue",
"NameError",
"nil",
"# ignore missing classes",
"end",
"end",
".",
"compact",
"middleware",
".",
"clear_cache!",
"calculate_subscription_index",
"end"
] |
reload actions classes, intended only for devel
|
[
"reload",
"actions",
"classes",
"intended",
"only",
"for",
"devel"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/world.rb#L117-L128
|
18,020
|
Dynflow/dynflow
|
lib/dynflow/action/rescue.rb
|
Dynflow.Action::Rescue.rescue_strategy
|
def rescue_strategy
suggested_strategies = []
if self.steps.compact.any? { |step| step.state == :error }
suggested_strategies << SuggestedStrategy[self, rescue_strategy_for_self]
end
self.planned_actions.each do |planned_action|
rescue_strategy = rescue_strategy_for_planned_action(planned_action)
next unless rescue_strategy # ignore actions that have no say in the rescue strategy
suggested_strategies << SuggestedStrategy[planned_action, rescue_strategy]
end
combine_suggested_strategies(suggested_strategies)
end
|
ruby
|
def rescue_strategy
suggested_strategies = []
if self.steps.compact.any? { |step| step.state == :error }
suggested_strategies << SuggestedStrategy[self, rescue_strategy_for_self]
end
self.planned_actions.each do |planned_action|
rescue_strategy = rescue_strategy_for_planned_action(planned_action)
next unless rescue_strategy # ignore actions that have no say in the rescue strategy
suggested_strategies << SuggestedStrategy[planned_action, rescue_strategy]
end
combine_suggested_strategies(suggested_strategies)
end
|
[
"def",
"rescue_strategy",
"suggested_strategies",
"=",
"[",
"]",
"if",
"self",
".",
"steps",
".",
"compact",
".",
"any?",
"{",
"|",
"step",
"|",
"step",
".",
"state",
"==",
":error",
"}",
"suggested_strategies",
"<<",
"SuggestedStrategy",
"[",
"self",
",",
"rescue_strategy_for_self",
"]",
"end",
"self",
".",
"planned_actions",
".",
"each",
"do",
"|",
"planned_action",
"|",
"rescue_strategy",
"=",
"rescue_strategy_for_planned_action",
"(",
"planned_action",
")",
"next",
"unless",
"rescue_strategy",
"# ignore actions that have no say in the rescue strategy",
"suggested_strategies",
"<<",
"SuggestedStrategy",
"[",
"planned_action",
",",
"rescue_strategy",
"]",
"end",
"combine_suggested_strategies",
"(",
"suggested_strategies",
")",
"end"
] |
What strategy should be used for rescuing from error in
the action or its sub actions
@return Strategy
When determining the strategy, the algorithm starts from the
entry action that by default takes the strategy from #rescue_strategy_for_self
and #rescue_strategy_for_planned_actions and combines them together.
|
[
"What",
"strategy",
"should",
"be",
"used",
"for",
"rescuing",
"from",
"error",
"in",
"the",
"action",
"or",
"its",
"sub",
"actions"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/action/rescue.rb#L21-L35
|
18,021
|
Dynflow/dynflow
|
lib/dynflow/action/rescue.rb
|
Dynflow.Action::Rescue.combine_suggested_strategies
|
def combine_suggested_strategies(suggested_strategies)
if suggested_strategies.empty?
nil
else
# TODO: Find the safest rescue strategy among the suggested ones
if suggested_strategies.all? { |suggested_strategy| suggested_strategy.strategy == Skip }
return Skip
elsif suggested_strategies.all? { |suggested_strategy| suggested_strategy.strategy == Fail }
return Fail
else
return Pause # We don't know how to handle this case, so we'll just pause
end
end
end
|
ruby
|
def combine_suggested_strategies(suggested_strategies)
if suggested_strategies.empty?
nil
else
# TODO: Find the safest rescue strategy among the suggested ones
if suggested_strategies.all? { |suggested_strategy| suggested_strategy.strategy == Skip }
return Skip
elsif suggested_strategies.all? { |suggested_strategy| suggested_strategy.strategy == Fail }
return Fail
else
return Pause # We don't know how to handle this case, so we'll just pause
end
end
end
|
[
"def",
"combine_suggested_strategies",
"(",
"suggested_strategies",
")",
"if",
"suggested_strategies",
".",
"empty?",
"nil",
"else",
"# TODO: Find the safest rescue strategy among the suggested ones",
"if",
"suggested_strategies",
".",
"all?",
"{",
"|",
"suggested_strategy",
"|",
"suggested_strategy",
".",
"strategy",
"==",
"Skip",
"}",
"return",
"Skip",
"elsif",
"suggested_strategies",
".",
"all?",
"{",
"|",
"suggested_strategy",
"|",
"suggested_strategy",
".",
"strategy",
"==",
"Fail",
"}",
"return",
"Fail",
"else",
"return",
"Pause",
"# We don't know how to handle this case, so we'll just pause",
"end",
"end",
"end"
] |
Override when different approach should be taken for combining
the suggested strategies
|
[
"Override",
"when",
"different",
"approach",
"should",
"be",
"taken",
"for",
"combining",
"the",
"suggested",
"strategies"
] |
b52b2a91e36e34f8736200afa7a3fe5e1c94a020
|
https://github.com/Dynflow/dynflow/blob/b52b2a91e36e34f8736200afa7a3fe5e1c94a020/lib/dynflow/action/rescue.rb#L51-L64
|
18,022
|
theodi/csvlint.rb
|
lib/csvlint/error_collector.rb
|
Csvlint.ErrorCollector.build_errors
|
def build_errors(type, category = nil, row = nil, column = nil, content = nil, constraints = {})
@errors << Csvlint::ErrorMessage.new(type, category, row, column, content, constraints)
end
|
ruby
|
def build_errors(type, category = nil, row = nil, column = nil, content = nil, constraints = {})
@errors << Csvlint::ErrorMessage.new(type, category, row, column, content, constraints)
end
|
[
"def",
"build_errors",
"(",
"type",
",",
"category",
"=",
"nil",
",",
"row",
"=",
"nil",
",",
"column",
"=",
"nil",
",",
"content",
"=",
"nil",
",",
"constraints",
"=",
"{",
"}",
")",
"@errors",
"<<",
"Csvlint",
"::",
"ErrorMessage",
".",
"new",
"(",
"type",
",",
"category",
",",
"row",
",",
"column",
",",
"content",
",",
"constraints",
")",
"end"
] |
Creates a validation error
|
[
"Creates",
"a",
"validation",
"error"
] |
e11a4de001d18a1de1a692a9690f7a66b1430bfb
|
https://github.com/theodi/csvlint.rb/blob/e11a4de001d18a1de1a692a9690f7a66b1430bfb/lib/csvlint/error_collector.rb#L5-L7
|
18,023
|
theodi/csvlint.rb
|
lib/csvlint/validate.rb
|
Csvlint.Validator.parse_contents
|
def parse_contents(stream, line = nil)
# parse_contents will parse one line and apply headers, formats methods and error handle as appropriate
current_line = line.present? ? line : 1
all_errors = []
@csv_options[:encoding] = @encoding
begin
row = LineCSV.parse_line(stream, @csv_options)
rescue LineCSV::MalformedCSVError => e
build_exception_messages(e, stream, current_line)
end
if row
if current_line <= 1 && @csv_header
# this conditional should be refactored somewhere
row = row.reject { |col| col.nil? || col.empty? }
validate_header(row)
@col_counts << row.size
else
build_formats(row)
@col_counts << row.reject { |col| col.nil? || col.empty? }.size
@expected_columns = row.size unless @expected_columns != 0
build_errors(:blank_rows, :structure, current_line, nil, stream.to_s) if row.reject { |c| c.nil? || c.empty? }.size == 0
# Builds errors and warnings related to the provided schema file
if @schema
@schema.validate_row(row, current_line, all_errors, @source, @validate)
@errors += @schema.errors
all_errors += @schema.errors
@warnings += @schema.warnings
else
build_errors(:ragged_rows, :structure, current_line, nil, stream.to_s) if !row.empty? && row.size != @expected_columns
end
end
end
@data << row
end
|
ruby
|
def parse_contents(stream, line = nil)
# parse_contents will parse one line and apply headers, formats methods and error handle as appropriate
current_line = line.present? ? line : 1
all_errors = []
@csv_options[:encoding] = @encoding
begin
row = LineCSV.parse_line(stream, @csv_options)
rescue LineCSV::MalformedCSVError => e
build_exception_messages(e, stream, current_line)
end
if row
if current_line <= 1 && @csv_header
# this conditional should be refactored somewhere
row = row.reject { |col| col.nil? || col.empty? }
validate_header(row)
@col_counts << row.size
else
build_formats(row)
@col_counts << row.reject { |col| col.nil? || col.empty? }.size
@expected_columns = row.size unless @expected_columns != 0
build_errors(:blank_rows, :structure, current_line, nil, stream.to_s) if row.reject { |c| c.nil? || c.empty? }.size == 0
# Builds errors and warnings related to the provided schema file
if @schema
@schema.validate_row(row, current_line, all_errors, @source, @validate)
@errors += @schema.errors
all_errors += @schema.errors
@warnings += @schema.warnings
else
build_errors(:ragged_rows, :structure, current_line, nil, stream.to_s) if !row.empty? && row.size != @expected_columns
end
end
end
@data << row
end
|
[
"def",
"parse_contents",
"(",
"stream",
",",
"line",
"=",
"nil",
")",
"# parse_contents will parse one line and apply headers, formats methods and error handle as appropriate",
"current_line",
"=",
"line",
".",
"present?",
"?",
"line",
":",
"1",
"all_errors",
"=",
"[",
"]",
"@csv_options",
"[",
":encoding",
"]",
"=",
"@encoding",
"begin",
"row",
"=",
"LineCSV",
".",
"parse_line",
"(",
"stream",
",",
"@csv_options",
")",
"rescue",
"LineCSV",
"::",
"MalformedCSVError",
"=>",
"e",
"build_exception_messages",
"(",
"e",
",",
"stream",
",",
"current_line",
")",
"end",
"if",
"row",
"if",
"current_line",
"<=",
"1",
"&&",
"@csv_header",
"# this conditional should be refactored somewhere",
"row",
"=",
"row",
".",
"reject",
"{",
"|",
"col",
"|",
"col",
".",
"nil?",
"||",
"col",
".",
"empty?",
"}",
"validate_header",
"(",
"row",
")",
"@col_counts",
"<<",
"row",
".",
"size",
"else",
"build_formats",
"(",
"row",
")",
"@col_counts",
"<<",
"row",
".",
"reject",
"{",
"|",
"col",
"|",
"col",
".",
"nil?",
"||",
"col",
".",
"empty?",
"}",
".",
"size",
"@expected_columns",
"=",
"row",
".",
"size",
"unless",
"@expected_columns",
"!=",
"0",
"build_errors",
"(",
":blank_rows",
",",
":structure",
",",
"current_line",
",",
"nil",
",",
"stream",
".",
"to_s",
")",
"if",
"row",
".",
"reject",
"{",
"|",
"c",
"|",
"c",
".",
"nil?",
"||",
"c",
".",
"empty?",
"}",
".",
"size",
"==",
"0",
"# Builds errors and warnings related to the provided schema file",
"if",
"@schema",
"@schema",
".",
"validate_row",
"(",
"row",
",",
"current_line",
",",
"all_errors",
",",
"@source",
",",
"@validate",
")",
"@errors",
"+=",
"@schema",
".",
"errors",
"all_errors",
"+=",
"@schema",
".",
"errors",
"@warnings",
"+=",
"@schema",
".",
"warnings",
"else",
"build_errors",
"(",
":ragged_rows",
",",
":structure",
",",
"current_line",
",",
"nil",
",",
"stream",
".",
"to_s",
")",
"if",
"!",
"row",
".",
"empty?",
"&&",
"row",
".",
"size",
"!=",
"@expected_columns",
"end",
"end",
"end",
"@data",
"<<",
"row",
"end"
] |
analyses the provided csv and builds errors, warnings and info messages
|
[
"analyses",
"the",
"provided",
"csv",
"and",
"builds",
"errors",
"warnings",
"and",
"info",
"messages"
] |
e11a4de001d18a1de1a692a9690f7a66b1430bfb
|
https://github.com/theodi/csvlint.rb/blob/e11a4de001d18a1de1a692a9690f7a66b1430bfb/lib/csvlint/validate.rb#L174-L210
|
18,024
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.create_order_reference_for_id
|
def create_order_reference_for_id(
id,
id_type,
inherit_shipping_address: nil,
confirm_now: nil,
amount: nil,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
store_name: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CreateOrderReferenceForId',
'SellerId' => merchant_id,
'Id' => id,
'IdType' => id_type
}
optional = {
'InheritShippingAddress' => inherit_shipping_address,
'ConfirmNow' => confirm_now,
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code,
'OrderReferenceAttributes.PlatformId' => platform_id,
'OrderReferenceAttributes.SellerNote' => seller_note,
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def create_order_reference_for_id(
id,
id_type,
inherit_shipping_address: nil,
confirm_now: nil,
amount: nil,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
store_name: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CreateOrderReferenceForId',
'SellerId' => merchant_id,
'Id' => id,
'IdType' => id_type
}
optional = {
'InheritShippingAddress' => inherit_shipping_address,
'ConfirmNow' => confirm_now,
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code,
'OrderReferenceAttributes.PlatformId' => platform_id,
'OrderReferenceAttributes.SellerNote' => seller_note,
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"create_order_reference_for_id",
"(",
"id",
",",
"id_type",
",",
"inherit_shipping_address",
":",
"nil",
",",
"confirm_now",
":",
"nil",
",",
"amount",
":",
"nil",
",",
"currency_code",
":",
"@currency_code",
",",
"platform_id",
":",
"nil",
",",
"seller_note",
":",
"nil",
",",
"seller_order_id",
":",
"nil",
",",
"store_name",
":",
"nil",
",",
"custom_information",
":",
"nil",
",",
"supplementary_data",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'CreateOrderReferenceForId'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'Id'",
"=>",
"id",
",",
"'IdType'",
"=>",
"id_type",
"}",
"optional",
"=",
"{",
"'InheritShippingAddress'",
"=>",
"inherit_shipping_address",
",",
"'ConfirmNow'",
"=>",
"confirm_now",
",",
"'OrderReferenceAttributes.OrderTotal.Amount'",
"=>",
"amount",
",",
"'OrderReferenceAttributes.OrderTotal.CurrencyCode'",
"=>",
"currency_code",
",",
"'OrderReferenceAttributes.PlatformId'",
"=>",
"platform_id",
",",
"'OrderReferenceAttributes.SellerNote'",
"=>",
"seller_note",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId'",
"=>",
"seller_order_id",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.StoreName'",
"=>",
"store_name",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation'",
"=>",
"custom_information",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData'",
"=>",
"supplementary_data",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Creates an order reference for the given object
@see https://pay.amazon.com/documentation/apireference/201751630#201751670
@param id [String]
@param id_type [String]
@optional inherit_shipping_address [Boolean]
@optional confirm_now [Boolean]
@optional amount [String] (required when confirm_now is set to true)
@optional currency_code [String]
@optional platform_id [String]
@optional seller_note [String]
@optional seller_order_id [String]
@optional store_name [String]
@optional custom_information [String]
@optional supplementary_data [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Creates",
"an",
"order",
"reference",
"for",
"the",
"given",
"object"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L133-L172
|
18,025
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_billing_agreement_details
|
def get_billing_agreement_details(
amazon_billing_agreement_id,
address_consent_token: nil,
access_token: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetBillingAgreementDetails',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
# Preseving address_consent_token for backwards compatibility
# AccessToken returns all data in AddressConsentToken plus new data
# You cannot pass both address_consent_token and access_token in
# the same call or you will encounter a 400/"AmbiguousToken" error
'AccessToken' => access_token,
'AddressConsentToken' => address_consent_token,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_billing_agreement_details(
amazon_billing_agreement_id,
address_consent_token: nil,
access_token: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetBillingAgreementDetails',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
# Preseving address_consent_token for backwards compatibility
# AccessToken returns all data in AddressConsentToken plus new data
# You cannot pass both address_consent_token and access_token in
# the same call or you will encounter a 400/"AmbiguousToken" error
'AccessToken' => access_token,
'AddressConsentToken' => address_consent_token,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_billing_agreement_details",
"(",
"amazon_billing_agreement_id",
",",
"address_consent_token",
":",
"nil",
",",
"access_token",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetBillingAgreementDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonBillingAgreementId'",
"=>",
"amazon_billing_agreement_id",
"}",
"optional",
"=",
"{",
"# Preseving address_consent_token for backwards compatibility",
"# AccessToken returns all data in AddressConsentToken plus new data",
"# You cannot pass both address_consent_token and access_token in",
"# the same call or you will encounter a 400/\"AmbiguousToken\" error",
"'AccessToken'",
"=>",
"access_token",
",",
"'AddressConsentToken'",
"=>",
"address_consent_token",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns details about the Billing Agreement object and its current state
@see https://pay.amazon.com/documentation/apireference/201751630#201751690
@param amazon_billing_agreement_id [String]
@optional address_consent_token [String]
@optional access_token [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"details",
"about",
"the",
"Billing",
"Agreement",
"object",
"and",
"its",
"current",
"state"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L182-L207
|
18,026
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.set_billing_agreement_details
|
def set_billing_agreement_details(
amazon_billing_agreement_id,
platform_id: nil,
seller_note: nil,
seller_billing_agreement_id: nil,
custom_information: nil,
store_name: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetBillingAgreementDetails',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'BillingAgreementAttributes.PlatformId' => platform_id,
'BillingAgreementAttributes.SellerNote' => seller_note,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def set_billing_agreement_details(
amazon_billing_agreement_id,
platform_id: nil,
seller_note: nil,
seller_billing_agreement_id: nil,
custom_information: nil,
store_name: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetBillingAgreementDetails',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'BillingAgreementAttributes.PlatformId' => platform_id,
'BillingAgreementAttributes.SellerNote' => seller_note,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"set_billing_agreement_details",
"(",
"amazon_billing_agreement_id",
",",
"platform_id",
":",
"nil",
",",
"seller_note",
":",
"nil",
",",
"seller_billing_agreement_id",
":",
"nil",
",",
"custom_information",
":",
"nil",
",",
"store_name",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'SetBillingAgreementDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonBillingAgreementId'",
"=>",
"amazon_billing_agreement_id",
"}",
"optional",
"=",
"{",
"'BillingAgreementAttributes.PlatformId'",
"=>",
"platform_id",
",",
"'BillingAgreementAttributes.SellerNote'",
"=>",
"seller_note",
",",
"'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId'",
"=>",
"seller_billing_agreement_id",
",",
"'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation'",
"=>",
"custom_information",
",",
"'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName'",
"=>",
"store_name",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Sets billing agreement details such as a description of the agreement
and other information about the seller.
@see https://pay.amazon.com/documentation/apireference/201751630#201751700
@param amazon_billing_agreement_id [String]
@optional platform_id [String]
@optional seller_note [String]
@optional seller_billing_agreement_id [String]
@optional custom_information [String]
@optional store_name [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Sets",
"billing",
"agreement",
"details",
"such",
"as",
"a",
"description",
"of",
"the",
"agreement",
"and",
"other",
"information",
"about",
"the",
"seller",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L220-L247
|
18,027
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.confirm_billing_agreement
|
def confirm_billing_agreement(
amazon_billing_agreement_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ConfirmBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def confirm_billing_agreement(
amazon_billing_agreement_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ConfirmBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"confirm_billing_agreement",
"(",
"amazon_billing_agreement_id",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'ConfirmBillingAgreement'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonBillingAgreementId'",
"=>",
"amazon_billing_agreement_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Confirms that the billing agreement is free of constraints and all
required information has been set on the billing agreement
@see https://pay.amazon.com/documentation/apireference/201751630#201751710
@param amazon_billing_agreement_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Confirms",
"that",
"the",
"billing",
"agreement",
"is",
"free",
"of",
"constraints",
"and",
"all",
"required",
"information",
"has",
"been",
"set",
"on",
"the",
"billing",
"agreement"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L255-L272
|
18,028
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.validate_billing_agreement
|
def validate_billing_agreement(
amazon_billing_agreement_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ValidateBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def validate_billing_agreement(
amazon_billing_agreement_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ValidateBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"validate_billing_agreement",
"(",
"amazon_billing_agreement_id",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'ValidateBillingAgreement'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonBillingAgreementId'",
"=>",
"amazon_billing_agreement_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Validates the status of the BillingAgreement object and the payment
method associated with it
@see https://pay.amazon.com/documentation/apireference/201751630#201751720
@param amazon_billing_agreement_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Validates",
"the",
"status",
"of",
"the",
"BillingAgreement",
"object",
"and",
"the",
"payment",
"method",
"associated",
"with",
"it"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L280-L297
|
18,029
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.close_billing_agreement
|
def close_billing_agreement(
amazon_billing_agreement_id,
closure_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CloseBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'ClosureReason' => closure_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def close_billing_agreement(
amazon_billing_agreement_id,
closure_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CloseBillingAgreement',
'SellerId' => merchant_id,
'AmazonBillingAgreementId' => amazon_billing_agreement_id
}
optional = {
'ClosureReason' => closure_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"close_billing_agreement",
"(",
"amazon_billing_agreement_id",
",",
"closure_reason",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'CloseBillingAgreement'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonBillingAgreementId'",
"=>",
"amazon_billing_agreement_id",
"}",
"optional",
"=",
"{",
"'ClosureReason'",
"=>",
"closure_reason",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Confirms that you want to terminate the billing agreement with the buyer
and that you do not expect to create any new order references or
authorizations on this billing agreement
@see https://pay.amazon.com/documentation/apireference/201751630#201751950
@param amazon_billing_agreement_id [String]
@optional closure_reason [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Confirms",
"that",
"you",
"want",
"to",
"terminate",
"the",
"billing",
"agreement",
"with",
"the",
"buyer",
"and",
"that",
"you",
"do",
"not",
"expect",
"to",
"create",
"any",
"new",
"order",
"references",
"or",
"authorizations",
"on",
"this",
"billing",
"agreement"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L374-L393
|
18,030
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.list_order_reference
|
def list_order_reference(
query_id,
query_id_type,
created_time_range_start: nil,
created_time_range_end: nil,
sort_order: nil,
page_size: nil,
order_reference_status_list_filter: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
payment_domain = payment_domain_hash[@region]
parameters = {
'Action' => 'ListOrderReference',
'SellerId' => merchant_id,
'QueryId' => query_id,
'QueryIdType' => query_id_type
}
optional = {
'CreatedTimeRange.StartTime' => created_time_range_start,
'CreatedTimeRange.EndTime' => created_time_range_end,
'SortOrder' => sort_order,
'PageSize' => page_size,
'PaymentDomain' => payment_domain,
'MWSAuthToken' => mws_auth_token
}
if order_reference_status_list_filter
order_reference_status_list_filter.each_with_index do |val, index|
optional_key = "OrderReferenceStatusListFilter.OrderReferenceStatus.#{index + 1}"
optional[optional_key] = val
end
end
operation(parameters, optional)
end
|
ruby
|
def list_order_reference(
query_id,
query_id_type,
created_time_range_start: nil,
created_time_range_end: nil,
sort_order: nil,
page_size: nil,
order_reference_status_list_filter: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
payment_domain = payment_domain_hash[@region]
parameters = {
'Action' => 'ListOrderReference',
'SellerId' => merchant_id,
'QueryId' => query_id,
'QueryIdType' => query_id_type
}
optional = {
'CreatedTimeRange.StartTime' => created_time_range_start,
'CreatedTimeRange.EndTime' => created_time_range_end,
'SortOrder' => sort_order,
'PageSize' => page_size,
'PaymentDomain' => payment_domain,
'MWSAuthToken' => mws_auth_token
}
if order_reference_status_list_filter
order_reference_status_list_filter.each_with_index do |val, index|
optional_key = "OrderReferenceStatusListFilter.OrderReferenceStatus.#{index + 1}"
optional[optional_key] = val
end
end
operation(parameters, optional)
end
|
[
"def",
"list_order_reference",
"(",
"query_id",
",",
"query_id_type",
",",
"created_time_range_start",
":",
"nil",
",",
"created_time_range_end",
":",
"nil",
",",
"sort_order",
":",
"nil",
",",
"page_size",
":",
"nil",
",",
"order_reference_status_list_filter",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"payment_domain",
"=",
"payment_domain_hash",
"[",
"@region",
"]",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'ListOrderReference'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'QueryId'",
"=>",
"query_id",
",",
"'QueryIdType'",
"=>",
"query_id_type",
"}",
"optional",
"=",
"{",
"'CreatedTimeRange.StartTime'",
"=>",
"created_time_range_start",
",",
"'CreatedTimeRange.EndTime'",
"=>",
"created_time_range_end",
",",
"'SortOrder'",
"=>",
"sort_order",
",",
"'PageSize'",
"=>",
"page_size",
",",
"'PaymentDomain'",
"=>",
"payment_domain",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"if",
"order_reference_status_list_filter",
"order_reference_status_list_filter",
".",
"each_with_index",
"do",
"|",
"val",
",",
"index",
"|",
"optional_key",
"=",
"\"OrderReferenceStatusListFilter.OrderReferenceStatus.#{index + 1}\"",
"optional",
"[",
"optional_key",
"]",
"=",
"val",
"end",
"end",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Allows the search of any Amazon Pay order made using secondary
seller order IDs generated manually, a solution provider, or a custom
order fulfillment service.
@param query_id [String]
@param query_id_type [String]
@optional created_time_range_start [String]
@optional created_time_range_end [String]
@optional sort_order [String]
@optional page_size [Integer]
@optional order_reference_status_list_filter Array[String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Allows",
"the",
"search",
"of",
"any",
"Amazon",
"Pay",
"order",
"made",
"using",
"secondary",
"seller",
"order",
"IDs",
"generated",
"manually",
"a",
"solution",
"provider",
"or",
"a",
"custom",
"order",
"fulfillment",
"service",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L407-L445
|
18,031
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_merchant_account_status
|
def get_merchant_account_status(
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetMerchantAccountStatus',
'SellerId' => merchant_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_merchant_account_status(
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetMerchantAccountStatus',
'SellerId' => merchant_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_merchant_account_status",
"(",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetMerchantAccountStatus'",
",",
"'SellerId'",
"=>",
"merchant_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns status of the merchant
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"status",
"of",
"the",
"merchant"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L464-L479
|
18,032
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_order_reference_details
|
def get_order_reference_details(
amazon_order_reference_id,
address_consent_token: nil,
access_token: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetOrderReferenceDetails',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
# Preseving address_consent_token for backwards compatibility
# AccessToken returns all data in AddressConsentToken plus new data
'AccessToken' => access_token || address_consent_token,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_order_reference_details(
amazon_order_reference_id,
address_consent_token: nil,
access_token: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetOrderReferenceDetails',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
# Preseving address_consent_token for backwards compatibility
# AccessToken returns all data in AddressConsentToken plus new data
'AccessToken' => access_token || address_consent_token,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_order_reference_details",
"(",
"amazon_order_reference_id",
",",
"address_consent_token",
":",
"nil",
",",
"access_token",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetOrderReferenceDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonOrderReferenceId'",
"=>",
"amazon_order_reference_id",
"}",
"optional",
"=",
"{",
"# Preseving address_consent_token for backwards compatibility",
"# AccessToken returns all data in AddressConsentToken plus new data",
"'AccessToken'",
"=>",
"access_token",
"||",
"address_consent_token",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns details about the Order Reference object and its current state
@see https://pay.amazon.com/documentation/apireference/201751630#201751970
@param amazon_order_reference_id [String]
@optional address_consent_token [String]
@optional access_token [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"details",
"about",
"the",
"Order",
"Reference",
"object",
"and",
"its",
"current",
"state"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L488-L510
|
18,033
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.set_order_reference_details
|
def set_order_reference_details(
amazon_order_reference_id,
amount,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
request_payment_authorization: nil,
store_name: nil,
order_item_categories: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetOrderReferenceDetails',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id,
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code
}
optional = {
'OrderReferenceAttributes.PlatformId' => platform_id,
'OrderReferenceAttributes.RequestPaymentAuthorization' => request_payment_authorization,
'OrderReferenceAttributes.SellerNote' => seller_note,
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
if order_item_categories
optional.merge!(
get_categories_list(
'OrderReferenceAttributes',
order_item_categories
)
)
end
operation(parameters, optional)
end
|
ruby
|
def set_order_reference_details(
amazon_order_reference_id,
amount,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
request_payment_authorization: nil,
store_name: nil,
order_item_categories: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetOrderReferenceDetails',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id,
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code
}
optional = {
'OrderReferenceAttributes.PlatformId' => platform_id,
'OrderReferenceAttributes.RequestPaymentAuthorization' => request_payment_authorization,
'OrderReferenceAttributes.SellerNote' => seller_note,
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
if order_item_categories
optional.merge!(
get_categories_list(
'OrderReferenceAttributes',
order_item_categories
)
)
end
operation(parameters, optional)
end
|
[
"def",
"set_order_reference_details",
"(",
"amazon_order_reference_id",
",",
"amount",
",",
"currency_code",
":",
"@currency_code",
",",
"platform_id",
":",
"nil",
",",
"seller_note",
":",
"nil",
",",
"seller_order_id",
":",
"nil",
",",
"request_payment_authorization",
":",
"nil",
",",
"store_name",
":",
"nil",
",",
"order_item_categories",
":",
"nil",
",",
"custom_information",
":",
"nil",
",",
"supplementary_data",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'SetOrderReferenceDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonOrderReferenceId'",
"=>",
"amazon_order_reference_id",
",",
"'OrderReferenceAttributes.OrderTotal.Amount'",
"=>",
"amount",
",",
"'OrderReferenceAttributes.OrderTotal.CurrencyCode'",
"=>",
"currency_code",
"}",
"optional",
"=",
"{",
"'OrderReferenceAttributes.PlatformId'",
"=>",
"platform_id",
",",
"'OrderReferenceAttributes.RequestPaymentAuthorization'",
"=>",
"request_payment_authorization",
",",
"'OrderReferenceAttributes.SellerNote'",
"=>",
"seller_note",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId'",
"=>",
"seller_order_id",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.StoreName'",
"=>",
"store_name",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation'",
"=>",
"custom_information",
",",
"'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData'",
"=>",
"supplementary_data",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"if",
"order_item_categories",
"optional",
".",
"merge!",
"(",
"get_categories_list",
"(",
"'OrderReferenceAttributes'",
",",
"order_item_categories",
")",
")",
"end",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Sets order reference details such as the order total and a description
for the order
@see https://pay.amazon.com/documentation/apireference/201751630#201751960
@param amazon_order_reference_id [String]
@param amount [String]
@optional currency_code [String]
@optional platform_id [String]
@optional seller_note [String]
@optional seller_order_id [String]
@optional request_payment_authorization [Boolean]
@optional store_name [String]
@optional order_item_categories Array[String]
@optional custom_information [String]
@optional supplementary_data [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Sets",
"order",
"reference",
"details",
"such",
"as",
"the",
"order",
"total",
"and",
"a",
"description",
"for",
"the",
"order"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L528-L573
|
18,034
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.set_order_attributes
|
def set_order_attributes(
amazon_order_reference_id,
amount: nil,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
payment_service_provider_id: nil,
payment_service_provider_order_id: nil,
request_payment_authorization: nil,
store_name: nil,
order_item_categories: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetOrderAttributes',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'OrderAttributes.OrderTotal.Amount' => amount,
'OrderAttributes.OrderTotal.CurrencyCode' => currency_code,
'OrderAttributes.PlatformId' => platform_id,
'OrderAttributes.SellerNote' => seller_note,
'OrderAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId' => payment_service_provider_id,
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId' => payment_service_provider_order_id,
'OrderAttributes.RequestPaymentAuthorization' => request_payment_authorization,
'OrderAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
optional['OrderAttributes.OrderTotal.CurrencyCode'] = nil if amount.nil?
if order_item_categories
optional.merge!(
get_categories_list(
'OrderAttributes',
order_item_categories
)
)
end
operation(parameters, optional)
end
|
ruby
|
def set_order_attributes(
amazon_order_reference_id,
amount: nil,
currency_code: @currency_code,
platform_id: nil,
seller_note: nil,
seller_order_id: nil,
payment_service_provider_id: nil,
payment_service_provider_order_id: nil,
request_payment_authorization: nil,
store_name: nil,
order_item_categories: nil,
custom_information: nil,
supplementary_data: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'SetOrderAttributes',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'OrderAttributes.OrderTotal.Amount' => amount,
'OrderAttributes.OrderTotal.CurrencyCode' => currency_code,
'OrderAttributes.PlatformId' => platform_id,
'OrderAttributes.SellerNote' => seller_note,
'OrderAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId' => payment_service_provider_id,
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId' => payment_service_provider_order_id,
'OrderAttributes.RequestPaymentAuthorization' => request_payment_authorization,
'OrderAttributes.SellerOrderAttributes.StoreName' => store_name,
'OrderAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
'OrderAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
'MWSAuthToken' => mws_auth_token
}
optional['OrderAttributes.OrderTotal.CurrencyCode'] = nil if amount.nil?
if order_item_categories
optional.merge!(
get_categories_list(
'OrderAttributes',
order_item_categories
)
)
end
operation(parameters, optional)
end
|
[
"def",
"set_order_attributes",
"(",
"amazon_order_reference_id",
",",
"amount",
":",
"nil",
",",
"currency_code",
":",
"@currency_code",
",",
"platform_id",
":",
"nil",
",",
"seller_note",
":",
"nil",
",",
"seller_order_id",
":",
"nil",
",",
"payment_service_provider_id",
":",
"nil",
",",
"payment_service_provider_order_id",
":",
"nil",
",",
"request_payment_authorization",
":",
"nil",
",",
"store_name",
":",
"nil",
",",
"order_item_categories",
":",
"nil",
",",
"custom_information",
":",
"nil",
",",
"supplementary_data",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'SetOrderAttributes'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonOrderReferenceId'",
"=>",
"amazon_order_reference_id",
"}",
"optional",
"=",
"{",
"'OrderAttributes.OrderTotal.Amount'",
"=>",
"amount",
",",
"'OrderAttributes.OrderTotal.CurrencyCode'",
"=>",
"currency_code",
",",
"'OrderAttributes.PlatformId'",
"=>",
"platform_id",
",",
"'OrderAttributes.SellerNote'",
"=>",
"seller_note",
",",
"'OrderAttributes.SellerOrderAttributes.SellerOrderId'",
"=>",
"seller_order_id",
",",
"'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId'",
"=>",
"payment_service_provider_id",
",",
"'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId'",
"=>",
"payment_service_provider_order_id",
",",
"'OrderAttributes.RequestPaymentAuthorization'",
"=>",
"request_payment_authorization",
",",
"'OrderAttributes.SellerOrderAttributes.StoreName'",
"=>",
"store_name",
",",
"'OrderAttributes.SellerOrderAttributes.CustomInformation'",
"=>",
"custom_information",
",",
"'OrderAttributes.SellerOrderAttributes.SupplementaryData'",
"=>",
"supplementary_data",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"optional",
"[",
"'OrderAttributes.OrderTotal.CurrencyCode'",
"]",
"=",
"nil",
"if",
"amount",
".",
"nil?",
"if",
"order_item_categories",
"optional",
".",
"merge!",
"(",
"get_categories_list",
"(",
"'OrderAttributes'",
",",
"order_item_categories",
")",
")",
"end",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Sets order attributes such as the order total and a description
for the order
@see https://pay.amazon.com/documentation/apireference/201751630#201751960
@param amazon_order_reference_id [String]
@optional amount [String]
@optional currency_code [String]
@optional platform_id [String]
@optional seller_note [String]
@optional seller_order_id [String]
@optional request_payment_authorization [Boolean]
@optional store_name [String]
@optional order_item_categories Array[String]
@optional custom_information [String]
@optional supplementary_data [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Sets",
"order",
"attributes",
"such",
"as",
"the",
"order",
"total",
"and",
"a",
"description",
"for",
"the",
"order"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L591-L642
|
18,035
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.confirm_order_reference
|
def confirm_order_reference(
amazon_order_reference_id,
success_url: nil,
failure_url: nil,
authorization_amount: nil,
currency_code: @currency_code,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ConfirmOrderReference',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'SuccessUrl' => success_url,
'FailureUrl' => failure_url,
'AuthorizationAmount.Amount' => authorization_amount,
'AuthorizationAmount.CurrencyCode' => currency_code,
'MWSAuthToken' => mws_auth_token
}
optional['AuthorizationAmount.CurrencyCode'] = nil if authorization_amount.nil?
operation(parameters, optional)
end
|
ruby
|
def confirm_order_reference(
amazon_order_reference_id,
success_url: nil,
failure_url: nil,
authorization_amount: nil,
currency_code: @currency_code,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'ConfirmOrderReference',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'SuccessUrl' => success_url,
'FailureUrl' => failure_url,
'AuthorizationAmount.Amount' => authorization_amount,
'AuthorizationAmount.CurrencyCode' => currency_code,
'MWSAuthToken' => mws_auth_token
}
optional['AuthorizationAmount.CurrencyCode'] = nil if authorization_amount.nil?
operation(parameters, optional)
end
|
[
"def",
"confirm_order_reference",
"(",
"amazon_order_reference_id",
",",
"success_url",
":",
"nil",
",",
"failure_url",
":",
"nil",
",",
"authorization_amount",
":",
"nil",
",",
"currency_code",
":",
"@currency_code",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'ConfirmOrderReference'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonOrderReferenceId'",
"=>",
"amazon_order_reference_id",
"}",
"optional",
"=",
"{",
"'SuccessUrl'",
"=>",
"success_url",
",",
"'FailureUrl'",
"=>",
"failure_url",
",",
"'AuthorizationAmount.Amount'",
"=>",
"authorization_amount",
",",
"'AuthorizationAmount.CurrencyCode'",
"=>",
"currency_code",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"optional",
"[",
"'AuthorizationAmount.CurrencyCode'",
"]",
"=",
"nil",
"if",
"authorization_amount",
".",
"nil?",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Confirms that the order reference is free of constraints and all required
information has been set on the order reference
@see https://pay.amazon.com/documentation/apireference/201751630#201751980
@param amazon_order_reference_id [String]
@optional success_url [String]
@optional failure_url [String]
@optional authorization_amount [String]
@optional currency_code [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Confirms",
"that",
"the",
"order",
"reference",
"is",
"free",
"of",
"constraints",
"and",
"all",
"required",
"information",
"has",
"been",
"set",
"on",
"the",
"order",
"reference"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L654-L681
|
18,036
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.cancel_order_reference
|
def cancel_order_reference(
amazon_order_reference_id,
cancelation_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CancelOrderReference',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'CancelationReason' => cancelation_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def cancel_order_reference(
amazon_order_reference_id,
cancelation_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CancelOrderReference',
'SellerId' => merchant_id,
'AmazonOrderReferenceId' => amazon_order_reference_id
}
optional = {
'CancelationReason' => cancelation_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"cancel_order_reference",
"(",
"amazon_order_reference_id",
",",
"cancelation_reason",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'CancelOrderReference'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonOrderReferenceId'",
"=>",
"amazon_order_reference_id",
"}",
"optional",
"=",
"{",
"'CancelationReason'",
"=>",
"cancelation_reason",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Cancels a previously confirmed order reference
@see https://pay.amazon.com/documentation/apireference/201751630#201751990
@param amazon_order_reference_id [String]
@optional cancelation_reason [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Cancels",
"a",
"previously",
"confirmed",
"order",
"reference"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L689-L708
|
18,037
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_authorization_details
|
def get_authorization_details(
amazon_authorization_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetAuthorizationDetails',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_authorization_details(
amazon_authorization_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetAuthorizationDetails',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_authorization_details",
"(",
"amazon_authorization_id",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetAuthorizationDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonAuthorizationId'",
"=>",
"amazon_authorization_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns the status of a particular authorization and the total amount
captured on the authorization
@see https://pay.amazon.com/documentation/apireference/201751630#201752030
@param amazon_authorization_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"the",
"status",
"of",
"a",
"particular",
"authorization",
"and",
"the",
"total",
"amount",
"captured",
"on",
"the",
"authorization"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L766-L783
|
18,038
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.capture
|
def capture(
amazon_authorization_id,
capture_reference_id,
amount,
currency_code: @currency_code,
seller_capture_note: nil,
soft_descriptor: nil,
provider_credit_details: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'Capture',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id,
'CaptureReferenceId' => capture_reference_id,
'CaptureAmount.Amount' => amount,
'CaptureAmount.CurrencyCode' => currency_code
}
optional = {
'SellerCaptureNote' => seller_capture_note,
'SoftDescriptor' => soft_descriptor,
'MWSAuthToken' => mws_auth_token
}
optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details
operation(parameters, optional)
end
|
ruby
|
def capture(
amazon_authorization_id,
capture_reference_id,
amount,
currency_code: @currency_code,
seller_capture_note: nil,
soft_descriptor: nil,
provider_credit_details: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'Capture',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id,
'CaptureReferenceId' => capture_reference_id,
'CaptureAmount.Amount' => amount,
'CaptureAmount.CurrencyCode' => currency_code
}
optional = {
'SellerCaptureNote' => seller_capture_note,
'SoftDescriptor' => soft_descriptor,
'MWSAuthToken' => mws_auth_token
}
optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details
operation(parameters, optional)
end
|
[
"def",
"capture",
"(",
"amazon_authorization_id",
",",
"capture_reference_id",
",",
"amount",
",",
"currency_code",
":",
"@currency_code",
",",
"seller_capture_note",
":",
"nil",
",",
"soft_descriptor",
":",
"nil",
",",
"provider_credit_details",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'Capture'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonAuthorizationId'",
"=>",
"amazon_authorization_id",
",",
"'CaptureReferenceId'",
"=>",
"capture_reference_id",
",",
"'CaptureAmount.Amount'",
"=>",
"amount",
",",
"'CaptureAmount.CurrencyCode'",
"=>",
"currency_code",
"}",
"optional",
"=",
"{",
"'SellerCaptureNote'",
"=>",
"seller_capture_note",
",",
"'SoftDescriptor'",
"=>",
"soft_descriptor",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"optional",
".",
"merge!",
"(",
"set_provider_credit_details",
"(",
"provider_credit_details",
")",
")",
"if",
"provider_credit_details",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Captures funds from an authorized payment instrument.
@see https://pay.amazon.com/documentation/apireference/201751630#201752040
@param amazon_authorization_id [String]
@param capture_reference_id [String]
@param amount [String]
@optional currency_code [String]
@optional seller_capture_note [String]
@optional soft_descriptor [String]
@optional provider_credit_details [Array of Hash]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Captures",
"funds",
"from",
"an",
"authorized",
"payment",
"instrument",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L796-L826
|
18,039
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_capture_details
|
def get_capture_details(
amazon_capture_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetCaptureDetails',
'SellerId' => merchant_id,
'AmazonCaptureId' => amazon_capture_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_capture_details(
amazon_capture_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetCaptureDetails',
'SellerId' => merchant_id,
'AmazonCaptureId' => amazon_capture_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_capture_details",
"(",
"amazon_capture_id",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetCaptureDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonCaptureId'",
"=>",
"amazon_capture_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns the status of a particular capture and the total amount refunded
on the capture
@see https://pay.amazon.com/documentation/apireference/201751630#201752060
@param amazon_capture_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"the",
"status",
"of",
"a",
"particular",
"capture",
"and",
"the",
"total",
"amount",
"refunded",
"on",
"the",
"capture"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L834-L851
|
18,040
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.refund
|
def refund(
amazon_capture_id,
refund_reference_id,
amount,
currency_code: @currency_code,
seller_refund_note: nil,
soft_descriptor: nil,
provider_credit_reversal_details: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'Refund',
'SellerId' => merchant_id,
'AmazonCaptureId' => amazon_capture_id,
'RefundReferenceId' => refund_reference_id,
'RefundAmount.Amount' => amount,
'RefundAmount.CurrencyCode' => currency_code
}
optional = {
'SellerRefundNote' => seller_refund_note,
'SoftDescriptor' => soft_descriptor,
'MWSAuthToken' => mws_auth_token
}
optional.merge!(set_provider_credit_reversal_details(provider_credit_reversal_details)) if provider_credit_reversal_details
operation(parameters, optional)
end
|
ruby
|
def refund(
amazon_capture_id,
refund_reference_id,
amount,
currency_code: @currency_code,
seller_refund_note: nil,
soft_descriptor: nil,
provider_credit_reversal_details: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'Refund',
'SellerId' => merchant_id,
'AmazonCaptureId' => amazon_capture_id,
'RefundReferenceId' => refund_reference_id,
'RefundAmount.Amount' => amount,
'RefundAmount.CurrencyCode' => currency_code
}
optional = {
'SellerRefundNote' => seller_refund_note,
'SoftDescriptor' => soft_descriptor,
'MWSAuthToken' => mws_auth_token
}
optional.merge!(set_provider_credit_reversal_details(provider_credit_reversal_details)) if provider_credit_reversal_details
operation(parameters, optional)
end
|
[
"def",
"refund",
"(",
"amazon_capture_id",
",",
"refund_reference_id",
",",
"amount",
",",
"currency_code",
":",
"@currency_code",
",",
"seller_refund_note",
":",
"nil",
",",
"soft_descriptor",
":",
"nil",
",",
"provider_credit_reversal_details",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'Refund'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonCaptureId'",
"=>",
"amazon_capture_id",
",",
"'RefundReferenceId'",
"=>",
"refund_reference_id",
",",
"'RefundAmount.Amount'",
"=>",
"amount",
",",
"'RefundAmount.CurrencyCode'",
"=>",
"currency_code",
"}",
"optional",
"=",
"{",
"'SellerRefundNote'",
"=>",
"seller_refund_note",
",",
"'SoftDescriptor'",
"=>",
"soft_descriptor",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"optional",
".",
"merge!",
"(",
"set_provider_credit_reversal_details",
"(",
"provider_credit_reversal_details",
")",
")",
"if",
"provider_credit_reversal_details",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Refunds a previously captured amount
@see https://pay.amazon.com/documentation/apireference/201751630#201752080
@param amazon_capture_id [String]
@param refund_reference_id [String]
@param amount [String]
@optional currency_code [String]
@optional seller_refund_note [String]
@optional soft_descriptor [String]
@optional provider_credit_reversal_details [Array of Hash]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Refunds",
"a",
"previously",
"captured",
"amount"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L864-L894
|
18,041
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.get_refund_details
|
def get_refund_details(
amazon_refund_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetRefundDetails',
'SellerId' => merchant_id,
'AmazonRefundId' => amazon_refund_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def get_refund_details(
amazon_refund_id,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'GetRefundDetails',
'SellerId' => merchant_id,
'AmazonRefundId' => amazon_refund_id
}
optional = {
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"get_refund_details",
"(",
"amazon_refund_id",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'GetRefundDetails'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonRefundId'",
"=>",
"amazon_refund_id",
"}",
"optional",
"=",
"{",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Returns the status of a particular refund
@see https://pay.amazon.com/documentation/apireference/201751630#201752100
@param amazon_refund_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Returns",
"the",
"status",
"of",
"a",
"particular",
"refund"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L901-L918
|
18,042
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.close_authorization
|
def close_authorization(
amazon_authorization_id,
closure_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CloseAuthorization',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id
}
optional = {
'ClosureReason' => closure_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
ruby
|
def close_authorization(
amazon_authorization_id,
closure_reason: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
parameters = {
'Action' => 'CloseAuthorization',
'SellerId' => merchant_id,
'AmazonAuthorizationId' => amazon_authorization_id
}
optional = {
'ClosureReason' => closure_reason,
'MWSAuthToken' => mws_auth_token
}
operation(parameters, optional)
end
|
[
"def",
"close_authorization",
"(",
"amazon_authorization_id",
",",
"closure_reason",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"parameters",
"=",
"{",
"'Action'",
"=>",
"'CloseAuthorization'",
",",
"'SellerId'",
"=>",
"merchant_id",
",",
"'AmazonAuthorizationId'",
"=>",
"amazon_authorization_id",
"}",
"optional",
"=",
"{",
"'ClosureReason'",
"=>",
"closure_reason",
",",
"'MWSAuthToken'",
"=>",
"mws_auth_token",
"}",
"operation",
"(",
"parameters",
",",
"optional",
")",
"end"
] |
Closes an authorization
@see https://pay.amazon.com/documentation/apireference/201751630#201752070
@param amazon_authorization_id [String]
@optional closure_reason [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"Closes",
"an",
"authorization"
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L926-L945
|
18,043
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.set_provider_credit_details
|
def set_provider_credit_details(provider_credit_details)
member_details = {}
provider_credit_details.each_with_index do |val, index|
member = index + 1
member_details["ProviderCreditList.member.#{member}.ProviderId"] = val[:provider_id]
member_details["ProviderCreditList.member.#{member}.CreditAmount.Amount"] = val[:amount]
member_details["ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode"] = val[:currency_code]
end
member_details
end
|
ruby
|
def set_provider_credit_details(provider_credit_details)
member_details = {}
provider_credit_details.each_with_index do |val, index|
member = index + 1
member_details["ProviderCreditList.member.#{member}.ProviderId"] = val[:provider_id]
member_details["ProviderCreditList.member.#{member}.CreditAmount.Amount"] = val[:amount]
member_details["ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode"] = val[:currency_code]
end
member_details
end
|
[
"def",
"set_provider_credit_details",
"(",
"provider_credit_details",
")",
"member_details",
"=",
"{",
"}",
"provider_credit_details",
".",
"each_with_index",
"do",
"|",
"val",
",",
"index",
"|",
"member",
"=",
"index",
"+",
"1",
"member_details",
"[",
"\"ProviderCreditList.member.#{member}.ProviderId\"",
"]",
"=",
"val",
"[",
":provider_id",
"]",
"member_details",
"[",
"\"ProviderCreditList.member.#{member}.CreditAmount.Amount\"",
"]",
"=",
"val",
"[",
":amount",
"]",
"member_details",
"[",
"\"ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode\"",
"]",
"=",
"val",
"[",
":currency_code",
"]",
"end",
"member_details",
"end"
] |
This method builds the provider credit details hash
that will be combined with either the authorize or capture
API call.
|
[
"This",
"method",
"builds",
"the",
"provider",
"credit",
"details",
"hash",
"that",
"will",
"be",
"combined",
"with",
"either",
"the",
"authorize",
"or",
"capture",
"API",
"call",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L1081-L1091
|
18,044
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client.rb
|
AmazonPay.Client.set_provider_credit_reversal_details
|
def set_provider_credit_reversal_details(provider_credit_reversal_details)
member_details = {}
provider_credit_reversal_details.each_with_index do |val, index|
member = index + 1
member_details["ProviderCreditReversalList.member.#{member}.ProviderId"] = val[:provider_id]
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount"] = val[:amount]
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode"] = val[:currency_code]
end
member_details
end
|
ruby
|
def set_provider_credit_reversal_details(provider_credit_reversal_details)
member_details = {}
provider_credit_reversal_details.each_with_index do |val, index|
member = index + 1
member_details["ProviderCreditReversalList.member.#{member}.ProviderId"] = val[:provider_id]
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount"] = val[:amount]
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode"] = val[:currency_code]
end
member_details
end
|
[
"def",
"set_provider_credit_reversal_details",
"(",
"provider_credit_reversal_details",
")",
"member_details",
"=",
"{",
"}",
"provider_credit_reversal_details",
".",
"each_with_index",
"do",
"|",
"val",
",",
"index",
"|",
"member",
"=",
"index",
"+",
"1",
"member_details",
"[",
"\"ProviderCreditReversalList.member.#{member}.ProviderId\"",
"]",
"=",
"val",
"[",
":provider_id",
"]",
"member_details",
"[",
"\"ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount\"",
"]",
"=",
"val",
"[",
":amount",
"]",
"member_details",
"[",
"\"ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode\"",
"]",
"=",
"val",
"[",
":currency_code",
"]",
"end",
"member_details",
"end"
] |
This method builds the provider credit reversal
details hash that will be combined with the refund
API call.
|
[
"This",
"method",
"builds",
"the",
"provider",
"credit",
"reversal",
"details",
"hash",
"that",
"will",
"be",
"combined",
"with",
"the",
"refund",
"API",
"call",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client.rb#L1096-L1106
|
18,045
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/request.rb
|
AmazonPay.Request.build_post_url
|
def build_post_url
@optional.map { |k, v| @parameters[k] = v unless v.nil? }
@parameters['Timestamp'] = Time.now.utc.iso8601 unless @parameters.key?('Timestamp')
@parameters = @default_hash.merge(@parameters)
post_url = @parameters.sort.map { |k, v| "#{k}=#{custom_escape(v)}" }.join('&')
post_body = ['POST', @mws_endpoint.to_s, "/#{@sandbox_str}/#{AmazonPay::API_VERSION}", post_url].join("\n")
post_url += '&Signature=' + sign(post_body)
if @log_enabled
data = AmazonPay::Sanitize.new(post_url)
@logger.debug("request/Post: #{data.sanitize_request_data}")
end
post_url
end
|
ruby
|
def build_post_url
@optional.map { |k, v| @parameters[k] = v unless v.nil? }
@parameters['Timestamp'] = Time.now.utc.iso8601 unless @parameters.key?('Timestamp')
@parameters = @default_hash.merge(@parameters)
post_url = @parameters.sort.map { |k, v| "#{k}=#{custom_escape(v)}" }.join('&')
post_body = ['POST', @mws_endpoint.to_s, "/#{@sandbox_str}/#{AmazonPay::API_VERSION}", post_url].join("\n")
post_url += '&Signature=' + sign(post_body)
if @log_enabled
data = AmazonPay::Sanitize.new(post_url)
@logger.debug("request/Post: #{data.sanitize_request_data}")
end
post_url
end
|
[
"def",
"build_post_url",
"@optional",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"@parameters",
"[",
"k",
"]",
"=",
"v",
"unless",
"v",
".",
"nil?",
"}",
"@parameters",
"[",
"'Timestamp'",
"]",
"=",
"Time",
".",
"now",
".",
"utc",
".",
"iso8601",
"unless",
"@parameters",
".",
"key?",
"(",
"'Timestamp'",
")",
"@parameters",
"=",
"@default_hash",
".",
"merge",
"(",
"@parameters",
")",
"post_url",
"=",
"@parameters",
".",
"sort",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}=#{custom_escape(v)}\"",
"}",
".",
"join",
"(",
"'&'",
")",
"post_body",
"=",
"[",
"'POST'",
",",
"@mws_endpoint",
".",
"to_s",
",",
"\"/#{@sandbox_str}/#{AmazonPay::API_VERSION}\"",
",",
"post_url",
"]",
".",
"join",
"(",
"\"\\n\"",
")",
"post_url",
"+=",
"'&Signature='",
"+",
"sign",
"(",
"post_body",
")",
"if",
"@log_enabled",
"data",
"=",
"AmazonPay",
"::",
"Sanitize",
".",
"new",
"(",
"post_url",
")",
"@logger",
".",
"debug",
"(",
"\"request/Post: #{data.sanitize_request_data}\"",
")",
"end",
"post_url",
"end"
] |
This method combines the required and optional
parameters to sign the post body and generate
the post url.
|
[
"This",
"method",
"combines",
"the",
"required",
"and",
"optional",
"parameters",
"to",
"sign",
"the",
"post",
"body",
"and",
"generate",
"the",
"post",
"url",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/request.rb#L65-L78
|
18,046
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/request.rb
|
AmazonPay.Request.sign
|
def sign(post_body)
custom_escape(Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, @secret_key, post_body)))
end
|
ruby
|
def sign(post_body)
custom_escape(Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, @secret_key, post_body)))
end
|
[
"def",
"sign",
"(",
"post_body",
")",
"custom_escape",
"(",
"Base64",
".",
"strict_encode64",
"(",
"OpenSSL",
"::",
"HMAC",
".",
"digest",
"(",
"OpenSSL",
"::",
"Digest",
"::",
"SHA256",
".",
"new",
",",
"@secret_key",
",",
"post_body",
")",
")",
")",
"end"
] |
This method signs the post body that is being sent
using the secret key provided.
|
[
"This",
"method",
"signs",
"the",
"post",
"body",
"that",
"is",
"being",
"sent",
"using",
"the",
"secret",
"key",
"provided",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/request.rb#L82-L84
|
18,047
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/request.rb
|
AmazonPay.Request.post
|
def post(mws_endpoint, sandbox_str, post_url)
uri = URI("https://#{mws_endpoint}/#{sandbox_str}/#{AmazonPay::API_VERSION}")
https = Net::HTTP.new(uri.host, uri.port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
user_agent = { 'User-Agent' => "#{AmazonPay::SDK_NAME}/#{AmazonPay::VERSION}; (#{@application_name + '/' if @application_name}#{@application_version.to_s + ';' if @application_version} #{RUBY_VERSION}; #{RUBY_PLATFORM})" }
tries = 0
begin
response = https.post(uri.path, post_url, user_agent)
if @log_enabled
data = AmazonPay::Sanitize.new(response.body)
@logger.debug("response: #{data.sanitize_response_data}")
end
if @throttle.eql?(true)
raise 'InternalServerError' if response.code.eql?('500')
raise 'ServiceUnavailable or RequestThrottled' if response.code.eql?('503')
end
AmazonPay::Response.new(response)
rescue StandardError => error
tries += 1
sleep(get_seconds_for_try_count(tries))
retry if tries <= MAX_RETRIES
raise error.message
end
end
|
ruby
|
def post(mws_endpoint, sandbox_str, post_url)
uri = URI("https://#{mws_endpoint}/#{sandbox_str}/#{AmazonPay::API_VERSION}")
https = Net::HTTP.new(uri.host, uri.port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
user_agent = { 'User-Agent' => "#{AmazonPay::SDK_NAME}/#{AmazonPay::VERSION}; (#{@application_name + '/' if @application_name}#{@application_version.to_s + ';' if @application_version} #{RUBY_VERSION}; #{RUBY_PLATFORM})" }
tries = 0
begin
response = https.post(uri.path, post_url, user_agent)
if @log_enabled
data = AmazonPay::Sanitize.new(response.body)
@logger.debug("response: #{data.sanitize_response_data}")
end
if @throttle.eql?(true)
raise 'InternalServerError' if response.code.eql?('500')
raise 'ServiceUnavailable or RequestThrottled' if response.code.eql?('503')
end
AmazonPay::Response.new(response)
rescue StandardError => error
tries += 1
sleep(get_seconds_for_try_count(tries))
retry if tries <= MAX_RETRIES
raise error.message
end
end
|
[
"def",
"post",
"(",
"mws_endpoint",
",",
"sandbox_str",
",",
"post_url",
")",
"uri",
"=",
"URI",
"(",
"\"https://#{mws_endpoint}/#{sandbox_str}/#{AmazonPay::API_VERSION}\"",
")",
"https",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
",",
"@proxy_addr",
",",
"@proxy_port",
",",
"@proxy_user",
",",
"@proxy_pass",
")",
"https",
".",
"use_ssl",
"=",
"true",
"https",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_PEER",
"user_agent",
"=",
"{",
"'User-Agent'",
"=>",
"\"#{AmazonPay::SDK_NAME}/#{AmazonPay::VERSION}; (#{@application_name + '/' if @application_name}#{@application_version.to_s + ';' if @application_version} #{RUBY_VERSION}; #{RUBY_PLATFORM})\"",
"}",
"tries",
"=",
"0",
"begin",
"response",
"=",
"https",
".",
"post",
"(",
"uri",
".",
"path",
",",
"post_url",
",",
"user_agent",
")",
"if",
"@log_enabled",
"data",
"=",
"AmazonPay",
"::",
"Sanitize",
".",
"new",
"(",
"response",
".",
"body",
")",
"@logger",
".",
"debug",
"(",
"\"response: #{data.sanitize_response_data}\"",
")",
"end",
"if",
"@throttle",
".",
"eql?",
"(",
"true",
")",
"raise",
"'InternalServerError'",
"if",
"response",
".",
"code",
".",
"eql?",
"(",
"'500'",
")",
"raise",
"'ServiceUnavailable or RequestThrottled'",
"if",
"response",
".",
"code",
".",
"eql?",
"(",
"'503'",
")",
"end",
"AmazonPay",
"::",
"Response",
".",
"new",
"(",
"response",
")",
"rescue",
"StandardError",
"=>",
"error",
"tries",
"+=",
"1",
"sleep",
"(",
"get_seconds_for_try_count",
"(",
"tries",
")",
")",
"retry",
"if",
"tries",
"<=",
"MAX_RETRIES",
"raise",
"error",
".",
"message",
"end",
"end"
] |
This method performs the post to the MWS endpoint.
It will retry three times after the initial post if
the status code comes back as either 500 or 503.
|
[
"This",
"method",
"performs",
"the",
"post",
"to",
"the",
"MWS",
"endpoint",
".",
"It",
"will",
"retry",
"three",
"times",
"after",
"the",
"initial",
"post",
"if",
"the",
"status",
"code",
"comes",
"back",
"as",
"either",
"500",
"or",
"503",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/request.rb#L89-L115
|
18,048
|
amzn/amazon-pay-sdk-ruby
|
lib/amazon_pay/client_helper.rb
|
AmazonPay.Client.charge
|
def charge(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code: @currency_code,
charge_note: nil,
charge_order_id: nil,
store_name: nil,
custom_information: nil,
soft_descriptor: nil,
platform_id: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
if order_reference?(amazon_reference_id)
call_order_reference_api(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code,
charge_note,
charge_order_id,
store_name,
custom_information,
soft_descriptor,
platform_id,
merchant_id,
mws_auth_token
)
elsif billing_agreement?(amazon_reference_id)
call_billing_agreement_api(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code,
charge_note,
charge_order_id,
store_name,
custom_information,
soft_descriptor,
platform_id,
merchant_id,
mws_auth_token
)
end
end
|
ruby
|
def charge(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code: @currency_code,
charge_note: nil,
charge_order_id: nil,
store_name: nil,
custom_information: nil,
soft_descriptor: nil,
platform_id: nil,
merchant_id: @merchant_id,
mws_auth_token: nil
)
if order_reference?(amazon_reference_id)
call_order_reference_api(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code,
charge_note,
charge_order_id,
store_name,
custom_information,
soft_descriptor,
platform_id,
merchant_id,
mws_auth_token
)
elsif billing_agreement?(amazon_reference_id)
call_billing_agreement_api(
amazon_reference_id,
authorization_reference_id,
charge_amount,
charge_currency_code,
charge_note,
charge_order_id,
store_name,
custom_information,
soft_descriptor,
platform_id,
merchant_id,
mws_auth_token
)
end
end
|
[
"def",
"charge",
"(",
"amazon_reference_id",
",",
"authorization_reference_id",
",",
"charge_amount",
",",
"charge_currency_code",
":",
"@currency_code",
",",
"charge_note",
":",
"nil",
",",
"charge_order_id",
":",
"nil",
",",
"store_name",
":",
"nil",
",",
"custom_information",
":",
"nil",
",",
"soft_descriptor",
":",
"nil",
",",
"platform_id",
":",
"nil",
",",
"merchant_id",
":",
"@merchant_id",
",",
"mws_auth_token",
":",
"nil",
")",
"if",
"order_reference?",
"(",
"amazon_reference_id",
")",
"call_order_reference_api",
"(",
"amazon_reference_id",
",",
"authorization_reference_id",
",",
"charge_amount",
",",
"charge_currency_code",
",",
"charge_note",
",",
"charge_order_id",
",",
"store_name",
",",
"custom_information",
",",
"soft_descriptor",
",",
"platform_id",
",",
"merchant_id",
",",
"mws_auth_token",
")",
"elsif",
"billing_agreement?",
"(",
"amazon_reference_id",
")",
"call_billing_agreement_api",
"(",
"amazon_reference_id",
",",
"authorization_reference_id",
",",
"charge_amount",
",",
"charge_currency_code",
",",
"charge_note",
",",
"charge_order_id",
",",
"store_name",
",",
"custom_information",
",",
"soft_descriptor",
",",
"platform_id",
",",
"merchant_id",
",",
"mws_auth_token",
")",
"end",
"end"
] |
This method combines multiple API calls to perform
a complete transaction with minimum requirements.
@param amazon_reference_id [String]
@param authorization_reference_id [String]
@param charge_amount [String]
@optional charge_currency_code [String]
@optional charge_note [String]
@optional charge_order [String]
@optional store_name [String]
@optional custom_information [String]
@optional soft_descriptor [String]
@optional platform_id [String]
@optional merchant_id [String]
@optional mws_auth_token [String]
|
[
"This",
"method",
"combines",
"multiple",
"API",
"calls",
"to",
"perform",
"a",
"complete",
"transaction",
"with",
"minimum",
"requirements",
"."
] |
6321994cc10b5614630b6743da8d1eb79b2bc1ed
|
https://github.com/amzn/amazon-pay-sdk-ruby/blob/6321994cc10b5614630b6743da8d1eb79b2bc1ed/lib/amazon_pay/client_helper.rb#L21-L67
|
18,049
|
AlexWayfer/flame
|
lib/flame/router.rb
|
Flame.Router.add
|
def add(routes_refine)
routes.deep_merge! routes_refine.routes
reverse_routes.merge! routes_refine.reverse_routes
end
|
ruby
|
def add(routes_refine)
routes.deep_merge! routes_refine.routes
reverse_routes.merge! routes_refine.reverse_routes
end
|
[
"def",
"add",
"(",
"routes_refine",
")",
"routes",
".",
"deep_merge!",
"routes_refine",
".",
"routes",
"reverse_routes",
".",
"merge!",
"routes_refine",
".",
"reverse_routes",
"end"
] |
Add RoutesRefine to Router
@param routes_refine [Flame::Router::RoutesRefine] refined routes
|
[
"Add",
"RoutesRefine",
"to",
"Router"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/router.rb#L36-L39
|
18,050
|
AlexWayfer/flame
|
lib/flame/router.rb
|
Flame.Router.find_nearest_route
|
def find_nearest_route(path)
path_parts = path.parts.dup
loop do
route = routes.navigate(*path_parts)&.values&.grep(Route)&.first
break route if route || path_parts.pop.nil?
end
end
|
ruby
|
def find_nearest_route(path)
path_parts = path.parts.dup
loop do
route = routes.navigate(*path_parts)&.values&.grep(Route)&.first
break route if route || path_parts.pop.nil?
end
end
|
[
"def",
"find_nearest_route",
"(",
"path",
")",
"path_parts",
"=",
"path",
".",
"parts",
".",
"dup",
"loop",
"do",
"route",
"=",
"routes",
".",
"navigate",
"(",
"path_parts",
")",
"&.",
"values",
"&.",
"grep",
"(",
"Route",
")",
"&.",
"first",
"break",
"route",
"if",
"route",
"||",
"path_parts",
".",
"pop",
".",
"nil?",
"end",
"end"
] |
Find the nearest route by path
@param path [Flame::Path] path for route finding
@return [Flame::Route, nil] return the found nearest route or `nil`
|
[
"Find",
"the",
"nearest",
"route",
"by",
"path"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/router.rb#L44-L50
|
18,051
|
AlexWayfer/flame
|
lib/flame/router.rb
|
Flame.Router.path_of
|
def path_of(route_or_controller, action = nil)
if route_or_controller.is_a?(Flame::Router::Route)
route = route_or_controller
controller = route.controller
action = route.action
else
controller = route_or_controller
end
reverse_routes.dig(controller.to_s, action)
end
|
ruby
|
def path_of(route_or_controller, action = nil)
if route_or_controller.is_a?(Flame::Router::Route)
route = route_or_controller
controller = route.controller
action = route.action
else
controller = route_or_controller
end
reverse_routes.dig(controller.to_s, action)
end
|
[
"def",
"path_of",
"(",
"route_or_controller",
",",
"action",
"=",
"nil",
")",
"if",
"route_or_controller",
".",
"is_a?",
"(",
"Flame",
"::",
"Router",
"::",
"Route",
")",
"route",
"=",
"route_or_controller",
"controller",
"=",
"route",
".",
"controller",
"action",
"=",
"route",
".",
"action",
"else",
"controller",
"=",
"route_or_controller",
"end",
"reverse_routes",
".",
"dig",
"(",
"controller",
".",
"to_s",
",",
"action",
")",
"end"
] |
Find the path of route
@param route_or_controller [Flame::Router::Route, Flame::Controller]
route or controller
@param action [Symbol, nil] action (or not for route)
@return [Flame::Path] mounted path to action of controller
|
[
"Find",
"the",
"path",
"of",
"route"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/router.rb#L57-L66
|
18,052
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.render
|
def render(cache: true, &block)
@cache = cache
## Compile Tilt to instance hash
return unless @filename
tilt = compile_file
## Render Tilt from instance hash with new options
layout_render tilt.render(@scope, @locals, &block)
end
|
ruby
|
def render(cache: true, &block)
@cache = cache
## Compile Tilt to instance hash
return unless @filename
tilt = compile_file
## Render Tilt from instance hash with new options
layout_render tilt.render(@scope, @locals, &block)
end
|
[
"def",
"render",
"(",
"cache",
":",
"true",
",",
"&",
"block",
")",
"@cache",
"=",
"cache",
"## Compile Tilt to instance hash",
"return",
"unless",
"@filename",
"tilt",
"=",
"compile_file",
"## Render Tilt from instance hash with new options",
"layout_render",
"tilt",
".",
"render",
"(",
"@scope",
",",
"@locals",
",",
"block",
")",
"end"
] |
Create a new instance from controller, by path and with options
@param controller [Flame::Controller]
controller for default scope, views directory and cache
@param path [Symbol, String] path (full or the last part) for view search
@param options [Hash] options for template
@option options [Object] :scope (controller)
scope of visibility in rendering
@option options [Symbol, String, false] :layout ('layout.*')
name of the layout file
@option options [Hash] :tilt options for Tilt
@option options [Hash] :locals ({}) local variables for rendering
Render template with layout
@param cache [Boolean] cache compiles or not
@return [String] compiled template
|
[
"Create",
"a",
"new",
"instance",
"from",
"controller",
"by",
"path",
"and",
"with",
"options"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L51-L59
|
18,053
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.compile_file
|
def compile_file(filename = @filename)
cached = @controller.cached_tilts[filename]
return cached if @cache && cached
compiled = Tilt.new(filename, nil, @tilt_options)
@controller.cached_tilts[filename] ||= compiled if @cache
compiled
end
|
ruby
|
def compile_file(filename = @filename)
cached = @controller.cached_tilts[filename]
return cached if @cache && cached
compiled = Tilt.new(filename, nil, @tilt_options)
@controller.cached_tilts[filename] ||= compiled if @cache
compiled
end
|
[
"def",
"compile_file",
"(",
"filename",
"=",
"@filename",
")",
"cached",
"=",
"@controller",
".",
"cached_tilts",
"[",
"filename",
"]",
"return",
"cached",
"if",
"@cache",
"&&",
"cached",
"compiled",
"=",
"Tilt",
".",
"new",
"(",
"filename",
",",
"nil",
",",
"@tilt_options",
")",
"@controller",
".",
"cached_tilts",
"[",
"filename",
"]",
"||=",
"compiled",
"if",
"@cache",
"compiled",
"end"
] |
Compile file with Tilt engine
@param filename [String] filename
|
[
"Compile",
"file",
"with",
"Tilt",
"engine"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L69-L76
|
18,054
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.find_file
|
def find_file(path)
caller_path = caller_locations(4..4).first.path
caller_dir =
begin
File.dirname(caller_path).sub(views_dir, '') if Tilt[caller_path]
rescue LoadError
nil
end
find_files(path, controller_dirs | Array(caller_dir))
.find { |file| Tilt[file] }
end
|
ruby
|
def find_file(path)
caller_path = caller_locations(4..4).first.path
caller_dir =
begin
File.dirname(caller_path).sub(views_dir, '') if Tilt[caller_path]
rescue LoadError
nil
end
find_files(path, controller_dirs | Array(caller_dir))
.find { |file| Tilt[file] }
end
|
[
"def",
"find_file",
"(",
"path",
")",
"caller_path",
"=",
"caller_locations",
"(",
"4",
"..",
"4",
")",
".",
"first",
".",
"path",
"caller_dir",
"=",
"begin",
"File",
".",
"dirname",
"(",
"caller_path",
")",
".",
"sub",
"(",
"views_dir",
",",
"''",
")",
"if",
"Tilt",
"[",
"caller_path",
"]",
"rescue",
"LoadError",
"nil",
"end",
"find_files",
"(",
"path",
",",
"controller_dirs",
"|",
"Array",
"(",
"caller_dir",
")",
")",
".",
"find",
"{",
"|",
"file",
"|",
"Tilt",
"[",
"file",
"]",
"}",
"end"
] |
Find template-file by path
|
[
"Find",
"template",
"-",
"file",
"by",
"path"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L97-L109
|
18,055
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.find_layouts
|
def find_layouts(path)
find_files(path, layout_dirs)
.select { |file| Tilt[file] }
.sort! { |a, b| b.split('/').size <=> a.split('/').size }
end
|
ruby
|
def find_layouts(path)
find_files(path, layout_dirs)
.select { |file| Tilt[file] }
.sort! { |a, b| b.split('/').size <=> a.split('/').size }
end
|
[
"def",
"find_layouts",
"(",
"path",
")",
"find_files",
"(",
"path",
",",
"layout_dirs",
")",
".",
"select",
"{",
"|",
"file",
"|",
"Tilt",
"[",
"file",
"]",
"}",
".",
"sort!",
"{",
"|",
"a",
",",
"b",
"|",
"b",
".",
"split",
"(",
"'/'",
")",
".",
"size",
"<=>",
"a",
".",
"split",
"(",
"'/'",
")",
".",
"size",
"}",
"end"
] |
Find layout-files by path
|
[
"Find",
"layout",
"-",
"files",
"by",
"path"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L112-L116
|
18,056
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.controller_dirs
|
def controller_dirs
parts = @controller.class.underscore.split('/').map do |part|
%w[_controller _ctrl]
.find { |suffix| part.chomp! suffix }
part
## Alternative, but slower by ~50%:
# part.sub(/_(controller|ctrl)$/, '')
end
combine_parts(parts).map! { |path| path.join('/') }
end
|
ruby
|
def controller_dirs
parts = @controller.class.underscore.split('/').map do |part|
%w[_controller _ctrl]
.find { |suffix| part.chomp! suffix }
part
## Alternative, but slower by ~50%:
# part.sub(/_(controller|ctrl)$/, '')
end
combine_parts(parts).map! { |path| path.join('/') }
end
|
[
"def",
"controller_dirs",
"parts",
"=",
"@controller",
".",
"class",
".",
"underscore",
".",
"split",
"(",
"'/'",
")",
".",
"map",
"do",
"|",
"part",
"|",
"%w[",
"_controller",
"_ctrl",
"]",
".",
"find",
"{",
"|",
"suffix",
"|",
"part",
".",
"chomp!",
"suffix",
"}",
"part",
"## Alternative, but slower by ~50%:",
"# part.sub(/_(controller|ctrl)$/, '')",
"end",
"combine_parts",
"(",
"parts",
")",
".",
"map!",
"{",
"|",
"path",
"|",
"path",
".",
"join",
"(",
"'/'",
")",
"}",
"end"
] |
Find possible directories for the controller
|
[
"Find",
"possible",
"directories",
"for",
"the",
"controller"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L121-L130
|
18,057
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.combine_parts
|
def combine_parts(parts)
parts.size.downto(1).with_object([]) do |i, arr|
arr.push(*parts.combination(i).to_a)
end
# variants.uniq!.reject!(&:empty?)
end
|
ruby
|
def combine_parts(parts)
parts.size.downto(1).with_object([]) do |i, arr|
arr.push(*parts.combination(i).to_a)
end
# variants.uniq!.reject!(&:empty?)
end
|
[
"def",
"combine_parts",
"(",
"parts",
")",
"parts",
".",
"size",
".",
"downto",
"(",
"1",
")",
".",
"with_object",
"(",
"[",
"]",
")",
"do",
"|",
"i",
",",
"arr",
"|",
"arr",
".",
"push",
"(",
"parts",
".",
"combination",
"(",
"i",
")",
".",
"to_a",
")",
"end",
"# variants.uniq!.reject!(&:empty?)",
"end"
] |
Make combinations in order with different sizes
@example Make parts for ['project', 'namespace', 'controller']
# => [
['project', 'namespace', 'controller'],
['project', 'namespace'],
['namespace', 'controller'],
['namespace']
]
|
[
"Make",
"combinations",
"in",
"order",
"with",
"different",
"sizes"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L140-L145
|
18,058
|
AlexWayfer/flame
|
lib/flame/render.rb
|
Flame.Render.layout_render
|
def layout_render(content)
return content unless @layout
layout_files = find_layouts(@layout)
return content if layout_files.empty?
layout_files.each_with_object(content.dup) do |layout_file, result|
layout = compile_file(layout_file)
result.replace layout.render(@scope, @locals) { result }
end
end
|
ruby
|
def layout_render(content)
return content unless @layout
layout_files = find_layouts(@layout)
return content if layout_files.empty?
layout_files.each_with_object(content.dup) do |layout_file, result|
layout = compile_file(layout_file)
result.replace layout.render(@scope, @locals) { result }
end
end
|
[
"def",
"layout_render",
"(",
"content",
")",
"return",
"content",
"unless",
"@layout",
"layout_files",
"=",
"find_layouts",
"(",
"@layout",
")",
"return",
"content",
"if",
"layout_files",
".",
"empty?",
"layout_files",
".",
"each_with_object",
"(",
"content",
".",
"dup",
")",
"do",
"|",
"layout_file",
",",
"result",
"|",
"layout",
"=",
"compile_file",
"(",
"layout_file",
")",
"result",
".",
"replace",
"layout",
".",
"render",
"(",
"@scope",
",",
"@locals",
")",
"{",
"result",
"}",
"end",
"end"
] |
Render the layout with template
@param result [String] result of template rendering
|
[
"Render",
"the",
"layout",
"with",
"template"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/render.rb#L158-L168
|
18,059
|
AlexWayfer/flame
|
lib/flame/path.rb
|
Flame.Path.adapt
|
def adapt(ctrl, action)
parameters = ctrl.instance_method(action).parameters
parameters.map! do |parameter|
parameter_type, parameter_name = parameter
path_part = self.class::Part.new parameter_name, arg: parameter_type
path_part unless parts.include? path_part
end
self.class.new @path.empty? ? "/#{action}" : self, *parameters.compact
end
|
ruby
|
def adapt(ctrl, action)
parameters = ctrl.instance_method(action).parameters
parameters.map! do |parameter|
parameter_type, parameter_name = parameter
path_part = self.class::Part.new parameter_name, arg: parameter_type
path_part unless parts.include? path_part
end
self.class.new @path.empty? ? "/#{action}" : self, *parameters.compact
end
|
[
"def",
"adapt",
"(",
"ctrl",
",",
"action",
")",
"parameters",
"=",
"ctrl",
".",
"instance_method",
"(",
"action",
")",
".",
"parameters",
"parameters",
".",
"map!",
"do",
"|",
"parameter",
"|",
"parameter_type",
",",
"parameter_name",
"=",
"parameter",
"path_part",
"=",
"self",
".",
"class",
"::",
"Part",
".",
"new",
"parameter_name",
",",
"arg",
":",
"parameter_type",
"path_part",
"unless",
"parts",
".",
"include?",
"path_part",
"end",
"self",
".",
"class",
".",
"new",
"@path",
".",
"empty?",
"?",
"\"/#{action}\"",
":",
"self",
",",
"parameters",
".",
"compact",
"end"
] |
Compare by parts count and the first arg position
@param other [Flame::Path] other path
@return [-1, 0, 1] result of comparing
Compare with other path by parts
@param other [Flame::Path, String] other path
@return [true, false] equal or not
Complete path for the action of controller
@param ctrl [Flame::Controller] to which controller adapt
@param action [Symbol] to which action of controller adapt
@return [Flame::Path] adapted path
@todo Add :arg:type support (:id:num, :name:str, etc.)
|
[
"Compare",
"by",
"parts",
"count",
"and",
"the",
"first",
"arg",
"position"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/path.rb#L80-L88
|
18,060
|
AlexWayfer/flame
|
lib/flame/path.rb
|
Flame.Path.to_routes_with_endpoint
|
def to_routes_with_endpoint
endpoint =
parts.reduce(result = Flame::Router::Routes.new) do |hash, part|
hash[part] ||= Flame::Router::Routes.new
end
[result, endpoint]
end
|
ruby
|
def to_routes_with_endpoint
endpoint =
parts.reduce(result = Flame::Router::Routes.new) do |hash, part|
hash[part] ||= Flame::Router::Routes.new
end
[result, endpoint]
end
|
[
"def",
"to_routes_with_endpoint",
"endpoint",
"=",
"parts",
".",
"reduce",
"(",
"result",
"=",
"Flame",
"::",
"Router",
"::",
"Routes",
".",
"new",
")",
"do",
"|",
"hash",
",",
"part",
"|",
"hash",
"[",
"part",
"]",
"||=",
"Flame",
"::",
"Router",
"::",
"Routes",
".",
"new",
"end",
"[",
"result",
",",
"endpoint",
"]",
"end"
] |
Path parts as keys of nested Hashes
@return [Array(Flame::Router::Routes, Flame::Router::Routes)]
whole Routes (parent) and the endpoint (most nested Routes)
|
[
"Path",
"parts",
"as",
"keys",
"of",
"nested",
"Hashes"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/path.rb#L113-L119
|
18,061
|
AlexWayfer/flame
|
lib/flame/path.rb
|
Flame.Path.assign_argument
|
def assign_argument(part, args = {})
## Not argument
return part unless part.arg?
## Not required argument
return args.delete(part[2..-1].to_sym) if part.opt_arg?
## Required argument
param = args.delete(part[1..-1].to_sym)
## Required argument is nil
error = Errors::ArgumentNotAssignedError.new(@path, part)
raise error if param.nil?
## All is ok
param
end
|
ruby
|
def assign_argument(part, args = {})
## Not argument
return part unless part.arg?
## Not required argument
return args.delete(part[2..-1].to_sym) if part.opt_arg?
## Required argument
param = args.delete(part[1..-1].to_sym)
## Required argument is nil
error = Errors::ArgumentNotAssignedError.new(@path, part)
raise error if param.nil?
## All is ok
param
end
|
[
"def",
"assign_argument",
"(",
"part",
",",
"args",
"=",
"{",
"}",
")",
"## Not argument",
"return",
"part",
"unless",
"part",
".",
"arg?",
"## Not required argument",
"return",
"args",
".",
"delete",
"(",
"part",
"[",
"2",
"..",
"-",
"1",
"]",
".",
"to_sym",
")",
"if",
"part",
".",
"opt_arg?",
"## Required argument",
"param",
"=",
"args",
".",
"delete",
"(",
"part",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"to_sym",
")",
"## Required argument is nil",
"error",
"=",
"Errors",
"::",
"ArgumentNotAssignedError",
".",
"new",
"(",
"@path",
",",
"part",
")",
"raise",
"error",
"if",
"param",
".",
"nil?",
"## All is ok",
"param",
"end"
] |
Helpers for `assign_arguments`
|
[
"Helpers",
"for",
"assign_arguments"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/path.rb#L124-L138
|
18,062
|
AlexWayfer/flame
|
lib/flame/dispatcher.rb
|
Flame.Dispatcher.status
|
def status(value = nil)
response.status ||= 200
response.headers['X-Cascade'] = 'pass' if value == 404
value ? response.status = value : response.status
end
|
ruby
|
def status(value = nil)
response.status ||= 200
response.headers['X-Cascade'] = 'pass' if value == 404
value ? response.status = value : response.status
end
|
[
"def",
"status",
"(",
"value",
"=",
"nil",
")",
"response",
".",
"status",
"||=",
"200",
"response",
".",
"headers",
"[",
"'X-Cascade'",
"]",
"=",
"'pass'",
"if",
"value",
"==",
"404",
"value",
"?",
"response",
".",
"status",
"=",
"value",
":",
"response",
".",
"status",
"end"
] |
Acccess to the status of response
@param value [Ineger, nil] integer value for new status
@return [Integer] current status
@example Set status value
status 200
|
[
"Acccess",
"to",
"the",
"status",
"of",
"response"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/dispatcher.rb#L56-L60
|
18,063
|
AlexWayfer/flame
|
lib/flame/dispatcher.rb
|
Flame.Dispatcher.params
|
def params
@params ||=
begin
request.params.symbolize_keys(deep: true)
rescue ArgumentError => e
raise unless e.message.include?('invalid %-encoding')
{}
end
end
|
ruby
|
def params
@params ||=
begin
request.params.symbolize_keys(deep: true)
rescue ArgumentError => e
raise unless e.message.include?('invalid %-encoding')
{}
end
end
|
[
"def",
"params",
"@params",
"||=",
"begin",
"request",
".",
"params",
".",
"symbolize_keys",
"(",
"deep",
":",
"true",
")",
"rescue",
"ArgumentError",
"=>",
"e",
"raise",
"unless",
"e",
".",
"message",
".",
"include?",
"(",
"'invalid %-encoding'",
")",
"{",
"}",
"end",
"end"
] |
Parameters of the request
|
[
"Parameters",
"of",
"the",
"request"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/dispatcher.rb#L74-L83
|
18,064
|
AlexWayfer/flame
|
lib/flame/dispatcher.rb
|
Flame.Dispatcher.dump_error
|
def dump_error(error)
error_message = [
"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - " \
"#{error.class} - #{error.message}:",
*error.backtrace
].join("\n\t")
@env[Rack::RACK_ERRORS].puts(error_message)
end
|
ruby
|
def dump_error(error)
error_message = [
"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - " \
"#{error.class} - #{error.message}:",
*error.backtrace
].join("\n\t")
@env[Rack::RACK_ERRORS].puts(error_message)
end
|
[
"def",
"dump_error",
"(",
"error",
")",
"error_message",
"=",
"[",
"\"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - \"",
"\"#{error.class} - #{error.message}:\"",
",",
"error",
".",
"backtrace",
"]",
".",
"join",
"(",
"\"\\n\\t\"",
")",
"@env",
"[",
"Rack",
"::",
"RACK_ERRORS",
"]",
".",
"puts",
"(",
"error_message",
")",
"end"
] |
Add error's backtrace to @env['rack.errors'] (terminal or file)
@param error [Exception] exception for class, message and backtrace
|
[
"Add",
"error",
"s",
"backtrace",
"to"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/dispatcher.rb#L125-L132
|
18,065
|
AlexWayfer/flame
|
lib/flame/dispatcher.rb
|
Flame.Dispatcher.try_options
|
def try_options
return unless request.http_method == :OPTIONS
allow = available_endpoint&.allow
halt 404 unless allow
response.headers['Allow'] = allow
end
|
ruby
|
def try_options
return unless request.http_method == :OPTIONS
allow = available_endpoint&.allow
halt 404 unless allow
response.headers['Allow'] = allow
end
|
[
"def",
"try_options",
"return",
"unless",
"request",
".",
"http_method",
"==",
":OPTIONS",
"allow",
"=",
"available_endpoint",
"&.",
"allow",
"halt",
"404",
"unless",
"allow",
"response",
".",
"headers",
"[",
"'Allow'",
"]",
"=",
"allow",
"end"
] |
Return response if HTTP-method is OPTIONS
|
[
"Return",
"response",
"if",
"HTTP",
"-",
"method",
"is",
"OPTIONS"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/dispatcher.rb#L157-L163
|
18,066
|
AlexWayfer/flame
|
lib/flame/controller.rb
|
Flame.Controller.redirect
|
def redirect(*args)
args[0] = args.first.to_s if args.first.is_a? URI
unless args.first.is_a? String
path_to_args_range = 0..(args.last.is_a?(Integer) ? -2 : -1)
args[path_to_args_range] = path_to(*args[path_to_args_range])
end
response.redirect(*args)
status
end
|
ruby
|
def redirect(*args)
args[0] = args.first.to_s if args.first.is_a? URI
unless args.first.is_a? String
path_to_args_range = 0..(args.last.is_a?(Integer) ? -2 : -1)
args[path_to_args_range] = path_to(*args[path_to_args_range])
end
response.redirect(*args)
status
end
|
[
"def",
"redirect",
"(",
"*",
"args",
")",
"args",
"[",
"0",
"]",
"=",
"args",
".",
"first",
".",
"to_s",
"if",
"args",
".",
"first",
".",
"is_a?",
"URI",
"unless",
"args",
".",
"first",
".",
"is_a?",
"String",
"path_to_args_range",
"=",
"0",
"..",
"(",
"args",
".",
"last",
".",
"is_a?",
"(",
"Integer",
")",
"?",
"-",
"2",
":",
"-",
"1",
")",
"args",
"[",
"path_to_args_range",
"]",
"=",
"path_to",
"(",
"args",
"[",
"path_to_args_range",
"]",
")",
"end",
"response",
".",
"redirect",
"(",
"args",
")",
"status",
"end"
] |
Redirect for response
@overload redirect(path, status)
Redirect to the string path
@param path [String] path
@param status [Ingeter, nil] HTTP status
@return [nil]
@example Redirect to '/hello'
redirect '/hello'
@example Redirect to '/hello' with status 301
redirect '/hello', 301
@overload redirect(uri, status)
Redirect to the URI location
@param uri [URI] URI object
@param status [Ingeter, nil] HTTP status
@return [nil]
@example Redirect to 'http://example.com'
redirect URI::HTTP.build(host: 'example.com')
@example Redirect to 'http://example.com' with status 301
redirect URI::HTTP.build(host: 'example.com'), 301
@overload redirect(*args, status)
Redirect to the path of `path_to` method
@param args arguments for `path_to` method
@param status [Ingeter, nil] HTTP status
@return [nil]
@example Redirect to `show` method of `ArticlesController` with id = 2
redirect ArticlesController, :show, id: 2
@example Redirect to method of controller with status 301
redirect ArticlesController, :show, { id: 2 }, 301
|
[
"Redirect",
"for",
"response"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/controller.rb#L90-L98
|
18,067
|
AlexWayfer/flame
|
lib/flame/controller.rb
|
Flame.Controller.attachment
|
def attachment(filename = nil, disposition = :attachment)
content_dis = 'Content-Disposition'
response[content_dis] = disposition.to_s
return unless filename
response[content_dis] << "; filename=\"#{File.basename(filename)}\""
ext = File.extname(filename)
response.content_type = ext unless ext.empty?
end
|
ruby
|
def attachment(filename = nil, disposition = :attachment)
content_dis = 'Content-Disposition'
response[content_dis] = disposition.to_s
return unless filename
response[content_dis] << "; filename=\"#{File.basename(filename)}\""
ext = File.extname(filename)
response.content_type = ext unless ext.empty?
end
|
[
"def",
"attachment",
"(",
"filename",
"=",
"nil",
",",
"disposition",
"=",
":attachment",
")",
"content_dis",
"=",
"'Content-Disposition'",
"response",
"[",
"content_dis",
"]",
"=",
"disposition",
".",
"to_s",
"return",
"unless",
"filename",
"response",
"[",
"content_dis",
"]",
"<<",
"\"; filename=\\\"#{File.basename(filename)}\\\"\"",
"ext",
"=",
"File",
".",
"extname",
"(",
"filename",
")",
"response",
".",
"content_type",
"=",
"ext",
"unless",
"ext",
".",
"empty?",
"end"
] |
Set the Content-Disposition to "attachment" with the specified filename,
instructing the user agents to prompt to save,
and set Content-Type by filename.
@param filename [String, nil] filename of attachment
@param disposition [Symbol, String] main content for Content-Disposition
@example Set Content-Disposition header without filename
attachment
@example Set Content-Disposition header with filename and Content-Type
attachment 'style.css'
|
[
"Set",
"the",
"Content",
"-",
"Disposition",
"to",
"attachment",
"with",
"the",
"specified",
"filename",
"instructing",
"the",
"user",
"agents",
"to",
"prompt",
"to",
"save",
"and",
"set",
"Content",
"-",
"Type",
"by",
"filename",
"."
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/controller.rb#L109-L117
|
18,068
|
AlexWayfer/flame
|
lib/flame/controller.rb
|
Flame.Controller.reroute
|
def reroute(*args)
add_controller_class(args)
ctrl, action = args[0..1]
ctrl_object = ctrl == self.class ? self : ctrl.new(@dispatcher)
ctrl_object.send :execute, action
body
end
|
ruby
|
def reroute(*args)
add_controller_class(args)
ctrl, action = args[0..1]
ctrl_object = ctrl == self.class ? self : ctrl.new(@dispatcher)
ctrl_object.send :execute, action
body
end
|
[
"def",
"reroute",
"(",
"*",
"args",
")",
"add_controller_class",
"(",
"args",
")",
"ctrl",
",",
"action",
"=",
"args",
"[",
"0",
"..",
"1",
"]",
"ctrl_object",
"=",
"ctrl",
"==",
"self",
".",
"class",
"?",
"self",
":",
"ctrl",
".",
"new",
"(",
"@dispatcher",
")",
"ctrl_object",
".",
"send",
":execute",
",",
"action",
"body",
"end"
] |
Execute any action from any controller
@example Execute `new` action of `ArticlesController`
reroute ArticlesController, :new
@example Execute `index` action of `ArticlesController`
reroute ArticlesController
@example Execute `foo` action of current controller
reroute :foo
|
[
"Execute",
"any",
"action",
"from",
"any",
"controller"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/controller.rb#L163-L169
|
18,069
|
AlexWayfer/flame
|
lib/flame/application.rb
|
Flame.Application.call
|
def call(env)
@app.call(env) if @app.respond_to? :call
Flame::Dispatcher.new(self.class, env).run!
end
|
ruby
|
def call(env)
@app.call(env) if @app.respond_to? :call
Flame::Dispatcher.new(self.class, env).run!
end
|
[
"def",
"call",
"(",
"env",
")",
"@app",
".",
"call",
"(",
"env",
")",
"if",
"@app",
".",
"respond_to?",
":call",
"Flame",
"::",
"Dispatcher",
".",
"new",
"(",
"self",
".",
"class",
",",
"env",
")",
".",
"run!",
"end"
] |
Request recieving method
|
[
"Request",
"recieving",
"method"
] |
aecb2bb22b43abf4d99a36ea580d67923e3a6564
|
https://github.com/AlexWayfer/flame/blob/aecb2bb22b43abf4d99a36ea580d67923e3a6564/lib/flame/application.rb#L151-L154
|
18,070
|
avinashbot/redd
|
lib/redd/client.rb
|
Redd.Client.request
|
def request(verb, path, options = {})
# puts "#{verb.to_s.upcase} #{path}", ' ' + options.inspect
response = connection.request(verb, path, **options)
Response.new(response.status.code, response.headers, response.body.to_s)
end
|
ruby
|
def request(verb, path, options = {})
# puts "#{verb.to_s.upcase} #{path}", ' ' + options.inspect
response = connection.request(verb, path, **options)
Response.new(response.status.code, response.headers, response.body.to_s)
end
|
[
"def",
"request",
"(",
"verb",
",",
"path",
",",
"options",
"=",
"{",
"}",
")",
"# puts \"#{verb.to_s.upcase} #{path}\", ' ' + options.inspect",
"response",
"=",
"connection",
".",
"request",
"(",
"verb",
",",
"path",
",",
"**",
"options",
")",
"Response",
".",
"new",
"(",
"response",
".",
"status",
".",
"code",
",",
"response",
".",
"headers",
",",
"response",
".",
"body",
".",
"to_s",
")",
"end"
] |
Create a new client.
@param endpoint [String] the base endpoint to make all requests from
@param user_agent [String] a user agent string
Make an HTTP request.
@param verb [:get, :post, :put, :patch, :delete] the HTTP verb to use
@param path [String] the path relative to the endpoint
@param options [Hash] the request parameters
@option options [Hash] :params the parameters to supply with the url
@option options [Hash] :form the parameters to supply in the body
@option options [Hash] :body the direct body contents
@return [Response] the response
|
[
"Create",
"a",
"new",
"client",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/client.rb#L35-L39
|
18,071
|
avinashbot/redd
|
lib/redd/middleware.rb
|
Redd.Middleware.redirect_to_reddit!
|
def redirect_to_reddit!
state = SecureRandom.urlsafe_base64
url = Redd.url(
client_id: @client_id,
redirect_uri: @redirect_uri,
scope: @scope,
duration: @duration,
state: state
)
@request.session[:redd_state] = state
[302, { 'Location' => url }, []]
end
|
ruby
|
def redirect_to_reddit!
state = SecureRandom.urlsafe_base64
url = Redd.url(
client_id: @client_id,
redirect_uri: @redirect_uri,
scope: @scope,
duration: @duration,
state: state
)
@request.session[:redd_state] = state
[302, { 'Location' => url }, []]
end
|
[
"def",
"redirect_to_reddit!",
"state",
"=",
"SecureRandom",
".",
"urlsafe_base64",
"url",
"=",
"Redd",
".",
"url",
"(",
"client_id",
":",
"@client_id",
",",
"redirect_uri",
":",
"@redirect_uri",
",",
"scope",
":",
"@scope",
",",
"duration",
":",
"@duration",
",",
"state",
":",
"state",
")",
"@request",
".",
"session",
"[",
":redd_state",
"]",
"=",
"state",
"[",
"302",
",",
"{",
"'Location'",
"=>",
"url",
"}",
",",
"[",
"]",
"]",
"end"
] |
Creates a unique state and redirects the user to reddit for authentication.
|
[
"Creates",
"a",
"unique",
"state",
"and",
"redirects",
"the",
"user",
"to",
"reddit",
"for",
"authentication",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/middleware.rb#L58-L69
|
18,072
|
avinashbot/redd
|
lib/redd/middleware.rb
|
Redd.Middleware.after_call
|
def after_call
env_session = @request.env['redd.session']
if env_session && env_session.client.access
# Make sure to flush any changes made to the Session client to the browser.
@request.session[:redd_session] = env_session.client.access.to_h
else
# Clear the session if the app explicitly set 'redd.session' to nil.
@request.session.delete(:redd_session)
end
end
|
ruby
|
def after_call
env_session = @request.env['redd.session']
if env_session && env_session.client.access
# Make sure to flush any changes made to the Session client to the browser.
@request.session[:redd_session] = env_session.client.access.to_h
else
# Clear the session if the app explicitly set 'redd.session' to nil.
@request.session.delete(:redd_session)
end
end
|
[
"def",
"after_call",
"env_session",
"=",
"@request",
".",
"env",
"[",
"'redd.session'",
"]",
"if",
"env_session",
"&&",
"env_session",
".",
"client",
".",
"access",
"# Make sure to flush any changes made to the Session client to the browser.",
"@request",
".",
"session",
"[",
":redd_session",
"]",
"=",
"env_session",
".",
"client",
".",
"access",
".",
"to_h",
"else",
"# Clear the session if the app explicitly set 'redd.session' to nil.",
"@request",
".",
"session",
".",
"delete",
"(",
":redd_session",
")",
"end",
"end"
] |
Do any cleanup or changes after calling the application.
|
[
"Do",
"any",
"cleanup",
"or",
"changes",
"after",
"calling",
"the",
"application",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/middleware.rb#L82-L91
|
18,073
|
avinashbot/redd
|
lib/redd/middleware.rb
|
Redd.Middleware.handle_token_error
|
def handle_token_error
message = nil
message = 'invalid_state' if @request.GET['state'] != @request.session[:redd_state]
message = @request.GET['error'] if @request.GET['error']
raise Errors::TokenRetrievalError, message if message
end
|
ruby
|
def handle_token_error
message = nil
message = 'invalid_state' if @request.GET['state'] != @request.session[:redd_state]
message = @request.GET['error'] if @request.GET['error']
raise Errors::TokenRetrievalError, message if message
end
|
[
"def",
"handle_token_error",
"message",
"=",
"nil",
"message",
"=",
"'invalid_state'",
"if",
"@request",
".",
"GET",
"[",
"'state'",
"]",
"!=",
"@request",
".",
"session",
"[",
":redd_state",
"]",
"message",
"=",
"@request",
".",
"GET",
"[",
"'error'",
"]",
"if",
"@request",
".",
"GET",
"[",
"'error'",
"]",
"raise",
"Errors",
"::",
"TokenRetrievalError",
",",
"message",
"if",
"message",
"end"
] |
Assigns a single string representing a reddit authentication errors.
|
[
"Assigns",
"a",
"single",
"string",
"representing",
"a",
"reddit",
"authentication",
"errors",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/middleware.rb#L94-L99
|
18,074
|
avinashbot/redd
|
lib/redd/middleware.rb
|
Redd.Middleware.create_session!
|
def create_session!
# Skip authorizing if there was an error from the authorization.
handle_token_error
# Try to get a code (the rescue block will also prevent crazy crashes)
access = @strategy.authenticate(@request.GET['code'])
@request.session[:redd_session] = access.to_h
rescue Errors::TokenRetrievalError, Errors::ResponseError => error
@request.env['redd.error'] = error
end
|
ruby
|
def create_session!
# Skip authorizing if there was an error from the authorization.
handle_token_error
# Try to get a code (the rescue block will also prevent crazy crashes)
access = @strategy.authenticate(@request.GET['code'])
@request.session[:redd_session] = access.to_h
rescue Errors::TokenRetrievalError, Errors::ResponseError => error
@request.env['redd.error'] = error
end
|
[
"def",
"create_session!",
"# Skip authorizing if there was an error from the authorization.",
"handle_token_error",
"# Try to get a code (the rescue block will also prevent crazy crashes)",
"access",
"=",
"@strategy",
".",
"authenticate",
"(",
"@request",
".",
"GET",
"[",
"'code'",
"]",
")",
"@request",
".",
"session",
"[",
":redd_session",
"]",
"=",
"access",
".",
"to_h",
"rescue",
"Errors",
"::",
"TokenRetrievalError",
",",
"Errors",
"::",
"ResponseError",
"=>",
"error",
"@request",
".",
"env",
"[",
"'redd.error'",
"]",
"=",
"error",
"end"
] |
Store the access token and other details in the user's browser, assigning any errors to
the 'redd.error' env variable.
|
[
"Store",
"the",
"access",
"token",
"and",
"other",
"details",
"in",
"the",
"user",
"s",
"browser",
"assigning",
"any",
"errors",
"to",
"the",
"redd",
".",
"error",
"env",
"variable",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/middleware.rb#L103-L111
|
18,075
|
avinashbot/redd
|
lib/redd/api_client.rb
|
Redd.APIClient.request
|
def request(verb, path, raw: false, params: {}, **options)
# Make sure @access is populated by a valid access
ensure_access_is_valid
# Setup base API params and make request
api_params = { api_type: 'json', raw_json: 1 }.merge(params)
# This loop is retried @max_retries number of times until it succeeds
handle_retryable_errors do
response = @rate_limiter.after_limit { super(verb, path, params: api_params, **options) }
# Raise errors if encountered at the API level.
response_error = @error_handler.check_error(response, raw: raw)
raise response_error unless response_error.nil?
# All done, return the response
response
end
end
|
ruby
|
def request(verb, path, raw: false, params: {}, **options)
# Make sure @access is populated by a valid access
ensure_access_is_valid
# Setup base API params and make request
api_params = { api_type: 'json', raw_json: 1 }.merge(params)
# This loop is retried @max_retries number of times until it succeeds
handle_retryable_errors do
response = @rate_limiter.after_limit { super(verb, path, params: api_params, **options) }
# Raise errors if encountered at the API level.
response_error = @error_handler.check_error(response, raw: raw)
raise response_error unless response_error.nil?
# All done, return the response
response
end
end
|
[
"def",
"request",
"(",
"verb",
",",
"path",
",",
"raw",
":",
"false",
",",
"params",
":",
"{",
"}",
",",
"**",
"options",
")",
"# Make sure @access is populated by a valid access",
"ensure_access_is_valid",
"# Setup base API params and make request",
"api_params",
"=",
"{",
"api_type",
":",
"'json'",
",",
"raw_json",
":",
"1",
"}",
".",
"merge",
"(",
"params",
")",
"# This loop is retried @max_retries number of times until it succeeds",
"handle_retryable_errors",
"do",
"response",
"=",
"@rate_limiter",
".",
"after_limit",
"{",
"super",
"(",
"verb",
",",
"path",
",",
"params",
":",
"api_params",
",",
"**",
"options",
")",
"}",
"# Raise errors if encountered at the API level.",
"response_error",
"=",
"@error_handler",
".",
"check_error",
"(",
"response",
",",
"raw",
":",
"raw",
")",
"raise",
"response_error",
"unless",
"response_error",
".",
"nil?",
"# All done, return the response",
"response",
"end",
"end"
] |
Makes a request, ensuring not to break the rate limit by sleeping.
@see Client#request
|
[
"Makes",
"a",
"request",
"ensuring",
"not",
"to",
"break",
"the",
"rate",
"limit",
"by",
"sleeping",
"."
] |
3b1519a2d121efd18de59b935da6e652757eee90
|
https://github.com/avinashbot/redd/blob/3b1519a2d121efd18de59b935da6e652757eee90/lib/redd/api_client.rb#L65-L80
|
18,076
|
ansible/ansible_tower_client_ruby
|
lib/ansible_tower_client/hash_model.rb
|
AnsibleTowerClient.HashModel.hash_to_model
|
def hash_to_model(klass_name, hash)
model_klass =
if self.class.const_defined?("#{self.class}::#{klass_name}")
self.class.const_get(klass_name)
else
self.class.const_set(klass_name, Class.new(HashModel))
end
model_klass.new(hash)
end
|
ruby
|
def hash_to_model(klass_name, hash)
model_klass =
if self.class.const_defined?("#{self.class}::#{klass_name}")
self.class.const_get(klass_name)
else
self.class.const_set(klass_name, Class.new(HashModel))
end
model_klass.new(hash)
end
|
[
"def",
"hash_to_model",
"(",
"klass_name",
",",
"hash",
")",
"model_klass",
"=",
"if",
"self",
".",
"class",
".",
"const_defined?",
"(",
"\"#{self.class}::#{klass_name}\"",
")",
"self",
".",
"class",
".",
"const_get",
"(",
"klass_name",
")",
"else",
"self",
".",
"class",
".",
"const_set",
"(",
"klass_name",
",",
"Class",
".",
"new",
"(",
"HashModel",
")",
")",
"end",
"model_klass",
".",
"new",
"(",
"hash",
")",
"end"
] |
Convert a hash to an instance of nested model class
This is the default implementation; the resulting object is based on HashModel
To be overridden by subclasses
|
[
"Convert",
"a",
"hash",
"to",
"an",
"instance",
"of",
"nested",
"model",
"class"
] |
39454d74b9d4ea4771b16d4c41cbbbd83ad05df5
|
https://github.com/ansible/ansible_tower_client_ruby/blob/39454d74b9d4ea4771b16d4c41cbbbd83ad05df5/lib/ansible_tower_client/hash_model.rb#L133-L141
|
18,077
|
roma/roma
|
lib/roma/tools/mkconfig.rb
|
Roma.Mkconfig.save_data
|
def save_data(res)
if res.key?("storage")
case res["storage"].value
when "Ruby Hash"
req = "rh_storage"
storage = "RubyHashStorage"
when "Tokyo Cabinet"
req = "tc_storage"
storage = "TCStorage"
bnum = Calculate.get_bnum(res)
bnum = 5000000 if bnum < 5000000
xmsiz = Calculate.get_xmsize_max(res)
when "Groonga"
req = "groonga_storage"
storage = "GroongaStorage"
bnum = Calculate.get_bnum(res)
bnum = 5000000 if bnum < 5000000
xmsiz = Calculate.get_xmsize_max(res)
end
end
if res.key?("language")
fd = Calculate.get_fd(res)
print "\r\nPlease set FileDescriptor bigger than #{fd}.\r\n\r\n"
end
body = ""
open(CONFIG_TEMPLATE_PATH, "r") do |f|
body = f.read
end
if req
body = ch_assign(body, "require", " ", "roma\/storage\/#{req}")
body = ch_assign(body, "STORAGE_CLASS", "Roma::Storage::#{storage}")
case req
when "rh_storage"
body = ch_assign(body, "STORAGE_OPTION","")
when /^(tc_storage|groonga_storage)$/
body = ch_assign(body, "STORAGE_OPTION", "bnum=#{bnum}\#xmsiz=#{xmsiz}\#opts=d#dfunit=10")
end
end
if res.key?("plugin")
body = ch_assign(body, "PLUGIN_FILES", res["plugin"].value)
end
open(CONFIG_OUT_PATH, "w") do |f|
f.flock(File::LOCK_EX)
f.puts body
f.truncate(f.tell)
f.flock(File::LOCK_UN)
end
puts "Before"
Box.print_with_box(@defaults)
re_require(CONFIG_OUT_PATH, Config)
results = load_config([:STORAGE_CLASS, :STORAGE_OPTION, :PLUGIN_FILES])
print "\r\nAfter\r\n"
Box.print_with_box(results)
print "\r\nMkconfig is finish.\r\n"
print "\r\nIf you need, change directory path about LOG, RTTABLE, STORAGE, WB and other setting.\r\n\r\n"
end
|
ruby
|
def save_data(res)
if res.key?("storage")
case res["storage"].value
when "Ruby Hash"
req = "rh_storage"
storage = "RubyHashStorage"
when "Tokyo Cabinet"
req = "tc_storage"
storage = "TCStorage"
bnum = Calculate.get_bnum(res)
bnum = 5000000 if bnum < 5000000
xmsiz = Calculate.get_xmsize_max(res)
when "Groonga"
req = "groonga_storage"
storage = "GroongaStorage"
bnum = Calculate.get_bnum(res)
bnum = 5000000 if bnum < 5000000
xmsiz = Calculate.get_xmsize_max(res)
end
end
if res.key?("language")
fd = Calculate.get_fd(res)
print "\r\nPlease set FileDescriptor bigger than #{fd}.\r\n\r\n"
end
body = ""
open(CONFIG_TEMPLATE_PATH, "r") do |f|
body = f.read
end
if req
body = ch_assign(body, "require", " ", "roma\/storage\/#{req}")
body = ch_assign(body, "STORAGE_CLASS", "Roma::Storage::#{storage}")
case req
when "rh_storage"
body = ch_assign(body, "STORAGE_OPTION","")
when /^(tc_storage|groonga_storage)$/
body = ch_assign(body, "STORAGE_OPTION", "bnum=#{bnum}\#xmsiz=#{xmsiz}\#opts=d#dfunit=10")
end
end
if res.key?("plugin")
body = ch_assign(body, "PLUGIN_FILES", res["plugin"].value)
end
open(CONFIG_OUT_PATH, "w") do |f|
f.flock(File::LOCK_EX)
f.puts body
f.truncate(f.tell)
f.flock(File::LOCK_UN)
end
puts "Before"
Box.print_with_box(@defaults)
re_require(CONFIG_OUT_PATH, Config)
results = load_config([:STORAGE_CLASS, :STORAGE_OPTION, :PLUGIN_FILES])
print "\r\nAfter\r\n"
Box.print_with_box(results)
print "\r\nMkconfig is finish.\r\n"
print "\r\nIf you need, change directory path about LOG, RTTABLE, STORAGE, WB and other setting.\r\n\r\n"
end
|
[
"def",
"save_data",
"(",
"res",
")",
"if",
"res",
".",
"key?",
"(",
"\"storage\"",
")",
"case",
"res",
"[",
"\"storage\"",
"]",
".",
"value",
"when",
"\"Ruby Hash\"",
"req",
"=",
"\"rh_storage\"",
"storage",
"=",
"\"RubyHashStorage\"",
"when",
"\"Tokyo Cabinet\"",
"req",
"=",
"\"tc_storage\"",
"storage",
"=",
"\"TCStorage\"",
"bnum",
"=",
"Calculate",
".",
"get_bnum",
"(",
"res",
")",
"bnum",
"=",
"5000000",
"if",
"bnum",
"<",
"5000000",
"xmsiz",
"=",
"Calculate",
".",
"get_xmsize_max",
"(",
"res",
")",
"when",
"\"Groonga\"",
"req",
"=",
"\"groonga_storage\"",
"storage",
"=",
"\"GroongaStorage\"",
"bnum",
"=",
"Calculate",
".",
"get_bnum",
"(",
"res",
")",
"bnum",
"=",
"5000000",
"if",
"bnum",
"<",
"5000000",
"xmsiz",
"=",
"Calculate",
".",
"get_xmsize_max",
"(",
"res",
")",
"end",
"end",
"if",
"res",
".",
"key?",
"(",
"\"language\"",
")",
"fd",
"=",
"Calculate",
".",
"get_fd",
"(",
"res",
")",
"print",
"\"\\r\\nPlease set FileDescriptor bigger than #{fd}.\\r\\n\\r\\n\"",
"end",
"body",
"=",
"\"\"",
"open",
"(",
"CONFIG_TEMPLATE_PATH",
",",
"\"r\"",
")",
"do",
"|",
"f",
"|",
"body",
"=",
"f",
".",
"read",
"end",
"if",
"req",
"body",
"=",
"ch_assign",
"(",
"body",
",",
"\"require\"",
",",
"\" \"",
",",
"\"roma\\/storage\\/#{req}\"",
")",
"body",
"=",
"ch_assign",
"(",
"body",
",",
"\"STORAGE_CLASS\"",
",",
"\"Roma::Storage::#{storage}\"",
")",
"case",
"req",
"when",
"\"rh_storage\"",
"body",
"=",
"ch_assign",
"(",
"body",
",",
"\"STORAGE_OPTION\"",
",",
"\"\"",
")",
"when",
"/",
"/",
"body",
"=",
"ch_assign",
"(",
"body",
",",
"\"STORAGE_OPTION\"",
",",
"\"bnum=#{bnum}\\#xmsiz=#{xmsiz}\\#opts=d#dfunit=10\"",
")",
"end",
"end",
"if",
"res",
".",
"key?",
"(",
"\"plugin\"",
")",
"body",
"=",
"ch_assign",
"(",
"body",
",",
"\"PLUGIN_FILES\"",
",",
"res",
"[",
"\"plugin\"",
"]",
".",
"value",
")",
"end",
"open",
"(",
"CONFIG_OUT_PATH",
",",
"\"w\"",
")",
"do",
"|",
"f",
"|",
"f",
".",
"flock",
"(",
"File",
"::",
"LOCK_EX",
")",
"f",
".",
"puts",
"body",
"f",
".",
"truncate",
"(",
"f",
".",
"tell",
")",
"f",
".",
"flock",
"(",
"File",
"::",
"LOCK_UN",
")",
"end",
"puts",
"\"Before\"",
"Box",
".",
"print_with_box",
"(",
"@defaults",
")",
"re_require",
"(",
"CONFIG_OUT_PATH",
",",
"Config",
")",
"results",
"=",
"load_config",
"(",
"[",
":STORAGE_CLASS",
",",
":STORAGE_OPTION",
",",
":PLUGIN_FILES",
"]",
")",
"print",
"\"\\r\\nAfter\\r\\n\"",
"Box",
".",
"print_with_box",
"(",
"results",
")",
"print",
"\"\\r\\nMkconfig is finish.\\r\\n\"",
"print",
"\"\\r\\nIf you need, change directory path about LOG, RTTABLE, STORAGE, WB and other setting.\\r\\n\\r\\n\"",
"end"
] |
make config.rb based on input data
|
[
"make",
"config",
".",
"rb",
"based",
"on",
"input",
"data"
] |
3dea10df0171742c314ff48f2ed4eebaafc80abf
|
https://github.com/roma/roma/blob/3dea10df0171742c314ff48f2ed4eebaafc80abf/lib/roma/tools/mkconfig.rb#L511-L574
|
18,078
|
ansible/ansible_tower_client_ruby
|
lib/ansible_tower_client/base_model.rb
|
AnsibleTowerClient.BaseModel.update_attributes!
|
def update_attributes!(attributes)
@api.patch(url, attributes.to_json)
attributes.each do |method_name, value|
invoke_name = "#{override_raw_attributes[method_name] || method_name}="
if respond_to?(invoke_name)
send(invoke_name, value)
else
AnsibleTowerClient.logger.warn("Unknown attribute/method: #{invoke_name}. Skip updating it ...")
end
end
true
end
|
ruby
|
def update_attributes!(attributes)
@api.patch(url, attributes.to_json)
attributes.each do |method_name, value|
invoke_name = "#{override_raw_attributes[method_name] || method_name}="
if respond_to?(invoke_name)
send(invoke_name, value)
else
AnsibleTowerClient.logger.warn("Unknown attribute/method: #{invoke_name}. Skip updating it ...")
end
end
true
end
|
[
"def",
"update_attributes!",
"(",
"attributes",
")",
"@api",
".",
"patch",
"(",
"url",
",",
"attributes",
".",
"to_json",
")",
"attributes",
".",
"each",
"do",
"|",
"method_name",
",",
"value",
"|",
"invoke_name",
"=",
"\"#{override_raw_attributes[method_name] || method_name}=\"",
"if",
"respond_to?",
"(",
"invoke_name",
")",
"send",
"(",
"invoke_name",
",",
"value",
")",
"else",
"AnsibleTowerClient",
".",
"logger",
".",
"warn",
"(",
"\"Unknown attribute/method: #{invoke_name}. Skip updating it ...\"",
")",
"end",
"end",
"true",
"end"
] |
Persist changes passed in as a Hash and return a
representation of that object to the caller.
Example:
project = connection.api.projects.find 2
project.update_attributes!(:name => 'test')
# The values passed to update_attributes! are available in calling object
project.name # => 'test'
Errors:
Any error raised by the API will be returned and logged
|
[
"Persist",
"changes",
"passed",
"in",
"as",
"a",
"Hash",
"and",
"return",
"a",
"representation",
"of",
"that",
"object",
"to",
"the",
"caller",
"."
] |
39454d74b9d4ea4771b16d4c41cbbbd83ad05df5
|
https://github.com/ansible/ansible_tower_client_ruby/blob/39454d74b9d4ea4771b16d4c41cbbbd83ad05df5/lib/ansible_tower_client/base_model.rb#L82-L93
|
18,079
|
ansible/ansible_tower_client_ruby
|
lib/ansible_tower_client/base_model.rb
|
AnsibleTowerClient.BaseModel.hash_to_model
|
def hash_to_model(klass_name, hash)
model_klass =
if self.class.const_defined?(klass_name, false)
self.class.const_get(klass_name)
else
self.class.const_set(klass_name, Class.new(BaseModel))
end
model_klass.new(api, hash)
end
|
ruby
|
def hash_to_model(klass_name, hash)
model_klass =
if self.class.const_defined?(klass_name, false)
self.class.const_get(klass_name)
else
self.class.const_set(klass_name, Class.new(BaseModel))
end
model_klass.new(api, hash)
end
|
[
"def",
"hash_to_model",
"(",
"klass_name",
",",
"hash",
")",
"model_klass",
"=",
"if",
"self",
".",
"class",
".",
"const_defined?",
"(",
"klass_name",
",",
"false",
")",
"self",
".",
"class",
".",
"const_get",
"(",
"klass_name",
")",
"else",
"self",
".",
"class",
".",
"const_set",
"(",
"klass_name",
",",
"Class",
".",
"new",
"(",
"BaseModel",
")",
")",
"end",
"model_klass",
".",
"new",
"(",
"api",
",",
"hash",
")",
"end"
] |
convert a hash to an instance of nested model class
|
[
"convert",
"a",
"hash",
"to",
"an",
"instance",
"of",
"nested",
"model",
"class"
] |
39454d74b9d4ea4771b16d4c41cbbbd83ad05df5
|
https://github.com/ansible/ansible_tower_client_ruby/blob/39454d74b9d4ea4771b16d4c41cbbbd83ad05df5/lib/ansible_tower_client/base_model.rb#L164-L172
|
18,080
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/stats.rb
|
MLBStatsAPI.Stats.stats
|
def stats(options = {})
raise ArgumentError, '#stats requires a stats arg' unless options[:stats]
raise ArgumentError, '#stats requires a group arg' unless options[:group]
get '/stats', options
end
|
ruby
|
def stats(options = {})
raise ArgumentError, '#stats requires a stats arg' unless options[:stats]
raise ArgumentError, '#stats requires a group arg' unless options[:group]
get '/stats', options
end
|
[
"def",
"stats",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'#stats requires a stats arg'",
"unless",
"options",
"[",
":stats",
"]",
"raise",
"ArgumentError",
",",
"'#stats requires a group arg'",
"unless",
"options",
"[",
":group",
"]",
"get",
"'/stats'",
",",
"options",
"end"
] |
View statistics based on statType, group, season, and organization.
@see https://statsapi.mlb.com/docs/#operation/stats
|
[
"View",
"statistics",
"based",
"on",
"statType",
"group",
"season",
"and",
"organization",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/stats.rb#L9-L14
|
18,081
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/standings.rb
|
MLBStatsAPI.Standings.standings
|
def standings(options = {})
options[:hydrate] = 'team' unless options.key?(:hydrate)
if options[:leagues] && !options[:leagueId]
league_ids = Leagues::LEAGUES.values_at(*options.delete(:leagues))
options[:leagueId] = league_ids
end
options[:leagueId] = [103, 104] unless Array(options[:leagueId])&.any?
get '/standings', options
end
|
ruby
|
def standings(options = {})
options[:hydrate] = 'team' unless options.key?(:hydrate)
if options[:leagues] && !options[:leagueId]
league_ids = Leagues::LEAGUES.values_at(*options.delete(:leagues))
options[:leagueId] = league_ids
end
options[:leagueId] = [103, 104] unless Array(options[:leagueId])&.any?
get '/standings', options
end
|
[
"def",
"standings",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":hydrate",
"]",
"=",
"'team'",
"unless",
"options",
".",
"key?",
"(",
":hydrate",
")",
"if",
"options",
"[",
":leagues",
"]",
"&&",
"!",
"options",
"[",
":leagueId",
"]",
"league_ids",
"=",
"Leagues",
"::",
"LEAGUES",
".",
"values_at",
"(",
"options",
".",
"delete",
"(",
":leagues",
")",
")",
"options",
"[",
":leagueId",
"]",
"=",
"league_ids",
"end",
"options",
"[",
":leagueId",
"]",
"=",
"[",
"103",
",",
"104",
"]",
"unless",
"Array",
"(",
"options",
"[",
":leagueId",
"]",
")",
"&.",
"any?",
"get",
"'/standings'",
",",
"options",
"end"
] |
View standings for a league.
@see https://statsapi.mlb.com/docs/#operation/standings
|
[
"View",
"standings",
"for",
"a",
"league",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/standings.rb#L9-L21
|
18,082
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/leagues.rb
|
MLBStatsAPI.Leagues.all_star_ballot
|
def all_star_ballot(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarBallot", options
end
|
ruby
|
def all_star_ballot(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarBallot", options
end
|
[
"def",
"all_star_ballot",
"(",
"league_id",
",",
"season",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":season",
"]",
"=",
"season",
"||",
"Time",
".",
"now",
".",
"year",
"get",
"\"/league/#{league_id}/allStarBallot\"",
",",
"options",
"end"
] |
View All-Star Ballots per league.
@see https://statsapi.mlb.com/docs/#operation/allStarBallot
|
[
"View",
"All",
"-",
"Star",
"Ballots",
"per",
"league",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/leagues.rb#L38-L42
|
18,083
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/leagues.rb
|
MLBStatsAPI.Leagues.all_star_write_ins
|
def all_star_write_ins(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarWriteIns", options
end
|
ruby
|
def all_star_write_ins(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarWriteIns", options
end
|
[
"def",
"all_star_write_ins",
"(",
"league_id",
",",
"season",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":season",
"]",
"=",
"season",
"||",
"Time",
".",
"now",
".",
"year",
"get",
"\"/league/#{league_id}/allStarWriteIns\"",
",",
"options",
"end"
] |
View All-Star Write-ins per league.
@see https://statsapi.mlb.com/docs/#operation/allStarWriteIns
|
[
"View",
"All",
"-",
"Star",
"Write",
"-",
"ins",
"per",
"league",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/leagues.rb#L46-L50
|
18,084
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/leagues.rb
|
MLBStatsAPI.Leagues.all_star_final_vote
|
def all_star_final_vote(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarFinalVote", options
end
|
ruby
|
def all_star_final_vote(league_id, season = nil, options = {})
options[:season] = season || Time.now.year
get "/league/#{league_id}/allStarFinalVote", options
end
|
[
"def",
"all_star_final_vote",
"(",
"league_id",
",",
"season",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":season",
"]",
"=",
"season",
"||",
"Time",
".",
"now",
".",
"year",
"get",
"\"/league/#{league_id}/allStarFinalVote\"",
",",
"options",
"end"
] |
View All-Star Final Vote per league.
@see https://statsapi.mlb.com/docs/#operation/allStarFinalVote
|
[
"View",
"All",
"-",
"Star",
"Final",
"Vote",
"per",
"league",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/leagues.rb#L54-L58
|
18,085
|
Fustrate/mlb_stats_api
|
lib/mlb_stats_api/people.rb
|
MLBStatsAPI.People.person
|
def person(person_ids, options = {})
ids = Array(person_ids)
result = get('/people', options.merge(personIds: ids)).dig('people')
return result.first if ids.length == 1
result
end
|
ruby
|
def person(person_ids, options = {})
ids = Array(person_ids)
result = get('/people', options.merge(personIds: ids)).dig('people')
return result.first if ids.length == 1
result
end
|
[
"def",
"person",
"(",
"person_ids",
",",
"options",
"=",
"{",
"}",
")",
"ids",
"=",
"Array",
"(",
"person_ids",
")",
"result",
"=",
"get",
"(",
"'/people'",
",",
"options",
".",
"merge",
"(",
"personIds",
":",
"ids",
")",
")",
".",
"dig",
"(",
"'people'",
")",
"return",
"result",
".",
"first",
"if",
"ids",
".",
"length",
"==",
"1",
"result",
"end"
] |
View one or more person's stats and biographical information.
@see https://statsapi.mlb.com/docs/#operation/person
|
[
"View",
"one",
"or",
"more",
"person",
"s",
"stats",
"and",
"biographical",
"information",
"."
] |
6bbb430dbea4557b5d99c00cdd048b27aeeca231
|
https://github.com/Fustrate/mlb_stats_api/blob/6bbb430dbea4557b5d99c00cdd048b27aeeca231/lib/mlb_stats_api/people.rb#L9-L17
|
18,086
|
makandra/gemika
|
lib/gemika/rspec.rb
|
Gemika.RSpec.run_specs
|
def run_specs(options = nil)
options ||= {}
files = options.fetch(:files, 'spec')
rspec_options = options.fetch(:options, '--color')
# We need to override the gemfile explicitely, since we have a default Gemfile in the project root
gemfile = options.fetch(:gemfile, Gemika::Env.gemfile)
fatal = options.fetch(:fatal, true)
runner = binary(:gemfile => gemfile)
bundle_exec = options.fetch(:bundle_exec) ? 'bundle exec' : nil
command = [bundle_exec, runner, rspec_options, files].compact.join(' ')
result = shell_out(command)
if result
true
elsif fatal
raise RSpecFailed, "RSpec failed: #{command}"
else
false
end
end
|
ruby
|
def run_specs(options = nil)
options ||= {}
files = options.fetch(:files, 'spec')
rspec_options = options.fetch(:options, '--color')
# We need to override the gemfile explicitely, since we have a default Gemfile in the project root
gemfile = options.fetch(:gemfile, Gemika::Env.gemfile)
fatal = options.fetch(:fatal, true)
runner = binary(:gemfile => gemfile)
bundle_exec = options.fetch(:bundle_exec) ? 'bundle exec' : nil
command = [bundle_exec, runner, rspec_options, files].compact.join(' ')
result = shell_out(command)
if result
true
elsif fatal
raise RSpecFailed, "RSpec failed: #{command}"
else
false
end
end
|
[
"def",
"run_specs",
"(",
"options",
"=",
"nil",
")",
"options",
"||=",
"{",
"}",
"files",
"=",
"options",
".",
"fetch",
"(",
":files",
",",
"'spec'",
")",
"rspec_options",
"=",
"options",
".",
"fetch",
"(",
":options",
",",
"'--color'",
")",
"# We need to override the gemfile explicitely, since we have a default Gemfile in the project root",
"gemfile",
"=",
"options",
".",
"fetch",
"(",
":gemfile",
",",
"Gemika",
"::",
"Env",
".",
"gemfile",
")",
"fatal",
"=",
"options",
".",
"fetch",
"(",
":fatal",
",",
"true",
")",
"runner",
"=",
"binary",
"(",
":gemfile",
"=>",
"gemfile",
")",
"bundle_exec",
"=",
"options",
".",
"fetch",
"(",
":bundle_exec",
")",
"?",
"'bundle exec'",
":",
"nil",
"command",
"=",
"[",
"bundle_exec",
",",
"runner",
",",
"rspec_options",
",",
"files",
"]",
".",
"compact",
".",
"join",
"(",
"' '",
")",
"result",
"=",
"shell_out",
"(",
"command",
")",
"if",
"result",
"true",
"elsif",
"fatal",
"raise",
"RSpecFailed",
",",
"\"RSpec failed: #{command}\"",
"else",
"false",
"end",
"end"
] |
Runs the RSpec binary.
|
[
"Runs",
"the",
"RSpec",
"binary",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/rspec.rb#L10-L28
|
18,087
|
makandra/gemika
|
lib/gemika/rspec.rb
|
Gemika.RSpec.configure_should_syntax
|
def configure_should_syntax
if Env.gem?('rspec', '>= 2.11')
configure do |config|
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] }
end
else
# We have an old RSpec that only understands should syntax
end
end
|
ruby
|
def configure_should_syntax
if Env.gem?('rspec', '>= 2.11')
configure do |config|
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] }
end
else
# We have an old RSpec that only understands should syntax
end
end
|
[
"def",
"configure_should_syntax",
"if",
"Env",
".",
"gem?",
"(",
"'rspec'",
",",
"'>= 2.11'",
")",
"configure",
"do",
"|",
"config",
"|",
"config",
".",
"expect_with",
"(",
":rspec",
")",
"{",
"|",
"c",
"|",
"c",
".",
"syntax",
"=",
"[",
":should",
",",
":expect",
"]",
"}",
"config",
".",
"mock_with",
"(",
":rspec",
")",
"{",
"|",
"c",
"|",
"c",
".",
"syntax",
"=",
"[",
":should",
",",
":expect",
"]",
"}",
"end",
"else",
"# We have an old RSpec that only understands should syntax",
"end",
"end"
] |
Configures RSpec so it allows the `should` syntax that works across all RSpec versions.
|
[
"Configures",
"RSpec",
"so",
"it",
"allows",
"the",
"should",
"syntax",
"that",
"works",
"across",
"all",
"RSpec",
"versions",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/rspec.rb#L68-L77
|
18,088
|
makandra/gemika
|
lib/gemika/database.rb
|
Gemika.Database.adapter_config
|
def adapter_config
default_config = {}
default_config['database'] = guess_database_name
if Env.gem?('pg')
default_config['adapter'] = 'postgresql'
default_config['username'] = 'postgres' if Env.travis?
default_config['password'] = ''
user_config = @yaml_config['postgresql'] || @yaml_config['postgres'] || @yaml_config['pg'] || {}
elsif Env.gem?('mysql2')
default_config['adapter'] = 'mysql2'
default_config['username'] = 'travis' if Env.travis?
default_config['encoding'] = 'utf8'
user_config = (@yaml_config['mysql'] || @yaml_config['mysql2']) || {}
elsif Env.gem?('sqlite3')
default_config['adapter'] = 'sqlite3'
default_config['database'] = ':memory:'
user_config = (@yaml_config['sqlite'] || @yaml_config['sqlite3']) || {}
else
raise UnknownAdapter, "Unknown database type. Either 'pg', 'mysql2', or 'sqlite3' gem should be in your current bundle."
end
default_config.merge(user_config)
end
|
ruby
|
def adapter_config
default_config = {}
default_config['database'] = guess_database_name
if Env.gem?('pg')
default_config['adapter'] = 'postgresql'
default_config['username'] = 'postgres' if Env.travis?
default_config['password'] = ''
user_config = @yaml_config['postgresql'] || @yaml_config['postgres'] || @yaml_config['pg'] || {}
elsif Env.gem?('mysql2')
default_config['adapter'] = 'mysql2'
default_config['username'] = 'travis' if Env.travis?
default_config['encoding'] = 'utf8'
user_config = (@yaml_config['mysql'] || @yaml_config['mysql2']) || {}
elsif Env.gem?('sqlite3')
default_config['adapter'] = 'sqlite3'
default_config['database'] = ':memory:'
user_config = (@yaml_config['sqlite'] || @yaml_config['sqlite3']) || {}
else
raise UnknownAdapter, "Unknown database type. Either 'pg', 'mysql2', or 'sqlite3' gem should be in your current bundle."
end
default_config.merge(user_config)
end
|
[
"def",
"adapter_config",
"default_config",
"=",
"{",
"}",
"default_config",
"[",
"'database'",
"]",
"=",
"guess_database_name",
"if",
"Env",
".",
"gem?",
"(",
"'pg'",
")",
"default_config",
"[",
"'adapter'",
"]",
"=",
"'postgresql'",
"default_config",
"[",
"'username'",
"]",
"=",
"'postgres'",
"if",
"Env",
".",
"travis?",
"default_config",
"[",
"'password'",
"]",
"=",
"''",
"user_config",
"=",
"@yaml_config",
"[",
"'postgresql'",
"]",
"||",
"@yaml_config",
"[",
"'postgres'",
"]",
"||",
"@yaml_config",
"[",
"'pg'",
"]",
"||",
"{",
"}",
"elsif",
"Env",
".",
"gem?",
"(",
"'mysql2'",
")",
"default_config",
"[",
"'adapter'",
"]",
"=",
"'mysql2'",
"default_config",
"[",
"'username'",
"]",
"=",
"'travis'",
"if",
"Env",
".",
"travis?",
"default_config",
"[",
"'encoding'",
"]",
"=",
"'utf8'",
"user_config",
"=",
"(",
"@yaml_config",
"[",
"'mysql'",
"]",
"||",
"@yaml_config",
"[",
"'mysql2'",
"]",
")",
"||",
"{",
"}",
"elsif",
"Env",
".",
"gem?",
"(",
"'sqlite3'",
")",
"default_config",
"[",
"'adapter'",
"]",
"=",
"'sqlite3'",
"default_config",
"[",
"'database'",
"]",
"=",
"':memory:'",
"user_config",
"=",
"(",
"@yaml_config",
"[",
"'sqlite'",
"]",
"||",
"@yaml_config",
"[",
"'sqlite3'",
"]",
")",
"||",
"{",
"}",
"else",
"raise",
"UnknownAdapter",
",",
"\"Unknown database type. Either 'pg', 'mysql2', or 'sqlite3' gem should be in your current bundle.\"",
"end",
"default_config",
".",
"merge",
"(",
"user_config",
")",
"end"
] |
Returns a hash of ActiveRecord adapter options for the currently activated database gem.
|
[
"Returns",
"a",
"hash",
"of",
"ActiveRecord",
"adapter",
"options",
"for",
"the",
"currently",
"activated",
"database",
"gem",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/database.rb#L85-L106
|
18,089
|
makandra/gemika
|
lib/gemika/matrix.rb
|
Gemika.Matrix.each
|
def each(&block)
@all_passed = true
rows.each do |row|
gemfile = row.gemfile
if row.compatible_with_ruby?(current_ruby)
@compatible_count += 1
print_title gemfile
gemfile_passed = Env.with_gemfile(gemfile, row, &block)
@all_passed &= gemfile_passed
if gemfile_passed
@results[row] = tint('Success', COLOR_SUCCESS)
else
@results[row] = tint('Failed', COLOR_FAILURE)
end
else
@results[row] = tint("Skipped", COLOR_WARNING)
end
end
print_summary
end
|
ruby
|
def each(&block)
@all_passed = true
rows.each do |row|
gemfile = row.gemfile
if row.compatible_with_ruby?(current_ruby)
@compatible_count += 1
print_title gemfile
gemfile_passed = Env.with_gemfile(gemfile, row, &block)
@all_passed &= gemfile_passed
if gemfile_passed
@results[row] = tint('Success', COLOR_SUCCESS)
else
@results[row] = tint('Failed', COLOR_FAILURE)
end
else
@results[row] = tint("Skipped", COLOR_WARNING)
end
end
print_summary
end
|
[
"def",
"each",
"(",
"&",
"block",
")",
"@all_passed",
"=",
"true",
"rows",
".",
"each",
"do",
"|",
"row",
"|",
"gemfile",
"=",
"row",
".",
"gemfile",
"if",
"row",
".",
"compatible_with_ruby?",
"(",
"current_ruby",
")",
"@compatible_count",
"+=",
"1",
"print_title",
"gemfile",
"gemfile_passed",
"=",
"Env",
".",
"with_gemfile",
"(",
"gemfile",
",",
"row",
",",
"block",
")",
"@all_passed",
"&=",
"gemfile_passed",
"if",
"gemfile_passed",
"@results",
"[",
"row",
"]",
"=",
"tint",
"(",
"'Success'",
",",
"COLOR_SUCCESS",
")",
"else",
"@results",
"[",
"row",
"]",
"=",
"tint",
"(",
"'Failed'",
",",
"COLOR_FAILURE",
")",
"end",
"else",
"@results",
"[",
"row",
"]",
"=",
"tint",
"(",
"\"Skipped\"",
",",
"COLOR_WARNING",
")",
"end",
"end",
"print_summary",
"end"
] |
Runs the given `block` for each matrix row that is compatible with the current Ruby.
The row's gemfile will be set as an environment variable, so Bundler will use that gemfile if you shell out in `block`.
At the end it will print a summary of which rows have passed, failed or were skipped (due to incompatible Ruby version).
|
[
"Runs",
"the",
"given",
"block",
"for",
"each",
"matrix",
"row",
"that",
"is",
"compatible",
"with",
"the",
"current",
"Ruby",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/matrix.rb#L107-L126
|
18,090
|
makandra/gemika
|
lib/gemika/env.rb
|
Gemika.Env.with_gemfile
|
def with_gemfile(path, *args, &block)
# Make sure that if block calls #gemfile we still return the gemfile for this
# process, regardless of what's in ENV temporarily
@gemfile_changed = true
@process_gemfile = ENV['BUNDLE_GEMFILE']
Bundler.with_clean_env do
ENV['BUNDLE_GEMFILE'] = path
block.call(*args)
end
ensure
@gemfile_changed = false
ENV['BUNDLE_GEMFILE'] = @process_gemfile
end
|
ruby
|
def with_gemfile(path, *args, &block)
# Make sure that if block calls #gemfile we still return the gemfile for this
# process, regardless of what's in ENV temporarily
@gemfile_changed = true
@process_gemfile = ENV['BUNDLE_GEMFILE']
Bundler.with_clean_env do
ENV['BUNDLE_GEMFILE'] = path
block.call(*args)
end
ensure
@gemfile_changed = false
ENV['BUNDLE_GEMFILE'] = @process_gemfile
end
|
[
"def",
"with_gemfile",
"(",
"path",
",",
"*",
"args",
",",
"&",
"block",
")",
"# Make sure that if block calls #gemfile we still return the gemfile for this",
"# process, regardless of what's in ENV temporarily",
"@gemfile_changed",
"=",
"true",
"@process_gemfile",
"=",
"ENV",
"[",
"'BUNDLE_GEMFILE'",
"]",
"Bundler",
".",
"with_clean_env",
"do",
"ENV",
"[",
"'BUNDLE_GEMFILE'",
"]",
"=",
"path",
"block",
".",
"call",
"(",
"args",
")",
"end",
"ensure",
"@gemfile_changed",
"=",
"false",
"ENV",
"[",
"'BUNDLE_GEMFILE'",
"]",
"=",
"@process_gemfile",
"end"
] |
Changes the gemfile to the given `path`, runs the given `block`, then resets
the gemfile to its original path.
@example
Gemika::Env.with_gemfile('gemfiles/Gemfile.rails3') do
system('rspec spec') or raise 'RSpec failed'
end
|
[
"Changes",
"the",
"gemfile",
"to",
"the",
"given",
"path",
"runs",
"the",
"given",
"block",
"then",
"resets",
"the",
"gemfile",
"to",
"its",
"original",
"path",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/env.rb#L33-L45
|
18,091
|
makandra/gemika
|
lib/gemika/env.rb
|
Gemika.Env.gem?
|
def gem?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name, requirement_string = args
if options[:gemfile] && !process_gemfile?(options[:gemfile])
gem_in_gemfile?(options[:gemfile], name, requirement_string)
else
gem_activated?(name, requirement_string)
end
end
|
ruby
|
def gem?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name, requirement_string = args
if options[:gemfile] && !process_gemfile?(options[:gemfile])
gem_in_gemfile?(options[:gemfile], name, requirement_string)
else
gem_activated?(name, requirement_string)
end
end
|
[
"def",
"gem?",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"pop",
":",
"{",
"}",
"name",
",",
"requirement_string",
"=",
"args",
"if",
"options",
"[",
":gemfile",
"]",
"&&",
"!",
"process_gemfile?",
"(",
"options",
"[",
":gemfile",
"]",
")",
"gem_in_gemfile?",
"(",
"options",
"[",
":gemfile",
"]",
",",
"name",
",",
"requirement_string",
")",
"else",
"gem_activated?",
"(",
"name",
",",
"requirement_string",
")",
"end",
"end"
] |
Check if the given gem was activated by the current gemfile.
It might or might not have been `require`d yet.
@example
Gemika::Env.gem?('activerecord')
Gemika::Env.gem?('activerecord', '= 5.0.0')
Gemika::Env.gem?('activerecord', '~> 4.2.0')
|
[
"Check",
"if",
"the",
"given",
"gem",
"was",
"activated",
"by",
"the",
"current",
"gemfile",
".",
"It",
"might",
"or",
"might",
"not",
"have",
"been",
"require",
"d",
"yet",
"."
] |
3cd120c2df2123edcde02489cf6b5b74cd710148
|
https://github.com/makandra/gemika/blob/3cd120c2df2123edcde02489cf6b5b74cd710148/lib/gemika/env.rb#L56-L64
|
18,092
|
fabienpiette/fetcheable_on_api
|
lib/fetcheable_on_api/filterable.rb
|
FetcheableOnApi.Filterable.predicates
|
def predicates(predicate, collection, klass, column_name, value)
case predicate
when :between
klass.arel_table[column_name].between(value.first..value.last)
when :does_not_match
klass.arel_table[column_name].does_not_match("%#{value}%")
when :does_not_match_all
klass.arel_table[column_name].does_not_match_all(value)
when :does_not_match_any
klass.arel_table[column_name].does_not_match_any(value)
when :eq
klass.arel_table[column_name].eq(value)
when :eq_all
klass.arel_table[column_name].eq_all(value)
when :eq_any
klass.arel_table[column_name].eq_any(value)
when :gt
klass.arel_table[column_name].gt(value)
when :gt_all
klass.arel_table[column_name].gt_all(value)
when :gt_any
klass.arel_table[column_name].gt_any(value)
when :gteq
klass.arel_table[column_name].gteq(value)
when :gteq_all
klass.arel_table[column_name].gteq_all(value)
when :gteq_any
klass.arel_table[column_name].gteq_any(value)
when :in
klass.arel_table[column_name].in(value)
when :in_all
klass.arel_table[column_name].in_all(value)
when :in_any
klass.arel_table[column_name].in_any(value)
when :lt
klass.arel_table[column_name].lt(value)
when :lt_all
klass.arel_table[column_name].lt_all(value)
when :lt_any
klass.arel_table[column_name].lt_any(value)
when :lteq
klass.arel_table[column_name].lteq(value)
when :lteq_all
klass.arel_table[column_name].lteq_all(value)
when :lteq_any
klass.arel_table[column_name].lteq_any(value)
when :ilike
klass.arel_table[column_name].matches("%#{value}%")
when :matches
klass.arel_table[column_name].matches(value)
when :matches_all
klass.arel_table[column_name].matches_all(value)
when :matches_any
klass.arel_table[column_name].matches_any(value)
when :not_between
klass.arel_table[column_name].not_between(value.first..value.last)
when :not_eq
klass.arel_table[column_name].not_eq(value)
when :not_eq_all
klass.arel_table[column_name].not_eq_all(value)
when :not_eq_any
klass.arel_table[column_name].not_eq_any(value)
when :not_in
klass.arel_table[column_name].not_in(value)
when :not_in_all
klass.arel_table[column_name].not_in_all(value)
when :not_in_any
klass.arel_table[column_name].not_in_any(value)
else
unless predicate.respond_to?(:call)
raise ArgumentError,
"unsupported predicate `#{predicate}`"
end
predicate.call(collection, value)
end
end
|
ruby
|
def predicates(predicate, collection, klass, column_name, value)
case predicate
when :between
klass.arel_table[column_name].between(value.first..value.last)
when :does_not_match
klass.arel_table[column_name].does_not_match("%#{value}%")
when :does_not_match_all
klass.arel_table[column_name].does_not_match_all(value)
when :does_not_match_any
klass.arel_table[column_name].does_not_match_any(value)
when :eq
klass.arel_table[column_name].eq(value)
when :eq_all
klass.arel_table[column_name].eq_all(value)
when :eq_any
klass.arel_table[column_name].eq_any(value)
when :gt
klass.arel_table[column_name].gt(value)
when :gt_all
klass.arel_table[column_name].gt_all(value)
when :gt_any
klass.arel_table[column_name].gt_any(value)
when :gteq
klass.arel_table[column_name].gteq(value)
when :gteq_all
klass.arel_table[column_name].gteq_all(value)
when :gteq_any
klass.arel_table[column_name].gteq_any(value)
when :in
klass.arel_table[column_name].in(value)
when :in_all
klass.arel_table[column_name].in_all(value)
when :in_any
klass.arel_table[column_name].in_any(value)
when :lt
klass.arel_table[column_name].lt(value)
when :lt_all
klass.arel_table[column_name].lt_all(value)
when :lt_any
klass.arel_table[column_name].lt_any(value)
when :lteq
klass.arel_table[column_name].lteq(value)
when :lteq_all
klass.arel_table[column_name].lteq_all(value)
when :lteq_any
klass.arel_table[column_name].lteq_any(value)
when :ilike
klass.arel_table[column_name].matches("%#{value}%")
when :matches
klass.arel_table[column_name].matches(value)
when :matches_all
klass.arel_table[column_name].matches_all(value)
when :matches_any
klass.arel_table[column_name].matches_any(value)
when :not_between
klass.arel_table[column_name].not_between(value.first..value.last)
when :not_eq
klass.arel_table[column_name].not_eq(value)
when :not_eq_all
klass.arel_table[column_name].not_eq_all(value)
when :not_eq_any
klass.arel_table[column_name].not_eq_any(value)
when :not_in
klass.arel_table[column_name].not_in(value)
when :not_in_all
klass.arel_table[column_name].not_in_all(value)
when :not_in_any
klass.arel_table[column_name].not_in_any(value)
else
unless predicate.respond_to?(:call)
raise ArgumentError,
"unsupported predicate `#{predicate}`"
end
predicate.call(collection, value)
end
end
|
[
"def",
"predicates",
"(",
"predicate",
",",
"collection",
",",
"klass",
",",
"column_name",
",",
"value",
")",
"case",
"predicate",
"when",
":between",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"between",
"(",
"value",
".",
"first",
"..",
"value",
".",
"last",
")",
"when",
":does_not_match",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"does_not_match",
"(",
"\"%#{value}%\"",
")",
"when",
":does_not_match_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"does_not_match_all",
"(",
"value",
")",
"when",
":does_not_match_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"does_not_match_any",
"(",
"value",
")",
"when",
":eq",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"eq",
"(",
"value",
")",
"when",
":eq_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"eq_all",
"(",
"value",
")",
"when",
":eq_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"eq_any",
"(",
"value",
")",
"when",
":gt",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gt",
"(",
"value",
")",
"when",
":gt_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gt_all",
"(",
"value",
")",
"when",
":gt_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gt_any",
"(",
"value",
")",
"when",
":gteq",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gteq",
"(",
"value",
")",
"when",
":gteq_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gteq_all",
"(",
"value",
")",
"when",
":gteq_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"gteq_any",
"(",
"value",
")",
"when",
":in",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"in",
"(",
"value",
")",
"when",
":in_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"in_all",
"(",
"value",
")",
"when",
":in_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"in_any",
"(",
"value",
")",
"when",
":lt",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lt",
"(",
"value",
")",
"when",
":lt_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lt_all",
"(",
"value",
")",
"when",
":lt_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lt_any",
"(",
"value",
")",
"when",
":lteq",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lteq",
"(",
"value",
")",
"when",
":lteq_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lteq_all",
"(",
"value",
")",
"when",
":lteq_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"lteq_any",
"(",
"value",
")",
"when",
":ilike",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"matches",
"(",
"\"%#{value}%\"",
")",
"when",
":matches",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"matches",
"(",
"value",
")",
"when",
":matches_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"matches_all",
"(",
"value",
")",
"when",
":matches_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"matches_any",
"(",
"value",
")",
"when",
":not_between",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_between",
"(",
"value",
".",
"first",
"..",
"value",
".",
"last",
")",
"when",
":not_eq",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_eq",
"(",
"value",
")",
"when",
":not_eq_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_eq_all",
"(",
"value",
")",
"when",
":not_eq_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_eq_any",
"(",
"value",
")",
"when",
":not_in",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_in",
"(",
"value",
")",
"when",
":not_in_all",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_in_all",
"(",
"value",
")",
"when",
":not_in_any",
"klass",
".",
"arel_table",
"[",
"column_name",
"]",
".",
"not_in_any",
"(",
"value",
")",
"else",
"unless",
"predicate",
".",
"respond_to?",
"(",
":call",
")",
"raise",
"ArgumentError",
",",
"\"unsupported predicate `#{predicate}`\"",
"end",
"predicate",
".",
"call",
"(",
"collection",
",",
"value",
")",
"end",
"end"
] |
Apply arel predicate on collection
|
[
"Apply",
"arel",
"predicate",
"on",
"collection"
] |
ad19c38bc3978f4dc1c88ee6c301a09769c0f9f7
|
https://github.com/fabienpiette/fetcheable_on_api/blob/ad19c38bc3978f4dc1c88ee6c301a09769c0f9f7/lib/fetcheable_on_api/filterable.rb#L141-L217
|
18,093
|
ledbettj/systemd-journal
|
lib/systemd/journal_entry.rb
|
Systemd.JournalEntry.catalog
|
def catalog(opts = {})
return nil unless catalog?
opts[:replace] = true unless opts.key?(:replace)
cat = Systemd::Journal.catalog_for(self[:message_id])
# catalog_for does not do field substitution for us, so we do it here
# if requested
opts[:replace] ? field_substitute(cat) : cat
end
|
ruby
|
def catalog(opts = {})
return nil unless catalog?
opts[:replace] = true unless opts.key?(:replace)
cat = Systemd::Journal.catalog_for(self[:message_id])
# catalog_for does not do field substitution for us, so we do it here
# if requested
opts[:replace] ? field_substitute(cat) : cat
end
|
[
"def",
"catalog",
"(",
"opts",
"=",
"{",
"}",
")",
"return",
"nil",
"unless",
"catalog?",
"opts",
"[",
":replace",
"]",
"=",
"true",
"unless",
"opts",
".",
"key?",
"(",
":replace",
")",
"cat",
"=",
"Systemd",
"::",
"Journal",
".",
"catalog_for",
"(",
"self",
"[",
":message_id",
"]",
")",
"# catalog_for does not do field substitution for us, so we do it here",
"# if requested",
"opts",
"[",
":replace",
"]",
"?",
"field_substitute",
"(",
"cat",
")",
":",
"cat",
"end"
] |
Returns the catalog message that this Journal Entry references, if any.
@option opts [Boolean] :replace set to false to not replace placeholder
strings in the catalog with the associated values in this Journal Entry.
defaults to true.
@return [String] the catalog provided message for this Journal Entry, or
nil if non exists.
|
[
"Returns",
"the",
"catalog",
"message",
"that",
"this",
"Journal",
"Entry",
"references",
"if",
"any",
"."
] |
823ac01a88da58fd3e703076b1d6e918aba73522
|
https://github.com/ledbettj/systemd-journal/blob/823ac01a88da58fd3e703076b1d6e918aba73522/lib/systemd/journal_entry.rb#L71-L80
|
18,094
|
ledbettj/systemd-journal
|
lib/systemd/journal.rb
|
Systemd.Journal.query_unique
|
def query_unique(field)
results = []
Native.sd_journal_restart_unique(@ptr)
rc = Native.sd_journal_query_unique(@ptr, field.to_s.upcase)
raise JournalError, rc if rc < 0
while (kvpair = enumerate_helper(:sd_journal_enumerate_unique))
results << kvpair.last
end
results
end
|
ruby
|
def query_unique(field)
results = []
Native.sd_journal_restart_unique(@ptr)
rc = Native.sd_journal_query_unique(@ptr, field.to_s.upcase)
raise JournalError, rc if rc < 0
while (kvpair = enumerate_helper(:sd_journal_enumerate_unique))
results << kvpair.last
end
results
end
|
[
"def",
"query_unique",
"(",
"field",
")",
"results",
"=",
"[",
"]",
"Native",
".",
"sd_journal_restart_unique",
"(",
"@ptr",
")",
"rc",
"=",
"Native",
".",
"sd_journal_query_unique",
"(",
"@ptr",
",",
"field",
".",
"to_s",
".",
"upcase",
")",
"raise",
"JournalError",
",",
"rc",
"if",
"rc",
"<",
"0",
"while",
"(",
"kvpair",
"=",
"enumerate_helper",
"(",
":sd_journal_enumerate_unique",
")",
")",
"results",
"<<",
"kvpair",
".",
"last",
"end",
"results",
"end"
] |
Get the list of unique values stored in the journal for the given field.
If passed a block, each possible value will be yielded.
@return [Array] the list of possible values.
@example Fetch all possible boot ids from the journal
j = Systemd::Journal.new
j.query_unique('_BOOT_ID')
|
[
"Get",
"the",
"list",
"of",
"unique",
"values",
"stored",
"in",
"the",
"journal",
"for",
"the",
"given",
"field",
".",
"If",
"passed",
"a",
"block",
"each",
"possible",
"value",
"will",
"be",
"yielded",
"."
] |
823ac01a88da58fd3e703076b1d6e918aba73522
|
https://github.com/ledbettj/systemd-journal/blob/823ac01a88da58fd3e703076b1d6e918aba73522/lib/systemd/journal.rb#L155-L168
|
18,095
|
ledbettj/systemd-journal
|
lib/systemd/journal.rb
|
Systemd.Journal.data_threshold
|
def data_threshold
size_ptr = FFI::MemoryPointer.new(:size_t, 1)
if (rc = Native.sd_journal_get_data_threshold(@ptr, size_ptr)) < 0
raise JournalError, rc
end
size_ptr.read_size_t
end
|
ruby
|
def data_threshold
size_ptr = FFI::MemoryPointer.new(:size_t, 1)
if (rc = Native.sd_journal_get_data_threshold(@ptr, size_ptr)) < 0
raise JournalError, rc
end
size_ptr.read_size_t
end
|
[
"def",
"data_threshold",
"size_ptr",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"new",
"(",
":size_t",
",",
"1",
")",
"if",
"(",
"rc",
"=",
"Native",
".",
"sd_journal_get_data_threshold",
"(",
"@ptr",
",",
"size_ptr",
")",
")",
"<",
"0",
"raise",
"JournalError",
",",
"rc",
"end",
"size_ptr",
".",
"read_size_t",
"end"
] |
Get the maximum length of a data field that will be returned.
Fields longer than this will be truncated. Default is 64K.
@return [Integer] size in bytes.
|
[
"Get",
"the",
"maximum",
"length",
"of",
"a",
"data",
"field",
"that",
"will",
"be",
"returned",
".",
"Fields",
"longer",
"than",
"this",
"will",
"be",
"truncated",
".",
"Default",
"is",
"64K",
"."
] |
823ac01a88da58fd3e703076b1d6e918aba73522
|
https://github.com/ledbettj/systemd-journal/blob/823ac01a88da58fd3e703076b1d6e918aba73522/lib/systemd/journal.rb#L186-L193
|
18,096
|
documentcloud/cloud-crowd
|
lib/cloud_crowd/action.rb
|
CloudCrowd.Action.download
|
def download(url, path)
if url.match(FILE_URL)
FileUtils.cp(url.sub(FILE_URL, ''), path)
else
File.open(path, 'w+') do |file|
Net::HTTP.get_response(URI(url)) do |response|
response.read_body do |chunk|
file.write chunk
end
end
end
end
path
end
|
ruby
|
def download(url, path)
if url.match(FILE_URL)
FileUtils.cp(url.sub(FILE_URL, ''), path)
else
File.open(path, 'w+') do |file|
Net::HTTP.get_response(URI(url)) do |response|
response.read_body do |chunk|
file.write chunk
end
end
end
end
path
end
|
[
"def",
"download",
"(",
"url",
",",
"path",
")",
"if",
"url",
".",
"match",
"(",
"FILE_URL",
")",
"FileUtils",
".",
"cp",
"(",
"url",
".",
"sub",
"(",
"FILE_URL",
",",
"''",
")",
",",
"path",
")",
"else",
"File",
".",
"open",
"(",
"path",
",",
"'w+'",
")",
"do",
"|",
"file",
"|",
"Net",
"::",
"HTTP",
".",
"get_response",
"(",
"URI",
"(",
"url",
")",
")",
"do",
"|",
"response",
"|",
"response",
".",
"read_body",
"do",
"|",
"chunk",
"|",
"file",
".",
"write",
"chunk",
"end",
"end",
"end",
"end",
"path",
"end"
] |
Download a file to the specified path.
|
[
"Download",
"a",
"file",
"to",
"the",
"specified",
"path",
"."
] |
a66172eabc6cb526b27be2bb821e2ea4258c82d4
|
https://github.com/documentcloud/cloud-crowd/blob/a66172eabc6cb526b27be2bb821e2ea4258c82d4/lib/cloud_crowd/action.rb#L44-L57
|
18,097
|
documentcloud/cloud-crowd
|
lib/cloud_crowd/action.rb
|
CloudCrowd.Action.`
|
def `(command)
result = super(command)
exit_code = $?.to_i
raise Error::CommandFailed.new(result, exit_code) unless exit_code == 0
result
end
|
ruby
|
def `(command)
result = super(command)
exit_code = $?.to_i
raise Error::CommandFailed.new(result, exit_code) unless exit_code == 0
result
end
|
[
"def",
"`",
"(",
"command",
")",
"result",
"=",
"super",
"(",
"command",
")",
"exit_code",
"=",
"$?",
".",
"to_i",
"raise",
"Error",
"::",
"CommandFailed",
".",
"new",
"(",
"result",
",",
"exit_code",
")",
"unless",
"exit_code",
"==",
"0",
"result",
"end"
] |
Actions have a backticks command that raises a CommandFailed exception
on failure, so that processing doesn't just blithely continue.
|
[
"Actions",
"have",
"a",
"backticks",
"command",
"that",
"raises",
"a",
"CommandFailed",
"exception",
"on",
"failure",
"so",
"that",
"processing",
"doesn",
"t",
"just",
"blithely",
"continue",
"."
] |
a66172eabc6cb526b27be2bb821e2ea4258c82d4
|
https://github.com/documentcloud/cloud-crowd/blob/a66172eabc6cb526b27be2bb821e2ea4258c82d4/lib/cloud_crowd/action.rb#L74-L79
|
18,098
|
documentcloud/cloud-crowd
|
lib/cloud_crowd/action.rb
|
CloudCrowd.Action.safe_filename
|
def safe_filename(url)
url = url.sub(/\?.*\Z/, '')
ext = File.extname(url)
name = URI.unescape(File.basename(url)).gsub(/[^a-zA-Z0-9_\-.]/, '-').gsub(/-+/, '-')
File.basename(name, ext).gsub('.', '-') + ext
end
|
ruby
|
def safe_filename(url)
url = url.sub(/\?.*\Z/, '')
ext = File.extname(url)
name = URI.unescape(File.basename(url)).gsub(/[^a-zA-Z0-9_\-.]/, '-').gsub(/-+/, '-')
File.basename(name, ext).gsub('.', '-') + ext
end
|
[
"def",
"safe_filename",
"(",
"url",
")",
"url",
"=",
"url",
".",
"sub",
"(",
"/",
"\\?",
"\\Z",
"/",
",",
"''",
")",
"ext",
"=",
"File",
".",
"extname",
"(",
"url",
")",
"name",
"=",
"URI",
".",
"unescape",
"(",
"File",
".",
"basename",
"(",
"url",
")",
")",
".",
"gsub",
"(",
"/",
"\\-",
"/",
",",
"'-'",
")",
".",
"gsub",
"(",
"/",
"/",
",",
"'-'",
")",
"File",
".",
"basename",
"(",
"name",
",",
"ext",
")",
".",
"gsub",
"(",
"'.'",
",",
"'-'",
")",
"+",
"ext",
"end"
] |
Convert an unsafe URL into a filesystem-friendly filename.
|
[
"Convert",
"an",
"unsafe",
"URL",
"into",
"a",
"filesystem",
"-",
"friendly",
"filename",
"."
] |
a66172eabc6cb526b27be2bb821e2ea4258c82d4
|
https://github.com/documentcloud/cloud-crowd/blob/a66172eabc6cb526b27be2bb821e2ea4258c82d4/lib/cloud_crowd/action.rb#L85-L90
|
18,099
|
documentcloud/cloud-crowd
|
lib/cloud_crowd/action.rb
|
CloudCrowd.Action.download_input
|
def download_input
return unless input_is_url?
Dir.chdir(@work_directory) do
@input_path = File.join(@work_directory, safe_filename(@input))
@file_name = File.basename(@input_path, File.extname(@input_path))
download(@input, @input_path)
end
end
|
ruby
|
def download_input
return unless input_is_url?
Dir.chdir(@work_directory) do
@input_path = File.join(@work_directory, safe_filename(@input))
@file_name = File.basename(@input_path, File.extname(@input_path))
download(@input, @input_path)
end
end
|
[
"def",
"download_input",
"return",
"unless",
"input_is_url?",
"Dir",
".",
"chdir",
"(",
"@work_directory",
")",
"do",
"@input_path",
"=",
"File",
".",
"join",
"(",
"@work_directory",
",",
"safe_filename",
"(",
"@input",
")",
")",
"@file_name",
"=",
"File",
".",
"basename",
"(",
"@input_path",
",",
"File",
".",
"extname",
"(",
"@input_path",
")",
")",
"download",
"(",
"@input",
",",
"@input_path",
")",
"end",
"end"
] |
If the input is a URL, download the file before beginning processing.
|
[
"If",
"the",
"input",
"is",
"a",
"URL",
"download",
"the",
"file",
"before",
"beginning",
"processing",
"."
] |
a66172eabc6cb526b27be2bb821e2ea4258c82d4
|
https://github.com/documentcloud/cloud-crowd/blob/a66172eabc6cb526b27be2bb821e2ea4258c82d4/lib/cloud_crowd/action.rb#L118-L125
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.