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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
wooandoo/motion-pool | motion/common/term.rb | Term.ANSIColor.uncolored | def uncolored(string = nil) # :yields:
if block_given?
yield.gsub(COLORED_REGEXP, '')
elsif string
string.gsub(COLORED_REGEXP, '')
elsif respond_to?(:to_str)
gsub(COLORED_REGEXP, '')
else
''
end
end | ruby | def uncolored(string = nil) # :yields:
if block_given?
yield.gsub(COLORED_REGEXP, '')
elsif string
string.gsub(COLORED_REGEXP, '')
elsif respond_to?(:to_str)
gsub(COLORED_REGEXP, '')
else
''
end
end | [
"def",
"uncolored",
"(",
"string",
"=",
"nil",
")",
"if",
"block_given?",
"yield",
".",
"gsub",
"(",
"COLORED_REGEXP",
",",
"''",
")",
"elsif",
"string",
"string",
".",
"gsub",
"(",
"COLORED_REGEXP",
",",
"''",
")",
"elsif",
"respond_to?",
"(",
":to_str",
")",
"gsub",
"(",
"COLORED_REGEXP",
",",
"''",
")",
"else",
"''",
"end",
"end"
] | Returns an uncolored version of the string, that is all
ANSI-sequences are stripped from the string. | [
"Returns",
"an",
"uncolored",
"version",
"of",
"the",
"string",
"that",
"is",
"all",
"ANSI",
"-",
"sequences",
"are",
"stripped",
"from",
"the",
"string",
"."
] | e0a8b56a096e7bcf90a60d3ae0f62018e92dcf2b | https://github.com/wooandoo/motion-pool/blob/e0a8b56a096e7bcf90a60d3ae0f62018e92dcf2b/motion/common/term.rb#L536-L546 | train |
riddopic/garcun | lib/garcon/task/atomic.rb | Garcon.AtomicDirectUpdate.try_update | def try_update
old_value = get
new_value = yield old_value
unless compare_and_set(old_value, new_value)
raise ConcurrentUpdateError, "Update failed"
end
new_value
end | ruby | def try_update
old_value = get
new_value = yield old_value
unless compare_and_set(old_value, new_value)
raise ConcurrentUpdateError, "Update failed"
end
new_value
end | [
"def",
"try_update",
"old_value",
"=",
"get",
"new_value",
"=",
"yield",
"old_value",
"unless",
"compare_and_set",
"(",
"old_value",
",",
"new_value",
")",
"raise",
"ConcurrentUpdateError",
",",
"\"Update failed\"",
"end",
"new_value",
"end"
] | Pass the current value to the given block, replacing it with the block's
result. Raise an exception if the update fails.
@yield [Object]
Calculate a new value for the atomic reference using given (old) value.
@yieldparam [Object] old_value
The starting value of the atomic reference.
@raise [Garcon::ConcurrentUpdateError]
If the update fails
@return [Object] the new value | [
"Pass",
"the",
"current",
"value",
"to",
"the",
"given",
"block",
"replacing",
"it",
"with",
"the",
"block",
"s",
"result",
".",
"Raise",
"an",
"exception",
"if",
"the",
"update",
"fails",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/atomic.rb#L51-L58 | train |
riddopic/garcun | lib/garcon/task/atomic.rb | Garcon.AtomicMutex._compare_and_set | def _compare_and_set(old_value, new_value)
return false unless @mutex.try_lock
begin
return false unless @value.equal? old_value
@value = new_value
ensure
@mutex.unlock
end
true
end | ruby | def _compare_and_set(old_value, new_value)
return false unless @mutex.try_lock
begin
return false unless @value.equal? old_value
@value = new_value
ensure
@mutex.unlock
end
true
end | [
"def",
"_compare_and_set",
"(",
"old_value",
",",
"new_value",
")",
"return",
"false",
"unless",
"@mutex",
".",
"try_lock",
"begin",
"return",
"false",
"unless",
"@value",
".",
"equal?",
"old_value",
"@value",
"=",
"new_value",
"ensure",
"@mutex",
".",
"unlock",
"end",
"true",
"end"
] | Atomically sets the value to the given updated value if the current value
is equal the expected value.
@param [Object] old_value
The expected value.
@param [Object] new_value
The new value.
@return [Boolean]
`true` if successful, `false` indicates that the actual value was not
equal to the expected value. | [
"Atomically",
"sets",
"the",
"value",
"to",
"the",
"given",
"updated",
"value",
"if",
"the",
"current",
"value",
"is",
"equal",
"the",
"expected",
"value",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/atomic.rb#L140-L149 | train |
avdgaag/whenner | lib/whenner/deferred.rb | Whenner.Deferred.fulfill | def fulfill(value = nil)
raise CannotTransitionError if rejected?
return if fulfilled?
unless resolved?
self.value = value
resolve_to(:fulfilled)
end
self
end | ruby | def fulfill(value = nil)
raise CannotTransitionError if rejected?
return if fulfilled?
unless resolved?
self.value = value
resolve_to(:fulfilled)
end
self
end | [
"def",
"fulfill",
"(",
"value",
"=",
"nil",
")",
"raise",
"CannotTransitionError",
"if",
"rejected?",
"return",
"if",
"fulfilled?",
"unless",
"resolved?",
"self",
".",
"value",
"=",
"value",
"resolve_to",
"(",
":fulfilled",
")",
"end",
"self",
"end"
] | Fulfill this promise with an optional value. The value will be stored in
the deferred and passed along to any registered `done` callbacks.
When fulfilling a deferred twice, nothing happens.
@raise [CannotTransitionError] when it was already fulfilled.
@return [Deferred] self | [
"Fulfill",
"this",
"promise",
"with",
"an",
"optional",
"value",
".",
"The",
"value",
"will",
"be",
"stored",
"in",
"the",
"deferred",
"and",
"passed",
"along",
"to",
"any",
"registered",
"done",
"callbacks",
"."
] | f27331435402648d02377bef9fce9ff8ae84845a | https://github.com/avdgaag/whenner/blob/f27331435402648d02377bef9fce9ff8ae84845a/lib/whenner/deferred.rb#L76-L84 | train |
avdgaag/whenner | lib/whenner/deferred.rb | Whenner.Deferred.reject | def reject(reason = nil)
raise CannotTransitionError if fulfilled?
return if rejected?
unless resolved?
self.reason = reason
resolve_to(:rejected)
end
self
end | ruby | def reject(reason = nil)
raise CannotTransitionError if fulfilled?
return if rejected?
unless resolved?
self.reason = reason
resolve_to(:rejected)
end
self
end | [
"def",
"reject",
"(",
"reason",
"=",
"nil",
")",
"raise",
"CannotTransitionError",
"if",
"fulfilled?",
"return",
"if",
"rejected?",
"unless",
"resolved?",
"self",
".",
"reason",
"=",
"reason",
"resolve_to",
"(",
":rejected",
")",
"end",
"self",
"end"
] | Reject this promise with an optional reason. The reason will be stored in
the deferred and passed along to any registered `fail` callbacks.
When rejecting a deferred twice, nothing happens.
@raise [CannotTransitionError] when it was already fulfilled.
@return [Deferred] self | [
"Reject",
"this",
"promise",
"with",
"an",
"optional",
"reason",
".",
"The",
"reason",
"will",
"be",
"stored",
"in",
"the",
"deferred",
"and",
"passed",
"along",
"to",
"any",
"registered",
"fail",
"callbacks",
"."
] | f27331435402648d02377bef9fce9ff8ae84845a | https://github.com/avdgaag/whenner/blob/f27331435402648d02377bef9fce9ff8ae84845a/lib/whenner/deferred.rb#L93-L101 | train |
avdgaag/whenner | lib/whenner/deferred.rb | Whenner.Deferred.fail | def fail(&block)
cb = Callback.new(block)
rejected_callbacks << cb
cb.call(*callback_response) if rejected?
cb.promise
end | ruby | def fail(&block)
cb = Callback.new(block)
rejected_callbacks << cb
cb.call(*callback_response) if rejected?
cb.promise
end | [
"def",
"fail",
"(",
"&",
"block",
")",
"cb",
"=",
"Callback",
".",
"new",
"(",
"block",
")",
"rejected_callbacks",
"<<",
"cb",
"cb",
".",
"call",
"(",
"*",
"callback_response",
")",
"if",
"rejected?",
"cb",
".",
"promise",
"end"
] | Register a callback to be run when the deferred is rejected.
@yieldparam [Object] reason
@return [Promise] a new promise representing the return value
of the callback, or -- when that return value is a promise itself
-- a promise mimicking that promise. | [
"Register",
"a",
"callback",
"to",
"be",
"run",
"when",
"the",
"deferred",
"is",
"rejected",
"."
] | f27331435402648d02377bef9fce9ff8ae84845a | https://github.com/avdgaag/whenner/blob/f27331435402648d02377bef9fce9ff8ae84845a/lib/whenner/deferred.rb#L147-L152 | train |
avdgaag/whenner | lib/whenner/deferred.rb | Whenner.Deferred.always | def always(&block)
cb = Callback.new(block)
always_callbacks << cb
cb.call(*callback_response) if resolved?
cb.promise
end | ruby | def always(&block)
cb = Callback.new(block)
always_callbacks << cb
cb.call(*callback_response) if resolved?
cb.promise
end | [
"def",
"always",
"(",
"&",
"block",
")",
"cb",
"=",
"Callback",
".",
"new",
"(",
"block",
")",
"always_callbacks",
"<<",
"cb",
"cb",
".",
"call",
"(",
"*",
"callback_response",
")",
"if",
"resolved?",
"cb",
".",
"promise",
"end"
] | Register a callback to be run when the deferred is resolved.
@yieldparam [Object] value
@yieldparam [Object] reason
@return [Promise] a new promise representing the return value
of the callback, or -- when that return value is a promise itself
-- a promise mimicking that promise. | [
"Register",
"a",
"callback",
"to",
"be",
"run",
"when",
"the",
"deferred",
"is",
"resolved",
"."
] | f27331435402648d02377bef9fce9ff8ae84845a | https://github.com/avdgaag/whenner/blob/f27331435402648d02377bef9fce9ff8ae84845a/lib/whenner/deferred.rb#L161-L166 | train |
garytaylor/capybara_objects | lib/capybara_objects/scoped_finders.rb | CapybaraObjects.ScopedFinders.get_component | def get_component(ctype, *args)
registry.lookup_ctype(ctype).new(*args).tap do |comp|
comp.scope = full_scope
comp.validate!
end
end | ruby | def get_component(ctype, *args)
registry.lookup_ctype(ctype).new(*args).tap do |comp|
comp.scope = full_scope
comp.validate!
end
end | [
"def",
"get_component",
"(",
"ctype",
",",
"*",
"args",
")",
"registry",
".",
"lookup_ctype",
"(",
"ctype",
")",
".",
"new",
"(",
"*",
"args",
")",
".",
"tap",
"do",
"|",
"comp",
"|",
"comp",
".",
"scope",
"=",
"full_scope",
"comp",
".",
"validate!",
"end",
"end"
] | Fetch a component from within this component
@TODO Make this operate within the scope
@TODO Pass the scope on to any found instances
@param [String|Symbol] ctype The component alias to find
@param [Any] args Any further arguments are passed on to the instance of the component
@return [CapybaraObjects::ComponentObject] An instance inheriting from the component object | [
"Fetch",
"a",
"component",
"from",
"within",
"this",
"component"
] | 7cc2998400a35ceb6f9354cdf949fc59eddcdb12 | https://github.com/garytaylor/capybara_objects/blob/7cc2998400a35ceb6f9354cdf949fc59eddcdb12/lib/capybara_objects/scoped_finders.rb#L12-L17 | train |
AvnerCohen/service-jynx | lib/service_jynx.rb | ServiceJynx.Jynx.clean_aged | def clean_aged(time_now)
near_past = time_now - @time_window_in_seconds
@errors = @errors.reverse.select{|time_stamp| time_stamp > near_past }.reverse.to_a
end | ruby | def clean_aged(time_now)
near_past = time_now - @time_window_in_seconds
@errors = @errors.reverse.select{|time_stamp| time_stamp > near_past }.reverse.to_a
end | [
"def",
"clean_aged",
"(",
"time_now",
")",
"near_past",
"=",
"time_now",
"-",
"@time_window_in_seconds",
"@errors",
"=",
"@errors",
".",
"reverse",
".",
"select",
"{",
"|",
"time_stamp",
"|",
"time_stamp",
">",
"near_past",
"}",
".",
"reverse",
".",
"to_a",
"end"
] | clean up errors that are older than time_window_in_secons | [
"clean",
"up",
"errors",
"that",
"are",
"older",
"than",
"time_window_in_secons"
] | 01f21aee273d12021d20e5d7b97e13ec6b9bc291 | https://github.com/AvnerCohen/service-jynx/blob/01f21aee273d12021d20e5d7b97e13ec6b9bc291/lib/service_jynx.rb#L63-L66 | train |
ErikSchlyter/rspec-illustrate | lib/rspec/illustrate.rb | RSpec.Illustrate.illustrate | def illustrate(content, *args)
illustration = { :text => content.to_s,
:show_when_passed => true,
:show_when_failed => true,
:show_when_pending => true }
args.each{|arg|
illustration[arg] = true if arg.is_a?(Symbol)
illustration.merge!(arg) if arg.kind_of?(Hash)
}
RSpec.current_example.metadata[:illustrations] << illustration
content
end | ruby | def illustrate(content, *args)
illustration = { :text => content.to_s,
:show_when_passed => true,
:show_when_failed => true,
:show_when_pending => true }
args.each{|arg|
illustration[arg] = true if arg.is_a?(Symbol)
illustration.merge!(arg) if arg.kind_of?(Hash)
}
RSpec.current_example.metadata[:illustrations] << illustration
content
end | [
"def",
"illustrate",
"(",
"content",
",",
"*",
"args",
")",
"illustration",
"=",
"{",
":text",
"=>",
"content",
".",
"to_s",
",",
":show_when_passed",
"=>",
"true",
",",
":show_when_failed",
"=>",
"true",
",",
":show_when_pending",
"=>",
"true",
"}",
"args",
".",
"each",
"{",
"|",
"arg",
"|",
"illustration",
"[",
"arg",
"]",
"=",
"true",
"if",
"arg",
".",
"is_a?",
"(",
"Symbol",
")",
"illustration",
".",
"merge!",
"(",
"arg",
")",
"if",
"arg",
".",
"kind_of?",
"(",
"Hash",
")",
"}",
"RSpec",
".",
"current_example",
".",
"metadata",
"[",
":illustrations",
"]",
"<<",
"illustration",
"content",
"end"
] | Stores an object in the surrounding example's metadata, which can be used
by the output formatter as an illustration for the example.
@param content The object that will act as an illustration.
@param args [Array<Hash, Symbol>] Additional options.
@return The given illustration object. | [
"Stores",
"an",
"object",
"in",
"the",
"surrounding",
"example",
"s",
"metadata",
"which",
"can",
"be",
"used",
"by",
"the",
"output",
"formatter",
"as",
"an",
"illustration",
"for",
"the",
"example",
"."
] | f9275bdb5cc86642bee187acf327ee3c3d311577 | https://github.com/ErikSchlyter/rspec-illustrate/blob/f9275bdb5cc86642bee187acf327ee3c3d311577/lib/rspec/illustrate.rb#L14-L27 | train |
avdgaag/observatory | lib/observatory/dispatcher.rb | Observatory.Dispatcher.connect | def connect(signal, *args, &block)
# ugly argument parsing.
# Make sure that there is either a block given, or that the second argument is
# something callable. If there is a block given, the second argument, if given,
# must be a Hash which defaults to an empty Hash. If there is no block given,
# the third optional argument must be Hash.
if block_given?
observer = block
if args.size == 1 && args.first.is_a?(Hash)
options = args.first
elsif args.size == 0
options = {}
else
raise ArgumentError, 'When given a block, #connect only expects a signal and options hash as arguments'
end
else
observer = args.shift
raise ArgumentError, 'Use a block, method or proc to specify an observer' unless observer.respond_to?(:call)
if args.any?
options = args.shift
raise ArgumentError, '#connect only expects a signal, method and options hash as arguments' unless options.is_a?(Hash) || args.any?
else
options = {}
end
end
# Initialize the list of observers for this signal and add this observer
observers[signal] ||= Stack.new
observers[signal].push(observer, options[:priority])
end | ruby | def connect(signal, *args, &block)
# ugly argument parsing.
# Make sure that there is either a block given, or that the second argument is
# something callable. If there is a block given, the second argument, if given,
# must be a Hash which defaults to an empty Hash. If there is no block given,
# the third optional argument must be Hash.
if block_given?
observer = block
if args.size == 1 && args.first.is_a?(Hash)
options = args.first
elsif args.size == 0
options = {}
else
raise ArgumentError, 'When given a block, #connect only expects a signal and options hash as arguments'
end
else
observer = args.shift
raise ArgumentError, 'Use a block, method or proc to specify an observer' unless observer.respond_to?(:call)
if args.any?
options = args.shift
raise ArgumentError, '#connect only expects a signal, method and options hash as arguments' unless options.is_a?(Hash) || args.any?
else
options = {}
end
end
# Initialize the list of observers for this signal and add this observer
observers[signal] ||= Stack.new
observers[signal].push(observer, options[:priority])
end | [
"def",
"connect",
"(",
"signal",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"block_given?",
"observer",
"=",
"block",
"if",
"args",
".",
"size",
"==",
"1",
"&&",
"args",
".",
"first",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"args",
".",
"first",
"elsif",
"args",
".",
"size",
"==",
"0",
"options",
"=",
"{",
"}",
"else",
"raise",
"ArgumentError",
",",
"'When given a block, #connect only expects a signal and options hash as arguments'",
"end",
"else",
"observer",
"=",
"args",
".",
"shift",
"raise",
"ArgumentError",
",",
"'Use a block, method or proc to specify an observer'",
"unless",
"observer",
".",
"respond_to?",
"(",
":call",
")",
"if",
"args",
".",
"any?",
"options",
"=",
"args",
".",
"shift",
"raise",
"ArgumentError",
",",
"'#connect only expects a signal, method and options hash as arguments'",
"unless",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"||",
"args",
".",
"any?",
"else",
"options",
"=",
"{",
"}",
"end",
"end",
"observers",
"[",
"signal",
"]",
"||=",
"Stack",
".",
"new",
"observers",
"[",
"signal",
"]",
".",
"push",
"(",
"observer",
",",
"options",
"[",
":priority",
"]",
")",
"end"
] | Register a observer for a given signal.
Instead of adding a method or Proc object to the stack, you could
also use a block. Either the observer argument or the block is required.
Optionally, you could pass in an options hash as the last argument, that
can specify an explicit priority. When omitted, an internal counter starting
from 1 will be used. To make sure your observer is called last, specify
a high, **positive** number. To make sure your observer is called first, specify
a high, **negative** number.
@example Using a block as an observer
dispatcher.connect('post.publish') do |event|
puts "Post was published"
end
@example Using a method as an observer
class Reporter
def log(event)
puts "Post published"
end
end
dispatcher.connect('post.publish', Reporter.new.method(:log))
@example Determining observer call order using priority
dispatcher.connect('pulp', :priority => 10) do
puts "I dare you!"
end
dispatcher.connect('pulp', :priority => -10) do
puts "I double-dare you!"
end
# output when "pulp" is triggered:
"I double-dare you!"
"I dare you!"
@overload connect(signal, observer, options = {})
@param [String] signal is the name used by the observable to trigger
observers
@param [#call] observer is the Proc or method that will react to
an event issued by an observable.
@param [Hash] options is an optional Hash of additional options.
@option options [Fixnum] :priority is the priority of this observer
in the stack of all observers for this signal. A higher number means
lower priority. Negative numbers are allowed.
@overload connect(signal, options = {}, &block)
@param [String] signal is the name used by the observable to trigger
observers
@param [Hash] options is an optional Hash of additional options.
@option options [Fixnum] :priority is the priority of this observer
in the stack of all observers for this signal. A higher number means
lower priority. Negative numbers are allowed.
@return [#call] the added observer | [
"Register",
"a",
"observer",
"for",
"a",
"given",
"signal",
"."
] | af8fdb445c42f425067ac97c39fcdbef5ebac73e | https://github.com/avdgaag/observatory/blob/af8fdb445c42f425067ac97c39fcdbef5ebac73e/lib/observatory/dispatcher.rb#L132-L161 | train |
avdgaag/observatory | lib/observatory/dispatcher.rb | Observatory.Dispatcher.disconnect | def disconnect(signal, observer)
return nil unless observers.key?(signal)
observers[signal].delete(observer)
end | ruby | def disconnect(signal, observer)
return nil unless observers.key?(signal)
observers[signal].delete(observer)
end | [
"def",
"disconnect",
"(",
"signal",
",",
"observer",
")",
"return",
"nil",
"unless",
"observers",
".",
"key?",
"(",
"signal",
")",
"observers",
"[",
"signal",
"]",
".",
"delete",
"(",
"observer",
")",
"end"
] | Removes an observer from a signal stack, so it no longer gets triggered.
@param [String] signal is the name of the stack to remove the observer
from.
@param [#call] observer is the original observer to remove.
@return [#call, nil] the removed observer or nil if it could not be found | [
"Removes",
"an",
"observer",
"from",
"a",
"signal",
"stack",
"so",
"it",
"no",
"longer",
"gets",
"triggered",
"."
] | af8fdb445c42f425067ac97c39fcdbef5ebac73e | https://github.com/avdgaag/observatory/blob/af8fdb445c42f425067ac97c39fcdbef5ebac73e/lib/observatory/dispatcher.rb#L169-L172 | train |
wedesoft/multiarray | lib/multiarray/gcctype.rb | Hornetseye.GCCType.identifier | def identifier
case @typecode
when nil
'void'
when BOOL
'char'
when BYTE
'char'
when UBYTE
'unsigned char'
when SINT
'short int'
when USINT
'unsigned short int'
when INT
'int'
when UINT
'unsigned int'
when SFLOAT
'float'
when DFLOAT
'double'
else
if @typecode < Pointer_
'unsigned char *'
elsif @typecode < INDEX_
'int'
else
raise "No identifier available for #{@typecode.inspect}"
end
end
end | ruby | def identifier
case @typecode
when nil
'void'
when BOOL
'char'
when BYTE
'char'
when UBYTE
'unsigned char'
when SINT
'short int'
when USINT
'unsigned short int'
when INT
'int'
when UINT
'unsigned int'
when SFLOAT
'float'
when DFLOAT
'double'
else
if @typecode < Pointer_
'unsigned char *'
elsif @typecode < INDEX_
'int'
else
raise "No identifier available for #{@typecode.inspect}"
end
end
end | [
"def",
"identifier",
"case",
"@typecode",
"when",
"nil",
"'void'",
"when",
"BOOL",
"'char'",
"when",
"BYTE",
"'char'",
"when",
"UBYTE",
"'unsigned char'",
"when",
"SINT",
"'short int'",
"when",
"USINT",
"'unsigned short int'",
"when",
"INT",
"'int'",
"when",
"UINT",
"'unsigned int'",
"when",
"SFLOAT",
"'float'",
"when",
"DFLOAT",
"'double'",
"else",
"if",
"@typecode",
"<",
"Pointer_",
"'unsigned char *'",
"elsif",
"@typecode",
"<",
"INDEX_",
"'int'",
"else",
"raise",
"\"No identifier available for #{@typecode.inspect}\"",
"end",
"end",
"end"
] | Construct GCC type
@param [Class] typecode Native type (e.g. +UBYTE+).
@private
Get C identifier for native type
@return [String] String with valid C syntax to declare type.
@private | [
"Construct",
"GCC",
"type"
] | 1ae1d98bacb4b941d6f406e44ccb184de12f83d9 | https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/gcctype.rb#L39-L70 | train |
wedesoft/multiarray | lib/multiarray/gcctype.rb | Hornetseye.GCCType.identifiers | def identifiers
if @typecode < Composite
GCCType.new( @typecode.element_type ).identifiers * @typecode.num_elements
else
[ GCCType.new( @typecode ).identifier ]
end
end | ruby | def identifiers
if @typecode < Composite
GCCType.new( @typecode.element_type ).identifiers * @typecode.num_elements
else
[ GCCType.new( @typecode ).identifier ]
end
end | [
"def",
"identifiers",
"if",
"@typecode",
"<",
"Composite",
"GCCType",
".",
"new",
"(",
"@typecode",
".",
"element_type",
")",
".",
"identifiers",
"*",
"@typecode",
".",
"num_elements",
"else",
"[",
"GCCType",
".",
"new",
"(",
"@typecode",
")",
".",
"identifier",
"]",
"end",
"end"
] | Get array of C identifiers for native type
@return [Array<String>] Array of C declarations for the elements of the type.
@private | [
"Get",
"array",
"of",
"C",
"identifiers",
"for",
"native",
"type"
] | 1ae1d98bacb4b941d6f406e44ccb184de12f83d9 | https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/gcctype.rb#L77-L83 | train |
wedesoft/multiarray | lib/multiarray/gcctype.rb | Hornetseye.GCCType.r2c | def r2c
case @typecode
when BOOL
[ proc { |expr| "( #{expr} ) != Qfalse" } ]
when BYTE, UBYTE, SINT, USINT, INT, UINT
[ proc { |expr| "NUM2INT( #{expr} )" } ]
when SFLOAT, DFLOAT
[ proc { |expr| "NUM2DBL( #{expr} )" } ]
else
if @typecode < Pointer_
[ proc { |expr| "(#{identifier})mallocToPtr( #{expr} )" } ]
elsif @typecode < Composite
GCCType.new( @typecode.element_type ).r2c * @typecode.num_elements
else
raise "No conversion available for #{@typecode.inspect}"
end
end
end | ruby | def r2c
case @typecode
when BOOL
[ proc { |expr| "( #{expr} ) != Qfalse" } ]
when BYTE, UBYTE, SINT, USINT, INT, UINT
[ proc { |expr| "NUM2INT( #{expr} )" } ]
when SFLOAT, DFLOAT
[ proc { |expr| "NUM2DBL( #{expr} )" } ]
else
if @typecode < Pointer_
[ proc { |expr| "(#{identifier})mallocToPtr( #{expr} )" } ]
elsif @typecode < Composite
GCCType.new( @typecode.element_type ).r2c * @typecode.num_elements
else
raise "No conversion available for #{@typecode.inspect}"
end
end
end | [
"def",
"r2c",
"case",
"@typecode",
"when",
"BOOL",
"[",
"proc",
"{",
"|",
"expr",
"|",
"\"( #{expr} ) != Qfalse\"",
"}",
"]",
"when",
"BYTE",
",",
"UBYTE",
",",
"SINT",
",",
"USINT",
",",
"INT",
",",
"UINT",
"[",
"proc",
"{",
"|",
"expr",
"|",
"\"NUM2INT( #{expr} )\"",
"}",
"]",
"when",
"SFLOAT",
",",
"DFLOAT",
"[",
"proc",
"{",
"|",
"expr",
"|",
"\"NUM2DBL( #{expr} )\"",
"}",
"]",
"else",
"if",
"@typecode",
"<",
"Pointer_",
"[",
"proc",
"{",
"|",
"expr",
"|",
"\"(#{identifier})mallocToPtr( #{expr} )\"",
"}",
"]",
"elsif",
"@typecode",
"<",
"Composite",
"GCCType",
".",
"new",
"(",
"@typecode",
".",
"element_type",
")",
".",
"r2c",
"*",
"@typecode",
".",
"num_elements",
"else",
"raise",
"\"No conversion available for #{@typecode.inspect}\"",
"end",
"end",
"end"
] | Get code for converting Ruby VALUE to C value
This method returns a nameless function. The nameless function is used for
getting the code to convert a given parameter to a C value of this type.
@return [Proc] Nameless function accepting a C expression to be converted.
@private | [
"Get",
"code",
"for",
"converting",
"Ruby",
"VALUE",
"to",
"C",
"value"
] | 1ae1d98bacb4b941d6f406e44ccb184de12f83d9 | https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/gcctype.rb#L93-L110 | train |
ozgg/weighted-select | lib/weighted-select.rb | WeightedSelect.Selector.add | def add(item, weight)
delta = Integer(weight)
if delta > 0
new_weight = @total_weight + delta
weights[@total_weight...new_weight] = item
@total_weight = new_weight
end
end | ruby | def add(item, weight)
delta = Integer(weight)
if delta > 0
new_weight = @total_weight + delta
weights[@total_weight...new_weight] = item
@total_weight = new_weight
end
end | [
"def",
"add",
"(",
"item",
",",
"weight",
")",
"delta",
"=",
"Integer",
"(",
"weight",
")",
"if",
"delta",
">",
"0",
"new_weight",
"=",
"@total_weight",
"+",
"delta",
"weights",
"[",
"@total_weight",
"...",
"new_weight",
"]",
"=",
"item",
"@total_weight",
"=",
"new_weight",
"end",
"end"
] | Sets initial weights
Accepts Hash as an argument, where keys are items and corresponding values
are their weights (positive integers).
@param [Hash] weights
Add item with weight
@param [Object] item
@param [Integer] weight | [
"Sets",
"initial",
"weights"
] | 5cf3a8a1f2ba74f2885dcc8111396e5ca10ccad4 | https://github.com/ozgg/weighted-select/blob/5cf3a8a1f2ba74f2885dcc8111396e5ca10ccad4/lib/weighted-select.rb#L23-L30 | train |
ozgg/weighted-select | lib/weighted-select.rb | WeightedSelect.Selector.extract_item | def extract_item
weight = Random.rand(@total_weight)
@weights.each do |range, item|
return item if range === weight
end
end | ruby | def extract_item
weight = Random.rand(@total_weight)
@weights.each do |range, item|
return item if range === weight
end
end | [
"def",
"extract_item",
"weight",
"=",
"Random",
".",
"rand",
"(",
"@total_weight",
")",
"@weights",
".",
"each",
"do",
"|",
"range",
",",
"item",
"|",
"return",
"item",
"if",
"range",
"===",
"weight",
"end",
"end"
] | Extract item based on weights distribution
@return [Object] | [
"Extract",
"item",
"based",
"on",
"weights",
"distribution"
] | 5cf3a8a1f2ba74f2885dcc8111396e5ca10ccad4 | https://github.com/ozgg/weighted-select/blob/5cf3a8a1f2ba74f2885dcc8111396e5ca10ccad4/lib/weighted-select.rb#L44-L49 | train |
knuedge/off_the_grid | lib/off_the_grid/host_group.rb | OffTheGrid.HostGroup.entries | def entries
extract_detail(:hostlist).map do |host|
host =~ /^@/ ? HostGroup.new(host) : ExecuteHost.new(host)
end
end | ruby | def entries
extract_detail(:hostlist).map do |host|
host =~ /^@/ ? HostGroup.new(host) : ExecuteHost.new(host)
end
end | [
"def",
"entries",
"extract_detail",
"(",
":hostlist",
")",
".",
"map",
"do",
"|",
"host",
"|",
"host",
"=~",
"/",
"/",
"?",
"HostGroup",
".",
"new",
"(",
"host",
")",
":",
"ExecuteHost",
".",
"new",
"(",
"host",
")",
"end",
"end"
] | Direct entries in this HostGroup's hostlist attribute | [
"Direct",
"entries",
"in",
"this",
"HostGroup",
"s",
"hostlist",
"attribute"
] | cf367b6d22de5c73da2e2550e1f45e103a219a51 | https://github.com/knuedge/off_the_grid/blob/cf367b6d22de5c73da2e2550e1f45e103a219a51/lib/off_the_grid/host_group.rb#L20-L24 | train |
knuedge/off_the_grid | lib/off_the_grid/host_group.rb | OffTheGrid.HostGroup.hosts | def hosts
entries.map do |entry|
entry.is_a?(HostGroup) ? entry.hosts : entry
end.flatten.uniq
end | ruby | def hosts
entries.map do |entry|
entry.is_a?(HostGroup) ? entry.hosts : entry
end.flatten.uniq
end | [
"def",
"hosts",
"entries",
".",
"map",
"do",
"|",
"entry",
"|",
"entry",
".",
"is_a?",
"(",
"HostGroup",
")",
"?",
"entry",
".",
"hosts",
":",
"entry",
"end",
".",
"flatten",
".",
"uniq",
"end"
] | A recursive listing of all hosts associated with this HostGroup | [
"A",
"recursive",
"listing",
"of",
"all",
"hosts",
"associated",
"with",
"this",
"HostGroup"
] | cf367b6d22de5c73da2e2550e1f45e103a219a51 | https://github.com/knuedge/off_the_grid/blob/cf367b6d22de5c73da2e2550e1f45e103a219a51/lib/off_the_grid/host_group.rb#L27-L31 | train |
syborg/mme_tools | lib/mme_tools/webparse.rb | MMETools.Webparse.datify | def datify(str)
pttrn = /(\d+)[\/-](\d+)[\/-](\d+)(\W+(\d+)\:(\d+))?/
day, month, year, dummy, hour, min = str.match(pttrn).captures.map {|d| d ? d.to_i : 0 }
case year
when 0..69
year += 2000
when 70..99
year += 1900
end
DateTime.civil year, month, day, hour, min
end | ruby | def datify(str)
pttrn = /(\d+)[\/-](\d+)[\/-](\d+)(\W+(\d+)\:(\d+))?/
day, month, year, dummy, hour, min = str.match(pttrn).captures.map {|d| d ? d.to_i : 0 }
case year
when 0..69
year += 2000
when 70..99
year += 1900
end
DateTime.civil year, month, day, hour, min
end | [
"def",
"datify",
"(",
"str",
")",
"pttrn",
"=",
"/",
"\\d",
"\\/",
"\\d",
"\\/",
"\\d",
"\\W",
"\\d",
"\\:",
"\\d",
"/",
"day",
",",
"month",
",",
"year",
",",
"dummy",
",",
"hour",
",",
"min",
"=",
"str",
".",
"match",
"(",
"pttrn",
")",
".",
"captures",
".",
"map",
"{",
"|",
"d",
"|",
"d",
"?",
"d",
".",
"to_i",
":",
"0",
"}",
"case",
"year",
"when",
"0",
"..",
"69",
"year",
"+=",
"2000",
"when",
"70",
"..",
"99",
"year",
"+=",
"1900",
"end",
"DateTime",
".",
"civil",
"year",
",",
"month",
",",
"day",
",",
"hour",
",",
"min",
"end"
] | Extracts and returns the first provable DateTime from a string | [
"Extracts",
"and",
"returns",
"the",
"first",
"provable",
"DateTime",
"from",
"a",
"string"
] | e93919f7fcfb408b941d6144290991a7feabaa7d | https://github.com/syborg/mme_tools/blob/e93919f7fcfb408b941d6144290991a7feabaa7d/lib/mme_tools/webparse.rb#L78-L88 | train |
nulogy/spreadsheet | lib/spreadsheet/workbook.rb | Spreadsheet.Workbook.format | def format idx
case idx
when Integer
@formats[idx] || @default_format
when String
@formats.find do |fmt| fmt.name == idx end
end
end | ruby | def format idx
case idx
when Integer
@formats[idx] || @default_format
when String
@formats.find do |fmt| fmt.name == idx end
end
end | [
"def",
"format",
"idx",
"case",
"idx",
"when",
"Integer",
"@formats",
"[",
"idx",
"]",
"||",
"@default_format",
"when",
"String",
"@formats",
".",
"find",
"do",
"|",
"fmt",
"|",
"fmt",
".",
"name",
"==",
"idx",
"end",
"end",
"end"
] | The Format at _idx_, or - if _idx_ is a String -
the Format with name == _idx_ | [
"The",
"Format",
"at",
"_idx_",
"or",
"-",
"if",
"_idx_",
"is",
"a",
"String",
"-",
"the",
"Format",
"with",
"name",
"==",
"_idx_"
] | c89825047f02ab26deddaab779f3b4ca349b6a0c | https://github.com/nulogy/spreadsheet/blob/c89825047f02ab26deddaab779f3b4ca349b6a0c/lib/spreadsheet/workbook.rb#L72-L79 | train |
robfors/ruby-sumac | lib/sumac/directive_queue.rb | Sumac.DirectiveQueue.execute_next | def execute_next(&block)
@mutex.synchronize do
if @active_thread
condition_variable = ConditionVariable.new
@waiting_threads.unshift(condition_variable)
condition_variable.wait(@mutex)
end
@active_thread = true
end
return_value = yield
ensure
@mutex.synchronize do
@active_thread = false
next_waiting_thread = @waiting_threads.shift
next_waiting_thread&.signal
end
end | ruby | def execute_next(&block)
@mutex.synchronize do
if @active_thread
condition_variable = ConditionVariable.new
@waiting_threads.unshift(condition_variable)
condition_variable.wait(@mutex)
end
@active_thread = true
end
return_value = yield
ensure
@mutex.synchronize do
@active_thread = false
next_waiting_thread = @waiting_threads.shift
next_waiting_thread&.signal
end
end | [
"def",
"execute_next",
"(",
"&",
"block",
")",
"@mutex",
".",
"synchronize",
"do",
"if",
"@active_thread",
"condition_variable",
"=",
"ConditionVariable",
".",
"new",
"@waiting_threads",
".",
"unshift",
"(",
"condition_variable",
")",
"condition_variable",
".",
"wait",
"(",
"@mutex",
")",
"end",
"@active_thread",
"=",
"true",
"end",
"return_value",
"=",
"yield",
"ensure",
"@mutex",
".",
"synchronize",
"do",
"@active_thread",
"=",
"false",
"next_waiting_thread",
"=",
"@waiting_threads",
".",
"shift",
"next_waiting_thread",
"&.",
"signal",
"end",
"end"
] | Execute a block next.
If no other thread is executing a block, the block will be executed immediately.
If another thread is executing a block, add the thread to the front of the queue and executes
the block when the current thread has finished its block.
@note if multiple threads are queued via this method their order is undefined
@yield [] executed when permitted
@raise [Exception] anything raised in block
@return [Object] return value from block | [
"Execute",
"a",
"block",
"next",
".",
"If",
"no",
"other",
"thread",
"is",
"executing",
"a",
"block",
"the",
"block",
"will",
"be",
"executed",
"immediately",
".",
"If",
"another",
"thread",
"is",
"executing",
"a",
"block",
"add",
"the",
"thread",
"to",
"the",
"front",
"of",
"the",
"queue",
"and",
"executes",
"the",
"block",
"when",
"the",
"current",
"thread",
"has",
"finished",
"its",
"block",
"."
] | 524fa68b7d1bb10a74baa69cd594ab2b8cae20a3 | https://github.com/robfors/ruby-sumac/blob/524fa68b7d1bb10a74baa69cd594ab2b8cae20a3/lib/sumac/directive_queue.rb#L49-L65 | train |
Sammidysam/file_templater | lib/file_templater/template.rb | FileTemplater.Template.transform_file_name | def transform_file_name(file)
if @bind
variables = file.scan(/{{([^}]*)}}/).flatten
variables.each do |v|
file.sub!("{{#{v}}}", @bind.get_binding.eval(v))
end
end
(!@nomodify && file.end_with?(".erb") && !File.directory?(file)) ? File.basename(file, ".*") : file
end | ruby | def transform_file_name(file)
if @bind
variables = file.scan(/{{([^}]*)}}/).flatten
variables.each do |v|
file.sub!("{{#{v}}}", @bind.get_binding.eval(v))
end
end
(!@nomodify && file.end_with?(".erb") && !File.directory?(file)) ? File.basename(file, ".*") : file
end | [
"def",
"transform_file_name",
"(",
"file",
")",
"if",
"@bind",
"variables",
"=",
"file",
".",
"scan",
"(",
"/",
"/",
")",
".",
"flatten",
"variables",
".",
"each",
"do",
"|",
"v",
"|",
"file",
".",
"sub!",
"(",
"\"{{#{v}}}\"",
",",
"@bind",
".",
"get_binding",
".",
"eval",
"(",
"v",
")",
")",
"end",
"end",
"(",
"!",
"@nomodify",
"&&",
"file",
".",
"end_with?",
"(",
"\".erb\"",
")",
"&&",
"!",
"File",
".",
"directory?",
"(",
"file",
")",
")",
"?",
"File",
".",
"basename",
"(",
"file",
",",
"\".*\"",
")",
":",
"file",
"end"
] | Expands the variable-in-file-name notation. | [
"Expands",
"the",
"variable",
"-",
"in",
"-",
"file",
"-",
"name",
"notation",
"."
] | 081b3d4b82aaa955551a790a2ee8a90870dc1b45 | https://github.com/Sammidysam/file_templater/blob/081b3d4b82aaa955551a790a2ee8a90870dc1b45/lib/file_templater/template.rb#L57-L67 | train |
riddopic/garcun | lib/garcon/utility/file_helper.rb | Garcon.FileHelper.which | def which(prog, path = ENV['PATH'])
path.split(File::PATH_SEPARATOR).each do |dir|
file = File.join(dir, prog)
return file if File.executable?(file) && !File.directory?(file)
end
nil
end | ruby | def which(prog, path = ENV['PATH'])
path.split(File::PATH_SEPARATOR).each do |dir|
file = File.join(dir, prog)
return file if File.executable?(file) && !File.directory?(file)
end
nil
end | [
"def",
"which",
"(",
"prog",
",",
"path",
"=",
"ENV",
"[",
"'PATH'",
"]",
")",
"path",
".",
"split",
"(",
"File",
"::",
"PATH_SEPARATOR",
")",
".",
"each",
"do",
"|",
"dir",
"|",
"file",
"=",
"File",
".",
"join",
"(",
"dir",
",",
"prog",
")",
"return",
"file",
"if",
"File",
".",
"executable?",
"(",
"file",
")",
"&&",
"!",
"File",
".",
"directory?",
"(",
"file",
")",
"end",
"nil",
"end"
] | Looks for the first occurrence of program within path.
@param [String] cmd
The name of the command to find.
@param [String] path
The path to search for the command.
@return [String, NilClass]
@api public | [
"Looks",
"for",
"the",
"first",
"occurrence",
"of",
"program",
"within",
"path",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/utility/file_helper.rb#L53-L60 | train |
riddopic/garcun | lib/garcon/utility/file_helper.rb | Garcon.FileHelper.whereis | def whereis(prog, path = ENV['PATH'])
dirs = []
path.split(File::PATH_SEPARATOR).each do |dir|
f = File.join(dir,prog)
if File.executable?(f) && !File.directory?(f)
if block_given?
yield f
else
dirs << f
end
end
end
dirs.empty? ? nil : dirs
end | ruby | def whereis(prog, path = ENV['PATH'])
dirs = []
path.split(File::PATH_SEPARATOR).each do |dir|
f = File.join(dir,prog)
if File.executable?(f) && !File.directory?(f)
if block_given?
yield f
else
dirs << f
end
end
end
dirs.empty? ? nil : dirs
end | [
"def",
"whereis",
"(",
"prog",
",",
"path",
"=",
"ENV",
"[",
"'PATH'",
"]",
")",
"dirs",
"=",
"[",
"]",
"path",
".",
"split",
"(",
"File",
"::",
"PATH_SEPARATOR",
")",
".",
"each",
"do",
"|",
"dir",
"|",
"f",
"=",
"File",
".",
"join",
"(",
"dir",
",",
"prog",
")",
"if",
"File",
".",
"executable?",
"(",
"f",
")",
"&&",
"!",
"File",
".",
"directory?",
"(",
"f",
")",
"if",
"block_given?",
"yield",
"f",
"else",
"dirs",
"<<",
"f",
"end",
"end",
"end",
"dirs",
".",
"empty?",
"?",
"nil",
":",
"dirs",
"end"
] | In block form, yields each program within path. In non-block form,
returns an array of each program within path. Returns nil if not found
found.
@example
whereis('ruby')
# => [
[0] "/opt/chefdk/embedded/bin/ruby",
[1] "/usr/bin/ruby",
[2] "/Users/sharding/.rvm/rubies/ruby-2.2.0/bin/ruby",
[3] "/usr/bin/ruby"
]
@param [String] cmd
The name of the command to find.
@param [String] path
The path to search for the command.
@return [String, Array, NilClass]
@api public | [
"In",
"block",
"form",
"yields",
"each",
"program",
"within",
"path",
".",
"In",
"non",
"-",
"block",
"form",
"returns",
"an",
"array",
"of",
"each",
"program",
"within",
"path",
".",
"Returns",
"nil",
"if",
"not",
"found",
"found",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/utility/file_helper.rb#L84-L98 | train |
tpendragon/marmotta | lib/marmotta/connection.rb | Marmotta.Connection.get | def get(resource_uri)
result = connection.get("resource") do |request|
request.query[:uri] = resource_uri.to_s
request.query.delete(:graph)
end
MaybeGraphResult.new(result).value
end | ruby | def get(resource_uri)
result = connection.get("resource") do |request|
request.query[:uri] = resource_uri.to_s
request.query.delete(:graph)
end
MaybeGraphResult.new(result).value
end | [
"def",
"get",
"(",
"resource_uri",
")",
"result",
"=",
"connection",
".",
"get",
"(",
"\"resource\"",
")",
"do",
"|",
"request",
"|",
"request",
".",
"query",
"[",
":uri",
"]",
"=",
"resource_uri",
".",
"to_s",
"request",
".",
"query",
".",
"delete",
"(",
":graph",
")",
"end",
"MaybeGraphResult",
".",
"new",
"(",
"result",
")",
".",
"value",
"end"
] | Returns an RDFSource represented by the resource URI.
@param [String, #to_s] resource_uri URI to request
@return [RDF::Graph] The resulting graph | [
"Returns",
"an",
"RDFSource",
"represented",
"by",
"the",
"resource",
"URI",
"."
] | 01b28f656a441f4e23690c7eaf3b3b3ef76a888b | https://github.com/tpendragon/marmotta/blob/01b28f656a441f4e23690c7eaf3b3b3ef76a888b/lib/marmotta/connection.rb#L18-L24 | train |
tpendragon/marmotta | lib/marmotta/connection.rb | Marmotta.Connection.delete | def delete(resource_uri)
connection.delete("resource") do |request|
request.query[:uri] = resource_uri.to_s
request.query.delete(:graph)
end
end | ruby | def delete(resource_uri)
connection.delete("resource") do |request|
request.query[:uri] = resource_uri.to_s
request.query.delete(:graph)
end
end | [
"def",
"delete",
"(",
"resource_uri",
")",
"connection",
".",
"delete",
"(",
"\"resource\"",
")",
"do",
"|",
"request",
"|",
"request",
".",
"query",
"[",
":uri",
"]",
"=",
"resource_uri",
".",
"to_s",
"request",
".",
"query",
".",
"delete",
"(",
":graph",
")",
"end",
"end"
] | Deletes a subject from the context.
@param [String, #to_s] resource_uri URI of resource to delete.
@return [True, False] Result of deleting.
@todo Should this only delete triples from the given context? | [
"Deletes",
"a",
"subject",
"from",
"the",
"context",
"."
] | 01b28f656a441f4e23690c7eaf3b3b3ef76a888b | https://github.com/tpendragon/marmotta/blob/01b28f656a441f4e23690c7eaf3b3b3ef76a888b/lib/marmotta/connection.rb#L38-L43 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.partial_email | def partial_email
@partial_email ||=
begin
uid,_,domain = email.partition('@')
if uid.length < 4
uid = '*' * uid.length
elsif uid.length < 8
uid = uid[0..2] + ('*' * (uid.length - 3))
else
uid = uid[0..2] + ('*' * (uid.length - 6)) + uid[-3..-1]
end
"#{uid}@#{domain}"
end
end | ruby | def partial_email
@partial_email ||=
begin
uid,_,domain = email.partition('@')
if uid.length < 4
uid = '*' * uid.length
elsif uid.length < 8
uid = uid[0..2] + ('*' * (uid.length - 3))
else
uid = uid[0..2] + ('*' * (uid.length - 6)) + uid[-3..-1]
end
"#{uid}@#{domain}"
end
end | [
"def",
"partial_email",
"@partial_email",
"||=",
"begin",
"uid",
",",
"_",
",",
"domain",
"=",
"email",
".",
"partition",
"(",
"'@'",
")",
"if",
"uid",
".",
"length",
"<",
"4",
"uid",
"=",
"'*'",
"*",
"uid",
".",
"length",
"elsif",
"uid",
".",
"length",
"<",
"8",
"uid",
"=",
"uid",
"[",
"0",
"..",
"2",
"]",
"+",
"(",
"'*'",
"*",
"(",
"uid",
".",
"length",
"-",
"3",
")",
")",
"else",
"uid",
"=",
"uid",
"[",
"0",
"..",
"2",
"]",
"+",
"(",
"'*'",
"*",
"(",
"uid",
".",
"length",
"-",
"6",
")",
")",
"+",
"uid",
"[",
"-",
"3",
"..",
"-",
"1",
"]",
"end",
"\"#{uid}@#{domain}\"",
"end",
"end"
] | Gets the email address in a partially obfuscated fashion. | [
"Gets",
"the",
"email",
"address",
"in",
"a",
"partially",
"obfuscated",
"fashion",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L86-L99 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.effective_groups | def effective_groups(refresh = false)
@effective_groups = nil if refresh
@effective_groups ||= if system_admin?
AccessGroup.all.map{ |g| g.to_s.upcase }
else
groups
.collect{ |g| g.effective_groups }
.flatten
end
.map{ |g| g.to_s.upcase }
.uniq
.sort
end | ruby | def effective_groups(refresh = false)
@effective_groups = nil if refresh
@effective_groups ||= if system_admin?
AccessGroup.all.map{ |g| g.to_s.upcase }
else
groups
.collect{ |g| g.effective_groups }
.flatten
end
.map{ |g| g.to_s.upcase }
.uniq
.sort
end | [
"def",
"effective_groups",
"(",
"refresh",
"=",
"false",
")",
"@effective_groups",
"=",
"nil",
"if",
"refresh",
"@effective_groups",
"||=",
"if",
"system_admin?",
"AccessGroup",
".",
"all",
".",
"map",
"{",
"|",
"g",
"|",
"g",
".",
"to_s",
".",
"upcase",
"}",
"else",
"groups",
".",
"collect",
"{",
"|",
"g",
"|",
"g",
".",
"effective_groups",
"}",
".",
"flatten",
"end",
".",
"map",
"{",
"|",
"g",
"|",
"g",
".",
"to_s",
".",
"upcase",
"}",
".",
"uniq",
".",
"sort",
"end"
] | Gets the effective group membership of this user. | [
"Gets",
"the",
"effective",
"group",
"membership",
"of",
"this",
"user",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L124-L136 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.has_any_group? | def has_any_group?(*group_list)
return :system_admin if system_admin?
return false if anonymous?
r = group_list.select{|g| effective_groups.include?(g.upcase)}
r.blank? ? false : r
end | ruby | def has_any_group?(*group_list)
return :system_admin if system_admin?
return false if anonymous?
r = group_list.select{|g| effective_groups.include?(g.upcase)}
r.blank? ? false : r
end | [
"def",
"has_any_group?",
"(",
"*",
"group_list",
")",
"return",
":system_admin",
"if",
"system_admin?",
"return",
"false",
"if",
"anonymous?",
"r",
"=",
"group_list",
".",
"select",
"{",
"|",
"g",
"|",
"effective_groups",
".",
"include?",
"(",
"g",
".",
"upcase",
")",
"}",
"r",
".",
"blank?",
"?",
"false",
":",
"r",
"end"
] | Does this user have the equivalent of one or more of these groups? | [
"Does",
"this",
"user",
"have",
"the",
"equivalent",
"of",
"one",
"or",
"more",
"of",
"these",
"groups?"
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L140-L147 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.remember | def remember
self.remember_token = Incline::User::new_token
update_attribute(:remember_digest, Incline::User::digest(self.remember_token))
end | ruby | def remember
self.remember_token = Incline::User::new_token
update_attribute(:remember_digest, Incline::User::digest(self.remember_token))
end | [
"def",
"remember",
"self",
".",
"remember_token",
"=",
"Incline",
"::",
"User",
"::",
"new_token",
"update_attribute",
"(",
":remember_digest",
",",
"Incline",
"::",
"User",
"::",
"digest",
"(",
"self",
".",
"remember_token",
")",
")",
"end"
] | Generates a remember token and saves the digest to the user model. | [
"Generates",
"a",
"remember",
"token",
"and",
"saves",
"the",
"digest",
"to",
"the",
"user",
"model",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L151-L154 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.authenticated? | def authenticated?(attribute, token)
return false unless respond_to?("#{attribute}_digest")
digest = send("#{attribute}_digest")
return false if digest.blank?
BCrypt::Password.new(digest).is_password?(token)
end | ruby | def authenticated?(attribute, token)
return false unless respond_to?("#{attribute}_digest")
digest = send("#{attribute}_digest")
return false if digest.blank?
BCrypt::Password.new(digest).is_password?(token)
end | [
"def",
"authenticated?",
"(",
"attribute",
",",
"token",
")",
"return",
"false",
"unless",
"respond_to?",
"(",
"\"#{attribute}_digest\"",
")",
"digest",
"=",
"send",
"(",
"\"#{attribute}_digest\"",
")",
"return",
"false",
"if",
"digest",
".",
"blank?",
"BCrypt",
"::",
"Password",
".",
"new",
"(",
"digest",
")",
".",
"is_password?",
"(",
"token",
")",
"end"
] | Determines if the supplied token digests to the stored digest in the user model. | [
"Determines",
"if",
"the",
"supplied",
"token",
"digests",
"to",
"the",
"stored",
"digest",
"in",
"the",
"user",
"model",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L164-L169 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.disable | def disable(other_user, reason)
return false unless other_user&.system_admin?
return false if other_user == self
update_columns(
disabled_by: other_user.email,
disabled_at: Time.now,
disabled_reason: reason,
enabled: false
) && refresh_comments
end | ruby | def disable(other_user, reason)
return false unless other_user&.system_admin?
return false if other_user == self
update_columns(
disabled_by: other_user.email,
disabled_at: Time.now,
disabled_reason: reason,
enabled: false
) && refresh_comments
end | [
"def",
"disable",
"(",
"other_user",
",",
"reason",
")",
"return",
"false",
"unless",
"other_user",
"&.",
"system_admin?",
"return",
"false",
"if",
"other_user",
"==",
"self",
"update_columns",
"(",
"disabled_by",
":",
"other_user",
".",
"email",
",",
"disabled_at",
":",
"Time",
".",
"now",
",",
"disabled_reason",
":",
"reason",
",",
"enabled",
":",
"false",
")",
"&&",
"refresh_comments",
"end"
] | Disables the user.
The +other_user+ is required, cannot be the current user, and must be a system administrator.
The +reason+ is technically optional, but should be provided. | [
"Disables",
"the",
"user",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L176-L186 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.create_reset_digest | def create_reset_digest
self.reset_token = Incline::User::new_token
update_columns(
reset_digest: Incline::User::digest(reset_token),
reset_sent_at: Time.now
)
end | ruby | def create_reset_digest
self.reset_token = Incline::User::new_token
update_columns(
reset_digest: Incline::User::digest(reset_token),
reset_sent_at: Time.now
)
end | [
"def",
"create_reset_digest",
"self",
".",
"reset_token",
"=",
"Incline",
"::",
"User",
"::",
"new_token",
"update_columns",
"(",
"reset_digest",
":",
"Incline",
"::",
"User",
"::",
"digest",
"(",
"reset_token",
")",
",",
"reset_sent_at",
":",
"Time",
".",
"now",
")",
"end"
] | Creates a reset token and stores the digest to the user model. | [
"Creates",
"a",
"reset",
"token",
"and",
"stores",
"the",
"digest",
"to",
"the",
"user",
"model",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L217-L223 | train |
barkerest/incline | app/models/incline/user.rb | Incline.User.failed_login_streak | def failed_login_streak
@failed_login_streak ||=
begin
results = login_histories.where.not(successful: true)
if last_successful_login
results = results.where('created_at > ?', last_successful_login.created_at)
end
results.order(created_at: :desc)
end
end | ruby | def failed_login_streak
@failed_login_streak ||=
begin
results = login_histories.where.not(successful: true)
if last_successful_login
results = results.where('created_at > ?', last_successful_login.created_at)
end
results.order(created_at: :desc)
end
end | [
"def",
"failed_login_streak",
"@failed_login_streak",
"||=",
"begin",
"results",
"=",
"login_histories",
".",
"where",
".",
"not",
"(",
"successful",
":",
"true",
")",
"if",
"last_successful_login",
"results",
"=",
"results",
".",
"where",
"(",
"'created_at > ?'",
",",
"last_successful_login",
".",
"created_at",
")",
"end",
"results",
".",
"order",
"(",
"created_at",
":",
":desc",
")",
"end",
"end"
] | Gets the failed logins for a user since the last successful login. | [
"Gets",
"the",
"failed",
"logins",
"for",
"a",
"user",
"since",
"the",
"last",
"successful",
"login",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/app/models/incline/user.rb#L251-L260 | train |
leoniv/ass_maintainer-info_base | lib/ass_maintainer/info_base.rb | AssMaintainer.InfoBase.add_hook | def add_hook(hook, &block)
fail ArgumentError, "Invalid hook `#{hook}'" unless\
HOOKS.keys.include? hook
fail ArgumentError, 'Block require' unless block_given?
options[hook] = block
end | ruby | def add_hook(hook, &block)
fail ArgumentError, "Invalid hook `#{hook}'" unless\
HOOKS.keys.include? hook
fail ArgumentError, 'Block require' unless block_given?
options[hook] = block
end | [
"def",
"add_hook",
"(",
"hook",
",",
"&",
"block",
")",
"fail",
"ArgumentError",
",",
"\"Invalid hook `#{hook}'\"",
"unless",
"HOOKS",
".",
"keys",
".",
"include?",
"hook",
"fail",
"ArgumentError",
",",
"'Block require'",
"unless",
"block_given?",
"options",
"[",
"hook",
"]",
"=",
"block",
"end"
] | Add hook. In all hook whill be passed +self+
@raise [ArgumentError] if invalid hook name or not block given
@param hook [Symbol] hook name | [
"Add",
"hook",
".",
"In",
"all",
"hook",
"whill",
"be",
"passed",
"+",
"self",
"+"
] | 1cc9212fc240dafb058faae1e122eb9c8ece1cf7 | https://github.com/leoniv/ass_maintainer-info_base/blob/1cc9212fc240dafb058faae1e122eb9c8ece1cf7/lib/ass_maintainer/info_base.rb#L137-L142 | train |
leoniv/ass_maintainer-info_base | lib/ass_maintainer/info_base.rb | AssMaintainer.InfoBase.make_infobase! | def make_infobase!
fail MethodDenied, :make_infobase! if read_only?
before_make.call(self)
maker.execute(self)
after_make.call(self)
self
end | ruby | def make_infobase!
fail MethodDenied, :make_infobase! if read_only?
before_make.call(self)
maker.execute(self)
after_make.call(self)
self
end | [
"def",
"make_infobase!",
"fail",
"MethodDenied",
",",
":make_infobase!",
"if",
"read_only?",
"before_make",
".",
"call",
"(",
"self",
")",
"maker",
".",
"execute",
"(",
"self",
")",
"after_make",
".",
"call",
"(",
"self",
")",
"self",
"end"
] | Make new empty infobase
wrpped in +before_make+ and +after_make+ hooks
@raise [MethodDenied] if infobase {#read_only?} | [
"Make",
"new",
"empty",
"infobase",
"wrpped",
"in",
"+",
"before_make",
"+",
"and",
"+",
"after_make",
"+",
"hooks"
] | 1cc9212fc240dafb058faae1e122eb9c8ece1cf7 | https://github.com/leoniv/ass_maintainer-info_base/blob/1cc9212fc240dafb058faae1e122eb9c8ece1cf7/lib/ass_maintainer/info_base.rb#L166-L172 | train |
leoniv/ass_maintainer-info_base | lib/ass_maintainer/info_base.rb | AssMaintainer.InfoBase.rm_infobase! | def rm_infobase!
fail MethodDenied, :rm_infobase! if read_only?
before_rm.call(self)
destroyer.execute(self)
after_rm.call(self)
end | ruby | def rm_infobase!
fail MethodDenied, :rm_infobase! if read_only?
before_rm.call(self)
destroyer.execute(self)
after_rm.call(self)
end | [
"def",
"rm_infobase!",
"fail",
"MethodDenied",
",",
":rm_infobase!",
"if",
"read_only?",
"before_rm",
".",
"call",
"(",
"self",
")",
"destroyer",
".",
"execute",
"(",
"self",
")",
"after_rm",
".",
"call",
"(",
"self",
")",
"end"
] | Remove infobase
wrpped in +before_rm+ and +after_rm+ hooks
@raise [MethodDenied] if infobase {#read_only?} | [
"Remove",
"infobase",
"wrpped",
"in",
"+",
"before_rm",
"+",
"and",
"+",
"after_rm",
"+",
"hooks"
] | 1cc9212fc240dafb058faae1e122eb9c8ece1cf7 | https://github.com/leoniv/ass_maintainer-info_base/blob/1cc9212fc240dafb058faae1e122eb9c8ece1cf7/lib/ass_maintainer/info_base.rb#L186-L191 | train |
leoniv/ass_maintainer-info_base | lib/ass_maintainer/info_base.rb | AssMaintainer.InfoBase.dump | def dump(path)
designer do
dumpIB path
end.run.wait.result.verify!
path
end | ruby | def dump(path)
designer do
dumpIB path
end.run.wait.result.verify!
path
end | [
"def",
"dump",
"(",
"path",
")",
"designer",
"do",
"dumpIB",
"path",
"end",
".",
"run",
".",
"wait",
".",
"result",
".",
"verify!",
"path",
"end"
] | Dump infobase to +.dt+ file | [
"Dump",
"infobase",
"to",
"+",
".",
"dt",
"+",
"file"
] | 1cc9212fc240dafb058faae1e122eb9c8ece1cf7 | https://github.com/leoniv/ass_maintainer-info_base/blob/1cc9212fc240dafb058faae1e122eb9c8ece1cf7/lib/ass_maintainer/info_base.rb#L260-L265 | train |
leoniv/ass_maintainer-info_base | lib/ass_maintainer/info_base.rb | AssMaintainer.InfoBase.restore! | def restore!(path)
fail MethodDenied, :restore! if read_only?
designer do
restoreIB path
end.run.wait.result.verify!
path
end | ruby | def restore!(path)
fail MethodDenied, :restore! if read_only?
designer do
restoreIB path
end.run.wait.result.verify!
path
end | [
"def",
"restore!",
"(",
"path",
")",
"fail",
"MethodDenied",
",",
":restore!",
"if",
"read_only?",
"designer",
"do",
"restoreIB",
"path",
"end",
".",
"run",
".",
"wait",
".",
"result",
".",
"verify!",
"path",
"end"
] | Restore infobase from +.dt+ file
@raise [MethodDenied] if {#read_only?} | [
"Restore",
"infobase",
"from",
"+",
".",
"dt",
"+",
"file"
] | 1cc9212fc240dafb058faae1e122eb9c8ece1cf7 | https://github.com/leoniv/ass_maintainer-info_base/blob/1cc9212fc240dafb058faae1e122eb9c8ece1cf7/lib/ass_maintainer/info_base.rb#L269-L275 | train |
riddopic/hoodie | lib/hoodie/memoizable.rb | Hoodie.Memoizable.memoize | def memoize(methods, cache = nil)
cache ||= Hoodie::Stash.new
methods.each do |name|
uncached_name = "#{name}_uncached".to_sym
singleton_class.class_eval do
alias_method uncached_name, name
define_method(name) do |*a, &b|
cache.cache(name) { send uncached_name, *a, &b }
end
end
end
end | ruby | def memoize(methods, cache = nil)
cache ||= Hoodie::Stash.new
methods.each do |name|
uncached_name = "#{name}_uncached".to_sym
singleton_class.class_eval do
alias_method uncached_name, name
define_method(name) do |*a, &b|
cache.cache(name) { send uncached_name, *a, &b }
end
end
end
end | [
"def",
"memoize",
"(",
"methods",
",",
"cache",
"=",
"nil",
")",
"cache",
"||=",
"Hoodie",
"::",
"Stash",
".",
"new",
"methods",
".",
"each",
"do",
"|",
"name",
"|",
"uncached_name",
"=",
"\"#{name}_uncached\"",
".",
"to_sym",
"singleton_class",
".",
"class_eval",
"do",
"alias_method",
"uncached_name",
",",
"name",
"define_method",
"(",
"name",
")",
"do",
"|",
"*",
"a",
",",
"&",
"b",
"|",
"cache",
".",
"cache",
"(",
"name",
")",
"{",
"send",
"uncached_name",
",",
"*",
"a",
",",
"&",
"b",
"}",
"end",
"end",
"end",
"end"
] | Create a new memoized method. To use, extend class with Memoizable,
then, in initialize, call memoize
@return [undefined] | [
"Create",
"a",
"new",
"memoized",
"method",
".",
"To",
"use",
"extend",
"class",
"with",
"Memoizable",
"then",
"in",
"initialize",
"call",
"memoize"
] | 921601dd4849845d3f5d3765dafcf00178b2aa66 | https://github.com/riddopic/hoodie/blob/921601dd4849845d3f5d3765dafcf00178b2aa66/lib/hoodie/memoizable.rb#L33-L44 | train |
coralnexus/nucleon | lib/core/manager.rb | Nucleon.Manager.parallel_finalize | def parallel_finalize
active_plugins.each do |namespace, namespace_plugins|
namespace_plugins.each do |plugin_type, type_plugins|
type_plugins.each do |instance_name, plugin|
remove(plugin)
end
end
end
end | ruby | def parallel_finalize
active_plugins.each do |namespace, namespace_plugins|
namespace_plugins.each do |plugin_type, type_plugins|
type_plugins.each do |instance_name, plugin|
remove(plugin)
end
end
end
end | [
"def",
"parallel_finalize",
"active_plugins",
".",
"each",
"do",
"|",
"namespace",
",",
"namespace_plugins",
"|",
"namespace_plugins",
".",
"each",
"do",
"|",
"plugin_type",
",",
"type_plugins",
"|",
"type_plugins",
".",
"each",
"do",
"|",
"instance_name",
",",
"plugin",
"|",
"remove",
"(",
"plugin",
")",
"end",
"end",
"end",
"end"
] | Initialize a new Nucleon environment
IMORTANT: The environment constructor should accept no parameters!
* *Parameters*
- [String, Symbol] *actor_id* Name of the plugin manager
- [Boolean] *reset* Whether or not to reinitialize the manager
* *Returns*
- [Void] This method does not return a value
* *Errors*
See also:
- Nucleon::Facade#logger
- Nucleon::Environment
Perform any cleanup operations during manager shutdown
This only runs when in parallel mode.
* *Parameters*
* *Returns*
- [Void] This method does not return a value
* *Errors*
See also:
- #active_plugins
- #remove | [
"Initialize",
"a",
"new",
"Nucleon",
"environment"
] | 3a3c489251139c184e0884feaa55269cf64cad44 | https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/manager.rb#L125-L133 | train |
coralnexus/nucleon | lib/core/manager.rb | Nucleon.Manager.define_plugin | def define_plugin(namespace, plugin_type, base_path, file, &code) # :yields: data
@@environments[@actor_id].define_plugin(namespace, plugin_type, base_path, file, &code)
myself
end | ruby | def define_plugin(namespace, plugin_type, base_path, file, &code) # :yields: data
@@environments[@actor_id].define_plugin(namespace, plugin_type, base_path, file, &code)
myself
end | [
"def",
"define_plugin",
"(",
"namespace",
",",
"plugin_type",
",",
"base_path",
",",
"file",
",",
"&",
"code",
")",
"@@environments",
"[",
"@actor_id",
"]",
".",
"define_plugin",
"(",
"namespace",
",",
"plugin_type",
",",
"base_path",
",",
"file",
",",
"&",
"code",
")",
"myself",
"end"
] | Define a new plugin provider of a specified plugin type.
* *Parameters*
- [String, Symbol] *namespace* Namespace that contains plugin types
- [String, Symbol] *plugin_type* Plugin type name to fetch default provider
- [String] *base_path* Base load path of the plugin provider
- [String] *file* File that contains the provider definition
* *Returns*
- [Nucleon::Manager, Celluloid::Actor] Returns reference to self for compound operations
* *Errors*
* *Yields*
- [Hash<Symbol|ANY>] *data* Plugin load information
See:
- Nucleon::Environment#define_plugin | [
"Define",
"a",
"new",
"plugin",
"provider",
"of",
"a",
"specified",
"plugin",
"type",
"."
] | 3a3c489251139c184e0884feaa55269cf64cad44 | https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/manager.rb#L357-L360 | train |
UzxMx/api_warden | lib/api_warden/authentication.rb | ApiWarden.Authentication.authenticate! | def authenticate!
return unless @authenticated.nil?
id, access_token = @params.retrieve_id, @params.retrieve_access_token
@key_for_access_token = @scope.key_for_access_token(id, access_token)
if access_token && !access_token.empty?
ApiWarden.redis { |conn| @value_for_access_token = conn.get(@key_for_access_token) }
end
unless @value_for_access_token
@authenticated = false
raise AuthenticationError
end
@authenticated = true
@id = id
@access_token = access_token
self
end | ruby | def authenticate!
return unless @authenticated.nil?
id, access_token = @params.retrieve_id, @params.retrieve_access_token
@key_for_access_token = @scope.key_for_access_token(id, access_token)
if access_token && !access_token.empty?
ApiWarden.redis { |conn| @value_for_access_token = conn.get(@key_for_access_token) }
end
unless @value_for_access_token
@authenticated = false
raise AuthenticationError
end
@authenticated = true
@id = id
@access_token = access_token
self
end | [
"def",
"authenticate!",
"return",
"unless",
"@authenticated",
".",
"nil?",
"id",
",",
"access_token",
"=",
"@params",
".",
"retrieve_id",
",",
"@params",
".",
"retrieve_access_token",
"@key_for_access_token",
"=",
"@scope",
".",
"key_for_access_token",
"(",
"id",
",",
"access_token",
")",
"if",
"access_token",
"&&",
"!",
"access_token",
".",
"empty?",
"ApiWarden",
".",
"redis",
"{",
"|",
"conn",
"|",
"@value_for_access_token",
"=",
"conn",
".",
"get",
"(",
"@key_for_access_token",
")",
"}",
"end",
"unless",
"@value_for_access_token",
"@authenticated",
"=",
"false",
"raise",
"AuthenticationError",
"end",
"@authenticated",
"=",
"true",
"@id",
"=",
"id",
"@access_token",
"=",
"access_token",
"self",
"end"
] | This method will only authenticate once, and cache the result.
@return self | [
"This",
"method",
"will",
"only",
"authenticate",
"once",
"and",
"cache",
"the",
"result",
"."
] | 78e4fa421abc5333da2df6903d736d8e4871483a | https://github.com/UzxMx/api_warden/blob/78e4fa421abc5333da2df6903d736d8e4871483a/lib/api_warden/authentication.rb#L51-L70 | train |
UzxMx/api_warden | lib/api_warden/authentication.rb | ApiWarden.Authentication.ttl_for_access_token= | def ttl_for_access_token=(seconds)
raise_if_authentication_failed!
key = @key_for_access_token
value = @value_for_access_token
ApiWarden.redis { |conn| conn.set(key, value, ex: seconds) }
end | ruby | def ttl_for_access_token=(seconds)
raise_if_authentication_failed!
key = @key_for_access_token
value = @value_for_access_token
ApiWarden.redis { |conn| conn.set(key, value, ex: seconds) }
end | [
"def",
"ttl_for_access_token",
"=",
"(",
"seconds",
")",
"raise_if_authentication_failed!",
"key",
"=",
"@key_for_access_token",
"value",
"=",
"@value_for_access_token",
"ApiWarden",
".",
"redis",
"{",
"|",
"conn",
"|",
"conn",
".",
"set",
"(",
"key",
",",
"value",
",",
"ex",
":",
"seconds",
")",
"}",
"end"
] | Set the ttl for access token. | [
"Set",
"the",
"ttl",
"for",
"access",
"token",
"."
] | 78e4fa421abc5333da2df6903d736d8e4871483a | https://github.com/UzxMx/api_warden/blob/78e4fa421abc5333da2df6903d736d8e4871483a/lib/api_warden/authentication.rb#L115-L121 | train |
kddeisz/helpful_comments | lib/helpful_comments/controller_routes.rb | HelpfulComments.ControllerRoutes.build | def build
controller_name = @klass.name.gsub(/Controller$/, '').underscore
Rails.application.routes.routes.each_with_object({}) do |route, comments|
if route.defaults[:controller] == controller_name
verb_match = route.verb.to_s.match(/\^(.*)\$/)
verbs = verb_match.nil? ? '*' : verb_match[1]
(comments[route.defaults[:action]] ||= []) << "#{verbs} #{route.ast}"
end
end
end | ruby | def build
controller_name = @klass.name.gsub(/Controller$/, '').underscore
Rails.application.routes.routes.each_with_object({}) do |route, comments|
if route.defaults[:controller] == controller_name
verb_match = route.verb.to_s.match(/\^(.*)\$/)
verbs = verb_match.nil? ? '*' : verb_match[1]
(comments[route.defaults[:action]] ||= []) << "#{verbs} #{route.ast}"
end
end
end | [
"def",
"build",
"controller_name",
"=",
"@klass",
".",
"name",
".",
"gsub",
"(",
"/",
"/",
",",
"''",
")",
".",
"underscore",
"Rails",
".",
"application",
".",
"routes",
".",
"routes",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"route",
",",
"comments",
"|",
"if",
"route",
".",
"defaults",
"[",
":controller",
"]",
"==",
"controller_name",
"verb_match",
"=",
"route",
".",
"verb",
".",
"to_s",
".",
"match",
"(",
"/",
"\\^",
"\\$",
"/",
")",
"verbs",
"=",
"verb_match",
".",
"nil?",
"?",
"'*'",
":",
"verb_match",
"[",
"1",
"]",
"(",
"comments",
"[",
"route",
".",
"defaults",
"[",
":action",
"]",
"]",
"||=",
"[",
"]",
")",
"<<",
"\"#{verbs} #{route.ast}\"",
"end",
"end",
"end"
] | takes a controller
builds the lines to be put into the file | [
"takes",
"a",
"controller",
"builds",
"the",
"lines",
"to",
"be",
"put",
"into",
"the",
"file"
] | 45dce953a4f248ad847ca0032872a059eace58a4 | https://github.com/kddeisz/helpful_comments/blob/45dce953a4f248ad847ca0032872a059eace58a4/lib/helpful_comments/controller_routes.rb#L10-L19 | train |
Lupeipei/i18n-processes | lib/i18n/processes/data/tree/siblings.rb | I18n::Processes::Data::Tree.Siblings.set | def set(full_key, node)
fail 'value should be a I18n::Processes::Data::Tree::Node' unless node.is_a?(Node)
key_part, rest = split_key(full_key, 2)
child = key_to_node[key_part]
if rest
unless child
child = Node.new(
key: key_part,
parent: parent,
children: [],
warn_about_add_children_to_leaf: @warn_add_children_to_leaf
)
append! child
end
unless child.children
warn_add_children_to_leaf child if @warn_about_add_children_to_leaf
child.children = []
end
child.children.set rest, node
else
remove! child if child
append! node
end
dirty!
node
end | ruby | def set(full_key, node)
fail 'value should be a I18n::Processes::Data::Tree::Node' unless node.is_a?(Node)
key_part, rest = split_key(full_key, 2)
child = key_to_node[key_part]
if rest
unless child
child = Node.new(
key: key_part,
parent: parent,
children: [],
warn_about_add_children_to_leaf: @warn_add_children_to_leaf
)
append! child
end
unless child.children
warn_add_children_to_leaf child if @warn_about_add_children_to_leaf
child.children = []
end
child.children.set rest, node
else
remove! child if child
append! node
end
dirty!
node
end | [
"def",
"set",
"(",
"full_key",
",",
"node",
")",
"fail",
"'value should be a I18n::Processes::Data::Tree::Node'",
"unless",
"node",
".",
"is_a?",
"(",
"Node",
")",
"key_part",
",",
"rest",
"=",
"split_key",
"(",
"full_key",
",",
"2",
")",
"child",
"=",
"key_to_node",
"[",
"key_part",
"]",
"if",
"rest",
"unless",
"child",
"child",
"=",
"Node",
".",
"new",
"(",
"key",
":",
"key_part",
",",
"parent",
":",
"parent",
",",
"children",
":",
"[",
"]",
",",
"warn_about_add_children_to_leaf",
":",
"@warn_add_children_to_leaf",
")",
"append!",
"child",
"end",
"unless",
"child",
".",
"children",
"warn_add_children_to_leaf",
"child",
"if",
"@warn_about_add_children_to_leaf",
"child",
".",
"children",
"=",
"[",
"]",
"end",
"child",
".",
"children",
".",
"set",
"rest",
",",
"node",
"else",
"remove!",
"child",
"if",
"child",
"append!",
"node",
"end",
"dirty!",
"node",
"end"
] | add or replace node by full key | [
"add",
"or",
"replace",
"node",
"by",
"full",
"key"
] | 83c91517f80b82371ab19e197665e6e131024df3 | https://github.com/Lupeipei/i18n-processes/blob/83c91517f80b82371ab19e197665e6e131024df3/lib/i18n/processes/data/tree/siblings.rb#L106-L132 | train |
hinrik/ircsupport | lib/ircsupport/encoding.rb | IRCSupport.Encoding.decode_irc! | def decode_irc!(string, encoding = :irc)
if encoding == :irc
# If incoming text is valid UTF-8, it will be interpreted as
# such. If it fails validation, a CP1252 -> UTF-8 conversion
# is performed. This allows you to see non-ASCII from mIRC
# users (non-UTF-8) and other users sending you UTF-8.
#
# (from http://xchat.org/encoding/#hybrid)
string.force_encoding("UTF-8")
if !string.valid_encoding?
string.force_encoding("CP1252").encode!("UTF-8", {:invalid => :replace, :undef => :replace})
end
else
string.force_encoding(encoding).encode!({:invalid => :replace, :undef => :replace})
string = string.chars.select { |c| c.valid_encoding? }.join
end
return string
end | ruby | def decode_irc!(string, encoding = :irc)
if encoding == :irc
# If incoming text is valid UTF-8, it will be interpreted as
# such. If it fails validation, a CP1252 -> UTF-8 conversion
# is performed. This allows you to see non-ASCII from mIRC
# users (non-UTF-8) and other users sending you UTF-8.
#
# (from http://xchat.org/encoding/#hybrid)
string.force_encoding("UTF-8")
if !string.valid_encoding?
string.force_encoding("CP1252").encode!("UTF-8", {:invalid => :replace, :undef => :replace})
end
else
string.force_encoding(encoding).encode!({:invalid => :replace, :undef => :replace})
string = string.chars.select { |c| c.valid_encoding? }.join
end
return string
end | [
"def",
"decode_irc!",
"(",
"string",
",",
"encoding",
"=",
":irc",
")",
"if",
"encoding",
"==",
":irc",
"string",
".",
"force_encoding",
"(",
"\"UTF-8\"",
")",
"if",
"!",
"string",
".",
"valid_encoding?",
"string",
".",
"force_encoding",
"(",
"\"CP1252\"",
")",
".",
"encode!",
"(",
"\"UTF-8\"",
",",
"{",
":invalid",
"=>",
":replace",
",",
":undef",
"=>",
":replace",
"}",
")",
"end",
"else",
"string",
".",
"force_encoding",
"(",
"encoding",
")",
".",
"encode!",
"(",
"{",
":invalid",
"=>",
":replace",
",",
":undef",
"=>",
":replace",
"}",
")",
"string",
"=",
"string",
".",
"chars",
".",
"select",
"{",
"|",
"c",
"|",
"c",
".",
"valid_encoding?",
"}",
".",
"join",
"end",
"return",
"string",
"end"
] | Decode a message from an IRC connection, modifying it in place.
@param [String] string The IRC string you want to decode.
@param [Symbol] encoding The source encoding.
@return [String] A UTF-8 Ruby string. | [
"Decode",
"a",
"message",
"from",
"an",
"IRC",
"connection",
"modifying",
"it",
"in",
"place",
"."
] | d028b7d5ccc604a6af175ee2264c18d25b1f7dff | https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/encoding.rb#L27-L45 | train |
hinrik/ircsupport | lib/ircsupport/encoding.rb | IRCSupport.Encoding.encode_irc! | def encode_irc!(string, encoding = :irc)
if encoding == :irc
# If your text contains only characters that fit inside the CP1252
# code page (aka Windows Latin-1), the entire line will be sent
# that way. mIRC users should see it correctly. XChat users who
# are using UTF-8 will also see it correctly, because it will fail
# UTF-8 validation and will be assumed to be CP1252, even by older
# XChat versions.
#
# If the text doesn't fit inside the CP1252 code page, (for example if you
# type Eastern European characters, or Russian) it will be sent as UTF-8. Only
# UTF-8 capable clients will be able to see these characters correctly
#
# (from http://xchat.org/encoding/#hybrid)
begin
string.encode!("CP1252")
rescue ::Encoding::UndefinedConversionError
end
else
string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
end
return string
end | ruby | def encode_irc!(string, encoding = :irc)
if encoding == :irc
# If your text contains only characters that fit inside the CP1252
# code page (aka Windows Latin-1), the entire line will be sent
# that way. mIRC users should see it correctly. XChat users who
# are using UTF-8 will also see it correctly, because it will fail
# UTF-8 validation and will be assumed to be CP1252, even by older
# XChat versions.
#
# If the text doesn't fit inside the CP1252 code page, (for example if you
# type Eastern European characters, or Russian) it will be sent as UTF-8. Only
# UTF-8 capable clients will be able to see these characters correctly
#
# (from http://xchat.org/encoding/#hybrid)
begin
string.encode!("CP1252")
rescue ::Encoding::UndefinedConversionError
end
else
string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
end
return string
end | [
"def",
"encode_irc!",
"(",
"string",
",",
"encoding",
"=",
":irc",
")",
"if",
"encoding",
"==",
":irc",
"begin",
"string",
".",
"encode!",
"(",
"\"CP1252\"",
")",
"rescue",
"::",
"Encoding",
"::",
"UndefinedConversionError",
"end",
"else",
"string",
".",
"encode!",
"(",
"encoding",
",",
"{",
":invalid",
"=>",
":replace",
",",
":undef",
"=>",
":replace",
"}",
")",
".",
"force_encoding",
"(",
"\"ASCII-8BIT\"",
")",
"end",
"return",
"string",
"end"
] | Encode a message to be sent over an IRC connection, modifying it in place.
@param [String] string The string you want to encode.
@param [Symbol] encoding The target encoding.
@return [String] A string encoded in the encoding you specified. | [
"Encode",
"a",
"message",
"to",
"be",
"sent",
"over",
"an",
"IRC",
"connection",
"modifying",
"it",
"in",
"place",
"."
] | d028b7d5ccc604a6af175ee2264c18d25b1f7dff | https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/encoding.rb#L51-L74 | train |
otherinbox/luggage | lib/luggage/message.rb | Luggage.Message.reload | def reload
fields = fetch_fields
@mail = Mail.new(fields["BODY[]"])
@flags = fields["FLAGS"]
@date = Time.parse(fields["INTERNALDATE"])
self
end | ruby | def reload
fields = fetch_fields
@mail = Mail.new(fields["BODY[]"])
@flags = fields["FLAGS"]
@date = Time.parse(fields["INTERNALDATE"])
self
end | [
"def",
"reload",
"fields",
"=",
"fetch_fields",
"@mail",
"=",
"Mail",
".",
"new",
"(",
"fields",
"[",
"\"BODY[]\"",
"]",
")",
"@flags",
"=",
"fields",
"[",
"\"FLAGS\"",
"]",
"@date",
"=",
"Time",
".",
"parse",
"(",
"fields",
"[",
"\"INTERNALDATE\"",
"]",
")",
"self",
"end"
] | Fetch this message from the server and update all its attributes | [
"Fetch",
"this",
"message",
"from",
"the",
"server",
"and",
"update",
"all",
"its",
"attributes"
] | 032095e09e34cf93186dd9eea4d617d6cdfdd3ec | https://github.com/otherinbox/luggage/blob/032095e09e34cf93186dd9eea4d617d6cdfdd3ec/lib/luggage/message.rb#L68-L74 | train |
otherinbox/luggage | lib/luggage/message.rb | Luggage.Message.save! | def save!
mailbox.select!
connection.append(mailbox.name, raw_message, flags, date)
end | ruby | def save!
mailbox.select!
connection.append(mailbox.name, raw_message, flags, date)
end | [
"def",
"save!",
"mailbox",
".",
"select!",
"connection",
".",
"append",
"(",
"mailbox",
".",
"name",
",",
"raw_message",
",",
"flags",
",",
"date",
")",
"end"
] | Append this message to the remote mailbox | [
"Append",
"this",
"message",
"to",
"the",
"remote",
"mailbox"
] | 032095e09e34cf93186dd9eea4d617d6cdfdd3ec | https://github.com/otherinbox/luggage/blob/032095e09e34cf93186dd9eea4d617d6cdfdd3ec/lib/luggage/message.rb#L78-L81 | train |
otherinbox/luggage | lib/luggage/message.rb | Luggage.Message.copy_to! | def copy_to!(mailbox_name)
mailbox.select!
connection.uid_copy([uid], Luggage::Mailbox.convert_mailbox_name(mailbox_name))
end | ruby | def copy_to!(mailbox_name)
mailbox.select!
connection.uid_copy([uid], Luggage::Mailbox.convert_mailbox_name(mailbox_name))
end | [
"def",
"copy_to!",
"(",
"mailbox_name",
")",
"mailbox",
".",
"select!",
"connection",
".",
"uid_copy",
"(",
"[",
"uid",
"]",
",",
"Luggage",
"::",
"Mailbox",
".",
"convert_mailbox_name",
"(",
"mailbox_name",
")",
")",
"end"
] | Uses IMAP's COPY command to copy the message into the named mailbox | [
"Uses",
"IMAP",
"s",
"COPY",
"command",
"to",
"copy",
"the",
"message",
"into",
"the",
"named",
"mailbox"
] | 032095e09e34cf93186dd9eea4d617d6cdfdd3ec | https://github.com/otherinbox/luggage/blob/032095e09e34cf93186dd9eea4d617d6cdfdd3ec/lib/luggage/message.rb#L85-L88 | train |
detroit/detroit-locat | lib/detroit-locat.rb | Detroit.LOCat.generate | def generate
options = {}
options[:title] = title if title
options[:format] = format if format
options[:output] = output if output
options[:config] = config if config
options[:files] = collect_files
locat = ::LOCat::Command.new(options)
locat.run
end | ruby | def generate
options = {}
options[:title] = title if title
options[:format] = format if format
options[:output] = output if output
options[:config] = config if config
options[:files] = collect_files
locat = ::LOCat::Command.new(options)
locat.run
end | [
"def",
"generate",
"options",
"=",
"{",
"}",
"options",
"[",
":title",
"]",
"=",
"title",
"if",
"title",
"options",
"[",
":format",
"]",
"=",
"format",
"if",
"format",
"options",
"[",
":output",
"]",
"=",
"output",
"if",
"output",
"options",
"[",
":config",
"]",
"=",
"config",
"if",
"config",
"options",
"[",
":files",
"]",
"=",
"collect_files",
"locat",
"=",
"::",
"LOCat",
"::",
"Command",
".",
"new",
"(",
"options",
")",
"locat",
".",
"run",
"end"
] | S E R V I C E M E T H O D S
Render templates. | [
"S",
"E",
"R",
"V",
"I",
"C",
"E",
"M",
"E",
"T",
"H",
"O",
"D",
"S",
"Render",
"templates",
"."
] | dff72e2880a2c83a4b763e590326e5af56073981 | https://github.com/detroit/detroit-locat/blob/dff72e2880a2c83a4b763e590326e5af56073981/lib/detroit-locat.rb#L61-L73 | train |
Potpourri-Projects/fbuser | app/controllers/fbuser/api/v1/users_controller.rb | Fbuser.Api::V1::UsersController.index_authorize | def index_authorize
if !::Authorization::Fbuser::V1::User.index?(current_user)
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
end
end | ruby | def index_authorize
if !::Authorization::Fbuser::V1::User.index?(current_user)
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
end
end | [
"def",
"index_authorize",
"if",
"!",
"::",
"Authorization",
"::",
"Fbuser",
"::",
"V1",
"::",
"User",
".",
"index?",
"(",
"current_user",
")",
"render",
":json",
"=>",
"{",
"errors",
":",
"\"User is not authorized for this action\"",
"}",
",",
"status",
":",
":forbidden",
"end",
"end"
] | Authorizations below here | [
"Authorizations",
"below",
"here"
] | d39e6f107bdcf9d969df5e7b175e0e4f229e877d | https://github.com/Potpourri-Projects/fbuser/blob/d39e6f107bdcf9d969df5e7b175e0e4f229e877d/app/controllers/fbuser/api/v1/users_controller.rb#L70-L74 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.thePi | def thePi
hash = HashWithThermalFission.new
hash.thermal_fission[:U235] = 0.98
hash.thermal_fission[:Pu239] = 0.01
hash.thermal_fission[:U238] = 0.01
hash.thermal_fission
end | ruby | def thePi
hash = HashWithThermalFission.new
hash.thermal_fission[:U235] = 0.98
hash.thermal_fission[:Pu239] = 0.01
hash.thermal_fission[:U238] = 0.01
hash.thermal_fission
end | [
"def",
"thePi",
"hash",
"=",
"HashWithThermalFission",
".",
"new",
"hash",
".",
"thermal_fission",
"[",
":U235",
"]",
"=",
"0.98",
"hash",
".",
"thermal_fission",
"[",
":Pu239",
"]",
"=",
"0.01",
"hash",
".",
"thermal_fission",
"[",
":U238",
"]",
"=",
"0.01",
"hash",
".",
"thermal_fission",
"end"
] | thePi is Pi in ANS-5.1-1979. | [
"thePi",
"is",
"Pi",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L35-L43 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.theU235_alpha | def theU235_alpha
array = Array.new(23)
array[0] = 6.5057E-01
array[1] = 5.1264E-01
array[2] = 2.4384E-01
array[3] = 1.3850E-01
array[4] = 5.544E-02
array[5] = 2.2225E-02
array[6] = 3.3088E-03
array[7] = 9.3015E-04
array[8] = 8.0943E-04
array[9] = 1.9567E-04
array[10] = 3.2535E-05
array[11] = 7.5595E-06
array[12] = 2.5232E-06
array[13] = 4.9948E-07
array[14] = 1.8531E-07
array[15] = 2.6608E-08
array[16] = 2.2398E-09
array[17] = 8.1641E-12
array[18] = 8.7797E-11
array[19] = 2.5131E-14
array[20] = 3.2176E-16
array[21] = 4.5038E-17
array[22] = 7.4791E-17
array
end | ruby | def theU235_alpha
array = Array.new(23)
array[0] = 6.5057E-01
array[1] = 5.1264E-01
array[2] = 2.4384E-01
array[3] = 1.3850E-01
array[4] = 5.544E-02
array[5] = 2.2225E-02
array[6] = 3.3088E-03
array[7] = 9.3015E-04
array[8] = 8.0943E-04
array[9] = 1.9567E-04
array[10] = 3.2535E-05
array[11] = 7.5595E-06
array[12] = 2.5232E-06
array[13] = 4.9948E-07
array[14] = 1.8531E-07
array[15] = 2.6608E-08
array[16] = 2.2398E-09
array[17] = 8.1641E-12
array[18] = 8.7797E-11
array[19] = 2.5131E-14
array[20] = 3.2176E-16
array[21] = 4.5038E-17
array[22] = 7.4791E-17
array
end | [
"def",
"theU235_alpha",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"6.5057E-01",
"array",
"[",
"1",
"]",
"=",
"5.1264E-01",
"array",
"[",
"2",
"]",
"=",
"2.4384E-01",
"array",
"[",
"3",
"]",
"=",
"1.3850E-01",
"array",
"[",
"4",
"]",
"=",
"5.544E-02",
"array",
"[",
"5",
"]",
"=",
"2.2225E-02",
"array",
"[",
"6",
"]",
"=",
"3.3088E-03",
"array",
"[",
"7",
"]",
"=",
"9.3015E-04",
"array",
"[",
"8",
"]",
"=",
"8.0943E-04",
"array",
"[",
"9",
"]",
"=",
"1.9567E-04",
"array",
"[",
"10",
"]",
"=",
"3.2535E-05",
"array",
"[",
"11",
"]",
"=",
"7.5595E-06",
"array",
"[",
"12",
"]",
"=",
"2.5232E-06",
"array",
"[",
"13",
"]",
"=",
"4.9948E-07",
"array",
"[",
"14",
"]",
"=",
"1.8531E-07",
"array",
"[",
"15",
"]",
"=",
"2.6608E-08",
"array",
"[",
"16",
"]",
"=",
"2.2398E-09",
"array",
"[",
"17",
"]",
"=",
"8.1641E-12",
"array",
"[",
"18",
"]",
"=",
"8.7797E-11",
"array",
"[",
"19",
"]",
"=",
"2.5131E-14",
"array",
"[",
"20",
"]",
"=",
"3.2176E-16",
"array",
"[",
"21",
"]",
"=",
"4.5038E-17",
"array",
"[",
"22",
"]",
"=",
"7.4791E-17",
"array",
"end"
] | theU235_alpha is alpha in ANS-5.1-1979 Table 7. | [
"theU235_alpha",
"is",
"alpha",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"7",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L55-L83 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.theU235_lamda | def theU235_lamda
array = Array.new(23)
array[0] = 2.2138E+01
array[1] = 5.1587E-01
array[2] = 1.9594E-01
array[3] = 1.0314E-01
array[4] = 3.3656E-02
array[5] = 1.1681E-02
array[6] = 3.5870E-03
array[7] = 1.3930E-03
array[8] = 6.2630E-04
array[9] = 1.8906E-04
array[10] = 5.4988E-05
array[11] = 2.0958E-05
array[12] = 1.0010E-05
array[13] = 2.5438E-06
array[14] = 6.6361E-07
array[15] = 1.2290E-07
array[16] = 2.7213E-08
array[17] = 4.3714E-09
array[18] = 7.5780E-10
array[19] = 2.4786E-10
array[20] = 2.2384E-13
array[21] = 2.4600E-14
array[22] = 1.5699E-14
array
end | ruby | def theU235_lamda
array = Array.new(23)
array[0] = 2.2138E+01
array[1] = 5.1587E-01
array[2] = 1.9594E-01
array[3] = 1.0314E-01
array[4] = 3.3656E-02
array[5] = 1.1681E-02
array[6] = 3.5870E-03
array[7] = 1.3930E-03
array[8] = 6.2630E-04
array[9] = 1.8906E-04
array[10] = 5.4988E-05
array[11] = 2.0958E-05
array[12] = 1.0010E-05
array[13] = 2.5438E-06
array[14] = 6.6361E-07
array[15] = 1.2290E-07
array[16] = 2.7213E-08
array[17] = 4.3714E-09
array[18] = 7.5780E-10
array[19] = 2.4786E-10
array[20] = 2.2384E-13
array[21] = 2.4600E-14
array[22] = 1.5699E-14
array
end | [
"def",
"theU235_lamda",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"2.2138E+01",
"array",
"[",
"1",
"]",
"=",
"5.1587E-01",
"array",
"[",
"2",
"]",
"=",
"1.9594E-01",
"array",
"[",
"3",
"]",
"=",
"1.0314E-01",
"array",
"[",
"4",
"]",
"=",
"3.3656E-02",
"array",
"[",
"5",
"]",
"=",
"1.1681E-02",
"array",
"[",
"6",
"]",
"=",
"3.5870E-03",
"array",
"[",
"7",
"]",
"=",
"1.3930E-03",
"array",
"[",
"8",
"]",
"=",
"6.2630E-04",
"array",
"[",
"9",
"]",
"=",
"1.8906E-04",
"array",
"[",
"10",
"]",
"=",
"5.4988E-05",
"array",
"[",
"11",
"]",
"=",
"2.0958E-05",
"array",
"[",
"12",
"]",
"=",
"1.0010E-05",
"array",
"[",
"13",
"]",
"=",
"2.5438E-06",
"array",
"[",
"14",
"]",
"=",
"6.6361E-07",
"array",
"[",
"15",
"]",
"=",
"1.2290E-07",
"array",
"[",
"16",
"]",
"=",
"2.7213E-08",
"array",
"[",
"17",
"]",
"=",
"4.3714E-09",
"array",
"[",
"18",
"]",
"=",
"7.5780E-10",
"array",
"[",
"19",
"]",
"=",
"2.4786E-10",
"array",
"[",
"20",
"]",
"=",
"2.2384E-13",
"array",
"[",
"21",
"]",
"=",
"2.4600E-14",
"array",
"[",
"22",
"]",
"=",
"1.5699E-14",
"array",
"end"
] | theU235_lamda is lamda in ANS-5.1-1979 Table 7. | [
"theU235_lamda",
"is",
"lamda",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"7",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L86-L114 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.thePu239_alpha | def thePu239_alpha
array = Array.new(23)
array[0] = 2.083E-01
array[1] = 3.853E-01
array[2] = 2.213E-01
array[3] = 9.460E-02
array[4] = 3.531E-02
array[5] = 2.292E-02
array[6] = 3.946E-03
array[7] = 1.317E-03
array[8] = 7.052E-04
array[9] = 1.432E-04
array[10] = 1.765E-05
array[11] = 7.347E-06
array[12] = 1.747E-06
array[13] = 5.481E-07
array[14] = 1.671E-07
array[15] = 2.112E-08
array[16] = 2.996E-09
array[17] = 5.107E-11
array[18] = 5.730E-11
array[19] = 4.138E-14
array[20] = 1.088E-15
array[21] = 2.454E-17
array[22] = 7.557E-17
array
end | ruby | def thePu239_alpha
array = Array.new(23)
array[0] = 2.083E-01
array[1] = 3.853E-01
array[2] = 2.213E-01
array[3] = 9.460E-02
array[4] = 3.531E-02
array[5] = 2.292E-02
array[6] = 3.946E-03
array[7] = 1.317E-03
array[8] = 7.052E-04
array[9] = 1.432E-04
array[10] = 1.765E-05
array[11] = 7.347E-06
array[12] = 1.747E-06
array[13] = 5.481E-07
array[14] = 1.671E-07
array[15] = 2.112E-08
array[16] = 2.996E-09
array[17] = 5.107E-11
array[18] = 5.730E-11
array[19] = 4.138E-14
array[20] = 1.088E-15
array[21] = 2.454E-17
array[22] = 7.557E-17
array
end | [
"def",
"thePu239_alpha",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"2.083E-01",
"array",
"[",
"1",
"]",
"=",
"3.853E-01",
"array",
"[",
"2",
"]",
"=",
"2.213E-01",
"array",
"[",
"3",
"]",
"=",
"9.460E-02",
"array",
"[",
"4",
"]",
"=",
"3.531E-02",
"array",
"[",
"5",
"]",
"=",
"2.292E-02",
"array",
"[",
"6",
"]",
"=",
"3.946E-03",
"array",
"[",
"7",
"]",
"=",
"1.317E-03",
"array",
"[",
"8",
"]",
"=",
"7.052E-04",
"array",
"[",
"9",
"]",
"=",
"1.432E-04",
"array",
"[",
"10",
"]",
"=",
"1.765E-05",
"array",
"[",
"11",
"]",
"=",
"7.347E-06",
"array",
"[",
"12",
"]",
"=",
"1.747E-06",
"array",
"[",
"13",
"]",
"=",
"5.481E-07",
"array",
"[",
"14",
"]",
"=",
"1.671E-07",
"array",
"[",
"15",
"]",
"=",
"2.112E-08",
"array",
"[",
"16",
"]",
"=",
"2.996E-09",
"array",
"[",
"17",
"]",
"=",
"5.107E-11",
"array",
"[",
"18",
"]",
"=",
"5.730E-11",
"array",
"[",
"19",
"]",
"=",
"4.138E-14",
"array",
"[",
"20",
"]",
"=",
"1.088E-15",
"array",
"[",
"21",
"]",
"=",
"2.454E-17",
"array",
"[",
"22",
"]",
"=",
"7.557E-17",
"array",
"end"
] | thePu239_alpha is alpha in ANS-5.1-1979 Table 8. | [
"thePu239_alpha",
"is",
"alpha",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"8",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L117-L145 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.thePu239_lamda | def thePu239_lamda
array = Array.new(23)
array[0] = 1.002E+01
array[1] = 6.433E-01
array[2] = 2.186E-01
array[3] = 1.004E-01
array[4] = 3.728E-02
array[5] = 1.435E-02
array[6] = 4.549E-03
array[7] = 1.328E-03
array[8] = 5.356E-04
array[9] = 1.730E-04
array[10] = 4.881E-05
array[11] = 2.006E-05
array[12] = 8.319E-06
array[13] = 2.358E-06
array[14] = 6.450E-07
array[15] = 1.278E-07
array[16] = 2.466E-08
array[17] = 9.378E-09
array[18] = 7.450E-10
array[19] = 2.426E-10
array[20] = 2.210E-13
array[21] = 2.640E-14
array[22] = 1.380E-14
array
end | ruby | def thePu239_lamda
array = Array.new(23)
array[0] = 1.002E+01
array[1] = 6.433E-01
array[2] = 2.186E-01
array[3] = 1.004E-01
array[4] = 3.728E-02
array[5] = 1.435E-02
array[6] = 4.549E-03
array[7] = 1.328E-03
array[8] = 5.356E-04
array[9] = 1.730E-04
array[10] = 4.881E-05
array[11] = 2.006E-05
array[12] = 8.319E-06
array[13] = 2.358E-06
array[14] = 6.450E-07
array[15] = 1.278E-07
array[16] = 2.466E-08
array[17] = 9.378E-09
array[18] = 7.450E-10
array[19] = 2.426E-10
array[20] = 2.210E-13
array[21] = 2.640E-14
array[22] = 1.380E-14
array
end | [
"def",
"thePu239_lamda",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"1.002E+01",
"array",
"[",
"1",
"]",
"=",
"6.433E-01",
"array",
"[",
"2",
"]",
"=",
"2.186E-01",
"array",
"[",
"3",
"]",
"=",
"1.004E-01",
"array",
"[",
"4",
"]",
"=",
"3.728E-02",
"array",
"[",
"5",
"]",
"=",
"1.435E-02",
"array",
"[",
"6",
"]",
"=",
"4.549E-03",
"array",
"[",
"7",
"]",
"=",
"1.328E-03",
"array",
"[",
"8",
"]",
"=",
"5.356E-04",
"array",
"[",
"9",
"]",
"=",
"1.730E-04",
"array",
"[",
"10",
"]",
"=",
"4.881E-05",
"array",
"[",
"11",
"]",
"=",
"2.006E-05",
"array",
"[",
"12",
"]",
"=",
"8.319E-06",
"array",
"[",
"13",
"]",
"=",
"2.358E-06",
"array",
"[",
"14",
"]",
"=",
"6.450E-07",
"array",
"[",
"15",
"]",
"=",
"1.278E-07",
"array",
"[",
"16",
"]",
"=",
"2.466E-08",
"array",
"[",
"17",
"]",
"=",
"9.378E-09",
"array",
"[",
"18",
"]",
"=",
"7.450E-10",
"array",
"[",
"19",
"]",
"=",
"2.426E-10",
"array",
"[",
"20",
"]",
"=",
"2.210E-13",
"array",
"[",
"21",
"]",
"=",
"2.640E-14",
"array",
"[",
"22",
"]",
"=",
"1.380E-14",
"array",
"end"
] | thePu239_lamda is lamda in ANS-5.1-1979 Table 8. | [
"thePu239_lamda",
"is",
"lamda",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"8",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L148-L176 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.theU238_alpha | def theU238_alpha
array = Array.new(23)
array[0] = 1.2311E+0
array[1] = 1.1486E+0
array[2] = 7.0701E-01
array[3] = 2.5209E-01
array[4] = 7.187E-02
array[5] = 2.8291E-02
array[6] = 6.8382E-03
array[7] = 1.2322E-03
array[8] = 6.8409E-04
array[9] = 1.6975E-04
array[10] = 2.4182E-05
array[11] = 6.6356E-06
array[12] = 1.0075E-06
array[13] = 4.9894E-07
array[14] = 1.6352E-07
array[15] = 2.3355E-08
array[16] = 2.8094E-09
array[17] = 3.6236E-11
array[18] = 6.4577E-11
array[19] = 4.4963E-14
array[20] = 3.6654E-16
array[21] = 5.6293E-17
array[22] = 7.1602E-17
array
end | ruby | def theU238_alpha
array = Array.new(23)
array[0] = 1.2311E+0
array[1] = 1.1486E+0
array[2] = 7.0701E-01
array[3] = 2.5209E-01
array[4] = 7.187E-02
array[5] = 2.8291E-02
array[6] = 6.8382E-03
array[7] = 1.2322E-03
array[8] = 6.8409E-04
array[9] = 1.6975E-04
array[10] = 2.4182E-05
array[11] = 6.6356E-06
array[12] = 1.0075E-06
array[13] = 4.9894E-07
array[14] = 1.6352E-07
array[15] = 2.3355E-08
array[16] = 2.8094E-09
array[17] = 3.6236E-11
array[18] = 6.4577E-11
array[19] = 4.4963E-14
array[20] = 3.6654E-16
array[21] = 5.6293E-17
array[22] = 7.1602E-17
array
end | [
"def",
"theU238_alpha",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"1.2311E+0",
"array",
"[",
"1",
"]",
"=",
"1.1486E+0",
"array",
"[",
"2",
"]",
"=",
"7.0701E-01",
"array",
"[",
"3",
"]",
"=",
"2.5209E-01",
"array",
"[",
"4",
"]",
"=",
"7.187E-02",
"array",
"[",
"5",
"]",
"=",
"2.8291E-02",
"array",
"[",
"6",
"]",
"=",
"6.8382E-03",
"array",
"[",
"7",
"]",
"=",
"1.2322E-03",
"array",
"[",
"8",
"]",
"=",
"6.8409E-04",
"array",
"[",
"9",
"]",
"=",
"1.6975E-04",
"array",
"[",
"10",
"]",
"=",
"2.4182E-05",
"array",
"[",
"11",
"]",
"=",
"6.6356E-06",
"array",
"[",
"12",
"]",
"=",
"1.0075E-06",
"array",
"[",
"13",
"]",
"=",
"4.9894E-07",
"array",
"[",
"14",
"]",
"=",
"1.6352E-07",
"array",
"[",
"15",
"]",
"=",
"2.3355E-08",
"array",
"[",
"16",
"]",
"=",
"2.8094E-09",
"array",
"[",
"17",
"]",
"=",
"3.6236E-11",
"array",
"[",
"18",
"]",
"=",
"6.4577E-11",
"array",
"[",
"19",
"]",
"=",
"4.4963E-14",
"array",
"[",
"20",
"]",
"=",
"3.6654E-16",
"array",
"[",
"21",
"]",
"=",
"5.6293E-17",
"array",
"[",
"22",
"]",
"=",
"7.1602E-17",
"array",
"end"
] | theU238_alpha is alpha in ANS-5.1-1979 Table 9. | [
"theU238_alpha",
"is",
"alpha",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"9",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L179-L207 | train |
ccclin/decay_heat_with_nuclear | lib/decay_heat_with_nuclear/thermal_data.rb | ThermalData.DataForANS_5_1_1979.theU238_lamda | def theU238_lamda
array = Array.new(23)
array[0] = 3.2881E+0
array[1] = 9.3805E-01
array[2] = 3.7073E-01
array[3] = 1.1118E-01
array[4] = 3.6143E-02
array[5] = 1.3272E-02
array[6] = 5.0133E-03
array[7] = 1.3655E-03
array[8] = 5.5158E-04
array[9] = 1.7873E-04
array[10] = 4.9032E-05
array[11] = 1.7058E-05
array[12] = 7.0465E-06
array[13] = 2.3190E-06
array[14] = 6.4480E-07
array[15] = 1.2649E-07
array[16] = 2.5548E-08
array[17] = 8.4782E-09
array[18] = 7.5130E-10
array[19] = 2.4188E-10
array[20] = 2.2739E-13
array[21] = 9.0536E-14
array[22] = 5.6098E-15
array
end | ruby | def theU238_lamda
array = Array.new(23)
array[0] = 3.2881E+0
array[1] = 9.3805E-01
array[2] = 3.7073E-01
array[3] = 1.1118E-01
array[4] = 3.6143E-02
array[5] = 1.3272E-02
array[6] = 5.0133E-03
array[7] = 1.3655E-03
array[8] = 5.5158E-04
array[9] = 1.7873E-04
array[10] = 4.9032E-05
array[11] = 1.7058E-05
array[12] = 7.0465E-06
array[13] = 2.3190E-06
array[14] = 6.4480E-07
array[15] = 1.2649E-07
array[16] = 2.5548E-08
array[17] = 8.4782E-09
array[18] = 7.5130E-10
array[19] = 2.4188E-10
array[20] = 2.2739E-13
array[21] = 9.0536E-14
array[22] = 5.6098E-15
array
end | [
"def",
"theU238_lamda",
"array",
"=",
"Array",
".",
"new",
"(",
"23",
")",
"array",
"[",
"0",
"]",
"=",
"3.2881E+0",
"array",
"[",
"1",
"]",
"=",
"9.3805E-01",
"array",
"[",
"2",
"]",
"=",
"3.7073E-01",
"array",
"[",
"3",
"]",
"=",
"1.1118E-01",
"array",
"[",
"4",
"]",
"=",
"3.6143E-02",
"array",
"[",
"5",
"]",
"=",
"1.3272E-02",
"array",
"[",
"6",
"]",
"=",
"5.0133E-03",
"array",
"[",
"7",
"]",
"=",
"1.3655E-03",
"array",
"[",
"8",
"]",
"=",
"5.5158E-04",
"array",
"[",
"9",
"]",
"=",
"1.7873E-04",
"array",
"[",
"10",
"]",
"=",
"4.9032E-05",
"array",
"[",
"11",
"]",
"=",
"1.7058E-05",
"array",
"[",
"12",
"]",
"=",
"7.0465E-06",
"array",
"[",
"13",
"]",
"=",
"2.3190E-06",
"array",
"[",
"14",
"]",
"=",
"6.4480E-07",
"array",
"[",
"15",
"]",
"=",
"1.2649E-07",
"array",
"[",
"16",
"]",
"=",
"2.5548E-08",
"array",
"[",
"17",
"]",
"=",
"8.4782E-09",
"array",
"[",
"18",
"]",
"=",
"7.5130E-10",
"array",
"[",
"19",
"]",
"=",
"2.4188E-10",
"array",
"[",
"20",
"]",
"=",
"2.2739E-13",
"array",
"[",
"21",
"]",
"=",
"9.0536E-14",
"array",
"[",
"22",
"]",
"=",
"5.6098E-15",
"array",
"end"
] | theU238_lamda is lamda in ANS-5.1-1979 Table 9. | [
"theU238_lamda",
"is",
"lamda",
"in",
"ANS",
"-",
"5",
".",
"1",
"-",
"1979",
"Table",
"9",
"."
] | fc81505803c9d8488420216ca6f0e6597b2c47d7 | https://github.com/ccclin/decay_heat_with_nuclear/blob/fc81505803c9d8488420216ca6f0e6597b2c47d7/lib/decay_heat_with_nuclear/thermal_data.rb#L210-L238 | train |
bwillis/rockit | lib/rockit/application.rb | Rockit.Application.run | def run
rockit_file = CONFIG_FILES.select { |f| File.exists?(f) }.first
raise ArgumentError "No Rockitfile found (looking for: #{CONFIG_FILES.join(',')})" unless rockit_file
Dsl.new(self).instance_eval(File.read(rockit_file), rockit_file)
end | ruby | def run
rockit_file = CONFIG_FILES.select { |f| File.exists?(f) }.first
raise ArgumentError "No Rockitfile found (looking for: #{CONFIG_FILES.join(',')})" unless rockit_file
Dsl.new(self).instance_eval(File.read(rockit_file), rockit_file)
end | [
"def",
"run",
"rockit_file",
"=",
"CONFIG_FILES",
".",
"select",
"{",
"|",
"f",
"|",
"File",
".",
"exists?",
"(",
"f",
")",
"}",
".",
"first",
"raise",
"ArgumentError",
"\"No Rockitfile found (looking for: #{CONFIG_FILES.join(',')})\"",
"unless",
"rockit_file",
"Dsl",
".",
"new",
"(",
"self",
")",
".",
"instance_eval",
"(",
"File",
".",
"read",
"(",
"rockit_file",
")",
",",
"rockit_file",
")",
"end"
] | Run a Rockit configuration file and Rails dependency checks
unless turned off by configuration. | [
"Run",
"a",
"Rockit",
"configuration",
"file",
"and",
"Rails",
"dependency",
"checks",
"unless",
"turned",
"off",
"by",
"configuration",
"."
] | b0604538e2436d6c26a4e29c605235638e819fee | https://github.com/bwillis/rockit/blob/b0604538e2436d6c26a4e29c605235638e819fee/lib/rockit/application.rb#L26-L30 | train |
bwillis/rockit | lib/rockit/application.rb | Rockit.Application.if_string_digest_changed | def if_string_digest_changed(key, input, &block)
if_string_changed(key, Digest::SHA256.new.update(input.to_s).hexdigest.to_s, &block)
end | ruby | def if_string_digest_changed(key, input, &block)
if_string_changed(key, Digest::SHA256.new.update(input.to_s).hexdigest.to_s, &block)
end | [
"def",
"if_string_digest_changed",
"(",
"key",
",",
"input",
",",
"&",
"block",
")",
"if_string_changed",
"(",
"key",
",",
"Digest",
"::",
"SHA256",
".",
"new",
".",
"update",
"(",
"input",
".",
"to_s",
")",
".",
"hexdigest",
".",
"to_s",
",",
"&",
"block",
")",
"end"
] | If the digest of the input is different from the stored key, execute the block. | [
"If",
"the",
"digest",
"of",
"the",
"input",
"is",
"different",
"from",
"the",
"stored",
"key",
"execute",
"the",
"block",
"."
] | b0604538e2436d6c26a4e29c605235638e819fee | https://github.com/bwillis/rockit/blob/b0604538e2436d6c26a4e29c605235638e819fee/lib/rockit/application.rb#L78-L80 | train |
bwillis/rockit | lib/rockit/application.rb | Rockit.Application.if_file_changed | def if_file_changed(file, &block)
if_string_changed(file, Digest::SHA256.file(file).hexdigest.to_s, &block)
end | ruby | def if_file_changed(file, &block)
if_string_changed(file, Digest::SHA256.file(file).hexdigest.to_s, &block)
end | [
"def",
"if_file_changed",
"(",
"file",
",",
"&",
"block",
")",
"if_string_changed",
"(",
"file",
",",
"Digest",
"::",
"SHA256",
".",
"file",
"(",
"file",
")",
".",
"hexdigest",
".",
"to_s",
",",
"&",
"block",
")",
"end"
] | If the digest of the file is different from the stored digest, execute the block. | [
"If",
"the",
"digest",
"of",
"the",
"file",
"is",
"different",
"from",
"the",
"stored",
"digest",
"execute",
"the",
"block",
"."
] | b0604538e2436d6c26a4e29c605235638e819fee | https://github.com/bwillis/rockit/blob/b0604538e2436d6c26a4e29c605235638e819fee/lib/rockit/application.rb#L83-L85 | train |
bwillis/rockit | lib/rockit/application.rb | Rockit.Application.if_string_changed | def if_string_changed(key, new_value, &block)
if new_value != @hash_store[key]
old_value = @hash_store[key]
@hash_store[key] = new_value
block.call(key, new_value, old_value) if block_given?
end
end | ruby | def if_string_changed(key, new_value, &block)
if new_value != @hash_store[key]
old_value = @hash_store[key]
@hash_store[key] = new_value
block.call(key, new_value, old_value) if block_given?
end
end | [
"def",
"if_string_changed",
"(",
"key",
",",
"new_value",
",",
"&",
"block",
")",
"if",
"new_value",
"!=",
"@hash_store",
"[",
"key",
"]",
"old_value",
"=",
"@hash_store",
"[",
"key",
"]",
"@hash_store",
"[",
"key",
"]",
"=",
"new_value",
"block",
".",
"call",
"(",
"key",
",",
"new_value",
",",
"old_value",
")",
"if",
"block_given?",
"end",
"end"
] | Execute the given block if the input is different from
the output .
key - the key to lookup the stored hash value
new_value - the value to compare with the stored hash value
block - block to execute if the hash value does not match the stored hash value
return if the block was not executed, false, if it is executed, the return
status of the block | [
"Execute",
"the",
"given",
"block",
"if",
"the",
"input",
"is",
"different",
"from",
"the",
"output",
"."
] | b0604538e2436d6c26a4e29c605235638e819fee | https://github.com/bwillis/rockit/blob/b0604538e2436d6c26a4e29c605235638e819fee/lib/rockit/application.rb#L96-L102 | train |
bwillis/rockit | lib/rockit/application.rb | Rockit.Application.system_exit_on_error | def system_exit_on_error(command, options={})
options = {'print_command' => true}.merge(string_keys(options))
output command if options['print_command'] || @debug
command_output = system_command(command)
output command_output if @debug
unless last_process.success?
result = options['on_failure'].call(command, options) if options['on_failure'].is_a?(Proc)
return true if result
output options['failure_message'] || command_output
return exit(last_process.exitstatus)
end
options['on_success'].call(command, options) if options['on_success'].is_a?(Proc)
true
end | ruby | def system_exit_on_error(command, options={})
options = {'print_command' => true}.merge(string_keys(options))
output command if options['print_command'] || @debug
command_output = system_command(command)
output command_output if @debug
unless last_process.success?
result = options['on_failure'].call(command, options) if options['on_failure'].is_a?(Proc)
return true if result
output options['failure_message'] || command_output
return exit(last_process.exitstatus)
end
options['on_success'].call(command, options) if options['on_success'].is_a?(Proc)
true
end | [
"def",
"system_exit_on_error",
"(",
"command",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"'print_command'",
"=>",
"true",
"}",
".",
"merge",
"(",
"string_keys",
"(",
"options",
")",
")",
"output",
"command",
"if",
"options",
"[",
"'print_command'",
"]",
"||",
"@debug",
"command_output",
"=",
"system_command",
"(",
"command",
")",
"output",
"command_output",
"if",
"@debug",
"unless",
"last_process",
".",
"success?",
"result",
"=",
"options",
"[",
"'on_failure'",
"]",
".",
"call",
"(",
"command",
",",
"options",
")",
"if",
"options",
"[",
"'on_failure'",
"]",
".",
"is_a?",
"(",
"Proc",
")",
"return",
"true",
"if",
"result",
"output",
"options",
"[",
"'failure_message'",
"]",
"||",
"command_output",
"return",
"exit",
"(",
"last_process",
".",
"exitstatus",
")",
"end",
"options",
"[",
"'on_success'",
"]",
".",
"call",
"(",
"command",
",",
"options",
")",
"if",
"options",
"[",
"'on_success'",
"]",
".",
"is_a?",
"(",
"Proc",
")",
"true",
"end"
] | Run system commands and if not successful exit and print out an error
message. Default behavior is to print output of a command when it does
not return success.
command - the system command you want to execute
options - 'error_message' - a message to print when command is not successful
'print_command' - displays the command being run
'failure_callback' - Proc to execute when the command fails. If a callback returns
true then it will avoid
'on_success' - Proc to execute when the command is successful
returns only true, will perform exit() when not successful | [
"Run",
"system",
"commands",
"and",
"if",
"not",
"successful",
"exit",
"and",
"print",
"out",
"an",
"error",
"message",
".",
"Default",
"behavior",
"is",
"to",
"print",
"output",
"of",
"a",
"command",
"when",
"it",
"does",
"not",
"return",
"success",
"."
] | b0604538e2436d6c26a4e29c605235638e819fee | https://github.com/bwillis/rockit/blob/b0604538e2436d6c26a4e29c605235638e819fee/lib/rockit/application.rb#L117-L130 | train |
epuber-io/bade | lib/bade/renderer.rb | Bade.Renderer._find_file! | def _find_file!(name, reference_path)
sub_path = File.expand_path(name, File.dirname(reference_path))
if File.exist?(sub_path)
return if sub_path.end_with?('.rb') # handled in Generator
sub_path
else
bade_path = "#{sub_path}.bade"
rb_path = "#{sub_path}.rb"
bade_exist = File.exist?(bade_path)
rb_exist = File.exist?(rb_path)
relative = Pathname.new(reference_path).relative_path_from(Pathname.new(File.dirname(file_path))).to_s
if bade_exist && rb_exist
message = "Found both .bade and .rb files for `#{name}` in file #{relative}, "\
'change the import path so it references uniq file.'
raise LoadError.new(name, reference_path, message)
elsif bade_exist
return bade_path
elsif rb_exist
return # handled in Generator
else
message = "Can't find file matching name `#{name}` referenced from file #{relative}"
raise LoadError.new(name, reference_path, message)
end
end
end | ruby | def _find_file!(name, reference_path)
sub_path = File.expand_path(name, File.dirname(reference_path))
if File.exist?(sub_path)
return if sub_path.end_with?('.rb') # handled in Generator
sub_path
else
bade_path = "#{sub_path}.bade"
rb_path = "#{sub_path}.rb"
bade_exist = File.exist?(bade_path)
rb_exist = File.exist?(rb_path)
relative = Pathname.new(reference_path).relative_path_from(Pathname.new(File.dirname(file_path))).to_s
if bade_exist && rb_exist
message = "Found both .bade and .rb files for `#{name}` in file #{relative}, "\
'change the import path so it references uniq file.'
raise LoadError.new(name, reference_path, message)
elsif bade_exist
return bade_path
elsif rb_exist
return # handled in Generator
else
message = "Can't find file matching name `#{name}` referenced from file #{relative}"
raise LoadError.new(name, reference_path, message)
end
end
end | [
"def",
"_find_file!",
"(",
"name",
",",
"reference_path",
")",
"sub_path",
"=",
"File",
".",
"expand_path",
"(",
"name",
",",
"File",
".",
"dirname",
"(",
"reference_path",
")",
")",
"if",
"File",
".",
"exist?",
"(",
"sub_path",
")",
"return",
"if",
"sub_path",
".",
"end_with?",
"(",
"'.rb'",
")",
"sub_path",
"else",
"bade_path",
"=",
"\"#{sub_path}.bade\"",
"rb_path",
"=",
"\"#{sub_path}.rb\"",
"bade_exist",
"=",
"File",
".",
"exist?",
"(",
"bade_path",
")",
"rb_exist",
"=",
"File",
".",
"exist?",
"(",
"rb_path",
")",
"relative",
"=",
"Pathname",
".",
"new",
"(",
"reference_path",
")",
".",
"relative_path_from",
"(",
"Pathname",
".",
"new",
"(",
"File",
".",
"dirname",
"(",
"file_path",
")",
")",
")",
".",
"to_s",
"if",
"bade_exist",
"&&",
"rb_exist",
"message",
"=",
"\"Found both .bade and .rb files for `#{name}` in file #{relative}, \"",
"'change the import path so it references uniq file.'",
"raise",
"LoadError",
".",
"new",
"(",
"name",
",",
"reference_path",
",",
"message",
")",
"elsif",
"bade_exist",
"return",
"bade_path",
"elsif",
"rb_exist",
"return",
"else",
"message",
"=",
"\"Can't find file matching name `#{name}` referenced from file #{relative}\"",
"raise",
"LoadError",
".",
"new",
"(",
"name",
",",
"reference_path",
",",
"message",
")",
"end",
"end",
"end"
] | Tries to find file with name, if no file could be found or there are multiple files matching the name error is
raised
@param [String] name name of the file that should be found
@param [String] reference_path path to file from which is loading/finding
@return [String, nil] returns nil when this file should be skipped otherwise absolute path to file | [
"Tries",
"to",
"find",
"file",
"with",
"name",
"if",
"no",
"file",
"could",
"be",
"found",
"or",
"there",
"are",
"multiple",
"files",
"matching",
"the",
"name",
"error",
"is",
"raised"
] | fe128e0178d28b5a789d94b861ac6c6d2e4a3a8e | https://github.com/epuber-io/bade/blob/fe128e0178d28b5a789d94b861ac6c6d2e4a3a8e/lib/bade/renderer.rb#L247-L274 | train |
Raybeam/myreplicator | lib/exporter/export_metadata.rb | Myreplicator.ExportMetadata.equals | def equals object
if table == object.table && database == object.database
return true
end
return false
end | ruby | def equals object
if table == object.table && database == object.database
return true
end
return false
end | [
"def",
"equals",
"object",
"if",
"table",
"==",
"object",
".",
"table",
"&&",
"database",
"==",
"object",
".",
"database",
"return",
"true",
"end",
"return",
"false",
"end"
] | Compares the object with another metadata object
Return true if they are for the same table | [
"Compares",
"the",
"object",
"with",
"another",
"metadata",
"object",
"Return",
"true",
"if",
"they",
"are",
"for",
"the",
"same",
"table"
] | 470938e70f46886b525c65a4a464b4cf8383d00d | https://github.com/Raybeam/myreplicator/blob/470938e70f46886b525c65a4a464b4cf8383d00d/lib/exporter/export_metadata.rb#L60-L65 | train |
Raybeam/myreplicator | lib/exporter/export_metadata.rb | Myreplicator.ExportMetadata.store! | def store!
Kernel.p "$$$$$$$$$$$$$$$$$$ @ssh CHECK $$$$$$$$$$$$$$$$$$"
cmd = "echo \"#{self.to_json.gsub("\"","\\\\\"")}\" > #{@filepath}.json"
puts cmd
result = @ssh.exec!(cmd)
puts result
end | ruby | def store!
Kernel.p "$$$$$$$$$$$$$$$$$$ @ssh CHECK $$$$$$$$$$$$$$$$$$"
cmd = "echo \"#{self.to_json.gsub("\"","\\\\\"")}\" > #{@filepath}.json"
puts cmd
result = @ssh.exec!(cmd)
puts result
end | [
"def",
"store!",
"Kernel",
".",
"p",
"\"$$$$$$$$$$$$$$$$$$ @ssh CHECK $$$$$$$$$$$$$$$$$$\"",
"cmd",
"=",
"\"echo \\\"#{self.to_json.gsub(\"\\\"\",\"\\\\\\\\\\\"\")}\\\" > #{@filepath}.json\"",
"puts",
"cmd",
"result",
"=",
"@ssh",
".",
"exec!",
"(",
"cmd",
")",
"puts",
"result",
"end"
] | Writes Json to file using echo
file is written to remote server via SSH
Echo is used for writing the file | [
"Writes",
"Json",
"to",
"file",
"using",
"echo",
"file",
"is",
"written",
"to",
"remote",
"server",
"via",
"SSH",
"Echo",
"is",
"used",
"for",
"writing",
"the",
"file"
] | 470938e70f46886b525c65a4a464b4cf8383d00d | https://github.com/Raybeam/myreplicator/blob/470938e70f46886b525c65a4a464b4cf8383d00d/lib/exporter/export_metadata.rb#L192-L198 | train |
nulogy/spreadsheet | lib/spreadsheet/row.rb | Spreadsheet.Row.formatted | def formatted
copy = dup
@formats.rcompact!
if copy.length < @formats.size
copy.concat Array.new(@formats.size - copy.length)
end
copy
end | ruby | def formatted
copy = dup
@formats.rcompact!
if copy.length < @formats.size
copy.concat Array.new(@formats.size - copy.length)
end
copy
end | [
"def",
"formatted",
"copy",
"=",
"dup",
"@formats",
".",
"rcompact!",
"if",
"copy",
".",
"length",
"<",
"@formats",
".",
"size",
"copy",
".",
"concat",
"Array",
".",
"new",
"(",
"@formats",
".",
"size",
"-",
"copy",
".",
"length",
")",
"end",
"copy",
"end"
] | Returns a copy of self with nil-values appended for empty cells that have
an associated Format.
This is primarily a helper-function for the writer classes. | [
"Returns",
"a",
"copy",
"of",
"self",
"with",
"nil",
"-",
"values",
"appended",
"for",
"empty",
"cells",
"that",
"have",
"an",
"associated",
"Format",
".",
"This",
"is",
"primarily",
"a",
"helper",
"-",
"function",
"for",
"the",
"writer",
"classes",
"."
] | c89825047f02ab26deddaab779f3b4ca349b6a0c | https://github.com/nulogy/spreadsheet/blob/c89825047f02ab26deddaab779f3b4ca349b6a0c/lib/spreadsheet/row.rb#L91-L98 | train |
kenpratt/dbox | lib/dbox/utils.rb | Dbox.Utils.relative_to_local_path | def relative_to_local_path(path)
if path && path.length > 0
case_insensitive_join(local_path, path)
else
case_insensitive_resolve(local_path)
end
end | ruby | def relative_to_local_path(path)
if path && path.length > 0
case_insensitive_join(local_path, path)
else
case_insensitive_resolve(local_path)
end
end | [
"def",
"relative_to_local_path",
"(",
"path",
")",
"if",
"path",
"&&",
"path",
".",
"length",
">",
"0",
"case_insensitive_join",
"(",
"local_path",
",",
"path",
")",
"else",
"case_insensitive_resolve",
"(",
"local_path",
")",
"end",
"end"
] | assumes local_path is defined | [
"assumes",
"local_path",
"is",
"defined"
] | f75dbc9dfd8d6ddba24a812ac676cf07325f1899 | https://github.com/kenpratt/dbox/blob/f75dbc9dfd8d6ddba24a812ac676cf07325f1899/lib/dbox/utils.rb#L45-L51 | train |
kenpratt/dbox | lib/dbox/utils.rb | Dbox.Utils.relative_to_remote_path | def relative_to_remote_path(path)
if path && path.length > 0
File.join(remote_path, path)
else
remote_path
end
end | ruby | def relative_to_remote_path(path)
if path && path.length > 0
File.join(remote_path, path)
else
remote_path
end
end | [
"def",
"relative_to_remote_path",
"(",
"path",
")",
"if",
"path",
"&&",
"path",
".",
"length",
">",
"0",
"File",
".",
"join",
"(",
"remote_path",
",",
"path",
")",
"else",
"remote_path",
"end",
"end"
] | assumes remote_path is defined | [
"assumes",
"remote_path",
"is",
"defined"
] | f75dbc9dfd8d6ddba24a812ac676cf07325f1899 | https://github.com/kenpratt/dbox/blob/f75dbc9dfd8d6ddba24a812ac676cf07325f1899/lib/dbox/utils.rb#L54-L60 | train |
botanicus/nake | lib/nake/abstract_task.rb | Nake.AbstractTask.config | def config
@config ||= begin
Hash.new do |hash, key|
raise ConfigurationError, "Configuration key #{key} in task #{name} doesn't exist"
end.tap do |hash|
hash.define_singleton_method(:declare) do |*keys|
keys.each { |key| self[key] = nil unless self.has_key?(key) }
end
end
end
end | ruby | def config
@config ||= begin
Hash.new do |hash, key|
raise ConfigurationError, "Configuration key #{key} in task #{name} doesn't exist"
end.tap do |hash|
hash.define_singleton_method(:declare) do |*keys|
keys.each { |key| self[key] = nil unless self.has_key?(key) }
end
end
end
end | [
"def",
"config",
"@config",
"||=",
"begin",
"Hash",
".",
"new",
"do",
"|",
"hash",
",",
"key",
"|",
"raise",
"ConfigurationError",
",",
"\"Configuration key #{key} in task #{name} doesn't exist\"",
"end",
".",
"tap",
"do",
"|",
"hash",
"|",
"hash",
".",
"define_singleton_method",
"(",
":declare",
")",
"do",
"|",
"*",
"keys",
"|",
"keys",
".",
"each",
"{",
"|",
"key",
"|",
"self",
"[",
"key",
"]",
"=",
"nil",
"unless",
"self",
".",
"has_key?",
"(",
"key",
")",
"}",
"end",
"end",
"end",
"end"
] | don't use this if you don't have to! | [
"don",
"t",
"use",
"this",
"if",
"you",
"don",
"t",
"have",
"to!"
] | d0ca22c3ce686dc916bdbe5bbd5475a18371a41d | https://github.com/botanicus/nake/blob/d0ca22c3ce686dc916bdbe5bbd5475a18371a41d/lib/nake/abstract_task.rb#L61-L71 | train |
apostle/apostle-ruby | lib/apostle/mail.rb | Apostle.Mail.deliver! | def deliver!
return true unless Apostle.deliver
unless template_id && template_id != ''
raise DeliveryError,
'No email template_id provided'
end
queue = Apostle::Queue.new
queue.add self
queue.deliver!
# Return true or false depending on successful delivery
if queue.results[:valid].include?(self)
return true
else
raise _exception
end
end | ruby | def deliver!
return true unless Apostle.deliver
unless template_id && template_id != ''
raise DeliveryError,
'No email template_id provided'
end
queue = Apostle::Queue.new
queue.add self
queue.deliver!
# Return true or false depending on successful delivery
if queue.results[:valid].include?(self)
return true
else
raise _exception
end
end | [
"def",
"deliver!",
"return",
"true",
"unless",
"Apostle",
".",
"deliver",
"unless",
"template_id",
"&&",
"template_id",
"!=",
"''",
"raise",
"DeliveryError",
",",
"'No email template_id provided'",
"end",
"queue",
"=",
"Apostle",
"::",
"Queue",
".",
"new",
"queue",
".",
"add",
"self",
"queue",
".",
"deliver!",
"if",
"queue",
".",
"results",
"[",
":valid",
"]",
".",
"include?",
"(",
"self",
")",
"return",
"true",
"else",
"raise",
"_exception",
"end",
"end"
] | Shortcut method to deliver a single message | [
"Shortcut",
"method",
"to",
"deliver",
"a",
"single",
"message"
] | 1d3a99d62da4f4c6cdbc8f061ab7640b8f85d1e2 | https://github.com/apostle/apostle-ruby/blob/1d3a99d62da4f4c6cdbc8f061ab7640b8f85d1e2/lib/apostle/mail.rb#L59-L77 | train |
patchapps/rabbit-hutch | lib/worker.rb | RabbitHutch.Worker.start | def start
@exchange = @channel.topic(@exchange_name, :durable => true, :auto_delete => false, :internal => true)
@queue = @channel.queue(@queue_name, :durable => true, :auto_delete => false)
@queue.bind(@exchange, :routing_key => 'publish.#')
@queue.subscribe(&@consumer.method(:handle_message))
end | ruby | def start
@exchange = @channel.topic(@exchange_name, :durable => true, :auto_delete => false, :internal => true)
@queue = @channel.queue(@queue_name, :durable => true, :auto_delete => false)
@queue.bind(@exchange, :routing_key => 'publish.#')
@queue.subscribe(&@consumer.method(:handle_message))
end | [
"def",
"start",
"@exchange",
"=",
"@channel",
".",
"topic",
"(",
"@exchange_name",
",",
":durable",
"=>",
"true",
",",
":auto_delete",
"=>",
"false",
",",
":internal",
"=>",
"true",
")",
"@queue",
"=",
"@channel",
".",
"queue",
"(",
"@queue_name",
",",
":durable",
"=>",
"true",
",",
":auto_delete",
"=>",
"false",
")",
"@queue",
".",
"bind",
"(",
"@exchange",
",",
":routing_key",
"=>",
"'publish.#'",
")",
"@queue",
".",
"subscribe",
"(",
"&",
"@consumer",
".",
"method",
"(",
":handle_message",
")",
")",
"end"
] | begin listening for all topics in publish. | [
"begin",
"listening",
"for",
"all",
"topics",
"in",
"publish",
"."
] | 42337b0ddda60b749fc2fe088f4e8dba674d198d | https://github.com/patchapps/rabbit-hutch/blob/42337b0ddda60b749fc2fe088f4e8dba674d198d/lib/worker.rb#L20-L25 | train |
codegram/simple_currency | lib/simple_currency/currency_convertible.rb | CurrencyConvertible.Proxy.cached_rate | def cached_rate(original, target)
if defined?(Rails)
unless rate = Rails.cache.read("#{original}_#{target}_#{stringified_exchange_date}")
rate = (1.0 / Rails.cache.read("#{target}_#{original}_#{stringified_exchange_date}")) rescue nil
end
rate
end
end | ruby | def cached_rate(original, target)
if defined?(Rails)
unless rate = Rails.cache.read("#{original}_#{target}_#{stringified_exchange_date}")
rate = (1.0 / Rails.cache.read("#{target}_#{original}_#{stringified_exchange_date}")) rescue nil
end
rate
end
end | [
"def",
"cached_rate",
"(",
"original",
",",
"target",
")",
"if",
"defined?",
"(",
"Rails",
")",
"unless",
"rate",
"=",
"Rails",
".",
"cache",
".",
"read",
"(",
"\"#{original}_#{target}_#{stringified_exchange_date}\"",
")",
"rate",
"=",
"(",
"1.0",
"/",
"Rails",
".",
"cache",
".",
"read",
"(",
"\"#{target}_#{original}_#{stringified_exchange_date}\"",
")",
")",
"rescue",
"nil",
"end",
"rate",
"end",
"end"
] | Tries to either get rate or calculate the inverse rate from cache.
First looks for an "usd_eur_25-8-2010" entry in the cache,
and if it does not find it, it looks for "eur_usd_25-8-2010" and
inverts it. | [
"Tries",
"to",
"either",
"get",
"rate",
"or",
"calculate",
"the",
"inverse",
"rate",
"from",
"cache",
"."
] | 4bc4406735dc095ed9ba97ee3a4dcb9b72d047ec | https://github.com/codegram/simple_currency/blob/4bc4406735dc095ed9ba97ee3a4dcb9b72d047ec/lib/simple_currency/currency_convertible.rb#L189-L196 | train |
reggieb/ominous | app/models/ominous/warning.rb | Ominous.Warning.pass_method_to_warning_closer | def pass_method_to_warning_closer(symbol, closer)
raise "A closer is needed to identify the warning_closer" unless closer.kind_of? Closer
warning_closer = warning_closers.where(:closer_id => closer.id).first
warning_closer.send(symbol) if warning_closer
end | ruby | def pass_method_to_warning_closer(symbol, closer)
raise "A closer is needed to identify the warning_closer" unless closer.kind_of? Closer
warning_closer = warning_closers.where(:closer_id => closer.id).first
warning_closer.send(symbol) if warning_closer
end | [
"def",
"pass_method_to_warning_closer",
"(",
"symbol",
",",
"closer",
")",
"raise",
"\"A closer is needed to identify the warning_closer\"",
"unless",
"closer",
".",
"kind_of?",
"Closer",
"warning_closer",
"=",
"warning_closers",
".",
"where",
"(",
":closer_id",
"=>",
"closer",
".",
"id",
")",
".",
"first",
"warning_closer",
".",
"send",
"(",
"symbol",
")",
"if",
"warning_closer",
"end"
] | Allows acts_as_list methods to be used within the warning.
If closers were the act_as_list object, you could do things like this
warning.closers.last.move_higher
However, as closers are used on multiple warnings and they
need to be independently sortable within each warning, it is the
through table model WarningCloser that acts_as_list. To change
position the change must be made in the context of the warning.
pass_method_to_warning_closer in combination with method_missing,
allows you to pass to a warning the acts_as_list method together with
the closer it needs to effect. The equivalent move_higher call then becomes:
warning.move_higher(warning.closers.last)
You can also do:
warning.move_to_top(closer)
warning.last?(closer) | [
"Allows",
"acts_as_list",
"methods",
"to",
"be",
"used",
"within",
"the",
"warning",
".",
"If",
"closers",
"were",
"the",
"act_as_list",
"object",
"you",
"could",
"do",
"things",
"like",
"this"
] | 725ec70e9cc718f07a72bb8dd68ed2da4c8a6a13 | https://github.com/reggieb/ominous/blob/725ec70e9cc718f07a72bb8dd68ed2da4c8a6a13/app/models/ominous/warning.rb#L75-L79 | train |
26fe/tree.rb | lib/tree_rb/core/tree_node.rb | TreeRb.TreeNode.find | def find(content = nil, &block)
if content and block_given?
raise "TreeNode::find - passed content AND block"
end
if content
if content.class == Regexp
block = proc { |l| l.content =~ content }
else
block = proc { |l| l.content == content }
end
end
return self if block.call(self)
leaf = @leaves.find { |l| block.call(l) }
return leaf if leaf
@children.each do |child|
node = child.find &block
return node if node
end
nil
end | ruby | def find(content = nil, &block)
if content and block_given?
raise "TreeNode::find - passed content AND block"
end
if content
if content.class == Regexp
block = proc { |l| l.content =~ content }
else
block = proc { |l| l.content == content }
end
end
return self if block.call(self)
leaf = @leaves.find { |l| block.call(l) }
return leaf if leaf
@children.each do |child|
node = child.find &block
return node if node
end
nil
end | [
"def",
"find",
"(",
"content",
"=",
"nil",
",",
"&",
"block",
")",
"if",
"content",
"and",
"block_given?",
"raise",
"\"TreeNode::find - passed content AND block\"",
"end",
"if",
"content",
"if",
"content",
".",
"class",
"==",
"Regexp",
"block",
"=",
"proc",
"{",
"|",
"l",
"|",
"l",
".",
"content",
"=~",
"content",
"}",
"else",
"block",
"=",
"proc",
"{",
"|",
"l",
"|",
"l",
".",
"content",
"==",
"content",
"}",
"end",
"end",
"return",
"self",
"if",
"block",
".",
"call",
"(",
"self",
")",
"leaf",
"=",
"@leaves",
".",
"find",
"{",
"|",
"l",
"|",
"block",
".",
"call",
"(",
"l",
")",
"}",
"return",
"leaf",
"if",
"leaf",
"@children",
".",
"each",
"do",
"|",
"child",
"|",
"node",
"=",
"child",
".",
"find",
"&",
"block",
"return",
"node",
"if",
"node",
"end",
"nil",
"end"
] | Find a node down the hierarchy with content
@param [Object,Regexp] content of searched node
@return [Object, nil] nil if not found | [
"Find",
"a",
"node",
"down",
"the",
"hierarchy",
"with",
"content"
] | 5ecf0cfbbc439e27c72b9676d6a1ccee8e6bb02b | https://github.com/26fe/tree.rb/blob/5ecf0cfbbc439e27c72b9676d6a1ccee8e6bb02b/lib/tree_rb/core/tree_node.rb#L229-L251 | train |
kamui/rack-accept_headers | lib/rack/accept_headers/charset.rb | Rack::AcceptHeaders.Charset.matches | def matches(charset)
values.select {|v|
v == charset || v == '*'
}.sort {|a, b|
# "*" gets least precedence, any others should be equal.
a == '*' ? 1 : (b == '*' ? -1 : 0)
}
end | ruby | def matches(charset)
values.select {|v|
v == charset || v == '*'
}.sort {|a, b|
# "*" gets least precedence, any others should be equal.
a == '*' ? 1 : (b == '*' ? -1 : 0)
}
end | [
"def",
"matches",
"(",
"charset",
")",
"values",
".",
"select",
"{",
"|",
"v",
"|",
"v",
"==",
"charset",
"||",
"v",
"==",
"'*'",
"}",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"a",
"==",
"'*'",
"?",
"1",
":",
"(",
"b",
"==",
"'*'",
"?",
"-",
"1",
":",
"0",
")",
"}",
"end"
] | Returns an array of character sets from this header that match the given
+charset+, ordered by precedence. | [
"Returns",
"an",
"array",
"of",
"character",
"sets",
"from",
"this",
"header",
"that",
"match",
"the",
"given",
"+",
"charset",
"+",
"ordered",
"by",
"precedence",
"."
] | 099bfbb919de86b5842c8e14be42b8b784e53f03 | https://github.com/kamui/rack-accept_headers/blob/099bfbb919de86b5842c8e14be42b8b784e53f03/lib/rack/accept_headers/charset.rb#L27-L34 | train |
timwaters/nypl_repo | lib/nypl_repo.rb | NyplRepo.Client.get_capture_items | def get_capture_items(c_uuid)
url = "#{@server_url}/items/#{c_uuid}.json?per_page=500"
json = self.get_json(url)
captures = []
capture = json["nyplAPI"]["response"]["capture"]
captures << capture
totalPages = json["nyplAPI"]["request"]["totalPages"].to_i
if totalPages >= 2
puts "total pages " + totalPages.to_s if @debug
(2..totalPages).each do | page |
puts "page: "+page.to_s if @debug
newurl = url + "&page=#{page}"
json = self.get_json(newurl)
newcapture = json["nyplAPI"]["response"]["capture"]
captures << newcapture
end
end
captures.flatten!
captures
end | ruby | def get_capture_items(c_uuid)
url = "#{@server_url}/items/#{c_uuid}.json?per_page=500"
json = self.get_json(url)
captures = []
capture = json["nyplAPI"]["response"]["capture"]
captures << capture
totalPages = json["nyplAPI"]["request"]["totalPages"].to_i
if totalPages >= 2
puts "total pages " + totalPages.to_s if @debug
(2..totalPages).each do | page |
puts "page: "+page.to_s if @debug
newurl = url + "&page=#{page}"
json = self.get_json(newurl)
newcapture = json["nyplAPI"]["response"]["capture"]
captures << newcapture
end
end
captures.flatten!
captures
end | [
"def",
"get_capture_items",
"(",
"c_uuid",
")",
"url",
"=",
"\"#{@server_url}/items/#{c_uuid}.json?per_page=500\"",
"json",
"=",
"self",
".",
"get_json",
"(",
"url",
")",
"captures",
"=",
"[",
"]",
"capture",
"=",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"capture\"",
"]",
"captures",
"<<",
"capture",
"totalPages",
"=",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"request\"",
"]",
"[",
"\"totalPages\"",
"]",
".",
"to_i",
"if",
"totalPages",
">=",
"2",
"puts",
"\"total pages \"",
"+",
"totalPages",
".",
"to_s",
"if",
"@debug",
"(",
"2",
"..",
"totalPages",
")",
".",
"each",
"do",
"|",
"page",
"|",
"puts",
"\"page: \"",
"+",
"page",
".",
"to_s",
"if",
"@debug",
"newurl",
"=",
"url",
"+",
"\"&page=#{page}\"",
"json",
"=",
"self",
".",
"get_json",
"(",
"newurl",
")",
"newcapture",
"=",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"capture\"",
"]",
"captures",
"<<",
"newcapture",
"end",
"end",
"captures",
".",
"flatten!",
"captures",
"end"
] | Given a container uuid, or biblographic uuid, returns a
list of mods uuids. | [
"Given",
"a",
"container",
"uuid",
"or",
"biblographic",
"uuid",
"returns",
"a",
"list",
"of",
"mods",
"uuids",
"."
] | 213180a6dbeb1608aed0e615f239ee7e7551539c | https://github.com/timwaters/nypl_repo/blob/213180a6dbeb1608aed0e615f239ee7e7551539c/lib/nypl_repo.rb#L44-L65 | train |
timwaters/nypl_repo | lib/nypl_repo.rb | NyplRepo.Client.get_mods_item | def get_mods_item(mods_uuid)
url = "#{@server_url}/items/mods/#{mods_uuid}.json"
json = self.get_json(url)
item = nil
if json["nyplAPI"]["response"]["mods"]
item = json["nyplAPI"]["response"]["mods"]
end
return item
end | ruby | def get_mods_item(mods_uuid)
url = "#{@server_url}/items/mods/#{mods_uuid}.json"
json = self.get_json(url)
item = nil
if json["nyplAPI"]["response"]["mods"]
item = json["nyplAPI"]["response"]["mods"]
end
return item
end | [
"def",
"get_mods_item",
"(",
"mods_uuid",
")",
"url",
"=",
"\"#{@server_url}/items/mods/#{mods_uuid}.json\"",
"json",
"=",
"self",
".",
"get_json",
"(",
"url",
")",
"item",
"=",
"nil",
"if",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"mods\"",
"]",
"item",
"=",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"mods\"",
"]",
"end",
"return",
"item",
"end"
] | get the item detail from a uuid | [
"get",
"the",
"item",
"detail",
"from",
"a",
"uuid"
] | 213180a6dbeb1608aed0e615f239ee7e7551539c | https://github.com/timwaters/nypl_repo/blob/213180a6dbeb1608aed0e615f239ee7e7551539c/lib/nypl_repo.rb#L68-L78 | train |
timwaters/nypl_repo | lib/nypl_repo.rb | NyplRepo.Client.get_bibl_uuid | def get_bibl_uuid(image_id)
url = "#{@server_url}/items/local_image_id/#{image_id}.json"
json = self.get_json(url)
bibl_uuid = nil
if json["nyplAPI"]["response"]["numResults"].to_i > 0
bibl_uuid = json["nyplAPI"]["response"]["uuid"]
end
return bibl_uuid
end | ruby | def get_bibl_uuid(image_id)
url = "#{@server_url}/items/local_image_id/#{image_id}.json"
json = self.get_json(url)
bibl_uuid = nil
if json["nyplAPI"]["response"]["numResults"].to_i > 0
bibl_uuid = json["nyplAPI"]["response"]["uuid"]
end
return bibl_uuid
end | [
"def",
"get_bibl_uuid",
"(",
"image_id",
")",
"url",
"=",
"\"#{@server_url}/items/local_image_id/#{image_id}.json\"",
"json",
"=",
"self",
".",
"get_json",
"(",
"url",
")",
"bibl_uuid",
"=",
"nil",
"if",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"numResults\"",
"]",
".",
"to_i",
">",
"0",
"bibl_uuid",
"=",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"uuid\"",
"]",
"end",
"return",
"bibl_uuid",
"end"
] | get bibliographic container uuid from an image_id | [
"get",
"bibliographic",
"container",
"uuid",
"from",
"an",
"image_id"
] | 213180a6dbeb1608aed0e615f239ee7e7551539c | https://github.com/timwaters/nypl_repo/blob/213180a6dbeb1608aed0e615f239ee7e7551539c/lib/nypl_repo.rb#L117-L126 | train |
timwaters/nypl_repo | lib/nypl_repo.rb | NyplRepo.Client.get_highreslink | def get_highreslink(bibl_uuid, image_id)
url = "#{@server_url}/items/#{bibl_uuid}.json?per_page=500"
json = self.get_json(url)
highreslink = nil
json["nyplAPI"]["response"]["capture"].each do | capture|
if capture["imageID"] == image_id
highreslink = capture["highResLink"]
break
end #if
end if json["nyplAPI"]["response"]["numResults"].to_i > 0
return highreslink
end | ruby | def get_highreslink(bibl_uuid, image_id)
url = "#{@server_url}/items/#{bibl_uuid}.json?per_page=500"
json = self.get_json(url)
highreslink = nil
json["nyplAPI"]["response"]["capture"].each do | capture|
if capture["imageID"] == image_id
highreslink = capture["highResLink"]
break
end #if
end if json["nyplAPI"]["response"]["numResults"].to_i > 0
return highreslink
end | [
"def",
"get_highreslink",
"(",
"bibl_uuid",
",",
"image_id",
")",
"url",
"=",
"\"#{@server_url}/items/#{bibl_uuid}.json?per_page=500\"",
"json",
"=",
"self",
".",
"get_json",
"(",
"url",
")",
"highreslink",
"=",
"nil",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"capture\"",
"]",
".",
"each",
"do",
"|",
"capture",
"|",
"if",
"capture",
"[",
"\"imageID\"",
"]",
"==",
"image_id",
"highreslink",
"=",
"capture",
"[",
"\"highResLink\"",
"]",
"break",
"end",
"end",
"if",
"json",
"[",
"\"nyplAPI\"",
"]",
"[",
"\"response\"",
"]",
"[",
"\"numResults\"",
"]",
".",
"to_i",
">",
"0",
"return",
"highreslink",
"end"
] | get highreslink from an item, matching up the image idi
since some bibliographic items may have many maps under them | [
"get",
"highreslink",
"from",
"an",
"item",
"matching",
"up",
"the",
"image",
"idi",
"since",
"some",
"bibliographic",
"items",
"may",
"have",
"many",
"maps",
"under",
"them"
] | 213180a6dbeb1608aed0e615f239ee7e7551539c | https://github.com/timwaters/nypl_repo/blob/213180a6dbeb1608aed0e615f239ee7e7551539c/lib/nypl_repo.rb#L131-L145 | train |
cordawyn/kalimba | lib/kalimba/attribute_assignment.rb | Kalimba.AttributeAssignment.assign_attributes | def assign_attributes(new_attributes = {}, options = {})
return if new_attributes.blank?
attributes = new_attributes.stringify_keys
multi_parameter_attributes = []
nested_parameter_attributes = []
attributes.each do |k, v|
if k.include?("(")
multi_parameter_attributes << [ k, v ]
elsif respond_to?("#{k}=")
if v.is_a?(Hash)
nested_parameter_attributes << [ k, v ]
else
send("#{k}=", v)
end
else
raise UnknownAttributeError, "unknown attribute: #{k}"
end
end
# assign any deferred nested attributes after the base attributes have been set
nested_parameter_attributes.each do |k,v|
send("#{k}=", v)
end
assign_multiparameter_attributes(multi_parameter_attributes)
end | ruby | def assign_attributes(new_attributes = {}, options = {})
return if new_attributes.blank?
attributes = new_attributes.stringify_keys
multi_parameter_attributes = []
nested_parameter_attributes = []
attributes.each do |k, v|
if k.include?("(")
multi_parameter_attributes << [ k, v ]
elsif respond_to?("#{k}=")
if v.is_a?(Hash)
nested_parameter_attributes << [ k, v ]
else
send("#{k}=", v)
end
else
raise UnknownAttributeError, "unknown attribute: #{k}"
end
end
# assign any deferred nested attributes after the base attributes have been set
nested_parameter_attributes.each do |k,v|
send("#{k}=", v)
end
assign_multiparameter_attributes(multi_parameter_attributes)
end | [
"def",
"assign_attributes",
"(",
"new_attributes",
"=",
"{",
"}",
",",
"options",
"=",
"{",
"}",
")",
"return",
"if",
"new_attributes",
".",
"blank?",
"attributes",
"=",
"new_attributes",
".",
"stringify_keys",
"multi_parameter_attributes",
"=",
"[",
"]",
"nested_parameter_attributes",
"=",
"[",
"]",
"attributes",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"if",
"k",
".",
"include?",
"(",
"\"(\"",
")",
"multi_parameter_attributes",
"<<",
"[",
"k",
",",
"v",
"]",
"elsif",
"respond_to?",
"(",
"\"#{k}=\"",
")",
"if",
"v",
".",
"is_a?",
"(",
"Hash",
")",
"nested_parameter_attributes",
"<<",
"[",
"k",
",",
"v",
"]",
"else",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"else",
"raise",
"UnknownAttributeError",
",",
"\"unknown attribute: #{k}\"",
"end",
"end",
"nested_parameter_attributes",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"assign_multiparameter_attributes",
"(",
"multi_parameter_attributes",
")",
"end"
] | Assign attributes from the given hash
@param [Hash<[Symbol, String] => Any>] new_attributes
@param [Hash] options
@return [void] | [
"Assign",
"attributes",
"from",
"the",
"given",
"hash"
] | c1b29948744a66cadb643213785a9cdd4c07be83 | https://github.com/cordawyn/kalimba/blob/c1b29948744a66cadb643213785a9cdd4c07be83/lib/kalimba/attribute_assignment.rb#L8-L35 | train |
forecastxl/twinfield-ruby | lib/twinfield/customer.rb | Twinfield.Customer.find_by_code | def find_by_code(code)
Twinfield::Process.new(@session).
request(:process_xml_document, get_dimension_xml(@company, 'DEB', { code: code })).
body[:process_xml_document_response][:process_xml_document_result][:dimension]
end | ruby | def find_by_code(code)
Twinfield::Process.new(@session).
request(:process_xml_document, get_dimension_xml(@company, 'DEB', { code: code })).
body[:process_xml_document_response][:process_xml_document_result][:dimension]
end | [
"def",
"find_by_code",
"(",
"code",
")",
"Twinfield",
"::",
"Process",
".",
"new",
"(",
"@session",
")",
".",
"request",
"(",
":process_xml_document",
",",
"get_dimension_xml",
"(",
"@company",
",",
"'DEB'",
",",
"{",
"code",
":",
"code",
"}",
")",
")",
".",
"body",
"[",
":process_xml_document_response",
"]",
"[",
":process_xml_document_result",
"]",
"[",
":dimension",
"]",
"end"
] | Find customer by twinfield customer code | [
"Find",
"customer",
"by",
"twinfield",
"customer",
"code"
] | 90591ba1f11875c0f5b73c02a5ef5a88fef3ee45 | https://github.com/forecastxl/twinfield-ruby/blob/90591ba1f11875c0f5b73c02a5ef5a88fef3ee45/lib/twinfield/customer.rb#L19-L23 | train |
forecastxl/twinfield-ruby | lib/twinfield/customer.rb | Twinfield.Customer.find_by_name | def find_by_name(name)
Twinfield::Finder.new(@session).
search(Twinfield::FinderSearch.new('DIM', name, 0, 1, 0, { office: @company, dimtype: 'DEB'} )).
body[:search_response][:data]
end | ruby | def find_by_name(name)
Twinfield::Finder.new(@session).
search(Twinfield::FinderSearch.new('DIM', name, 0, 1, 0, { office: @company, dimtype: 'DEB'} )).
body[:search_response][:data]
end | [
"def",
"find_by_name",
"(",
"name",
")",
"Twinfield",
"::",
"Finder",
".",
"new",
"(",
"@session",
")",
".",
"search",
"(",
"Twinfield",
"::",
"FinderSearch",
".",
"new",
"(",
"'DIM'",
",",
"name",
",",
"0",
",",
"1",
",",
"0",
",",
"{",
"office",
":",
"@company",
",",
"dimtype",
":",
"'DEB'",
"}",
")",
")",
".",
"body",
"[",
":search_response",
"]",
"[",
":data",
"]",
"end"
] | Find customer by name | [
"Find",
"customer",
"by",
"name"
] | 90591ba1f11875c0f5b73c02a5ef5a88fef3ee45 | https://github.com/forecastxl/twinfield-ruby/blob/90591ba1f11875c0f5b73c02a5ef5a88fef3ee45/lib/twinfield/customer.rb#L26-L30 | train |
forecastxl/twinfield-ruby | lib/twinfield/customer.rb | Twinfield.Customer.get_dimension_xml | def get_dimension_xml(office, dimtype, opts = {})
xml = Builder::XmlMarkup.new
xml = xml.read do
xml.type('dimensions')
xml.office(office)
xml.dimtype(dimtype)
xml.code(opts.fetch(:code){})
end
end | ruby | def get_dimension_xml(office, dimtype, opts = {})
xml = Builder::XmlMarkup.new
xml = xml.read do
xml.type('dimensions')
xml.office(office)
xml.dimtype(dimtype)
xml.code(opts.fetch(:code){})
end
end | [
"def",
"get_dimension_xml",
"(",
"office",
",",
"dimtype",
",",
"opts",
"=",
"{",
"}",
")",
"xml",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"xml",
"=",
"xml",
".",
"read",
"do",
"xml",
".",
"type",
"(",
"'dimensions'",
")",
"xml",
".",
"office",
"(",
"office",
")",
"xml",
".",
"dimtype",
"(",
"dimtype",
")",
"xml",
".",
"code",
"(",
"opts",
".",
"fetch",
"(",
":code",
")",
"{",
"}",
")",
"end",
"end"
] | The request for getting all elements in a Twinfield dimension | [
"The",
"request",
"for",
"getting",
"all",
"elements",
"in",
"a",
"Twinfield",
"dimension"
] | 90591ba1f11875c0f5b73c02a5ef5a88fef3ee45 | https://github.com/forecastxl/twinfield-ruby/blob/90591ba1f11875c0f5b73c02a5ef5a88fef3ee45/lib/twinfield/customer.rb#L40-L49 | train |
mirego/emotions | lib/emotions/emotional.rb | Emotions.Emotional.express! | def express!(emotion, emotive)
emotion = _emotions_about(emotive).where(emotion: emotion).first_or_initialize
begin
emotion.tap(&:save!)
rescue ActiveRecord::RecordInvalid => e
raise InvalidEmotion.new(e.record)
end
end | ruby | def express!(emotion, emotive)
emotion = _emotions_about(emotive).where(emotion: emotion).first_or_initialize
begin
emotion.tap(&:save!)
rescue ActiveRecord::RecordInvalid => e
raise InvalidEmotion.new(e.record)
end
end | [
"def",
"express!",
"(",
"emotion",
",",
"emotive",
")",
"emotion",
"=",
"_emotions_about",
"(",
"emotive",
")",
".",
"where",
"(",
"emotion",
":",
"emotion",
")",
".",
"first_or_initialize",
"begin",
"emotion",
".",
"tap",
"(",
"&",
":save!",
")",
"rescue",
"ActiveRecord",
"::",
"RecordInvalid",
"=>",
"e",
"raise",
"InvalidEmotion",
".",
"new",
"(",
"e",
".",
"record",
")",
"end",
"end"
] | Express an emotion towards another record
@example
user = User.first
picture = Picture.first
user.express! :happy, picture | [
"Express",
"an",
"emotion",
"towards",
"another",
"record"
] | f0adc687dbdac906d9fcebfb0f3bf6afb6fa5d56 | https://github.com/mirego/emotions/blob/f0adc687dbdac906d9fcebfb0f3bf6afb6fa5d56/lib/emotions/emotional.rb#L37-L45 | train |
mirego/emotions | lib/emotions/emotional.rb | Emotions.Emotional.no_longer_express! | def no_longer_express!(emotion, emotive)
_emotions_about(emotive).where(emotion: emotion).first.tap { |e| e.try(:destroy) }
end | ruby | def no_longer_express!(emotion, emotive)
_emotions_about(emotive).where(emotion: emotion).first.tap { |e| e.try(:destroy) }
end | [
"def",
"no_longer_express!",
"(",
"emotion",
",",
"emotive",
")",
"_emotions_about",
"(",
"emotive",
")",
".",
"where",
"(",
"emotion",
":",
"emotion",
")",
".",
"first",
".",
"tap",
"{",
"|",
"e",
"|",
"e",
".",
"try",
"(",
":destroy",
")",
"}",
"end"
] | No longer express an emotion towards another record
@example
user = User.first
picture = Picture.first
user.no_longer_express! :happy, picture | [
"No",
"longer",
"express",
"an",
"emotion",
"towards",
"another",
"record"
] | f0adc687dbdac906d9fcebfb0f3bf6afb6fa5d56 | https://github.com/mirego/emotions/blob/f0adc687dbdac906d9fcebfb0f3bf6afb6fa5d56/lib/emotions/emotional.rb#L53-L55 | train |
26fe/tree.rb | lib/tree_rb/output_plugins/dircat/dircat_visitor.rb | TreeRb.DirCatVisitor.add_entry | def add_entry(e)
@entries.push(e)
if @md5_to_entries.has_key?(e.md5)
@md5_to_entries[e.md5].push(e)
else
@md5_to_entries[e.md5] = [e]
end
end | ruby | def add_entry(e)
@entries.push(e)
if @md5_to_entries.has_key?(e.md5)
@md5_to_entries[e.md5].push(e)
else
@md5_to_entries[e.md5] = [e]
end
end | [
"def",
"add_entry",
"(",
"e",
")",
"@entries",
".",
"push",
"(",
"e",
")",
"if",
"@md5_to_entries",
".",
"has_key?",
"(",
"e",
".",
"md5",
")",
"@md5_to_entries",
"[",
"e",
".",
"md5",
"]",
".",
"push",
"(",
"e",
")",
"else",
"@md5_to_entries",
"[",
"e",
".",
"md5",
"]",
"=",
"[",
"e",
"]",
"end",
"end"
] | add entry to this catalog
@private | [
"add",
"entry",
"to",
"this",
"catalog"
] | 5ecf0cfbbc439e27c72b9676d6a1ccee8e6bb02b | https://github.com/26fe/tree.rb/blob/5ecf0cfbbc439e27c72b9676d6a1ccee8e6bb02b/lib/tree_rb/output_plugins/dircat/dircat_visitor.rb#L35-L42 | train |
holman/stars | lib/stars/services/favstar.rb | Stars.Favstar.parse_title | def parse_title(title)
strip = title.split(':').first
title = title.gsub(strip,'')
title = title[2..-1] if title[0..1] == ": "
title
end | ruby | def parse_title(title)
strip = title.split(':').first
title = title.gsub(strip,'')
title = title[2..-1] if title[0..1] == ": "
title
end | [
"def",
"parse_title",
"(",
"title",
")",
"strip",
"=",
"title",
".",
"split",
"(",
"':'",
")",
".",
"first",
"title",
"=",
"title",
".",
"gsub",
"(",
"strip",
",",
"''",
")",
"title",
"=",
"title",
"[",
"2",
"..",
"-",
"1",
"]",
"if",
"title",
"[",
"0",
"..",
"1",
"]",
"==",
"\": \"",
"title",
"end"
] | Parse the title from a Favstar RSS title.
title - a Favstar-formatted String (x stars: title here)
This splits on the first colon, and then use everything after that. To
account for tweets with colons in them, we have to strip the first ": "
String we find, and then shift the String back two characters. | [
"Parse",
"the",
"title",
"from",
"a",
"Favstar",
"RSS",
"title",
"."
] | 4c12a7d2fa935fe746d263aad5208ed0630c0b1e | https://github.com/holman/stars/blob/4c12a7d2fa935fe746d263aad5208ed0630c0b1e/lib/stars/services/favstar.rb#L50-L55 | train |
jemmyw/bisques | lib/bisques/client.rb | Bisques.Client.create_queue | def create_queue(name, attributes = {})
response = action("CreateQueue", {"QueueName" => Queue.sanitize_name("#{queue_prefix}#{name}")}.merge(attributes))
if response.success?
Queue.new(self, response.doc.xpath("//QueueUrl").text)
else
raise "Could not create queue #{name}"
end
rescue AwsActionError => error
if error.code == "AWS.SimpleQueueService.QueueDeletedRecently"
raise QueueDeletedRecentlyError, error.message
else
raise error
end
end | ruby | def create_queue(name, attributes = {})
response = action("CreateQueue", {"QueueName" => Queue.sanitize_name("#{queue_prefix}#{name}")}.merge(attributes))
if response.success?
Queue.new(self, response.doc.xpath("//QueueUrl").text)
else
raise "Could not create queue #{name}"
end
rescue AwsActionError => error
if error.code == "AWS.SimpleQueueService.QueueDeletedRecently"
raise QueueDeletedRecentlyError, error.message
else
raise error
end
end | [
"def",
"create_queue",
"(",
"name",
",",
"attributes",
"=",
"{",
"}",
")",
"response",
"=",
"action",
"(",
"\"CreateQueue\"",
",",
"{",
"\"QueueName\"",
"=>",
"Queue",
".",
"sanitize_name",
"(",
"\"#{queue_prefix}#{name}\"",
")",
"}",
".",
"merge",
"(",
"attributes",
")",
")",
"if",
"response",
".",
"success?",
"Queue",
".",
"new",
"(",
"self",
",",
"response",
".",
"doc",
".",
"xpath",
"(",
"\"//QueueUrl\"",
")",
".",
"text",
")",
"else",
"raise",
"\"Could not create queue #{name}\"",
"end",
"rescue",
"AwsActionError",
"=>",
"error",
"if",
"error",
".",
"code",
"==",
"\"AWS.SimpleQueueService.QueueDeletedRecently\"",
"raise",
"QueueDeletedRecentlyError",
",",
"error",
".",
"message",
"else",
"raise",
"error",
"end",
"end"
] | Creates a new SQS queue and returns a Queue object.
@param [String] name
@param [Hash] attributes
@return [Queue]
@raise [AwsActionError] | [
"Creates",
"a",
"new",
"SQS",
"queue",
"and",
"returns",
"a",
"Queue",
"object",
"."
] | c48ab555f07664752bcbf9e8deb99bd75cbdc41b | https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/client.rb#L52-L67 | train |
jemmyw/bisques | lib/bisques/client.rb | Bisques.Client.get_queue | def get_queue(name, options = {})
response = action("GetQueueUrl", {"QueueName" => Queue.sanitize_name("#{queue_prefix}#{name}")}.merge(options))
if response.success?
Queue.new(self, response.doc.xpath("//QueueUrl").text)
end
rescue Bisques::AwsActionError => e
raise unless e.code == "AWS.SimpleQueueService.NonExistentQueue"
end | ruby | def get_queue(name, options = {})
response = action("GetQueueUrl", {"QueueName" => Queue.sanitize_name("#{queue_prefix}#{name}")}.merge(options))
if response.success?
Queue.new(self, response.doc.xpath("//QueueUrl").text)
end
rescue Bisques::AwsActionError => e
raise unless e.code == "AWS.SimpleQueueService.NonExistentQueue"
end | [
"def",
"get_queue",
"(",
"name",
",",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"action",
"(",
"\"GetQueueUrl\"",
",",
"{",
"\"QueueName\"",
"=>",
"Queue",
".",
"sanitize_name",
"(",
"\"#{queue_prefix}#{name}\"",
")",
"}",
".",
"merge",
"(",
"options",
")",
")",
"if",
"response",
".",
"success?",
"Queue",
".",
"new",
"(",
"self",
",",
"response",
".",
"doc",
".",
"xpath",
"(",
"\"//QueueUrl\"",
")",
".",
"text",
")",
"end",
"rescue",
"Bisques",
"::",
"AwsActionError",
"=>",
"e",
"raise",
"unless",
"e",
".",
"code",
"==",
"\"AWS.SimpleQueueService.NonExistentQueue\"",
"end"
] | Get an SQS queue by name.
@param [String] name
@param [Hash] options
@return [Queue,nil] Returns a Queue object if the queue is found, otherwise nil.
@raise [AwsActionError] | [
"Get",
"an",
"SQS",
"queue",
"by",
"name",
"."
] | c48ab555f07664752bcbf9e8deb99bd75cbdc41b | https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/client.rb#L82-L91 | train |
jemmyw/bisques | lib/bisques/client.rb | Bisques.Client.list_queues | def list_queues(prefix = "")
response = action("ListQueues", "QueueNamePrefix" => "#{queue_prefix}#{prefix}")
response.doc.xpath("//ListQueuesResult/QueueUrl").map(&:text).map do |url|
Queue.new(self, url)
end
end | ruby | def list_queues(prefix = "")
response = action("ListQueues", "QueueNamePrefix" => "#{queue_prefix}#{prefix}")
response.doc.xpath("//ListQueuesResult/QueueUrl").map(&:text).map do |url|
Queue.new(self, url)
end
end | [
"def",
"list_queues",
"(",
"prefix",
"=",
"\"\"",
")",
"response",
"=",
"action",
"(",
"\"ListQueues\"",
",",
"\"QueueNamePrefix\"",
"=>",
"\"#{queue_prefix}#{prefix}\"",
")",
"response",
".",
"doc",
".",
"xpath",
"(",
"\"//ListQueuesResult/QueueUrl\"",
")",
".",
"map",
"(",
"&",
":text",
")",
".",
"map",
"do",
"|",
"url",
"|",
"Queue",
".",
"new",
"(",
"self",
",",
"url",
")",
"end",
"end"
] | Return an array of Queue objects representing the queues found in SQS. An
optional prefix can be supplied to restrict the queues found. This prefix
is additional to the client prefix.
@param [String] prefix option prefix to restrict the queues found.
@return [Array<Queue>] queue objects found.
@raise [AwsActionError]
@example Delete all the queues
client.list_queues.each do |queue|
queue.delete
end | [
"Return",
"an",
"array",
"of",
"Queue",
"objects",
"representing",
"the",
"queues",
"found",
"in",
"SQS",
".",
"An",
"optional",
"prefix",
"can",
"be",
"supplied",
"to",
"restrict",
"the",
"queues",
"found",
".",
"This",
"prefix",
"is",
"additional",
"to",
"the",
"client",
"prefix",
"."
] | c48ab555f07664752bcbf9e8deb99bd75cbdc41b | https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/client.rb#L107-L112 | train |
jemmyw/bisques | lib/bisques/client.rb | Bisques.Client.send_message | def send_message(queue_url, message_body, delay_seconds=nil)
options = {"MessageBody" => message_body}
options["DelaySeconds"] = delay_seconds if delay_seconds
tries = 0
md5 = Digest::MD5.hexdigest(message_body)
begin
tries += 1
response = action("SendMessage", queue_url, options)
returned_md5 = response.doc.xpath("//MD5OfMessageBody").text
raise MessageHasWrongMd5Error.new(message_body, md5, returned_md5) unless md5 == returned_md5
rescue MessageHasWrongMd5Error
if tries < 2
retry
else
raise
end
end
end | ruby | def send_message(queue_url, message_body, delay_seconds=nil)
options = {"MessageBody" => message_body}
options["DelaySeconds"] = delay_seconds if delay_seconds
tries = 0
md5 = Digest::MD5.hexdigest(message_body)
begin
tries += 1
response = action("SendMessage", queue_url, options)
returned_md5 = response.doc.xpath("//MD5OfMessageBody").text
raise MessageHasWrongMd5Error.new(message_body, md5, returned_md5) unless md5 == returned_md5
rescue MessageHasWrongMd5Error
if tries < 2
retry
else
raise
end
end
end | [
"def",
"send_message",
"(",
"queue_url",
",",
"message_body",
",",
"delay_seconds",
"=",
"nil",
")",
"options",
"=",
"{",
"\"MessageBody\"",
"=>",
"message_body",
"}",
"options",
"[",
"\"DelaySeconds\"",
"]",
"=",
"delay_seconds",
"if",
"delay_seconds",
"tries",
"=",
"0",
"md5",
"=",
"Digest",
"::",
"MD5",
".",
"hexdigest",
"(",
"message_body",
")",
"begin",
"tries",
"+=",
"1",
"response",
"=",
"action",
"(",
"\"SendMessage\"",
",",
"queue_url",
",",
"options",
")",
"returned_md5",
"=",
"response",
".",
"doc",
".",
"xpath",
"(",
"\"//MD5OfMessageBody\"",
")",
".",
"text",
"raise",
"MessageHasWrongMd5Error",
".",
"new",
"(",
"message_body",
",",
"md5",
",",
"returned_md5",
")",
"unless",
"md5",
"==",
"returned_md5",
"rescue",
"MessageHasWrongMd5Error",
"if",
"tries",
"<",
"2",
"retry",
"else",
"raise",
"end",
"end",
"end"
] | Put a message on a queue. Takes the queue url and the message body, which
should be a string. An optional delay seconds argument can be added if
the message should not become visible immediately.
@param [String] queue_url
@param [String] message_body
@param [Fixnum] delay_seconds
@return nil
@raise [MessageHasWrongMd5Error]
@raise [AwsActionError]
@example
client.send_message(queue.path, "test message") | [
"Put",
"a",
"message",
"on",
"a",
"queue",
".",
"Takes",
"the",
"queue",
"url",
"and",
"the",
"message",
"body",
"which",
"should",
"be",
"a",
"string",
".",
"An",
"optional",
"delay",
"seconds",
"argument",
"can",
"be",
"added",
"if",
"the",
"message",
"should",
"not",
"become",
"visible",
"immediately",
"."
] | c48ab555f07664752bcbf9e8deb99bd75cbdc41b | https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/client.rb#L146-L166 | train |
ntalbott/mupnp | lib/UPnP.rb | UPnP.UPnP.externalIP | def externalIP()
joinThread()
external_ip = getCString()
r = MiniUPnP.UPNP_GetExternalIPAddress(@urls.controlURL,
@data.servicetype,external_ip)
if r != 0 then
raise UPnPException.new, "Error while retriving the external ip address. #{code2error(r)}."
end
return external_ip.rstrip()
end | ruby | def externalIP()
joinThread()
external_ip = getCString()
r = MiniUPnP.UPNP_GetExternalIPAddress(@urls.controlURL,
@data.servicetype,external_ip)
if r != 0 then
raise UPnPException.new, "Error while retriving the external ip address. #{code2error(r)}."
end
return external_ip.rstrip()
end | [
"def",
"externalIP",
"(",
")",
"joinThread",
"(",
")",
"external_ip",
"=",
"getCString",
"(",
")",
"r",
"=",
"MiniUPnP",
".",
"UPNP_GetExternalIPAddress",
"(",
"@urls",
".",
"controlURL",
",",
"@data",
".",
"servicetype",
",",
"external_ip",
")",
"if",
"r",
"!=",
"0",
"then",
"raise",
"UPnPException",
".",
"new",
",",
"\"Error while retriving the external ip address. #{code2error(r)}.\"",
"end",
"return",
"external_ip",
".",
"rstrip",
"(",
")",
"end"
] | Returns the external network ip | [
"Returns",
"the",
"external",
"network",
"ip"
] | c3c566cd2d7c9ecf1cb2baff253d116be163384d | https://github.com/ntalbott/mupnp/blob/c3c566cd2d7c9ecf1cb2baff253d116be163384d/lib/UPnP.rb#L154-L163 | train |
ntalbott/mupnp | lib/UPnP.rb | UPnP.UPnP.status | def status()
joinThread()
lastconnerror = getCString()
status = getCString()
uptime = 0
begin
uptime_uint = MiniUPnP.new_uintp()
r = MiniUPnP.UPNP_GetStatusInfo(@urls.controlURL,
@data.servicetype, status, uptime_uint,
lastconnerror)
if r != 0 then
raise UPnPException.new, "Error while retriving status info. #{code2error(r)}."
end
uptime = MiniUPnP.uintp_value(uptime_uint)
rescue
raise
ensure
MiniUPnP.delete_uintp(uptime_uint)
end
return status.rstrip,lastconnerror.rstrip,uptime
end | ruby | def status()
joinThread()
lastconnerror = getCString()
status = getCString()
uptime = 0
begin
uptime_uint = MiniUPnP.new_uintp()
r = MiniUPnP.UPNP_GetStatusInfo(@urls.controlURL,
@data.servicetype, status, uptime_uint,
lastconnerror)
if r != 0 then
raise UPnPException.new, "Error while retriving status info. #{code2error(r)}."
end
uptime = MiniUPnP.uintp_value(uptime_uint)
rescue
raise
ensure
MiniUPnP.delete_uintp(uptime_uint)
end
return status.rstrip,lastconnerror.rstrip,uptime
end | [
"def",
"status",
"(",
")",
"joinThread",
"(",
")",
"lastconnerror",
"=",
"getCString",
"(",
")",
"status",
"=",
"getCString",
"(",
")",
"uptime",
"=",
"0",
"begin",
"uptime_uint",
"=",
"MiniUPnP",
".",
"new_uintp",
"(",
")",
"r",
"=",
"MiniUPnP",
".",
"UPNP_GetStatusInfo",
"(",
"@urls",
".",
"controlURL",
",",
"@data",
".",
"servicetype",
",",
"status",
",",
"uptime_uint",
",",
"lastconnerror",
")",
"if",
"r",
"!=",
"0",
"then",
"raise",
"UPnPException",
".",
"new",
",",
"\"Error while retriving status info. #{code2error(r)}.\"",
"end",
"uptime",
"=",
"MiniUPnP",
".",
"uintp_value",
"(",
"uptime_uint",
")",
"rescue",
"raise",
"ensure",
"MiniUPnP",
".",
"delete_uintp",
"(",
"uptime_uint",
")",
"end",
"return",
"status",
".",
"rstrip",
",",
"lastconnerror",
".",
"rstrip",
",",
"uptime",
"end"
] | Returns the status of the router which is an array of 3 elements.
Connection status, Last error, Uptime. | [
"Returns",
"the",
"status",
"of",
"the",
"router",
"which",
"is",
"an",
"array",
"of",
"3",
"elements",
".",
"Connection",
"status",
"Last",
"error",
"Uptime",
"."
] | c3c566cd2d7c9ecf1cb2baff253d116be163384d | https://github.com/ntalbott/mupnp/blob/c3c566cd2d7c9ecf1cb2baff253d116be163384d/lib/UPnP.rb#L173-L193 | train |
ntalbott/mupnp | lib/UPnP.rb | UPnP.UPnP.connectionType | def connectionType()
joinThread()
type = getCString()
if MiniUPnP.UPNP_GetConnectionTypeInfo(@urls.controlURL,
@data.servicetype,type) != 0 then
raise UPnPException.new, "Error while retriving connection info."
end
type.rstrip
end | ruby | def connectionType()
joinThread()
type = getCString()
if MiniUPnP.UPNP_GetConnectionTypeInfo(@urls.controlURL,
@data.servicetype,type) != 0 then
raise UPnPException.new, "Error while retriving connection info."
end
type.rstrip
end | [
"def",
"connectionType",
"(",
")",
"joinThread",
"(",
")",
"type",
"=",
"getCString",
"(",
")",
"if",
"MiniUPnP",
".",
"UPNP_GetConnectionTypeInfo",
"(",
"@urls",
".",
"controlURL",
",",
"@data",
".",
"servicetype",
",",
"type",
")",
"!=",
"0",
"then",
"raise",
"UPnPException",
".",
"new",
",",
"\"Error while retriving connection info.\"",
"end",
"type",
".",
"rstrip",
"end"
] | Router connection information | [
"Router",
"connection",
"information"
] | c3c566cd2d7c9ecf1cb2baff253d116be163384d | https://github.com/ntalbott/mupnp/blob/c3c566cd2d7c9ecf1cb2baff253d116be163384d/lib/UPnP.rb#L196-L204 | train |
ntalbott/mupnp | lib/UPnP.rb | UPnP.UPnP.totalBytesSent | def totalBytesSent()
joinThread()
v = MiniUPnP.UPNP_GetTotalBytesSent(@urls.controlURL_CIF,
@data.servicetype_CIF)
if v < 0 then
raise UPnPException.new, "Error while retriving total bytes sent."
end
return v
end | ruby | def totalBytesSent()
joinThread()
v = MiniUPnP.UPNP_GetTotalBytesSent(@urls.controlURL_CIF,
@data.servicetype_CIF)
if v < 0 then
raise UPnPException.new, "Error while retriving total bytes sent."
end
return v
end | [
"def",
"totalBytesSent",
"(",
")",
"joinThread",
"(",
")",
"v",
"=",
"MiniUPnP",
".",
"UPNP_GetTotalBytesSent",
"(",
"@urls",
".",
"controlURL_CIF",
",",
"@data",
".",
"servicetype_CIF",
")",
"if",
"v",
"<",
"0",
"then",
"raise",
"UPnPException",
".",
"new",
",",
"\"Error while retriving total bytes sent.\"",
"end",
"return",
"v",
"end"
] | Total bytes sent from the router to external network | [
"Total",
"bytes",
"sent",
"from",
"the",
"router",
"to",
"external",
"network"
] | c3c566cd2d7c9ecf1cb2baff253d116be163384d | https://github.com/ntalbott/mupnp/blob/c3c566cd2d7c9ecf1cb2baff253d116be163384d/lib/UPnP.rb#L207-L215 | train |
ntalbott/mupnp | lib/UPnP.rb | UPnP.UPnP.totalBytesReceived | def totalBytesReceived()
joinThread()
v = MiniUPnP.UPNP_GetTotalBytesReceived(@urls.controlURL_CIF,
@data.servicetype_CIF)
if v < 0 then
raise UPnPException.new, "Error while retriving total bytes received."
end
return v
end | ruby | def totalBytesReceived()
joinThread()
v = MiniUPnP.UPNP_GetTotalBytesReceived(@urls.controlURL_CIF,
@data.servicetype_CIF)
if v < 0 then
raise UPnPException.new, "Error while retriving total bytes received."
end
return v
end | [
"def",
"totalBytesReceived",
"(",
")",
"joinThread",
"(",
")",
"v",
"=",
"MiniUPnP",
".",
"UPNP_GetTotalBytesReceived",
"(",
"@urls",
".",
"controlURL_CIF",
",",
"@data",
".",
"servicetype_CIF",
")",
"if",
"v",
"<",
"0",
"then",
"raise",
"UPnPException",
".",
"new",
",",
"\"Error while retriving total bytes received.\"",
"end",
"return",
"v",
"end"
] | Total bytes received from the external network. | [
"Total",
"bytes",
"received",
"from",
"the",
"external",
"network",
"."
] | c3c566cd2d7c9ecf1cb2baff253d116be163384d | https://github.com/ntalbott/mupnp/blob/c3c566cd2d7c9ecf1cb2baff253d116be163384d/lib/UPnP.rb#L218-L226 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.