id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,200 | blahah/biopsy | lib/biopsy/target.rb | Biopsy.Target.method_missing | def method_missing(method, *args, &block)
const_methods = @constructor.class.instance_methods(false)
if const_methods.include? method
return @constructor.send(method, *args, &block)
else
super
end
end | ruby | def method_missing(method, *args, &block)
const_methods = @constructor.class.instance_methods(false)
if const_methods.include? method
return @constructor.send(method, *args, &block)
else
super
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"const_methods",
"=",
"@constructor",
".",
"class",
".",
"instance_methods",
"(",
"false",
")",
"if",
"const_methods",
".",
"include?",
"method",
"return",
"@constructor",
".",
"send",
"(",
"method",
",",
"args",
",",
"block",
")",
"else",
"super",
"end",
"end"
] | pass calls to missing methods to the constructor iff
the constructor's class directly defines that method | [
"pass",
"calls",
"to",
"missing",
"methods",
"to",
"the",
"constructor",
"iff",
"the",
"constructor",
"s",
"class",
"directly",
"defines",
"that",
"method"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/target.rb#L147-L154 |
5,201 | blahah/biopsy | lib/biopsy/target.rb | Biopsy.Target.respond_to? | def respond_to?(method, *args, &block)
const_methods = @constructor.class.instance_methods(false)
if const_methods.include? method
true
else
super
end
end | ruby | def respond_to?(method, *args, &block)
const_methods = @constructor.class.instance_methods(false)
if const_methods.include? method
true
else
super
end
end | [
"def",
"respond_to?",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"const_methods",
"=",
"@constructor",
".",
"class",
".",
"instance_methods",
"(",
"false",
")",
"if",
"const_methods",
".",
"include?",
"method",
"true",
"else",
"super",
"end",
"end"
] | accurately report ability to respond to methods passed
to constructor | [
"accurately",
"report",
"ability",
"to",
"respond",
"to",
"methods",
"passed",
"to",
"constructor"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/target.rb#L158-L165 |
5,202 | brianmichel/BadFruit | lib/badfruit/base.rb | BadFruit.Base.get_movie_info | def get_movie_info(movie_id, action)
url = nil
case action
when "details"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}"
when "reviews"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}"
when "cast"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_key}"
when "main"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}"
else
puts "Not a valid action"
return
end
return get(url)
end | ruby | def get_movie_info(movie_id, action)
url = nil
case action
when "details"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}"
when "reviews"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}"
when "cast"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_key}"
when "main"
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}"
else
puts "Not a valid action"
return
end
return get(url)
end | [
"def",
"get_movie_info",
"(",
"movie_id",
",",
"action",
")",
"url",
"=",
"nil",
"case",
"action",
"when",
"\"details\"",
"url",
"=",
"\"#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}\"",
"when",
"\"reviews\"",
"url",
"=",
"\"#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}\"",
"when",
"\"cast\"",
"url",
"=",
"\"#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_key}\"",
"when",
"\"main\"",
"url",
"=",
"\"#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}\"",
"else",
"puts",
"\"Not a valid action\"",
"return",
"end",
"return",
"get",
"(",
"url",
")",
"end"
] | Get various bits of info for a given movie id.
@param [String] movie_id The id of the movie to get information for.
@param [String] action The type of information to request.
@note Valid action values are "details", "reviews", "cast", "main"
@return [Hash] A hash of information for a specific movie id. | [
"Get",
"various",
"bits",
"of",
"info",
"for",
"a",
"given",
"movie",
"id",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/base.rb#L83-L99 |
5,203 | brianmichel/BadFruit | lib/badfruit/base.rb | BadFruit.Base.get_lists_action | def get_lists_action(action)
url = nil
case action
when "new_releases"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}"
when "opening"
url = "#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}"
when "upcoming"
url = "#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_key}"
when "in_theaters"
url = "#{LISTS_DETAIL_BASE_URL}/movies/in_theaters.json?apikey=#{@api_key}"
when "current_releases"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/current_releases.json?apikey=#{@api_key}"
when "upcoming_dvds"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/upcoming.json?apikey=#{@api_key}"
when "top_rentals"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/top_rentals.json?apikey=#{@api_key}"
else
puts "Not a valid action"
return
end
return get(url)
end | ruby | def get_lists_action(action)
url = nil
case action
when "new_releases"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}"
when "opening"
url = "#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}"
when "upcoming"
url = "#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_key}"
when "in_theaters"
url = "#{LISTS_DETAIL_BASE_URL}/movies/in_theaters.json?apikey=#{@api_key}"
when "current_releases"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/current_releases.json?apikey=#{@api_key}"
when "upcoming_dvds"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/upcoming.json?apikey=#{@api_key}"
when "top_rentals"
url = "#{LISTS_DETAIL_BASE_URL}/dvds/top_rentals.json?apikey=#{@api_key}"
else
puts "Not a valid action"
return
end
return get(url)
end | [
"def",
"get_lists_action",
"(",
"action",
")",
"url",
"=",
"nil",
"case",
"action",
"when",
"\"new_releases\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}\"",
"when",
"\"opening\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}\"",
"when",
"\"upcoming\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_key}\"",
"when",
"\"in_theaters\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/movies/in_theaters.json?apikey=#{@api_key}\"",
"when",
"\"current_releases\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/dvds/current_releases.json?apikey=#{@api_key}\"",
"when",
"\"upcoming_dvds\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/dvds/upcoming.json?apikey=#{@api_key}\"",
"when",
"\"top_rentals\"",
"url",
"=",
"\"#{LISTS_DETAIL_BASE_URL}/dvds/top_rentals.json?apikey=#{@api_key}\"",
"else",
"puts",
"\"Not a valid action\"",
"return",
"end",
"return",
"get",
"(",
"url",
")",
"end"
] | Provides access to the various lists that Rotten Tomatoes provides.
@param [String] action The type of list to request.
@return [Array<BadFruit::Movie>] An array of programs contains in the requested list. | [
"Provides",
"access",
"to",
"the",
"various",
"lists",
"that",
"Rotten",
"Tomatoes",
"provides",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/base.rb#L121-L143 |
5,204 | brianmichel/BadFruit | lib/badfruit/base.rb | BadFruit.Base.parse_movies_array | def parse_movies_array(hash)
moviesArray = Array.new
hash["movies"].each do |movie|
moviesArray.push(Movie.new(movie, self))
end
return moviesArray
end | ruby | def parse_movies_array(hash)
moviesArray = Array.new
hash["movies"].each do |movie|
moviesArray.push(Movie.new(movie, self))
end
return moviesArray
end | [
"def",
"parse_movies_array",
"(",
"hash",
")",
"moviesArray",
"=",
"Array",
".",
"new",
"hash",
"[",
"\"movies\"",
"]",
".",
"each",
"do",
"|",
"movie",
"|",
"moviesArray",
".",
"push",
"(",
"Movie",
".",
"new",
"(",
"movie",
",",
"self",
")",
")",
"end",
"return",
"moviesArray",
"end"
] | Parse the movies out of a hash.
@param [Hash] hash The has to convert into an array of movies.
@return [Array<BadFruit::Movie>] An array of BadFruit::Movie objects. | [
"Parse",
"the",
"movies",
"out",
"of",
"a",
"hash",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/base.rb#L152-L158 |
5,205 | brianmichel/BadFruit | lib/badfruit/base.rb | BadFruit.Base.parse_actors_array | def parse_actors_array(hash)
actorsArray = Array.new
hash["cast"].each do |actor|
actorsArray.push(Actor.new(actor))
end
return actorsArray
end | ruby | def parse_actors_array(hash)
actorsArray = Array.new
hash["cast"].each do |actor|
actorsArray.push(Actor.new(actor))
end
return actorsArray
end | [
"def",
"parse_actors_array",
"(",
"hash",
")",
"actorsArray",
"=",
"Array",
".",
"new",
"hash",
"[",
"\"cast\"",
"]",
".",
"each",
"do",
"|",
"actor",
"|",
"actorsArray",
".",
"push",
"(",
"Actor",
".",
"new",
"(",
"actor",
")",
")",
"end",
"return",
"actorsArray",
"end"
] | Parse the actors out of a movie hash.
@param [Hash] hash The movie has to extract the actors out of.
@return [Array<BadFruit::Actor>] An array of BadFruit::Actor objects. | [
"Parse",
"the",
"actors",
"out",
"of",
"a",
"movie",
"hash",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/base.rb#L179-L185 |
5,206 | brianmichel/BadFruit | lib/badfruit/base.rb | BadFruit.Base.get | def get(url)
data = nil
resp = HTTParty.get(url)
if resp.code == 200
return resp.body
end
end | ruby | def get(url)
data = nil
resp = HTTParty.get(url)
if resp.code == 200
return resp.body
end
end | [
"def",
"get",
"(",
"url",
")",
"data",
"=",
"nil",
"resp",
"=",
"HTTParty",
".",
"get",
"(",
"url",
")",
"if",
"resp",
".",
"code",
"==",
"200",
"return",
"resp",
".",
"body",
"end",
"end"
] | Get the response of a given URL.
@param [String] url The URL to elicit a response from.
@return [Hash] The response from the server, or nil if there is no response. | [
"Get",
"the",
"response",
"of",
"a",
"given",
"URL",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/base.rb#L194-L202 |
5,207 | Sharparam/chatrix | lib/chatrix/client.rb | Chatrix.Client.sync! | def sync!
events = @matrix.sync since: @since
process_sync events
rescue ApiError => err
broadcast(:sync_error, err)
end | ruby | def sync!
events = @matrix.sync since: @since
process_sync events
rescue ApiError => err
broadcast(:sync_error, err)
end | [
"def",
"sync!",
"events",
"=",
"@matrix",
".",
"sync",
"since",
":",
"@since",
"process_sync",
"events",
"rescue",
"ApiError",
"=>",
"err",
"broadcast",
"(",
":sync_error",
",",
"err",
")",
"end"
] | Syncs against the server.
If an API error occurs during sync, it will be rescued and broadcasted
as `:sync_error`. | [
"Syncs",
"against",
"the",
"server",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/client.rb#L105-L110 |
5,208 | Sharparam/chatrix | lib/chatrix/client.rb | Chatrix.Client.process_sync | def process_sync(events)
return unless events.is_a? Hash
@since = events['next_batch']
broadcast(:sync, events)
@rooms.process_events events['rooms'] if events.key? 'rooms'
end | ruby | def process_sync(events)
return unless events.is_a? Hash
@since = events['next_batch']
broadcast(:sync, events)
@rooms.process_events events['rooms'] if events.key? 'rooms'
end | [
"def",
"process_sync",
"(",
"events",
")",
"return",
"unless",
"events",
".",
"is_a?",
"Hash",
"@since",
"=",
"events",
"[",
"'next_batch'",
"]",
"broadcast",
"(",
":sync",
",",
"events",
")",
"@rooms",
".",
"process_events",
"events",
"[",
"'rooms'",
"]",
"if",
"events",
".",
"key?",
"'rooms'",
"end"
] | Process the sync result.
@param events [Hash] The events to sync. | [
"Process",
"the",
"sync",
"result",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/client.rb#L115-L121 |
5,209 | wordjelly/Auth | app/helpers/auth/application_helper.rb | Auth.ApplicationHelper.get_signed_in_scope | def get_signed_in_scope
if signed_in?
Devise.mappings.keys.each do |res|
l = send "#{res.to_s}_signed_in?"
if send "#{res.to_s}_signed_in?"
return res.to_s
end
end
end
return 'user'
end | ruby | def get_signed_in_scope
if signed_in?
Devise.mappings.keys.each do |res|
l = send "#{res.to_s}_signed_in?"
if send "#{res.to_s}_signed_in?"
return res.to_s
end
end
end
return 'user'
end | [
"def",
"get_signed_in_scope",
"if",
"signed_in?",
"Devise",
".",
"mappings",
".",
"keys",
".",
"each",
"do",
"|",
"res",
"|",
"l",
"=",
"send",
"\"#{res.to_s}_signed_in?\"",
"if",
"send",
"\"#{res.to_s}_signed_in?\"",
"return",
"res",
".",
"to_s",
"end",
"end",
"end",
"return",
"'user'",
"end"
] | returns the name in small case of the class of the currently signed in resource
@example : will return 'user' or 'admin' | [
"returns",
"the",
"name",
"in",
"small",
"case",
"of",
"the",
"class",
"of",
"the",
"currently",
"signed",
"in",
"resource"
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/helpers/auth/application_helper.rb#L9-L19 |
5,210 | wordjelly/Auth | app/helpers/auth/application_helper.rb | Auth.ApplicationHelper.resource_in_navbar? | def resource_in_navbar?(resource)
return false unless resource
return (Auth.configuration.auth_resources[resource.class.name][:nav_bar] && Auth.configuration.enable_sign_in_modals)
end | ruby | def resource_in_navbar?(resource)
return false unless resource
return (Auth.configuration.auth_resources[resource.class.name][:nav_bar] && Auth.configuration.enable_sign_in_modals)
end | [
"def",
"resource_in_navbar?",
"(",
"resource",
")",
"return",
"false",
"unless",
"resource",
"return",
"(",
"Auth",
".",
"configuration",
".",
"auth_resources",
"[",
"resource",
".",
"class",
".",
"name",
"]",
"[",
":nav_bar",
"]",
"&&",
"Auth",
".",
"configuration",
".",
"enable_sign_in_modals",
")",
"end"
] | SHOULD THE RESOURCE SIGN IN OPTIONS BE SHOWN IN THE NAV BAR? | [
"SHOULD",
"THE",
"RESOURCE",
"SIGN",
"IN",
"OPTIONS",
"BE",
"SHOWN",
"IN",
"THE",
"NAV",
"BAR?"
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/helpers/auth/application_helper.rb#L39-L42 |
5,211 | koraktor/rubikon | lib/rubikon/has_arguments.rb | Rubikon.HasArguments.<< | def <<(arg)
raise ExtraArgumentError.new(@name) unless more_args?
if @arg_names.size > @args.size
name = @arg_names[@args.size]
if @max_arg_count == -1 && @arg_names.size == @args.size + 1
@args[name] = [arg]
else
@args[name] = arg
end
elsif !@arg_names.empty? && @max_arg_count == -1
@args[@arg_names.last] << arg
else
@args[@args.size] = arg
end
end | ruby | def <<(arg)
raise ExtraArgumentError.new(@name) unless more_args?
if @arg_names.size > @args.size
name = @arg_names[@args.size]
if @max_arg_count == -1 && @arg_names.size == @args.size + 1
@args[name] = [arg]
else
@args[name] = arg
end
elsif !@arg_names.empty? && @max_arg_count == -1
@args[@arg_names.last] << arg
else
@args[@args.size] = arg
end
end | [
"def",
"<<",
"(",
"arg",
")",
"raise",
"ExtraArgumentError",
".",
"new",
"(",
"@name",
")",
"unless",
"more_args?",
"if",
"@arg_names",
".",
"size",
">",
"@args",
".",
"size",
"name",
"=",
"@arg_names",
"[",
"@args",
".",
"size",
"]",
"if",
"@max_arg_count",
"==",
"-",
"1",
"&&",
"@arg_names",
".",
"size",
"==",
"@args",
".",
"size",
"+",
"1",
"@args",
"[",
"name",
"]",
"=",
"[",
"arg",
"]",
"else",
"@args",
"[",
"name",
"]",
"=",
"arg",
"end",
"elsif",
"!",
"@arg_names",
".",
"empty?",
"&&",
"@max_arg_count",
"==",
"-",
"1",
"@args",
"[",
"@arg_names",
".",
"last",
"]",
"<<",
"arg",
"else",
"@args",
"[",
"@args",
".",
"size",
"]",
"=",
"arg",
"end",
"end"
] | Adds an argument to this parameter. Arguments can be accessed inside the
application code using the args method.
@param [String] arg The argument to add to the supplied arguments of this
parameter
@raise [ExtraArgumentError] if the parameter has all required arguments
supplied and does not take optional arguments
@return [Array] The supplied arguments of this parameter
@see #[]
@see #args
@since 0.3.0 | [
"Adds",
"an",
"argument",
"to",
"this",
"parameter",
".",
"Arguments",
"can",
"be",
"accessed",
"inside",
"the",
"application",
"code",
"using",
"the",
"args",
"method",
"."
] | c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b | https://github.com/koraktor/rubikon/blob/c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b/lib/rubikon/has_arguments.rb#L173-L188 |
5,212 | koraktor/rubikon | lib/rubikon/has_arguments.rb | Rubikon.HasArguments.check_args | def check_args
raise MissingArgumentError.new(@name) unless args_full?
unless @arg_values.empty?
@args.each do |name, arg|
if @arg_values.key? name
arg = [arg] unless arg.is_a? Array
arg.each do |a|
unless a =~ @arg_values[name]
raise UnexpectedArgumentError.new(a)
end
end
end
end
end
end | ruby | def check_args
raise MissingArgumentError.new(@name) unless args_full?
unless @arg_values.empty?
@args.each do |name, arg|
if @arg_values.key? name
arg = [arg] unless arg.is_a? Array
arg.each do |a|
unless a =~ @arg_values[name]
raise UnexpectedArgumentError.new(a)
end
end
end
end
end
end | [
"def",
"check_args",
"raise",
"MissingArgumentError",
".",
"new",
"(",
"@name",
")",
"unless",
"args_full?",
"unless",
"@arg_values",
".",
"empty?",
"@args",
".",
"each",
"do",
"|",
"name",
",",
"arg",
"|",
"if",
"@arg_values",
".",
"key?",
"name",
"arg",
"=",
"[",
"arg",
"]",
"unless",
"arg",
".",
"is_a?",
"Array",
"arg",
".",
"each",
"do",
"|",
"a",
"|",
"unless",
"a",
"=~",
"@arg_values",
"[",
"name",
"]",
"raise",
"UnexpectedArgumentError",
".",
"new",
"(",
"a",
")",
"end",
"end",
"end",
"end",
"end",
"end"
] | Checks the arguments for this parameter
@raise [MissingArgumentError] if there are not enough arguments for
this parameter
@since 0.3.0 | [
"Checks",
"the",
"arguments",
"for",
"this",
"parameter"
] | c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b | https://github.com/koraktor/rubikon/blob/c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b/lib/rubikon/has_arguments.rb#L220-L234 |
5,213 | koraktor/rubikon | lib/rubikon/has_arguments.rb | Rubikon.HasArguments.method_missing | def method_missing(name, *args, &block)
if args.empty? && !block_given? && @arg_names.include?(name)
@args[name]
else
super
end
end | ruby | def method_missing(name, *args, &block)
if args.empty? && !block_given? && @arg_names.include?(name)
@args[name]
else
super
end
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"args",
".",
"empty?",
"&&",
"!",
"block_given?",
"&&",
"@arg_names",
".",
"include?",
"(",
"name",
")",
"@args",
"[",
"name",
"]",
"else",
"super",
"end",
"end"
] | If a named argument with the specified method name exists, a call to that
method will return the value of the argument.
@param (see ClassMethods#method_missing)
@see #args
@see #[]
@example
option :user, [:name] do
@user = name
end | [
"If",
"a",
"named",
"argument",
"with",
"the",
"specified",
"method",
"name",
"exists",
"a",
"call",
"to",
"that",
"method",
"will",
"return",
"the",
"value",
"of",
"the",
"argument",
"."
] | c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b | https://github.com/koraktor/rubikon/blob/c5a09d2a6a0878bb4ae5bcf71fcb111646ed0b2b/lib/rubikon/has_arguments.rb#L247-L253 |
5,214 | gmalette/pubsubstub | lib/pubsubstub/subscription.rb | Pubsubstub.Subscription.fetch_scrollback | def fetch_scrollback(last_event_id)
event_sent = false
if last_event_id
channels.each do |channel|
channel.scrollback(since: last_event_id).each do |event|
event_sent = true
queue.push(event)
end
end
end
queue.push(Pubsubstub.heartbeat_event) unless event_sent
end | ruby | def fetch_scrollback(last_event_id)
event_sent = false
if last_event_id
channels.each do |channel|
channel.scrollback(since: last_event_id).each do |event|
event_sent = true
queue.push(event)
end
end
end
queue.push(Pubsubstub.heartbeat_event) unless event_sent
end | [
"def",
"fetch_scrollback",
"(",
"last_event_id",
")",
"event_sent",
"=",
"false",
"if",
"last_event_id",
"channels",
".",
"each",
"do",
"|",
"channel",
"|",
"channel",
".",
"scrollback",
"(",
"since",
":",
"last_event_id",
")",
".",
"each",
"do",
"|",
"event",
"|",
"event_sent",
"=",
"true",
"queue",
".",
"push",
"(",
"event",
")",
"end",
"end",
"end",
"queue",
".",
"push",
"(",
"Pubsubstub",
".",
"heartbeat_event",
")",
"unless",
"event_sent",
"end"
] | This method is not ideal as it doesn't guarantee order in case of multi-channel subscription | [
"This",
"method",
"is",
"not",
"ideal",
"as",
"it",
"doesn",
"t",
"guarantee",
"order",
"in",
"case",
"of",
"multi",
"-",
"channel",
"subscription"
] | a445c4969f2a7a1fe0894320f1ecd1d7e362d611 | https://github.com/gmalette/pubsubstub/blob/a445c4969f2a7a1fe0894320f1ecd1d7e362d611/lib/pubsubstub/subscription.rb#L42-L54 |
5,215 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/region.rb | GosuEnhanced.Region.contains? | def contains?(col, row = nil)
return contains_point?(col) if col.respond_to? :x
col.between?(left, left + width - 1) &&
row.between?(top, top + height - 1)
end | ruby | def contains?(col, row = nil)
return contains_point?(col) if col.respond_to? :x
col.between?(left, left + width - 1) &&
row.between?(top, top + height - 1)
end | [
"def",
"contains?",
"(",
"col",
",",
"row",
"=",
"nil",
")",
"return",
"contains_point?",
"(",
"col",
")",
"if",
"col",
".",
"respond_to?",
":x",
"col",
".",
"between?",
"(",
"left",
",",
"left",
"+",
"width",
"-",
"1",
")",
"&&",
"row",
".",
"between?",
"(",
"top",
",",
"top",
"+",
"height",
"-",
"1",
")",
"end"
] | Create a new region with specified +pos+ as top left corner and +size+
as width and height. The stored positions are copies of the passed
position and size to avoid aliasing.
Alternatively, can be initialized with 2 +Point+s.
Return whether the region contains the specified +row+ and +col+
Alternatively, can be passed a +Point+ | [
"Create",
"a",
"new",
"region",
"with",
"specified",
"+",
"pos",
"+",
"as",
"top",
"left",
"corner",
"and",
"+",
"size",
"+",
"as",
"width",
"and",
"height",
".",
"The",
"stored",
"positions",
"are",
"copies",
"of",
"the",
"passed",
"position",
"and",
"size",
"to",
"avoid",
"aliasing",
"."
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/region.rb#L33-L38 |
5,216 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/region.rb | GosuEnhanced.Region.draw | def draw(surface, z_order, colour)
surface.draw_rectangle(position, size, z_order, colour)
end | ruby | def draw(surface, z_order, colour)
surface.draw_rectangle(position, size, z_order, colour)
end | [
"def",
"draw",
"(",
"surface",
",",
"z_order",
",",
"colour",
")",
"surface",
".",
"draw_rectangle",
"(",
"position",
",",
"size",
",",
"z_order",
",",
"colour",
")",
"end"
] | Duplicate a Region, must be done explicitly to avoid aliasing.
Draw a rectangle on the specified +surface+ at the specified +z_order+
and with the specified +colour+ | [
"Duplicate",
"a",
"Region",
"must",
"be",
"done",
"explicitly",
"to",
"avoid",
"aliasing",
".",
"Draw",
"a",
"rectangle",
"on",
"the",
"specified",
"+",
"surface",
"+",
"at",
"the",
"specified",
"+",
"z_order",
"+",
"and",
"with",
"the",
"specified",
"+",
"colour",
"+"
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/region.rb#L57-L59 |
5,217 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/region.rb | GosuEnhanced.Region.contains_point? | def contains_point?(pt)
pt.x.between?(left, left + width - 1) &&
pt.y.between?(top, top + height - 1)
end | ruby | def contains_point?(pt)
pt.x.between?(left, left + width - 1) &&
pt.y.between?(top, top + height - 1)
end | [
"def",
"contains_point?",
"(",
"pt",
")",
"pt",
".",
"x",
".",
"between?",
"(",
"left",
",",
"left",
"+",
"width",
"-",
"1",
")",
"&&",
"pt",
".",
"y",
".",
"between?",
"(",
"top",
",",
"top",
"+",
"height",
"-",
"1",
")",
"end"
] | Return whether the passed Point +pt+ is contained within the current
Region. | [
"Return",
"whether",
"the",
"passed",
"Point",
"+",
"pt",
"+",
"is",
"contained",
"within",
"the",
"current",
"Region",
"."
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/region.rb#L70-L73 |
5,218 | blahah/biopsy | lib/biopsy/experiment.rb | Biopsy.Experiment.select_algorithm | def select_algorithm
return if algorithm
max = Settings.instance.sweep_cutoff
n = @target.count_parameter_permutations
if n < max
@algorithm = ParameterSweeper.new(@target.parameters, @id)
else
@algorithm = TabuSearch.new(@target.parameters, @id)
end
end | ruby | def select_algorithm
return if algorithm
max = Settings.instance.sweep_cutoff
n = @target.count_parameter_permutations
if n < max
@algorithm = ParameterSweeper.new(@target.parameters, @id)
else
@algorithm = TabuSearch.new(@target.parameters, @id)
end
end | [
"def",
"select_algorithm",
"return",
"if",
"algorithm",
"max",
"=",
"Settings",
".",
"instance",
".",
"sweep_cutoff",
"n",
"=",
"@target",
".",
"count_parameter_permutations",
"if",
"n",
"<",
"max",
"@algorithm",
"=",
"ParameterSweeper",
".",
"new",
"(",
"@target",
".",
"parameters",
",",
"@id",
")",
"else",
"@algorithm",
"=",
"TabuSearch",
".",
"new",
"(",
"@target",
".",
"parameters",
",",
"@id",
")",
"end",
"end"
] | select the optimisation algorithm to use | [
"select",
"the",
"optimisation",
"algorithm",
"to",
"use"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/experiment.rb#L62-L71 |
5,219 | blahah/biopsy | lib/biopsy/experiment.rb | Biopsy.Experiment.run | def run
start_time = Time.now
in_progress = true
@algorithm.setup @start
@current_params = @start
max_scores = @target.count_parameter_permutations
while in_progress
run_iteration
# update the best result
best = @best
@best = @algorithm.best
ptext = @best[:parameters].each_pair.map{ |k, v| "#{k}:#{v}" }.join(", ")
if @best &&
@best.key?(:score) &&
best &&
best.key?(:score) &&
@best[:score] > best[:score]
unless @verbosity == :silent
puts "found a new best score: #{@best[:score]} "+
"for parameters #{ptext}"
end
end
# have we finished?
in_progress = [email protected]? && @scores.size < max_scores
if in_progress && !(@timelimit.nil?)
in_progress = (Time.now - start_time < @timelimit)
end
end
@algorithm.write_data if @algorithm.respond_to? :write_data
unless @verbosity == :silent
puts "found optimum score: #{@best[:score]} for parameters "+
"#{@best[:parameters]} in #{@iteration_count} iterations."
end
return @best
end | ruby | def run
start_time = Time.now
in_progress = true
@algorithm.setup @start
@current_params = @start
max_scores = @target.count_parameter_permutations
while in_progress
run_iteration
# update the best result
best = @best
@best = @algorithm.best
ptext = @best[:parameters].each_pair.map{ |k, v| "#{k}:#{v}" }.join(", ")
if @best &&
@best.key?(:score) &&
best &&
best.key?(:score) &&
@best[:score] > best[:score]
unless @verbosity == :silent
puts "found a new best score: #{@best[:score]} "+
"for parameters #{ptext}"
end
end
# have we finished?
in_progress = [email protected]? && @scores.size < max_scores
if in_progress && !(@timelimit.nil?)
in_progress = (Time.now - start_time < @timelimit)
end
end
@algorithm.write_data if @algorithm.respond_to? :write_data
unless @verbosity == :silent
puts "found optimum score: #{@best[:score]} for parameters "+
"#{@best[:parameters]} in #{@iteration_count} iterations."
end
return @best
end | [
"def",
"run",
"start_time",
"=",
"Time",
".",
"now",
"in_progress",
"=",
"true",
"@algorithm",
".",
"setup",
"@start",
"@current_params",
"=",
"@start",
"max_scores",
"=",
"@target",
".",
"count_parameter_permutations",
"while",
"in_progress",
"run_iteration",
"# update the best result",
"best",
"=",
"@best",
"@best",
"=",
"@algorithm",
".",
"best",
"ptext",
"=",
"@best",
"[",
":parameters",
"]",
".",
"each_pair",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}:#{v}\"",
"}",
".",
"join",
"(",
"\", \"",
")",
"if",
"@best",
"&&",
"@best",
".",
"key?",
"(",
":score",
")",
"&&",
"best",
"&&",
"best",
".",
"key?",
"(",
":score",
")",
"&&",
"@best",
"[",
":score",
"]",
">",
"best",
"[",
":score",
"]",
"unless",
"@verbosity",
"==",
":silent",
"puts",
"\"found a new best score: #{@best[:score]} \"",
"+",
"\"for parameters #{ptext}\"",
"end",
"end",
"# have we finished?",
"in_progress",
"=",
"!",
"@algorithm",
".",
"finished?",
"&&",
"@scores",
".",
"size",
"<",
"max_scores",
"if",
"in_progress",
"&&",
"!",
"(",
"@timelimit",
".",
"nil?",
")",
"in_progress",
"=",
"(",
"Time",
".",
"now",
"-",
"start_time",
"<",
"@timelimit",
")",
"end",
"end",
"@algorithm",
".",
"write_data",
"if",
"@algorithm",
".",
"respond_to?",
":write_data",
"unless",
"@verbosity",
"==",
":silent",
"puts",
"\"found optimum score: #{@best[:score]} for parameters \"",
"+",
"\"#{@best[:parameters]} in #{@iteration_count} iterations.\"",
"end",
"return",
"@best",
"end"
] | Runs the experiment until the completion criteria
are met. On completion, returns the best parameter
set. | [
"Runs",
"the",
"experiment",
"until",
"the",
"completion",
"criteria",
"are",
"met",
".",
"On",
"completion",
"returns",
"the",
"best",
"parameter",
"set",
"."
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/experiment.rb#L82-L116 |
5,220 | blahah/biopsy | lib/biopsy/experiment.rb | Biopsy.Experiment.create_tempdir | def create_tempdir
token = loop do
# generate random dirnames until we find one that
# doesn't exist
test_token = SecureRandom.hex
break test_token unless File.exist? test_token
end
Dir.mkdir(token)
@last_tempdir = token
token
end | ruby | def create_tempdir
token = loop do
# generate random dirnames until we find one that
# doesn't exist
test_token = SecureRandom.hex
break test_token unless File.exist? test_token
end
Dir.mkdir(token)
@last_tempdir = token
token
end | [
"def",
"create_tempdir",
"token",
"=",
"loop",
"do",
"# generate random dirnames until we find one that",
"# doesn't exist",
"test_token",
"=",
"SecureRandom",
".",
"hex",
"break",
"test_token",
"unless",
"File",
".",
"exist?",
"test_token",
"end",
"Dir",
".",
"mkdir",
"(",
"token",
")",
"@last_tempdir",
"=",
"token",
"token",
"end"
] | create a guaranteed random temporary directory for storing outputs
return the dirname | [
"create",
"a",
"guaranteed",
"random",
"temporary",
"directory",
"for",
"storing",
"outputs",
"return",
"the",
"dirname"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/experiment.rb#L179-L189 |
5,221 | blahah/biopsy | lib/biopsy/experiment.rb | Biopsy.Experiment.set_id | def set_id id
@id = id
if @id.nil?
t = Time.now
parts = %w[y m d H M S Z].map{ |p| t.strftime "%#{p}" }
@id = "experiment_#{parts.join('_')}"
end
end | ruby | def set_id id
@id = id
if @id.nil?
t = Time.now
parts = %w[y m d H M S Z].map{ |p| t.strftime "%#{p}" }
@id = "experiment_#{parts.join('_')}"
end
end | [
"def",
"set_id",
"id",
"@id",
"=",
"id",
"if",
"@id",
".",
"nil?",
"t",
"=",
"Time",
".",
"now",
"parts",
"=",
"%w[",
"y",
"m",
"d",
"H",
"M",
"S",
"Z",
"]",
".",
"map",
"{",
"|",
"p",
"|",
"t",
".",
"strftime",
"\"%#{p}\"",
"}",
"@id",
"=",
"\"experiment_#{parts.join('_')}\"",
"end",
"end"
] | set experiment ID with either user provided value, or date-time
as fallback | [
"set",
"experiment",
"ID",
"with",
"either",
"user",
"provided",
"value",
"or",
"date",
"-",
"time",
"as",
"fallback"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/experiment.rb#L193-L200 |
5,222 | lasso/racket-registry | lib/racket/registry.rb | Racket.Registry.register | def register(key, proc = nil, &block)
Helper.register(obj: self, key: key, proc: proc, block: block)
end | ruby | def register(key, proc = nil, &block)
Helper.register(obj: self, key: key, proc: proc, block: block)
end | [
"def",
"register",
"(",
"key",
",",
"proc",
"=",
"nil",
",",
"&",
"block",
")",
"Helper",
".",
"register",
"(",
"obj",
":",
"self",
",",
"key",
":",
"key",
",",
"proc",
":",
"proc",
",",
"block",
":",
"block",
")",
"end"
] | Registers a new callback in the registry. This will add a new method
matching +key+ to the registry that can be used both outside the
registry and when registering other callbacks dependant of the
current entry. Results from the callback will not be cached, meaning
that the callback may return a different object every time.
@param [String|Symbol] key
@param [Proc|nil] proc
@return [nil] | [
"Registers",
"a",
"new",
"callback",
"in",
"the",
"registry",
".",
"This",
"will",
"add",
"a",
"new",
"method",
"matching",
"+",
"key",
"+",
"to",
"the",
"registry",
"that",
"can",
"be",
"used",
"both",
"outside",
"the",
"registry",
"and",
"when",
"registering",
"other",
"callbacks",
"dependant",
"of",
"the",
"current",
"entry",
".",
"Results",
"from",
"the",
"callback",
"will",
"not",
"be",
"cached",
"meaning",
"that",
"the",
"callback",
"may",
"return",
"a",
"different",
"object",
"every",
"time",
"."
] | d3413d822c297765d5a78bff0216f4cf0b2ace41 | https://github.com/lasso/racket-registry/blob/d3413d822c297765d5a78bff0216f4cf0b2ace41/lib/racket/registry.rb#L73-L75 |
5,223 | lasso/racket-registry | lib/racket/registry.rb | Racket.Registry.register_singleton | def register_singleton(key, proc = nil, &block)
Helper.register_singleton(obj: self, key: key, proc: proc, block: block)
end | ruby | def register_singleton(key, proc = nil, &block)
Helper.register_singleton(obj: self, key: key, proc: proc, block: block)
end | [
"def",
"register_singleton",
"(",
"key",
",",
"proc",
"=",
"nil",
",",
"&",
"block",
")",
"Helper",
".",
"register_singleton",
"(",
"obj",
":",
"self",
",",
"key",
":",
"key",
",",
"proc",
":",
"proc",
",",
"block",
":",
"block",
")",
"end"
] | Registers a new callback in the registry. This will add a new method
matching +key+ to the registry that can be used both outside the
registry and when registering other callbacks dependant of the
current entry. Results from the callnack will be cached, meaning
that the callback will return the same object every time.
@param [String|Symbol] key
@param [Proc|nil] proc
@return [nil] | [
"Registers",
"a",
"new",
"callback",
"in",
"the",
"registry",
".",
"This",
"will",
"add",
"a",
"new",
"method",
"matching",
"+",
"key",
"+",
"to",
"the",
"registry",
"that",
"can",
"be",
"used",
"both",
"outside",
"the",
"registry",
"and",
"when",
"registering",
"other",
"callbacks",
"dependant",
"of",
"the",
"current",
"entry",
".",
"Results",
"from",
"the",
"callnack",
"will",
"be",
"cached",
"meaning",
"that",
"the",
"callback",
"will",
"return",
"the",
"same",
"object",
"every",
"time",
"."
] | d3413d822c297765d5a78bff0216f4cf0b2ace41 | https://github.com/lasso/racket-registry/blob/d3413d822c297765d5a78bff0216f4cf0b2ace41/lib/racket/registry.rb#L86-L88 |
5,224 | datamapper/dm-sweatshop | lib/dm-sweatshop/model.rb | DataMapper.Model.generate | def generate(name = default_fauxture_name, attributes = {})
name, attributes = default_fauxture_name, name if name.is_a? Hash
Sweatshop.create(self, name, attributes)
end | ruby | def generate(name = default_fauxture_name, attributes = {})
name, attributes = default_fauxture_name, name if name.is_a? Hash
Sweatshop.create(self, name, attributes)
end | [
"def",
"generate",
"(",
"name",
"=",
"default_fauxture_name",
",",
"attributes",
"=",
"{",
"}",
")",
"name",
",",
"attributes",
"=",
"default_fauxture_name",
",",
"name",
"if",
"name",
".",
"is_a?",
"Hash",
"Sweatshop",
".",
"create",
"(",
"self",
",",
"name",
",",
"attributes",
")",
"end"
] | Creates an instance from hash of attributes, saves it
and adds it to the record map. Attributes given as the
second argument are merged into attributes from fixture.
If record is valid because of duplicated property value,
this method does a retry.
@param name [Symbol]
@param attributes [Hash]
@api public
@return [DataMapper::Resource] added instance | [
"Creates",
"an",
"instance",
"from",
"hash",
"of",
"attributes",
"saves",
"it",
"and",
"adds",
"it",
"to",
"the",
"record",
"map",
".",
"Attributes",
"given",
"as",
"the",
"second",
"argument",
"are",
"merged",
"into",
"attributes",
"from",
"fixture",
"."
] | 25d6b2353973df329734801417e31709f6ff7686 | https://github.com/datamapper/dm-sweatshop/blob/25d6b2353973df329734801417e31709f6ff7686/lib/dm-sweatshop/model.rb#L36-L39 |
5,225 | datamapper/dm-sweatshop | lib/dm-sweatshop/model.rb | DataMapper.Model.make | def make(name = default_fauxture_name, attributes = {})
name, attributes = default_fauxture_name, name if name.is_a? Hash
Sweatshop.make(self, name, attributes)
end | ruby | def make(name = default_fauxture_name, attributes = {})
name, attributes = default_fauxture_name, name if name.is_a? Hash
Sweatshop.make(self, name, attributes)
end | [
"def",
"make",
"(",
"name",
"=",
"default_fauxture_name",
",",
"attributes",
"=",
"{",
"}",
")",
"name",
",",
"attributes",
"=",
"default_fauxture_name",
",",
"name",
"if",
"name",
".",
"is_a?",
"Hash",
"Sweatshop",
".",
"make",
"(",
"self",
",",
"name",
",",
"attributes",
")",
"end"
] | Creates an instance from given hash of attributes
and adds it to records map without saving.
@param name [Symbol] name of the fauxture to use
@param attributes [Hash]
@api private
@return [DataMapper::Resource] added instance | [
"Creates",
"an",
"instance",
"from",
"given",
"hash",
"of",
"attributes",
"and",
"adds",
"it",
"to",
"records",
"map",
"without",
"saving",
"."
] | 25d6b2353973df329734801417e31709f6ff7686 | https://github.com/datamapper/dm-sweatshop/blob/25d6b2353973df329734801417e31709f6ff7686/lib/dm-sweatshop/model.rb#L82-L85 |
5,226 | postmodern/deployml | lib/deployml/project.rb | DeploYML.Project.environment | def environment(name=:production)
name = name.to_sym
unless @environments[name]
raise(UnknownEnvironment,"unknown environment: #{name}",caller)
end
return @environments[name]
end | ruby | def environment(name=:production)
name = name.to_sym
unless @environments[name]
raise(UnknownEnvironment,"unknown environment: #{name}",caller)
end
return @environments[name]
end | [
"def",
"environment",
"(",
"name",
"=",
":production",
")",
"name",
"=",
"name",
".",
"to_sym",
"unless",
"@environments",
"[",
"name",
"]",
"raise",
"(",
"UnknownEnvironment",
",",
"\"unknown environment: #{name}\"",
",",
"caller",
")",
"end",
"return",
"@environments",
"[",
"name",
"]",
"end"
] | Creates a new project using the given configuration file.
@param [String] root
The root directory of the project.
@raise [ConfigNotFound]
The configuration file for the project could not be found
in any of the common directories.
@param [Symbol, String] name
The name of the environment to use.
@return [Environment]
The environment with the given name.
@raise [UnknownEnvironment]
No environment was configured with the given name.
@since 0.3.0 | [
"Creates",
"a",
"new",
"project",
"using",
"the",
"given",
"configuration",
"file",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/project.rb#L64-L72 |
5,227 | postmodern/deployml | lib/deployml/project.rb | DeploYML.Project.load_configuration | def load_configuration(path)
config = YAML.load_file(path)
unless config.kind_of?(Hash)
raise(InvalidConfig,"DeploYML file #{path.dump} does not contain a Hash",caller)
end
return config
end | ruby | def load_configuration(path)
config = YAML.load_file(path)
unless config.kind_of?(Hash)
raise(InvalidConfig,"DeploYML file #{path.dump} does not contain a Hash",caller)
end
return config
end | [
"def",
"load_configuration",
"(",
"path",
")",
"config",
"=",
"YAML",
".",
"load_file",
"(",
"path",
")",
"unless",
"config",
".",
"kind_of?",
"(",
"Hash",
")",
"raise",
"(",
"InvalidConfig",
",",
"\"DeploYML file #{path.dump} does not contain a Hash\"",
",",
"caller",
")",
"end",
"return",
"config",
"end"
] | Loads configuration from a YAML file.
@param [String] path
The path to the configuration file.
@return [Hash]
The loaded configuration.
@raise [InvalidConfig]
The configuration file did not contain a YAML Hash.
@since 0.4.1 | [
"Loads",
"configuration",
"from",
"a",
"YAML",
"file",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/project.rb#L297-L305 |
5,228 | postmodern/deployml | lib/deployml/project.rb | DeploYML.Project.load_environments! | def load_environments!
base_config = infer_configuration
if File.file?(@config_file)
base_config.merge!(load_configuration(@config_file))
end
@environments = {}
if File.directory?(@environments_dir)
Dir.glob(File.join(@environments_dir,'*.yml')) do |path|
config = base_config.merge(load_configuration(path))
name = File.basename(path).sub(/\.yml$/,'').to_sym
@environments[name] = Environment.new(name,config)
end
else
@environments[:production] = Environment.new(:production,base_config)
end
end | ruby | def load_environments!
base_config = infer_configuration
if File.file?(@config_file)
base_config.merge!(load_configuration(@config_file))
end
@environments = {}
if File.directory?(@environments_dir)
Dir.glob(File.join(@environments_dir,'*.yml')) do |path|
config = base_config.merge(load_configuration(path))
name = File.basename(path).sub(/\.yml$/,'').to_sym
@environments[name] = Environment.new(name,config)
end
else
@environments[:production] = Environment.new(:production,base_config)
end
end | [
"def",
"load_environments!",
"base_config",
"=",
"infer_configuration",
"if",
"File",
".",
"file?",
"(",
"@config_file",
")",
"base_config",
".",
"merge!",
"(",
"load_configuration",
"(",
"@config_file",
")",
")",
"end",
"@environments",
"=",
"{",
"}",
"if",
"File",
".",
"directory?",
"(",
"@environments_dir",
")",
"Dir",
".",
"glob",
"(",
"File",
".",
"join",
"(",
"@environments_dir",
",",
"'*.yml'",
")",
")",
"do",
"|",
"path",
"|",
"config",
"=",
"base_config",
".",
"merge",
"(",
"load_configuration",
"(",
"path",
")",
")",
"name",
"=",
"File",
".",
"basename",
"(",
"path",
")",
".",
"sub",
"(",
"/",
"\\.",
"/",
",",
"''",
")",
".",
"to_sym",
"@environments",
"[",
"name",
"]",
"=",
"Environment",
".",
"new",
"(",
"name",
",",
"config",
")",
"end",
"else",
"@environments",
"[",
":production",
"]",
"=",
"Environment",
".",
"new",
"(",
":production",
",",
"base_config",
")",
"end",
"end"
] | Loads the project configuration.
@since 0.3.0 | [
"Loads",
"the",
"project",
"configuration",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/project.rb#L312-L331 |
5,229 | mose/cogbot | lib/cogbot.rb | Cogbot.Bot.start | def start
# prepare config
config = {}
begin
config = YAML::load_file(CONFIG_FILE)
rescue Exception => e
load 'lib/cogbot/setup.rb'
config['main'] = Cogbot::Setup.init
end
# prepare daemon
Daemons.daemonize(
:app_name => 'cogbot',
:dir_mode => :normal,
:log_dir => LOG_DIR,
:log_output => true,
:dir => CONFIG_DIR
)
# checkout plugins
plugins = []
config['main']['plugins'].each do |p|
if File.exists?(File.join(ROOT_DIR, 'plugins', "#{p}.rb"))
require File.join(ROOT_DIR, 'plugins', p)
plugins.push Cinch::Plugins.const_get(p.camelize)
end
end
# create bot
bot = Cinch::Bot.new do
configure do |c|
c.server = config['main']['server']
c.ssl.use = ( config['main']['ssl'] == 'true' )
c.nick = config['main']['nick']
c.user = config['main']['nick']
c.realname = config['main']['nick']
c.channels = config['main']['channels']
c.sasl.username = config['main']['sasl_user']
c.sasl.password = config['main']['sasl_pass']
c.options = { 'cogconf' => config }
c.plugins.prefix = config['main']['prefix']
c.plugins.plugins = plugins
end
on :message, 'hi' do |m|
m.reply "Hello, #{m.user.nick}"
end
end
bot.loggers.debug(plugins.inspect)
Signal.trap('TERM') { EM.stop }
EM.run do
EM.defer { bot.start }
if config['server']
EM.add_timer(3) do
EM.start_server(
config['server']['ip'],
config['server']['port'],
Server,
bot
)
end
end
end
bot.quit
end | ruby | def start
# prepare config
config = {}
begin
config = YAML::load_file(CONFIG_FILE)
rescue Exception => e
load 'lib/cogbot/setup.rb'
config['main'] = Cogbot::Setup.init
end
# prepare daemon
Daemons.daemonize(
:app_name => 'cogbot',
:dir_mode => :normal,
:log_dir => LOG_DIR,
:log_output => true,
:dir => CONFIG_DIR
)
# checkout plugins
plugins = []
config['main']['plugins'].each do |p|
if File.exists?(File.join(ROOT_DIR, 'plugins', "#{p}.rb"))
require File.join(ROOT_DIR, 'plugins', p)
plugins.push Cinch::Plugins.const_get(p.camelize)
end
end
# create bot
bot = Cinch::Bot.new do
configure do |c|
c.server = config['main']['server']
c.ssl.use = ( config['main']['ssl'] == 'true' )
c.nick = config['main']['nick']
c.user = config['main']['nick']
c.realname = config['main']['nick']
c.channels = config['main']['channels']
c.sasl.username = config['main']['sasl_user']
c.sasl.password = config['main']['sasl_pass']
c.options = { 'cogconf' => config }
c.plugins.prefix = config['main']['prefix']
c.plugins.plugins = plugins
end
on :message, 'hi' do |m|
m.reply "Hello, #{m.user.nick}"
end
end
bot.loggers.debug(plugins.inspect)
Signal.trap('TERM') { EM.stop }
EM.run do
EM.defer { bot.start }
if config['server']
EM.add_timer(3) do
EM.start_server(
config['server']['ip'],
config['server']['port'],
Server,
bot
)
end
end
end
bot.quit
end | [
"def",
"start",
"# prepare config",
"config",
"=",
"{",
"}",
"begin",
"config",
"=",
"YAML",
"::",
"load_file",
"(",
"CONFIG_FILE",
")",
"rescue",
"Exception",
"=>",
"e",
"load",
"'lib/cogbot/setup.rb'",
"config",
"[",
"'main'",
"]",
"=",
"Cogbot",
"::",
"Setup",
".",
"init",
"end",
"# prepare daemon",
"Daemons",
".",
"daemonize",
"(",
":app_name",
"=>",
"'cogbot'",
",",
":dir_mode",
"=>",
":normal",
",",
":log_dir",
"=>",
"LOG_DIR",
",",
":log_output",
"=>",
"true",
",",
":dir",
"=>",
"CONFIG_DIR",
")",
"# checkout plugins",
"plugins",
"=",
"[",
"]",
"config",
"[",
"'main'",
"]",
"[",
"'plugins'",
"]",
".",
"each",
"do",
"|",
"p",
"|",
"if",
"File",
".",
"exists?",
"(",
"File",
".",
"join",
"(",
"ROOT_DIR",
",",
"'plugins'",
",",
"\"#{p}.rb\"",
")",
")",
"require",
"File",
".",
"join",
"(",
"ROOT_DIR",
",",
"'plugins'",
",",
"p",
")",
"plugins",
".",
"push",
"Cinch",
"::",
"Plugins",
".",
"const_get",
"(",
"p",
".",
"camelize",
")",
"end",
"end",
"# create bot",
"bot",
"=",
"Cinch",
"::",
"Bot",
".",
"new",
"do",
"configure",
"do",
"|",
"c",
"|",
"c",
".",
"server",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'server'",
"]",
"c",
".",
"ssl",
".",
"use",
"=",
"(",
"config",
"[",
"'main'",
"]",
"[",
"'ssl'",
"]",
"==",
"'true'",
")",
"c",
".",
"nick",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'nick'",
"]",
"c",
".",
"user",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'nick'",
"]",
"c",
".",
"realname",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'nick'",
"]",
"c",
".",
"channels",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'channels'",
"]",
"c",
".",
"sasl",
".",
"username",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'sasl_user'",
"]",
"c",
".",
"sasl",
".",
"password",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'sasl_pass'",
"]",
"c",
".",
"options",
"=",
"{",
"'cogconf'",
"=>",
"config",
"}",
"c",
".",
"plugins",
".",
"prefix",
"=",
"config",
"[",
"'main'",
"]",
"[",
"'prefix'",
"]",
"c",
".",
"plugins",
".",
"plugins",
"=",
"plugins",
"end",
"on",
":message",
",",
"'hi'",
"do",
"|",
"m",
"|",
"m",
".",
"reply",
"\"Hello, #{m.user.nick}\"",
"end",
"end",
"bot",
".",
"loggers",
".",
"debug",
"(",
"plugins",
".",
"inspect",
")",
"Signal",
".",
"trap",
"(",
"'TERM'",
")",
"{",
"EM",
".",
"stop",
"}",
"EM",
".",
"run",
"do",
"EM",
".",
"defer",
"{",
"bot",
".",
"start",
"}",
"if",
"config",
"[",
"'server'",
"]",
"EM",
".",
"add_timer",
"(",
"3",
")",
"do",
"EM",
".",
"start_server",
"(",
"config",
"[",
"'server'",
"]",
"[",
"'ip'",
"]",
",",
"config",
"[",
"'server'",
"]",
"[",
"'port'",
"]",
",",
"Server",
",",
"bot",
")",
"end",
"end",
"end",
"bot",
".",
"quit",
"end"
] | manages the start cli command | [
"manages",
"the",
"start",
"cli",
"command"
] | 844dab70f9093aba13dd50a8e445483d790b868a | https://github.com/mose/cogbot/blob/844dab70f9093aba13dd50a8e445483d790b868a/lib/cogbot.rb#L20-L87 |
5,230 | mose/cogbot | lib/cogbot.rb | Cogbot.Bot.stop | def stop
pid_file = File.join(CONFIG_DIR, 'cogbot.pid')
pid = File.read(pid_file).to_i if File.exist?(pid_file)
Process.kill('TERM', pid)
end | ruby | def stop
pid_file = File.join(CONFIG_DIR, 'cogbot.pid')
pid = File.read(pid_file).to_i if File.exist?(pid_file)
Process.kill('TERM', pid)
end | [
"def",
"stop",
"pid_file",
"=",
"File",
".",
"join",
"(",
"CONFIG_DIR",
",",
"'cogbot.pid'",
")",
"pid",
"=",
"File",
".",
"read",
"(",
"pid_file",
")",
".",
"to_i",
"if",
"File",
".",
"exist?",
"(",
"pid_file",
")",
"Process",
".",
"kill",
"(",
"'TERM'",
",",
"pid",
")",
"end"
] | manages the stop cli command | [
"manages",
"the",
"stop",
"cli",
"command"
] | 844dab70f9093aba13dd50a8e445483d790b868a | https://github.com/mose/cogbot/blob/844dab70f9093aba13dd50a8e445483d790b868a/lib/cogbot.rb#L91-L95 |
5,231 | ManageIQ/polisher | lib/polisher/mixins/versioned_dependencies.rb | Polisher.VersionedDependencies.dependency_versions | def dependency_versions(args = {}, &bl)
versions = {}
args = {:recursive => true, :dev_deps => true, :versions => versions}.merge(args)
deps.each do |dep|
gem = Polisher::Gem.retrieve(dep.name)
versions.merge!(gem.versions(args, &bl))
end
versions
end | ruby | def dependency_versions(args = {}, &bl)
versions = {}
args = {:recursive => true, :dev_deps => true, :versions => versions}.merge(args)
deps.each do |dep|
gem = Polisher::Gem.retrieve(dep.name)
versions.merge!(gem.versions(args, &bl))
end
versions
end | [
"def",
"dependency_versions",
"(",
"args",
"=",
"{",
"}",
",",
"&",
"bl",
")",
"versions",
"=",
"{",
"}",
"args",
"=",
"{",
":recursive",
"=>",
"true",
",",
":dev_deps",
"=>",
"true",
",",
":versions",
"=>",
"versions",
"}",
".",
"merge",
"(",
"args",
")",
"deps",
".",
"each",
"do",
"|",
"dep",
"|",
"gem",
"=",
"Polisher",
"::",
"Gem",
".",
"retrieve",
"(",
"dep",
".",
"name",
")",
"versions",
".",
"merge!",
"(",
"gem",
".",
"versions",
"(",
"args",
",",
"bl",
")",
")",
"end",
"versions",
"end"
] | Return list of versions of dependencies of component. | [
"Return",
"list",
"of",
"versions",
"of",
"dependencies",
"of",
"component",
"."
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/mixins/versioned_dependencies.rb#L23-L31 |
5,232 | ManageIQ/polisher | lib/polisher/mixins/versioned_dependencies.rb | Polisher.VersionedDependencies.dependency_tree | def dependency_tree(args = {}, &bl)
dependencies = {}
args = {:recursive => true,
:dev_deps => true,
:matching => :latest,
:dependencies => dependencies}.merge(args)
process = []
deps.each do |dep|
resolved = nil
begin
resolved = Polisher::Gem.matching(dep, args[:matching])
rescue
end
yield self, dep, resolved
process << resolved unless resolved.nil?
end
process.each { |dep|
dependencies.merge!(dep.dependency_tree(args, &bl))
}
dependencies
end | ruby | def dependency_tree(args = {}, &bl)
dependencies = {}
args = {:recursive => true,
:dev_deps => true,
:matching => :latest,
:dependencies => dependencies}.merge(args)
process = []
deps.each do |dep|
resolved = nil
begin
resolved = Polisher::Gem.matching(dep, args[:matching])
rescue
end
yield self, dep, resolved
process << resolved unless resolved.nil?
end
process.each { |dep|
dependencies.merge!(dep.dependency_tree(args, &bl))
}
dependencies
end | [
"def",
"dependency_tree",
"(",
"args",
"=",
"{",
"}",
",",
"&",
"bl",
")",
"dependencies",
"=",
"{",
"}",
"args",
"=",
"{",
":recursive",
"=>",
"true",
",",
":dev_deps",
"=>",
"true",
",",
":matching",
"=>",
":latest",
",",
":dependencies",
"=>",
"dependencies",
"}",
".",
"merge",
"(",
"args",
")",
"process",
"=",
"[",
"]",
"deps",
".",
"each",
"do",
"|",
"dep",
"|",
"resolved",
"=",
"nil",
"begin",
"resolved",
"=",
"Polisher",
"::",
"Gem",
".",
"matching",
"(",
"dep",
",",
"args",
"[",
":matching",
"]",
")",
"rescue",
"end",
"yield",
"self",
",",
"dep",
",",
"resolved",
"process",
"<<",
"resolved",
"unless",
"resolved",
".",
"nil?",
"end",
"process",
".",
"each",
"{",
"|",
"dep",
"|",
"dependencies",
".",
"merge!",
"(",
"dep",
".",
"dependency_tree",
"(",
"args",
",",
"bl",
")",
")",
"}",
"dependencies",
"end"
] | Return mapping of gems to dependency versions | [
"Return",
"mapping",
"of",
"gems",
"to",
"dependency",
"versions"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/mixins/versioned_dependencies.rb#L34-L57 |
5,233 | ManageIQ/polisher | lib/polisher/mixins/versioned_dependencies.rb | Polisher.VersionedDependencies.missing_dependencies | def missing_dependencies
missing = []
dependency_versions(:recursive => false).each do |pkg, target_versions|
found = false
target_versions.each do |_target, versions|
dependency = dependency_for(pkg)
found = versions.any? { |version| dependency.match?(pkg, version) }
end
missing << pkg unless found
end
missing
end | ruby | def missing_dependencies
missing = []
dependency_versions(:recursive => false).each do |pkg, target_versions|
found = false
target_versions.each do |_target, versions|
dependency = dependency_for(pkg)
found = versions.any? { |version| dependency.match?(pkg, version) }
end
missing << pkg unless found
end
missing
end | [
"def",
"missing_dependencies",
"missing",
"=",
"[",
"]",
"dependency_versions",
"(",
":recursive",
"=>",
"false",
")",
".",
"each",
"do",
"|",
"pkg",
",",
"target_versions",
"|",
"found",
"=",
"false",
"target_versions",
".",
"each",
"do",
"|",
"_target",
",",
"versions",
"|",
"dependency",
"=",
"dependency_for",
"(",
"pkg",
")",
"found",
"=",
"versions",
".",
"any?",
"{",
"|",
"version",
"|",
"dependency",
".",
"match?",
"(",
"pkg",
",",
"version",
")",
"}",
"end",
"missing",
"<<",
"pkg",
"unless",
"found",
"end",
"missing",
"end"
] | Return missing dependencies | [
"Return",
"missing",
"dependencies"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/mixins/versioned_dependencies.rb#L60-L71 |
5,234 | ManageIQ/polisher | lib/polisher/mixins/versioned_dependencies.rb | Polisher.VersionedDependencies.dependency_states | def dependency_states
states = {}
deps.each do |dep|
gem = Polisher::Gem.new :name => dep.name
states.merge! dep.name => gem.state(:check => dep)
end
states
end | ruby | def dependency_states
states = {}
deps.each do |dep|
gem = Polisher::Gem.new :name => dep.name
states.merge! dep.name => gem.state(:check => dep)
end
states
end | [
"def",
"dependency_states",
"states",
"=",
"{",
"}",
"deps",
".",
"each",
"do",
"|",
"dep",
"|",
"gem",
"=",
"Polisher",
"::",
"Gem",
".",
"new",
":name",
"=>",
"dep",
".",
"name",
"states",
".",
"merge!",
"dep",
".",
"name",
"=>",
"gem",
".",
"state",
"(",
":check",
"=>",
"dep",
")",
"end",
"states",
"end"
] | Return list of states which gem dependencies are in | [
"Return",
"list",
"of",
"states",
"which",
"gem",
"dependencies",
"are",
"in"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/mixins/versioned_dependencies.rb#L79-L86 |
5,235 | cbot/push0r | lib/push0r/Queue.rb | Push0r.Queue.add | def add(message)
@services.each do |service|
if service.can_send?(message)
if @queued_messages[service].nil?
@queued_messages[service] = []
end
@queued_messages[service] << message
return true
end
end
return false
end | ruby | def add(message)
@services.each do |service|
if service.can_send?(message)
if @queued_messages[service].nil?
@queued_messages[service] = []
end
@queued_messages[service] << message
return true
end
end
return false
end | [
"def",
"add",
"(",
"message",
")",
"@services",
".",
"each",
"do",
"|",
"service",
"|",
"if",
"service",
".",
"can_send?",
"(",
"message",
")",
"if",
"@queued_messages",
"[",
"service",
"]",
".",
"nil?",
"@queued_messages",
"[",
"service",
"]",
"=",
"[",
"]",
"end",
"@queued_messages",
"[",
"service",
"]",
"<<",
"message",
"return",
"true",
"end",
"end",
"return",
"false",
"end"
] | Adds a PushMessage to the queue
@param message [PushMessage] the message to be added to the queue
@return [Boolean] true if message was added to the queue (that is: if any of the registered services can handle the message), otherwise false
@see PushMessage | [
"Adds",
"a",
"PushMessage",
"to",
"the",
"queue"
] | 07eb7bece1f251608529dea0d7a93af1444ffeb6 | https://github.com/cbot/push0r/blob/07eb7bece1f251608529dea0d7a93af1444ffeb6/lib/push0r/Queue.rb#L44-L55 |
5,236 | cbot/push0r | lib/push0r/Queue.rb | Push0r.Queue.flush | def flush
failed_messages = []
new_token_messages = []
@queued_messages.each do |service, messages|
service.init_push
messages.each do |message|
service.send(message)
end
(failed, new_token) = service.end_push
failed_messages += failed
new_token_messages += new_token
end
@queued_messages = {}
return FlushResult.new(failed_messages, new_token_messages)
end | ruby | def flush
failed_messages = []
new_token_messages = []
@queued_messages.each do |service, messages|
service.init_push
messages.each do |message|
service.send(message)
end
(failed, new_token) = service.end_push
failed_messages += failed
new_token_messages += new_token
end
@queued_messages = {}
return FlushResult.new(failed_messages, new_token_messages)
end | [
"def",
"flush",
"failed_messages",
"=",
"[",
"]",
"new_token_messages",
"=",
"[",
"]",
"@queued_messages",
".",
"each",
"do",
"|",
"service",
",",
"messages",
"|",
"service",
".",
"init_push",
"messages",
".",
"each",
"do",
"|",
"message",
"|",
"service",
".",
"send",
"(",
"message",
")",
"end",
"(",
"failed",
",",
"new_token",
")",
"=",
"service",
".",
"end_push",
"failed_messages",
"+=",
"failed",
"new_token_messages",
"+=",
"new_token",
"end",
"@queued_messages",
"=",
"{",
"}",
"return",
"FlushResult",
".",
"new",
"(",
"failed_messages",
",",
"new_token_messages",
")",
"end"
] | Flushes the queue by transmitting the enqueued messages using the registered services
@return [FlushResult] the result of the operation | [
"Flushes",
"the",
"queue",
"by",
"transmitting",
"the",
"enqueued",
"messages",
"using",
"the",
"registered",
"services"
] | 07eb7bece1f251608529dea0d7a93af1444ffeb6 | https://github.com/cbot/push0r/blob/07eb7bece1f251608529dea0d7a93af1444ffeb6/lib/push0r/Queue.rb#L59-L74 |
5,237 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.normalize_hash | def normalize_hash(hash)
new_hash = {}
hash.each do |key,value|
new_hash[key.to_sym] = normalize(value)
end
return new_hash
end | ruby | def normalize_hash(hash)
new_hash = {}
hash.each do |key,value|
new_hash[key.to_sym] = normalize(value)
end
return new_hash
end | [
"def",
"normalize_hash",
"(",
"hash",
")",
"new_hash",
"=",
"{",
"}",
"hash",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"new_hash",
"[",
"key",
".",
"to_sym",
"]",
"=",
"normalize",
"(",
"value",
")",
"end",
"return",
"new_hash",
"end"
] | Converts all the keys of a Hash to Symbols.
@param [Hash{Object => Object}] hash
The hash to be converted.
@return [Hash{Symbol => Object}]
The normalized Hash. | [
"Converts",
"all",
"the",
"keys",
"of",
"a",
"Hash",
"to",
"Symbols",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L185-L193 |
5,238 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.normalize | def normalize(value)
case value
when Hash
normalize_hash(value)
when Array
normalize_array(value)
else
value
end
end | ruby | def normalize(value)
case value
when Hash
normalize_hash(value)
when Array
normalize_array(value)
else
value
end
end | [
"def",
"normalize",
"(",
"value",
")",
"case",
"value",
"when",
"Hash",
"normalize_hash",
"(",
"value",
")",
"when",
"Array",
"normalize_array",
"(",
"value",
")",
"else",
"value",
"end",
"end"
] | Normalizes a value.
@param [Hash, Array, Object] value
The value to normalize.
@return [Hash, Array, Object]
The normalized value.
@since 0.5.0 | [
"Normalizes",
"a",
"value",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L206-L215 |
5,239 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.parse_server | def parse_server(server)
name = nil
options = {}
case server
when Symbol, String
name = server.to_sym
when Hash
unless server.has_key?(:name)
raise(MissingOption,"the 'server' option must contain a 'name' option for which server to use",caller)
end
if server.has_key?(:name)
name = server[:name].to_sym
end
if server.has_key?(:options)
options.merge!(server[:options])
end
end
return [name, options]
end | ruby | def parse_server(server)
name = nil
options = {}
case server
when Symbol, String
name = server.to_sym
when Hash
unless server.has_key?(:name)
raise(MissingOption,"the 'server' option must contain a 'name' option for which server to use",caller)
end
if server.has_key?(:name)
name = server[:name].to_sym
end
if server.has_key?(:options)
options.merge!(server[:options])
end
end
return [name, options]
end | [
"def",
"parse_server",
"(",
"server",
")",
"name",
"=",
"nil",
"options",
"=",
"{",
"}",
"case",
"server",
"when",
"Symbol",
",",
"String",
"name",
"=",
"server",
".",
"to_sym",
"when",
"Hash",
"unless",
"server",
".",
"has_key?",
"(",
":name",
")",
"raise",
"(",
"MissingOption",
",",
"\"the 'server' option must contain a 'name' option for which server to use\"",
",",
"caller",
")",
"end",
"if",
"server",
".",
"has_key?",
"(",
":name",
")",
"name",
"=",
"server",
"[",
":name",
"]",
".",
"to_sym",
"end",
"if",
"server",
".",
"has_key?",
"(",
":options",
")",
"options",
".",
"merge!",
"(",
"server",
"[",
":options",
"]",
")",
"end",
"end",
"return",
"[",
"name",
",",
"options",
"]",
"end"
] | Parses the value for the `server` setting.
@return [Array<Symbol, Hash>]
The name of the server and additional options.
@since 0.5.0 | [
"Parses",
"the",
"value",
"for",
"the",
"server",
"setting",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L225-L247 |
5,240 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.parse_address | def parse_address(address)
case address
when Hash
Addressable::URI.new(address)
when String
Addressable::URI.parse(address)
else
raise(InvalidConfig,"invalid address: #{address.inspect}",caller)
end
end | ruby | def parse_address(address)
case address
when Hash
Addressable::URI.new(address)
when String
Addressable::URI.parse(address)
else
raise(InvalidConfig,"invalid address: #{address.inspect}",caller)
end
end | [
"def",
"parse_address",
"(",
"address",
")",
"case",
"address",
"when",
"Hash",
"Addressable",
"::",
"URI",
".",
"new",
"(",
"address",
")",
"when",
"String",
"Addressable",
"::",
"URI",
".",
"parse",
"(",
"address",
")",
"else",
"raise",
"(",
"InvalidConfig",
",",
"\"invalid address: #{address.inspect}\"",
",",
"caller",
")",
"end",
"end"
] | Parses an address.
@param [Hash, String] address
The address to parse.
@return [Addressable::URI]
The parsed address.
@since 0.5.0 | [
"Parses",
"an",
"address",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L260-L269 |
5,241 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.parse_dest | def parse_dest(dest)
case dest
when Array
dest.map { |address| parse_address(address) }
else
parse_address(dest)
end
end | ruby | def parse_dest(dest)
case dest
when Array
dest.map { |address| parse_address(address) }
else
parse_address(dest)
end
end | [
"def",
"parse_dest",
"(",
"dest",
")",
"case",
"dest",
"when",
"Array",
"dest",
".",
"map",
"{",
"|",
"address",
"|",
"parse_address",
"(",
"address",
")",
"}",
"else",
"parse_address",
"(",
"dest",
")",
"end",
"end"
] | Parses the value for the `dest` setting.
@param [Array, Hash, String] dest
The value of the `dest` setting.
@return [Array<Addressable::URI>, Addressable::URI]
The parsed `dest` value.
@since 0.5.0 | [
"Parses",
"the",
"value",
"for",
"the",
"dest",
"setting",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L282-L289 |
5,242 | postmodern/deployml | lib/deployml/configuration.rb | DeploYML.Configuration.parse_commands | def parse_commands(command)
case command
when Array
command.map { |line| line.to_s }
when String
command.enum_for(:each_line).map { |line| line.chomp }
else
raise(InvalidConfig,"commands must be an Array or a String")
end
end | ruby | def parse_commands(command)
case command
when Array
command.map { |line| line.to_s }
when String
command.enum_for(:each_line).map { |line| line.chomp }
else
raise(InvalidConfig,"commands must be an Array or a String")
end
end | [
"def",
"parse_commands",
"(",
"command",
")",
"case",
"command",
"when",
"Array",
"command",
".",
"map",
"{",
"|",
"line",
"|",
"line",
".",
"to_s",
"}",
"when",
"String",
"command",
".",
"enum_for",
"(",
":each_line",
")",
".",
"map",
"{",
"|",
"line",
"|",
"line",
".",
"chomp",
"}",
"else",
"raise",
"(",
"InvalidConfig",
",",
"\"commands must be an Array or a String\"",
")",
"end",
"end"
] | Parses a command.
@param [Array, String] command
The command or commands to parse.
@return [Array<String>]
The individual commands.
@raise [InvalidConfig]
The command must be either an Array of a String.
@since 0.5.0 | [
"Parses",
"a",
"command",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/configuration.rb#L305-L314 |
5,243 | brianmichel/BadFruit | lib/badfruit/Movies/movie.rb | BadFruit.Movie.reviews | def reviews
data = JSON.parse(@badfruit.get_movie_info(@id, "reviews"))
reviews = Array.new
data["reviews"].each do |review|
reviews.push(Review.new(review))
end
return reviews
end | ruby | def reviews
data = JSON.parse(@badfruit.get_movie_info(@id, "reviews"))
reviews = Array.new
data["reviews"].each do |review|
reviews.push(Review.new(review))
end
return reviews
end | [
"def",
"reviews",
"data",
"=",
"JSON",
".",
"parse",
"(",
"@badfruit",
".",
"get_movie_info",
"(",
"@id",
",",
"\"reviews\"",
")",
")",
"reviews",
"=",
"Array",
".",
"new",
"data",
"[",
"\"reviews\"",
"]",
".",
"each",
"do",
"|",
"review",
"|",
"reviews",
".",
"push",
"(",
"Review",
".",
"new",
"(",
"review",
")",
")",
"end",
"return",
"reviews",
"end"
] | Get all of the reivews for a movie.
@return [Array<BadFruit::Review>] A list of review for the movie. | [
"Get",
"all",
"of",
"the",
"reivews",
"for",
"a",
"movie",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/Movies/movie.rb#L97-L104 |
5,244 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.units | def units
@units ||= {}.tap do |u|
UNIT_TYPES.each do |type|
k = type.to_s.pluralize.to_sym
u[k] = []
next unless manifest
next if manifest[k].nil?
manifest[k].each { |v| u[k] << create_unit(type, attributes: v) }
end
end
end | ruby | def units
@units ||= {}.tap do |u|
UNIT_TYPES.each do |type|
k = type.to_s.pluralize.to_sym
u[k] = []
next unless manifest
next if manifest[k].nil?
manifest[k].each { |v| u[k] << create_unit(type, attributes: v) }
end
end
end | [
"def",
"units",
"@units",
"||=",
"{",
"}",
".",
"tap",
"do",
"|",
"u",
"|",
"UNIT_TYPES",
".",
"each",
"do",
"|",
"type",
"|",
"k",
"=",
"type",
".",
"to_s",
".",
"pluralize",
".",
"to_sym",
"u",
"[",
"k",
"]",
"=",
"[",
"]",
"next",
"unless",
"manifest",
"next",
"if",
"manifest",
"[",
"k",
"]",
".",
"nil?",
"manifest",
"[",
"k",
"]",
".",
"each",
"{",
"|",
"v",
"|",
"u",
"[",
"k",
"]",
"<<",
"create_unit",
"(",
"type",
",",
"attributes",
":",
"v",
")",
"}",
"end",
"end",
"end"
] | Unit objects defined by the manifest and organized by type.
@return [Hash] keys are pluralized unit types from {UNIT_TYPES} | [
"Unit",
"objects",
"defined",
"by",
"the",
"manifest",
"and",
"organized",
"by",
"type",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L49-L61 |
5,245 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.install | def install
return false unless install? quiet: !(logger.level == Logger::DEBUG)
UNIT_TYPES.each do |type|
units[type.to_s.pluralize.to_sym].each do |unit|
return nil unless install_unit(unit, type)
end
end
true
end | ruby | def install
return false unless install? quiet: !(logger.level == Logger::DEBUG)
UNIT_TYPES.each do |type|
units[type.to_s.pluralize.to_sym].each do |unit|
return nil unless install_unit(unit, type)
end
end
true
end | [
"def",
"install",
"return",
"false",
"unless",
"install?",
"quiet",
":",
"!",
"(",
"logger",
".",
"level",
"==",
"Logger",
"::",
"DEBUG",
")",
"UNIT_TYPES",
".",
"each",
"do",
"|",
"type",
"|",
"units",
"[",
"type",
".",
"to_s",
".",
"pluralize",
".",
"to_sym",
"]",
".",
"each",
"do",
"|",
"unit",
"|",
"return",
"nil",
"unless",
"install_unit",
"(",
"unit",
",",
"type",
")",
"end",
"end",
"true",
"end"
] | Installs all units from the manifest.
@return [Boolean, nil] if units were installed or nil if fails mid-install | [
"Installs",
"all",
"units",
"from",
"the",
"manifest",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L65-L74 |
5,246 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.install? | def install?(quiet: false)
result = true
UNIT_TYPES.each do |type|
units[type.to_s.pluralize.to_sym].each do |unit|
result = install_unit?(unit, type, quiet) ? result : false
end
end
result
end | ruby | def install?(quiet: false)
result = true
UNIT_TYPES.each do |type|
units[type.to_s.pluralize.to_sym].each do |unit|
result = install_unit?(unit, type, quiet) ? result : false
end
end
result
end | [
"def",
"install?",
"(",
"quiet",
":",
"false",
")",
"result",
"=",
"true",
"UNIT_TYPES",
".",
"each",
"do",
"|",
"type",
"|",
"units",
"[",
"type",
".",
"to_s",
".",
"pluralize",
".",
"to_sym",
"]",
".",
"each",
"do",
"|",
"unit",
"|",
"result",
"=",
"install_unit?",
"(",
"unit",
",",
"type",
",",
"quiet",
")",
"?",
"result",
":",
"false",
"end",
"end",
"result",
"end"
] | Checks all units in the manifest for any detectable install issues.
@param quiet [Boolean] suppress some {#logger} output
@return [Boolean] if units can be installed | [
"Checks",
"all",
"units",
"in",
"the",
"manifest",
"for",
"any",
"detectable",
"install",
"issues",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L79-L87 |
5,247 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.create_unit | def create_unit(type, attributes: {})
"#{self.class.name.split('::').first}::#{type.to_s.camelize}".constantize
.new(options: unit_options, logger: logger).tap do |unit|
{src: :source, dst: :destination}.each do |k, v|
unit.send "#{v}=".to_sym, attributes[k] unless attributes[k].nil?
end
UNIT_ATTRIBUTES[type].each do |v|
unit.send "#{v}=".to_sym, defaults[v] unless defaults[v].nil?
unit.send "#{v}=".to_sym, attributes[v] unless attributes[v].nil?
end
end
end | ruby | def create_unit(type, attributes: {})
"#{self.class.name.split('::').first}::#{type.to_s.camelize}".constantize
.new(options: unit_options, logger: logger).tap do |unit|
{src: :source, dst: :destination}.each do |k, v|
unit.send "#{v}=".to_sym, attributes[k] unless attributes[k].nil?
end
UNIT_ATTRIBUTES[type].each do |v|
unit.send "#{v}=".to_sym, defaults[v] unless defaults[v].nil?
unit.send "#{v}=".to_sym, attributes[v] unless attributes[v].nil?
end
end
end | [
"def",
"create_unit",
"(",
"type",
",",
"attributes",
":",
"{",
"}",
")",
"\"#{self.class.name.split('::').first}::#{type.to_s.camelize}\"",
".",
"constantize",
".",
"new",
"(",
"options",
":",
"unit_options",
",",
"logger",
":",
"logger",
")",
".",
"tap",
"do",
"|",
"unit",
"|",
"{",
"src",
":",
":source",
",",
"dst",
":",
":destination",
"}",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"unit",
".",
"send",
"\"#{v}=\"",
".",
"to_sym",
",",
"attributes",
"[",
"k",
"]",
"unless",
"attributes",
"[",
"k",
"]",
".",
"nil?",
"end",
"UNIT_ATTRIBUTES",
"[",
"type",
"]",
".",
"each",
"do",
"|",
"v",
"|",
"unit",
".",
"send",
"\"#{v}=\"",
".",
"to_sym",
",",
"defaults",
"[",
"v",
"]",
"unless",
"defaults",
"[",
"v",
"]",
".",
"nil?",
"unit",
".",
"send",
"\"#{v}=\"",
".",
"to_sym",
",",
"attributes",
"[",
"v",
"]",
"unless",
"attributes",
"[",
"v",
"]",
".",
"nil?",
"end",
"end",
"end"
] | Creates a new unit object for the collection.
@param type [Symbol] a unit type in {UNIT_TYPES}
@param attributes [Hash] attributes for the unit from {UNIT_ATTRIBUTES}
@return [Unit] the unit object of the appropriate subclass | [
"Creates",
"a",
"new",
"unit",
"object",
"for",
"the",
"collection",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L93-L105 |
5,248 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.unit_options | def unit_options
options = {}
return options unless manifest
%i(root package_tool).each do |k|
options[k] = manifest[k] unless manifest[k].nil?
end
options
end | ruby | def unit_options
options = {}
return options unless manifest
%i(root package_tool).each do |k|
options[k] = manifest[k] unless manifest[k].nil?
end
options
end | [
"def",
"unit_options",
"options",
"=",
"{",
"}",
"return",
"options",
"unless",
"manifest",
"%i(",
"root",
"package_tool",
")",
".",
"each",
"do",
"|",
"k",
"|",
"options",
"[",
"k",
"]",
"=",
"manifest",
"[",
"k",
"]",
"unless",
"manifest",
"[",
"k",
"]",
".",
"nil?",
"end",
"options",
"end"
] | Load basic unit options from the manifest.
@return [Hash] the options | [
"Load",
"basic",
"unit",
"options",
"from",
"the",
"manifest",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L125-L132 |
5,249 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.install_unit | def install_unit(unit, type, quiet = false)
success = unit.install
logger.info do
"Installed #{type_name(type)}: #{unit.source} => #{unit.destination_path}"
end unless quiet || !success
return true
rescue Unit::InstallFailed => e
logger.fatal { "Halting install! Install attempt failed for #{type_name(type)}: #{e}" }
return false
end | ruby | def install_unit(unit, type, quiet = false)
success = unit.install
logger.info do
"Installed #{type_name(type)}: #{unit.source} => #{unit.destination_path}"
end unless quiet || !success
return true
rescue Unit::InstallFailed => e
logger.fatal { "Halting install! Install attempt failed for #{type_name(type)}: #{e}" }
return false
end | [
"def",
"install_unit",
"(",
"unit",
",",
"type",
",",
"quiet",
"=",
"false",
")",
"success",
"=",
"unit",
".",
"install",
"logger",
".",
"info",
"do",
"\"Installed #{type_name(type)}: #{unit.source} => #{unit.destination_path}\"",
"end",
"unless",
"quiet",
"||",
"!",
"success",
"return",
"true",
"rescue",
"Unit",
"::",
"InstallFailed",
"=>",
"e",
"logger",
".",
"fatal",
"{",
"\"Halting install! Install attempt failed for #{type_name(type)}: #{e}\"",
"}",
"return",
"false",
"end"
] | Installs a unit.
@param unit [Unit] the unit to install
@param type [Symbol] the unit type
@param quiet [Boolean] suppress some {#logger} output
@return [Boolean] if unit was installed | [
"Installs",
"a",
"unit",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L139-L149 |
5,250 | razor-x/config_curator | lib/config_curator/collection.rb | ConfigCurator.Collection.install_unit? | def install_unit?(unit, type, quiet = false)
unit.install?
logger.info do
"Testing install for #{type_name(type)}:" \
" #{unit.source} => #{unit.destination_path}"
end unless quiet
return true
rescue Unit::InstallFailed => e
logger.error { "Cannot install #{type_name(type)}: #{e}" }
return false
end | ruby | def install_unit?(unit, type, quiet = false)
unit.install?
logger.info do
"Testing install for #{type_name(type)}:" \
" #{unit.source} => #{unit.destination_path}"
end unless quiet
return true
rescue Unit::InstallFailed => e
logger.error { "Cannot install #{type_name(type)}: #{e}" }
return false
end | [
"def",
"install_unit?",
"(",
"unit",
",",
"type",
",",
"quiet",
"=",
"false",
")",
"unit",
".",
"install?",
"logger",
".",
"info",
"do",
"\"Testing install for #{type_name(type)}:\"",
"\" #{unit.source} => #{unit.destination_path}\"",
"end",
"unless",
"quiet",
"return",
"true",
"rescue",
"Unit",
"::",
"InstallFailed",
"=>",
"e",
"logger",
".",
"error",
"{",
"\"Cannot install #{type_name(type)}: #{e}\"",
"}",
"return",
"false",
"end"
] | Checks if a unit can be installed.
@param unit [Unit] the unit to check
@param type [Symbol] the unit type
@param quiet [Boolean] suppress some {#logger} output
@return [Boolean] if unit can be installed | [
"Checks",
"if",
"a",
"unit",
"can",
"be",
"installed",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/collection.rb#L156-L167 |
5,251 | webzakimbo/bcome-kontrol | lib/objects/registry/command/shortcut.rb | Bcome::Registry::Command.Shortcut.execute | def execute(node, arguments) ## We'll add in arguments later
if run_as_pseudo_tty?
node.pseudo_tty command
else
node.run command
end
rescue Interrupt
puts "\nExiting gracefully from interrupt\n".warning
end | ruby | def execute(node, arguments) ## We'll add in arguments later
if run_as_pseudo_tty?
node.pseudo_tty command
else
node.run command
end
rescue Interrupt
puts "\nExiting gracefully from interrupt\n".warning
end | [
"def",
"execute",
"(",
"node",
",",
"arguments",
")",
"## We'll add in arguments later",
"if",
"run_as_pseudo_tty?",
"node",
".",
"pseudo_tty",
"command",
"else",
"node",
".",
"run",
"command",
"end",
"rescue",
"Interrupt",
"puts",
"\"\\nExiting gracefully from interrupt\\n\"",
".",
"warning",
"end"
] | In which the bcome context is a shortcut to a more complex command | [
"In",
"which",
"the",
"bcome",
"context",
"is",
"a",
"shortcut",
"to",
"a",
"more",
"complex",
"command"
] | 59129cc7c8bb6c39e457abed783aa23c1d60cd05 | https://github.com/webzakimbo/bcome-kontrol/blob/59129cc7c8bb6c39e457abed783aa23c1d60cd05/lib/objects/registry/command/shortcut.rb#L5-L13 |
5,252 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.process_options | def process_options options
options = options.clone
[:left, :right].each do |key|
if options.key?(key) && !(options[key].nil?)
options[key] = File.expand_path options[key]
end
end
options
end | ruby | def process_options options
options = options.clone
[:left, :right].each do |key|
if options.key?(key) && !(options[key].nil?)
options[key] = File.expand_path options[key]
end
end
options
end | [
"def",
"process_options",
"options",
"options",
"=",
"options",
".",
"clone",
"[",
":left",
",",
":right",
"]",
".",
"each",
"do",
"|",
"key",
"|",
"if",
"options",
".",
"key?",
"(",
"key",
")",
"&&",
"!",
"(",
"options",
"[",
"key",
"]",
".",
"nil?",
")",
"options",
"[",
"key",
"]",
"=",
"File",
".",
"expand_path",
"options",
"[",
"key",
"]",
"end",
"end",
"options",
"end"
] | Creates a new Controller
@return [Controller] the Controller
initialize
Cleanup and validity checking of global options | [
"Creates",
"a",
"new",
"Controller"
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L26-L34 |
5,253 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.run | def run
if @options[:list_assemblers]
puts @assemblerman.list_assemblers
return
elsif @options[:install_assemblers]
@assemblerman.install_assemblers(@options[:install_assemblers])
return
end
if (@options[:left].nil? || @options[:right].nil?)
logger.error "Reads must be provided with --left and --right"
logger.error "Try --help for command-line help"
exit(1)
end
unless (@options[:timelimit].nil?)
logger.info "Time limit set to #{@options[:timelimit]}"
end
subsample_input
res = @assemblerman.run_all_assemblers @options
write_metadata res
merge_assemblies res
end | ruby | def run
if @options[:list_assemblers]
puts @assemblerman.list_assemblers
return
elsif @options[:install_assemblers]
@assemblerman.install_assemblers(@options[:install_assemblers])
return
end
if (@options[:left].nil? || @options[:right].nil?)
logger.error "Reads must be provided with --left and --right"
logger.error "Try --help for command-line help"
exit(1)
end
unless (@options[:timelimit].nil?)
logger.info "Time limit set to #{@options[:timelimit]}"
end
subsample_input
res = @assemblerman.run_all_assemblers @options
write_metadata res
merge_assemblies res
end | [
"def",
"run",
"if",
"@options",
"[",
":list_assemblers",
"]",
"puts",
"@assemblerman",
".",
"list_assemblers",
"return",
"elsif",
"@options",
"[",
":install_assemblers",
"]",
"@assemblerman",
".",
"install_assemblers",
"(",
"@options",
"[",
":install_assemblers",
"]",
")",
"return",
"end",
"if",
"(",
"@options",
"[",
":left",
"]",
".",
"nil?",
"||",
"@options",
"[",
":right",
"]",
".",
"nil?",
")",
"logger",
".",
"error",
"\"Reads must be provided with --left and --right\"",
"logger",
".",
"error",
"\"Try --help for command-line help\"",
"exit",
"(",
"1",
")",
"end",
"unless",
"(",
"@options",
"[",
":timelimit",
"]",
".",
"nil?",
")",
"logger",
".",
"info",
"\"Time limit set to #{@options[:timelimit]}\"",
"end",
"subsample_input",
"res",
"=",
"@assemblerman",
".",
"run_all_assemblers",
"@options",
"write_metadata",
"res",
"merge_assemblies",
"res",
"end"
] | Runs the program | [
"Runs",
"the",
"program"
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L37-L62 |
5,254 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.init_settings | def init_settings
s = Biopsy::Settings.instance
s.set_defaults
libdir = File.dirname(__FILE__)
s.target_dir = [File.join(libdir, 'assemblers/')]
s.objectives_dir = [File.join(libdir, 'objectives/')]
logger.debug "initialised Biopsy settings"
end | ruby | def init_settings
s = Biopsy::Settings.instance
s.set_defaults
libdir = File.dirname(__FILE__)
s.target_dir = [File.join(libdir, 'assemblers/')]
s.objectives_dir = [File.join(libdir, 'objectives/')]
logger.debug "initialised Biopsy settings"
end | [
"def",
"init_settings",
"s",
"=",
"Biopsy",
"::",
"Settings",
".",
"instance",
"s",
".",
"set_defaults",
"libdir",
"=",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"s",
".",
"target_dir",
"=",
"[",
"File",
".",
"join",
"(",
"libdir",
",",
"'assemblers/'",
")",
"]",
"s",
".",
"objectives_dir",
"=",
"[",
"File",
".",
"join",
"(",
"libdir",
",",
"'objectives/'",
")",
"]",
"logger",
".",
"debug",
"\"initialised Biopsy settings\"",
"end"
] | Initialise the Biopsy settings with defaults,
setting target and objectiv directories to those
provided with Assemblotron | [
"Initialise",
"the",
"Biopsy",
"settings",
"with",
"defaults",
"setting",
"target",
"and",
"objectiv",
"directories",
"to",
"those",
"provided",
"with",
"Assemblotron"
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L76-L83 |
5,255 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.write_metadata | def write_metadata res
File.open(@options[:output_parameters], 'wb') do |f|
f.write(JSON.pretty_generate(res))
end
end | ruby | def write_metadata res
File.open(@options[:output_parameters], 'wb') do |f|
f.write(JSON.pretty_generate(res))
end
end | [
"def",
"write_metadata",
"res",
"File",
".",
"open",
"(",
"@options",
"[",
":output_parameters",
"]",
",",
"'wb'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"JSON",
".",
"pretty_generate",
"(",
"res",
")",
")",
"end",
"end"
] | Write out metadata from the optimisation run | [
"Write",
"out",
"metadata",
"from",
"the",
"optimisation",
"run"
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L86-L90 |
5,256 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.subsample_input | def subsample_input
if @options[:skip_subsample]
logger.info "Skipping subsample step (--skip-subsample is on)"
@options[:left_subset] = @options[:left]
@options[:right_subset] = @options[:right]
return
end
logger.info "Subsampling reads"
seed = @options[:seed]
seed = Time.now.to_i if seed == -1
logger.info "Using random seed #{seed}"
l = @options[:left]
r = @options[:right]
size = @options[:subsample_size]
sampler = Sampler.new
if @options[:sampler] == "stream"
ls, rs = sampler.sample_stream(l, r, size, seed)
elsif @options[:sampler] == "graph"
ls, rs = sampler.sample_graph(l, r, size, seed)
else
logger.error "sampler #{@options[:sampler]} was not a valid choice"
logger.error "please user --help to see the options"
exit 1
end
@options[:left_subset] = ls
@options[:right_subset] = rs
end | ruby | def subsample_input
if @options[:skip_subsample]
logger.info "Skipping subsample step (--skip-subsample is on)"
@options[:left_subset] = @options[:left]
@options[:right_subset] = @options[:right]
return
end
logger.info "Subsampling reads"
seed = @options[:seed]
seed = Time.now.to_i if seed == -1
logger.info "Using random seed #{seed}"
l = @options[:left]
r = @options[:right]
size = @options[:subsample_size]
sampler = Sampler.new
if @options[:sampler] == "stream"
ls, rs = sampler.sample_stream(l, r, size, seed)
elsif @options[:sampler] == "graph"
ls, rs = sampler.sample_graph(l, r, size, seed)
else
logger.error "sampler #{@options[:sampler]} was not a valid choice"
logger.error "please user --help to see the options"
exit 1
end
@options[:left_subset] = ls
@options[:right_subset] = rs
end | [
"def",
"subsample_input",
"if",
"@options",
"[",
":skip_subsample",
"]",
"logger",
".",
"info",
"\"Skipping subsample step (--skip-subsample is on)\"",
"@options",
"[",
":left_subset",
"]",
"=",
"@options",
"[",
":left",
"]",
"@options",
"[",
":right_subset",
"]",
"=",
"@options",
"[",
":right",
"]",
"return",
"end",
"logger",
".",
"info",
"\"Subsampling reads\"",
"seed",
"=",
"@options",
"[",
":seed",
"]",
"seed",
"=",
"Time",
".",
"now",
".",
"to_i",
"if",
"seed",
"==",
"-",
"1",
"logger",
".",
"info",
"\"Using random seed #{seed}\"",
"l",
"=",
"@options",
"[",
":left",
"]",
"r",
"=",
"@options",
"[",
":right",
"]",
"size",
"=",
"@options",
"[",
":subsample_size",
"]",
"sampler",
"=",
"Sampler",
".",
"new",
"if",
"@options",
"[",
":sampler",
"]",
"==",
"\"stream\"",
"ls",
",",
"rs",
"=",
"sampler",
".",
"sample_stream",
"(",
"l",
",",
"r",
",",
"size",
",",
"seed",
")",
"elsif",
"@options",
"[",
":sampler",
"]",
"==",
"\"graph\"",
"ls",
",",
"rs",
"=",
"sampler",
".",
"sample_graph",
"(",
"l",
",",
"r",
",",
"size",
",",
"seed",
")",
"else",
"logger",
".",
"error",
"\"sampler #{@options[:sampler]} was not a valid choice\"",
"logger",
".",
"error",
"\"please user --help to see the options\"",
"exit",
"1",
"end",
"@options",
"[",
":left_subset",
"]",
"=",
"ls",
"@options",
"[",
":right_subset",
"]",
"=",
"rs",
"end"
] | Run the subsampler on the input reads, storing
the paths to the samples in the assembler_options
hash. | [
"Run",
"the",
"subsampler",
"on",
"the",
"input",
"reads",
"storing",
"the",
"paths",
"to",
"the",
"samples",
"in",
"the",
"assembler_options",
"hash",
"."
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L95-L127 |
5,257 | blahah/assemblotron | lib/assemblotron/controller.rb | Assemblotron.Controller.merge_assemblies | def merge_assemblies res
l = @options[:left]
r = @options[:right]
transfuse = Transfuse::Transfuse.new(@options[:threads], false)
assemblies = res.each_value.map { |assembler| assember[:final] }
scores = transfuse.transrate(assemblies, l, r)
filtered = transfuse.filter(assemblies, scores)
cat = transfuse.concatenate filtered
transfuse.load_fasta cat
clusters = transfuse.cluster cat
best = transfuse.select_contigs(clusters, scores)
transfuse.output_contigs(best, cat, 'merged.fa')
end | ruby | def merge_assemblies res
l = @options[:left]
r = @options[:right]
transfuse = Transfuse::Transfuse.new(@options[:threads], false)
assemblies = res.each_value.map { |assembler| assember[:final] }
scores = transfuse.transrate(assemblies, l, r)
filtered = transfuse.filter(assemblies, scores)
cat = transfuse.concatenate filtered
transfuse.load_fasta cat
clusters = transfuse.cluster cat
best = transfuse.select_contigs(clusters, scores)
transfuse.output_contigs(best, cat, 'merged.fa')
end | [
"def",
"merge_assemblies",
"res",
"l",
"=",
"@options",
"[",
":left",
"]",
"r",
"=",
"@options",
"[",
":right",
"]",
"transfuse",
"=",
"Transfuse",
"::",
"Transfuse",
".",
"new",
"(",
"@options",
"[",
":threads",
"]",
",",
"false",
")",
"assemblies",
"=",
"res",
".",
"each_value",
".",
"map",
"{",
"|",
"assembler",
"|",
"assember",
"[",
":final",
"]",
"}",
"scores",
"=",
"transfuse",
".",
"transrate",
"(",
"assemblies",
",",
"l",
",",
"r",
")",
"filtered",
"=",
"transfuse",
".",
"filter",
"(",
"assemblies",
",",
"scores",
")",
"cat",
"=",
"transfuse",
".",
"concatenate",
"filtered",
"transfuse",
".",
"load_fasta",
"cat",
"clusters",
"=",
"transfuse",
".",
"cluster",
"cat",
"best",
"=",
"transfuse",
".",
"select_contigs",
"(",
"clusters",
",",
"scores",
")",
"transfuse",
".",
"output_contigs",
"(",
"best",
",",
"cat",
",",
"'merged.fa'",
")",
"end"
] | Merge the final assemblies | [
"Merge",
"the",
"final",
"assemblies"
] | 475d59c72ba36ebb2799076a0009758d12fa1508 | https://github.com/blahah/assemblotron/blob/475d59c72ba36ebb2799076a0009758d12fa1508/lib/assemblotron/controller.rb#L130-L145 |
5,258 | blahah/biopsy | lib/biopsy/settings.rb | Biopsy.Settings.all_settings | def all_settings
settings = {}
instance_variables.each do |var|
key = var[1..-1]
settings[key] = self.instance_variable_get(var)
end
settings
end | ruby | def all_settings
settings = {}
instance_variables.each do |var|
key = var[1..-1]
settings[key] = self.instance_variable_get(var)
end
settings
end | [
"def",
"all_settings",
"settings",
"=",
"{",
"}",
"instance_variables",
".",
"each",
"do",
"|",
"var",
"|",
"key",
"=",
"var",
"[",
"1",
"..",
"-",
"1",
"]",
"settings",
"[",
"key",
"]",
"=",
"self",
".",
"instance_variable_get",
"(",
"var",
")",
"end",
"settings",
"end"
] | Returns a hash of the settings | [
"Returns",
"a",
"hash",
"of",
"the",
"settings"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/settings.rb#L79-L86 |
5,259 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/enhanced.rb | Gosu.Window.draw_rectangle | def draw_rectangle(point, size, z_index, colour)
left = point.x
top = point.y
width = size.width
height = size.height
draw_quad(
left, top, colour,
left + width, top, colour,
left + width, top + height, colour,
left, top + height, colour,
z_index)
end | ruby | def draw_rectangle(point, size, z_index, colour)
left = point.x
top = point.y
width = size.width
height = size.height
draw_quad(
left, top, colour,
left + width, top, colour,
left + width, top + height, colour,
left, top + height, colour,
z_index)
end | [
"def",
"draw_rectangle",
"(",
"point",
",",
"size",
",",
"z_index",
",",
"colour",
")",
"left",
"=",
"point",
".",
"x",
"top",
"=",
"point",
".",
"y",
"width",
"=",
"size",
".",
"width",
"height",
"=",
"size",
".",
"height",
"draw_quad",
"(",
"left",
",",
"top",
",",
"colour",
",",
"left",
"+",
"width",
",",
"top",
",",
"colour",
",",
"left",
"+",
"width",
",",
"top",
"+",
"height",
",",
"colour",
",",
"left",
",",
"top",
"+",
"height",
",",
"colour",
",",
"z_index",
")",
"end"
] | Simplify drawing a rectangle in a single colour.
* +point+ [Point] Top left corner
* +size+ [Size] Width and Height
* +z_index+ [Fixnum] Z-order
* +colour+ [Gosu::Color] Colour of rectangle | [
"Simplify",
"drawing",
"a",
"rectangle",
"in",
"a",
"single",
"colour",
"."
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/enhanced.rb#L14-L26 |
5,260 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/enhanced.rb | Gosu.Window.draw_simple_line | def draw_simple_line(p1, p2, z_index, colour)
draw_line(p1.x, p1.y, colour, p2.x, p2.y, colour, z_index)
end | ruby | def draw_simple_line(p1, p2, z_index, colour)
draw_line(p1.x, p1.y, colour, p2.x, p2.y, colour, z_index)
end | [
"def",
"draw_simple_line",
"(",
"p1",
",",
"p2",
",",
"z_index",
",",
"colour",
")",
"draw_line",
"(",
"p1",
".",
"x",
",",
"p1",
".",
"y",
",",
"colour",
",",
"p2",
".",
"x",
",",
"p2",
".",
"y",
",",
"colour",
",",
"z_index",
")",
"end"
] | Simplify drawing a line.
There are dire warnings in the Gosu documentation for draw_line() which
suggest that line drawing should only be done for debugging purposes.
* +p1+ [Point] Beginning point
* +p2+ [Point] Endpoint
* +z_index+ [Fixnum] Z-order
* +colour+ [Gosu::Color] Colour of line | [
"Simplify",
"drawing",
"a",
"line",
"."
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/enhanced.rb#L38-L40 |
5,261 | JulianNicholls/gosu_enhanced-gem | lib/gosu_enhanced/enhanced.rb | Gosu.Font.centred_in | def centred_in(text, rect)
size = measure(text)
Point((rect.width - size.width) / 2, (rect.height - size.height) / 2)
end | ruby | def centred_in(text, rect)
size = measure(text)
Point((rect.width - size.width) / 2, (rect.height - size.height) / 2)
end | [
"def",
"centred_in",
"(",
"text",
",",
"rect",
")",
"size",
"=",
"measure",
"(",
"text",
")",
"Point",
"(",
"(",
"rect",
".",
"width",
"-",
"size",
".",
"width",
")",
"/",
"2",
",",
"(",
"rect",
".",
"height",
"-",
"size",
".",
"height",
")",
"/",
"2",
")",
"end"
] | Return the co-ordnates needed to place a given string in the centre of an
area, both vertically and horizontally.
* +text+ [String] String to centre
* +rect+ [Size] Rectangular area size
return:: [Point] The point to write the string, expressed as an offset
from the top-left corner of the rectangle. | [
"Return",
"the",
"co",
"-",
"ordnates",
"needed",
"to",
"place",
"a",
"given",
"string",
"in",
"the",
"centre",
"of",
"an",
"area",
"both",
"vertically",
"and",
"horizontally",
"."
] | 07b5258458c4c3c315f697c8d5da839a93eb2c67 | https://github.com/JulianNicholls/gosu_enhanced-gem/blob/07b5258458c4c3c315f697c8d5da839a93eb2c67/lib/gosu_enhanced/enhanced.rb#L67-L71 |
5,262 | kwi/BrB | lib/brb/request.rb | BrB.Request.new_brb_out_request | def new_brb_out_request(meth, *args, &blck)
Thread.current[:brb_nb_out] ||= 0
Thread.current[:brb_nb_out] += 1
raise BrBCallbackWithBlockingMethodException.new if is_brb_request_blocking?(meth) and block_given?
block = (is_brb_request_blocking?(meth) or block_given?) ? Thread.current.to_s.to_sym : nil
if block
args << block
args << Thread.current[:brb_nb_out]
end
if block_given?
# Simulate a method with _block in order to make BrB send the answer
meth = "#{meth}_block".to_sym
end
args.size > 0 ? brb_send([MessageRequestCode, meth, args]) : brb_send([MessageRequestCode, meth])
if block_given?
# Declare the callback
declare_callback(block, Thread.current[:brb_nb_out], &blck)
elsif block # Block until the request return
#TimeMonitor.instance.watch_thread!(@timeout_rcv_value || 45)
begin
r = recv(block, Thread.current[:brb_nb_out], &blck)
rescue Exception => e
raise e
ensure
#TimeMonitor.instance.remove_thread!
end
if r.kind_of? Exception
raise r
end
return r
end
nil
end | ruby | def new_brb_out_request(meth, *args, &blck)
Thread.current[:brb_nb_out] ||= 0
Thread.current[:brb_nb_out] += 1
raise BrBCallbackWithBlockingMethodException.new if is_brb_request_blocking?(meth) and block_given?
block = (is_brb_request_blocking?(meth) or block_given?) ? Thread.current.to_s.to_sym : nil
if block
args << block
args << Thread.current[:brb_nb_out]
end
if block_given?
# Simulate a method with _block in order to make BrB send the answer
meth = "#{meth}_block".to_sym
end
args.size > 0 ? brb_send([MessageRequestCode, meth, args]) : brb_send([MessageRequestCode, meth])
if block_given?
# Declare the callback
declare_callback(block, Thread.current[:brb_nb_out], &blck)
elsif block # Block until the request return
#TimeMonitor.instance.watch_thread!(@timeout_rcv_value || 45)
begin
r = recv(block, Thread.current[:brb_nb_out], &blck)
rescue Exception => e
raise e
ensure
#TimeMonitor.instance.remove_thread!
end
if r.kind_of? Exception
raise r
end
return r
end
nil
end | [
"def",
"new_brb_out_request",
"(",
"meth",
",",
"*",
"args",
",",
"&",
"blck",
")",
"Thread",
".",
"current",
"[",
":brb_nb_out",
"]",
"||=",
"0",
"Thread",
".",
"current",
"[",
":brb_nb_out",
"]",
"+=",
"1",
"raise",
"BrBCallbackWithBlockingMethodException",
".",
"new",
"if",
"is_brb_request_blocking?",
"(",
"meth",
")",
"and",
"block_given?",
"block",
"=",
"(",
"is_brb_request_blocking?",
"(",
"meth",
")",
"or",
"block_given?",
")",
"?",
"Thread",
".",
"current",
".",
"to_s",
".",
"to_sym",
":",
"nil",
"if",
"block",
"args",
"<<",
"block",
"args",
"<<",
"Thread",
".",
"current",
"[",
":brb_nb_out",
"]",
"end",
"if",
"block_given?",
"# Simulate a method with _block in order to make BrB send the answer\r",
"meth",
"=",
"\"#{meth}_block\"",
".",
"to_sym",
"end",
"args",
".",
"size",
">",
"0",
"?",
"brb_send",
"(",
"[",
"MessageRequestCode",
",",
"meth",
",",
"args",
"]",
")",
":",
"brb_send",
"(",
"[",
"MessageRequestCode",
",",
"meth",
"]",
")",
"if",
"block_given?",
"# Declare the callback\r",
"declare_callback",
"(",
"block",
",",
"Thread",
".",
"current",
"[",
":brb_nb_out",
"]",
",",
"blck",
")",
"elsif",
"block",
"# Block until the request return\r",
"#TimeMonitor.instance.watch_thread!(@timeout_rcv_value || 45)\r",
"begin",
"r",
"=",
"recv",
"(",
"block",
",",
"Thread",
".",
"current",
"[",
":brb_nb_out",
"]",
",",
"blck",
")",
"rescue",
"Exception",
"=>",
"e",
"raise",
"e",
"ensure",
"#TimeMonitor.instance.remove_thread!\r",
"end",
"if",
"r",
".",
"kind_of?",
"Exception",
"raise",
"r",
"end",
"return",
"r",
"end",
"nil",
"end"
] | Execute a request on a distant object | [
"Execute",
"a",
"request",
"on",
"a",
"distant",
"object"
] | 1ae0c82fc44759627f2145fd9e02092b37e19d69 | https://github.com/kwi/BrB/blob/1ae0c82fc44759627f2145fd9e02092b37e19d69/lib/brb/request.rb#L16-L56 |
5,263 | kwi/BrB | lib/brb/request.rb | BrB.Request.new_brb_in_request | def new_brb_in_request(meth, *args)
if is_brb_request_blocking?(meth)
m = meth.to_s
m = m[0, m.size - 6].to_sym
idrequest = args.pop
thread = args.pop
begin
r = ((args.size > 0) ? @object.send(m, *args) : @object.send(m))
brb_send([ReturnCode, r, thread, idrequest])
rescue Exception => e
brb_send([ReturnCode, e, thread, idrequest])
BrB.logger.error e.to_s
BrB.logger.error e.backtrace.join("\n")
#raise e
end
else
begin
(args.size > 0) ? @object.send(meth, *args) : @object.send(meth)
rescue Exception => e
BrB.logger.error "#{e.to_s} => By calling #{meth} on #{@object.class} with args : #{args.inspect}"
BrB.logger.error e.backtrace.join("\n")
raise e
end
end
end | ruby | def new_brb_in_request(meth, *args)
if is_brb_request_blocking?(meth)
m = meth.to_s
m = m[0, m.size - 6].to_sym
idrequest = args.pop
thread = args.pop
begin
r = ((args.size > 0) ? @object.send(m, *args) : @object.send(m))
brb_send([ReturnCode, r, thread, idrequest])
rescue Exception => e
brb_send([ReturnCode, e, thread, idrequest])
BrB.logger.error e.to_s
BrB.logger.error e.backtrace.join("\n")
#raise e
end
else
begin
(args.size > 0) ? @object.send(meth, *args) : @object.send(meth)
rescue Exception => e
BrB.logger.error "#{e.to_s} => By calling #{meth} on #{@object.class} with args : #{args.inspect}"
BrB.logger.error e.backtrace.join("\n")
raise e
end
end
end | [
"def",
"new_brb_in_request",
"(",
"meth",
",",
"*",
"args",
")",
"if",
"is_brb_request_blocking?",
"(",
"meth",
")",
"m",
"=",
"meth",
".",
"to_s",
"m",
"=",
"m",
"[",
"0",
",",
"m",
".",
"size",
"-",
"6",
"]",
".",
"to_sym",
"idrequest",
"=",
"args",
".",
"pop",
"thread",
"=",
"args",
".",
"pop",
"begin",
"r",
"=",
"(",
"(",
"args",
".",
"size",
">",
"0",
")",
"?",
"@object",
".",
"send",
"(",
"m",
",",
"args",
")",
":",
"@object",
".",
"send",
"(",
"m",
")",
")",
"brb_send",
"(",
"[",
"ReturnCode",
",",
"r",
",",
"thread",
",",
"idrequest",
"]",
")",
"rescue",
"Exception",
"=>",
"e",
"brb_send",
"(",
"[",
"ReturnCode",
",",
"e",
",",
"thread",
",",
"idrequest",
"]",
")",
"BrB",
".",
"logger",
".",
"error",
"e",
".",
"to_s",
"BrB",
".",
"logger",
".",
"error",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
"#raise e\r",
"end",
"else",
"begin",
"(",
"args",
".",
"size",
">",
"0",
")",
"?",
"@object",
".",
"send",
"(",
"meth",
",",
"args",
")",
":",
"@object",
".",
"send",
"(",
"meth",
")",
"rescue",
"Exception",
"=>",
"e",
"BrB",
".",
"logger",
".",
"error",
"\"#{e.to_s} => By calling #{meth} on #{@object.class} with args : #{args.inspect}\"",
"BrB",
".",
"logger",
".",
"error",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
"raise",
"e",
"end",
"end",
"end"
] | Execute a request on the local object | [
"Execute",
"a",
"request",
"on",
"the",
"local",
"object"
] | 1ae0c82fc44759627f2145fd9e02092b37e19d69 | https://github.com/kwi/BrB/blob/1ae0c82fc44759627f2145fd9e02092b37e19d69/lib/brb/request.rb#L59-L89 |
5,264 | ManageIQ/polisher | lib/polisher/gem/diff.rb | Polisher.GemDiff.diff | def diff(other)
require_dep! 'awesome_spawn'
require_cmd! diff_cmd
out = nil
begin
this_dir = unpack
other_dir = if other.is_a?(Polisher::Gem)
other.unpack
elsif other.is_a?(Polisher::Git::Repo)
other.path
else
other
end
result = AwesomeSpawn.run("#{diff_cmd} -r #{this_dir} #{other_dir}")
out = result.output.gsub("#{this_dir}", 'a').gsub("#{other_dir}", 'b')
rescue
ensure
FileUtils.rm_rf this_dir unless this_dir.nil?
FileUtils.rm_rf other_dir unless other_dir.nil? ||
!other.is_a?(Polisher::Gem)
end
out
end | ruby | def diff(other)
require_dep! 'awesome_spawn'
require_cmd! diff_cmd
out = nil
begin
this_dir = unpack
other_dir = if other.is_a?(Polisher::Gem)
other.unpack
elsif other.is_a?(Polisher::Git::Repo)
other.path
else
other
end
result = AwesomeSpawn.run("#{diff_cmd} -r #{this_dir} #{other_dir}")
out = result.output.gsub("#{this_dir}", 'a').gsub("#{other_dir}", 'b')
rescue
ensure
FileUtils.rm_rf this_dir unless this_dir.nil?
FileUtils.rm_rf other_dir unless other_dir.nil? ||
!other.is_a?(Polisher::Gem)
end
out
end | [
"def",
"diff",
"(",
"other",
")",
"require_dep!",
"'awesome_spawn'",
"require_cmd!",
"diff_cmd",
"out",
"=",
"nil",
"begin",
"this_dir",
"=",
"unpack",
"other_dir",
"=",
"if",
"other",
".",
"is_a?",
"(",
"Polisher",
"::",
"Gem",
")",
"other",
".",
"unpack",
"elsif",
"other",
".",
"is_a?",
"(",
"Polisher",
"::",
"Git",
"::",
"Repo",
")",
"other",
".",
"path",
"else",
"other",
"end",
"result",
"=",
"AwesomeSpawn",
".",
"run",
"(",
"\"#{diff_cmd} -r #{this_dir} #{other_dir}\"",
")",
"out",
"=",
"result",
".",
"output",
".",
"gsub",
"(",
"\"#{this_dir}\"",
",",
"'a'",
")",
".",
"gsub",
"(",
"\"#{other_dir}\"",
",",
"'b'",
")",
"rescue",
"ensure",
"FileUtils",
".",
"rm_rf",
"this_dir",
"unless",
"this_dir",
".",
"nil?",
"FileUtils",
".",
"rm_rf",
"other_dir",
"unless",
"other_dir",
".",
"nil?",
"||",
"!",
"other",
".",
"is_a?",
"(",
"Polisher",
"::",
"Gem",
")",
"end",
"out",
"end"
] | Return diff of content in this gem against other | [
"Return",
"diff",
"of",
"content",
"in",
"this",
"gem",
"against",
"other"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/gem/diff.rb#L12-L37 |
5,265 | xtremelabs/xl-passbook-ruby | app/controllers/passbook/registrations_controller.rb | Passbook.RegistrationsController.push_token | def push_token
return params[:pushToken] if params.include?(:pushToken)
if request && request.body
request.body.rewind
json_body = JSON.parse(request.body.read)
if json_body['pushToken']
json_body['pushToken']
end
end
end | ruby | def push_token
return params[:pushToken] if params.include?(:pushToken)
if request && request.body
request.body.rewind
json_body = JSON.parse(request.body.read)
if json_body['pushToken']
json_body['pushToken']
end
end
end | [
"def",
"push_token",
"return",
"params",
"[",
":pushToken",
"]",
"if",
"params",
".",
"include?",
"(",
":pushToken",
")",
"if",
"request",
"&&",
"request",
".",
"body",
"request",
".",
"body",
".",
"rewind",
"json_body",
"=",
"JSON",
".",
"parse",
"(",
"request",
".",
"body",
".",
"read",
")",
"if",
"json_body",
"[",
"'pushToken'",
"]",
"json_body",
"[",
"'pushToken'",
"]",
"end",
"end",
"end"
] | Convienience method for parsing the pushToken out of a JSON POST body | [
"Convienience",
"method",
"for",
"parsing",
"the",
"pushToken",
"out",
"of",
"a",
"JSON",
"POST",
"body"
] | 01ef5f5461258287b8067a00df1f15f00133c865 | https://github.com/xtremelabs/xl-passbook-ruby/blob/01ef5f5461258287b8067a00df1f15f00133c865/app/controllers/passbook/registrations_controller.rb#L158-L167 |
5,266 | evgenyneu/siba | lib/siba/generator.rb | Siba.Generator.generate | def generate
siba_file.run_this do
file_path = @name.gsub /\.yml$/, ""
file_path += ".yml"
file_path = siba_file.file_expand_path file_path
if siba_file.file_file?(file_path) || siba_file.file_directory?(file_path)
raise Siba::Error, "Options file already exists: #{file_path}"
end
options_data = []
Siba::Plugins::PLUGINS_HASH.each do |category, types|
type = nil
if types.size > 1
max_type_length = types.keys.max do |a,b|
a.length <=> b.length
end.length + 5
siba_kernel.puts "\nChoose #{category} plugin:"
types.keys.each_index do |i|
type = types.keys[i]
siba_kernel.puts " #{i+1}. #{Siba::Plugins.plugin_type_and_description(category, type, max_type_length)}"
end
type = Siba::Generator.get_plugin_user_choice types.keys
if type.nil?
siba_kernel.puts "Cancelled by user"
return
end
unless Siba::InstalledPlugins.installed? category, type
siba_kernel.puts Siba::InstalledPlugins.install_gem_message(category, type)
return
end
else
type = types.keys.first
end
options = Siba::Generator.load_plugin_yaml_content category, type
unless options =~ /^\s*type:/
options = "type: #{type}\n" + options
end
options.gsub! /^/, " "
options = "#{category}:\n" + options
options_data << options
end
file_data = options_data.join("\n")
file_data = "# SIBA options file\n" + file_data
dest_dir = File.dirname file_path
siba_file.file_utils_mkpath(dest_dir) unless siba_file.file_directory?(dest_dir)
Siba::FileHelper.write file_path, file_data
file_path
end
end | ruby | def generate
siba_file.run_this do
file_path = @name.gsub /\.yml$/, ""
file_path += ".yml"
file_path = siba_file.file_expand_path file_path
if siba_file.file_file?(file_path) || siba_file.file_directory?(file_path)
raise Siba::Error, "Options file already exists: #{file_path}"
end
options_data = []
Siba::Plugins::PLUGINS_HASH.each do |category, types|
type = nil
if types.size > 1
max_type_length = types.keys.max do |a,b|
a.length <=> b.length
end.length + 5
siba_kernel.puts "\nChoose #{category} plugin:"
types.keys.each_index do |i|
type = types.keys[i]
siba_kernel.puts " #{i+1}. #{Siba::Plugins.plugin_type_and_description(category, type, max_type_length)}"
end
type = Siba::Generator.get_plugin_user_choice types.keys
if type.nil?
siba_kernel.puts "Cancelled by user"
return
end
unless Siba::InstalledPlugins.installed? category, type
siba_kernel.puts Siba::InstalledPlugins.install_gem_message(category, type)
return
end
else
type = types.keys.first
end
options = Siba::Generator.load_plugin_yaml_content category, type
unless options =~ /^\s*type:/
options = "type: #{type}\n" + options
end
options.gsub! /^/, " "
options = "#{category}:\n" + options
options_data << options
end
file_data = options_data.join("\n")
file_data = "# SIBA options file\n" + file_data
dest_dir = File.dirname file_path
siba_file.file_utils_mkpath(dest_dir) unless siba_file.file_directory?(dest_dir)
Siba::FileHelper.write file_path, file_data
file_path
end
end | [
"def",
"generate",
"siba_file",
".",
"run_this",
"do",
"file_path",
"=",
"@name",
".",
"gsub",
"/",
"\\.",
"/",
",",
"\"\"",
"file_path",
"+=",
"\".yml\"",
"file_path",
"=",
"siba_file",
".",
"file_expand_path",
"file_path",
"if",
"siba_file",
".",
"file_file?",
"(",
"file_path",
")",
"||",
"siba_file",
".",
"file_directory?",
"(",
"file_path",
")",
"raise",
"Siba",
"::",
"Error",
",",
"\"Options file already exists: #{file_path}\"",
"end",
"options_data",
"=",
"[",
"]",
"Siba",
"::",
"Plugins",
"::",
"PLUGINS_HASH",
".",
"each",
"do",
"|",
"category",
",",
"types",
"|",
"type",
"=",
"nil",
"if",
"types",
".",
"size",
">",
"1",
"max_type_length",
"=",
"types",
".",
"keys",
".",
"max",
"do",
"|",
"a",
",",
"b",
"|",
"a",
".",
"length",
"<=>",
"b",
".",
"length",
"end",
".",
"length",
"+",
"5",
"siba_kernel",
".",
"puts",
"\"\\nChoose #{category} plugin:\"",
"types",
".",
"keys",
".",
"each_index",
"do",
"|",
"i",
"|",
"type",
"=",
"types",
".",
"keys",
"[",
"i",
"]",
"siba_kernel",
".",
"puts",
"\" #{i+1}. #{Siba::Plugins.plugin_type_and_description(category, type, max_type_length)}\"",
"end",
"type",
"=",
"Siba",
"::",
"Generator",
".",
"get_plugin_user_choice",
"types",
".",
"keys",
"if",
"type",
".",
"nil?",
"siba_kernel",
".",
"puts",
"\"Cancelled by user\"",
"return",
"end",
"unless",
"Siba",
"::",
"InstalledPlugins",
".",
"installed?",
"category",
",",
"type",
"siba_kernel",
".",
"puts",
"Siba",
"::",
"InstalledPlugins",
".",
"install_gem_message",
"(",
"category",
",",
"type",
")",
"return",
"end",
"else",
"type",
"=",
"types",
".",
"keys",
".",
"first",
"end",
"options",
"=",
"Siba",
"::",
"Generator",
".",
"load_plugin_yaml_content",
"category",
",",
"type",
"unless",
"options",
"=~",
"/",
"\\s",
"/",
"options",
"=",
"\"type: #{type}\\n\"",
"+",
"options",
"end",
"options",
".",
"gsub!",
"/",
"/",
",",
"\" \"",
"options",
"=",
"\"#{category}:\\n\"",
"+",
"options",
"options_data",
"<<",
"options",
"end",
"file_data",
"=",
"options_data",
".",
"join",
"(",
"\"\\n\"",
")",
"file_data",
"=",
"\"# SIBA options file\\n\"",
"+",
"file_data",
"dest_dir",
"=",
"File",
".",
"dirname",
"file_path",
"siba_file",
".",
"file_utils_mkpath",
"(",
"dest_dir",
")",
"unless",
"siba_file",
".",
"file_directory?",
"(",
"dest_dir",
")",
"Siba",
"::",
"FileHelper",
".",
"write",
"file_path",
",",
"file_data",
"file_path",
"end",
"end"
] | Generates yaml options file and returns its path | [
"Generates",
"yaml",
"options",
"file",
"and",
"returns",
"its",
"path"
] | 04cd0eca8222092c14ce4a662b48f5f113ffe6df | https://github.com/evgenyneu/siba/blob/04cd0eca8222092c14ce4a662b48f5f113ffe6df/lib/siba/generator.rb#L16-L70 |
5,267 | ubcsanskrit/sanscript.rb | lib/sanscript/transliterate.rb | Sanscript.Transliterate.add_brahmic_scheme | def add_brahmic_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
@schemes[name] = IceNine.deep_freeze(scheme)
@brahmic_schemes.add(name)
@scheme_names.add(name)
scheme
end | ruby | def add_brahmic_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
@schemes[name] = IceNine.deep_freeze(scheme)
@brahmic_schemes.add(name)
@scheme_names.add(name)
scheme
end | [
"def",
"add_brahmic_scheme",
"(",
"name",
",",
"scheme",
")",
"name",
"=",
"name",
".",
"to_sym",
"scheme",
"=",
"scheme",
".",
"deep_dup",
"@schemes",
"[",
"name",
"]",
"=",
"IceNine",
".",
"deep_freeze",
"(",
"scheme",
")",
"@brahmic_schemes",
".",
"add",
"(",
"name",
")",
"@scheme_names",
".",
"add",
"(",
"name",
")",
"scheme",
"end"
] | Add a Brahmic scheme to Sanscript.
Schemes are of two types: "Brahmic" and "roman". Brahmic consonants
have an inherent vowel sound, but roman consonants do not. This is the
main difference between these two types of scheme.
A scheme definition is a Hash that maps a group name to a
list of characters. For illustration, see `transliterate/schemes.rb`.
You can use whatever group names you like, but for the best results,
you should use the same group names that Sanscript does.
@param name [Symbol] the scheme name
@param scheme [Hash] the scheme data, constructed as described above
@return [Hash] the frozen scheme data as it exists inside the module | [
"Add",
"a",
"Brahmic",
"scheme",
"to",
"Sanscript",
"."
] | 0e50c4a856599a7b13c9f0cbc281206245859c71 | https://github.com/ubcsanskrit/sanscript.rb/blob/0e50c4a856599a7b13c9f0cbc281206245859c71/lib/sanscript/transliterate.rb#L74-L81 |
5,268 | ubcsanskrit/sanscript.rb | lib/sanscript/transliterate.rb | Sanscript.Transliterate.add_roman_scheme | def add_roman_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
scheme[:vowel_marks] = scheme[:vowels][1..-1] unless scheme.key?(:vowel_marks)
@schemes[name] = IceNine.deep_freeze(scheme)
@roman_schemes.add(name)
@scheme_names.add(name)
scheme
end | ruby | def add_roman_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
scheme[:vowel_marks] = scheme[:vowels][1..-1] unless scheme.key?(:vowel_marks)
@schemes[name] = IceNine.deep_freeze(scheme)
@roman_schemes.add(name)
@scheme_names.add(name)
scheme
end | [
"def",
"add_roman_scheme",
"(",
"name",
",",
"scheme",
")",
"name",
"=",
"name",
".",
"to_sym",
"scheme",
"=",
"scheme",
".",
"deep_dup",
"scheme",
"[",
":vowel_marks",
"]",
"=",
"scheme",
"[",
":vowels",
"]",
"[",
"1",
"..",
"-",
"1",
"]",
"unless",
"scheme",
".",
"key?",
"(",
":vowel_marks",
")",
"@schemes",
"[",
"name",
"]",
"=",
"IceNine",
".",
"deep_freeze",
"(",
"scheme",
")",
"@roman_schemes",
".",
"add",
"(",
"name",
")",
"@scheme_names",
".",
"add",
"(",
"name",
")",
"scheme",
"end"
] | Add a roman scheme to Sanscript.
@param name [Symbol] the scheme name
@param scheme [Hash] the scheme data, constructed as in {add_brahmic_scheme}.
The "vowel_marks" field can be omitted
@return [Hash] the frozen scheme data as it exists inside the module | [
"Add",
"a",
"roman",
"scheme",
"to",
"Sanscript",
"."
] | 0e50c4a856599a7b13c9f0cbc281206245859c71 | https://github.com/ubcsanskrit/sanscript.rb/blob/0e50c4a856599a7b13c9f0cbc281206245859c71/lib/sanscript/transliterate.rb#L89-L97 |
5,269 | ubcsanskrit/sanscript.rb | lib/sanscript/transliterate.rb | Sanscript.Transliterate.transliterate | def transliterate(data, from, to, **opts)
from = from.to_sym
to = to.to_sym
return data if from == to
raise SchemeNotSupportedError, from unless @schemes.key?(from)
raise SchemeNotSupportedError, to unless @schemes.key?(to)
data = data.to_str.dup
options = @defaults.merge(opts)
map = make_map(from, to)
data.gsub!(/(<.*?>)/, "##\\1##") if options[:skip_sgml]
# Easy way out for "{\m+}", "\", and ".h".
if from == :itrans
data.gsub!(/\{\\m\+\}/, ".h.N")
data.gsub!(/\.h/, "")
data.gsub!(/\\([^'`_]|$)/, "##\\1##")
end
if map[:from_roman?]
transliterate_roman(data, map, options)
else
transliterate_brahmic(data, map)
end
end | ruby | def transliterate(data, from, to, **opts)
from = from.to_sym
to = to.to_sym
return data if from == to
raise SchemeNotSupportedError, from unless @schemes.key?(from)
raise SchemeNotSupportedError, to unless @schemes.key?(to)
data = data.to_str.dup
options = @defaults.merge(opts)
map = make_map(from, to)
data.gsub!(/(<.*?>)/, "##\\1##") if options[:skip_sgml]
# Easy way out for "{\m+}", "\", and ".h".
if from == :itrans
data.gsub!(/\{\\m\+\}/, ".h.N")
data.gsub!(/\.h/, "")
data.gsub!(/\\([^'`_]|$)/, "##\\1##")
end
if map[:from_roman?]
transliterate_roman(data, map, options)
else
transliterate_brahmic(data, map)
end
end | [
"def",
"transliterate",
"(",
"data",
",",
"from",
",",
"to",
",",
"**",
"opts",
")",
"from",
"=",
"from",
".",
"to_sym",
"to",
"=",
"to",
".",
"to_sym",
"return",
"data",
"if",
"from",
"==",
"to",
"raise",
"SchemeNotSupportedError",
",",
"from",
"unless",
"@schemes",
".",
"key?",
"(",
"from",
")",
"raise",
"SchemeNotSupportedError",
",",
"to",
"unless",
"@schemes",
".",
"key?",
"(",
"to",
")",
"data",
"=",
"data",
".",
"to_str",
".",
"dup",
"options",
"=",
"@defaults",
".",
"merge",
"(",
"opts",
")",
"map",
"=",
"make_map",
"(",
"from",
",",
"to",
")",
"data",
".",
"gsub!",
"(",
"/",
"/",
",",
"\"##\\\\1##\"",
")",
"if",
"options",
"[",
":skip_sgml",
"]",
"# Easy way out for \"{\\m+}\", \"\\\", and \".h\".",
"if",
"from",
"==",
":itrans",
"data",
".",
"gsub!",
"(",
"/",
"\\{",
"\\\\",
"\\+",
"\\}",
"/",
",",
"\".h.N\"",
")",
"data",
".",
"gsub!",
"(",
"/",
"\\.",
"/",
",",
"\"\"",
")",
"data",
".",
"gsub!",
"(",
"/",
"\\\\",
"/",
",",
"\"##\\\\1##\"",
")",
"end",
"if",
"map",
"[",
":from_roman?",
"]",
"transliterate_roman",
"(",
"data",
",",
"map",
",",
"options",
")",
"else",
"transliterate_brahmic",
"(",
"data",
",",
"map",
")",
"end",
"end"
] | Transliterate from one script to another.
@param data [String] the String to transliterate
@param from [Symbol] the source script
@param to [Symbol] the destination script
@option opts [Boolean] :skip_sgml (false) escape SGML-style tags in text string
@option opts [Boolean] :syncope (false) activate Hindi-style schwa syncope
@return [String] the transliterated string | [
"Transliterate",
"from",
"one",
"script",
"to",
"another",
"."
] | 0e50c4a856599a7b13c9f0cbc281206245859c71 | https://github.com/ubcsanskrit/sanscript.rb/blob/0e50c4a856599a7b13c9f0cbc281206245859c71/lib/sanscript/transliterate.rb#L143-L168 |
5,270 | postmodern/deployml | lib/deployml/local_shell.rb | DeploYML.LocalShell.run | def run(program,*arguments)
program = program.to_s
arguments = arguments.map { |arg| arg.to_s }
system(program,*arguments)
end | ruby | def run(program,*arguments)
program = program.to_s
arguments = arguments.map { |arg| arg.to_s }
system(program,*arguments)
end | [
"def",
"run",
"(",
"program",
",",
"*",
"arguments",
")",
"program",
"=",
"program",
".",
"to_s",
"arguments",
"=",
"arguments",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"to_s",
"}",
"system",
"(",
"program",
",",
"arguments",
")",
"end"
] | Runs a program locally.
@param [String] program
The name or path of the program to run.
@param [Array<String>] arguments
Additional arguments for the program. | [
"Runs",
"a",
"program",
"locally",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/local_shell.rb#L18-L23 |
5,271 | ryanstout/thor-ssh | lib/thor-ssh/remote_file.rb | ThorSsh.RemoteFile.mkdir_p | def mkdir_p(path)
stdout, stderr, _, _ = exec("mkdir -p #{path.inspect}", :with_codes => true)
if stderr =~ /Permission denied/
base.say_status :permission_error, stderr, :red
raise PermissionError, "unable to create directory #{path}"
end
end | ruby | def mkdir_p(path)
stdout, stderr, _, _ = exec("mkdir -p #{path.inspect}", :with_codes => true)
if stderr =~ /Permission denied/
base.say_status :permission_error, stderr, :red
raise PermissionError, "unable to create directory #{path}"
end
end | [
"def",
"mkdir_p",
"(",
"path",
")",
"stdout",
",",
"stderr",
",",
"_",
",",
"_",
"=",
"exec",
"(",
"\"mkdir -p #{path.inspect}\"",
",",
":with_codes",
"=>",
"true",
")",
"if",
"stderr",
"=~",
"/",
"/",
"base",
".",
"say_status",
":permission_error",
",",
"stderr",
",",
":red",
"raise",
"PermissionError",
",",
"\"unable to create directory #{path}\"",
"end",
"end"
] | Creates the directory at the path on the remote server | [
"Creates",
"the",
"directory",
"at",
"the",
"path",
"on",
"the",
"remote",
"server"
] | fdfd4892ccf4fb40573d32f4331b7f0d1b6fe05d | https://github.com/ryanstout/thor-ssh/blob/fdfd4892ccf4fb40573d32f4331b7f0d1b6fe05d/lib/thor-ssh/remote_file.rb#L45-L52 |
5,272 | ideonetwork/lato-core | lib/lato_core/cell.rb | LatoCore.Cell.validate_args | def validate_args(args: {}, requested_args: [], default_args: {})
requested_args.each do |requested_arg|
raise "Cell must have #{requested_arg} argument" if args[requested_arg] == nil
end
default_args.each do |key, value|
args[key] = value if args[key] == nil
end
args
end | ruby | def validate_args(args: {}, requested_args: [], default_args: {})
requested_args.each do |requested_arg|
raise "Cell must have #{requested_arg} argument" if args[requested_arg] == nil
end
default_args.each do |key, value|
args[key] = value if args[key] == nil
end
args
end | [
"def",
"validate_args",
"(",
"args",
":",
"{",
"}",
",",
"requested_args",
":",
"[",
"]",
",",
"default_args",
":",
"{",
"}",
")",
"requested_args",
".",
"each",
"do",
"|",
"requested_arg",
"|",
"raise",
"\"Cell must have #{requested_arg} argument\"",
"if",
"args",
"[",
"requested_arg",
"]",
"==",
"nil",
"end",
"default_args",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"args",
"[",
"key",
"]",
"=",
"value",
"if",
"args",
"[",
"key",
"]",
"==",
"nil",
"end",
"args",
"end"
] | This function is used from cells to validates arguments on constructor. | [
"This",
"function",
"is",
"used",
"from",
"cells",
"to",
"validates",
"arguments",
"on",
"constructor",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/cell.rb#L17-L27 |
5,273 | razor-x/config_curator | lib/config_curator/utils.rb | ConfigCurator.Utils.command? | def command?(command)
MakeMakefile::Logging.instance_variable_set :@logfile, File::NULL
MakeMakefile::Logging.quiet = true
MakeMakefile.find_executable command.to_s
end | ruby | def command?(command)
MakeMakefile::Logging.instance_variable_set :@logfile, File::NULL
MakeMakefile::Logging.quiet = true
MakeMakefile.find_executable command.to_s
end | [
"def",
"command?",
"(",
"command",
")",
"MakeMakefile",
"::",
"Logging",
".",
"instance_variable_set",
":@logfile",
",",
"File",
"::",
"NULL",
"MakeMakefile",
"::",
"Logging",
".",
"quiet",
"=",
"true",
"MakeMakefile",
".",
"find_executable",
"command",
".",
"to_s",
"end"
] | Checks if command exists.
@param command [String] command name to check
@return [String, nil] full path to command or nil if not found | [
"Checks",
"if",
"command",
"exists",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/utils.rb#L9-L13 |
5,274 | ianwhite/resources_controller | lib/resources_controller/specification.rb | ResourcesController.Specification.find_resource | def find_resource(controller)
(controller.enclosing_resource ? controller.enclosing_resource.send(source) : klass).find controller.params[key]
end | ruby | def find_resource(controller)
(controller.enclosing_resource ? controller.enclosing_resource.send(source) : klass).find controller.params[key]
end | [
"def",
"find_resource",
"(",
"controller",
")",
"(",
"controller",
".",
"enclosing_resource",
"?",
"controller",
".",
"enclosing_resource",
".",
"send",
"(",
"source",
")",
":",
"klass",
")",
".",
"find",
"controller",
".",
"params",
"[",
"key",
"]",
"end"
] | finds the resource on a controller using enclosing resources or resource class | [
"finds",
"the",
"resource",
"on",
"a",
"controller",
"using",
"enclosing",
"resources",
"or",
"resource",
"class"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller/specification.rb#L77-L79 |
5,275 | ianwhite/resources_controller | lib/resources_controller/specification.rb | ResourcesController.SingletonSpecification.find_resource | def find_resource(controller)
ResourcesController.raise_cant_find_singleton(name, klass) unless controller.enclosing_resource
controller.enclosing_resource.send(source)
end | ruby | def find_resource(controller)
ResourcesController.raise_cant_find_singleton(name, klass) unless controller.enclosing_resource
controller.enclosing_resource.send(source)
end | [
"def",
"find_resource",
"(",
"controller",
")",
"ResourcesController",
".",
"raise_cant_find_singleton",
"(",
"name",
",",
"klass",
")",
"unless",
"controller",
".",
"enclosing_resource",
"controller",
".",
"enclosing_resource",
".",
"send",
"(",
"source",
")",
"end"
] | finds the resource from the enclosing resource. Raise CantFindSingleton if there is no enclosing resource | [
"finds",
"the",
"resource",
"from",
"the",
"enclosing",
"resource",
".",
"Raise",
"CantFindSingleton",
"if",
"there",
"is",
"no",
"enclosing",
"resource"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller/specification.rb#L114-L117 |
5,276 | postmodern/deployml | lib/deployml/cli.rb | DeploYML.CLI.find_root | def find_root
Pathname.pwd.ascend do |root|
config_dir = root.join(Project::CONFIG_DIR)
if config_dir.directory?
config_file = config_dir.join(Project::CONFIG_FILE)
return root if config_file.file?
environments_dir = config_dir.join(Project::ENVIRONMENTS_DIR)
return root if environments_dir.directory?
end
end
shell.say "Could not find '#{Project::CONFIG_FILE}' in any parent directories", :red
exit -1
end | ruby | def find_root
Pathname.pwd.ascend do |root|
config_dir = root.join(Project::CONFIG_DIR)
if config_dir.directory?
config_file = config_dir.join(Project::CONFIG_FILE)
return root if config_file.file?
environments_dir = config_dir.join(Project::ENVIRONMENTS_DIR)
return root if environments_dir.directory?
end
end
shell.say "Could not find '#{Project::CONFIG_FILE}' in any parent directories", :red
exit -1
end | [
"def",
"find_root",
"Pathname",
".",
"pwd",
".",
"ascend",
"do",
"|",
"root",
"|",
"config_dir",
"=",
"root",
".",
"join",
"(",
"Project",
"::",
"CONFIG_DIR",
")",
"if",
"config_dir",
".",
"directory?",
"config_file",
"=",
"config_dir",
".",
"join",
"(",
"Project",
"::",
"CONFIG_FILE",
")",
"return",
"root",
"if",
"config_file",
".",
"file?",
"environments_dir",
"=",
"config_dir",
".",
"join",
"(",
"Project",
"::",
"ENVIRONMENTS_DIR",
")",
"return",
"root",
"if",
"environments_dir",
".",
"directory?",
"end",
"end",
"shell",
".",
"say",
"\"Could not find '#{Project::CONFIG_FILE}' in any parent directories\"",
",",
":red",
"exit",
"-",
"1",
"end"
] | Finds the root of the project, starting at the current working
directory and ascending upwards.
@return [Pathname]
The root of the project.
@since 0.3.0 | [
"Finds",
"the",
"root",
"of",
"the",
"project",
"starting",
"at",
"the",
"current",
"working",
"directory",
"and",
"ascending",
"upwards",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/cli.rb#L229-L244 |
5,277 | blahah/biopsy | lib/biopsy/objective_handler.rb | Biopsy.ObjectiveHandler.dimension_reduce | def dimension_reduce(results)
# calculate the weighted Euclidean distance from optimal
# d(p, q) = \sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2+...+(p_n - q_n)^2}
# here the max value is sqrt(n) where n is no. of results,
# min value (optimum) is 0
total = 0
results.each_value do |value|
o = value[:optimum]
w = value[:weighting]
a = value[:result]
m = value[:max]
total += w * (((o - a) / m)**2) if m != 0
end
Math.sqrt(total) / results.length
end | ruby | def dimension_reduce(results)
# calculate the weighted Euclidean distance from optimal
# d(p, q) = \sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2+...+(p_n - q_n)^2}
# here the max value is sqrt(n) where n is no. of results,
# min value (optimum) is 0
total = 0
results.each_value do |value|
o = value[:optimum]
w = value[:weighting]
a = value[:result]
m = value[:max]
total += w * (((o - a) / m)**2) if m != 0
end
Math.sqrt(total) / results.length
end | [
"def",
"dimension_reduce",
"(",
"results",
")",
"# calculate the weighted Euclidean distance from optimal",
"# d(p, q) = \\sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2+...+(p_n - q_n)^2}",
"# here the max value is sqrt(n) where n is no. of results,",
"# min value (optimum) is 0",
"total",
"=",
"0",
"results",
".",
"each_value",
"do",
"|",
"value",
"|",
"o",
"=",
"value",
"[",
":optimum",
"]",
"w",
"=",
"value",
"[",
":weighting",
"]",
"a",
"=",
"value",
"[",
":result",
"]",
"m",
"=",
"value",
"[",
":max",
"]",
"total",
"+=",
"w",
"*",
"(",
"(",
"(",
"o",
"-",
"a",
")",
"/",
"m",
")",
"**",
"2",
")",
"if",
"m",
"!=",
"0",
"end",
"Math",
".",
"sqrt",
"(",
"total",
")",
"/",
"results",
".",
"length",
"end"
] | Perform a euclidean distance dimension reduction of multiple objectives | [
"Perform",
"a",
"euclidean",
"distance",
"dimension",
"reduction",
"of",
"multiple",
"objectives"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/objective_handler.rb#L99-L113 |
5,278 | dwradcliffe/groupme | lib/groupme/bots.rb | GroupMe.Bots.bot_post | def bot_post(id, text, options = {})
data = {
:bot_id => id,
:text => text
}
data[:options] = options if options.any?
post('/bots/post', data).status == 202
end | ruby | def bot_post(id, text, options = {})
data = {
:bot_id => id,
:text => text
}
data[:options] = options if options.any?
post('/bots/post', data).status == 202
end | [
"def",
"bot_post",
"(",
"id",
",",
"text",
",",
"options",
"=",
"{",
"}",
")",
"data",
"=",
"{",
":bot_id",
"=>",
"id",
",",
":text",
"=>",
"text",
"}",
"data",
"[",
":options",
"]",
"=",
"options",
"if",
"options",
".",
"any?",
"post",
"(",
"'/bots/post'",
",",
"data",
")",
".",
"status",
"==",
"202",
"end"
] | Post a message from a bot.
@return [Boolean] Success/Failure
@see https://dev.groupme.com/docs/v3#bots_post
@param id [String, Integer] ID of the bot
@param text [String] Text to send to the group
@option options [String] :picture_url Picture URL from image service | [
"Post",
"a",
"message",
"from",
"a",
"bot",
"."
] | a306dbcf38cc4d9ed219e010783799b2ccb4f9a2 | https://github.com/dwradcliffe/groupme/blob/a306dbcf38cc4d9ed219e010783799b2ccb4f9a2/lib/groupme/bots.rb#L22-L29 |
5,279 | dwradcliffe/groupme | lib/groupme/bots.rb | GroupMe.Bots.create_bot | def create_bot(name, group_id, options = {})
data = {
:bot => options.merge(:name => name, :group_id => group_id)
}
post('/bots', data)
end | ruby | def create_bot(name, group_id, options = {})
data = {
:bot => options.merge(:name => name, :group_id => group_id)
}
post('/bots', data)
end | [
"def",
"create_bot",
"(",
"name",
",",
"group_id",
",",
"options",
"=",
"{",
"}",
")",
"data",
"=",
"{",
":bot",
"=>",
"options",
".",
"merge",
"(",
":name",
"=>",
"name",
",",
":group_id",
"=>",
"group_id",
")",
"}",
"post",
"(",
"'/bots'",
",",
"data",
")",
"end"
] | Create a new bot.
@return [Hashie::Mash] Hash representing the bot.
@see https://dev.groupme.com/docs/v3#bots_create
@param name [String] Name for the new bot
@param group_id [String, Integer] ID of the group
@option options [String] :avatar_url Avatar image URL for the bot
@option options [String] :callback_url Callback URL for the bot | [
"Create",
"a",
"new",
"bot",
"."
] | a306dbcf38cc4d9ed219e010783799b2ccb4f9a2 | https://github.com/dwradcliffe/groupme/blob/a306dbcf38cc4d9ed219e010783799b2ccb4f9a2/lib/groupme/bots.rb#L39-L44 |
5,280 | 10Pines/aws_ses_newsletters | app/workers/aws_ses_newsletters/newsletters_sender.rb | AwsSesNewsletters.NewslettersSender.preview_to | def preview_to(recipient)
@newsletter = build_newsletter
mail = build_mail
mail.to = recipient.email
replace_and_send_mail_safely(mail, recipient)
end | ruby | def preview_to(recipient)
@newsletter = build_newsletter
mail = build_mail
mail.to = recipient.email
replace_and_send_mail_safely(mail, recipient)
end | [
"def",
"preview_to",
"(",
"recipient",
")",
"@newsletter",
"=",
"build_newsletter",
"mail",
"=",
"build_mail",
"mail",
".",
"to",
"=",
"recipient",
".",
"email",
"replace_and_send_mail_safely",
"(",
"mail",
",",
"recipient",
")",
"end"
] | Send a preview email | [
"Send",
"a",
"preview",
"email"
] | 8c6d740ebad45d235e48b40bdb018cb25b1a28de | https://github.com/10Pines/aws_ses_newsletters/blob/8c6d740ebad45d235e48b40bdb018cb25b1a28de/app/workers/aws_ses_newsletters/newsletters_sender.rb#L21-L26 |
5,281 | 10Pines/aws_ses_newsletters | app/workers/aws_ses_newsletters/newsletters_sender.rb | AwsSesNewsletters.NewslettersSender.send_emails | def send_emails
mail = build_mail
get_recipients do |recipient|
unless EmailResponse.exists?(email: recipient.email) # bounces & complaints
mail.to = recipient.email
replace_and_send_mail_safely(mail, recipient)
end
end
end | ruby | def send_emails
mail = build_mail
get_recipients do |recipient|
unless EmailResponse.exists?(email: recipient.email) # bounces & complaints
mail.to = recipient.email
replace_and_send_mail_safely(mail, recipient)
end
end
end | [
"def",
"send_emails",
"mail",
"=",
"build_mail",
"get_recipients",
"do",
"|",
"recipient",
"|",
"unless",
"EmailResponse",
".",
"exists?",
"(",
"email",
":",
"recipient",
".",
"email",
")",
"# bounces & complaints",
"mail",
".",
"to",
"=",
"recipient",
".",
"email",
"replace_and_send_mail_safely",
"(",
"mail",
",",
"recipient",
")",
"end",
"end",
"end"
] | Iterate over recipients and sends emails | [
"Iterate",
"over",
"recipients",
"and",
"sends",
"emails"
] | 8c6d740ebad45d235e48b40bdb018cb25b1a28de | https://github.com/10Pines/aws_ses_newsletters/blob/8c6d740ebad45d235e48b40bdb018cb25b1a28de/app/workers/aws_ses_newsletters/newsletters_sender.rb#L30-L38 |
5,282 | 10Pines/aws_ses_newsletters | app/workers/aws_ses_newsletters/newsletters_sender.rb | AwsSesNewsletters.NewslettersSender.replace_and_send_mail_safely | def replace_and_send_mail_safely(mail, recipient)
html_body = mail.html_part.body.raw_source
do_custom_replacements_for(mail, recipient)
send_raw_email_safely(mail)
mail.html_part.body = html_body
end | ruby | def replace_and_send_mail_safely(mail, recipient)
html_body = mail.html_part.body.raw_source
do_custom_replacements_for(mail, recipient)
send_raw_email_safely(mail)
mail.html_part.body = html_body
end | [
"def",
"replace_and_send_mail_safely",
"(",
"mail",
",",
"recipient",
")",
"html_body",
"=",
"mail",
".",
"html_part",
".",
"body",
".",
"raw_source",
"do_custom_replacements_for",
"(",
"mail",
",",
"recipient",
")",
"send_raw_email_safely",
"(",
"mail",
")",
"mail",
".",
"html_part",
".",
"body",
"=",
"html_body",
"end"
] | Perform custom replacements and send the email without throwing any exception | [
"Perform",
"custom",
"replacements",
"and",
"send",
"the",
"email",
"without",
"throwing",
"any",
"exception"
] | 8c6d740ebad45d235e48b40bdb018cb25b1a28de | https://github.com/10Pines/aws_ses_newsletters/blob/8c6d740ebad45d235e48b40bdb018cb25b1a28de/app/workers/aws_ses_newsletters/newsletters_sender.rb#L73-L78 |
5,283 | 10Pines/aws_ses_newsletters | app/workers/aws_ses_newsletters/newsletters_sender.rb | AwsSesNewsletters.NewslettersSender.build_mail | def build_mail
AwsSesNewsletters::MailBuilder.new(
from: newsletter.from,
subject: newsletter.subject,
html_body: newsletter.html_body,
images: get_images,
).build
end | ruby | def build_mail
AwsSesNewsletters::MailBuilder.new(
from: newsletter.from,
subject: newsletter.subject,
html_body: newsletter.html_body,
images: get_images,
).build
end | [
"def",
"build_mail",
"AwsSesNewsletters",
"::",
"MailBuilder",
".",
"new",
"(",
"from",
":",
"newsletter",
".",
"from",
",",
"subject",
":",
"newsletter",
".",
"subject",
",",
"html_body",
":",
"newsletter",
".",
"html_body",
",",
"images",
":",
"get_images",
",",
")",
".",
"build",
"end"
] | Builds a Mail | [
"Builds",
"a",
"Mail"
] | 8c6d740ebad45d235e48b40bdb018cb25b1a28de | https://github.com/10Pines/aws_ses_newsletters/blob/8c6d740ebad45d235e48b40bdb018cb25b1a28de/app/workers/aws_ses_newsletters/newsletters_sender.rb#L99-L106 |
5,284 | wordjelly/Auth | app/models/auth/concerns/shopping/payment_concern.rb | Auth::Concerns::Shopping::PaymentConcern.ClassMethods.get_discount_payments | def get_discount_payments(cart_id)
discount_payments = Auth.configuration.payment_class.constantize.where(:cart_id => cart_id, :discount_id.nin => ["", nil], :payment_status => 1)
discount_payments
end | ruby | def get_discount_payments(cart_id)
discount_payments = Auth.configuration.payment_class.constantize.where(:cart_id => cart_id, :discount_id.nin => ["", nil], :payment_status => 1)
discount_payments
end | [
"def",
"get_discount_payments",
"(",
"cart_id",
")",
"discount_payments",
"=",
"Auth",
".",
"configuration",
".",
"payment_class",
".",
"constantize",
".",
"where",
"(",
":cart_id",
"=>",
"cart_id",
",",
":discount_id",
".",
"nin",
"=>",
"[",
"\"\"",
",",
"nil",
"]",
",",
":payment_status",
"=>",
"1",
")",
"discount_payments",
"end"
] | will return discount_payments of this cart id with a payments_status of 1. | [
"will",
"return",
"discount_payments",
"of",
"this",
"cart",
"id",
"with",
"a",
"payments_status",
"of",
"1",
"."
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/models/auth/concerns/shopping/payment_concern.rb#L208-L212 |
5,285 | wordjelly/Auth | app/models/auth/concerns/shopping/payment_concern.rb | Auth::Concerns::Shopping::PaymentConcern.ClassMethods.get_sum_of_discount_payments | def get_sum_of_discount_payments(cart_id)
sum_of_discount_payments = 0
get_discount_payments(cart_id).each do |dp|
sum_of_discount_payments+= dp.amount
end
sum_of_discount_payments
end | ruby | def get_sum_of_discount_payments(cart_id)
sum_of_discount_payments = 0
get_discount_payments(cart_id).each do |dp|
sum_of_discount_payments+= dp.amount
end
sum_of_discount_payments
end | [
"def",
"get_sum_of_discount_payments",
"(",
"cart_id",
")",
"sum_of_discount_payments",
"=",
"0",
"get_discount_payments",
"(",
"cart_id",
")",
".",
"each",
"do",
"|",
"dp",
"|",
"sum_of_discount_payments",
"+=",
"dp",
".",
"amount",
"end",
"sum_of_discount_payments",
"end"
] | will return the sum of the amounts of all successfull discount_payments. | [
"will",
"return",
"the",
"sum",
"of",
"the",
"amounts",
"of",
"all",
"successfull",
"discount_payments",
"."
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/models/auth/concerns/shopping/payment_concern.rb#L215-L224 |
5,286 | ideonetwork/lato-core | lib/lato_core/interfaces/general.rb | LatoCore.Interface::General.core__read_yaml | def core__read_yaml(file_path)
# return nil if file not exist
return unless File.exist?(file_path)
config_file = File.read(file_path)
# return yaml data
return YAML.safe_load(config_file).with_indifferent_access
rescue
nil
end | ruby | def core__read_yaml(file_path)
# return nil if file not exist
return unless File.exist?(file_path)
config_file = File.read(file_path)
# return yaml data
return YAML.safe_load(config_file).with_indifferent_access
rescue
nil
end | [
"def",
"core__read_yaml",
"(",
"file_path",
")",
"# return nil if file not exist",
"return",
"unless",
"File",
".",
"exist?",
"(",
"file_path",
")",
"config_file",
"=",
"File",
".",
"read",
"(",
"file_path",
")",
"# return yaml data",
"return",
"YAML",
".",
"safe_load",
"(",
"config_file",
")",
".",
"with_indifferent_access",
"rescue",
"nil",
"end"
] | This function takes a path to a yaml file and return the hash with yaml data
or nil if file not exist. | [
"This",
"function",
"takes",
"a",
"path",
"to",
"a",
"yaml",
"file",
"and",
"return",
"the",
"hash",
"with",
"yaml",
"data",
"or",
"nil",
"if",
"file",
"not",
"exist",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/general.rb#L8-L16 |
5,287 | ideonetwork/lato-core | lib/lato_core/interfaces/general.rb | LatoCore.Interface::General.core__paginate_array | def core__paginate_array(array, per_page, page)
start = (page - 1) * per_page
array[start, per_page]
end | ruby | def core__paginate_array(array, per_page, page)
start = (page - 1) * per_page
array[start, per_page]
end | [
"def",
"core__paginate_array",
"(",
"array",
",",
"per_page",
",",
"page",
")",
"start",
"=",
"(",
"page",
"-",
"1",
")",
"*",
"per_page",
"array",
"[",
"start",
",",
"per_page",
"]",
"end"
] | This function paginate an array and return the requested page. | [
"This",
"function",
"paginate",
"an",
"array",
"and",
"return",
"the",
"requested",
"page",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/general.rb#L24-L27 |
5,288 | ideonetwork/lato-core | lib/lato_core/interfaces/general.rb | LatoCore.Interface::General.core__add_param_to_url | def core__add_param_to_url(url, param_name, param_value)
uri = URI(url)
params = URI.decode_www_form(uri.query || "") << [param_name, param_value]
uri.query = URI.encode_www_form(params)
uri.to_s
end | ruby | def core__add_param_to_url(url, param_name, param_value)
uri = URI(url)
params = URI.decode_www_form(uri.query || "") << [param_name, param_value]
uri.query = URI.encode_www_form(params)
uri.to_s
end | [
"def",
"core__add_param_to_url",
"(",
"url",
",",
"param_name",
",",
"param_value",
")",
"uri",
"=",
"URI",
"(",
"url",
")",
"params",
"=",
"URI",
".",
"decode_www_form",
"(",
"uri",
".",
"query",
"||",
"\"\"",
")",
"<<",
"[",
"param_name",
",",
"param_value",
"]",
"uri",
".",
"query",
"=",
"URI",
".",
"encode_www_form",
"(",
"params",
")",
"uri",
".",
"to_s",
"end"
] | This function add a new GET param to an url string. | [
"This",
"function",
"add",
"a",
"new",
"GET",
"param",
"to",
"an",
"url",
"string",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/general.rb#L30-L35 |
5,289 | ManageIQ/polisher | lib/polisher/adaptors/checker_loader.rb | Polisher.CheckerLoader.targets | def targets
@targets ||= Dir.glob(File.join(target_dir, '*.rb'))
.collect { |t| t.gsub("#{target_dir}/", '').gsub('.rb', '').intern }
end | ruby | def targets
@targets ||= Dir.glob(File.join(target_dir, '*.rb'))
.collect { |t| t.gsub("#{target_dir}/", '').gsub('.rb', '').intern }
end | [
"def",
"targets",
"@targets",
"||=",
"Dir",
".",
"glob",
"(",
"File",
".",
"join",
"(",
"target_dir",
",",
"'*.rb'",
")",
")",
".",
"collect",
"{",
"|",
"t",
"|",
"t",
".",
"gsub",
"(",
"\"#{target_dir}/\"",
",",
"''",
")",
".",
"gsub",
"(",
"'.rb'",
",",
"''",
")",
".",
"intern",
"}",
"end"
] | Targets to check | [
"Targets",
"to",
"check"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/adaptors/checker_loader.rb#L17-L20 |
5,290 | ManageIQ/polisher | lib/polisher/adaptors/checker_loader.rb | Polisher.CheckerLoader.load_target | def load_target(target)
raise ArgumentError, target unless targets.include?(target)
require "polisher/adaptors/version_checker/#{target}"
tm = target_module(target)
@target_modules ||= []
@target_modules << tm
include tm
end | ruby | def load_target(target)
raise ArgumentError, target unless targets.include?(target)
require "polisher/adaptors/version_checker/#{target}"
tm = target_module(target)
@target_modules ||= []
@target_modules << tm
include tm
end | [
"def",
"load_target",
"(",
"target",
")",
"raise",
"ArgumentError",
",",
"target",
"unless",
"targets",
".",
"include?",
"(",
"target",
")",
"require",
"\"polisher/adaptors/version_checker/#{target}\"",
"tm",
"=",
"target_module",
"(",
"target",
")",
"@target_modules",
"||=",
"[",
"]",
"@target_modules",
"<<",
"tm",
"include",
"tm",
"end"
] | Load specified target | [
"Load",
"specified",
"target"
] | 8c19023c72573999c9dc53ec2e2a3eef11a9531e | https://github.com/ManageIQ/polisher/blob/8c19023c72573999c9dc53ec2e2a3eef11a9531e/lib/polisher/adaptors/checker_loader.rb#L38-L47 |
5,291 | wordjelly/Auth | app/models/auth/concerns/activity_concern.rb | Auth::Concerns::ActivityConcern.ClassMethods.activities_from_to | def activities_from_to(query,default_from,default_to)
defaults = {"range" => {"from" => default_from, "to" => default_to}}
query = defaults.deep_merge(query)
##default from and to assigned here.
from = query["range"]["from"].to_i
to = query["range"]["to"].to_i
if from >= to
query["range"]["from"] = default_from
query["range"]["to"] = default_to
end
return query
end | ruby | def activities_from_to(query,default_from,default_to)
defaults = {"range" => {"from" => default_from, "to" => default_to}}
query = defaults.deep_merge(query)
##default from and to assigned here.
from = query["range"]["from"].to_i
to = query["range"]["to"].to_i
if from >= to
query["range"]["from"] = default_from
query["range"]["to"] = default_to
end
return query
end | [
"def",
"activities_from_to",
"(",
"query",
",",
"default_from",
",",
"default_to",
")",
"defaults",
"=",
"{",
"\"range\"",
"=>",
"{",
"\"from\"",
"=>",
"default_from",
",",
"\"to\"",
"=>",
"default_to",
"}",
"}",
"query",
"=",
"defaults",
".",
"deep_merge",
"(",
"query",
")",
"##default from and to assigned here.",
"from",
"=",
"query",
"[",
"\"range\"",
"]",
"[",
"\"from\"",
"]",
".",
"to_i",
"to",
"=",
"query",
"[",
"\"range\"",
"]",
"[",
"\"to\"",
"]",
".",
"to_i",
"if",
"from",
">=",
"to",
"query",
"[",
"\"range\"",
"]",
"[",
"\"from\"",
"]",
"=",
"default_from",
"query",
"[",
"\"range\"",
"]",
"[",
"\"to\"",
"]",
"=",
"default_to",
"end",
"return",
"query",
"end"
] | the default "from" is the beginning of the current month, and the default "to" is the current time.
@used_in : last_n_months, get_in_range
@param[Hash] query: the "from","to" provided in the query if at all, otherwise nil, assumed that query has two keys : "from", "to", under a key called "range"
@param[Integer] default_from : the default_from for the particular function that is firing this query, it is an epoch
@param[Integer] default_to : the default_to for the particular function that is firing this query, it is an epoch
@return[Hash] : default values for "from", "to" | [
"the",
"default",
"from",
"is",
"the",
"beginning",
"of",
"the",
"current",
"month",
"and",
"the",
"default",
"to",
"is",
"the",
"current",
"time",
"."
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/models/auth/concerns/activity_concern.rb#L20-L31 |
5,292 | wordjelly/Auth | app/models/auth/concerns/activity_concern.rb | Auth::Concerns::ActivityConcern.ClassMethods.activities_fields | def activities_fields(query)
defaults = {"only" => Object.const_get(name).fields.keys}
query = defaults.deep_merge(query)
only = ((Object.const_get(name).fields.keys & query["only"]) + ["created_at"])
query["only"] = only
return query
end | ruby | def activities_fields(query)
defaults = {"only" => Object.const_get(name).fields.keys}
query = defaults.deep_merge(query)
only = ((Object.const_get(name).fields.keys & query["only"]) + ["created_at"])
query["only"] = only
return query
end | [
"def",
"activities_fields",
"(",
"query",
")",
"defaults",
"=",
"{",
"\"only\"",
"=>",
"Object",
".",
"const_get",
"(",
"name",
")",
".",
"fields",
".",
"keys",
"}",
"query",
"=",
"defaults",
".",
"deep_merge",
"(",
"query",
")",
"only",
"=",
"(",
"(",
"Object",
".",
"const_get",
"(",
"name",
")",
".",
"fields",
".",
"keys",
"&",
"query",
"[",
"\"only\"",
"]",
")",
"+",
"[",
"\"created_at\"",
"]",
")",
"query",
"[",
"\"only\"",
"]",
"=",
"only",
"return",
"query",
"end"
] | defaults for only.
if it is empty or nil, then it becomes all attributes
otherwise it becomes the intersect of all attributes and the ones specified in the only
created_at had to be added here, because otherwise it throws an error saying missing_attribute in the only. I think this has something to do with the fact that it is used in the query, so it will be included in the result.
@used_in: get_in_range
@param[query] : the provided query, expected to be of the structure:
{"only" => [array],,,other key value pairs}
@return[Hash] query : returns the query with the default values for the fields to be returned | [
"defaults",
"for",
"only",
".",
"if",
"it",
"is",
"empty",
"or",
"nil",
"then",
"it",
"becomes",
"all",
"attributes",
"otherwise",
"it",
"becomes",
"the",
"intersect",
"of",
"all",
"attributes",
"and",
"the",
"ones",
"specified",
"in",
"the",
"only",
"created_at",
"had",
"to",
"be",
"added",
"here",
"because",
"otherwise",
"it",
"throws",
"an",
"error",
"saying",
"missing_attribute",
"in",
"the",
"only",
".",
"I",
"think",
"this",
"has",
"something",
"to",
"do",
"with",
"the",
"fact",
"that",
"it",
"is",
"used",
"in",
"the",
"query",
"so",
"it",
"will",
"be",
"included",
"in",
"the",
"result",
"."
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/models/auth/concerns/activity_concern.rb#L42-L48 |
5,293 | logankoester/prometheus | lib/prometheus/extra/config/lib/plugin_dsl.rb | Prometheus.PluginDSL.start | def start
if File.exists? CONFIG_PATH
if Config.missing_configurables.size > 0
Prometheus::ConfigCommands.new.invoke :repair
else
super
end
else
Prometheus::ConfigCommands.new.invoke :edit
end
end | ruby | def start
if File.exists? CONFIG_PATH
if Config.missing_configurables.size > 0
Prometheus::ConfigCommands.new.invoke :repair
else
super
end
else
Prometheus::ConfigCommands.new.invoke :edit
end
end | [
"def",
"start",
"if",
"File",
".",
"exists?",
"CONFIG_PATH",
"if",
"Config",
".",
"missing_configurables",
".",
"size",
">",
"0",
"Prometheus",
"::",
"ConfigCommands",
".",
"new",
".",
"invoke",
":repair",
"else",
"super",
"end",
"else",
"Prometheus",
"::",
"ConfigCommands",
".",
"new",
".",
"invoke",
":edit",
"end",
"end"
] | Make sure the user has a complete config before continuing. | [
"Make",
"sure",
"the",
"user",
"has",
"a",
"complete",
"config",
"before",
"continuing",
"."
] | 7ca710a69c7ab328b19c4d021539efc7ff93e6c0 | https://github.com/logankoester/prometheus/blob/7ca710a69c7ab328b19c4d021539efc7ff93e6c0/lib/prometheus/extra/config/lib/plugin_dsl.rb#L4-L14 |
5,294 | Sharparam/chatrix | lib/chatrix/users.rb | Chatrix.Users.[] | def [](id)
return @users[id] if id.start_with? '@'
res = @users.find { |_, u| u.displayname == id }
res.last if res.respond_to? :last
end | ruby | def [](id)
return @users[id] if id.start_with? '@'
res = @users.find { |_, u| u.displayname == id }
res.last if res.respond_to? :last
end | [
"def",
"[]",
"(",
"id",
")",
"return",
"@users",
"[",
"id",
"]",
"if",
"id",
".",
"start_with?",
"'@'",
"res",
"=",
"@users",
".",
"find",
"{",
"|",
"_",
",",
"u",
"|",
"u",
".",
"displayname",
"==",
"id",
"}",
"res",
".",
"last",
"if",
"res",
".",
"respond_to?",
":last",
"end"
] | Initializes a new Users instance.
Gets a user by ID or display name.
@param id [String] A user's ID or display name.
@return [User,nil] The User instance for the specified user, or
`nil` if the user could not be found. | [
"Initializes",
"a",
"new",
"Users",
"instance",
".",
"Gets",
"a",
"user",
"by",
"ID",
"or",
"display",
"name",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/users.rb#L25-L30 |
5,295 | Sharparam/chatrix | lib/chatrix/users.rb | Chatrix.Users.process_power_levels | def process_power_levels(room, data)
data.each do |id, level|
get_user(id).process_power_level room, level
end
end | ruby | def process_power_levels(room, data)
data.each do |id, level|
get_user(id).process_power_level room, level
end
end | [
"def",
"process_power_levels",
"(",
"room",
",",
"data",
")",
"data",
".",
"each",
"do",
"|",
"id",
",",
"level",
"|",
"get_user",
"(",
"id",
")",
".",
"process_power_level",
"room",
",",
"level",
"end",
"end"
] | Process power level updates.
@param room [Room] The room this event came from.
@param data [Hash{String=>Fixnum}] Power level data, a hash of user IDs
and their associated power level. | [
"Process",
"power",
"level",
"updates",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/users.rb#L47-L51 |
5,296 | Sharparam/chatrix | lib/chatrix/users.rb | Chatrix.Users.process_invite | def process_invite(room, event)
sender = get_user(event['sender'])
invitee = get_user(event['state_key'])
invitee.process_invite room, sender, event
end | ruby | def process_invite(room, event)
sender = get_user(event['sender'])
invitee = get_user(event['state_key'])
invitee.process_invite room, sender, event
end | [
"def",
"process_invite",
"(",
"room",
",",
"event",
")",
"sender",
"=",
"get_user",
"(",
"event",
"[",
"'sender'",
"]",
")",
"invitee",
"=",
"get_user",
"(",
"event",
"[",
"'state_key'",
"]",
")",
"invitee",
".",
"process_invite",
"room",
",",
"sender",
",",
"event",
"end"
] | Process an invite event for a room.
@param room [Room] The room from which the event originated.
@param event [Hash] Event data. | [
"Process",
"an",
"invite",
"event",
"for",
"a",
"room",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/users.rb#L57-L61 |
5,297 | Sharparam/chatrix | lib/chatrix/users.rb | Chatrix.Users.get_user | def get_user(id)
return @users[id] if @users.key? id
user = User.new id
@users[id] = user
broadcast(:added, user)
user
end | ruby | def get_user(id)
return @users[id] if @users.key? id
user = User.new id
@users[id] = user
broadcast(:added, user)
user
end | [
"def",
"get_user",
"(",
"id",
")",
"return",
"@users",
"[",
"id",
"]",
"if",
"@users",
".",
"key?",
"id",
"user",
"=",
"User",
".",
"new",
"id",
"@users",
"[",
"id",
"]",
"=",
"user",
"broadcast",
"(",
":added",
",",
"user",
")",
"user",
"end"
] | Get the user instance for a specified user ID.
If an instance does not exist for the user, one is created and returned.
@param id [String] The user ID to get an instance for.
@return [User] An instance of User for the specified ID. | [
"Get",
"the",
"user",
"instance",
"for",
"a",
"specified",
"user",
"ID",
".",
"If",
"an",
"instance",
"does",
"not",
"exist",
"for",
"the",
"user",
"one",
"is",
"created",
"and",
"returned",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/users.rb#L70-L76 |
5,298 | ianwhite/resources_controller | lib/resources_controller.rb | ResourcesController.ClassMethods.nested_in | def nested_in(*names, &block)
options = names.extract_options!
raise ArgumentError, "when giving more than one nesting, you may not specify options or a block" if names.length > 1 and (block_given? or options.length > 0)
# convert :polymorphic option to '?'
if options.delete(:polymorphic)
raise ArgumentError, "when specifying :polymorphic => true, no block or other options may be given" if block_given? or options.length > 0
names = ["?#{names.first}"]
end
# ignore first '*' if it has already been specified by :load_enclosing == true
names.shift if specifications == ['*'] && names.first == '*'
names.each do |name|
ensure_sane_wildcard if name == '*'
specifications << (name.to_s =~ /^(\*|\?(.*))$/ ? name.to_s : Specification.new(name, options, &block))
end
end | ruby | def nested_in(*names, &block)
options = names.extract_options!
raise ArgumentError, "when giving more than one nesting, you may not specify options or a block" if names.length > 1 and (block_given? or options.length > 0)
# convert :polymorphic option to '?'
if options.delete(:polymorphic)
raise ArgumentError, "when specifying :polymorphic => true, no block or other options may be given" if block_given? or options.length > 0
names = ["?#{names.first}"]
end
# ignore first '*' if it has already been specified by :load_enclosing == true
names.shift if specifications == ['*'] && names.first == '*'
names.each do |name|
ensure_sane_wildcard if name == '*'
specifications << (name.to_s =~ /^(\*|\?(.*))$/ ? name.to_s : Specification.new(name, options, &block))
end
end | [
"def",
"nested_in",
"(",
"*",
"names",
",",
"&",
"block",
")",
"options",
"=",
"names",
".",
"extract_options!",
"raise",
"ArgumentError",
",",
"\"when giving more than one nesting, you may not specify options or a block\"",
"if",
"names",
".",
"length",
">",
"1",
"and",
"(",
"block_given?",
"or",
"options",
".",
"length",
">",
"0",
")",
"# convert :polymorphic option to '?'",
"if",
"options",
".",
"delete",
"(",
":polymorphic",
")",
"raise",
"ArgumentError",
",",
"\"when specifying :polymorphic => true, no block or other options may be given\"",
"if",
"block_given?",
"or",
"options",
".",
"length",
">",
"0",
"names",
"=",
"[",
"\"?#{names.first}\"",
"]",
"end",
"# ignore first '*' if it has already been specified by :load_enclosing == true",
"names",
".",
"shift",
"if",
"specifications",
"==",
"[",
"'*'",
"]",
"&&",
"names",
".",
"first",
"==",
"'*'",
"names",
".",
"each",
"do",
"|",
"name",
"|",
"ensure_sane_wildcard",
"if",
"name",
"==",
"'*'",
"specifications",
"<<",
"(",
"name",
".",
"to_s",
"=~",
"/",
"\\*",
"\\?",
"/",
"?",
"name",
".",
"to_s",
":",
"Specification",
".",
"new",
"(",
"name",
",",
"options",
",",
"block",
")",
")",
"end",
"end"
] | Specifies that this controller has a particular enclosing resource.
This can be called with an array of symbols (in which case options can't be specified) or
a symbol with options.
See Specification#new for details of how to call this. | [
"Specifies",
"that",
"this",
"controller",
"has",
"a",
"particular",
"enclosing",
"resource",
"."
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller.rb#L523-L540 |
5,299 | ianwhite/resources_controller | lib/resources_controller.rb | ResourcesController.ClassMethods.ensure_sane_wildcard | def ensure_sane_wildcard
idx = specifications.length
while (idx -= 1) >= 0
if specifications[idx] == '*'
raise ArgumentError, "Can only specify one wildcard '*' in between resource specifications"
elsif specifications[idx].is_a?(Specification)
break
end
end
true
end | ruby | def ensure_sane_wildcard
idx = specifications.length
while (idx -= 1) >= 0
if specifications[idx] == '*'
raise ArgumentError, "Can only specify one wildcard '*' in between resource specifications"
elsif specifications[idx].is_a?(Specification)
break
end
end
true
end | [
"def",
"ensure_sane_wildcard",
"idx",
"=",
"specifications",
".",
"length",
"while",
"(",
"idx",
"-=",
"1",
")",
">=",
"0",
"if",
"specifications",
"[",
"idx",
"]",
"==",
"'*'",
"raise",
"ArgumentError",
",",
"\"Can only specify one wildcard '*' in between resource specifications\"",
"elsif",
"specifications",
"[",
"idx",
"]",
".",
"is_a?",
"(",
"Specification",
")",
"break",
"end",
"end",
"true",
"end"
] | ensure that specifications array is determinate w.r.t route matching | [
"ensure",
"that",
"specifications",
"array",
"is",
"determinate",
"w",
".",
"r",
".",
"t",
"route",
"matching"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller.rb#L544-L554 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.