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,300 | ianwhite/resources_controller | lib/resources_controller.rb | ResourcesController.InstanceMethods.load_enclosing_resources | def load_enclosing_resources
namespace_segments.each {|segment| update_name_prefix("#{segment}_") }
specifications.each_with_index do |spec, idx|
case spec
when '*' then load_wildcards_from(idx)
when /^\?(.*)/ then load_wildcard($1)
else load_enclosing_resource_from_specification(spec)
end
end
end | ruby | def load_enclosing_resources
namespace_segments.each {|segment| update_name_prefix("#{segment}_") }
specifications.each_with_index do |spec, idx|
case spec
when '*' then load_wildcards_from(idx)
when /^\?(.*)/ then load_wildcard($1)
else load_enclosing_resource_from_specification(spec)
end
end
end | [
"def",
"load_enclosing_resources",
"namespace_segments",
".",
"each",
"{",
"|",
"segment",
"|",
"update_name_prefix",
"(",
"\"#{segment}_\"",
")",
"}",
"specifications",
".",
"each_with_index",
"do",
"|",
"spec",
",",
"idx",
"|",
"case",
"spec",
"when",
"'*'",
"then",
"load_wildcards_from",
"(",
"idx",
")",
"when",
"/",
"\\?",
"/",
"then",
"load_wildcard",
"(",
"$1",
")",
"else",
"load_enclosing_resource_from_specification",
"(",
"spec",
")",
"end",
"end",
"end"
] | this is the before_action that loads all specified and wildcard resources | [
"this",
"is",
"the",
"before_action",
"that",
"loads",
"all",
"specified",
"and",
"wildcard",
"resources"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller.rb#L662-L671 |
5,301 | ianwhite/resources_controller | lib/resources_controller.rb | ResourcesController.InstanceMethods.load_wildcards_from | def load_wildcards_from(start)
specs = specifications.slice(start..-1)
encls = nesting_segments.slice(enclosing_resources.size..-1)
if spec = specs.find {|s| s.is_a?(Specification)}
spec_seg = encls.index({:segment => spec.segment, :singleton => spec.singleton?}) or ResourcesController.raise_resource_mismatch(self)
number_of_wildcards = spec_seg - (specs.index(spec) -1)
else
number_of_wildcards = encls.length - (specs.length - 1)
end
number_of_wildcards.times { load_wildcard }
end | ruby | def load_wildcards_from(start)
specs = specifications.slice(start..-1)
encls = nesting_segments.slice(enclosing_resources.size..-1)
if spec = specs.find {|s| s.is_a?(Specification)}
spec_seg = encls.index({:segment => spec.segment, :singleton => spec.singleton?}) or ResourcesController.raise_resource_mismatch(self)
number_of_wildcards = spec_seg - (specs.index(spec) -1)
else
number_of_wildcards = encls.length - (specs.length - 1)
end
number_of_wildcards.times { load_wildcard }
end | [
"def",
"load_wildcards_from",
"(",
"start",
")",
"specs",
"=",
"specifications",
".",
"slice",
"(",
"start",
"..",
"-",
"1",
")",
"encls",
"=",
"nesting_segments",
".",
"slice",
"(",
"enclosing_resources",
".",
"size",
"..",
"-",
"1",
")",
"if",
"spec",
"=",
"specs",
".",
"find",
"{",
"|",
"s",
"|",
"s",
".",
"is_a?",
"(",
"Specification",
")",
"}",
"spec_seg",
"=",
"encls",
".",
"index",
"(",
"{",
":segment",
"=>",
"spec",
".",
"segment",
",",
":singleton",
"=>",
"spec",
".",
"singleton?",
"}",
")",
"or",
"ResourcesController",
".",
"raise_resource_mismatch",
"(",
"self",
")",
"number_of_wildcards",
"=",
"spec_seg",
"-",
"(",
"specs",
".",
"index",
"(",
"spec",
")",
"-",
"1",
")",
"else",
"number_of_wildcards",
"=",
"encls",
".",
"length",
"-",
"(",
"specs",
".",
"length",
"-",
"1",
")",
"end",
"number_of_wildcards",
".",
"times",
"{",
"load_wildcard",
"}",
"end"
] | loads a series of wildcard resources, from the specified specification idx
To do this, we need to figure out where the next specified resource is
and how many single wildcards are prior to that. What is left over from
the current route enclosing names will be the number of wildcards we need to load | [
"loads",
"a",
"series",
"of",
"wildcard",
"resources",
"from",
"the",
"specified",
"specification",
"idx"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller.rb#L697-L709 |
5,302 | ianwhite/resources_controller | lib/resources_controller.rb | ResourcesController.ResourceService.destroy | def destroy(*args)
resource = find(*args)
if enclosing_resource
service.destroy(*args)
resource
else
resource.destroy
end
end | ruby | def destroy(*args)
resource = find(*args)
if enclosing_resource
service.destroy(*args)
resource
else
resource.destroy
end
end | [
"def",
"destroy",
"(",
"*",
"args",
")",
"resource",
"=",
"find",
"(",
"args",
")",
"if",
"enclosing_resource",
"service",
".",
"destroy",
"(",
"args",
")",
"resource",
"else",
"resource",
".",
"destroy",
"end",
"end"
] | find the resource
If we have a resource service, we call destroy on it with the reosurce id, so that any callbacks can be triggered
Otherwise, just call destroy on the resource | [
"find",
"the",
"resource",
"If",
"we",
"have",
"a",
"resource",
"service",
"we",
"call",
"destroy",
"on",
"it",
"with",
"the",
"reosurce",
"id",
"so",
"that",
"any",
"callbacks",
"can",
"be",
"triggered",
"Otherwise",
"just",
"call",
"destroy",
"on",
"the",
"resource"
] | 14e76843ccf7d22a6da5da6db81681397c4838c5 | https://github.com/ianwhite/resources_controller/blob/14e76843ccf7d22a6da5da6db81681397c4838c5/lib/resources_controller.rb#L762-L770 |
5,303 | ideonetwork/lato-core | app/models/lato_core/superuser/entity_helpers.rb | LatoCore.Superuser::EntityHelpers.get_permission_name | def get_permission_name
permission = CONFIGS[:lato_core][:superusers_permissions].values.select{|x| x[:value] === self.permission}
return permission[0][:title] if permission && !permission.empty?
end | ruby | def get_permission_name
permission = CONFIGS[:lato_core][:superusers_permissions].values.select{|x| x[:value] === self.permission}
return permission[0][:title] if permission && !permission.empty?
end | [
"def",
"get_permission_name",
"permission",
"=",
"CONFIGS",
"[",
":lato_core",
"]",
"[",
":superusers_permissions",
"]",
".",
"values",
".",
"select",
"{",
"|",
"x",
"|",
"x",
"[",
":value",
"]",
"===",
"self",
".",
"permission",
"}",
"return",
"permission",
"[",
"0",
"]",
"[",
":title",
"]",
"if",
"permission",
"&&",
"!",
"permission",
".",
"empty?",
"end"
] | This function return the permission name for the user. | [
"This",
"function",
"return",
"the",
"permission",
"name",
"for",
"the",
"user",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/app/models/lato_core/superuser/entity_helpers.rb#L12-L15 |
5,304 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.sync | def sync(filter: nil, since: nil, full_state: false,
set_presence: true, timeout: 30_000)
options = { full_state: full_state }
options[:since] = since if since
options[:set_presence] = 'offline' unless set_presence
options[:timeout] = timeout if timeout
options[:filter] = parse_filter filter
make_request(:get, '/sync', params: options).parsed_response
end | ruby | def sync(filter: nil, since: nil, full_state: false,
set_presence: true, timeout: 30_000)
options = { full_state: full_state }
options[:since] = since if since
options[:set_presence] = 'offline' unless set_presence
options[:timeout] = timeout if timeout
options[:filter] = parse_filter filter
make_request(:get, '/sync', params: options).parsed_response
end | [
"def",
"sync",
"(",
"filter",
":",
"nil",
",",
"since",
":",
"nil",
",",
"full_state",
":",
"false",
",",
"set_presence",
":",
"true",
",",
"timeout",
":",
"30_000",
")",
"options",
"=",
"{",
"full_state",
":",
"full_state",
"}",
"options",
"[",
":since",
"]",
"=",
"since",
"if",
"since",
"options",
"[",
":set_presence",
"]",
"=",
"'offline'",
"unless",
"set_presence",
"options",
"[",
":timeout",
"]",
"=",
"timeout",
"if",
"timeout",
"options",
"[",
":filter",
"]",
"=",
"parse_filter",
"filter",
"make_request",
"(",
":get",
",",
"'/sync'",
",",
"params",
":",
"options",
")",
".",
"parsed_response",
"end"
] | Synchronize with the latest state on the server.
For initial sync, call this method with the `since` parameter
set to `nil`.
@param filter [String,Hash] The ID of a filter to use, or provided
directly as a hash.
@param since [String,nil] A point in time to continue sync from.
Will retrieve a snapshot of the state if not set, which will also
provide a `next_batch` value to use for `since` in the next call.
@param full_state [Boolean] If `true`, all state events will be returned
for all rooms the user is a member of.
@param set_presence [Boolean] If `true`, the user performing this request
will have their presence updated to show them as being online.
@param timeout [Fixnum] Maximum time (in milliseconds) to wait before
the request is aborted.
@return [Hash] The initial snapshot of the state (if no `since` value
was provided), or a delta to use for updating state. | [
"Synchronize",
"with",
"the",
"latest",
"state",
"on",
"the",
"server",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L134-L144 |
5,305 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.search | def search(from: nil, options: {})
make_request(
:post, '/search', params: { next_batch: from }, content: options
).parsed_response
end | ruby | def search(from: nil, options: {})
make_request(
:post, '/search', params: { next_batch: from }, content: options
).parsed_response
end | [
"def",
"search",
"(",
"from",
":",
"nil",
",",
"options",
":",
"{",
"}",
")",
"make_request",
"(",
":post",
",",
"'/search'",
",",
"params",
":",
"{",
"next_batch",
":",
"from",
"}",
",",
"content",
":",
"options",
")",
".",
"parsed_response",
"end"
] | Performs a full text search on the server.
@param from [String] Where to return events from, if given. This can be
obtained from previous calls to {#search}.
@param options [Hash] Search options, see the official documentation
for details on how to structure this.
@return [Hash] the search results. | [
"Performs",
"a",
"full",
"text",
"search",
"on",
"the",
"server",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L168-L172 |
5,306 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.make_request | def make_request(method, path, opts = {}, &block)
path = (opts[:base] || @base_uri) + URI.encode(path)
options = make_options opts[:params], opts[:content], opts[:headers]
parse_response METHODS[method].call(path, options, &block)
end | ruby | def make_request(method, path, opts = {}, &block)
path = (opts[:base] || @base_uri) + URI.encode(path)
options = make_options opts[:params], opts[:content], opts[:headers]
parse_response METHODS[method].call(path, options, &block)
end | [
"def",
"make_request",
"(",
"method",
",",
"path",
",",
"opts",
"=",
"{",
"}",
",",
"&",
"block",
")",
"path",
"=",
"(",
"opts",
"[",
":base",
"]",
"||",
"@base_uri",
")",
"+",
"URI",
".",
"encode",
"(",
"path",
")",
"options",
"=",
"make_options",
"opts",
"[",
":params",
"]",
",",
"opts",
"[",
":content",
"]",
",",
"opts",
"[",
":headers",
"]",
"parse_response",
"METHODS",
"[",
"method",
"]",
".",
"call",
"(",
"path",
",",
"options",
",",
"block",
")",
"end"
] | Helper method for performing requests to the homeserver.
@param method [Symbol] HTTP request method to use. Use only symbols
available as keys in {METHODS}.
@param path [String] The API path to query, relative to the base
API path, eg. `/login`.
@param opts [Hash] Additional request options.
@option opts [Hash] :params Additional parameters to include in the
query string (part of the URL, not put in the request body).
@option opts [Hash,#read] :content Content to put in the request body.
If set, must be a Hash or a stream object.
@option opts [Hash{String => String}] :headers Additional headers to
include in the request.
@option opts [String,nil] :base If this is set, it will be used as the
base URI for the request instead of the default (`@base_uri`).
@yield [fragment] HTTParty will call the block during the request.
@return [HTTParty::Response] The HTTParty response object. | [
"Helper",
"method",
"for",
"performing",
"requests",
"to",
"the",
"homeserver",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L201-L206 |
5,307 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.make_options | def make_options(params, content, headers = {})
{ headers: headers }.tap do |o|
o[:query] = @access_token ? { access_token: @access_token } : {}
o[:query].merge!(params) if params.is_a? Hash
o.merge! make_body content
end
end | ruby | def make_options(params, content, headers = {})
{ headers: headers }.tap do |o|
o[:query] = @access_token ? { access_token: @access_token } : {}
o[:query].merge!(params) if params.is_a? Hash
o.merge! make_body content
end
end | [
"def",
"make_options",
"(",
"params",
",",
"content",
",",
"headers",
"=",
"{",
"}",
")",
"{",
"headers",
":",
"headers",
"}",
".",
"tap",
"do",
"|",
"o",
"|",
"o",
"[",
":query",
"]",
"=",
"@access_token",
"?",
"{",
"access_token",
":",
"@access_token",
"}",
":",
"{",
"}",
"o",
"[",
":query",
"]",
".",
"merge!",
"(",
"params",
")",
"if",
"params",
".",
"is_a?",
"Hash",
"o",
".",
"merge!",
"make_body",
"content",
"end",
"end"
] | Create an options Hash to pass to a server request.
This method embeds the {#access_token access_token} into the
query parameters.
@param params [Hash{String=>String},nil] Query parameters to add to
the options hash.
@param content [Hash,#read,nil] Request content. Can be a hash,
stream, or `nil`.
@return [Hash] Options hash ready to be passed into a server request. | [
"Create",
"an",
"options",
"Hash",
"to",
"pass",
"to",
"a",
"server",
"request",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L220-L226 |
5,308 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.make_body | def make_body(content)
key = content.respond_to?(:read) ? :body_stream : :body
value = content.is_a?(Hash) ? content.to_json : content
{ key => value }
end | ruby | def make_body(content)
key = content.respond_to?(:read) ? :body_stream : :body
value = content.is_a?(Hash) ? content.to_json : content
{ key => value }
end | [
"def",
"make_body",
"(",
"content",
")",
"key",
"=",
"content",
".",
"respond_to?",
"(",
":read",
")",
"?",
":body_stream",
":",
":body",
"value",
"=",
"content",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"content",
".",
"to_json",
":",
"content",
"{",
"key",
"=>",
"value",
"}",
"end"
] | Create a hash with body content based on the type of `content`.
@param content [Hash,#read,Object] Some kind of content to put into
the request body. Can be a Hash, stream object, or other kind of
object.
@return [Hash{Symbol => Object}] A hash with the relevant body key
and value. | [
"Create",
"a",
"hash",
"with",
"body",
"content",
"based",
"on",
"the",
"type",
"of",
"content",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L234-L238 |
5,309 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.parse_response | def parse_response(response)
case response.code
when 200 # OK
response
else
handler = ERROR_HANDLERS[response.code]
raise handler.first.new(response.parsed_response), handler.last
end
end | ruby | def parse_response(response)
case response.code
when 200 # OK
response
else
handler = ERROR_HANDLERS[response.code]
raise handler.first.new(response.parsed_response), handler.last
end
end | [
"def",
"parse_response",
"(",
"response",
")",
"case",
"response",
".",
"code",
"when",
"200",
"# OK",
"response",
"else",
"handler",
"=",
"ERROR_HANDLERS",
"[",
"response",
".",
"code",
"]",
"raise",
"handler",
".",
"first",
".",
"new",
"(",
"response",
".",
"parsed_response",
")",
",",
"handler",
".",
"last",
"end",
"end"
] | Parses a HTTParty Response object and returns it if it was successful.
@param response [HTTParty::Response] The response object to parse.
@return [HTTParty::Response] The same response object that was passed
in, if the request was successful.
@raise [RequestError] If a `400` response code was returned from the
request.
@raise [AuthenticationError] If a `401` response code was returned
from the request.
@raise [ForbiddenError] If a `403` response code was returned from the
request.
@raise [NotFoundError] If a `404` response code was returned from the
request.
@raise [RateLimitError] If a `429` response code was returned from the
request.
@raise [ApiError] If an unknown response code was returned from the
request. | [
"Parses",
"a",
"HTTParty",
"Response",
"object",
"and",
"returns",
"it",
"if",
"it",
"was",
"successful",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L258-L266 |
5,310 | Sharparam/chatrix | lib/chatrix/matrix.rb | Chatrix.Matrix.parse_filter | def parse_filter(filter)
filter.is_a?(Hash) ? URI.encode(filter.to_json) : filter
end | ruby | def parse_filter(filter)
filter.is_a?(Hash) ? URI.encode(filter.to_json) : filter
end | [
"def",
"parse_filter",
"(",
"filter",
")",
"filter",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"URI",
".",
"encode",
"(",
"filter",
".",
"to_json",
")",
":",
"filter",
"end"
] | Parses a filter object for use in a query string.
@param filter [String,Hash] The filter object to parse.
@return [String] Query-friendly filter object. Or the `filter`
parameter as-is if it failed to parse. | [
"Parses",
"a",
"filter",
"object",
"for",
"use",
"in",
"a",
"query",
"string",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/matrix.rb#L272-L274 |
5,311 | picatz/command_lion | lib/command_lion/app.rb | CommandLion.App.command | def command(index, &block)
if index.is_a? Command
cmd = index
else
cmd = Command.new
cmd.index= index
cmd.instance_eval(&block)
end
@commands = {} unless @commands
@flags = [] unless @flags
if cmd.flags?
@flags << cmd.flags.short if cmd.flags.short?
@flags << cmd.flags.long if cmd.flags.long?
elsif cmd.index # just use index
@flags << cmd.index.to_s
else
raise "No index or flags were given to use this command."
end
if cmd.options?
cmd.options.each do |_, option|
if option.flags?
@flags << option.flags.short if option.flags.short?
@flags << option.flags.long if option.flags.long?
else # just use index
@flags << option.index.to_s
end
@commands[option.index] = option
end
end
@commands[cmd.index] = cmd
cmd
end | ruby | def command(index, &block)
if index.is_a? Command
cmd = index
else
cmd = Command.new
cmd.index= index
cmd.instance_eval(&block)
end
@commands = {} unless @commands
@flags = [] unless @flags
if cmd.flags?
@flags << cmd.flags.short if cmd.flags.short?
@flags << cmd.flags.long if cmd.flags.long?
elsif cmd.index # just use index
@flags << cmd.index.to_s
else
raise "No index or flags were given to use this command."
end
if cmd.options?
cmd.options.each do |_, option|
if option.flags?
@flags << option.flags.short if option.flags.short?
@flags << option.flags.long if option.flags.long?
else # just use index
@flags << option.index.to_s
end
@commands[option.index] = option
end
end
@commands[cmd.index] = cmd
cmd
end | [
"def",
"command",
"(",
"index",
",",
"&",
"block",
")",
"if",
"index",
".",
"is_a?",
"Command",
"cmd",
"=",
"index",
"else",
"cmd",
"=",
"Command",
".",
"new",
"cmd",
".",
"index",
"=",
"index",
"cmd",
".",
"instance_eval",
"(",
"block",
")",
"end",
"@commands",
"=",
"{",
"}",
"unless",
"@commands",
"@flags",
"=",
"[",
"]",
"unless",
"@flags",
"if",
"cmd",
".",
"flags?",
"@flags",
"<<",
"cmd",
".",
"flags",
".",
"short",
"if",
"cmd",
".",
"flags",
".",
"short?",
"@flags",
"<<",
"cmd",
".",
"flags",
".",
"long",
"if",
"cmd",
".",
"flags",
".",
"long?",
"elsif",
"cmd",
".",
"index",
"# just use index",
"@flags",
"<<",
"cmd",
".",
"index",
".",
"to_s",
"else",
"raise",
"\"No index or flags were given to use this command.\"",
"end",
"if",
"cmd",
".",
"options?",
"cmd",
".",
"options",
".",
"each",
"do",
"|",
"_",
",",
"option",
"|",
"if",
"option",
".",
"flags?",
"@flags",
"<<",
"option",
".",
"flags",
".",
"short",
"if",
"option",
".",
"flags",
".",
"short?",
"@flags",
"<<",
"option",
".",
"flags",
".",
"long",
"if",
"option",
".",
"flags",
".",
"long?",
"else",
"# just use index",
"@flags",
"<<",
"option",
".",
"index",
".",
"to_s",
"end",
"@commands",
"[",
"option",
".",
"index",
"]",
"=",
"option",
"end",
"end",
"@commands",
"[",
"cmd",
".",
"index",
"]",
"=",
"cmd",
"cmd",
"end"
] | An application usually has multiple commands.
== Example
app = CommandLion::App.build
# meta information
command :example1 do
# more code
end
command :example2 do
# more code
end
end
app.commands.map(&:name)
# => [:example1, :example2] | [
"An",
"application",
"usually",
"has",
"multiple",
"commands",
"."
] | a101056a72c481e30a23c159e836e7b532c9b004 | https://github.com/picatz/command_lion/blob/a101056a72c481e30a23c159e836e7b532c9b004/lib/command_lion/app.rb#L160-L191 |
5,312 | picatz/command_lion | lib/command_lion/app.rb | CommandLion.App.parse | def parse
@commands.each do |_, cmd|
if cmd.flags?
# or for the || seems to not do what I want it to do...
next unless argv_index = ARGV.index(cmd.flags.short) || ARGV.index(cmd.flags.long)
else
next unless argv_index = ARGV.index(cmd.index.to_s)
end
cmd.given = true unless argv_index.nil?
if cmd.type.nil?
yield cmd if block_given?
else
if parsed = parse_cmd(cmd, flags)
cmd.arguments = parsed || cmd.default
yield cmd if block_given?
elsif cmd.default
cmd.arguments = cmd.default
yield cmd if block_given?
end
end
end
end | ruby | def parse
@commands.each do |_, cmd|
if cmd.flags?
# or for the || seems to not do what I want it to do...
next unless argv_index = ARGV.index(cmd.flags.short) || ARGV.index(cmd.flags.long)
else
next unless argv_index = ARGV.index(cmd.index.to_s)
end
cmd.given = true unless argv_index.nil?
if cmd.type.nil?
yield cmd if block_given?
else
if parsed = parse_cmd(cmd, flags)
cmd.arguments = parsed || cmd.default
yield cmd if block_given?
elsif cmd.default
cmd.arguments = cmd.default
yield cmd if block_given?
end
end
end
end | [
"def",
"parse",
"@commands",
".",
"each",
"do",
"|",
"_",
",",
"cmd",
"|",
"if",
"cmd",
".",
"flags?",
"# or for the || seems to not do what I want it to do...",
"next",
"unless",
"argv_index",
"=",
"ARGV",
".",
"index",
"(",
"cmd",
".",
"flags",
".",
"short",
")",
"||",
"ARGV",
".",
"index",
"(",
"cmd",
".",
"flags",
".",
"long",
")",
"else",
"next",
"unless",
"argv_index",
"=",
"ARGV",
".",
"index",
"(",
"cmd",
".",
"index",
".",
"to_s",
")",
"end",
"cmd",
".",
"given",
"=",
"true",
"unless",
"argv_index",
".",
"nil?",
"if",
"cmd",
".",
"type",
".",
"nil?",
"yield",
"cmd",
"if",
"block_given?",
"else",
"if",
"parsed",
"=",
"parse_cmd",
"(",
"cmd",
",",
"flags",
")",
"cmd",
".",
"arguments",
"=",
"parsed",
"||",
"cmd",
".",
"default",
"yield",
"cmd",
"if",
"block_given?",
"elsif",
"cmd",
".",
"default",
"cmd",
".",
"arguments",
"=",
"cmd",
".",
"default",
"yield",
"cmd",
"if",
"block_given?",
"end",
"end",
"end",
"end"
] | Parse arguments off of ARGV.
@TODO Re-visit this. | [
"Parse",
"arguments",
"off",
"of",
"ARGV",
"."
] | a101056a72c481e30a23c159e836e7b532c9b004 | https://github.com/picatz/command_lion/blob/a101056a72c481e30a23c159e836e7b532c9b004/lib/command_lion/app.rb#L221-L242 |
5,313 | picatz/command_lion | lib/command_lion/app.rb | CommandLion.App.parse_cmd | def parse_cmd(cmd, flags)
if cmd.flags?
args = Raw.arguments_to(cmd.flags.short, flags)
if args.nil? || args.empty?
args = Raw.arguments_to(cmd.flags.long, flags)
end
else
args = Raw.arguments_to(cmd.index.to_s, flags)
end
unless cmd.type.to_s =~ /stdin/
return nil if args.nil?
end
case cmd.type
when :stdin
args = STDIN.gets.strip
when :stdin_stream
args = STDIN
when :stdin_string
args = STDIN.gets.strip
when :stdin_strings
args = []
while arg = STDIN.gets
next if arg.nil?
arg = arg.strip
args << arg
end
args
when :stdin_integer
args = STDIN.gets.strip.to_i
when :stdin_integers
args = []
while arg = STDIN.gets
next if arg.nil?
arg = arg.strip
parse = arg.to_i
if parse.to_s == arg
args << parse
end
end
args
when :stdin_bool
args = STDIN.gets.strip.downcase == "true"
when :single, :string
args = args.first
when :strings, :multi
if cmd.delimiter?
if args.count > 1
args = args.first.split(cmd.delimiter)
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args
when :integer
args = args.first.to_i
when :integers
if cmd.delimiter?
if args.count > 1
args = args.join
args = args.select { |arg| arg if arg.include?(cmd.delimiter) }
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args = args.map(&:to_i)
when :bool, :bools
if cmd.delimiter?
if args.count > 1
args = args.join
args = args.select { |arg| arg if arg.include?(cmd.delimiter) }
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args = args.map { |arg| arg == "true" }
end
rescue => e# this is dangerous
puts e
nil
end | ruby | def parse_cmd(cmd, flags)
if cmd.flags?
args = Raw.arguments_to(cmd.flags.short, flags)
if args.nil? || args.empty?
args = Raw.arguments_to(cmd.flags.long, flags)
end
else
args = Raw.arguments_to(cmd.index.to_s, flags)
end
unless cmd.type.to_s =~ /stdin/
return nil if args.nil?
end
case cmd.type
when :stdin
args = STDIN.gets.strip
when :stdin_stream
args = STDIN
when :stdin_string
args = STDIN.gets.strip
when :stdin_strings
args = []
while arg = STDIN.gets
next if arg.nil?
arg = arg.strip
args << arg
end
args
when :stdin_integer
args = STDIN.gets.strip.to_i
when :stdin_integers
args = []
while arg = STDIN.gets
next if arg.nil?
arg = arg.strip
parse = arg.to_i
if parse.to_s == arg
args << parse
end
end
args
when :stdin_bool
args = STDIN.gets.strip.downcase == "true"
when :single, :string
args = args.first
when :strings, :multi
if cmd.delimiter?
if args.count > 1
args = args.first.split(cmd.delimiter)
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args
when :integer
args = args.first.to_i
when :integers
if cmd.delimiter?
if args.count > 1
args = args.join
args = args.select { |arg| arg if arg.include?(cmd.delimiter) }
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args = args.map(&:to_i)
when :bool, :bools
if cmd.delimiter?
if args.count > 1
args = args.join
args = args.select { |arg| arg if arg.include?(cmd.delimiter) }
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
else
args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
end
end
args = args.map { |arg| arg == "true" }
end
rescue => e# this is dangerous
puts e
nil
end | [
"def",
"parse_cmd",
"(",
"cmd",
",",
"flags",
")",
"if",
"cmd",
".",
"flags?",
"args",
"=",
"Raw",
".",
"arguments_to",
"(",
"cmd",
".",
"flags",
".",
"short",
",",
"flags",
")",
"if",
"args",
".",
"nil?",
"||",
"args",
".",
"empty?",
"args",
"=",
"Raw",
".",
"arguments_to",
"(",
"cmd",
".",
"flags",
".",
"long",
",",
"flags",
")",
"end",
"else",
"args",
"=",
"Raw",
".",
"arguments_to",
"(",
"cmd",
".",
"index",
".",
"to_s",
",",
"flags",
")",
"end",
"unless",
"cmd",
".",
"type",
".",
"to_s",
"=~",
"/",
"/",
"return",
"nil",
"if",
"args",
".",
"nil?",
"end",
"case",
"cmd",
".",
"type",
"when",
":stdin",
"args",
"=",
"STDIN",
".",
"gets",
".",
"strip",
"when",
":stdin_stream",
"args",
"=",
"STDIN",
"when",
":stdin_string",
"args",
"=",
"STDIN",
".",
"gets",
".",
"strip",
"when",
":stdin_strings",
"args",
"=",
"[",
"]",
"while",
"arg",
"=",
"STDIN",
".",
"gets",
"next",
"if",
"arg",
".",
"nil?",
"arg",
"=",
"arg",
".",
"strip",
"args",
"<<",
"arg",
"end",
"args",
"when",
":stdin_integer",
"args",
"=",
"STDIN",
".",
"gets",
".",
"strip",
".",
"to_i",
"when",
":stdin_integers",
"args",
"=",
"[",
"]",
"while",
"arg",
"=",
"STDIN",
".",
"gets",
"next",
"if",
"arg",
".",
"nil?",
"arg",
"=",
"arg",
".",
"strip",
"parse",
"=",
"arg",
".",
"to_i",
"if",
"parse",
".",
"to_s",
"==",
"arg",
"args",
"<<",
"parse",
"end",
"end",
"args",
"when",
":stdin_bool",
"args",
"=",
"STDIN",
".",
"gets",
".",
"strip",
".",
"downcase",
"==",
"\"true\"",
"when",
":single",
",",
":string",
"args",
"=",
"args",
".",
"first",
"when",
":strings",
",",
":multi",
"if",
"cmd",
".",
"delimiter?",
"if",
"args",
".",
"count",
">",
"1",
"args",
"=",
"args",
".",
"first",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"else",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"}",
".",
"flatten",
"end",
"end",
"args",
"when",
":integer",
"args",
"=",
"args",
".",
"first",
".",
"to_i",
"when",
":integers",
"if",
"cmd",
".",
"delimiter?",
"if",
"args",
".",
"count",
">",
"1",
"args",
"=",
"args",
".",
"join",
"args",
"=",
"args",
".",
"select",
"{",
"|",
"arg",
"|",
"arg",
"if",
"arg",
".",
"include?",
"(",
"cmd",
".",
"delimiter",
")",
"}",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"}",
".",
"flatten",
"else",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"}",
".",
"flatten",
"end",
"end",
"args",
"=",
"args",
".",
"map",
"(",
":to_i",
")",
"when",
":bool",
",",
":bools",
"if",
"cmd",
".",
"delimiter?",
"if",
"args",
".",
"count",
">",
"1",
"args",
"=",
"args",
".",
"join",
"args",
"=",
"args",
".",
"select",
"{",
"|",
"arg",
"|",
"arg",
"if",
"arg",
".",
"include?",
"(",
"cmd",
".",
"delimiter",
")",
"}",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"}",
".",
"flatten",
"else",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
".",
"split",
"(",
"cmd",
".",
"delimiter",
")",
"}",
".",
"flatten",
"end",
"end",
"args",
"=",
"args",
".",
"map",
"{",
"|",
"arg",
"|",
"arg",
"==",
"\"true\"",
"}",
"end",
"rescue",
"=>",
"e",
"# this is dangerous",
"puts",
"e",
"nil",
"end"
] | Parse a given command with its given flags.
@TODO Re-visit this. | [
"Parse",
"a",
"given",
"command",
"with",
"its",
"given",
"flags",
"."
] | a101056a72c481e30a23c159e836e7b532c9b004 | https://github.com/picatz/command_lion/blob/a101056a72c481e30a23c159e836e7b532c9b004/lib/command_lion/app.rb#L246-L327 |
5,314 | thinkerbot/configurable | lib/configurable/config_hash.rb | Configurable.ConfigHash.[]= | def []=(key, value)
if config = configs[key]
config.set(receiver, value)
else
store[key] = value
end
end | ruby | def []=(key, value)
if config = configs[key]
config.set(receiver, value)
else
store[key] = value
end
end | [
"def",
"[]=",
"(",
"key",
",",
"value",
")",
"if",
"config",
"=",
"configs",
"[",
"key",
"]",
"config",
".",
"set",
"(",
"receiver",
",",
"value",
")",
"else",
"store",
"[",
"key",
"]",
"=",
"value",
"end",
"end"
] | Stores a value for the key, either on the receiver or in the store. | [
"Stores",
"a",
"value",
"for",
"the",
"key",
"either",
"on",
"the",
"receiver",
"or",
"in",
"the",
"store",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/config_hash.rb#L82-L88 |
5,315 | thinkerbot/configurable | lib/configurable/config_hash.rb | Configurable.ConfigHash.merge! | def merge!(another)
configs = self.configs
another.each_pair do |key, value|
if config = configs[key]
config.set(receiver, value)
else
store[key] = value
end
end
self
end | ruby | def merge!(another)
configs = self.configs
another.each_pair do |key, value|
if config = configs[key]
config.set(receiver, value)
else
store[key] = value
end
end
self
end | [
"def",
"merge!",
"(",
"another",
")",
"configs",
"=",
"self",
".",
"configs",
"another",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"config",
"=",
"configs",
"[",
"key",
"]",
"config",
".",
"set",
"(",
"receiver",
",",
"value",
")",
"else",
"store",
"[",
"key",
"]",
"=",
"value",
"end",
"end",
"self",
"end"
] | Merges another with self. | [
"Merges",
"another",
"with",
"self",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/config_hash.rb#L101-L111 |
5,316 | thinkerbot/configurable | lib/configurable/config_hash.rb | Configurable.ConfigHash.each_pair | def each_pair # :yields: key, value
configs.each_pair do |key, config|
yield(key, config.get(receiver))
end
store.each_pair do |key, value|
yield(key, value)
end
end | ruby | def each_pair # :yields: key, value
configs.each_pair do |key, config|
yield(key, config.get(receiver))
end
store.each_pair do |key, value|
yield(key, value)
end
end | [
"def",
"each_pair",
"# :yields: key, value",
"configs",
".",
"each_pair",
"do",
"|",
"key",
",",
"config",
"|",
"yield",
"(",
"key",
",",
"config",
".",
"get",
"(",
"receiver",
")",
")",
"end",
"store",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"yield",
"(",
"key",
",",
"value",
")",
"end",
"end"
] | Calls block once for each key-value pair stored in self. | [
"Calls",
"block",
"once",
"for",
"each",
"key",
"-",
"value",
"pair",
"stored",
"in",
"self",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/config_hash.rb#L114-L122 |
5,317 | thinkerbot/configurable | lib/configurable/config_hash.rb | Configurable.ConfigHash.to_hash | def to_hash
hash = {}
each_pair do |key, value|
if value.kind_of?(ConfigHash)
value = value.to_hash
end
hash[key] = value
end
hash
end | ruby | def to_hash
hash = {}
each_pair do |key, value|
if value.kind_of?(ConfigHash)
value = value.to_hash
end
hash[key] = value
end
hash
end | [
"def",
"to_hash",
"hash",
"=",
"{",
"}",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"value",
".",
"kind_of?",
"(",
"ConfigHash",
")",
"value",
"=",
"value",
".",
"to_hash",
"end",
"hash",
"[",
"key",
"]",
"=",
"value",
"end",
"hash",
"end"
] | Equal if the to_hash values of self and another are equal.
Returns self as a hash. Any ConfigHash values are recursively
hashified, to account for nesting. | [
"Equal",
"if",
"the",
"to_hash",
"values",
"of",
"self",
"and",
"another",
"are",
"equal",
".",
"Returns",
"self",
"as",
"a",
"hash",
".",
"Any",
"ConfigHash",
"values",
"are",
"recursively",
"hashified",
"to",
"account",
"for",
"nesting",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/config_hash.rb#L131-L141 |
5,318 | scepticulous/crypto-toolbox | lib/crypto-toolbox/ciphers/aes.rb | Ciphers.Aes.decipher_ecb | def decipher_ecb(key,input,strip_padding: true)
plain = decipher_ecb_blockwise(CryptBuffer(key),CryptBuffer(input).chunks_of(@block_size_bytes)).to_crypt_buffer
strip_padding ? plain.strip_padding : plain
end | ruby | def decipher_ecb(key,input,strip_padding: true)
plain = decipher_ecb_blockwise(CryptBuffer(key),CryptBuffer(input).chunks_of(@block_size_bytes)).to_crypt_buffer
strip_padding ? plain.strip_padding : plain
end | [
"def",
"decipher_ecb",
"(",
"key",
",",
"input",
",",
"strip_padding",
":",
"true",
")",
"plain",
"=",
"decipher_ecb_blockwise",
"(",
"CryptBuffer",
"(",
"key",
")",
",",
"CryptBuffer",
"(",
"input",
")",
".",
"chunks_of",
"(",
"@block_size_bytes",
")",
")",
".",
"to_crypt_buffer",
"strip_padding",
"?",
"plain",
".",
"strip_padding",
":",
"plain",
"end"
] | NOTE convert ECB encryption to AES gem or both to openssl | [
"NOTE",
"convert",
"ECB",
"encryption",
"to",
"AES",
"gem",
"or",
"both",
"to",
"openssl"
] | cdbe371109e497db2c2af5c1fe0f359612f44816 | https://github.com/scepticulous/crypto-toolbox/blob/cdbe371109e497db2c2af5c1fe0f359612f44816/lib/crypto-toolbox/ciphers/aes.rb#L12-L15 |
5,319 | scepticulous/crypto-toolbox | lib/crypto-toolbox/ciphers/aes.rb | Ciphers.Aes.unicipher_cbc | def unicipher_cbc(direction,key_str,input_buf,iv)
method="#{direction.to_s}_cbc_block"
blocks = input_buf.chunks_of(@block_size_bytes)
iv ||= blocks.shift.str
key = CryptBuffer(key_str).hex
prev_block=iv.to_crypt_buffer
strings = blocks.map.with_index do |block,i|
ctext_block = send(method,key,block,prev_block)
if direction == :encipher
prev_block = ctext_block
else
prev_block = block
end
ctext_block.str
end
CryptBuffer(strings.join)
end | ruby | def unicipher_cbc(direction,key_str,input_buf,iv)
method="#{direction.to_s}_cbc_block"
blocks = input_buf.chunks_of(@block_size_bytes)
iv ||= blocks.shift.str
key = CryptBuffer(key_str).hex
prev_block=iv.to_crypt_buffer
strings = blocks.map.with_index do |block,i|
ctext_block = send(method,key,block,prev_block)
if direction == :encipher
prev_block = ctext_block
else
prev_block = block
end
ctext_block.str
end
CryptBuffer(strings.join)
end | [
"def",
"unicipher_cbc",
"(",
"direction",
",",
"key_str",
",",
"input_buf",
",",
"iv",
")",
"method",
"=",
"\"#{direction.to_s}_cbc_block\"",
"blocks",
"=",
"input_buf",
".",
"chunks_of",
"(",
"@block_size_bytes",
")",
"iv",
"||=",
"blocks",
".",
"shift",
".",
"str",
"key",
"=",
"CryptBuffer",
"(",
"key_str",
")",
".",
"hex",
"prev_block",
"=",
"iv",
".",
"to_crypt_buffer",
"strings",
"=",
"blocks",
".",
"map",
".",
"with_index",
"do",
"|",
"block",
",",
"i",
"|",
"ctext_block",
"=",
"send",
"(",
"method",
",",
"key",
",",
"block",
",",
"prev_block",
")",
"if",
"direction",
"==",
":encipher",
"prev_block",
"=",
"ctext_block",
"else",
"prev_block",
"=",
"block",
"end",
"ctext_block",
".",
"str",
"end",
"CryptBuffer",
"(",
"strings",
".",
"join",
")",
"end"
] | this method is used for encipher and decipher since most of the code is identical
only the value of the previous block and the internal ecb method differs | [
"this",
"method",
"is",
"used",
"for",
"encipher",
"and",
"decipher",
"since",
"most",
"of",
"the",
"code",
"is",
"identical",
"only",
"the",
"value",
"of",
"the",
"previous",
"block",
"and",
"the",
"internal",
"ecb",
"method",
"differs"
] | cdbe371109e497db2c2af5c1fe0f359612f44816 | https://github.com/scepticulous/crypto-toolbox/blob/cdbe371109e497db2c2af5c1fe0f359612f44816/lib/crypto-toolbox/ciphers/aes.rb#L68-L89 |
5,320 | Birdie0/qna_maker | lib/qna_maker/endpoints/generate_answer.rb | QnAMaker.Client.generate_answer | def generate_answer(question, top = 1)
response = @http.post(
"#{BASE_URL}/#{@knowledgebase_id}/generateAnswer",
json: { question: question, top: top }
)
case response.code
when 200
response.parse['answers'].map do |answer|
Answer.new(
answer['answer'].normalize,
answer['questions'].map(&:normalize),
answer['score']
)
end
when 400
raise BadArgumentError, response.parse['error']['message'].join(' ')
when 401
raise UnauthorizedError, response.parse['error']['message']
when 403
raise QuotaExceededError, response.parse['error']['message']
when 404
raise NotFoundError, response.parse['error']['message']
when 408
raise OperationTimeOutError, response.parse['error']['message']
when 429
raise RateLimitExceededError, response.parse['error']['message']
else
raise UnknownError, "Oh no! (#{response.code})"
end
end | ruby | def generate_answer(question, top = 1)
response = @http.post(
"#{BASE_URL}/#{@knowledgebase_id}/generateAnswer",
json: { question: question, top: top }
)
case response.code
when 200
response.parse['answers'].map do |answer|
Answer.new(
answer['answer'].normalize,
answer['questions'].map(&:normalize),
answer['score']
)
end
when 400
raise BadArgumentError, response.parse['error']['message'].join(' ')
when 401
raise UnauthorizedError, response.parse['error']['message']
when 403
raise QuotaExceededError, response.parse['error']['message']
when 404
raise NotFoundError, response.parse['error']['message']
when 408
raise OperationTimeOutError, response.parse['error']['message']
when 429
raise RateLimitExceededError, response.parse['error']['message']
else
raise UnknownError, "Oh no! (#{response.code})"
end
end | [
"def",
"generate_answer",
"(",
"question",
",",
"top",
"=",
"1",
")",
"response",
"=",
"@http",
".",
"post",
"(",
"\"#{BASE_URL}/#{@knowledgebase_id}/generateAnswer\"",
",",
"json",
":",
"{",
"question",
":",
"question",
",",
"top",
":",
"top",
"}",
")",
"case",
"response",
".",
"code",
"when",
"200",
"response",
".",
"parse",
"[",
"'answers'",
"]",
".",
"map",
"do",
"|",
"answer",
"|",
"Answer",
".",
"new",
"(",
"answer",
"[",
"'answer'",
"]",
".",
"normalize",
",",
"answer",
"[",
"'questions'",
"]",
".",
"map",
"(",
":normalize",
")",
",",
"answer",
"[",
"'score'",
"]",
")",
"end",
"when",
"400",
"raise",
"BadArgumentError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
".",
"join",
"(",
"' '",
")",
"when",
"401",
"raise",
"UnauthorizedError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"403",
"raise",
"QuotaExceededError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"404",
"raise",
"NotFoundError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"408",
"raise",
"OperationTimeOutError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"429",
"raise",
"RateLimitExceededError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"else",
"raise",
"UnknownError",
",",
"\"Oh no! (#{response.code})\"",
"end",
"end"
] | Returns the list of answers for the given question sorted in descending
order of ranking score.
@param [String] question user question to be queried against your
knowledge base.
@param [Integer] top number of ranked results you want in the output.
@return [Array<Answer>] list of answers for the user query sorted in
decreasing order of ranking score. | [
"Returns",
"the",
"list",
"of",
"answers",
"for",
"the",
"given",
"question",
"sorted",
"in",
"descending",
"order",
"of",
"ranking",
"score",
"."
] | 5ac204ede100355352438b8ff4fe30ad84d9257b | https://github.com/Birdie0/qna_maker/blob/5ac204ede100355352438b8ff4fe30ad84d9257b/lib/qna_maker/endpoints/generate_answer.rb#L14-L44 |
5,321 | ideonetwork/lato-core | lib/lato_core/helpers/cells.rb | LatoCore.Helper::Cells.cell | def cell(*names)
# define variables
names_list = names.first.to_s.start_with?('Lato') ? names[1..-1] : names
cell_class = names.first.to_s.start_with?('Lato') ? "#{names.first}::" : 'LatoCore::'
# return correct cell
names_list.each do |name|
cell_class = "#{cell_class}#{name.capitalize}::"
end
"#{cell_class}Cell".constantize
end | ruby | def cell(*names)
# define variables
names_list = names.first.to_s.start_with?('Lato') ? names[1..-1] : names
cell_class = names.first.to_s.start_with?('Lato') ? "#{names.first}::" : 'LatoCore::'
# return correct cell
names_list.each do |name|
cell_class = "#{cell_class}#{name.capitalize}::"
end
"#{cell_class}Cell".constantize
end | [
"def",
"cell",
"(",
"*",
"names",
")",
"# define variables",
"names_list",
"=",
"names",
".",
"first",
".",
"to_s",
".",
"start_with?",
"(",
"'Lato'",
")",
"?",
"names",
"[",
"1",
"..",
"-",
"1",
"]",
":",
"names",
"cell_class",
"=",
"names",
".",
"first",
".",
"to_s",
".",
"start_with?",
"(",
"'Lato'",
")",
"?",
"\"#{names.first}::\"",
":",
"'LatoCore::'",
"# return correct cell",
"names_list",
".",
"each",
"do",
"|",
"name",
"|",
"cell_class",
"=",
"\"#{cell_class}#{name.capitalize}::\"",
"end",
"\"#{cell_class}Cell\"",
".",
"constantize",
"end"
] | This helper is used to create a new cell with a pretty format. | [
"This",
"helper",
"is",
"used",
"to",
"create",
"a",
"new",
"cell",
"with",
"a",
"pretty",
"format",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/helpers/cells.rb#L7-L16 |
5,322 | sergey-koba-mobidev/boxroom-engine | app/controllers/boxroom/folders_controller.rb | Boxroom.FoldersController.require_delete_permission | def require_delete_permission
unless @folder.is_root? || boxroom_current_user.can_delete(@folder)
redirect_to @folder.parent, :alert => t(:no_permissions_for_this_type, :method => t(:delete), :type => t(:this_folder))
else
require_delete_permissions_for(@folder.children)
end
end | ruby | def require_delete_permission
unless @folder.is_root? || boxroom_current_user.can_delete(@folder)
redirect_to @folder.parent, :alert => t(:no_permissions_for_this_type, :method => t(:delete), :type => t(:this_folder))
else
require_delete_permissions_for(@folder.children)
end
end | [
"def",
"require_delete_permission",
"unless",
"@folder",
".",
"is_root?",
"||",
"boxroom_current_user",
".",
"can_delete",
"(",
"@folder",
")",
"redirect_to",
"@folder",
".",
"parent",
",",
":alert",
"=>",
"t",
"(",
":no_permissions_for_this_type",
",",
":method",
"=>",
"t",
"(",
":delete",
")",
",",
":type",
"=>",
"t",
"(",
":this_folder",
")",
")",
"else",
"require_delete_permissions_for",
"(",
"@folder",
".",
"children",
")",
"end",
"end"
] | Overrides require_delete_permission in ApplicationController | [
"Overrides",
"require_delete_permission",
"in",
"ApplicationController"
] | ce7a6b3fc6a1e5c36021429c0d337fab71993427 | https://github.com/sergey-koba-mobidev/boxroom-engine/blob/ce7a6b3fc6a1e5c36021429c0d337fab71993427/app/controllers/boxroom/folders_controller.rb#L76-L82 |
5,323 | dolzenko/reflexive | lib/reflexive/routing_helpers.rb | Reflexive.RoutingHelpers.method_call_path | def method_call_path(method_call_tag)
# r method_call_tag.values_at(:name, :receiver)
name, receiver, scope = method_call_tag.values_at(:name, :receiver, :scope)
scope = scope.join("::")
if receiver == :class
scope = "Kernel" if scope.empty?
new_method_path(scope, :class, name)
elsif receiver == :instance
scope = "Kernel" if scope.empty?
new_method_path(scope, :instance, name)
else
receiver = receiver.join("::")
new_method_path(Reflexive.constant_lookup(receiver, scope), :class, name)
end
# if receiver.last == :instance
# new_method_path(receiver[0..-2].join("::"), :instance, name)
# else
# new_method_path(receiver.join("::"), :class, name)
# end rescue(r(method_call_tag))
end | ruby | def method_call_path(method_call_tag)
# r method_call_tag.values_at(:name, :receiver)
name, receiver, scope = method_call_tag.values_at(:name, :receiver, :scope)
scope = scope.join("::")
if receiver == :class
scope = "Kernel" if scope.empty?
new_method_path(scope, :class, name)
elsif receiver == :instance
scope = "Kernel" if scope.empty?
new_method_path(scope, :instance, name)
else
receiver = receiver.join("::")
new_method_path(Reflexive.constant_lookup(receiver, scope), :class, name)
end
# if receiver.last == :instance
# new_method_path(receiver[0..-2].join("::"), :instance, name)
# else
# new_method_path(receiver.join("::"), :class, name)
# end rescue(r(method_call_tag))
end | [
"def",
"method_call_path",
"(",
"method_call_tag",
")",
"# r method_call_tag.values_at(:name, :receiver)",
"name",
",",
"receiver",
",",
"scope",
"=",
"method_call_tag",
".",
"values_at",
"(",
":name",
",",
":receiver",
",",
":scope",
")",
"scope",
"=",
"scope",
".",
"join",
"(",
"\"::\"",
")",
"if",
"receiver",
"==",
":class",
"scope",
"=",
"\"Kernel\"",
"if",
"scope",
".",
"empty?",
"new_method_path",
"(",
"scope",
",",
":class",
",",
"name",
")",
"elsif",
"receiver",
"==",
":instance",
"scope",
"=",
"\"Kernel\"",
"if",
"scope",
".",
"empty?",
"new_method_path",
"(",
"scope",
",",
":instance",
",",
"name",
")",
"else",
"receiver",
"=",
"receiver",
".",
"join",
"(",
"\"::\"",
")",
"new_method_path",
"(",
"Reflexive",
".",
"constant_lookup",
"(",
"receiver",
",",
"scope",
")",
",",
":class",
",",
"name",
")",
"end",
"# if receiver.last == :instance",
"# new_method_path(receiver[0..-2].join(\"::\"), :instance, name)",
"# else",
"# new_method_path(receiver.join(\"::\"), :class, name)",
"# end rescue(r(method_call_tag))",
"end"
] | method_call_tag is the scanner event tag emitted by ReflexiveRipper | [
"method_call_tag",
"is",
"the",
"scanner",
"event",
"tag",
"emitted",
"by",
"ReflexiveRipper"
] | 04a58ba2f45c15e2815b7ca04a78a5b6b89a52b9 | https://github.com/dolzenko/reflexive/blob/04a58ba2f45c15e2815b7ca04a78a5b6b89a52b9/lib/reflexive/routing_helpers.rb#L6-L27 |
5,324 | amoghe/rb_tuntap | lib/rb_tuntap.rb | RbTunTap.Device.validate_address! | def validate_address!(addr)
ip = IPAddr.new(addr)
unless ip.ipv4?
raise NotImplementedError, 'Only IPv4 is supported by this library'
end
if addr.include?('/')
raise ArgumentError, 'Please specify a host IP address (without mask)'
end
addr.to_s
end | ruby | def validate_address!(addr)
ip = IPAddr.new(addr)
unless ip.ipv4?
raise NotImplementedError, 'Only IPv4 is supported by this library'
end
if addr.include?('/')
raise ArgumentError, 'Please specify a host IP address (without mask)'
end
addr.to_s
end | [
"def",
"validate_address!",
"(",
"addr",
")",
"ip",
"=",
"IPAddr",
".",
"new",
"(",
"addr",
")",
"unless",
"ip",
".",
"ipv4?",
"raise",
"NotImplementedError",
",",
"'Only IPv4 is supported by this library'",
"end",
"if",
"addr",
".",
"include?",
"(",
"'/'",
")",
"raise",
"ArgumentError",
",",
"'Please specify a host IP address (without mask)'",
"end",
"addr",
".",
"to_s",
"end"
] | Validate that the given string is a valid IP address.
@raises ArgumentError, NotImplementedError | [
"Validate",
"that",
"the",
"given",
"string",
"is",
"a",
"valid",
"IP",
"address",
"."
] | 6eaed110049ea75ec7131bbdc62b49afd9e19489 | https://github.com/amoghe/rb_tuntap/blob/6eaed110049ea75ec7131bbdc62b49afd9e19489/lib/rb_tuntap.rb#L90-L102 |
5,325 | ArchimediaZerogroup/KonoUtils | lib/kono_utils/search_attribute.rb | KonoUtils.SearchAttribute.cast_value | def cast_value(value)
return value if value.blank?
return value if form_options.is_a? Proc
return field_options[:cast].call(value) if field_options[:cast].is_a? Proc
case form_options[:as]
when :bs_datetimepicker
if value.is_a? String
DateTime.parse(value)
elsif value.is_a? Date
value.to_time
else
value
end
when :bs_datepicker
if value.is_a? String
DateTime.parse(value).to_date
elsif value.is_a? DateTime
value.to_date
else
value
end
else
value
end
end | ruby | def cast_value(value)
return value if value.blank?
return value if form_options.is_a? Proc
return field_options[:cast].call(value) if field_options[:cast].is_a? Proc
case form_options[:as]
when :bs_datetimepicker
if value.is_a? String
DateTime.parse(value)
elsif value.is_a? Date
value.to_time
else
value
end
when :bs_datepicker
if value.is_a? String
DateTime.parse(value).to_date
elsif value.is_a? DateTime
value.to_date
else
value
end
else
value
end
end | [
"def",
"cast_value",
"(",
"value",
")",
"return",
"value",
"if",
"value",
".",
"blank?",
"return",
"value",
"if",
"form_options",
".",
"is_a?",
"Proc",
"return",
"field_options",
"[",
":cast",
"]",
".",
"call",
"(",
"value",
")",
"if",
"field_options",
"[",
":cast",
"]",
".",
"is_a?",
"Proc",
"case",
"form_options",
"[",
":as",
"]",
"when",
":bs_datetimepicker",
"if",
"value",
".",
"is_a?",
"String",
"DateTime",
".",
"parse",
"(",
"value",
")",
"elsif",
"value",
".",
"is_a?",
"Date",
"value",
".",
"to_time",
"else",
"value",
"end",
"when",
":bs_datepicker",
"if",
"value",
".",
"is_a?",
"String",
"DateTime",
".",
"parse",
"(",
"value",
")",
".",
"to_date",
"elsif",
"value",
".",
"is_a?",
"DateTime",
"value",
".",
"to_date",
"else",
"value",
"end",
"else",
"value",
"end",
"end"
] | Esegue un casting dei valori rispetto al tipo di campo da utilizzare per formtastic | [
"Esegue",
"un",
"casting",
"dei",
"valori",
"rispetto",
"al",
"tipo",
"di",
"campo",
"da",
"utilizzare",
"per",
"formtastic"
] | a255a30b65e4e0f01cd6236d991da4fd13c64fc6 | https://github.com/ArchimediaZerogroup/KonoUtils/blob/a255a30b65e4e0f01cd6236d991da4fd13c64fc6/lib/kono_utils/search_attribute.rb#L30-L55 |
5,326 | CDLUC3/resync-client | lib/resync/client.rb | Resync.Client.get | def get(uri)
uri = Resync::XML.to_uri(uri)
@helper.fetch(uri: uri)
end | ruby | def get(uri)
uri = Resync::XML.to_uri(uri)
@helper.fetch(uri: uri)
end | [
"def",
"get",
"(",
"uri",
")",
"uri",
"=",
"Resync",
"::",
"XML",
".",
"to_uri",
"(",
"uri",
")",
"@helper",
".",
"fetch",
"(",
"uri",
":",
"uri",
")",
"end"
] | Gets the content of the specified URI as a string.
@param uri [URI, String] the URI to download
@return [String] the content of the URI | [
"Gets",
"the",
"content",
"of",
"the",
"specified",
"URI",
"as",
"a",
"string",
"."
] | e621c9d0c8b8de436923359d6ad36f74c89bb2c2 | https://github.com/CDLUC3/resync-client/blob/e621c9d0c8b8de436923359d6ad36f74c89bb2c2/lib/resync/client.rb#L36-L39 |
5,327 | CDLUC3/resync-client | lib/resync/client.rb | Resync.Client.download_to_temp_file | def download_to_temp_file(uri)
uri = Resync::XML.to_uri(uri)
@helper.fetch_to_file(uri: uri)
end | ruby | def download_to_temp_file(uri)
uri = Resync::XML.to_uri(uri)
@helper.fetch_to_file(uri: uri)
end | [
"def",
"download_to_temp_file",
"(",
"uri",
")",
"uri",
"=",
"Resync",
"::",
"XML",
".",
"to_uri",
"(",
"uri",
")",
"@helper",
".",
"fetch_to_file",
"(",
"uri",
":",
"uri",
")",
"end"
] | Gets the content of the specified URI and saves it to a temporary file.
@param uri [URI, String] the URI to download
@return [String] the path to the downloaded file | [
"Gets",
"the",
"content",
"of",
"the",
"specified",
"URI",
"and",
"saves",
"it",
"to",
"a",
"temporary",
"file",
"."
] | e621c9d0c8b8de436923359d6ad36f74c89bb2c2 | https://github.com/CDLUC3/resync-client/blob/e621c9d0c8b8de436923359d6ad36f74c89bb2c2/lib/resync/client.rb#L44-L47 |
5,328 | CDLUC3/resync-client | lib/resync/client.rb | Resync.Client.download_to_file | def download_to_file(uri:, path:)
uri = Resync::XML.to_uri(uri)
@helper.fetch_to_file(path: path, uri: uri)
end | ruby | def download_to_file(uri:, path:)
uri = Resync::XML.to_uri(uri)
@helper.fetch_to_file(path: path, uri: uri)
end | [
"def",
"download_to_file",
"(",
"uri",
":",
",",
"path",
":",
")",
"uri",
"=",
"Resync",
"::",
"XML",
".",
"to_uri",
"(",
"uri",
")",
"@helper",
".",
"fetch_to_file",
"(",
"path",
":",
"path",
",",
"uri",
":",
"uri",
")",
"end"
] | Gets the content of the specified URI and saves it to the specified file,
overwriting it if it exists.
@param uri [URI, String] the URI to download
@param path [String] the path to save the download to
@return [String] the path to the downloaded file | [
"Gets",
"the",
"content",
"of",
"the",
"specified",
"URI",
"and",
"saves",
"it",
"to",
"the",
"specified",
"file",
"overwriting",
"it",
"if",
"it",
"exists",
"."
] | e621c9d0c8b8de436923359d6ad36f74c89bb2c2 | https://github.com/CDLUC3/resync-client/blob/e621c9d0c8b8de436923359d6ad36f74c89bb2c2/lib/resync/client.rb#L54-L57 |
5,329 | ideonetwork/lato-core | lib/lato_core/interfaces/modules.rb | LatoCore.Interface::Modules.core__get_modules_list | def core__get_modules_list
all_gems = core__get_application_gems.keys
lato_gems = []
# check every gem
all_gems.each do |name|
lato_gems.push(name) if name.start_with? 'lato'
end
# return result
lato_gems
end | ruby | def core__get_modules_list
all_gems = core__get_application_gems.keys
lato_gems = []
# check every gem
all_gems.each do |name|
lato_gems.push(name) if name.start_with? 'lato'
end
# return result
lato_gems
end | [
"def",
"core__get_modules_list",
"all_gems",
"=",
"core__get_application_gems",
".",
"keys",
"lato_gems",
"=",
"[",
"]",
"# check every gem",
"all_gems",
".",
"each",
"do",
"|",
"name",
"|",
"lato_gems",
".",
"push",
"(",
"name",
")",
"if",
"name",
".",
"start_with?",
"'lato'",
"end",
"# return result",
"lato_gems",
"end"
] | This function returns the list of lato modules installed on main application. | [
"This",
"function",
"returns",
"the",
"list",
"of",
"lato",
"modules",
"installed",
"on",
"main",
"application",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/modules.rb#L15-L24 |
5,330 | ideonetwork/lato-core | lib/lato_core/interfaces/modules.rb | LatoCore.Interface::Modules.core__get_module_languages | def core__get_module_languages(module_name)
default_languages = core__get_module_default_languages(module_name)
application_languages = core__get_module_application_languages(module_name)
return default_languages unless application_languages
default_languages.each do |key, value|
application_languages[key] = value unless application_languages[key]
end
application_languages
end | ruby | def core__get_module_languages(module_name)
default_languages = core__get_module_default_languages(module_name)
application_languages = core__get_module_application_languages(module_name)
return default_languages unless application_languages
default_languages.each do |key, value|
application_languages[key] = value unless application_languages[key]
end
application_languages
end | [
"def",
"core__get_module_languages",
"(",
"module_name",
")",
"default_languages",
"=",
"core__get_module_default_languages",
"(",
"module_name",
")",
"application_languages",
"=",
"core__get_module_application_languages",
"(",
"module_name",
")",
"return",
"default_languages",
"unless",
"application_languages",
"default_languages",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"application_languages",
"[",
"key",
"]",
"=",
"value",
"unless",
"application_languages",
"[",
"key",
"]",
"end",
"application_languages",
"end"
] | This function load languages for a specific module.
This config are generated from the merge of application languages
for the module and default languages of the module. | [
"This",
"function",
"load",
"languages",
"for",
"a",
"specific",
"module",
".",
"This",
"config",
"are",
"generated",
"from",
"the",
"merge",
"of",
"application",
"languages",
"for",
"the",
"module",
"and",
"default",
"languages",
"of",
"the",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/modules.rb#L42-L52 |
5,331 | ideonetwork/lato-core | lib/lato_core/interfaces/modules.rb | LatoCore.Interface::Modules.core__get_module_configs | def core__get_module_configs module_name
default_config = core__get_module_default_configs(module_name)
application_config = core__get_module_application_configs(module_name)
return default_config unless application_config
default_config.each do |key, value|
application_config[key] = value unless application_config[key]
end
return application_config
end | ruby | def core__get_module_configs module_name
default_config = core__get_module_default_configs(module_name)
application_config = core__get_module_application_configs(module_name)
return default_config unless application_config
default_config.each do |key, value|
application_config[key] = value unless application_config[key]
end
return application_config
end | [
"def",
"core__get_module_configs",
"module_name",
"default_config",
"=",
"core__get_module_default_configs",
"(",
"module_name",
")",
"application_config",
"=",
"core__get_module_application_configs",
"(",
"module_name",
")",
"return",
"default_config",
"unless",
"application_config",
"default_config",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"application_config",
"[",
"key",
"]",
"=",
"value",
"unless",
"application_config",
"[",
"key",
"]",
"end",
"return",
"application_config",
"end"
] | This function load configs for a specific module.
This configs are generated from the merge of application configs for the module
and default configs of the module. | [
"This",
"function",
"load",
"configs",
"for",
"a",
"specific",
"module",
".",
"This",
"configs",
"are",
"generated",
"from",
"the",
"merge",
"of",
"application",
"configs",
"for",
"the",
"module",
"and",
"default",
"configs",
"of",
"the",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/modules.rb#L83-L93 |
5,332 | sinefunc/lunar | lib/lunar/index.rb | Lunar.Index.text | def text(att, value)
clear_text_field(att)
Scoring.new(value).scores.each do |word, score|
metaphone = Lunar.metaphone(word)
nest[att][metaphone].zadd(score, id)
metaphones[id][att].sadd(metaphone)
end
fields[TEXT].sadd(att)
end | ruby | def text(att, value)
clear_text_field(att)
Scoring.new(value).scores.each do |word, score|
metaphone = Lunar.metaphone(word)
nest[att][metaphone].zadd(score, id)
metaphones[id][att].sadd(metaphone)
end
fields[TEXT].sadd(att)
end | [
"def",
"text",
"(",
"att",
",",
"value",
")",
"clear_text_field",
"(",
"att",
")",
"Scoring",
".",
"new",
"(",
"value",
")",
".",
"scores",
".",
"each",
"do",
"|",
"word",
",",
"score",
"|",
"metaphone",
"=",
"Lunar",
".",
"metaphone",
"(",
"word",
")",
"nest",
"[",
"att",
"]",
"[",
"metaphone",
"]",
".",
"zadd",
"(",
"score",
",",
"id",
")",
"metaphones",
"[",
"id",
"]",
"[",
"att",
"]",
".",
"sadd",
"(",
"metaphone",
")",
"end",
"fields",
"[",
"TEXT",
"]",
".",
"sadd",
"(",
"att",
")",
"end"
] | Indexes all the metaphone equivalents of the words
in value except for words included in Stopwords.
@example
Lunar.index :Gadget do |i|
i.id 1001
i.text :title, "apple macbook pro"
end
# Executes the ff: in redis:
# ZADD Lunar:Gadget:title:APL 1 1001
# ZADD Lunar:Gadget:title:MKBK 1 1001
# ZADD Lunar:Gadget:title:PR 1 1001
# In addition a reference of all the words are stored
# SMEMBERS Lunar:Gadget:Metaphones:1001:title
# => (APL, MKBK, PR)
@param [Symbol] att the field name in your document
@param [String] value the content of the field name
@return [Array<String>] all the metaphones added for the document. | [
"Indexes",
"all",
"the",
"metaphone",
"equivalents",
"of",
"the",
"words",
"in",
"value",
"except",
"for",
"words",
"included",
"in",
"Stopwords",
"."
] | efc58f392dd75e771d313eef6cd4ada0d1ac02ff | https://github.com/sinefunc/lunar/blob/efc58f392dd75e771d313eef6cd4ada0d1ac02ff/lib/lunar/index.rb#L105-L116 |
5,333 | sinefunc/lunar | lib/lunar/index.rb | Lunar.Index.number | def number(att, value, purge = true)
if value.kind_of?(Enumerable)
clear_number_field(att)
value.each { |v| number(att, v, false) } and return
end
clear_number_field(att) if purge
numbers[att].zadd(value, id)
numbers[att][value].zadd(1, id)
numbers[id][att].sadd(value)
fields[NUMBERS].sadd att
end | ruby | def number(att, value, purge = true)
if value.kind_of?(Enumerable)
clear_number_field(att)
value.each { |v| number(att, v, false) } and return
end
clear_number_field(att) if purge
numbers[att].zadd(value, id)
numbers[att][value].zadd(1, id)
numbers[id][att].sadd(value)
fields[NUMBERS].sadd att
end | [
"def",
"number",
"(",
"att",
",",
"value",
",",
"purge",
"=",
"true",
")",
"if",
"value",
".",
"kind_of?",
"(",
"Enumerable",
")",
"clear_number_field",
"(",
"att",
")",
"value",
".",
"each",
"{",
"|",
"v",
"|",
"number",
"(",
"att",
",",
"v",
",",
"false",
")",
"}",
"and",
"return",
"end",
"clear_number_field",
"(",
"att",
")",
"if",
"purge",
"numbers",
"[",
"att",
"]",
".",
"zadd",
"(",
"value",
",",
"id",
")",
"numbers",
"[",
"att",
"]",
"[",
"value",
"]",
".",
"zadd",
"(",
"1",
",",
"id",
")",
"numbers",
"[",
"id",
"]",
"[",
"att",
"]",
".",
"sadd",
"(",
"value",
")",
"fields",
"[",
"NUMBERS",
"]",
".",
"sadd",
"att",
"end"
] | Adds a numeric index for `att` with `value`.
@example
Lunar.index :Gadget do |i|
i.id 1001
i.number :price, 200
end
# Executes the ff: in redis:
# ZADD Lunar:Gadget:price 200
@param [Symbol] att the field name in your document.
@param [Numeric] value the numeric value of `att`.
@return [Boolean] whether or not the value was added | [
"Adds",
"a",
"numeric",
"index",
"for",
"att",
"with",
"value",
"."
] | efc58f392dd75e771d313eef6cd4ada0d1ac02ff | https://github.com/sinefunc/lunar/blob/efc58f392dd75e771d313eef6cd4ada0d1ac02ff/lib/lunar/index.rb#L135-L149 |
5,334 | sinefunc/lunar | lib/lunar/index.rb | Lunar.Index.sortable | def sortable(att, value)
sortables[id][att].set(value)
fields[SORTABLES].sadd att
end | ruby | def sortable(att, value)
sortables[id][att].set(value)
fields[SORTABLES].sadd att
end | [
"def",
"sortable",
"(",
"att",
",",
"value",
")",
"sortables",
"[",
"id",
"]",
"[",
"att",
"]",
".",
"set",
"(",
"value",
")",
"fields",
"[",
"SORTABLES",
"]",
".",
"sadd",
"att",
"end"
] | Adds a sortable index for `att` with `value`.
@example
class Gadget
def self.[](id)
# find the gadget using id here
end
end
Lunar.index Gadget do |i|
i.id 1001
i.text 'apple macbook pro'
i.sortable :votes, 50
end
Lunar.index Gadget do |i|
i.id 1002
i.text 'apple iphone 3g'
i.sortable :votes, 20
end
results = Lunar.search(Gadget, :q => 'apple')
results.sort(:by => :votes, :order => 'DESC')
# returns [Gadget[1001], Gadget[1002]]
results.sort(:by => :votes, :order => 'ASC')
# returns [Gadget[1002], Gadget[1001]]
@param [Symbol] att the field you want to have sortability.
@param [String, Numeric] value the value of the sortable field.
@return [String] the response from the redis server. | [
"Adds",
"a",
"sortable",
"index",
"for",
"att",
"with",
"value",
"."
] | efc58f392dd75e771d313eef6cd4ada0d1ac02ff | https://github.com/sinefunc/lunar/blob/efc58f392dd75e771d313eef6cd4ada0d1ac02ff/lib/lunar/index.rb#L184-L188 |
5,335 | snusnu/substation | lib/substation/request.rb | Substation.Request.to_request | def to_request(new_input = Undefined)
new_input.equal?(Undefined) ? self : self.class.new(name, env, new_input)
end | ruby | def to_request(new_input = Undefined)
new_input.equal?(Undefined) ? self : self.class.new(name, env, new_input)
end | [
"def",
"to_request",
"(",
"new_input",
"=",
"Undefined",
")",
"new_input",
".",
"equal?",
"(",
"Undefined",
")",
"?",
"self",
":",
"self",
".",
"class",
".",
"new",
"(",
"name",
",",
"env",
",",
"new_input",
")",
"end"
] | Return self or a new instance with +input+
@param [Object] input
the input for the new instance
@return [self]
if +input+ is {Undefined}
@return [Request]
a new instance with +input+
@api private | [
"Return",
"self",
"or",
"a",
"new",
"instance",
"with",
"+",
"input",
"+"
] | fabf062a3640f5e82dae68597f0709b63f6b9027 | https://github.com/snusnu/substation/blob/fabf062a3640f5e82dae68597f0709b63f6b9027/lib/substation/request.rb#L81-L83 |
5,336 | ideonetwork/lato-core | lib/lato_core/interfaces/token.rb | LatoCore.Interface::Token.core__encode_token | def core__encode_token exp, payload
exp = 1.day.from_now unless exp
payload[:exp] = exp.to_i
JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
end | ruby | def core__encode_token exp, payload
exp = 1.day.from_now unless exp
payload[:exp] = exp.to_i
JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
end | [
"def",
"core__encode_token",
"exp",
",",
"payload",
"exp",
"=",
"1",
".",
"day",
".",
"from_now",
"unless",
"exp",
"payload",
"[",
":exp",
"]",
"=",
"exp",
".",
"to_i",
"JWT",
".",
"encode",
"(",
"payload",
",",
"Rails",
".",
"application",
".",
"secrets",
".",
"secret_key_base",
",",
"'HS256'",
")",
"end"
] | This functon return a token with encrypted payload information. | [
"This",
"functon",
"return",
"a",
"token",
"with",
"encrypted",
"payload",
"information",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/token.rb#L8-L12 |
5,337 | ideonetwork/lato-core | lib/lato_core/interfaces/token.rb | LatoCore.Interface::Token.core__decode_token | def core__decode_token token
begin
body = JWT.decode(token, Rails.application.secrets.secret_key_base,
true, algorithm: 'HS256')[0]
return HashWithIndifferentAccess.new body
rescue => exception
return nil
end
end | ruby | def core__decode_token token
begin
body = JWT.decode(token, Rails.application.secrets.secret_key_base,
true, algorithm: 'HS256')[0]
return HashWithIndifferentAccess.new body
rescue => exception
return nil
end
end | [
"def",
"core__decode_token",
"token",
"begin",
"body",
"=",
"JWT",
".",
"decode",
"(",
"token",
",",
"Rails",
".",
"application",
".",
"secrets",
".",
"secret_key_base",
",",
"true",
",",
"algorithm",
":",
"'HS256'",
")",
"[",
"0",
"]",
"return",
"HashWithIndifferentAccess",
".",
"new",
"body",
"rescue",
"=>",
"exception",
"return",
"nil",
"end",
"end"
] | This function return the payload of a token. | [
"This",
"function",
"return",
"the",
"payload",
"of",
"a",
"token",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/token.rb#L15-L23 |
5,338 | threez/marilyn-rpc | lib/marilyn-rpc/client.rb | MarilynRPC.NativeClient.authenticate | def authenticate(username, password, method = :plain)
execute(MarilynRPC::Service::AUTHENTICATION_PATH,
"authenticate_#{method}".to_sym, [username, password])
end | ruby | def authenticate(username, password, method = :plain)
execute(MarilynRPC::Service::AUTHENTICATION_PATH,
"authenticate_#{method}".to_sym, [username, password])
end | [
"def",
"authenticate",
"(",
"username",
",",
"password",
",",
"method",
"=",
":plain",
")",
"execute",
"(",
"MarilynRPC",
"::",
"Service",
"::",
"AUTHENTICATION_PATH",
",",
"\"authenticate_#{method}\"",
".",
"to_sym",
",",
"[",
"username",
",",
"password",
"]",
")",
"end"
] | authenicate the client to call methods that require authentication
@param [String] username the username of the client
@param [String] password the password of the client
@param [Symbol] method the method to use for authentication, currently
only plain is supported. So make sure you are using a secure socket. | [
"authenicate",
"the",
"client",
"to",
"call",
"methods",
"that",
"require",
"authentication"
] | e75b46b7dfe5040f4a5022b23702b5a29cf4844f | https://github.com/threez/marilyn-rpc/blob/e75b46b7dfe5040f4a5022b23702b5a29cf4844f/lib/marilyn-rpc/client.rb#L74-L77 |
5,339 | threez/marilyn-rpc | lib/marilyn-rpc/client.rb | MarilynRPC.NativeClient.execute | def execute(path, method, args)
thread = Thread.current
tag = "#{Time.now.to_f}:#{thread.object_id}"
@semaphore.synchronize {
# since this client can't multiplex, we set the tag to nil
@socket.write(MarilynRPC::MailFactory.build_call(tag, path, method, args))
# lets write our self to the list of waining threads
@threads[tag] = thread
}
# stop the current thread, the thread will be started after the response
# arrived
Thread.stop
# get mail from responses
mail = thread[MAIL_KEY]
if mail.is_a? MarilynRPC::CallResponseMail
mail.result
else
raise MarilynError.new # raise exception to capture the client backtrace
end
rescue MarilynError => exception
# add local and remote trace together and reraise the original exception
backtrace = []
backtrace += exception.backtrace
backtrace += mail.exception.backtrace
mail.exception.set_backtrace(backtrace)
raise mail.exception
end | ruby | def execute(path, method, args)
thread = Thread.current
tag = "#{Time.now.to_f}:#{thread.object_id}"
@semaphore.synchronize {
# since this client can't multiplex, we set the tag to nil
@socket.write(MarilynRPC::MailFactory.build_call(tag, path, method, args))
# lets write our self to the list of waining threads
@threads[tag] = thread
}
# stop the current thread, the thread will be started after the response
# arrived
Thread.stop
# get mail from responses
mail = thread[MAIL_KEY]
if mail.is_a? MarilynRPC::CallResponseMail
mail.result
else
raise MarilynError.new # raise exception to capture the client backtrace
end
rescue MarilynError => exception
# add local and remote trace together and reraise the original exception
backtrace = []
backtrace += exception.backtrace
backtrace += mail.exception.backtrace
mail.exception.set_backtrace(backtrace)
raise mail.exception
end | [
"def",
"execute",
"(",
"path",
",",
"method",
",",
"args",
")",
"thread",
"=",
"Thread",
".",
"current",
"tag",
"=",
"\"#{Time.now.to_f}:#{thread.object_id}\"",
"@semaphore",
".",
"synchronize",
"{",
"# since this client can't multiplex, we set the tag to nil",
"@socket",
".",
"write",
"(",
"MarilynRPC",
"::",
"MailFactory",
".",
"build_call",
"(",
"tag",
",",
"path",
",",
"method",
",",
"args",
")",
")",
"# lets write our self to the list of waining threads",
"@threads",
"[",
"tag",
"]",
"=",
"thread",
"}",
"# stop the current thread, the thread will be started after the response",
"# arrived",
"Thread",
".",
"stop",
"# get mail from responses",
"mail",
"=",
"thread",
"[",
"MAIL_KEY",
"]",
"if",
"mail",
".",
"is_a?",
"MarilynRPC",
"::",
"CallResponseMail",
"mail",
".",
"result",
"else",
"raise",
"MarilynError",
".",
"new",
"# raise exception to capture the client backtrace",
"end",
"rescue",
"MarilynError",
"=>",
"exception",
"# add local and remote trace together and reraise the original exception",
"backtrace",
"=",
"[",
"]",
"backtrace",
"+=",
"exception",
".",
"backtrace",
"backtrace",
"+=",
"mail",
".",
"exception",
".",
"backtrace",
"mail",
".",
"exception",
".",
"set_backtrace",
"(",
"backtrace",
")",
"raise",
"mail",
".",
"exception",
"end"
] | Executes a client call blocking. To issue an async call one needs to
have start separate threads. THe Native client uses then multiplexing to
avoid the other threads blocking.
@api private
@param [Object] path the path to identifiy the service
@param [Symbol, String] method the method name to call on the service
@param [Array<Object>] args the arguments that are passed to the remote
side
@return [Object] the result of the call | [
"Executes",
"a",
"client",
"call",
"blocking",
".",
"To",
"issue",
"an",
"async",
"call",
"one",
"needs",
"to",
"have",
"start",
"separate",
"threads",
".",
"THe",
"Native",
"client",
"uses",
"then",
"multiplexing",
"to",
"avoid",
"the",
"other",
"threads",
"blocking",
"."
] | e75b46b7dfe5040f4a5022b23702b5a29cf4844f | https://github.com/threez/marilyn-rpc/blob/e75b46b7dfe5040f4a5022b23702b5a29cf4844f/lib/marilyn-rpc/client.rb#L130-L161 |
5,340 | brianmichel/BadFruit | lib/badfruit/Movies/movies.rb | BadFruit.Movies.search_by_name | def search_by_name(name, page_limit=1, page=1)
if page_limit > 50
page_limit = MAX_PAGE_LIMIT #current limitation of the rotten tomatos API
end
results_json = @badfruit.search_movies(name, page_limit, page)
if results_json.nil?
return []
else
return @badfruit.parse_movies_array(JSON.parse(results_json))
end
end | ruby | def search_by_name(name, page_limit=1, page=1)
if page_limit > 50
page_limit = MAX_PAGE_LIMIT #current limitation of the rotten tomatos API
end
results_json = @badfruit.search_movies(name, page_limit, page)
if results_json.nil?
return []
else
return @badfruit.parse_movies_array(JSON.parse(results_json))
end
end | [
"def",
"search_by_name",
"(",
"name",
",",
"page_limit",
"=",
"1",
",",
"page",
"=",
"1",
")",
"if",
"page_limit",
">",
"50",
"page_limit",
"=",
"MAX_PAGE_LIMIT",
"#current limitation of the rotten tomatos API",
"end",
"results_json",
"=",
"@badfruit",
".",
"search_movies",
"(",
"name",
",",
"page_limit",
",",
"page",
")",
"if",
"results_json",
".",
"nil?",
"return",
"[",
"]",
"else",
"return",
"@badfruit",
".",
"parse_movies_array",
"(",
"JSON",
".",
"parse",
"(",
"results_json",
")",
")",
"end",
"end"
] | Initialize a wrapper around the Rotten Tomatoes API specific to movies.
Search for a movie by name.
@param [String] name The name of the movie to search for.
@param [Integer] page_limit The number of results to return for API response page. (Defaults to 1)
@param [Integer] page The page offset to request from the API. (Defaults to 1)
@return [Array<BadFruit::Movie>] An array of movie objects matching the name parameter. | [
"Initialize",
"a",
"wrapper",
"around",
"the",
"Rotten",
"Tomatoes",
"API",
"specific",
"to",
"movies",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/Movies/movies.rb#L25-L36 |
5,341 | brianmichel/BadFruit | lib/badfruit/Movies/movies.rb | BadFruit.Movies.search_by_id | def search_by_id(movie_id)
movie = @badfruit.get_movie_info(movie_id, "main")
raise 'Movie not found' if movie.nil? || movie.empty?
@badfruit.parse_movie_array(JSON.parse(movie))
end | ruby | def search_by_id(movie_id)
movie = @badfruit.get_movie_info(movie_id, "main")
raise 'Movie not found' if movie.nil? || movie.empty?
@badfruit.parse_movie_array(JSON.parse(movie))
end | [
"def",
"search_by_id",
"(",
"movie_id",
")",
"movie",
"=",
"@badfruit",
".",
"get_movie_info",
"(",
"movie_id",
",",
"\"main\"",
")",
"raise",
"'Movie not found'",
"if",
"movie",
".",
"nil?",
"||",
"movie",
".",
"empty?",
"@badfruit",
".",
"parse_movie_array",
"(",
"JSON",
".",
"parse",
"(",
"movie",
")",
")",
"end"
] | search by id
Search for a movie by Rotten Tomatoes id.
@param [String] movie_id The id of the movie to search for.
@return [BadFruit::Movie] A movie object from the response data. | [
"search",
"by",
"id"
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/Movies/movies.rb#L47-L51 |
5,342 | brianmichel/BadFruit | lib/badfruit/Movies/movies.rb | BadFruit.Movies.search_by_alias | def search_by_alias(alias_id, type='imdb')
movie = @badfruit.get_movie_alias_info(alias_id, type)
json = JSON.parse(movie)
raise 'Movie not found' if !json['error'].nil?
@badfruit.parse_movie_array(json)
end | ruby | def search_by_alias(alias_id, type='imdb')
movie = @badfruit.get_movie_alias_info(alias_id, type)
json = JSON.parse(movie)
raise 'Movie not found' if !json['error'].nil?
@badfruit.parse_movie_array(json)
end | [
"def",
"search_by_alias",
"(",
"alias_id",
",",
"type",
"=",
"'imdb'",
")",
"movie",
"=",
"@badfruit",
".",
"get_movie_alias_info",
"(",
"alias_id",
",",
"type",
")",
"json",
"=",
"JSON",
".",
"parse",
"(",
"movie",
")",
"raise",
"'Movie not found'",
"if",
"!",
"json",
"[",
"'error'",
"]",
".",
"nil?",
"@badfruit",
".",
"parse_movie_array",
"(",
"json",
")",
"end"
] | Search for a movie by way of a 3rd party id.
@param [String] alias_id The alias id of the movie.
@param [String] type The type of alias id that is being provided. (Defaults to 'imdb')
@return [BadFruit::Movie] A movie object representing the 3rd party id.
@note Currently only 'imdb' as a type is supported. | [
"Search",
"for",
"a",
"movie",
"by",
"way",
"of",
"a",
"3rd",
"party",
"id",
"."
] | dab9c28d4bcd79d64829239abf6a816bbbcc73a6 | https://github.com/brianmichel/BadFruit/blob/dab9c28d4bcd79d64829239abf6a816bbbcc73a6/lib/badfruit/Movies/movies.rb#L62-L67 |
5,343 | onesky/one_sky-ruby | lib/one_sky/translation.rb | OneSky.Translation.dashify_string_hash | def dashify_string_hash(string_hash)
output = Hash.new
string_hash.each do |key, value|
dashed = key.to_s.gsub("_", "-").to_sym
output[dashed] = value
end
output
end | ruby | def dashify_string_hash(string_hash)
output = Hash.new
string_hash.each do |key, value|
dashed = key.to_s.gsub("_", "-").to_sym
output[dashed] = value
end
output
end | [
"def",
"dashify_string_hash",
"(",
"string_hash",
")",
"output",
"=",
"Hash",
".",
"new",
"string_hash",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"dashed",
"=",
"key",
".",
"to_s",
".",
"gsub",
"(",
"\"_\"",
",",
"\"-\"",
")",
".",
"to_sym",
"output",
"[",
"dashed",
"]",
"=",
"value",
"end",
"output",
"end"
] | convert to "string-key" not "string_key" | [
"convert",
"to",
"string",
"-",
"key",
"not",
"string_key"
] | cc1ae294073086b7aab66340416062aaee59a160 | https://github.com/onesky/one_sky-ruby/blob/cc1ae294073086b7aab66340416062aaee59a160/lib/one_sky/translation.rb#L131-L138 |
5,344 | sunlightlabs/ruby-sunlight | lib/sunlight/legislator.rb | Sunlight.Legislator.committees | def committees
url = Sunlight::Base.construct_url("committees.allForLegislator", {:bioguide_id => self.bioguide_id})
if (result = Sunlight::Base.get_json_data(url))
committees = []
result["response"]["committees"].each do |committee|
committees << Sunlight::Committee.new(committee["committee"])
end
else
nil # appropriate params not found
end
committees
end | ruby | def committees
url = Sunlight::Base.construct_url("committees.allForLegislator", {:bioguide_id => self.bioguide_id})
if (result = Sunlight::Base.get_json_data(url))
committees = []
result["response"]["committees"].each do |committee|
committees << Sunlight::Committee.new(committee["committee"])
end
else
nil # appropriate params not found
end
committees
end | [
"def",
"committees",
"url",
"=",
"Sunlight",
"::",
"Base",
".",
"construct_url",
"(",
"\"committees.allForLegislator\"",
",",
"{",
":bioguide_id",
"=>",
"self",
".",
"bioguide_id",
"}",
")",
"if",
"(",
"result",
"=",
"Sunlight",
"::",
"Base",
".",
"get_json_data",
"(",
"url",
")",
")",
"committees",
"=",
"[",
"]",
"result",
"[",
"\"response\"",
"]",
"[",
"\"committees\"",
"]",
".",
"each",
"do",
"|",
"committee",
"|",
"committees",
"<<",
"Sunlight",
"::",
"Committee",
".",
"new",
"(",
"committee",
"[",
"\"committee\"",
"]",
")",
"end",
"else",
"nil",
"# appropriate params not found",
"end",
"committees",
"end"
] | Get the committees the Legislator sits on
Returns:
An array of Committee objects, each possibly
having its own subarray of subcommittees | [
"Get",
"the",
"committees",
"the",
"Legislator",
"sits",
"on"
] | 239063ccf26fadaf64d650fd3c22bcc734cc3394 | https://github.com/sunlightlabs/ruby-sunlight/blob/239063ccf26fadaf64d650fd3c22bcc734cc3394/lib/sunlight/legislator.rb#L32-L44 |
5,345 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.get_access_token | def get_access_token
@client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret)
request_token = @client.request_token
# ask the user to visit the auth url
puts "To authenticate your client, visit the URL: #{request_token.authorize_url}"
open_link request_token.authorize_url
# wait for the user to give us the PIN back
print 'Enter PIN: '
begin
@client.authorize(request_token.token, request_token.secret, :oauth_verifier => self.class.get_input.chomp)
rescue OAuth::Unauthorized
false # Didn't get an access token
end
end | ruby | def get_access_token
@client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret)
request_token = @client.request_token
# ask the user to visit the auth url
puts "To authenticate your client, visit the URL: #{request_token.authorize_url}"
open_link request_token.authorize_url
# wait for the user to give us the PIN back
print 'Enter PIN: '
begin
@client.authorize(request_token.token, request_token.secret, :oauth_verifier => self.class.get_input.chomp)
rescue OAuth::Unauthorized
false # Didn't get an access token
end
end | [
"def",
"get_access_token",
"@client",
"=",
"TwitterOAuth",
"::",
"Client",
".",
"new",
"(",
":consumer_key",
"=>",
"ConsumerKey",
",",
":consumer_secret",
"=>",
"ConsumerSecret",
")",
"request_token",
"=",
"@client",
".",
"request_token",
"# ask the user to visit the auth url",
"puts",
"\"To authenticate your client, visit the URL: #{request_token.authorize_url}\"",
"open_link",
"request_token",
".",
"authorize_url",
"# wait for the user to give us the PIN back",
"print",
"'Enter PIN: '",
"begin",
"@client",
".",
"authorize",
"(",
"request_token",
".",
"token",
",",
"request_token",
".",
"secret",
",",
":oauth_verifier",
"=>",
"self",
".",
"class",
".",
"get_input",
".",
"chomp",
")",
"rescue",
"OAuth",
"::",
"Unauthorized",
"false",
"# Didn't get an access token",
"end",
"end"
] | Prompt the user for a PIN using a request token, and see if we can successfully authenticate them | [
"Prompt",
"the",
"user",
"for",
"a",
"PIN",
"using",
"a",
"request",
"token",
"and",
"see",
"if",
"we",
"can",
"successfully",
"authenticate",
"them"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L46-L59 |
5,346 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.timeline | def timeline(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# Only send since_id to @client if it's not nil
home_timeline = since_id ? @client.home_timeline(:since_id => since_id) : @client.home_timeline
if home_timeline.any?
print_tweets(home_timeline)
# Save the last id as since_id
self.since_id = home_timeline.last['id']
end
end | ruby | def timeline(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# Only send since_id to @client if it's not nil
home_timeline = since_id ? @client.home_timeline(:since_id => since_id) : @client.home_timeline
if home_timeline.any?
print_tweets(home_timeline)
# Save the last id as since_id
self.since_id = home_timeline.last['id']
end
end | [
"def",
"timeline",
"(",
"*",
"args",
")",
"load_default_token",
"return",
"failtown",
"(",
"\"Unauthorized, re-run setup!\"",
")",
"unless",
"@client",
"&&",
"@client",
".",
"authorized?",
"# Only send since_id to @client if it's not nil",
"home_timeline",
"=",
"since_id",
"?",
"@client",
".",
"home_timeline",
"(",
":since_id",
"=>",
"since_id",
")",
":",
"@client",
".",
"home_timeline",
"if",
"home_timeline",
".",
"any?",
"print_tweets",
"(",
"home_timeline",
")",
"# Save the last id as since_id",
"self",
".",
"since_id",
"=",
"home_timeline",
".",
"last",
"[",
"'id'",
"]",
"end",
"end"
] | Display the user's timeline | [
"Display",
"the",
"user",
"s",
"timeline"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L62-L72 |
5,347 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.tweet | def tweet(*args)
load_default_token
# get it from them directly
tweet_text = args.join(' ').strip
# or let them append / or pipe
tweet_text += (tweet_text.empty? ? '' : ' ') + STDIN.read unless STDIN.tty?
# or let them get prompted for it
if tweet_text.empty?
print 'Tweet (Press return to finish): '
tweet_text = STDIN.gets.strip
end
return failtown("Empty Tweet") if tweet_text.empty?
return failtown("Tweet is too long!") if tweet_text.scan(/./mu).size > 140
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# actually post it
@client.update(tweet_text)
puts "Tweet Posted!"
end | ruby | def tweet(*args)
load_default_token
# get it from them directly
tweet_text = args.join(' ').strip
# or let them append / or pipe
tweet_text += (tweet_text.empty? ? '' : ' ') + STDIN.read unless STDIN.tty?
# or let them get prompted for it
if tweet_text.empty?
print 'Tweet (Press return to finish): '
tweet_text = STDIN.gets.strip
end
return failtown("Empty Tweet") if tweet_text.empty?
return failtown("Tweet is too long!") if tweet_text.scan(/./mu).size > 140
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# actually post it
@client.update(tweet_text)
puts "Tweet Posted!"
end | [
"def",
"tweet",
"(",
"*",
"args",
")",
"load_default_token",
"# get it from them directly",
"tweet_text",
"=",
"args",
".",
"join",
"(",
"' '",
")",
".",
"strip",
"# or let them append / or pipe",
"tweet_text",
"+=",
"(",
"tweet_text",
".",
"empty?",
"?",
"''",
":",
"' '",
")",
"+",
"STDIN",
".",
"read",
"unless",
"STDIN",
".",
"tty?",
"# or let them get prompted for it",
"if",
"tweet_text",
".",
"empty?",
"print",
"'Tweet (Press return to finish): '",
"tweet_text",
"=",
"STDIN",
".",
"gets",
".",
"strip",
"end",
"return",
"failtown",
"(",
"\"Empty Tweet\"",
")",
"if",
"tweet_text",
".",
"empty?",
"return",
"failtown",
"(",
"\"Tweet is too long!\"",
")",
"if",
"tweet_text",
".",
"scan",
"(",
"/",
"/mu",
")",
".",
"size",
">",
"140",
"return",
"failtown",
"(",
"\"Unauthorized, re-run setup!\"",
")",
"unless",
"@client",
"&&",
"@client",
".",
"authorized?",
"# actually post it",
"@client",
".",
"update",
"(",
"tweet_text",
")",
"puts",
"\"Tweet Posted!\"",
"end"
] | Send a tweet for the user | [
"Send",
"a",
"tweet",
"for",
"the",
"user"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L75-L92 |
5,348 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.show | def show(args)
# If we have no user to get, use the timeline instead
return timeline(args) if args.nil? || args.count == 0
target_user = args[0]
# Get the timeline and print the tweets if we don't get an error
load_default_token # for private tweets
res = @client.user_timeline(:screen_name => target_user)
return failtown("show :: #{res['error']}") if !res || res.include?('error')
print_tweets(res)
end | ruby | def show(args)
# If we have no user to get, use the timeline instead
return timeline(args) if args.nil? || args.count == 0
target_user = args[0]
# Get the timeline and print the tweets if we don't get an error
load_default_token # for private tweets
res = @client.user_timeline(:screen_name => target_user)
return failtown("show :: #{res['error']}") if !res || res.include?('error')
print_tweets(res)
end | [
"def",
"show",
"(",
"args",
")",
"# If we have no user to get, use the timeline instead",
"return",
"timeline",
"(",
"args",
")",
"if",
"args",
".",
"nil?",
"||",
"args",
".",
"count",
"==",
"0",
"target_user",
"=",
"args",
"[",
"0",
"]",
"# Get the timeline and print the tweets if we don't get an error",
"load_default_token",
"# for private tweets",
"res",
"=",
"@client",
".",
"user_timeline",
"(",
":screen_name",
"=>",
"target_user",
")",
"return",
"failtown",
"(",
"\"show :: #{res['error']}\"",
")",
"if",
"!",
"res",
"||",
"res",
".",
"include?",
"(",
"'error'",
")",
"print_tweets",
"(",
"res",
")",
"end"
] | Get 20 most recent statuses of user, or specified user | [
"Get",
"20",
"most",
"recent",
"statuses",
"of",
"user",
"or",
"specified",
"user"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L95-L104 |
5,349 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.status | def status(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
user = @client.info
status = user['status']
puts "#{user['name']} (at #{status['created_at']}) #{status['text']}" unless status.nil?
end | ruby | def status(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
user = @client.info
status = user['status']
puts "#{user['name']} (at #{status['created_at']}) #{status['text']}" unless status.nil?
end | [
"def",
"status",
"(",
"*",
"args",
")",
"load_default_token",
"return",
"failtown",
"(",
"\"Unauthorized, re-run setup!\"",
")",
"unless",
"@client",
"&&",
"@client",
".",
"authorized?",
"user",
"=",
"@client",
".",
"info",
"status",
"=",
"user",
"[",
"'status'",
"]",
"puts",
"\"#{user['name']} (at #{status['created_at']}) #{status['text']}\"",
"unless",
"status",
".",
"nil?",
"end"
] | Get the user's most recent status | [
"Get",
"the",
"user",
"s",
"most",
"recent",
"status"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L107-L113 |
5,350 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.setup | def setup(*args)
# Keep trying to get the access token
until @access_token = self.get_access_token
print "Try again? [Y/n] "
return false if self.class.get_input.downcase == 'n'
end
# When we finally get it, record it in a dotfile
tokens = {:default => { :token => @access_token.token, :secret => @access_token.secret }}
save_tokens(tokens)
end | ruby | def setup(*args)
# Keep trying to get the access token
until @access_token = self.get_access_token
print "Try again? [Y/n] "
return false if self.class.get_input.downcase == 'n'
end
# When we finally get it, record it in a dotfile
tokens = {:default => { :token => @access_token.token, :secret => @access_token.secret }}
save_tokens(tokens)
end | [
"def",
"setup",
"(",
"*",
"args",
")",
"# Keep trying to get the access token",
"until",
"@access_token",
"=",
"self",
".",
"get_access_token",
"print",
"\"Try again? [Y/n] \"",
"return",
"false",
"if",
"self",
".",
"class",
".",
"get_input",
".",
"downcase",
"==",
"'n'",
"end",
"# When we finally get it, record it in a dotfile",
"tokens",
"=",
"{",
":default",
"=>",
"{",
":token",
"=>",
"@access_token",
".",
"token",
",",
":secret",
"=>",
"@access_token",
".",
"secret",
"}",
"}",
"save_tokens",
"(",
"tokens",
")",
"end"
] | Get the access token for the user and save it | [
"Get",
"the",
"access",
"token",
"for",
"the",
"user",
"and",
"save",
"it"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L116-L125 |
5,351 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.replies | def replies(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# Only send since_id_replies to @client if it's not nil
mentions = since_id_replies ? @client.mentions(:since_id => since_id_replies) : @client.mentions
if mentions.any?
print_tweets(mentions)
# Save the last id as since_id
self.since_id_replies = mentions.last['id']
end
end | ruby | def replies(*args)
load_default_token
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
# Only send since_id_replies to @client if it's not nil
mentions = since_id_replies ? @client.mentions(:since_id => since_id_replies) : @client.mentions
if mentions.any?
print_tweets(mentions)
# Save the last id as since_id
self.since_id_replies = mentions.last['id']
end
end | [
"def",
"replies",
"(",
"*",
"args",
")",
"load_default_token",
"return",
"failtown",
"(",
"\"Unauthorized, re-run setup!\"",
")",
"unless",
"@client",
"&&",
"@client",
".",
"authorized?",
"# Only send since_id_replies to @client if it's not nil",
"mentions",
"=",
"since_id_replies",
"?",
"@client",
".",
"mentions",
"(",
":since_id",
"=>",
"since_id_replies",
")",
":",
"@client",
".",
"mentions",
"if",
"mentions",
".",
"any?",
"print_tweets",
"(",
"mentions",
")",
"# Save the last id as since_id",
"self",
".",
"since_id_replies",
"=",
"mentions",
".",
"last",
"[",
"'id'",
"]",
"end",
"end"
] | Returns the 20 most recent @replies / mentions | [
"Returns",
"the",
"20",
"most",
"recent"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L128-L138 |
5,352 | seejohnrun/console_tweet | lib/console_tweet/cli.rb | ConsoleTweet.CLI.help | def help(*args)
puts "#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <[email protected]>"
puts 'http://github.com/seejohnrun/console-tweet'
puts
puts "#{CommandColor}twitter#{DefaultColor} View your timeline, since last view"
puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account"
puts "#{CommandColor}twitter status#{DefaultColor} Get your most recent status"
puts "#{CommandColor}twitter tweet \"Hello World\"#{DefaultColor} Send out a tweet"
puts "#{CommandColor}twitter show [username]#{DefaultColor} Show the timeline for a user"
puts "#{CommandColor}twitter replies#{DefaultColor} Get the most recent @replies and mentions"
end | ruby | def help(*args)
puts "#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <[email protected]>"
puts 'http://github.com/seejohnrun/console-tweet'
puts
puts "#{CommandColor}twitter#{DefaultColor} View your timeline, since last view"
puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account"
puts "#{CommandColor}twitter status#{DefaultColor} Get your most recent status"
puts "#{CommandColor}twitter tweet \"Hello World\"#{DefaultColor} Send out a tweet"
puts "#{CommandColor}twitter show [username]#{DefaultColor} Show the timeline for a user"
puts "#{CommandColor}twitter replies#{DefaultColor} Get the most recent @replies and mentions"
end | [
"def",
"help",
"(",
"*",
"args",
")",
"puts",
"\"#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <[email protected]>\"",
"puts",
"'http://github.com/seejohnrun/console-tweet'",
"puts",
"puts",
"\"#{CommandColor}twitter#{DefaultColor} View your timeline, since last view\"",
"puts",
"\"#{CommandColor}twitter setup#{DefaultColor} Setup your account\"",
"puts",
"\"#{CommandColor}twitter status#{DefaultColor} Get your most recent status\"",
"puts",
"\"#{CommandColor}twitter tweet \\\"Hello World\\\"#{DefaultColor} Send out a tweet\"",
"puts",
"\"#{CommandColor}twitter show [username]#{DefaultColor} Show the timeline for a user\"",
"puts",
"\"#{CommandColor}twitter replies#{DefaultColor} Get the most recent @replies and mentions\"",
"end"
] | Display help section | [
"Display",
"help",
"section"
] | 6920bb0ead3060ac52eb968bc0df3c21b72e1ff6 | https://github.com/seejohnrun/console_tweet/blob/6920bb0ead3060ac52eb968bc0df3c21b72e1ff6/lib/console_tweet/cli.rb#L141-L151 |
5,353 | ubcsanskrit/sanscript.rb | lib/sanscript/benchmark.rb | Sanscript.Benchmark.detect! | def detect!(time = 2, warmup = 1)
::Benchmark.ips do |x|
x.config(time: time, warmup: warmup)
TEST_STRINGS_FLAT.each do |scheme, string|
x.report("Detect #{scheme}") do
Sanscript::Detect.detect_scheme(string)
end
end
x.compare!
end
true
end | ruby | def detect!(time = 2, warmup = 1)
::Benchmark.ips do |x|
x.config(time: time, warmup: warmup)
TEST_STRINGS_FLAT.each do |scheme, string|
x.report("Detect #{scheme}") do
Sanscript::Detect.detect_scheme(string)
end
end
x.compare!
end
true
end | [
"def",
"detect!",
"(",
"time",
"=",
"2",
",",
"warmup",
"=",
"1",
")",
"::",
"Benchmark",
".",
"ips",
"do",
"|",
"x",
"|",
"x",
".",
"config",
"(",
"time",
":",
"time",
",",
"warmup",
":",
"warmup",
")",
"TEST_STRINGS_FLAT",
".",
"each",
"do",
"|",
"scheme",
",",
"string",
"|",
"x",
".",
"report",
"(",
"\"Detect #{scheme}\"",
")",
"do",
"Sanscript",
"::",
"Detect",
".",
"detect_scheme",
"(",
"string",
")",
"end",
"end",
"x",
".",
"compare!",
"end",
"true",
"end"
] | Runs benchmark-ips test on detection methods. | [
"Runs",
"benchmark",
"-",
"ips",
"test",
"on",
"detection",
"methods",
"."
] | 0e50c4a856599a7b13c9f0cbc281206245859c71 | https://github.com/ubcsanskrit/sanscript.rb/blob/0e50c4a856599a7b13c9f0cbc281206245859c71/lib/sanscript/benchmark.rb#L51-L62 |
5,354 | ubcsanskrit/sanscript.rb | lib/sanscript/benchmark.rb | Sanscript.Benchmark.transliterate_roman! | def transliterate_roman!(time = 2, warmup = 1)
::Benchmark.ips do |x|
x.config(time: time, warmup: warmup)
TEST_STRINGS[:roman].to_a.product(TEST_STRINGS_FLAT.keys).each do |(ak, av), bk|
next if ak == bk
x.report("#{ak} => #{bk}") do
Sanscript.transliterate(av, ak, bk)
end
end
x.compare!
end
true
end | ruby | def transliterate_roman!(time = 2, warmup = 1)
::Benchmark.ips do |x|
x.config(time: time, warmup: warmup)
TEST_STRINGS[:roman].to_a.product(TEST_STRINGS_FLAT.keys).each do |(ak, av), bk|
next if ak == bk
x.report("#{ak} => #{bk}") do
Sanscript.transliterate(av, ak, bk)
end
end
x.compare!
end
true
end | [
"def",
"transliterate_roman!",
"(",
"time",
"=",
"2",
",",
"warmup",
"=",
"1",
")",
"::",
"Benchmark",
".",
"ips",
"do",
"|",
"x",
"|",
"x",
".",
"config",
"(",
"time",
":",
"time",
",",
"warmup",
":",
"warmup",
")",
"TEST_STRINGS",
"[",
":roman",
"]",
".",
"to_a",
".",
"product",
"(",
"TEST_STRINGS_FLAT",
".",
"keys",
")",
".",
"each",
"do",
"|",
"(",
"ak",
",",
"av",
")",
",",
"bk",
"|",
"next",
"if",
"ak",
"==",
"bk",
"x",
".",
"report",
"(",
"\"#{ak} => #{bk}\"",
")",
"do",
"Sanscript",
".",
"transliterate",
"(",
"av",
",",
"ak",
",",
"bk",
")",
"end",
"end",
"x",
".",
"compare!",
"end",
"true",
"end"
] | Runs benchmark-ips test on roman-source transliteration methods. | [
"Runs",
"benchmark",
"-",
"ips",
"test",
"on",
"roman",
"-",
"source",
"transliteration",
"methods",
"."
] | 0e50c4a856599a7b13c9f0cbc281206245859c71 | https://github.com/ubcsanskrit/sanscript.rb/blob/0e50c4a856599a7b13c9f0cbc281206245859c71/lib/sanscript/benchmark.rb#L65-L77 |
5,355 | mastahyeti/ifdef | lib/ifdef/logic_processor.rb | Ifdef.LogicProcessor.on_or | def on_or(node)
a, b = node.children.map { |c| @truth.fetch(c, process(c)) }
if a == :true || b == :true
:true
elsif a == :false && b == :false
:false
else
nil
end
end | ruby | def on_or(node)
a, b = node.children.map { |c| @truth.fetch(c, process(c)) }
if a == :true || b == :true
:true
elsif a == :false && b == :false
:false
else
nil
end
end | [
"def",
"on_or",
"(",
"node",
")",
"a",
",",
"b",
"=",
"node",
".",
"children",
".",
"map",
"{",
"|",
"c",
"|",
"@truth",
".",
"fetch",
"(",
"c",
",",
"process",
"(",
"c",
")",
")",
"}",
"if",
"a",
"==",
":true",
"||",
"b",
"==",
":true",
":true",
"elsif",
"a",
"==",
":false",
"&&",
"b",
"==",
":false",
":false",
"else",
"nil",
"end",
"end"
] | Handle the `||` statement.
node - the node to evaluate.
Returns :true if either side is known to be true, :false if both sides are
known to be false, and nil otherwise. | [
"Handle",
"the",
"||",
"statement",
"."
] | ad19060782b0fb9bf6c345272739b3bf4bd349f6 | https://github.com/mastahyeti/ifdef/blob/ad19060782b0fb9bf6c345272739b3bf4bd349f6/lib/ifdef/logic_processor.rb#L33-L43 |
5,356 | mastahyeti/ifdef | lib/ifdef/logic_processor.rb | Ifdef.LogicProcessor.on_send | def on_send(node)
_target, _method, _args = node.children
if _method == :!
case @truth.fetch(_target, process(_target))
when :true
:false
when :false
:true
else
nil
end
else
nil
end
end | ruby | def on_send(node)
_target, _method, _args = node.children
if _method == :!
case @truth.fetch(_target, process(_target))
when :true
:false
when :false
:true
else
nil
end
else
nil
end
end | [
"def",
"on_send",
"(",
"node",
")",
"_target",
",",
"_method",
",",
"_args",
"=",
"node",
".",
"children",
"if",
"_method",
"==",
":!",
"case",
"@truth",
".",
"fetch",
"(",
"_target",
",",
"process",
"(",
"_target",
")",
")",
"when",
":true",
":false",
"when",
":false",
":true",
"else",
"nil",
"end",
"else",
"nil",
"end",
"end"
] | Handles the `!` statement.
node - the node to evaluate.
Returns the inverse of the child expression. | [
"Handles",
"the",
"!",
"statement",
"."
] | ad19060782b0fb9bf6c345272739b3bf4bd349f6 | https://github.com/mastahyeti/ifdef/blob/ad19060782b0fb9bf6c345272739b3bf4bd349f6/lib/ifdef/logic_processor.rb#L69-L84 |
5,357 | mastahyeti/ifdef | lib/ifdef/logic_processor.rb | Ifdef.LogicProcessor.on_begin | def on_begin(node)
child, other_children = *node.children
# Not sure if this can happen in an `if` statement
raise LogicError if other_children
case @truth.fetch(child, process(child))
when :true
:true
when :false
:false
else
nil
end
end | ruby | def on_begin(node)
child, other_children = *node.children
# Not sure if this can happen in an `if` statement
raise LogicError if other_children
case @truth.fetch(child, process(child))
when :true
:true
when :false
:false
else
nil
end
end | [
"def",
"on_begin",
"(",
"node",
")",
"child",
",",
"other_children",
"=",
"node",
".",
"children",
"# Not sure if this can happen in an `if` statement",
"raise",
"LogicError",
"if",
"other_children",
"case",
"@truth",
".",
"fetch",
"(",
"child",
",",
"process",
"(",
"child",
")",
")",
"when",
":true",
":true",
"when",
":false",
":false",
"else",
"nil",
"end",
"end"
] | Handle logic statements explicitly wrapped in parenthesis.
node - the node to evaluate.
Returns the result of the statement within the parenthesis. | [
"Handle",
"logic",
"statements",
"explicitly",
"wrapped",
"in",
"parenthesis",
"."
] | ad19060782b0fb9bf6c345272739b3bf4bd349f6 | https://github.com/mastahyeti/ifdef/blob/ad19060782b0fb9bf6c345272739b3bf4bd349f6/lib/ifdef/logic_processor.rb#L91-L105 |
5,358 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.remote_shell | def remote_shell(&block)
each_dest.map do |dest|
shell = if dest.scheme == 'file'
LocalShell
else
RemoteShell
end
shell.new(dest,self,&block)
end
end | ruby | def remote_shell(&block)
each_dest.map do |dest|
shell = if dest.scheme == 'file'
LocalShell
else
RemoteShell
end
shell.new(dest,self,&block)
end
end | [
"def",
"remote_shell",
"(",
"&",
"block",
")",
"each_dest",
".",
"map",
"do",
"|",
"dest",
"|",
"shell",
"=",
"if",
"dest",
".",
"scheme",
"==",
"'file'",
"LocalShell",
"else",
"RemoteShell",
"end",
"shell",
".",
"new",
"(",
"dest",
",",
"self",
",",
"block",
")",
"end",
"end"
] | Creates a remote shell with the destination server.
@yield [shell]
If a block is given, it will be passed the new remote shell.
@yieldparam [LocalShell, RemoteShell] shell
The remote shell.
@return [Array<RemoteShell, LocalShell>]
The remote shell. If the destination is a local `file://` URI,
a local shell will be returned instead.
@since 0.3.0 | [
"Creates",
"a",
"remote",
"shell",
"with",
"the",
"destination",
"server",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L94-L104 |
5,359 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.exec | def exec(command)
remote_shell do |shell|
shell.cd(shell.uri.path)
shell.exec(command)
end
return true
end | ruby | def exec(command)
remote_shell do |shell|
shell.cd(shell.uri.path)
shell.exec(command)
end
return true
end | [
"def",
"exec",
"(",
"command",
")",
"remote_shell",
"do",
"|",
"shell",
"|",
"shell",
".",
"cd",
"(",
"shell",
".",
"uri",
".",
"path",
")",
"shell",
".",
"exec",
"(",
"command",
")",
"end",
"return",
"true",
"end"
] | Runs a command on the destination server, in the destination
directory.
@return [true]
@since 0.3.0 | [
"Runs",
"a",
"command",
"on",
"the",
"destination",
"server",
"in",
"the",
"destination",
"directory",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L114-L121 |
5,360 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.rake | def rake(task,*arguments)
remote_shell do |shell|
shell.cd(shell.uri.path)
shell.rake(task,*arguments)
end
return true
end | ruby | def rake(task,*arguments)
remote_shell do |shell|
shell.cd(shell.uri.path)
shell.rake(task,*arguments)
end
return true
end | [
"def",
"rake",
"(",
"task",
",",
"*",
"arguments",
")",
"remote_shell",
"do",
"|",
"shell",
"|",
"shell",
".",
"cd",
"(",
"shell",
".",
"uri",
".",
"path",
")",
"shell",
".",
"rake",
"(",
"task",
",",
"arguments",
")",
"end",
"return",
"true",
"end"
] | Executes a Rake task on the destination server, in the destination
directory.
@return [true]
@since 0.3.0 | [
"Executes",
"a",
"Rake",
"task",
"on",
"the",
"destination",
"server",
"in",
"the",
"destination",
"directory",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L131-L138 |
5,361 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.ssh | def ssh(*arguments)
each_dest do |dest|
RemoteShell.new(dest).ssh(*arguments)
end
return true
end | ruby | def ssh(*arguments)
each_dest do |dest|
RemoteShell.new(dest).ssh(*arguments)
end
return true
end | [
"def",
"ssh",
"(",
"*",
"arguments",
")",
"each_dest",
"do",
"|",
"dest",
"|",
"RemoteShell",
".",
"new",
"(",
"dest",
")",
".",
"ssh",
"(",
"arguments",
")",
"end",
"return",
"true",
"end"
] | Starts an SSH session with the destination server.
@param [Array] arguments
Additional arguments to pass to SSH.
@return [true]
@since 0.3.0 | [
"Starts",
"an",
"SSH",
"session",
"with",
"the",
"destination",
"server",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L150-L156 |
5,362 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.setup | def setup(shell)
shell.status "Cloning #{@source} ..."
shell.run 'git', 'clone', '--depth', 1, @source, shell.uri.path
shell.status "Cloned #{@source}."
end | ruby | def setup(shell)
shell.status "Cloning #{@source} ..."
shell.run 'git', 'clone', '--depth', 1, @source, shell.uri.path
shell.status "Cloned #{@source}."
end | [
"def",
"setup",
"(",
"shell",
")",
"shell",
".",
"status",
"\"Cloning #{@source} ...\"",
"shell",
".",
"run",
"'git'",
",",
"'clone'",
",",
"'--depth'",
",",
"1",
",",
"@source",
",",
"shell",
".",
"uri",
".",
"path",
"shell",
".",
"status",
"\"Cloned #{@source}.\"",
"end"
] | Sets up the deployment repository for the project.
@param [Shell] shell
The remote shell to execute commands through.
@since 0.3.0 | [
"Sets",
"up",
"the",
"deployment",
"repository",
"for",
"the",
"project",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L166-L172 |
5,363 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.update | def update(shell)
shell.status "Updating ..."
shell.run 'git', 'reset', '--hard', 'HEAD'
shell.run 'git', 'pull', '-f'
shell.status "Updated."
end | ruby | def update(shell)
shell.status "Updating ..."
shell.run 'git', 'reset', '--hard', 'HEAD'
shell.run 'git', 'pull', '-f'
shell.status "Updated."
end | [
"def",
"update",
"(",
"shell",
")",
"shell",
".",
"status",
"\"Updating ...\"",
"shell",
".",
"run",
"'git'",
",",
"'reset'",
",",
"'--hard'",
",",
"'HEAD'",
"shell",
".",
"run",
"'git'",
",",
"'pull'",
",",
"'-f'",
"shell",
".",
"status",
"\"Updated.\"",
"end"
] | Updates the deployed repository for the project.
@param [Shell] shell
The remote shell to execute commands through.
@since 0.3.0 | [
"Updates",
"the",
"deployed",
"repository",
"for",
"the",
"project",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L182-L189 |
5,364 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.invoke_task | def invoke_task(task,shell)
unless TASKS.include?(task)
raise("invalid task: #{task}")
end
if @before.has_key?(task)
@before[task].each { |command| shell.exec(command) }
end
send(task,shell) if respond_to?(task)
if @after.has_key?(task)
@after[task].each { |command| shell.exec(command) }
end
end | ruby | def invoke_task(task,shell)
unless TASKS.include?(task)
raise("invalid task: #{task}")
end
if @before.has_key?(task)
@before[task].each { |command| shell.exec(command) }
end
send(task,shell) if respond_to?(task)
if @after.has_key?(task)
@after[task].each { |command| shell.exec(command) }
end
end | [
"def",
"invoke_task",
"(",
"task",
",",
"shell",
")",
"unless",
"TASKS",
".",
"include?",
"(",
"task",
")",
"raise",
"(",
"\"invalid task: #{task}\"",
")",
"end",
"if",
"@before",
".",
"has_key?",
"(",
"task",
")",
"@before",
"[",
"task",
"]",
".",
"each",
"{",
"|",
"command",
"|",
"shell",
".",
"exec",
"(",
"command",
")",
"}",
"end",
"send",
"(",
"task",
",",
"shell",
")",
"if",
"respond_to?",
"(",
"task",
")",
"if",
"@after",
".",
"has_key?",
"(",
"task",
")",
"@after",
"[",
"task",
"]",
".",
"each",
"{",
"|",
"command",
"|",
"shell",
".",
"exec",
"(",
"command",
")",
"}",
"end",
"end"
] | Invokes a task.
@param [Symbol] task
The name of the task to run.
@param [Shell] shell
The shell to run the task in.
@raise [RuntimeError]
The task name was not known.
@since 0.5.0 | [
"Invokes",
"a",
"task",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L326-L340 |
5,365 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.invoke | def invoke(tasks)
remote_shell do |shell|
# setup the deployment repository
invoke_task(:setup,shell) if tasks.include?(:setup)
# cd into the deployment repository
shell.cd(shell.uri.path)
# update the deployment repository
invoke_task(:update,shell) if tasks.include?(:update)
# framework tasks
invoke_task(:install,shell) if tasks.include?(:install)
invoke_task(:migrate,shell) if tasks.include?(:migrate)
# server tasks
if tasks.include?(:config)
invoke_task(:config,shell)
elsif tasks.include?(:start)
invoke_task(:start,shell)
elsif tasks.include?(:stop)
invoke_task(:stop,shell)
elsif tasks.include?(:restart)
invoke_task(:restart,shell)
end
end
return true
end | ruby | def invoke(tasks)
remote_shell do |shell|
# setup the deployment repository
invoke_task(:setup,shell) if tasks.include?(:setup)
# cd into the deployment repository
shell.cd(shell.uri.path)
# update the deployment repository
invoke_task(:update,shell) if tasks.include?(:update)
# framework tasks
invoke_task(:install,shell) if tasks.include?(:install)
invoke_task(:migrate,shell) if tasks.include?(:migrate)
# server tasks
if tasks.include?(:config)
invoke_task(:config,shell)
elsif tasks.include?(:start)
invoke_task(:start,shell)
elsif tasks.include?(:stop)
invoke_task(:stop,shell)
elsif tasks.include?(:restart)
invoke_task(:restart,shell)
end
end
return true
end | [
"def",
"invoke",
"(",
"tasks",
")",
"remote_shell",
"do",
"|",
"shell",
"|",
"# setup the deployment repository",
"invoke_task",
"(",
":setup",
",",
"shell",
")",
"if",
"tasks",
".",
"include?",
"(",
":setup",
")",
"# cd into the deployment repository",
"shell",
".",
"cd",
"(",
"shell",
".",
"uri",
".",
"path",
")",
"# update the deployment repository",
"invoke_task",
"(",
":update",
",",
"shell",
")",
"if",
"tasks",
".",
"include?",
"(",
":update",
")",
"# framework tasks",
"invoke_task",
"(",
":install",
",",
"shell",
")",
"if",
"tasks",
".",
"include?",
"(",
":install",
")",
"invoke_task",
"(",
":migrate",
",",
"shell",
")",
"if",
"tasks",
".",
"include?",
"(",
":migrate",
")",
"# server tasks",
"if",
"tasks",
".",
"include?",
"(",
":config",
")",
"invoke_task",
"(",
":config",
",",
"shell",
")",
"elsif",
"tasks",
".",
"include?",
"(",
":start",
")",
"invoke_task",
"(",
":start",
",",
"shell",
")",
"elsif",
"tasks",
".",
"include?",
"(",
":stop",
")",
"invoke_task",
"(",
":stop",
",",
"shell",
")",
"elsif",
"tasks",
".",
"include?",
"(",
":restart",
")",
"invoke_task",
"(",
":restart",
",",
"shell",
")",
"end",
"end",
"return",
"true",
"end"
] | Deploys the project.
@param [Array<Symbol>] tasks
The tasks to run during the deployment.
@return [true]
Indicates that the tasks were successfully completed.
@since 0.4.0 | [
"Deploys",
"the",
"project",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L353-L381 |
5,366 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.load_framework! | def load_framework!
if @orm
unless FRAMEWORKS.has_key?(@framework)
raise(UnknownFramework,"Unknown framework #{@framework}",caller)
end
extend FRAMEWORKS[@framework]
initialize_framework if respond_to?(:initialize_framework)
end
end | ruby | def load_framework!
if @orm
unless FRAMEWORKS.has_key?(@framework)
raise(UnknownFramework,"Unknown framework #{@framework}",caller)
end
extend FRAMEWORKS[@framework]
initialize_framework if respond_to?(:initialize_framework)
end
end | [
"def",
"load_framework!",
"if",
"@orm",
"unless",
"FRAMEWORKS",
".",
"has_key?",
"(",
"@framework",
")",
"raise",
"(",
"UnknownFramework",
",",
"\"Unknown framework #{@framework}\"",
",",
"caller",
")",
"end",
"extend",
"FRAMEWORKS",
"[",
"@framework",
"]",
"initialize_framework",
"if",
"respond_to?",
"(",
":initialize_framework",
")",
"end",
"end"
] | Loads the framework configuration.
@since 0.3.0 | [
"Loads",
"the",
"framework",
"configuration",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L510-L520 |
5,367 | postmodern/deployml | lib/deployml/environment.rb | DeploYML.Environment.load_server! | def load_server!
if @server_name
unless SERVERS.has_key?(@server_name)
raise(UnknownServer,"Unknown server name #{@server_name}",caller)
end
extend SERVERS[@server_name]
initialize_server if respond_to?(:initialize_server)
end
end | ruby | def load_server!
if @server_name
unless SERVERS.has_key?(@server_name)
raise(UnknownServer,"Unknown server name #{@server_name}",caller)
end
extend SERVERS[@server_name]
initialize_server if respond_to?(:initialize_server)
end
end | [
"def",
"load_server!",
"if",
"@server_name",
"unless",
"SERVERS",
".",
"has_key?",
"(",
"@server_name",
")",
"raise",
"(",
"UnknownServer",
",",
"\"Unknown server name #{@server_name}\"",
",",
"caller",
")",
"end",
"extend",
"SERVERS",
"[",
"@server_name",
"]",
"initialize_server",
"if",
"respond_to?",
"(",
":initialize_server",
")",
"end",
"end"
] | Loads the server configuration.
@raise [UnknownServer]
@since 0.3.0 | [
"Loads",
"the",
"server",
"configuration",
"."
] | 4369d4ea719e41f0dc3aa6496e6422ad476b0dda | https://github.com/postmodern/deployml/blob/4369d4ea719e41f0dc3aa6496e6422ad476b0dda/lib/deployml/environment.rb#L529-L539 |
5,368 | ideonetwork/lato-core | lib/lato_core/interfaces/authentication.rb | LatoCore.Interface::Authentication.core__create_superuser_session | def core__create_superuser_session(superuser, lifetime)
token = core__encode_token(lifetime, superuser_id: superuser.id)
session[:lato_core__superuser_session_token] = token
end | ruby | def core__create_superuser_session(superuser, lifetime)
token = core__encode_token(lifetime, superuser_id: superuser.id)
session[:lato_core__superuser_session_token] = token
end | [
"def",
"core__create_superuser_session",
"(",
"superuser",
",",
"lifetime",
")",
"token",
"=",
"core__encode_token",
"(",
"lifetime",
",",
"superuser_id",
":",
"superuser",
".",
"id",
")",
"session",
"[",
":lato_core__superuser_session_token",
"]",
"=",
"token",
"end"
] | This function set a cookie to create the superuser session. | [
"This",
"function",
"set",
"a",
"cookie",
"to",
"create",
"the",
"superuser",
"session",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/authentication.rb#L9-L12 |
5,369 | ideonetwork/lato-core | lib/lato_core/interfaces/authentication.rb | LatoCore.Interface::Authentication.core__manage_superuser_session | def core__manage_superuser_session(permission = nil)
decoded_token = core__decode_token(session[:lato_core__superuser_session_token])
if decoded_token
@core__current_superuser = LatoCore::Superuser.find_by(id: decoded_token[:superuser_id])
unless @core__current_superuser
core__destroy_superuser_session
redirect_to lato_core.login_path
end
if permission && @core__current_superuser.permission < permission
flash[:danger] = 'PERMISSION ERROR'
redirect_to lato_core.root_path
end
else
redirect_to lato_core.login_path
end
end | ruby | def core__manage_superuser_session(permission = nil)
decoded_token = core__decode_token(session[:lato_core__superuser_session_token])
if decoded_token
@core__current_superuser = LatoCore::Superuser.find_by(id: decoded_token[:superuser_id])
unless @core__current_superuser
core__destroy_superuser_session
redirect_to lato_core.login_path
end
if permission && @core__current_superuser.permission < permission
flash[:danger] = 'PERMISSION ERROR'
redirect_to lato_core.root_path
end
else
redirect_to lato_core.login_path
end
end | [
"def",
"core__manage_superuser_session",
"(",
"permission",
"=",
"nil",
")",
"decoded_token",
"=",
"core__decode_token",
"(",
"session",
"[",
":lato_core__superuser_session_token",
"]",
")",
"if",
"decoded_token",
"@core__current_superuser",
"=",
"LatoCore",
"::",
"Superuser",
".",
"find_by",
"(",
"id",
":",
"decoded_token",
"[",
":superuser_id",
"]",
")",
"unless",
"@core__current_superuser",
"core__destroy_superuser_session",
"redirect_to",
"lato_core",
".",
"login_path",
"end",
"if",
"permission",
"&&",
"@core__current_superuser",
".",
"permission",
"<",
"permission",
"flash",
"[",
":danger",
"]",
"=",
"'PERMISSION ERROR'",
"redirect_to",
"lato_core",
".",
"root_path",
"end",
"else",
"redirect_to",
"lato_core",
".",
"login_path",
"end",
"end"
] | This function check the session for a superuser and set the variable @core__current_superuser.
If session is not valid the user should be redirect to login path. | [
"This",
"function",
"check",
"the",
"session",
"for",
"a",
"superuser",
"and",
"set",
"the",
"variable"
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/authentication.rb#L28-L45 |
5,370 | leshill/mongodoc | lib/mongo_doc/matchers.rb | MongoDoc.Matchers.matcher | def matcher(key, value)
if value.is_a?(Hash)
name = "Mongoid::Matchers::#{value.keys.first.gsub("$", "").camelize}"
return name.constantize.new(send(key))
end
Mongoid::Matchers::Default.new(send(key))
end | ruby | def matcher(key, value)
if value.is_a?(Hash)
name = "Mongoid::Matchers::#{value.keys.first.gsub("$", "").camelize}"
return name.constantize.new(send(key))
end
Mongoid::Matchers::Default.new(send(key))
end | [
"def",
"matcher",
"(",
"key",
",",
"value",
")",
"if",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"name",
"=",
"\"Mongoid::Matchers::#{value.keys.first.gsub(\"$\", \"\").camelize}\"",
"return",
"name",
".",
"constantize",
".",
"new",
"(",
"send",
"(",
"key",
")",
")",
"end",
"Mongoid",
"::",
"Matchers",
"::",
"Default",
".",
"new",
"(",
"send",
"(",
"key",
")",
")",
"end"
] | Get the matcher for the supplied key and value. Will determine the class
name from the key. | [
"Get",
"the",
"matcher",
"for",
"the",
"supplied",
"key",
"and",
"value",
".",
"Will",
"determine",
"the",
"class",
"name",
"from",
"the",
"key",
"."
] | fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4 | https://github.com/leshill/mongodoc/blob/fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4/lib/mongo_doc/matchers.rb#L27-L33 |
5,371 | Sharparam/chatrix | lib/chatrix/user.rb | Chatrix.User.process_power_level | def process_power_level(room, level)
membership = (@memberships[room] ||= {})
membership[:power] = level
broadcast(:power_level, self, room, level)
end | ruby | def process_power_level(room, level)
membership = (@memberships[room] ||= {})
membership[:power] = level
broadcast(:power_level, self, room, level)
end | [
"def",
"process_power_level",
"(",
"room",
",",
"level",
")",
"membership",
"=",
"(",
"@memberships",
"[",
"room",
"]",
"||=",
"{",
"}",
")",
"membership",
"[",
":power",
"]",
"=",
"level",
"broadcast",
"(",
":power_level",
",",
"self",
",",
"room",
",",
"level",
")",
"end"
] | Process a power level update in a room.
@param room [Room] The room where the level updated.
@param level [Fixnum] The new power level. | [
"Process",
"a",
"power",
"level",
"update",
"in",
"a",
"room",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/user.rb#L73-L77 |
5,372 | Sharparam/chatrix | lib/chatrix/user.rb | Chatrix.User.process_invite | def process_invite(room, sender, event)
# Return early if we're already part of this room
membership = (@memberships[room] ||= {})
return if membership[:type] == :join
process_member_event room, event
broadcast(:invited, self, room, sender)
end | ruby | def process_invite(room, sender, event)
# Return early if we're already part of this room
membership = (@memberships[room] ||= {})
return if membership[:type] == :join
process_member_event room, event
broadcast(:invited, self, room, sender)
end | [
"def",
"process_invite",
"(",
"room",
",",
"sender",
",",
"event",
")",
"# Return early if we're already part of this room",
"membership",
"=",
"(",
"@memberships",
"[",
"room",
"]",
"||=",
"{",
"}",
")",
"return",
"if",
"membership",
"[",
":type",
"]",
"==",
":join",
"process_member_event",
"room",
",",
"event",
"broadcast",
"(",
":invited",
",",
"self",
",",
"room",
",",
"sender",
")",
"end"
] | Process an invite to a room.
@param room [Room] The room the user was invited to.
@param sender [User] The user who sent the invite.
@param event [Hash] Event data. | [
"Process",
"an",
"invite",
"to",
"a",
"room",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/user.rb#L83-L89 |
5,373 | Sharparam/chatrix | lib/chatrix/user.rb | Chatrix.User.update | def update(data)
update_avatar(data['avatar_url']) if data.key? 'avatar_url'
update_displayname(data['displayname']) if data.key? 'displayname'
end | ruby | def update(data)
update_avatar(data['avatar_url']) if data.key? 'avatar_url'
update_displayname(data['displayname']) if data.key? 'displayname'
end | [
"def",
"update",
"(",
"data",
")",
"update_avatar",
"(",
"data",
"[",
"'avatar_url'",
"]",
")",
"if",
"data",
".",
"key?",
"'avatar_url'",
"update_displayname",
"(",
"data",
"[",
"'displayname'",
"]",
")",
"if",
"data",
".",
"key?",
"'displayname'",
"end"
] | Updates metadata for this user.
@param data [Hash{String=>String}] User metadata. | [
"Updates",
"metadata",
"for",
"this",
"user",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/user.rb#L102-L105 |
5,374 | kunishi/algebra-ruby2 | lib/algebra/algebraic-system.rb | Algebra.AlgebraCreator.wedge | def wedge(otype) # =:= tensor
if superior?(otype)
self
elsif otype.respond_to?(:superior?) && otype.superior?(self)
otype
else
raise "wedge: unknown pair (#{self}) .wedge (#{otype})"
end
end | ruby | def wedge(otype) # =:= tensor
if superior?(otype)
self
elsif otype.respond_to?(:superior?) && otype.superior?(self)
otype
else
raise "wedge: unknown pair (#{self}) .wedge (#{otype})"
end
end | [
"def",
"wedge",
"(",
"otype",
")",
"# =:= tensor",
"if",
"superior?",
"(",
"otype",
")",
"self",
"elsif",
"otype",
".",
"respond_to?",
"(",
":superior?",
")",
"&&",
"otype",
".",
"superior?",
"(",
"self",
")",
"otype",
"else",
"raise",
"\"wedge: unknown pair (#{self}) .wedge (#{otype})\"",
"end",
"end"
] | Needed in the type conversion of MatrixAlgebra | [
"Needed",
"in",
"the",
"type",
"conversion",
"of",
"MatrixAlgebra"
] | 8976fbaac14933d3206324c845b879bf67fa0cf7 | https://github.com/kunishi/algebra-ruby2/blob/8976fbaac14933d3206324c845b879bf67fa0cf7/lib/algebra/algebraic-system.rb#L28-L36 |
5,375 | Birdie0/qna_maker | lib/qna_maker/endpoints/delete_kb.rb | QnAMaker.Client.delete_kb | def delete_kb
response = @http.delete(
"#{BASE_URL}/#{knowledgebase_id}"
)
case response.code
when 204
nil
when 400
raise BadArgumentError, response.parse['error']['message'].join(' ')
when 401
raise UnauthorizedError, response.parse['error']['message']
when 403
raise ForbiddenError, response.parse['error']['message']
when 404
raise NotFoundError, response.parse['error']['message']
when 409
raise ConflictError, response.parse['error']['message']
else
raise UnknownError, "Oh no! (#{response.code})"
end
end | ruby | def delete_kb
response = @http.delete(
"#{BASE_URL}/#{knowledgebase_id}"
)
case response.code
when 204
nil
when 400
raise BadArgumentError, response.parse['error']['message'].join(' ')
when 401
raise UnauthorizedError, response.parse['error']['message']
when 403
raise ForbiddenError, response.parse['error']['message']
when 404
raise NotFoundError, response.parse['error']['message']
when 409
raise ConflictError, response.parse['error']['message']
else
raise UnknownError, "Oh no! (#{response.code})"
end
end | [
"def",
"delete_kb",
"response",
"=",
"@http",
".",
"delete",
"(",
"\"#{BASE_URL}/#{knowledgebase_id}\"",
")",
"case",
"response",
".",
"code",
"when",
"204",
"nil",
"when",
"400",
"raise",
"BadArgumentError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
".",
"join",
"(",
"' '",
")",
"when",
"401",
"raise",
"UnauthorizedError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"403",
"raise",
"ForbiddenError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"404",
"raise",
"NotFoundError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"when",
"409",
"raise",
"ConflictError",
",",
"response",
".",
"parse",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"else",
"raise",
"UnknownError",
",",
"\"Oh no! (#{response.code})\"",
"end",
"end"
] | Deletes the current knowledge base and all data associated with it.
@return [nil] on success | [
"Deletes",
"the",
"current",
"knowledge",
"base",
"and",
"all",
"data",
"associated",
"with",
"it",
"."
] | 5ac204ede100355352438b8ff4fe30ad84d9257b | https://github.com/Birdie0/qna_maker/blob/5ac204ede100355352438b8ff4fe30ad84d9257b/lib/qna_maker/endpoints/delete_kb.rb#L8-L29 |
5,376 | iaintshine/ruby-spanmanager | lib/spanmanager/tracer.rb | SpanManager.Tracer.start_span | def start_span(operation_name, child_of: active_span, **args)
span = @tracer.start_span(operation_name, child_of: child_of, **args)
@managed_span_source.make_active(span)
end | ruby | def start_span(operation_name, child_of: active_span, **args)
span = @tracer.start_span(operation_name, child_of: child_of, **args)
@managed_span_source.make_active(span)
end | [
"def",
"start_span",
"(",
"operation_name",
",",
"child_of",
":",
"active_span",
",",
"**",
"args",
")",
"span",
"=",
"@tracer",
".",
"start_span",
"(",
"operation_name",
",",
"child_of",
":",
"child_of",
",",
"**",
"args",
")",
"@managed_span_source",
".",
"make_active",
"(",
"span",
")",
"end"
] | Starts a new active span.
@param operation_name [String] The operation name for the Span
@param child_of [SpanContext, Span] SpanContext that acts as a parent to
the newly-started Span. If default argument is used then the currently
active span becomes an implicit parent of a newly-started span.
@return [SpanManager::ManagedSpan] The newly-started active Span | [
"Starts",
"a",
"new",
"active",
"span",
"."
] | 95f14b13269f35eacef88d61fa82dac90adde3be | https://github.com/iaintshine/ruby-spanmanager/blob/95f14b13269f35eacef88d61fa82dac90adde3be/lib/spanmanager/tracer.rb#L42-L45 |
5,377 | jwagener/oauth-active-resource | lib/oauth_active_resource/connection.rb | OAuthActiveResource.Connection.handle_response | def handle_response(response)
return super(response)
rescue ActiveResource::ClientError => exc
begin
# ugly code to insert the error_message into response
error_message = "#{format.decode response.body}"
if not error_message.nil? or error_message == ""
exc.response.instance_eval do ||
@message = error_message
end
end
ensure
raise exc
end
end | ruby | def handle_response(response)
return super(response)
rescue ActiveResource::ClientError => exc
begin
# ugly code to insert the error_message into response
error_message = "#{format.decode response.body}"
if not error_message.nil? or error_message == ""
exc.response.instance_eval do ||
@message = error_message
end
end
ensure
raise exc
end
end | [
"def",
"handle_response",
"(",
"response",
")",
"return",
"super",
"(",
"response",
")",
"rescue",
"ActiveResource",
"::",
"ClientError",
"=>",
"exc",
"begin",
"# ugly code to insert the error_message into response",
"error_message",
"=",
"\"#{format.decode response.body}\"",
"if",
"not",
"error_message",
".",
"nil?",
"or",
"error_message",
"==",
"\"\"",
"exc",
".",
"response",
".",
"instance_eval",
"do",
"|",
"|",
"@message",
"=",
"error_message",
"end",
"end",
"ensure",
"raise",
"exc",
"end",
"end"
] | make handle_response public and add error message from body if possible | [
"make",
"handle_response",
"public",
"and",
"add",
"error",
"message",
"from",
"body",
"if",
"possible"
] | fc5fc1e1a9fda157c1fc6d792a9cdf2491b59676 | https://github.com/jwagener/oauth-active-resource/blob/fc5fc1e1a9fda157c1fc6d792a9cdf2491b59676/lib/oauth_active_resource/connection.rb#L14-L28 |
5,378 | wordjelly/Auth | app/models/auth/concerns/shopping/product_concern.rb | Auth::Concerns::Shopping::ProductConcern.ClassMethods.add_to_previous_rolling_n_minutes | def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)
## get all the minutes less than that.
rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch}
end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes
end_min = end_min - 1
end_min = end_min > 0 ? end_min : 0
rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
minutes[epoch].cycles << cycle_to_add
end
end | ruby | def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)
## get all the minutes less than that.
rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch}
end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes
end_min = end_min - 1
end_min = end_min > 0 ? end_min : 0
rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
minutes[epoch].cycles << cycle_to_add
end
end | [
"def",
"add_to_previous_rolling_n_minutes",
"(",
"minutes",
",",
"origin_epoch",
",",
"cycle_to_add",
")",
"## get all the minutes less than that.",
"rolling_n_minutes_less_than_that",
"=",
"minutes",
".",
"keys",
".",
"select",
"{",
"|",
"c",
"|",
"c",
"<",
"origin_epoch",
"}",
"end_min",
"=",
"rolling_n_minutes_less_than_that",
".",
"size",
"<",
"Auth",
".",
"configuration",
".",
"rolling_minutes",
"?",
"rolling_n_minutes_less_than_that",
".",
"size",
":",
"Auth",
".",
"configuration",
".",
"rolling_minutes",
"end_min",
"=",
"end_min",
"-",
"1",
"end_min",
"=",
"end_min",
">",
"0",
"?",
"end_min",
":",
"0",
"rolling_n_minutes_less_than_that",
"[",
"0",
"..",
"end_min",
"]",
".",
"each",
"do",
"|",
"epoch",
"|",
"minutes",
"[",
"epoch",
"]",
".",
"cycles",
"<<",
"cycle_to_add",
"end",
"end"
] | so we have completed the rolling n minutes. | [
"so",
"we",
"have",
"completed",
"the",
"rolling",
"n",
"minutes",
"."
] | e1b6697a13c845f57b3cc83bfb79059a09541f47 | https://github.com/wordjelly/Auth/blob/e1b6697a13c845f57b3cc83bfb79059a09541f47/app/models/auth/concerns/shopping/product_concern.rb#L121-L135 |
5,379 | arman000/delorean_lang | lib/delorean/engine.rb | Delorean.Engine.parse_check_defined_node | def parse_check_defined_node(name, flag)
isdef = node_defined?(name)
if isdef != flag
isdef ? err(RedefinedError, "#{name} already defined") :
err(UndefinedError, "#{name} not defined yet")
end
end | ruby | def parse_check_defined_node(name, flag)
isdef = node_defined?(name)
if isdef != flag
isdef ? err(RedefinedError, "#{name} already defined") :
err(UndefinedError, "#{name} not defined yet")
end
end | [
"def",
"parse_check_defined_node",
"(",
"name",
",",
"flag",
")",
"isdef",
"=",
"node_defined?",
"(",
"name",
")",
"if",
"isdef",
"!=",
"flag",
"isdef",
"?",
"err",
"(",
"RedefinedError",
",",
"\"#{name} already defined\"",
")",
":",
"err",
"(",
"UndefinedError",
",",
"\"#{name} not defined yet\"",
")",
"end",
"end"
] | Check to see if node with given name is defined. flag tells the
method about our expectation. flag=true means that we make sure
that name is defined. flag=false is the opposite. | [
"Check",
"to",
"see",
"if",
"node",
"with",
"given",
"name",
"is",
"defined",
".",
"flag",
"tells",
"the",
"method",
"about",
"our",
"expectation",
".",
"flag",
"=",
"true",
"means",
"that",
"we",
"make",
"sure",
"that",
"name",
"is",
"defined",
".",
"flag",
"=",
"false",
"is",
"the",
"opposite",
"."
] | 25ef95238a1e15d5640afa468bd300c80fc68298 | https://github.com/arman000/delorean_lang/blob/25ef95238a1e15d5640afa468bd300c80fc68298/lib/delorean/engine.rb#L81-L88 |
5,380 | arman000/delorean_lang | lib/delorean/engine.rb | Delorean.Engine.parse_call_attr | def parse_call_attr(node_name, attr_name)
return [] if comp_set.member?(attr_name)
# get the class associated with node
klass = @pm.module_eval(node_name)
# puts attr_name, "#{attr_name}#{POST}".to_sym, klass.methods.inspect
begin
klass.send("#{attr_name}#{POST}".to_sym, [])
rescue NoMethodError
err(UndefinedError, "'#{attr_name}' not defined in #{node_name}")
end
end | ruby | def parse_call_attr(node_name, attr_name)
return [] if comp_set.member?(attr_name)
# get the class associated with node
klass = @pm.module_eval(node_name)
# puts attr_name, "#{attr_name}#{POST}".to_sym, klass.methods.inspect
begin
klass.send("#{attr_name}#{POST}".to_sym, [])
rescue NoMethodError
err(UndefinedError, "'#{attr_name}' not defined in #{node_name}")
end
end | [
"def",
"parse_call_attr",
"(",
"node_name",
",",
"attr_name",
")",
"return",
"[",
"]",
"if",
"comp_set",
".",
"member?",
"(",
"attr_name",
")",
"# get the class associated with node",
"klass",
"=",
"@pm",
".",
"module_eval",
"(",
"node_name",
")",
"# puts attr_name, \"#{attr_name}#{POST}\".to_sym, klass.methods.inspect",
"begin",
"klass",
".",
"send",
"(",
"\"#{attr_name}#{POST}\"",
".",
"to_sym",
",",
"[",
"]",
")",
"rescue",
"NoMethodError",
"err",
"(",
"UndefinedError",
",",
"\"'#{attr_name}' not defined in #{node_name}\"",
")",
"end",
"end"
] | Parse-time check to see if attr is available. If not, error is
raised. | [
"Parse",
"-",
"time",
"check",
"to",
"see",
"if",
"attr",
"is",
"available",
".",
"If",
"not",
"error",
"is",
"raised",
"."
] | 25ef95238a1e15d5640afa468bd300c80fc68298 | https://github.com/arman000/delorean_lang/blob/25ef95238a1e15d5640afa468bd300c80fc68298/lib/delorean/engine.rb#L118-L131 |
5,381 | arman000/delorean_lang | lib/delorean/engine.rb | Delorean.Engine.parse_define_attr | def parse_define_attr(name, spec)
err(ParseError, "Can't define '#{name}' outside a node") unless
@last_node
err(RedefinedError, "Can't redefine '#{name}' in node #{@last_node}") if
@node_attrs[@last_node].member? name
@node_attrs[@last_node] << name
checks = spec.map do |a|
n = a.index('.') ? a : "#{@last_node}.#{a}"
"_x.member?('#{n}') ? raise('#{n}') : #{a}#{POST}(_x + ['#{n}'])"
end.join(';')
code =
"class #{@last_node}; def self.#{name}#{POST}(_x); #{checks}; end; end"
# pp code
@pm.module_eval(code)
begin
parse_call_attr(@last_node, name)
rescue RuntimeError
err(RecursionError, "'#{name}' is recursive")
end
end | ruby | def parse_define_attr(name, spec)
err(ParseError, "Can't define '#{name}' outside a node") unless
@last_node
err(RedefinedError, "Can't redefine '#{name}' in node #{@last_node}") if
@node_attrs[@last_node].member? name
@node_attrs[@last_node] << name
checks = spec.map do |a|
n = a.index('.') ? a : "#{@last_node}.#{a}"
"_x.member?('#{n}') ? raise('#{n}') : #{a}#{POST}(_x + ['#{n}'])"
end.join(';')
code =
"class #{@last_node}; def self.#{name}#{POST}(_x); #{checks}; end; end"
# pp code
@pm.module_eval(code)
begin
parse_call_attr(@last_node, name)
rescue RuntimeError
err(RecursionError, "'#{name}' is recursive")
end
end | [
"def",
"parse_define_attr",
"(",
"name",
",",
"spec",
")",
"err",
"(",
"ParseError",
",",
"\"Can't define '#{name}' outside a node\"",
")",
"unless",
"@last_node",
"err",
"(",
"RedefinedError",
",",
"\"Can't redefine '#{name}' in node #{@last_node}\"",
")",
"if",
"@node_attrs",
"[",
"@last_node",
"]",
".",
"member?",
"name",
"@node_attrs",
"[",
"@last_node",
"]",
"<<",
"name",
"checks",
"=",
"spec",
".",
"map",
"do",
"|",
"a",
"|",
"n",
"=",
"a",
".",
"index",
"(",
"'.'",
")",
"?",
"a",
":",
"\"#{@last_node}.#{a}\"",
"\"_x.member?('#{n}') ? raise('#{n}') : #{a}#{POST}(_x + ['#{n}'])\"",
"end",
".",
"join",
"(",
"';'",
")",
"code",
"=",
"\"class #{@last_node}; def self.#{name}#{POST}(_x); #{checks}; end; end\"",
"# pp code",
"@pm",
".",
"module_eval",
"(",
"code",
")",
"begin",
"parse_call_attr",
"(",
"@last_node",
",",
"name",
")",
"rescue",
"RuntimeError",
"err",
"(",
"RecursionError",
",",
"\"'#{name}' is recursive\"",
")",
"end",
"end"
] | parse-time attr definition | [
"parse",
"-",
"time",
"attr",
"definition"
] | 25ef95238a1e15d5640afa468bd300c80fc68298 | https://github.com/arman000/delorean_lang/blob/25ef95238a1e15d5640afa468bd300c80fc68298/lib/delorean/engine.rb#L154-L180 |
5,382 | arman000/delorean_lang | lib/delorean/engine.rb | Delorean.Engine.enumerate_params_by_node | def enumerate_params_by_node(node)
attrs = enumerate_attrs_by_node(node)
Set.new(attrs.select { |a| @param_set.include?(a) })
end | ruby | def enumerate_params_by_node(node)
attrs = enumerate_attrs_by_node(node)
Set.new(attrs.select { |a| @param_set.include?(a) })
end | [
"def",
"enumerate_params_by_node",
"(",
"node",
")",
"attrs",
"=",
"enumerate_attrs_by_node",
"(",
"node",
")",
"Set",
".",
"new",
"(",
"attrs",
".",
"select",
"{",
"|",
"a",
"|",
"@param_set",
".",
"include?",
"(",
"a",
")",
"}",
")",
"end"
] | enumerate params by a single node | [
"enumerate",
"params",
"by",
"a",
"single",
"node"
] | 25ef95238a1e15d5640afa468bd300c80fc68298 | https://github.com/arman000/delorean_lang/blob/25ef95238a1e15d5640afa468bd300c80fc68298/lib/delorean/engine.rb#L358-L361 |
5,383 | siyegen/instrumentable | lib/instrumentable.rb | Instrumentable.ClassMethods.class_instrument_method | def class_instrument_method(klass, method_to_instrument, event_name, payload={})
class << klass; self; end.class_eval do
Instrumentality.begin(self, method_to_instrument, event_name, payload)
end
end | ruby | def class_instrument_method(klass, method_to_instrument, event_name, payload={})
class << klass; self; end.class_eval do
Instrumentality.begin(self, method_to_instrument, event_name, payload)
end
end | [
"def",
"class_instrument_method",
"(",
"klass",
",",
"method_to_instrument",
",",
"event_name",
",",
"payload",
"=",
"{",
"}",
")",
"class",
"<<",
"klass",
";",
"self",
";",
"end",
".",
"class_eval",
"do",
"Instrumentality",
".",
"begin",
"(",
"self",
",",
"method_to_instrument",
",",
"event_name",
",",
"payload",
")",
"end",
"end"
] | Class implementation of +instrument_method+ | [
"Class",
"implementation",
"of",
"+",
"instrument_method",
"+"
] | 9180a4661980e88f283dc8c424847f89fbeff2ae | https://github.com/siyegen/instrumentable/blob/9180a4661980e88f283dc8c424847f89fbeff2ae/lib/instrumentable.rb#L63-L67 |
5,384 | code-and-effect/effective_regions | app/models/effective/region.rb | Effective.Region.snippet_objects | def snippet_objects(locals = {})
locals = {} unless locals.kind_of?(Hash)
@snippet_objects ||= snippets.map do |key, snippet| # Key here is 'snippet_1'
if snippet['class_name']
klass = "Effective::Snippets::#{snippet['class_name'].classify}".safe_constantize
klass.new(snippet.merge!(locals).merge!(:region => self, :id => key)) if klass
end
end.compact
end | ruby | def snippet_objects(locals = {})
locals = {} unless locals.kind_of?(Hash)
@snippet_objects ||= snippets.map do |key, snippet| # Key here is 'snippet_1'
if snippet['class_name']
klass = "Effective::Snippets::#{snippet['class_name'].classify}".safe_constantize
klass.new(snippet.merge!(locals).merge!(:region => self, :id => key)) if klass
end
end.compact
end | [
"def",
"snippet_objects",
"(",
"locals",
"=",
"{",
"}",
")",
"locals",
"=",
"{",
"}",
"unless",
"locals",
".",
"kind_of?",
"(",
"Hash",
")",
"@snippet_objects",
"||=",
"snippets",
".",
"map",
"do",
"|",
"key",
",",
"snippet",
"|",
"# Key here is 'snippet_1'",
"if",
"snippet",
"[",
"'class_name'",
"]",
"klass",
"=",
"\"Effective::Snippets::#{snippet['class_name'].classify}\"",
".",
"safe_constantize",
"klass",
".",
"new",
"(",
"snippet",
".",
"merge!",
"(",
"locals",
")",
".",
"merge!",
"(",
":region",
"=>",
"self",
",",
":id",
"=>",
"key",
")",
")",
"if",
"klass",
"end",
"end",
".",
"compact",
"end"
] | Hash of the Snippets objectified
Returns a Hash of {'snippet_1' => CurrentUserInfo.new(snippets[:key]['options'])} | [
"Hash",
"of",
"the",
"Snippets",
"objectified"
] | c24fc30b5012420b81e7d156fd712590f23b9d0c | https://github.com/code-and-effect/effective_regions/blob/c24fc30b5012420b81e7d156fd712590f23b9d0c/app/models/effective/region.rb#L28-L36 |
5,385 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.Distribution.draw | def draw
r = @dist.rng.to_i
raise "drawn number must be an integer" unless r.is_a? Integer
# keep the value inside the allowed range
r = 0 - r if r < 0
if r >= @range.size
diff = 1 + r - @range.size
r = @range.size - diff
end
@range[r]
end | ruby | def draw
r = @dist.rng.to_i
raise "drawn number must be an integer" unless r.is_a? Integer
# keep the value inside the allowed range
r = 0 - r if r < 0
if r >= @range.size
diff = 1 + r - @range.size
r = @range.size - diff
end
@range[r]
end | [
"def",
"draw",
"r",
"=",
"@dist",
".",
"rng",
".",
"to_i",
"raise",
"\"drawn number must be an integer\"",
"unless",
"r",
".",
"is_a?",
"Integer",
"# keep the value inside the allowed range",
"r",
"=",
"0",
"-",
"r",
"if",
"r",
"<",
"0",
"if",
"r",
">=",
"@range",
".",
"size",
"diff",
"=",
"1",
"+",
"r",
"-",
"@range",
".",
"size",
"r",
"=",
"@range",
".",
"size",
"-",
"diff",
"end",
"@range",
"[",
"r",
"]",
"end"
] | draw from the distribution | [
"draw",
"from",
"the",
"distribution"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L69-L79 |
5,386 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.Hood.generate_neighbour | def generate_neighbour
n = 0
begin
if n >= 100
# taking too long to generate a neighbour,
# loosen the neighbourhood structure so we explore further
# debug("loosening distributions")
@distributions.each do |param, dist|
dist.loosen
end
end
# preform the probabilistic step move for each parameter
neighbour = Hash[@distributions.map { |param, dist| [param, dist.draw] }]
n += 1
end while self.is_tabu?(neighbour)
@tabu << neighbour
@members << neighbour
end | ruby | def generate_neighbour
n = 0
begin
if n >= 100
# taking too long to generate a neighbour,
# loosen the neighbourhood structure so we explore further
# debug("loosening distributions")
@distributions.each do |param, dist|
dist.loosen
end
end
# preform the probabilistic step move for each parameter
neighbour = Hash[@distributions.map { |param, dist| [param, dist.draw] }]
n += 1
end while self.is_tabu?(neighbour)
@tabu << neighbour
@members << neighbour
end | [
"def",
"generate_neighbour",
"n",
"=",
"0",
"begin",
"if",
"n",
">=",
"100",
"# taking too long to generate a neighbour,",
"# loosen the neighbourhood structure so we explore further",
"# debug(\"loosening distributions\")",
"@distributions",
".",
"each",
"do",
"|",
"param",
",",
"dist",
"|",
"dist",
".",
"loosen",
"end",
"end",
"# preform the probabilistic step move for each parameter",
"neighbour",
"=",
"Hash",
"[",
"@distributions",
".",
"map",
"{",
"|",
"param",
",",
"dist",
"|",
"[",
"param",
",",
"dist",
".",
"draw",
"]",
"}",
"]",
"n",
"+=",
"1",
"end",
"while",
"self",
".",
"is_tabu?",
"(",
"neighbour",
")",
"@tabu",
"<<",
"neighbour",
"@members",
"<<",
"neighbour",
"end"
] | generate a single neighbour | [
"generate",
"a",
"single",
"neighbour"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L107-L124 |
5,387 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.TabuSearch.update_neighbourhood_structure | def update_neighbourhood_structure
self.update_recent_scores
best = self.backtrack_or_continue
unless @distributions.empty?
@standard_deviations = Hash[@distributions.map { |k, d| [k, d.sd] }]
end
best[:parameters].each_pair do |param, value|
self.update_distribution(param, value)
end
end | ruby | def update_neighbourhood_structure
self.update_recent_scores
best = self.backtrack_or_continue
unless @distributions.empty?
@standard_deviations = Hash[@distributions.map { |k, d| [k, d.sd] }]
end
best[:parameters].each_pair do |param, value|
self.update_distribution(param, value)
end
end | [
"def",
"update_neighbourhood_structure",
"self",
".",
"update_recent_scores",
"best",
"=",
"self",
".",
"backtrack_or_continue",
"unless",
"@distributions",
".",
"empty?",
"@standard_deviations",
"=",
"Hash",
"[",
"@distributions",
".",
"map",
"{",
"|",
"k",
",",
"d",
"|",
"[",
"k",
",",
"d",
".",
"sd",
"]",
"}",
"]",
"end",
"best",
"[",
":parameters",
"]",
".",
"each_pair",
"do",
"|",
"param",
",",
"value",
"|",
"self",
".",
"update_distribution",
"(",
"param",
",",
"value",
")",
"end",
"end"
] | update the neighbourhood structure by adjusting the probability
distributions according to total performance of each parameter | [
"update",
"the",
"neighbourhood",
"structure",
"by",
"adjusting",
"the",
"probability",
"distributions",
"according",
"to",
"total",
"performance",
"of",
"each",
"parameter"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L310-L319 |
5,388 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.TabuSearch.backtrack_or_continue | def backtrack_or_continue
best = nil
if (@iterations_since_best / @backtracks) >= @backtrack_cutoff * @max_hood_size
self.backtrack
best = @best
else
best = @current_hood.best
self.adjust_distributions_using_gradient
end
if best[:parameters].nil?
# this should never happen!
best = @best
end
best
end | ruby | def backtrack_or_continue
best = nil
if (@iterations_since_best / @backtracks) >= @backtrack_cutoff * @max_hood_size
self.backtrack
best = @best
else
best = @current_hood.best
self.adjust_distributions_using_gradient
end
if best[:parameters].nil?
# this should never happen!
best = @best
end
best
end | [
"def",
"backtrack_or_continue",
"best",
"=",
"nil",
"if",
"(",
"@iterations_since_best",
"/",
"@backtracks",
")",
">=",
"@backtrack_cutoff",
"*",
"@max_hood_size",
"self",
".",
"backtrack",
"best",
"=",
"@best",
"else",
"best",
"=",
"@current_hood",
".",
"best",
"self",
".",
"adjust_distributions_using_gradient",
"end",
"if",
"best",
"[",
":parameters",
"]",
".",
"nil?",
"# this should never happen!",
"best",
"=",
"@best",
"end",
"best",
"end"
] | return the correct 'best' location to form a new neighbourhood around
deciding whether to continue progressing from the current location
or to backtrack to a previous good location to explore further | [
"return",
"the",
"correct",
"best",
"location",
"to",
"form",
"a",
"new",
"neighbourhood",
"around",
"deciding",
"whether",
"to",
"continue",
"progressing",
"from",
"the",
"current",
"location",
"or",
"to",
"backtrack",
"to",
"a",
"previous",
"good",
"location",
"to",
"explore",
"further"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L341-L355 |
5,389 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.TabuSearch.adjust_distributions_using_gradient | def adjust_distributions_using_gradient
return if @recent_scores.length < 3
vx = (1..@recent_scores.length).to_a.to_numeric
vy = @recent_scores.reverse.to_numeric
r = Statsample::Regression::Simple.new_from_vectors(vx,vy)
slope = r.b
if slope > 0
@distributions.each_pair { |k, d| d.tighten slope }
elsif slope < 0
@distributions.each_pair { |k, d| d.loosen slope }
end
end | ruby | def adjust_distributions_using_gradient
return if @recent_scores.length < 3
vx = (1..@recent_scores.length).to_a.to_numeric
vy = @recent_scores.reverse.to_numeric
r = Statsample::Regression::Simple.new_from_vectors(vx,vy)
slope = r.b
if slope > 0
@distributions.each_pair { |k, d| d.tighten slope }
elsif slope < 0
@distributions.each_pair { |k, d| d.loosen slope }
end
end | [
"def",
"adjust_distributions_using_gradient",
"return",
"if",
"@recent_scores",
".",
"length",
"<",
"3",
"vx",
"=",
"(",
"1",
"..",
"@recent_scores",
".",
"length",
")",
".",
"to_a",
".",
"to_numeric",
"vy",
"=",
"@recent_scores",
".",
"reverse",
".",
"to_numeric",
"r",
"=",
"Statsample",
"::",
"Regression",
"::",
"Simple",
".",
"new_from_vectors",
"(",
"vx",
",",
"vy",
")",
"slope",
"=",
"r",
".",
"b",
"if",
"slope",
">",
"0",
"@distributions",
".",
"each_pair",
"{",
"|",
"k",
",",
"d",
"|",
"d",
".",
"tighten",
"slope",
"}",
"elsif",
"slope",
"<",
"0",
"@distributions",
".",
"each_pair",
"{",
"|",
"k",
",",
"d",
"|",
"d",
".",
"loosen",
"slope",
"}",
"end",
"end"
] | use the gradient of recent best scores to update the distributions | [
"use",
"the",
"gradient",
"of",
"recent",
"best",
"scores",
"to",
"update",
"the",
"distributions"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L369-L380 |
5,390 | blahah/biopsy | lib/biopsy/optimisers/tabu_search.rb | Biopsy.TabuSearch.finished? | def finished?
return false unless @threads.all? do |t|
t.recent_scores.size == @jump_cutoff
end
probabilities = self.recent_scores_combination_test
n_significant = 0
probabilities.each do |mann_u, levene|
if mann_u <= @adjusted_alpha && levene <= @convergence_alpha
n_significant += 1
end
end
finish = n_significant >= probabilities.size * 0.5
end | ruby | def finished?
return false unless @threads.all? do |t|
t.recent_scores.size == @jump_cutoff
end
probabilities = self.recent_scores_combination_test
n_significant = 0
probabilities.each do |mann_u, levene|
if mann_u <= @adjusted_alpha && levene <= @convergence_alpha
n_significant += 1
end
end
finish = n_significant >= probabilities.size * 0.5
end | [
"def",
"finished?",
"return",
"false",
"unless",
"@threads",
".",
"all?",
"do",
"|",
"t",
"|",
"t",
".",
"recent_scores",
".",
"size",
"==",
"@jump_cutoff",
"end",
"probabilities",
"=",
"self",
".",
"recent_scores_combination_test",
"n_significant",
"=",
"0",
"probabilities",
".",
"each",
"do",
"|",
"mann_u",
",",
"levene",
"|",
"if",
"mann_u",
"<=",
"@adjusted_alpha",
"&&",
"levene",
"<=",
"@convergence_alpha",
"n_significant",
"+=",
"1",
"end",
"end",
"finish",
"=",
"n_significant",
">=",
"probabilities",
".",
"size",
"*",
"0.5",
"end"
] | check termination conditions
and return true if met | [
"check",
"termination",
"conditions",
"and",
"return",
"true",
"if",
"met"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/optimisers/tabu_search.rb#L403-L415 |
5,391 | lautis/sweet_notifications | lib/sweet_notifications/railtie.rb | SweetNotifications.Railtie.initialize_rails | def initialize_rails(name, log_subscriber, controller_runtime)
log_subscriber.attach_to name.to_sym
ActiveSupport.on_load(:action_controller) do
include controller_runtime
end
end | ruby | def initialize_rails(name, log_subscriber, controller_runtime)
log_subscriber.attach_to name.to_sym
ActiveSupport.on_load(:action_controller) do
include controller_runtime
end
end | [
"def",
"initialize_rails",
"(",
"name",
",",
"log_subscriber",
",",
"controller_runtime",
")",
"log_subscriber",
".",
"attach_to",
"name",
".",
"to_sym",
"ActiveSupport",
".",
"on_load",
"(",
":action_controller",
")",
"do",
"include",
"controller_runtime",
"end",
"end"
] | Attach LogSubscriber and ControllerRuntime to a notifications namespace
@param name [Symbol] Notifications namespace
@param log_subscriber [LogSubscriber] subscriber to be attached
@param controller_runtime [Module] mixin that logs runtime | [
"Attach",
"LogSubscriber",
"and",
"ControllerRuntime",
"to",
"a",
"notifications",
"namespace"
] | fcd137a1b474d24e1bc86619d116fc32caba8c19 | https://github.com/lautis/sweet_notifications/blob/fcd137a1b474d24e1bc86619d116fc32caba8c19/lib/sweet_notifications/railtie.rb#L12-L17 |
5,392 | lautis/sweet_notifications | lib/sweet_notifications/railtie.rb | SweetNotifications.Railtie.railtie | def railtie(name, log_subscriber, controller_runtime)
Class.new(Rails::Railtie) do
railtie_name name
initializer "#{name}.notifications" do
SweetNotifications::Railtie.initialize_rails(name,
log_subscriber,
controller_runtime)
end
end
end | ruby | def railtie(name, log_subscriber, controller_runtime)
Class.new(Rails::Railtie) do
railtie_name name
initializer "#{name}.notifications" do
SweetNotifications::Railtie.initialize_rails(name,
log_subscriber,
controller_runtime)
end
end
end | [
"def",
"railtie",
"(",
"name",
",",
"log_subscriber",
",",
"controller_runtime",
")",
"Class",
".",
"new",
"(",
"Rails",
"::",
"Railtie",
")",
"do",
"railtie_name",
"name",
"initializer",
"\"#{name}.notifications\"",
"do",
"SweetNotifications",
"::",
"Railtie",
".",
"initialize_rails",
"(",
"name",
",",
"log_subscriber",
",",
"controller_runtime",
")",
"end",
"end",
"end"
] | Create a Railtie for LogSubscriber and ControllerRuntime mixin
@param name [Symbol] Notifications namespace
@param log_subscriber [LogSubscriber] subscriber to be attached
@param controller_runtime [Module] mixin that logs runtime
@return [Rails::Railtie] Rails initializer | [
"Create",
"a",
"Railtie",
"for",
"LogSubscriber",
"and",
"ControllerRuntime",
"mixin"
] | fcd137a1b474d24e1bc86619d116fc32caba8c19 | https://github.com/lautis/sweet_notifications/blob/fcd137a1b474d24e1bc86619d116fc32caba8c19/lib/sweet_notifications/railtie.rb#L25-L34 |
5,393 | sinefunc/lunar | lib/lunar/result_set.rb | Lunar.ResultSet.sort | def sort(opts = {})
return [] if not distkey
opts[:by] = sortables[opts[:by]] if opts[:by]
if opts[:start] && opts[:limit]
opts[:limit] = [opts[:start], opts[:limit]]
end
objects(distkey.sort(opts))
end | ruby | def sort(opts = {})
return [] if not distkey
opts[:by] = sortables[opts[:by]] if opts[:by]
if opts[:start] && opts[:limit]
opts[:limit] = [opts[:start], opts[:limit]]
end
objects(distkey.sort(opts))
end | [
"def",
"sort",
"(",
"opts",
"=",
"{",
"}",
")",
"return",
"[",
"]",
"if",
"not",
"distkey",
"opts",
"[",
":by",
"]",
"=",
"sortables",
"[",
"opts",
"[",
":by",
"]",
"]",
"if",
"opts",
"[",
":by",
"]",
"if",
"opts",
"[",
":start",
"]",
"&&",
"opts",
"[",
":limit",
"]",
"opts",
"[",
":limit",
"]",
"=",
"[",
"opts",
"[",
":start",
"]",
",",
"opts",
"[",
":limit",
"]",
"]",
"end",
"objects",
"(",
"distkey",
".",
"sort",
"(",
"opts",
")",
")",
"end"
] | Gives the ability to sort the search results via a `sortable` field
in your index.
@example
Lunar.index Gadget do |i|
i.id 1001
i.text :title, "Apple Macbook Pro"
i.sortable :votes, 10
end
Lunar.index Gadget do |i|
i.id 1002
i.text :title, "Apple iPad"
i.sortable :votes, 50
end
results = Lunar.search(Gadget, :q => "apple")
sorted = results.sort(:by => :votes, :order => "DESC")
sorted == [Gadget[1002], Gadget[1001]]
# => true
@param [Hash] opts the various opts to pass to Redis SORT command.
@option opts [#to_s] :by the field in the namespace you want to sort by.
@option opts [#to_s] :order the direction you want to sort i.e. ASC DESC ALPHA
@option opts [Array] :limit offset and max results to return.
@return [Array] Array of objects as defined by the `finder`.
@see http://code.google.com/p/redis/wiki/SortCommand | [
"Gives",
"the",
"ability",
"to",
"sort",
"the",
"search",
"results",
"via",
"a",
"sortable",
"field",
"in",
"your",
"index",
"."
] | efc58f392dd75e771d313eef6cd4ada0d1ac02ff | https://github.com/sinefunc/lunar/blob/efc58f392dd75e771d313eef6cd4ada0d1ac02ff/lib/lunar/result_set.rb#L90-L100 |
5,394 | scepticulous/crypto-toolbox | lib/crypto-toolbox/crypt_buffer/concerns/padding.rb | CryptBufferConcern.Padding.padding | def padding
last = bytes.last
subset = subset_padding
if subset.all?{|e| e == last }
self.class.new(subset)
else
self.class.new([])
end
end | ruby | def padding
last = bytes.last
subset = subset_padding
if subset.all?{|e| e == last }
self.class.new(subset)
else
self.class.new([])
end
end | [
"def",
"padding",
"last",
"=",
"bytes",
".",
"last",
"subset",
"=",
"subset_padding",
"if",
"subset",
".",
"all?",
"{",
"|",
"e",
"|",
"e",
"==",
"last",
"}",
"self",
".",
"class",
".",
"new",
"(",
"subset",
")",
"else",
"self",
".",
"class",
".",
"new",
"(",
"[",
"]",
")",
"end",
"end"
] | Return any existing padding | [
"Return",
"any",
"existing",
"padding"
] | cdbe371109e497db2c2af5c1fe0f359612f44816 | https://github.com/scepticulous/crypto-toolbox/blob/cdbe371109e497db2c2af5c1fe0f359612f44816/lib/crypto-toolbox/crypt_buffer/concerns/padding.rb#L16-L25 |
5,395 | scepticulous/crypto-toolbox | lib/crypto-toolbox/crypt_buffer/concerns/padding.rb | CryptBufferConcern.Padding.strip_padding | def strip_padding
subset = bytes
if padding?
pad = padding
len = pad.length
subset = bytes[0,bytes.length - len]
end
self.class.new(subset)
end | ruby | def strip_padding
subset = bytes
if padding?
pad = padding
len = pad.length
subset = bytes[0,bytes.length - len]
end
self.class.new(subset)
end | [
"def",
"strip_padding",
"subset",
"=",
"bytes",
"if",
"padding?",
"pad",
"=",
"padding",
"len",
"=",
"pad",
".",
"length",
"subset",
"=",
"bytes",
"[",
"0",
",",
"bytes",
".",
"length",
"-",
"len",
"]",
"end",
"self",
".",
"class",
".",
"new",
"(",
"subset",
")",
"end"
] | Strip the existing padding if present | [
"Strip",
"the",
"existing",
"padding",
"if",
"present"
] | cdbe371109e497db2c2af5c1fe0f359612f44816 | https://github.com/scepticulous/crypto-toolbox/blob/cdbe371109e497db2c2af5c1fe0f359612f44816/lib/crypto-toolbox/crypt_buffer/concerns/padding.rb#L28-L37 |
5,396 | thinkerbot/configurable | lib/configurable/conversions.rb | Configurable.Conversions.to_parser | def to_parser(*args, &block)
parser = ConfigParser.new(*args, &block)
traverse do |nesting, config|
next if config[:hidden] == true || nesting.any? {|nest| nest[:hidden] == true }
nest_keys = nesting.collect {|nest| nest.key }
long, short = nesting.collect {|nest| nest.name }.push(config.name).join(':'), nil
long, short = short, long if long.length == 1
guess_attrs = {
:long => long,
:short => short
}
config_attrs = {
:key => config.key,
:nest_keys => nest_keys,
:default => config.default,
:callback => lambda {|value| config.type.cast(value) }
}
attrs = guess_attrs.merge(config.metadata).merge(config_attrs)
parser.on(attrs)
end
parser.sort_opts!
parser
end | ruby | def to_parser(*args, &block)
parser = ConfigParser.new(*args, &block)
traverse do |nesting, config|
next if config[:hidden] == true || nesting.any? {|nest| nest[:hidden] == true }
nest_keys = nesting.collect {|nest| nest.key }
long, short = nesting.collect {|nest| nest.name }.push(config.name).join(':'), nil
long, short = short, long if long.length == 1
guess_attrs = {
:long => long,
:short => short
}
config_attrs = {
:key => config.key,
:nest_keys => nest_keys,
:default => config.default,
:callback => lambda {|value| config.type.cast(value) }
}
attrs = guess_attrs.merge(config.metadata).merge(config_attrs)
parser.on(attrs)
end
parser.sort_opts!
parser
end | [
"def",
"to_parser",
"(",
"*",
"args",
",",
"&",
"block",
")",
"parser",
"=",
"ConfigParser",
".",
"new",
"(",
"args",
",",
"block",
")",
"traverse",
"do",
"|",
"nesting",
",",
"config",
"|",
"next",
"if",
"config",
"[",
":hidden",
"]",
"==",
"true",
"||",
"nesting",
".",
"any?",
"{",
"|",
"nest",
"|",
"nest",
"[",
":hidden",
"]",
"==",
"true",
"}",
"nest_keys",
"=",
"nesting",
".",
"collect",
"{",
"|",
"nest",
"|",
"nest",
".",
"key",
"}",
"long",
",",
"short",
"=",
"nesting",
".",
"collect",
"{",
"|",
"nest",
"|",
"nest",
".",
"name",
"}",
".",
"push",
"(",
"config",
".",
"name",
")",
".",
"join",
"(",
"':'",
")",
",",
"nil",
"long",
",",
"short",
"=",
"short",
",",
"long",
"if",
"long",
".",
"length",
"==",
"1",
"guess_attrs",
"=",
"{",
":long",
"=>",
"long",
",",
":short",
"=>",
"short",
"}",
"config_attrs",
"=",
"{",
":key",
"=>",
"config",
".",
"key",
",",
":nest_keys",
"=>",
"nest_keys",
",",
":default",
"=>",
"config",
".",
"default",
",",
":callback",
"=>",
"lambda",
"{",
"|",
"value",
"|",
"config",
".",
"type",
".",
"cast",
"(",
"value",
")",
"}",
"}",
"attrs",
"=",
"guess_attrs",
".",
"merge",
"(",
"config",
".",
"metadata",
")",
".",
"merge",
"(",
"config_attrs",
")",
"parser",
".",
"on",
"(",
"attrs",
")",
"end",
"parser",
".",
"sort_opts!",
"parser",
"end"
] | Initializes and returns a ConfigParser generated using the configs for
self. Arguments given to parser are passed to the ConfigParser
initializer. | [
"Initializes",
"and",
"returns",
"a",
"ConfigParser",
"generated",
"using",
"the",
"configs",
"for",
"self",
".",
"Arguments",
"given",
"to",
"parser",
"are",
"passed",
"to",
"the",
"ConfigParser",
"initializer",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/conversions.rb#L14-L41 |
5,397 | thinkerbot/configurable | lib/configurable/conversions.rb | Configurable.Conversions.to_default | def to_default
default = {}
each_pair do |key, config|
default[key] = config.default
end
default
end | ruby | def to_default
default = {}
each_pair do |key, config|
default[key] = config.default
end
default
end | [
"def",
"to_default",
"default",
"=",
"{",
"}",
"each_pair",
"do",
"|",
"key",
",",
"config",
"|",
"default",
"[",
"key",
"]",
"=",
"config",
".",
"default",
"end",
"default",
"end"
] | Returns a hash of the default values for each config in self. | [
"Returns",
"a",
"hash",
"of",
"the",
"default",
"values",
"for",
"each",
"config",
"in",
"self",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/conversions.rb#L44-L50 |
5,398 | thinkerbot/configurable | lib/configurable/conversions.rb | Configurable.Conversions.traverse | def traverse(nesting=[], &block)
each_value do |config|
if config.type.kind_of?(NestType)
nesting.push config
configs = config.type.configurable.class.configs
configs.traverse(nesting, &block)
nesting.pop
else
yield(nesting, config)
end
end
end | ruby | def traverse(nesting=[], &block)
each_value do |config|
if config.type.kind_of?(NestType)
nesting.push config
configs = config.type.configurable.class.configs
configs.traverse(nesting, &block)
nesting.pop
else
yield(nesting, config)
end
end
end | [
"def",
"traverse",
"(",
"nesting",
"=",
"[",
"]",
",",
"&",
"block",
")",
"each_value",
"do",
"|",
"config",
"|",
"if",
"config",
".",
"type",
".",
"kind_of?",
"(",
"NestType",
")",
"nesting",
".",
"push",
"config",
"configs",
"=",
"config",
".",
"type",
".",
"configurable",
".",
"class",
".",
"configs",
"configs",
".",
"traverse",
"(",
"nesting",
",",
"block",
")",
"nesting",
".",
"pop",
"else",
"yield",
"(",
"nesting",
",",
"config",
")",
"end",
"end",
"end"
] | Yields each config in configs to the block with nesting, after appened
self to nesting. | [
"Yields",
"each",
"config",
"in",
"configs",
"to",
"the",
"block",
"with",
"nesting",
"after",
"appened",
"self",
"to",
"nesting",
"."
] | 43c611f767f14194827b1fe31bc72c8bdf54efdf | https://github.com/thinkerbot/configurable/blob/43c611f767f14194827b1fe31bc72c8bdf54efdf/lib/configurable/conversions.rb#L78-L89 |
5,399 | ArchimediaZerogroup/KonoUtils | lib/kono_utils/tmp_file.rb | KonoUtils.TmpFile.clean_tmpdir | def clean_tmpdir
self.root_dir.each do |d|
if d != '..' and d!='.'
if d.to_i < Time.now.to_i-TIME_LIMIT
FileUtils.rm_rf(File.join(self.root_dir.path, d))
end
end
end
end | ruby | def clean_tmpdir
self.root_dir.each do |d|
if d != '..' and d!='.'
if d.to_i < Time.now.to_i-TIME_LIMIT
FileUtils.rm_rf(File.join(self.root_dir.path, d))
end
end
end
end | [
"def",
"clean_tmpdir",
"self",
".",
"root_dir",
".",
"each",
"do",
"|",
"d",
"|",
"if",
"d",
"!=",
"'..'",
"and",
"d!",
"=",
"'.'",
"if",
"d",
".",
"to_i",
"<",
"Time",
".",
"now",
".",
"to_i",
"-",
"TIME_LIMIT",
"FileUtils",
".",
"rm_rf",
"(",
"File",
".",
"join",
"(",
"self",
".",
"root_dir",
".",
"path",
",",
"d",
")",
")",
"end",
"end",
"end",
"end"
] | Clean the directory | [
"Clean",
"the",
"directory"
] | a255a30b65e4e0f01cd6236d991da4fd13c64fc6 | https://github.com/ArchimediaZerogroup/KonoUtils/blob/a255a30b65e4e0f01cd6236d991da4fd13c64fc6/lib/kono_utils/tmp_file.rb#L70-L78 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.