id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,600 |
kamui/rack-accept_headers
|
lib/rack/accept_headers/media_type.rb
|
Rack::AcceptHeaders.MediaType.params_match?
|
def params_match?(params, match)
return true if params == match
parsed = parse_range_params(params)
parsed == parsed.merge(parse_range_params(match))
end
|
ruby
|
def params_match?(params, match)
return true if params == match
parsed = parse_range_params(params)
parsed == parsed.merge(parse_range_params(match))
end
|
[
"def",
"params_match?",
"(",
"params",
",",
"match",
")",
"return",
"true",
"if",
"params",
"==",
"match",
"parsed",
"=",
"parse_range_params",
"(",
"params",
")",
"parsed",
"==",
"parsed",
".",
"merge",
"(",
"parse_range_params",
"(",
"match",
")",
")",
"end"
] |
Returns true if all parameters and values in +match+ are also present in
+params+.
|
[
"Returns",
"true",
"if",
"all",
"parameters",
"and",
"values",
"in",
"+",
"match",
"+",
"are",
"also",
"present",
"in",
"+",
"params",
"+",
"."
] |
099bfbb919de86b5842c8e14be42b8b784e53f03
|
https://github.com/kamui/rack-accept_headers/blob/099bfbb919de86b5842c8e14be42b8b784e53f03/lib/rack/accept_headers/media_type.rb#L67-L71
|
7,601 |
drichert/moby
|
lib/moby/parts_of_speech.rb
|
Moby.PartsOfSpeech.words
|
def words(pos_name)
pos.select {|w, c| c.include?(pos_code_map.key(pos_name)) }.keys
end
|
ruby
|
def words(pos_name)
pos.select {|w, c| c.include?(pos_code_map.key(pos_name)) }.keys
end
|
[
"def",
"words",
"(",
"pos_name",
")",
"pos",
".",
"select",
"{",
"|",
"w",
",",
"c",
"|",
"c",
".",
"include?",
"(",
"pos_code_map",
".",
"key",
"(",
"pos_name",
")",
")",
"}",
".",
"keys",
"end"
] |
Get words by pos name
|
[
"Get",
"words",
"by",
"pos",
"name"
] |
7fcbcaf0816832d0b0da0547204dea68cc1dcab9
|
https://github.com/drichert/moby/blob/7fcbcaf0816832d0b0da0547204dea68cc1dcab9/lib/moby/parts_of_speech.rb#L69-L71
|
7,602 |
jarhart/rattler
|
lib/rattler/runtime/packrat_parser.rb
|
Rattler::Runtime.PackratParser.apply
|
def apply(match_method_name)
start_pos = @scanner.pos
if m = memo(match_method_name, start_pos)
recall m, match_method_name
else
m = inject_fail match_method_name, start_pos
save m, eval_rule(match_method_name)
end
end
|
ruby
|
def apply(match_method_name)
start_pos = @scanner.pos
if m = memo(match_method_name, start_pos)
recall m, match_method_name
else
m = inject_fail match_method_name, start_pos
save m, eval_rule(match_method_name)
end
end
|
[
"def",
"apply",
"(",
"match_method_name",
")",
"start_pos",
"=",
"@scanner",
".",
"pos",
"if",
"m",
"=",
"memo",
"(",
"match_method_name",
",",
"start_pos",
")",
"recall",
"m",
",",
"match_method_name",
"else",
"m",
"=",
"inject_fail",
"match_method_name",
",",
"start_pos",
"save",
"m",
",",
"eval_rule",
"(",
"match_method_name",
")",
"end",
"end"
] |
Apply a rule by dispatching to the given match method. The result of
applying the rule is memoized so that the match method is invoked at most
once at a given parse position.
@param (see RecursiveDescentParser#apply)
@return (see RecursiveDescentParser#apply)
|
[
"Apply",
"a",
"rule",
"by",
"dispatching",
"to",
"the",
"given",
"match",
"method",
".",
"The",
"result",
"of",
"applying",
"the",
"rule",
"is",
"memoized",
"so",
"that",
"the",
"match",
"method",
"is",
"invoked",
"at",
"most",
"once",
"at",
"a",
"given",
"parse",
"position",
"."
] |
8b4efde2a05e9e790955bb635d4a1a9615893719
|
https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/runtime/packrat_parser.rb#L29-L37
|
7,603 |
mikiobraun/jblas-ruby
|
lib/jblas/mixin_class.rb
|
JBLAS.MatrixClassMixin.from_array
|
def from_array(data)
n = data.length
if data.reject{|l| Numeric === l}.size == 0
a = self.new(n, 1)
(0...data.length).each do |i|
a[i, 0] = data[i]
end
return a
else
begin
lengths = data.collect{|v| v.length}
rescue
raise "All columns must be arrays"
end
raise "All columns must have equal length!" if lengths.min < lengths.max
a = self.new(n, lengths.max)
for i in 0...n
for j in 0...lengths.max
a[i,j] = data[i][j]
end
end
return a
end
end
|
ruby
|
def from_array(data)
n = data.length
if data.reject{|l| Numeric === l}.size == 0
a = self.new(n, 1)
(0...data.length).each do |i|
a[i, 0] = data[i]
end
return a
else
begin
lengths = data.collect{|v| v.length}
rescue
raise "All columns must be arrays"
end
raise "All columns must have equal length!" if lengths.min < lengths.max
a = self.new(n, lengths.max)
for i in 0...n
for j in 0...lengths.max
a[i,j] = data[i][j]
end
end
return a
end
end
|
[
"def",
"from_array",
"(",
"data",
")",
"n",
"=",
"data",
".",
"length",
"if",
"data",
".",
"reject",
"{",
"|",
"l",
"|",
"Numeric",
"===",
"l",
"}",
".",
"size",
"==",
"0",
"a",
"=",
"self",
".",
"new",
"(",
"n",
",",
"1",
")",
"(",
"0",
"...",
"data",
".",
"length",
")",
".",
"each",
"do",
"|",
"i",
"|",
"a",
"[",
"i",
",",
"0",
"]",
"=",
"data",
"[",
"i",
"]",
"end",
"return",
"a",
"else",
"begin",
"lengths",
"=",
"data",
".",
"collect",
"{",
"|",
"v",
"|",
"v",
".",
"length",
"}",
"rescue",
"raise",
"\"All columns must be arrays\"",
"end",
"raise",
"\"All columns must have equal length!\"",
"if",
"lengths",
".",
"min",
"<",
"lengths",
".",
"max",
"a",
"=",
"self",
".",
"new",
"(",
"n",
",",
"lengths",
".",
"max",
")",
"for",
"i",
"in",
"0",
"...",
"n",
"for",
"j",
"in",
"0",
"...",
"lengths",
".",
"max",
"a",
"[",
"i",
",",
"j",
"]",
"=",
"data",
"[",
"i",
"]",
"[",
"j",
"]",
"end",
"end",
"return",
"a",
"end",
"end"
] |
Create a new matrix. There are two ways to use this function
<b>pass an array</b>::
Constructs a column vector. For example: DoubleMatrix.from_array 1, 2, 3
<b>pass an array of arrays</b>::
Constructs a matrix, inner arrays are rows. For
example: DoubleMatrix.from_array [[1,2,3],[4,5,6]]
See also [], JBLAS#mat
|
[
"Create",
"a",
"new",
"matrix",
".",
"There",
"are",
"two",
"ways",
"to",
"use",
"this",
"function"
] |
7233976c9e3b210e30bc36ead2b1e05ab3383fec
|
https://github.com/mikiobraun/jblas-ruby/blob/7233976c9e3b210e30bc36ead2b1e05ab3383fec/lib/jblas/mixin_class.rb#L55-L78
|
7,604 |
OpenBEL/bel_parser
|
examples/upgrade_kinase.rb
|
Main.TermASTGenerator.each
|
def each(io)
if block_given?
filter = BELParser::ASTFilter.new(
BELParser::ASTGenerator.new(io),
*TYPES)
filter.each do |results|
yield results
end
else
enum_for(:each, io)
end
end
|
ruby
|
def each(io)
if block_given?
filter = BELParser::ASTFilter.new(
BELParser::ASTGenerator.new(io),
*TYPES)
filter.each do |results|
yield results
end
else
enum_for(:each, io)
end
end
|
[
"def",
"each",
"(",
"io",
")",
"if",
"block_given?",
"filter",
"=",
"BELParser",
"::",
"ASTFilter",
".",
"new",
"(",
"BELParser",
"::",
"ASTGenerator",
".",
"new",
"(",
"io",
")",
",",
"TYPES",
")",
"filter",
".",
"each",
"do",
"|",
"results",
"|",
"yield",
"results",
"end",
"else",
"enum_for",
"(",
":each",
",",
"io",
")",
"end",
"end"
] |
Yields Term AST to the block argument or provides an enumerator of
Term AST.
|
[
"Yields",
"Term",
"AST",
"to",
"the",
"block",
"argument",
"or",
"provides",
"an",
"enumerator",
"of",
"Term",
"AST",
"."
] |
f0a35de93c300abff76c22e54696a83d22a4fbc9
|
https://github.com/OpenBEL/bel_parser/blob/f0a35de93c300abff76c22e54696a83d22a4fbc9/examples/upgrade_kinase.rb#L20-L31
|
7,605 |
jemmyw/bisques
|
lib/bisques/aws_connection.rb
|
Bisques.AwsConnection.request
|
def request(method, path, query = {}, body = nil, headers = {})
AwsRequest.new(aws_http_connection).tap do |aws_request|
aws_request.credentials = credentials
aws_request.path = path
aws_request.region = region
aws_request.service = service
aws_request.method = method
aws_request.query = query
aws_request.body = body
aws_request.headers = headers
aws_request.make_request
end
end
|
ruby
|
def request(method, path, query = {}, body = nil, headers = {})
AwsRequest.new(aws_http_connection).tap do |aws_request|
aws_request.credentials = credentials
aws_request.path = path
aws_request.region = region
aws_request.service = service
aws_request.method = method
aws_request.query = query
aws_request.body = body
aws_request.headers = headers
aws_request.make_request
end
end
|
[
"def",
"request",
"(",
"method",
",",
"path",
",",
"query",
"=",
"{",
"}",
",",
"body",
"=",
"nil",
",",
"headers",
"=",
"{",
"}",
")",
"AwsRequest",
".",
"new",
"(",
"aws_http_connection",
")",
".",
"tap",
"do",
"|",
"aws_request",
"|",
"aws_request",
".",
"credentials",
"=",
"credentials",
"aws_request",
".",
"path",
"=",
"path",
"aws_request",
".",
"region",
"=",
"region",
"aws_request",
".",
"service",
"=",
"service",
"aws_request",
".",
"method",
"=",
"method",
"aws_request",
".",
"query",
"=",
"query",
"aws_request",
".",
"body",
"=",
"body",
"aws_request",
".",
"headers",
"=",
"headers",
"aws_request",
".",
"make_request",
"end",
"end"
] |
Give the region, service and optionally the AwsCredentials.
@param [String] region the AWS region (ex. us-east-1)
@param [String] service the AWS service (ex. sqs)
@param [AwsCredentials] credentials
@example
class Sqs
include AwsConnection
def initialize(region)
super(region, 'sqs')
end
end
Perform an HTTP query to the given path using the given method (GET,
POST, PUT, DELETE). A hash of query params can be specified. A POST or
PUT body cna be specified as either a string or a hash of form params. A
hash of HTTP headers can be specified.
@param [String] method HTTP method, should be GET, POST, PUT or DELETE
@param [String] path
@param [Hash] query HTTP query params to send. Specify these as a hash, do not append them to the path.
@param [Hash,#to_s] body HTTP request body. This can be form data as a hash or a String. Only applies to POST and PUT HTTP methods.
@param [Hash] headers additional HTTP headers to send.
@return [AwsRequest]
|
[
"Give",
"the",
"region",
"service",
"and",
"optionally",
"the",
"AwsCredentials",
"."
] |
c48ab555f07664752bcbf9e8deb99bd75cbdc41b
|
https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/aws_connection.rb#L70-L82
|
7,606 |
jemmyw/bisques
|
lib/bisques/aws_connection.rb
|
Bisques.AwsConnection.action
|
def action(action_name, path = "/", options = {})
retries = 0
begin
# If options given in place of path assume /
options, path = path, "/" if path.is_a?(Hash) && options.empty?
request(:post, path, {}, options.merge("Action" => action_name)).response.tap do |response|
unless response.success?
element = response.doc.xpath("//Error")
raise AwsActionError.new(element.xpath("Type").text, element.xpath("Code").text, element.xpath("Message").text, response.http_response.status)
end
end
rescue AwsActionError => e
if retries < 2 && (500..599).include?(e.status.to_i)
retries += 1
retry
else
raise e
end
end
end
|
ruby
|
def action(action_name, path = "/", options = {})
retries = 0
begin
# If options given in place of path assume /
options, path = path, "/" if path.is_a?(Hash) && options.empty?
request(:post, path, {}, options.merge("Action" => action_name)).response.tap do |response|
unless response.success?
element = response.doc.xpath("//Error")
raise AwsActionError.new(element.xpath("Type").text, element.xpath("Code").text, element.xpath("Message").text, response.http_response.status)
end
end
rescue AwsActionError => e
if retries < 2 && (500..599).include?(e.status.to_i)
retries += 1
retry
else
raise e
end
end
end
|
[
"def",
"action",
"(",
"action_name",
",",
"path",
"=",
"\"/\"",
",",
"options",
"=",
"{",
"}",
")",
"retries",
"=",
"0",
"begin",
"# If options given in place of path assume /",
"options",
",",
"path",
"=",
"path",
",",
"\"/\"",
"if",
"path",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"options",
".",
"empty?",
"request",
"(",
":post",
",",
"path",
",",
"{",
"}",
",",
"options",
".",
"merge",
"(",
"\"Action\"",
"=>",
"action_name",
")",
")",
".",
"response",
".",
"tap",
"do",
"|",
"response",
"|",
"unless",
"response",
".",
"success?",
"element",
"=",
"response",
".",
"doc",
".",
"xpath",
"(",
"\"//Error\"",
")",
"raise",
"AwsActionError",
".",
"new",
"(",
"element",
".",
"xpath",
"(",
"\"Type\"",
")",
".",
"text",
",",
"element",
".",
"xpath",
"(",
"\"Code\"",
")",
".",
"text",
",",
"element",
".",
"xpath",
"(",
"\"Message\"",
")",
".",
"text",
",",
"response",
".",
"http_response",
".",
"status",
")",
"end",
"end",
"rescue",
"AwsActionError",
"=>",
"e",
"if",
"retries",
"<",
"2",
"&&",
"(",
"500",
"..",
"599",
")",
".",
"include?",
"(",
"e",
".",
"status",
".",
"to_i",
")",
"retries",
"+=",
"1",
"retry",
"else",
"raise",
"e",
"end",
"end",
"end"
] |
Call an AWS API with the given name at the given path. An optional hash
of options can be passed as arguments for the API call.
@note The API call will be automatically retried *once* if the returned status code is
in the 500 range.
@param [String] action_name
@param [String] path
@param [Hash] options
@return [AwsResponse]
@raise [AwsActionError] if the response is not successful. AWS error
information can be extracted from the exception.
|
[
"Call",
"an",
"AWS",
"API",
"with",
"the",
"given",
"name",
"at",
"the",
"given",
"path",
".",
"An",
"optional",
"hash",
"of",
"options",
"can",
"be",
"passed",
"as",
"arguments",
"for",
"the",
"API",
"call",
"."
] |
c48ab555f07664752bcbf9e8deb99bd75cbdc41b
|
https://github.com/jemmyw/bisques/blob/c48ab555f07664752bcbf9e8deb99bd75cbdc41b/lib/bisques/aws_connection.rb#L96-L116
|
7,607 |
NullVoxPopuli/authorizable
|
lib/authorizable/controller.rb
|
Authorizable.Controller.is_authorized_for_action?
|
def is_authorized_for_action?
action = params[:action].to_sym
self.class.authorizable_config ||= DefaultConfig.config
if !self.class.authorizable_config[action]
action = Authorizable::Controller.alias_action(action)
end
# retrieve the settings for this particular controller action
settings_for_action = self.class.authorizable_config[action]
# continue with evaluation
result = is_authorized_for_action_with_config?(action, settings_for_action)
# if we are configured to raise exception instead of handle the error
# ourselves, raise the exception!
if Authorizable.configuration.raise_exception_on_denial? and !result
raise Authorizable::Error::NotAuthorized.new(
action: action,
subject: params[:controller]
)
end
result
end
|
ruby
|
def is_authorized_for_action?
action = params[:action].to_sym
self.class.authorizable_config ||= DefaultConfig.config
if !self.class.authorizable_config[action]
action = Authorizable::Controller.alias_action(action)
end
# retrieve the settings for this particular controller action
settings_for_action = self.class.authorizable_config[action]
# continue with evaluation
result = is_authorized_for_action_with_config?(action, settings_for_action)
# if we are configured to raise exception instead of handle the error
# ourselves, raise the exception!
if Authorizable.configuration.raise_exception_on_denial? and !result
raise Authorizable::Error::NotAuthorized.new(
action: action,
subject: params[:controller]
)
end
result
end
|
[
"def",
"is_authorized_for_action?",
"action",
"=",
"params",
"[",
":action",
"]",
".",
"to_sym",
"self",
".",
"class",
".",
"authorizable_config",
"||=",
"DefaultConfig",
".",
"config",
"if",
"!",
"self",
".",
"class",
".",
"authorizable_config",
"[",
"action",
"]",
"action",
"=",
"Authorizable",
"::",
"Controller",
".",
"alias_action",
"(",
"action",
")",
"end",
"# retrieve the settings for this particular controller action",
"settings_for_action",
"=",
"self",
".",
"class",
".",
"authorizable_config",
"[",
"action",
"]",
"# continue with evaluation",
"result",
"=",
"is_authorized_for_action_with_config?",
"(",
"action",
",",
"settings_for_action",
")",
"# if we are configured to raise exception instead of handle the error",
"# ourselves, raise the exception!",
"if",
"Authorizable",
".",
"configuration",
".",
"raise_exception_on_denial?",
"and",
"!",
"result",
"raise",
"Authorizable",
"::",
"Error",
"::",
"NotAuthorized",
".",
"new",
"(",
"action",
":",
"action",
",",
"subject",
":",
"params",
"[",
":controller",
"]",
")",
"end",
"result",
"end"
] |
check if the resource can perform the action
@raise [Authorizable::Error::NotAuthorized] if configured to raise
exception instead of handle the errors
@return [Boolean] the result of the permission evaluation
will halt controller flow
|
[
"check",
"if",
"the",
"resource",
"can",
"perform",
"the",
"action"
] |
6a4ef94848861bb79b0ab1454264366aed4e2db8
|
https://github.com/NullVoxPopuli/authorizable/blob/6a4ef94848861bb79b0ab1454264366aed4e2db8/lib/authorizable/controller.rb#L22-L46
|
7,608 |
NullVoxPopuli/authorizable
|
lib/authorizable/controller.rb
|
Authorizable.Controller.is_authorized_for_action_with_config?
|
def is_authorized_for_action_with_config?(action, config)
request_may_proceed = false
return true unless config.present?
defaults = {
user: current_user,
permission: action.to_s,
message: I18n.t('authorizable.not_authorized'),
flash_type: Authorizable.configuration.flash_error
}
options = defaults.merge(config)
# run permission
request_may_proceed = evaluate_action_permission(options)
# redirect
unless request_may_proceed and request.format == :html
authorizable_respond_with(
options[:flash_type],
options[:message],
options[:redirect_path]
)
# halt
return false
end
# proceed with request execution
true
end
|
ruby
|
def is_authorized_for_action_with_config?(action, config)
request_may_proceed = false
return true unless config.present?
defaults = {
user: current_user,
permission: action.to_s,
message: I18n.t('authorizable.not_authorized'),
flash_type: Authorizable.configuration.flash_error
}
options = defaults.merge(config)
# run permission
request_may_proceed = evaluate_action_permission(options)
# redirect
unless request_may_proceed and request.format == :html
authorizable_respond_with(
options[:flash_type],
options[:message],
options[:redirect_path]
)
# halt
return false
end
# proceed with request execution
true
end
|
[
"def",
"is_authorized_for_action_with_config?",
"(",
"action",
",",
"config",
")",
"request_may_proceed",
"=",
"false",
"return",
"true",
"unless",
"config",
".",
"present?",
"defaults",
"=",
"{",
"user",
":",
"current_user",
",",
"permission",
":",
"action",
".",
"to_s",
",",
"message",
":",
"I18n",
".",
"t",
"(",
"'authorizable.not_authorized'",
")",
",",
"flash_type",
":",
"Authorizable",
".",
"configuration",
".",
"flash_error",
"}",
"options",
"=",
"defaults",
".",
"merge",
"(",
"config",
")",
"# run permission",
"request_may_proceed",
"=",
"evaluate_action_permission",
"(",
"options",
")",
"# redirect",
"unless",
"request_may_proceed",
"and",
"request",
".",
"format",
"==",
":html",
"authorizable_respond_with",
"(",
"options",
"[",
":flash_type",
"]",
",",
"options",
"[",
":message",
"]",
",",
"options",
"[",
":redirect_path",
"]",
")",
"# halt",
"return",
"false",
"end",
"# proceed with request execution",
"true",
"end"
] |
check if the resource can perform the action and respond
according to the specefied config
@param [Symbol] action the current controller action
@param [Hash] config the configuration for what to do with the given action
@return [Boolean] the result of the permission evaluation
|
[
"check",
"if",
"the",
"resource",
"can",
"perform",
"the",
"action",
"and",
"respond",
"according",
"to",
"the",
"specefied",
"config"
] |
6a4ef94848861bb79b0ab1454264366aed4e2db8
|
https://github.com/NullVoxPopuli/authorizable/blob/6a4ef94848861bb79b0ab1454264366aed4e2db8/lib/authorizable/controller.rb#L54-L84
|
7,609 |
NullVoxPopuli/authorizable
|
lib/authorizable/controller.rb
|
Authorizable.Controller.evaluate_action_permission
|
def evaluate_action_permission(options)
# the target is the @resource
# (@event, @user, @page, whatever)
# it must exist in order to perform a permission check
# involving the object
if options[:target]
object = instance_variable_get("@#{options[:target]}")
return options[:user].can?(options[:permission], object)
else
return options[:user].can?(options[:permission])
end
end
|
ruby
|
def evaluate_action_permission(options)
# the target is the @resource
# (@event, @user, @page, whatever)
# it must exist in order to perform a permission check
# involving the object
if options[:target]
object = instance_variable_get("@#{options[:target]}")
return options[:user].can?(options[:permission], object)
else
return options[:user].can?(options[:permission])
end
end
|
[
"def",
"evaluate_action_permission",
"(",
"options",
")",
"# the target is the @resource",
"# (@event, @user, @page, whatever)",
"# it must exist in order to perform a permission check",
"# involving the object",
"if",
"options",
"[",
":target",
"]",
"object",
"=",
"instance_variable_get",
"(",
"\"@#{options[:target]}\"",
")",
"return",
"options",
"[",
":user",
"]",
".",
"can?",
"(",
"options",
"[",
":permission",
"]",
",",
"object",
")",
"else",
"return",
"options",
"[",
":user",
"]",
".",
"can?",
"(",
"options",
"[",
":permission",
"]",
")",
"end",
"end"
] |
run the permission
@param [Hash] options the data for the permission
@return [Boolean] the result of the permission
|
[
"run",
"the",
"permission"
] |
6a4ef94848861bb79b0ab1454264366aed4e2db8
|
https://github.com/NullVoxPopuli/authorizable/blob/6a4ef94848861bb79b0ab1454264366aed4e2db8/lib/authorizable/controller.rb#L90-L101
|
7,610 |
khiemns54/takenoko
|
lib/takenoko/attach_helper.rb
|
Takenoko.AttachHelper.get_drive_files_list
|
def get_drive_files_list(folder)
ls = Hash.new
page_token = nil
begin
(files, page_token) = folder.files("pageToken" => page_token)
files.each do |f|
ls[f.original_filename] = f
end
end while page_token
return ls
end
|
ruby
|
def get_drive_files_list(folder)
ls = Hash.new
page_token = nil
begin
(files, page_token) = folder.files("pageToken" => page_token)
files.each do |f|
ls[f.original_filename] = f
end
end while page_token
return ls
end
|
[
"def",
"get_drive_files_list",
"(",
"folder",
")",
"ls",
"=",
"Hash",
".",
"new",
"page_token",
"=",
"nil",
"begin",
"(",
"files",
",",
"page_token",
")",
"=",
"folder",
".",
"files",
"(",
"\"pageToken\"",
"=>",
"page_token",
")",
"files",
".",
"each",
"do",
"|",
"f",
"|",
"ls",
"[",
"f",
".",
"original_filename",
"]",
"=",
"f",
"end",
"end",
"while",
"page_token",
"return",
"ls",
"end"
] |
Get all file from drive folder
|
[
"Get",
"all",
"file",
"from",
"drive",
"folder"
] |
5105f32fcf6b39c0e63e61935d372851de665b54
|
https://github.com/khiemns54/takenoko/blob/5105f32fcf6b39c0e63e61935d372851de665b54/lib/takenoko/attach_helper.rb#L53-L63
|
7,611 |
jeanlescure/hipster_sql_to_hbase
|
lib/result_tree_to_hbase_converter.rb
|
HipsterSqlToHbase.ResultTreeToHbaseConverter.insert_sentence
|
def insert_sentence(hash)
thrift_method = "mutateRow"
thrift_table = hash[:into]
thrift_calls = []
hash[:values].each do |value_set|
thrift_row = SecureRandom.uuid
thrift_mutations = []
i = 0
hash[:columns].each do |col|
thrift_mutations << HBase::Mutation.new(column: col, value: value_set[i].to_s)
i += 1
end
thrift_calls << {:method => thrift_method,:arguments => [thrift_table,thrift_row,thrift_mutations,{}]}
end
HipsterSqlToHbase::ThriftCallGroup.new(thrift_calls,true)
end
|
ruby
|
def insert_sentence(hash)
thrift_method = "mutateRow"
thrift_table = hash[:into]
thrift_calls = []
hash[:values].each do |value_set|
thrift_row = SecureRandom.uuid
thrift_mutations = []
i = 0
hash[:columns].each do |col|
thrift_mutations << HBase::Mutation.new(column: col, value: value_set[i].to_s)
i += 1
end
thrift_calls << {:method => thrift_method,:arguments => [thrift_table,thrift_row,thrift_mutations,{}]}
end
HipsterSqlToHbase::ThriftCallGroup.new(thrift_calls,true)
end
|
[
"def",
"insert_sentence",
"(",
"hash",
")",
"thrift_method",
"=",
"\"mutateRow\"",
"thrift_table",
"=",
"hash",
"[",
":into",
"]",
"thrift_calls",
"=",
"[",
"]",
"hash",
"[",
":values",
"]",
".",
"each",
"do",
"|",
"value_set",
"|",
"thrift_row",
"=",
"SecureRandom",
".",
"uuid",
"thrift_mutations",
"=",
"[",
"]",
"i",
"=",
"0",
"hash",
"[",
":columns",
"]",
".",
"each",
"do",
"|",
"col",
"|",
"thrift_mutations",
"<<",
"HBase",
"::",
"Mutation",
".",
"new",
"(",
"column",
":",
"col",
",",
"value",
":",
"value_set",
"[",
"i",
"]",
".",
"to_s",
")",
"i",
"+=",
"1",
"end",
"thrift_calls",
"<<",
"{",
":method",
"=>",
"thrift_method",
",",
":arguments",
"=>",
"[",
"thrift_table",
",",
"thrift_row",
",",
"thrift_mutations",
",",
"{",
"}",
"]",
"}",
"end",
"HipsterSqlToHbase",
"::",
"ThriftCallGroup",
".",
"new",
"(",
"thrift_calls",
",",
"true",
")",
"end"
] |
When SQL sentence is an INSERT query generate the Thrift mutations according
to the specified query values.
|
[
"When",
"SQL",
"sentence",
"is",
"an",
"INSERT",
"query",
"generate",
"the",
"Thrift",
"mutations",
"according",
"to",
"the",
"specified",
"query",
"values",
"."
] |
eb181f2f869606a8fd68e88bde0a485051f262b8
|
https://github.com/jeanlescure/hipster_sql_to_hbase/blob/eb181f2f869606a8fd68e88bde0a485051f262b8/lib/result_tree_to_hbase_converter.rb#L35-L50
|
7,612 |
jeanlescure/hipster_sql_to_hbase
|
lib/result_tree_to_hbase_converter.rb
|
HipsterSqlToHbase.ResultTreeToHbaseConverter.select_sentence
|
def select_sentence(hash)
thrift_method = "getRowsByScanner"
thrift_table = hash[:from]
thrift_columns = hash[:select]
thrift_filters = recurse_where(hash[:where] || [])
thrift_limit = hash[:limit]
HipsterSqlToHbase::ThriftCallGroup.new([{:method => thrift_method,:arguments => [thrift_table,thrift_columns,thrift_filters,thrift_limit,{}]}])
end
|
ruby
|
def select_sentence(hash)
thrift_method = "getRowsByScanner"
thrift_table = hash[:from]
thrift_columns = hash[:select]
thrift_filters = recurse_where(hash[:where] || [])
thrift_limit = hash[:limit]
HipsterSqlToHbase::ThriftCallGroup.new([{:method => thrift_method,:arguments => [thrift_table,thrift_columns,thrift_filters,thrift_limit,{}]}])
end
|
[
"def",
"select_sentence",
"(",
"hash",
")",
"thrift_method",
"=",
"\"getRowsByScanner\"",
"thrift_table",
"=",
"hash",
"[",
":from",
"]",
"thrift_columns",
"=",
"hash",
"[",
":select",
"]",
"thrift_filters",
"=",
"recurse_where",
"(",
"hash",
"[",
":where",
"]",
"||",
"[",
"]",
")",
"thrift_limit",
"=",
"hash",
"[",
":limit",
"]",
"HipsterSqlToHbase",
"::",
"ThriftCallGroup",
".",
"new",
"(",
"[",
"{",
":method",
"=>",
"thrift_method",
",",
":arguments",
"=>",
"[",
"thrift_table",
",",
"thrift_columns",
",",
"thrift_filters",
",",
"thrift_limit",
",",
"{",
"}",
"]",
"}",
"]",
")",
"end"
] |
When SQL sentence is a SELECT query generate the Thrift filters according
to the specified query values.
|
[
"When",
"SQL",
"sentence",
"is",
"a",
"SELECT",
"query",
"generate",
"the",
"Thrift",
"filters",
"according",
"to",
"the",
"specified",
"query",
"values",
"."
] |
eb181f2f869606a8fd68e88bde0a485051f262b8
|
https://github.com/jeanlescure/hipster_sql_to_hbase/blob/eb181f2f869606a8fd68e88bde0a485051f262b8/lib/result_tree_to_hbase_converter.rb#L54-L62
|
7,613 |
jeanlescure/hipster_sql_to_hbase
|
lib/result_tree_to_hbase_converter.rb
|
HipsterSqlToHbase.ResultTreeToHbaseConverter.filters_from_key_value_pair
|
def filters_from_key_value_pair(kvp)
kvp[:qualifier] = kvp[:column].split(':')
kvp[:column] = kvp[:qualifier].shift
if (kvp[:condition].to_s != "LIKE")
"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',#{kvp[:condition]},'binary:#{kvp[:value]}',true,true))"
else
kvp[:value] = Regexp.escape(kvp[:value])
kvp[:value].sub!(/^%/,"^.*")
kvp[:value].sub!(/%$/,".*$")
while kvp[:value].match(/([^\\]{1,1})%/)
kvp[:value].sub!(/([^\\]{1,1})%/,"#{$1}.*?")
end
kvp[:value].sub!(/^_/,"^.")
kvp[:value].sub!(/_$/,".$")
while kvp[:value].match(/([^\\]{1,1})_/)
kvp[:value].sub!(/([^\\]{1,1})_/,"#{$1}.")
end
"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',=,'regexstring:#{kvp[:value]}',true,true))"
end
end
|
ruby
|
def filters_from_key_value_pair(kvp)
kvp[:qualifier] = kvp[:column].split(':')
kvp[:column] = kvp[:qualifier].shift
if (kvp[:condition].to_s != "LIKE")
"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',#{kvp[:condition]},'binary:#{kvp[:value]}',true,true))"
else
kvp[:value] = Regexp.escape(kvp[:value])
kvp[:value].sub!(/^%/,"^.*")
kvp[:value].sub!(/%$/,".*$")
while kvp[:value].match(/([^\\]{1,1})%/)
kvp[:value].sub!(/([^\\]{1,1})%/,"#{$1}.*?")
end
kvp[:value].sub!(/^_/,"^.")
kvp[:value].sub!(/_$/,".$")
while kvp[:value].match(/([^\\]{1,1})_/)
kvp[:value].sub!(/([^\\]{1,1})_/,"#{$1}.")
end
"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',=,'regexstring:#{kvp[:value]}',true,true))"
end
end
|
[
"def",
"filters_from_key_value_pair",
"(",
"kvp",
")",
"kvp",
"[",
":qualifier",
"]",
"=",
"kvp",
"[",
":column",
"]",
".",
"split",
"(",
"':'",
")",
"kvp",
"[",
":column",
"]",
"=",
"kvp",
"[",
":qualifier",
"]",
".",
"shift",
"if",
"(",
"kvp",
"[",
":condition",
"]",
".",
"to_s",
"!=",
"\"LIKE\"",
")",
"\"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',#{kvp[:condition]},'binary:#{kvp[:value]}',true,true))\"",
"else",
"kvp",
"[",
":value",
"]",
"=",
"Regexp",
".",
"escape",
"(",
"kvp",
"[",
":value",
"]",
")",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"/",
",",
"\"^.*\"",
")",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"/",
",",
"\".*$\"",
")",
"while",
"kvp",
"[",
":value",
"]",
".",
"match",
"(",
"/",
"\\\\",
"/",
")",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"\\\\",
"/",
",",
"\"#{$1}.*?\"",
")",
"end",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"/",
",",
"\"^.\"",
")",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"/",
",",
"\".$\"",
")",
"while",
"kvp",
"[",
":value",
"]",
".",
"match",
"(",
"/",
"\\\\",
"/",
")",
"kvp",
"[",
":value",
"]",
".",
"sub!",
"(",
"/",
"\\\\",
"/",
",",
"\"#{$1}.\"",
")",
"end",
"\"(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',=,'regexstring:#{kvp[:value]}',true,true))\"",
"end",
"end"
] |
Generate a Thrift QualifierFilter and ValueFilter from key value pair.
|
[
"Generate",
"a",
"Thrift",
"QualifierFilter",
"and",
"ValueFilter",
"from",
"key",
"value",
"pair",
"."
] |
eb181f2f869606a8fd68e88bde0a485051f262b8
|
https://github.com/jeanlescure/hipster_sql_to_hbase/blob/eb181f2f869606a8fd68e88bde0a485051f262b8/lib/result_tree_to_hbase_converter.rb#L100-L119
|
7,614 |
JamitLabs/TMSync
|
lib/tmsync.rb
|
Tmsync.FileSearch.find_all_grouped_by_language
|
def find_all_grouped_by_language
all_files = Dir.glob(File.join(@base_path, '**/*'))
# apply exclude regex
found_files = all_files.select { |file_path|
file_path !~ @exclude_regex && !File.directory?(file_path)
}
# exclude empty files
found_files = found_files.select { |file_path|
content = File.open(file_path, 'r') { |f| f.read }
!content.to_s.scrub("<?>").strip.empty?
}
# apply matching regex
found_files = found_files.select { |file_path|
file_path =~ @matching_regex
}.map { |file_path|
[file_path.match(@matching_regex).captures.last, file_path]
}
result = found_files.group_by(&:first).map { |k,v| [k, v.each(&:shift).flatten] }.to_h
# replace nil key with fallback language
if !(nil_values = result[nil]).nil?
result[Tmsync::Constants::FALLBACK_LANGUAGE] = nil_values
result.delete(nil)
end
result
end
|
ruby
|
def find_all_grouped_by_language
all_files = Dir.glob(File.join(@base_path, '**/*'))
# apply exclude regex
found_files = all_files.select { |file_path|
file_path !~ @exclude_regex && !File.directory?(file_path)
}
# exclude empty files
found_files = found_files.select { |file_path|
content = File.open(file_path, 'r') { |f| f.read }
!content.to_s.scrub("<?>").strip.empty?
}
# apply matching regex
found_files = found_files.select { |file_path|
file_path =~ @matching_regex
}.map { |file_path|
[file_path.match(@matching_regex).captures.last, file_path]
}
result = found_files.group_by(&:first).map { |k,v| [k, v.each(&:shift).flatten] }.to_h
# replace nil key with fallback language
if !(nil_values = result[nil]).nil?
result[Tmsync::Constants::FALLBACK_LANGUAGE] = nil_values
result.delete(nil)
end
result
end
|
[
"def",
"find_all_grouped_by_language",
"all_files",
"=",
"Dir",
".",
"glob",
"(",
"File",
".",
"join",
"(",
"@base_path",
",",
"'**/*'",
")",
")",
"# apply exclude regex",
"found_files",
"=",
"all_files",
".",
"select",
"{",
"|",
"file_path",
"|",
"file_path",
"!~",
"@exclude_regex",
"&&",
"!",
"File",
".",
"directory?",
"(",
"file_path",
")",
"}",
"# exclude empty files",
"found_files",
"=",
"found_files",
".",
"select",
"{",
"|",
"file_path",
"|",
"content",
"=",
"File",
".",
"open",
"(",
"file_path",
",",
"'r'",
")",
"{",
"|",
"f",
"|",
"f",
".",
"read",
"}",
"!",
"content",
".",
"to_s",
".",
"scrub",
"(",
"\"<?>\"",
")",
".",
"strip",
".",
"empty?",
"}",
"# apply matching regex",
"found_files",
"=",
"found_files",
".",
"select",
"{",
"|",
"file_path",
"|",
"file_path",
"=~",
"@matching_regex",
"}",
".",
"map",
"{",
"|",
"file_path",
"|",
"[",
"file_path",
".",
"match",
"(",
"@matching_regex",
")",
".",
"captures",
".",
"last",
",",
"file_path",
"]",
"}",
"result",
"=",
"found_files",
".",
"group_by",
"(",
":first",
")",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"k",
",",
"v",
".",
"each",
"(",
":shift",
")",
".",
"flatten",
"]",
"}",
".",
"to_h",
"# replace nil key with fallback language",
"if",
"!",
"(",
"nil_values",
"=",
"result",
"[",
"nil",
"]",
")",
".",
"nil?",
"result",
"[",
"Tmsync",
"::",
"Constants",
"::",
"FALLBACK_LANGUAGE",
"]",
"=",
"nil_values",
"result",
".",
"delete",
"(",
"nil",
")",
"end",
"result",
"end"
] |
Initializes a file search object.
@param [String] base_path the path of the directory to search within
@param [String] matching_regex a regex that all localizable files match, optionally including a catch group for the language
@param [String] exclude_regex a regex to exclude some matches from matching_regex
Finds all files with corresponding language within a given directory
matching the specified regexes.
@return [Hash] a hash containing language codes as keys and all found files paths as values (so values are of type Array)
|
[
"Initializes",
"a",
"file",
"search",
"object",
"."
] |
4c57bfc0dcb705b56bb267b220dcadd90d3a61b4
|
https://github.com/JamitLabs/TMSync/blob/4c57bfc0dcb705b56bb267b220dcadd90d3a61b4/lib/tmsync.rb#L29-L59
|
7,615 |
DomainTools/api-ruby
|
lib/domain_tools/request.rb
|
DomainTools.Request.build_url
|
def build_url
parts = []
uri = ""
parts << "/#{@version}" if @version
parts << "/#{@domain}" if @domain
parts << "/#{@service}" if @service
uri = parts.join("")
parts << "?"
parts << "format=#{@format}"
parts << "&#{authentication_params(uri)}"
parts << "#{format_parameters}" if @parameters
@url = parts.join("")
end
|
ruby
|
def build_url
parts = []
uri = ""
parts << "/#{@version}" if @version
parts << "/#{@domain}" if @domain
parts << "/#{@service}" if @service
uri = parts.join("")
parts << "?"
parts << "format=#{@format}"
parts << "&#{authentication_params(uri)}"
parts << "#{format_parameters}" if @parameters
@url = parts.join("")
end
|
[
"def",
"build_url",
"parts",
"=",
"[",
"]",
"uri",
"=",
"\"\"",
"parts",
"<<",
"\"/#{@version}\"",
"if",
"@version",
"parts",
"<<",
"\"/#{@domain}\"",
"if",
"@domain",
"parts",
"<<",
"\"/#{@service}\"",
"if",
"@service",
"uri",
"=",
"parts",
".",
"join",
"(",
"\"\"",
")",
"parts",
"<<",
"\"?\"",
"parts",
"<<",
"\"format=#{@format}\"",
"parts",
"<<",
"\"&#{authentication_params(uri)}\"",
"parts",
"<<",
"\"#{format_parameters}\"",
"if",
"@parameters",
"@url",
"=",
"parts",
".",
"join",
"(",
"\"\"",
")",
"end"
] |
build service url
|
[
"build",
"service",
"url"
] |
8348b691e386feea824b3ae7fff93a872e5763ec
|
https://github.com/DomainTools/api-ruby/blob/8348b691e386feea824b3ae7fff93a872e5763ec/lib/domain_tools/request.rb#L31-L43
|
7,616 |
DomainTools/api-ruby
|
lib/domain_tools/request.rb
|
DomainTools.Request.execute
|
def execute(refresh=false)
return @response if @response && !refresh
validate
build_url
@done = true
DomainTools.counter!
require 'net/http'
begin
Net::HTTP.start(@host) do |http|
req = Net::HTTP::Get.new(@url)
@http = http.request(req)
@success = validate_http_status
return finalize
end
rescue DomainTools::ServiceException => e
@error = DomainTools::Error.new(self,e)
raise e.class.new(e)
end
end
|
ruby
|
def execute(refresh=false)
return @response if @response && !refresh
validate
build_url
@done = true
DomainTools.counter!
require 'net/http'
begin
Net::HTTP.start(@host) do |http|
req = Net::HTTP::Get.new(@url)
@http = http.request(req)
@success = validate_http_status
return finalize
end
rescue DomainTools::ServiceException => e
@error = DomainTools::Error.new(self,e)
raise e.class.new(e)
end
end
|
[
"def",
"execute",
"(",
"refresh",
"=",
"false",
")",
"return",
"@response",
"if",
"@response",
"&&",
"!",
"refresh",
"validate",
"build_url",
"@done",
"=",
"true",
"DomainTools",
".",
"counter!",
"require",
"'net/http'",
"begin",
"Net",
"::",
"HTTP",
".",
"start",
"(",
"@host",
")",
"do",
"|",
"http",
"|",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"@url",
")",
"@http",
"=",
"http",
".",
"request",
"(",
"req",
")",
"@success",
"=",
"validate_http_status",
"return",
"finalize",
"end",
"rescue",
"DomainTools",
"::",
"ServiceException",
"=>",
"e",
"@error",
"=",
"DomainTools",
"::",
"Error",
".",
"new",
"(",
"self",
",",
"e",
")",
"raise",
"e",
".",
"class",
".",
"new",
"(",
"e",
")",
"end",
"end"
] |
Connect to the server and execute the request
|
[
"Connect",
"to",
"the",
"server",
"and",
"execute",
"the",
"request"
] |
8348b691e386feea824b3ae7fff93a872e5763ec
|
https://github.com/DomainTools/api-ruby/blob/8348b691e386feea824b3ae7fff93a872e5763ec/lib/domain_tools/request.rb#L78-L96
|
7,617 |
palon7/zaif-ruby
|
lib/zaif.rb
|
Zaif.API.trade
|
def trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy")
currency_pair = currency_code + "_" + counter_currency_code
params = {:currency_pair => currency_pair, :action => action, :price => price, :amount => amount}
params.store(:limit, limit) if limit
json = post_ssl(@zaif_trade_url, "trade", params)
return json
end
|
ruby
|
def trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy")
currency_pair = currency_code + "_" + counter_currency_code
params = {:currency_pair => currency_pair, :action => action, :price => price, :amount => amount}
params.store(:limit, limit) if limit
json = post_ssl(@zaif_trade_url, "trade", params)
return json
end
|
[
"def",
"trade",
"(",
"currency_code",
",",
"price",
",",
"amount",
",",
"action",
",",
"limit",
"=",
"nil",
",",
"counter_currency_code",
"=",
"\"jpy\"",
")",
"currency_pair",
"=",
"currency_code",
"+",
"\"_\"",
"+",
"counter_currency_code",
"params",
"=",
"{",
":currency_pair",
"=>",
"currency_pair",
",",
":action",
"=>",
"action",
",",
":price",
"=>",
"price",
",",
":amount",
"=>",
"amount",
"}",
"params",
".",
"store",
"(",
":limit",
",",
"limit",
")",
"if",
"limit",
"json",
"=",
"post_ssl",
"(",
"@zaif_trade_url",
",",
"\"trade\"",
",",
"params",
")",
"return",
"json",
"end"
] |
Issue trade.
Need api key.
|
[
"Issue",
"trade",
".",
"Need",
"api",
"key",
"."
] |
c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6
|
https://github.com/palon7/zaif-ruby/blob/c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6/lib/zaif.rb#L105-L111
|
7,618 |
palon7/zaif-ruby
|
lib/zaif.rb
|
Zaif.API.bid
|
def bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
return trade(currency_code, price, amount, "bid", limit, counter_currency_code)
end
|
ruby
|
def bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
return trade(currency_code, price, amount, "bid", limit, counter_currency_code)
end
|
[
"def",
"bid",
"(",
"currency_code",
",",
"price",
",",
"amount",
",",
"limit",
"=",
"nil",
",",
"counter_currency_code",
"=",
"\"jpy\"",
")",
"return",
"trade",
"(",
"currency_code",
",",
"price",
",",
"amount",
",",
"\"bid\"",
",",
"limit",
",",
"counter_currency_code",
")",
"end"
] |
Issue bid order.
Need api key.
|
[
"Issue",
"bid",
"order",
".",
"Need",
"api",
"key",
"."
] |
c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6
|
https://github.com/palon7/zaif-ruby/blob/c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6/lib/zaif.rb#L115-L117
|
7,619 |
palon7/zaif-ruby
|
lib/zaif.rb
|
Zaif.API.ask
|
def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
return trade(currency_code, price, amount, "ask", limit, counter_currency_code)
end
|
ruby
|
def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
return trade(currency_code, price, amount, "ask", limit, counter_currency_code)
end
|
[
"def",
"ask",
"(",
"currency_code",
",",
"price",
",",
"amount",
",",
"limit",
"=",
"nil",
",",
"counter_currency_code",
"=",
"\"jpy\"",
")",
"return",
"trade",
"(",
"currency_code",
",",
"price",
",",
"amount",
",",
"\"ask\"",
",",
"limit",
",",
"counter_currency_code",
")",
"end"
] |
Issue ask order.
Need api key.
|
[
"Issue",
"ask",
"order",
".",
"Need",
"api",
"key",
"."
] |
c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6
|
https://github.com/palon7/zaif-ruby/blob/c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6/lib/zaif.rb#L121-L123
|
7,620 |
palon7/zaif-ruby
|
lib/zaif.rb
|
Zaif.API.withdraw
|
def withdraw(currency_code, address, amount, option = {})
option["currency"] = currency_code
option["address"] = address
option["amount"] = amount
json = post_ssl(@zaif_trade_url, "withdraw", option)
return json
end
|
ruby
|
def withdraw(currency_code, address, amount, option = {})
option["currency"] = currency_code
option["address"] = address
option["amount"] = amount
json = post_ssl(@zaif_trade_url, "withdraw", option)
return json
end
|
[
"def",
"withdraw",
"(",
"currency_code",
",",
"address",
",",
"amount",
",",
"option",
"=",
"{",
"}",
")",
"option",
"[",
"\"currency\"",
"]",
"=",
"currency_code",
"option",
"[",
"\"address\"",
"]",
"=",
"address",
"option",
"[",
"\"amount\"",
"]",
"=",
"amount",
"json",
"=",
"post_ssl",
"(",
"@zaif_trade_url",
",",
"\"withdraw\"",
",",
"option",
")",
"return",
"json",
"end"
] |
Withdraw funds.
Need api key.
|
[
"Withdraw",
"funds",
".",
"Need",
"api",
"key",
"."
] |
c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6
|
https://github.com/palon7/zaif-ruby/blob/c0c5d2e4ba86262d48d8ecccea51f0cb5e1df6d6/lib/zaif.rb#L134-L140
|
7,621 |
droptheplot/adminable
|
lib/adminable/field_collector.rb
|
Adminable.FieldCollector.associations
|
def associations
@associations ||= [].tap do |fields|
@model.reflect_on_all_associations.each do |association|
fields << resolve(association.macro, association.name)
end
end
end
|
ruby
|
def associations
@associations ||= [].tap do |fields|
@model.reflect_on_all_associations.each do |association|
fields << resolve(association.macro, association.name)
end
end
end
|
[
"def",
"associations",
"@associations",
"||=",
"[",
"]",
".",
"tap",
"do",
"|",
"fields",
"|",
"@model",
".",
"reflect_on_all_associations",
".",
"each",
"do",
"|",
"association",
"|",
"fields",
"<<",
"resolve",
"(",
"association",
".",
"macro",
",",
"association",
".",
"name",
")",
"end",
"end",
"end"
] |
Collects fields from model associations
@return [Array]
|
[
"Collects",
"fields",
"from",
"model",
"associations"
] |
ec5808e161a9d27f0150186e79c750242bdf7c6b
|
https://github.com/droptheplot/adminable/blob/ec5808e161a9d27f0150186e79c750242bdf7c6b/lib/adminable/field_collector.rb#L30-L36
|
7,622 |
mssola/cconfig
|
lib/cconfig/hash_utils.rb
|
CConfig.HashUtils.strict_merge_with_env
|
def strict_merge_with_env(default:, local:, prefix:)
hsh = {}
default.each do |k, v|
# The corresponding environment variable. If it's not the final value,
# then this just contains the partial prefix of the env. variable.
env = "#{prefix}_#{k}"
# If the current value is a hash, then go deeper to perform a deep
# merge, otherwise we merge the final value by respecting the order as
# specified in the documentation.
if v.is_a?(Hash)
l = local[k] || {}
hsh[k] = strict_merge_with_env(default: default[k], local: l, prefix: env)
else
hsh[k] = first_non_nil(get_env(env), local[k], v)
end
end
hsh
end
|
ruby
|
def strict_merge_with_env(default:, local:, prefix:)
hsh = {}
default.each do |k, v|
# The corresponding environment variable. If it's not the final value,
# then this just contains the partial prefix of the env. variable.
env = "#{prefix}_#{k}"
# If the current value is a hash, then go deeper to perform a deep
# merge, otherwise we merge the final value by respecting the order as
# specified in the documentation.
if v.is_a?(Hash)
l = local[k] || {}
hsh[k] = strict_merge_with_env(default: default[k], local: l, prefix: env)
else
hsh[k] = first_non_nil(get_env(env), local[k], v)
end
end
hsh
end
|
[
"def",
"strict_merge_with_env",
"(",
"default",
":",
",",
"local",
":",
",",
"prefix",
":",
")",
"hsh",
"=",
"{",
"}",
"default",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"# The corresponding environment variable. If it's not the final value,",
"# then this just contains the partial prefix of the env. variable.",
"env",
"=",
"\"#{prefix}_#{k}\"",
"# If the current value is a hash, then go deeper to perform a deep",
"# merge, otherwise we merge the final value by respecting the order as",
"# specified in the documentation.",
"if",
"v",
".",
"is_a?",
"(",
"Hash",
")",
"l",
"=",
"local",
"[",
"k",
"]",
"||",
"{",
"}",
"hsh",
"[",
"k",
"]",
"=",
"strict_merge_with_env",
"(",
"default",
":",
"default",
"[",
"k",
"]",
",",
"local",
":",
"l",
",",
"prefix",
":",
"env",
")",
"else",
"hsh",
"[",
"k",
"]",
"=",
"first_non_nil",
"(",
"get_env",
"(",
"env",
")",
",",
"local",
"[",
"k",
"]",
",",
"v",
")",
"end",
"end",
"hsh",
"end"
] |
Applies a deep merge while respecting the values from environment
variables. A deep merge consists of a merge of all the nested elements of
the two given hashes `config` and `local`. The `config` hash is supposed
to contain all the accepted keys, and the `local` hash is a subset of it.
Moreover, let's say that we have the following hash: { "ldap" => {
"enabled" => true } }. An environment variable that can modify the value
of the previous hash has to be named `#{prefix}_LDAP_ENABLED`. The `prefix`
argument specifies how all the environment variables have to start.
Returns the merged hash, where the precedence of the merge is as follows:
1. The value of the related environment variable if set.
2. The value from the `local` hash.
3. The value from the `config` hash.
|
[
"Applies",
"a",
"deep",
"merge",
"while",
"respecting",
"the",
"values",
"from",
"environment",
"variables",
".",
"A",
"deep",
"merge",
"consists",
"of",
"a",
"merge",
"of",
"all",
"the",
"nested",
"elements",
"of",
"the",
"two",
"given",
"hashes",
"config",
"and",
"local",
".",
"The",
"config",
"hash",
"is",
"supposed",
"to",
"contain",
"all",
"the",
"accepted",
"keys",
"and",
"the",
"local",
"hash",
"is",
"a",
"subset",
"of",
"it",
"."
] |
793fb743cdcc064a96fb911bc17483fa0d343056
|
https://github.com/mssola/cconfig/blob/793fb743cdcc064a96fb911bc17483fa0d343056/lib/cconfig/hash_utils.rb#L83-L102
|
7,623 |
mssola/cconfig
|
lib/cconfig/hash_utils.rb
|
CConfig.HashUtils.get_env
|
def get_env(key)
env = ENV[key.upcase]
return nil if env.nil?
# Try to convert it into a boolean value.
return true if env.casecmp("true").zero?
return false if env.casecmp("false").zero?
# Try to convert it into an integer. Otherwise just keep the string.
begin
Integer(env)
rescue ArgumentError
env
end
end
|
ruby
|
def get_env(key)
env = ENV[key.upcase]
return nil if env.nil?
# Try to convert it into a boolean value.
return true if env.casecmp("true").zero?
return false if env.casecmp("false").zero?
# Try to convert it into an integer. Otherwise just keep the string.
begin
Integer(env)
rescue ArgumentError
env
end
end
|
[
"def",
"get_env",
"(",
"key",
")",
"env",
"=",
"ENV",
"[",
"key",
".",
"upcase",
"]",
"return",
"nil",
"if",
"env",
".",
"nil?",
"# Try to convert it into a boolean value.",
"return",
"true",
"if",
"env",
".",
"casecmp",
"(",
"\"true\"",
")",
".",
"zero?",
"return",
"false",
"if",
"env",
".",
"casecmp",
"(",
"\"false\"",
")",
".",
"zero?",
"# Try to convert it into an integer. Otherwise just keep the string.",
"begin",
"Integer",
"(",
"env",
")",
"rescue",
"ArgumentError",
"env",
"end",
"end"
] |
Get the typed value of the specified environment variable. If it doesn't
exist, it will return nil. Otherwise, it will try to cast the fetched
value into the proper type and return it.
|
[
"Get",
"the",
"typed",
"value",
"of",
"the",
"specified",
"environment",
"variable",
".",
"If",
"it",
"doesn",
"t",
"exist",
"it",
"will",
"return",
"nil",
".",
"Otherwise",
"it",
"will",
"try",
"to",
"cast",
"the",
"fetched",
"value",
"into",
"the",
"proper",
"type",
"and",
"return",
"it",
"."
] |
793fb743cdcc064a96fb911bc17483fa0d343056
|
https://github.com/mssola/cconfig/blob/793fb743cdcc064a96fb911bc17483fa0d343056/lib/cconfig/hash_utils.rb#L121-L135
|
7,624 |
sgillesp/taxonomite
|
lib/taxonomite/node.rb
|
Taxonomite.Node.evaluate
|
def evaluate(m)
return self.owner.instance_eval(m) if self.owner != nil && self.owner.respond_to?(m)
return self.instance_eval(m) if self.respond_to?(m)
nil
end
|
ruby
|
def evaluate(m)
return self.owner.instance_eval(m) if self.owner != nil && self.owner.respond_to?(m)
return self.instance_eval(m) if self.respond_to?(m)
nil
end
|
[
"def",
"evaluate",
"(",
"m",
")",
"return",
"self",
".",
"owner",
".",
"instance_eval",
"(",
"m",
")",
"if",
"self",
".",
"owner",
"!=",
"nil",
"&&",
"self",
".",
"owner",
".",
"respond_to?",
"(",
"m",
")",
"return",
"self",
".",
"instance_eval",
"(",
"m",
")",
"if",
"self",
".",
"respond_to?",
"(",
"m",
")",
"nil",
"end"
] |
this is the associated object
evaluate a method on the owner of this node (if present). If an owner is
not present, then the method is evaluated on this object. In either case
a check is made to ensure that the object will respond_to? the method call.
If the owner exists but does not respond to the method, then the method is
tried on this node object in similar fashion.
!!! SHOULD THIS JUST OVERRIDE instance_eval ??
@param [Method] m method to call
@return [] the result of the method call, or nil if unable to evaluate
|
[
"this",
"is",
"the",
"associated",
"object"
] |
731b42d0dfa1f52b39d050026f49b2d205407ff8
|
https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/node.rb#L45-L49
|
7,625 |
sgillesp/taxonomite
|
lib/taxonomite/node.rb
|
Taxonomite.Node.validate_parent
|
def validate_parent(parent)
raise InvalidParent.create(parent, self) unless (!parent.nil? && is_valid_parent?(parent))
parent.validate_child(self)
end
|
ruby
|
def validate_parent(parent)
raise InvalidParent.create(parent, self) unless (!parent.nil? && is_valid_parent?(parent))
parent.validate_child(self)
end
|
[
"def",
"validate_parent",
"(",
"parent",
")",
"raise",
"InvalidParent",
".",
"create",
"(",
"parent",
",",
"self",
")",
"unless",
"(",
"!",
"parent",
".",
"nil?",
"&&",
"is_valid_parent?",
"(",
"parent",
")",
")",
"parent",
".",
"validate_child",
"(",
"self",
")",
"end"
] |
determine whether the parent is valid for this object. See description of
validate_child for more detail. This method calls validate_child to perform
the actual validation.
@param [Taxonomite::Node] parent the parent to validate
@return [Boolean] whether validation was successful
|
[
"determine",
"whether",
"the",
"parent",
"is",
"valid",
"for",
"this",
"object",
".",
"See",
"description",
"of",
"validate_child",
"for",
"more",
"detail",
".",
"This",
"method",
"calls",
"validate_child",
"to",
"perform",
"the",
"actual",
"validation",
"."
] |
731b42d0dfa1f52b39d050026f49b2d205407ff8
|
https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/node.rb#L130-L133
|
7,626 |
lateral/recommender-gem
|
lib/lateral_recommender.rb
|
LateralRecommender.API.match_documents
|
def match_documents(mind_results, database_results, key = 'id')
return [] unless database_results
mind_results.each_with_object([]) do |result, arr|
next unless (doc = database_results.find { |s| s[key].to_s == result['document_id'].to_s })
arr << doc.attributes.merge(result)
end
end
|
ruby
|
def match_documents(mind_results, database_results, key = 'id')
return [] unless database_results
mind_results.each_with_object([]) do |result, arr|
next unless (doc = database_results.find { |s| s[key].to_s == result['document_id'].to_s })
arr << doc.attributes.merge(result)
end
end
|
[
"def",
"match_documents",
"(",
"mind_results",
",",
"database_results",
",",
"key",
"=",
"'id'",
")",
"return",
"[",
"]",
"unless",
"database_results",
"mind_results",
".",
"each_with_object",
"(",
"[",
"]",
")",
"do",
"|",
"result",
",",
"arr",
"|",
"next",
"unless",
"(",
"doc",
"=",
"database_results",
".",
"find",
"{",
"|",
"s",
"|",
"s",
"[",
"key",
"]",
".",
"to_s",
"==",
"result",
"[",
"'document_id'",
"]",
".",
"to_s",
"}",
")",
"arr",
"<<",
"doc",
".",
"attributes",
".",
"merge",
"(",
"result",
")",
"end",
"end"
] |
Takes two result arrays and using the specified key merges the two
@param [Array] mind_results The results from the API
@param [Array] database_results The results from the database
@param [String] key The key of the database_results Hash that should match the mind_results id key
@return [Hash] An array of merged Hashes
|
[
"Takes",
"two",
"result",
"arrays",
"and",
"using",
"the",
"specified",
"key",
"merges",
"the",
"two"
] |
ec9cdeef1d83e489abd9c8e009eacc3062e1273e
|
https://github.com/lateral/recommender-gem/blob/ec9cdeef1d83e489abd9c8e009eacc3062e1273e/lib/lateral_recommender.rb#L58-L64
|
7,627 |
sutajio/auth
|
lib/auth/helpers.rb
|
Auth.Helpers.generate_secret
|
def generate_secret
if defined?(SecureRandom)
SecureRandom.urlsafe_base64(32)
else
Base64.encode64(
Digest::SHA256.digest("#{Time.now}-#{Time.now.usec}-#{$$}-#{rand}")
).gsub('/','-').gsub('+','_').gsub('=','').strip
end
end
|
ruby
|
def generate_secret
if defined?(SecureRandom)
SecureRandom.urlsafe_base64(32)
else
Base64.encode64(
Digest::SHA256.digest("#{Time.now}-#{Time.now.usec}-#{$$}-#{rand}")
).gsub('/','-').gsub('+','_').gsub('=','').strip
end
end
|
[
"def",
"generate_secret",
"if",
"defined?",
"(",
"SecureRandom",
")",
"SecureRandom",
".",
"urlsafe_base64",
"(",
"32",
")",
"else",
"Base64",
".",
"encode64",
"(",
"Digest",
"::",
"SHA256",
".",
"digest",
"(",
"\"#{Time.now}-#{Time.now.usec}-#{$$}-#{rand}\"",
")",
")",
".",
"gsub",
"(",
"'/'",
",",
"'-'",
")",
".",
"gsub",
"(",
"'+'",
",",
"'_'",
")",
".",
"gsub",
"(",
"'='",
",",
"''",
")",
".",
"strip",
"end",
"end"
] |
Generate a unique cryptographically secure secret
|
[
"Generate",
"a",
"unique",
"cryptographically",
"secure",
"secret"
] |
b3d1c289a22ba90fa66adb513de9eead70df6e60
|
https://github.com/sutajio/auth/blob/b3d1c289a22ba90fa66adb513de9eead70df6e60/lib/auth/helpers.rb#L13-L21
|
7,628 |
sutajio/auth
|
lib/auth/helpers.rb
|
Auth.Helpers.encrypt_password
|
def encrypt_password(password, salt, hash)
case hash.to_s
when 'sha256'
Digest::SHA256.hexdigest("#{password}-#{salt}")
else
raise 'Unsupported hash algorithm'
end
end
|
ruby
|
def encrypt_password(password, salt, hash)
case hash.to_s
when 'sha256'
Digest::SHA256.hexdigest("#{password}-#{salt}")
else
raise 'Unsupported hash algorithm'
end
end
|
[
"def",
"encrypt_password",
"(",
"password",
",",
"salt",
",",
"hash",
")",
"case",
"hash",
".",
"to_s",
"when",
"'sha256'",
"Digest",
"::",
"SHA256",
".",
"hexdigest",
"(",
"\"#{password}-#{salt}\"",
")",
"else",
"raise",
"'Unsupported hash algorithm'",
"end",
"end"
] |
Obfuscate a password using a salt and a cryptographic hash function
|
[
"Obfuscate",
"a",
"password",
"using",
"a",
"salt",
"and",
"a",
"cryptographic",
"hash",
"function"
] |
b3d1c289a22ba90fa66adb513de9eead70df6e60
|
https://github.com/sutajio/auth/blob/b3d1c289a22ba90fa66adb513de9eead70df6e60/lib/auth/helpers.rb#L24-L31
|
7,629 |
sutajio/auth
|
lib/auth/helpers.rb
|
Auth.Helpers.decode_scopes
|
def decode_scopes(scopes)
if scopes.is_a?(Array)
scopes.map {|s| s.to_s.strip }
else
scopes.to_s.split(' ').map {|s| s.strip }
end
end
|
ruby
|
def decode_scopes(scopes)
if scopes.is_a?(Array)
scopes.map {|s| s.to_s.strip }
else
scopes.to_s.split(' ').map {|s| s.strip }
end
end
|
[
"def",
"decode_scopes",
"(",
"scopes",
")",
"if",
"scopes",
".",
"is_a?",
"(",
"Array",
")",
"scopes",
".",
"map",
"{",
"|",
"s",
"|",
"s",
".",
"to_s",
".",
"strip",
"}",
"else",
"scopes",
".",
"to_s",
".",
"split",
"(",
"' '",
")",
".",
"map",
"{",
"|",
"s",
"|",
"s",
".",
"strip",
"}",
"end",
"end"
] |
Decode a space delimited string of security scopes and return an array
|
[
"Decode",
"a",
"space",
"delimited",
"string",
"of",
"security",
"scopes",
"and",
"return",
"an",
"array"
] |
b3d1c289a22ba90fa66adb513de9eead70df6e60
|
https://github.com/sutajio/auth/blob/b3d1c289a22ba90fa66adb513de9eead70df6e60/lib/auth/helpers.rb#L49-L55
|
7,630 |
seevibes/twitter_ads
|
lib/twitter_ads/rest_resource.rb
|
TwitterADS.RestResource.check_method
|
def check_method(tab_ops, prefix, method_sym, do_call, *arguments, &block)
method_sym = method_sym.id2name
verb = :get
[:post, :get, :delete, :put].each do |averb|
if method_sym.start_with? averb.id2name
verb = averb
method_sym[averb.id2name + '_'] = ''
break
end
end
if tab_ops[verb].include? method_sym.to_sym
if do_call
params = arguments.first
method = prefix + method_sym
method += "/#{params.shift}" if params.first && params.first.class != Hash
return do_request verb, method, params.shift
else
return nil
end
end
nil
end
|
ruby
|
def check_method(tab_ops, prefix, method_sym, do_call, *arguments, &block)
method_sym = method_sym.id2name
verb = :get
[:post, :get, :delete, :put].each do |averb|
if method_sym.start_with? averb.id2name
verb = averb
method_sym[averb.id2name + '_'] = ''
break
end
end
if tab_ops[verb].include? method_sym.to_sym
if do_call
params = arguments.first
method = prefix + method_sym
method += "/#{params.shift}" if params.first && params.first.class != Hash
return do_request verb, method, params.shift
else
return nil
end
end
nil
end
|
[
"def",
"check_method",
"(",
"tab_ops",
",",
"prefix",
",",
"method_sym",
",",
"do_call",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"method_sym",
"=",
"method_sym",
".",
"id2name",
"verb",
"=",
":get",
"[",
":post",
",",
":get",
",",
":delete",
",",
":put",
"]",
".",
"each",
"do",
"|",
"averb",
"|",
"if",
"method_sym",
".",
"start_with?",
"averb",
".",
"id2name",
"verb",
"=",
"averb",
"method_sym",
"[",
"averb",
".",
"id2name",
"+",
"'_'",
"]",
"=",
"''",
"break",
"end",
"end",
"if",
"tab_ops",
"[",
"verb",
"]",
".",
"include?",
"method_sym",
".",
"to_sym",
"if",
"do_call",
"params",
"=",
"arguments",
".",
"first",
"method",
"=",
"prefix",
"+",
"method_sym",
"method",
"+=",
"\"/#{params.shift}\"",
"if",
"params",
".",
"first",
"&&",
"params",
".",
"first",
".",
"class",
"!=",
"Hash",
"return",
"do_request",
"verb",
",",
"method",
",",
"params",
".",
"shift",
"else",
"return",
"nil",
"end",
"end",
"nil",
"end"
] |
Dynamic check of methods
tab_ops contain the list of allowed method and verbs
prefix the prefix to add to the method
|
[
"Dynamic",
"check",
"of",
"methods",
"tab_ops",
"contain",
"the",
"list",
"of",
"allowed",
"method",
"and",
"verbs",
"prefix",
"the",
"prefix",
"to",
"add",
"to",
"the",
"method"
] |
f7fbc16d3f31ef2ebb8baf49c7033f119c575594
|
https://github.com/seevibes/twitter_ads/blob/f7fbc16d3f31ef2ebb8baf49c7033f119c575594/lib/twitter_ads/rest_resource.rb#L64-L85
|
7,631 |
patchapps/rabbit-hutch
|
lib/consumer.rb
|
RabbitHutch.Consumer.handle_message
|
def handle_message(metadata, payload)
# loop through appenders and fire each as required
@consumers.each do |consumer|
action = metadata.routing_key.split('.', 2).first
if(action == "publish")
exchange = metadata.attributes[:headers]["exchange_name"]
queue = metadata.routing_key.split('.', 2).last
item = {:date => Time.now,
:exchange => exchange,
:queue => queue,
:routing_keys => metadata.attributes[:headers]["routing_keys"].inspect,
:attributes => metadata.attributes.inspect,
:payload => payload.inspect
}
consumer.log_event(item)
end
end
end
|
ruby
|
def handle_message(metadata, payload)
# loop through appenders and fire each as required
@consumers.each do |consumer|
action = metadata.routing_key.split('.', 2).first
if(action == "publish")
exchange = metadata.attributes[:headers]["exchange_name"]
queue = metadata.routing_key.split('.', 2).last
item = {:date => Time.now,
:exchange => exchange,
:queue => queue,
:routing_keys => metadata.attributes[:headers]["routing_keys"].inspect,
:attributes => metadata.attributes.inspect,
:payload => payload.inspect
}
consumer.log_event(item)
end
end
end
|
[
"def",
"handle_message",
"(",
"metadata",
",",
"payload",
")",
"# loop through appenders and fire each as required",
"@consumers",
".",
"each",
"do",
"|",
"consumer",
"|",
"action",
"=",
"metadata",
".",
"routing_key",
".",
"split",
"(",
"'.'",
",",
"2",
")",
".",
"first",
"if",
"(",
"action",
"==",
"\"publish\"",
")",
"exchange",
"=",
"metadata",
".",
"attributes",
"[",
":headers",
"]",
"[",
"\"exchange_name\"",
"]",
"queue",
"=",
"metadata",
".",
"routing_key",
".",
"split",
"(",
"'.'",
",",
"2",
")",
".",
"last",
"item",
"=",
"{",
":date",
"=>",
"Time",
".",
"now",
",",
":exchange",
"=>",
"exchange",
",",
":queue",
"=>",
"queue",
",",
":routing_keys",
"=>",
"metadata",
".",
"attributes",
"[",
":headers",
"]",
"[",
"\"routing_keys\"",
"]",
".",
"inspect",
",",
":attributes",
"=>",
"metadata",
".",
"attributes",
".",
"inspect",
",",
":payload",
"=>",
"payload",
".",
"inspect",
"}",
"consumer",
".",
"log_event",
"(",
"item",
")",
"end",
"end",
"end"
] |
Raised on receipt of a message from RabbitMq and uses the appropriate appender
|
[
"Raised",
"on",
"receipt",
"of",
"a",
"message",
"from",
"RabbitMq",
"and",
"uses",
"the",
"appropriate",
"appender"
] |
42337b0ddda60b749fc2fe088f4e8dba674d198d
|
https://github.com/patchapps/rabbit-hutch/blob/42337b0ddda60b749fc2fe088f4e8dba674d198d/lib/consumer.rb#L13-L30
|
7,632 |
dlangevin/gxapi_rails
|
lib/gxapi/google_analytics.rb
|
Gxapi.GoogleAnalytics.get_experiments
|
def get_experiments
@experiments ||= begin
# fetch our data from the cache
data = Gxapi.with_error_handling do
# handle caching
self.list_experiments_from_cache
end
# turn into Gxapi::Ostructs
(data || []).collect{|data| Ostruct.new(data)}
end
end
|
ruby
|
def get_experiments
@experiments ||= begin
# fetch our data from the cache
data = Gxapi.with_error_handling do
# handle caching
self.list_experiments_from_cache
end
# turn into Gxapi::Ostructs
(data || []).collect{|data| Ostruct.new(data)}
end
end
|
[
"def",
"get_experiments",
"@experiments",
"||=",
"begin",
"# fetch our data from the cache",
"data",
"=",
"Gxapi",
".",
"with_error_handling",
"do",
"# handle caching",
"self",
".",
"list_experiments_from_cache",
"end",
"# turn into Gxapi::Ostructs",
"(",
"data",
"||",
"[",
"]",
")",
".",
"collect",
"{",
"|",
"data",
"|",
"Ostruct",
".",
"new",
"(",
"data",
")",
"}",
"end",
"end"
] |
return a list of all experiments
@return [Array<Gxapi::Ostruct>]
|
[
"return",
"a",
"list",
"of",
"all",
"experiments"
] |
21361227f0c70118b38f7fa372a18c0ae7aab810
|
https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/google_analytics.rb#L23-L33
|
7,633 |
dlangevin/gxapi_rails
|
lib/gxapi/google_analytics.rb
|
Gxapi.GoogleAnalytics.get_variant
|
def get_variant(identifier)
# pull in an experiment
experiment = self.get_experiment(identifier)
if self.run_experiment?(experiment)
# select variant for the experiment
variant = self.select_variant(experiment)
# return if it it's present
return variant if variant.present?
end
# return blank value if we don't have an experiment or don't get
# a valid value
return Ostruct.new(
name: "default",
index: -1,
experiment_id: nil
)
end
|
ruby
|
def get_variant(identifier)
# pull in an experiment
experiment = self.get_experiment(identifier)
if self.run_experiment?(experiment)
# select variant for the experiment
variant = self.select_variant(experiment)
# return if it it's present
return variant if variant.present?
end
# return blank value if we don't have an experiment or don't get
# a valid value
return Ostruct.new(
name: "default",
index: -1,
experiment_id: nil
)
end
|
[
"def",
"get_variant",
"(",
"identifier",
")",
"# pull in an experiment",
"experiment",
"=",
"self",
".",
"get_experiment",
"(",
"identifier",
")",
"if",
"self",
".",
"run_experiment?",
"(",
"experiment",
")",
"# select variant for the experiment",
"variant",
"=",
"self",
".",
"select_variant",
"(",
"experiment",
")",
"# return if it it's present",
"return",
"variant",
"if",
"variant",
".",
"present?",
"end",
"# return blank value if we don't have an experiment or don't get",
"# a valid value",
"return",
"Ostruct",
".",
"new",
"(",
"name",
":",
"\"default\"",
",",
"index",
":",
"-",
"1",
",",
"experiment_id",
":",
"nil",
")",
"end"
] |
get a variant for an experiment
@param identifier [String, Hash] Either the experiment name
as a String or a hash of what to look for
@return [Gxapi::Ostruct]
|
[
"get",
"a",
"variant",
"for",
"an",
"experiment"
] |
21361227f0c70118b38f7fa372a18c0ae7aab810
|
https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/google_analytics.rb#L42-L59
|
7,634 |
dlangevin/gxapi_rails
|
lib/gxapi/google_analytics.rb
|
Gxapi.GoogleAnalytics.list_experiments
|
def list_experiments
response = self.client.execute({
api_method: self.analytics_experiments.list,
parameters: {
accountId: self.config.account_id.to_s,
profileId: self.config.profile_id.to_s,
webPropertyId: self.config.web_property_id
}
})
response.data.items.collect(&:to_hash)
end
|
ruby
|
def list_experiments
response = self.client.execute({
api_method: self.analytics_experiments.list,
parameters: {
accountId: self.config.account_id.to_s,
profileId: self.config.profile_id.to_s,
webPropertyId: self.config.web_property_id
}
})
response.data.items.collect(&:to_hash)
end
|
[
"def",
"list_experiments",
"response",
"=",
"self",
".",
"client",
".",
"execute",
"(",
"{",
"api_method",
":",
"self",
".",
"analytics_experiments",
".",
"list",
",",
"parameters",
":",
"{",
"accountId",
":",
"self",
".",
"config",
".",
"account_id",
".",
"to_s",
",",
"profileId",
":",
"self",
".",
"config",
".",
"profile_id",
".",
"to_s",
",",
"webPropertyId",
":",
"self",
".",
"config",
".",
"web_property_id",
"}",
"}",
")",
"response",
".",
"data",
".",
"items",
".",
"collect",
"(",
":to_hash",
")",
"end"
] |
List all experiments for our account
@return [Array<Gxapi::Ostruct>] Collection of Experiment data
retrieved from Google's API
|
[
"List",
"all",
"experiments",
"for",
"our",
"account"
] |
21361227f0c70118b38f7fa372a18c0ae7aab810
|
https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/google_analytics.rb#L82-L92
|
7,635 |
dlangevin/gxapi_rails
|
lib/gxapi/google_analytics.rb
|
Gxapi.GoogleAnalytics.client
|
def client
@client ||= begin
client = Google::APIClient.new
client.authorization = Signet::OAuth2::Client.new(
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
audience: 'https://accounts.google.com/o/oauth2/token',
scope: 'https://www.googleapis.com/auth/analytics.readonly',
issuer: Gxapi.config.google.email,
signing_key: self.get_key
)
client.authorization.fetch_access_token!
client
end
end
|
ruby
|
def client
@client ||= begin
client = Google::APIClient.new
client.authorization = Signet::OAuth2::Client.new(
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
audience: 'https://accounts.google.com/o/oauth2/token',
scope: 'https://www.googleapis.com/auth/analytics.readonly',
issuer: Gxapi.config.google.email,
signing_key: self.get_key
)
client.authorization.fetch_access_token!
client
end
end
|
[
"def",
"client",
"@client",
"||=",
"begin",
"client",
"=",
"Google",
"::",
"APIClient",
".",
"new",
"client",
".",
"authorization",
"=",
"Signet",
"::",
"OAuth2",
"::",
"Client",
".",
"new",
"(",
"token_credential_uri",
":",
"'https://accounts.google.com/o/oauth2/token'",
",",
"audience",
":",
"'https://accounts.google.com/o/oauth2/token'",
",",
"scope",
":",
"'https://www.googleapis.com/auth/analytics.readonly'",
",",
"issuer",
":",
"Gxapi",
".",
"config",
".",
"google",
".",
"email",
",",
"signing_key",
":",
"self",
".",
"get_key",
")",
"client",
".",
"authorization",
".",
"fetch_access_token!",
"client",
"end",
"end"
] |
google api client
@return [Google::APIClient]
|
[
"google",
"api",
"client"
] |
21361227f0c70118b38f7fa372a18c0ae7aab810
|
https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/google_analytics.rb#L117-L130
|
7,636 |
dlangevin/gxapi_rails
|
lib/gxapi/google_analytics.rb
|
Gxapi.GoogleAnalytics.select_variant
|
def select_variant(experiment)
# starts off at 0
accum = 0.0
sample = Kernel.rand
# go through our experiments and return the variation that matches
# our random value
experiment.variations.each_with_index do |variation, i|
# we want to record the index in the array for this variation
variation.index = i
variation.experiment_id = experiment.id
# add the variation's weight to accum
accum += variation.weight
# return the variation if accum is more than our random value
if sample <= accum
return variation
end
end
# default to nil
return nil
end
|
ruby
|
def select_variant(experiment)
# starts off at 0
accum = 0.0
sample = Kernel.rand
# go through our experiments and return the variation that matches
# our random value
experiment.variations.each_with_index do |variation, i|
# we want to record the index in the array for this variation
variation.index = i
variation.experiment_id = experiment.id
# add the variation's weight to accum
accum += variation.weight
# return the variation if accum is more than our random value
if sample <= accum
return variation
end
end
# default to nil
return nil
end
|
[
"def",
"select_variant",
"(",
"experiment",
")",
"# starts off at 0",
"accum",
"=",
"0.0",
"sample",
"=",
"Kernel",
".",
"rand",
"# go through our experiments and return the variation that matches",
"# our random value",
"experiment",
".",
"variations",
".",
"each_with_index",
"do",
"|",
"variation",
",",
"i",
"|",
"# we want to record the index in the array for this variation",
"variation",
".",
"index",
"=",
"i",
"variation",
".",
"experiment_id",
"=",
"experiment",
".",
"id",
"# add the variation's weight to accum",
"accum",
"+=",
"variation",
".",
"weight",
"# return the variation if accum is more than our random value",
"if",
"sample",
"<=",
"accum",
"return",
"variation",
"end",
"end",
"# default to nil",
"return",
"nil",
"end"
] |
Select a variant from a given experiment
@param experiment [Ostruct] The experiment to choose for
@return [Ostruct, nil] The selected variant or nil if none is
selected
|
[
"Select",
"a",
"variant",
"from",
"a",
"given",
"experiment"
] |
21361227f0c70118b38f7fa372a18c0ae7aab810
|
https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/google_analytics.rb#L185-L208
|
7,637 |
emad-elsaid/command_tree
|
lib/command_tree/tree.rb
|
CommandTree.Tree.merge
|
def merge(subtree, prefix, name, options = {})
register(prefix, name, options)
subtree.calls.each do |key, command|
next unless command
calls["#{prefix}#{key}"] = command
end
end
|
ruby
|
def merge(subtree, prefix, name, options = {})
register(prefix, name, options)
subtree.calls.each do |key, command|
next unless command
calls["#{prefix}#{key}"] = command
end
end
|
[
"def",
"merge",
"(",
"subtree",
",",
"prefix",
",",
"name",
",",
"options",
"=",
"{",
"}",
")",
"register",
"(",
"prefix",
",",
"name",
",",
"options",
")",
"subtree",
".",
"calls",
".",
"each",
"do",
"|",
"key",
",",
"command",
"|",
"next",
"unless",
"command",
"calls",
"[",
"\"#{prefix}#{key}\"",
"]",
"=",
"command",
"end",
"end"
] |
merge a subtree with a prefix and a name
|
[
"merge",
"a",
"subtree",
"with",
"a",
"prefix",
"and",
"a",
"name"
] |
d30e0f00c6ff8f3c344d7e63f662a71d8abe52c0
|
https://github.com/emad-elsaid/command_tree/blob/d30e0f00c6ff8f3c344d7e63f662a71d8abe52c0/lib/command_tree/tree.rb#L47-L54
|
7,638 |
postmodern/pullr
|
lib/pullr/local_repository.rb
|
Pullr.LocalRepository.scm_dir
|
def scm_dir
dir, scm = SCM::DIRS.find { |dir,scm| scm == @scm }
return dir
end
|
ruby
|
def scm_dir
dir, scm = SCM::DIRS.find { |dir,scm| scm == @scm }
return dir
end
|
[
"def",
"scm_dir",
"dir",
",",
"scm",
"=",
"SCM",
"::",
"DIRS",
".",
"find",
"{",
"|",
"dir",
",",
"scm",
"|",
"scm",
"==",
"@scm",
"}",
"return",
"dir",
"end"
] |
The control directory used by the SCM.
@return [String]
The name of the control directory.
|
[
"The",
"control",
"directory",
"used",
"by",
"the",
"SCM",
"."
] |
96993fdbf4765a75c539bdb3c4902373458093e7
|
https://github.com/postmodern/pullr/blob/96993fdbf4765a75c539bdb3c4902373458093e7/lib/pullr/local_repository.rb#L67-L71
|
7,639 |
ghn/transprt
|
lib/transprt/client.rb
|
Transprt.Client.locations
|
def locations(parameters)
allowed_parameters = %w(query x y type)
query = create_query(parameters, allowed_parameters)
locations = perform('locations', query)
locations['stations']
end
|
ruby
|
def locations(parameters)
allowed_parameters = %w(query x y type)
query = create_query(parameters, allowed_parameters)
locations = perform('locations', query)
locations['stations']
end
|
[
"def",
"locations",
"(",
"parameters",
")",
"allowed_parameters",
"=",
"%w(",
"query",
"x",
"y",
"type",
")",
"query",
"=",
"create_query",
"(",
"parameters",
",",
"allowed_parameters",
")",
"locations",
"=",
"perform",
"(",
"'locations'",
",",
"query",
")",
"locations",
"[",
"'stations'",
"]",
"end"
] |
=> find locations
|
[
"=",
">",
"find",
"locations"
] |
da609d39cd1907ec86814c7c5412e889a807193c
|
https://github.com/ghn/transprt/blob/da609d39cd1907ec86814c7c5412e889a807193c/lib/transprt/client.rb#L20-L27
|
7,640 |
ghn/transprt
|
lib/transprt/client.rb
|
Transprt.Client.connections
|
def connections(parameters)
allowed_parameters = %w(from to via date time isArrivalTime
transportations limit page direct sleeper
couchette bike)
query = create_query(parameters, allowed_parameters)
locations = perform('connections', query)
locations['connections']
end
|
ruby
|
def connections(parameters)
allowed_parameters = %w(from to via date time isArrivalTime
transportations limit page direct sleeper
couchette bike)
query = create_query(parameters, allowed_parameters)
locations = perform('connections', query)
locations['connections']
end
|
[
"def",
"connections",
"(",
"parameters",
")",
"allowed_parameters",
"=",
"%w(",
"from",
"to",
"via",
"date",
"time",
"isArrivalTime",
"transportations",
"limit",
"page",
"direct",
"sleeper",
"couchette",
"bike",
")",
"query",
"=",
"create_query",
"(",
"parameters",
",",
"allowed_parameters",
")",
"locations",
"=",
"perform",
"(",
"'connections'",
",",
"query",
")",
"locations",
"[",
"'connections'",
"]",
"end"
] |
=> find connections
|
[
"=",
">",
"find",
"connections"
] |
da609d39cd1907ec86814c7c5412e889a807193c
|
https://github.com/ghn/transprt/blob/da609d39cd1907ec86814c7c5412e889a807193c/lib/transprt/client.rb#L32-L41
|
7,641 |
ghn/transprt
|
lib/transprt/client.rb
|
Transprt.Client.stationboard
|
def stationboard(parameters)
allowed_parameters = %w(station id limit transportations datetime)
query = create_query(parameters, allowed_parameters)
locations = perform('stationboard', query)
locations['stationboard']
end
|
ruby
|
def stationboard(parameters)
allowed_parameters = %w(station id limit transportations datetime)
query = create_query(parameters, allowed_parameters)
locations = perform('stationboard', query)
locations['stationboard']
end
|
[
"def",
"stationboard",
"(",
"parameters",
")",
"allowed_parameters",
"=",
"%w(",
"station",
"id",
"limit",
"transportations",
"datetime",
")",
"query",
"=",
"create_query",
"(",
"parameters",
",",
"allowed_parameters",
")",
"locations",
"=",
"perform",
"(",
"'stationboard'",
",",
"query",
")",
"locations",
"[",
"'stationboard'",
"]",
"end"
] |
=> find station boards
|
[
"=",
">",
"find",
"station",
"boards"
] |
da609d39cd1907ec86814c7c5412e889a807193c
|
https://github.com/ghn/transprt/blob/da609d39cd1907ec86814c7c5412e889a807193c/lib/transprt/client.rb#L46-L53
|
7,642 |
billychan/simple_activity
|
lib/simple_activity/models/activity.rb
|
SimpleActivity.Activity.method_missing
|
def method_missing(method_name, *arguments, &block)
if method_name.to_s =~ /(actor|target)_(?!type|id).*/
self.cache.try(:[], method_name.to_s)
else
super
end
end
|
ruby
|
def method_missing(method_name, *arguments, &block)
if method_name.to_s =~ /(actor|target)_(?!type|id).*/
self.cache.try(:[], method_name.to_s)
else
super
end
end
|
[
"def",
"method_missing",
"(",
"method_name",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"if",
"method_name",
".",
"to_s",
"=~",
"/",
"/",
"self",
".",
"cache",
".",
"try",
"(",
":[]",
",",
"method_name",
".",
"to_s",
")",
"else",
"super",
"end",
"end"
] |
Delegate the methods start with "actor_" or "target_" to
cached result
|
[
"Delegate",
"the",
"methods",
"start",
"with",
"actor_",
"or",
"target_",
"to",
"cached",
"result"
] |
fd24768908393e6aeae285834902be05c7b8ce42
|
https://github.com/billychan/simple_activity/blob/fd24768908393e6aeae285834902be05c7b8ce42/lib/simple_activity/models/activity.rb#L35-L41
|
7,643 |
profitbricks/profitbricks-sdk-ruby
|
lib/profitbricks/loadbalancer.rb
|
ProfitBricks.Loadbalancer.update
|
def update(options = {})
response = ProfitBricks.request(
method: :patch,
path: "/datacenters/#{datacenterId}/loadbalancers/#{id}",
expects: 202,
body: options.to_json
)
if response
self.requestId = response['requestId']
@properties = @properties.merge(response['properties'])
end
self
end
|
ruby
|
def update(options = {})
response = ProfitBricks.request(
method: :patch,
path: "/datacenters/#{datacenterId}/loadbalancers/#{id}",
expects: 202,
body: options.to_json
)
if response
self.requestId = response['requestId']
@properties = @properties.merge(response['properties'])
end
self
end
|
[
"def",
"update",
"(",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"ProfitBricks",
".",
"request",
"(",
"method",
":",
":patch",
",",
"path",
":",
"\"/datacenters/#{datacenterId}/loadbalancers/#{id}\"",
",",
"expects",
":",
"202",
",",
"body",
":",
"options",
".",
"to_json",
")",
"if",
"response",
"self",
".",
"requestId",
"=",
"response",
"[",
"'requestId'",
"]",
"@properties",
"=",
"@properties",
".",
"merge",
"(",
"response",
"[",
"'properties'",
"]",
")",
"end",
"self",
"end"
] |
Update the loadbalancer.
|
[
"Update",
"the",
"loadbalancer",
"."
] |
03a379e412b0e6c0789ed14f2449f18bda622742
|
https://github.com/profitbricks/profitbricks-sdk-ruby/blob/03a379e412b0e6c0789ed14f2449f18bda622742/lib/profitbricks/loadbalancer.rb#L16-L28
|
7,644 |
jlinder/nitroapi
|
lib/nitro_api.rb
|
NitroApi.NitroApi.sign
|
def sign(time)
unencrypted_signature = @api_key + @secret + time + @user.to_s
to_digest = unencrypted_signature + unencrypted_signature.length.to_s
return Digest::MD5.hexdigest(to_digest)
end
|
ruby
|
def sign(time)
unencrypted_signature = @api_key + @secret + time + @user.to_s
to_digest = unencrypted_signature + unencrypted_signature.length.to_s
return Digest::MD5.hexdigest(to_digest)
end
|
[
"def",
"sign",
"(",
"time",
")",
"unencrypted_signature",
"=",
"@api_key",
"+",
"@secret",
"+",
"time",
"+",
"@user",
".",
"to_s",
"to_digest",
"=",
"unencrypted_signature",
"+",
"unencrypted_signature",
".",
"length",
".",
"to_s",
"return",
"Digest",
"::",
"MD5",
".",
"hexdigest",
"(",
"to_digest",
")",
"end"
] |
Method for constructing a signature
|
[
"Method",
"for",
"constructing",
"a",
"signature"
] |
9bf51a1988e213ce0020b783d7d375fe8d418638
|
https://github.com/jlinder/nitroapi/blob/9bf51a1988e213ce0020b783d7d375fe8d418638/lib/nitro_api.rb#L76-L80
|
7,645 |
jrochkind/borrow_direct
|
lib/borrow_direct/generate_query.rb
|
BorrowDirect.GenerateQuery.normalized_author
|
def normalized_author(author)
return "" if author.nil? || author.empty?
author = author.downcase
# Just take everything before the comma/semicolon if we have one --
# or before an "and", for stripping individuals out of 245c
# multiples.
if author =~ /\A([^,;]*)(,|\sand\s|;)/
author = $1
end
author.gsub!(/\A.*by\s*/, '')
# We want to remove some punctuation that is better
# turned into a space in the query. Along with
# any kind of unicode space, why not.
author.gsub!(PUNCT_STRIP_REGEX, ' ')
# compress any remaining whitespace
author.strip!
author.gsub!(/\s+/, ' ')
return author
end
|
ruby
|
def normalized_author(author)
return "" if author.nil? || author.empty?
author = author.downcase
# Just take everything before the comma/semicolon if we have one --
# or before an "and", for stripping individuals out of 245c
# multiples.
if author =~ /\A([^,;]*)(,|\sand\s|;)/
author = $1
end
author.gsub!(/\A.*by\s*/, '')
# We want to remove some punctuation that is better
# turned into a space in the query. Along with
# any kind of unicode space, why not.
author.gsub!(PUNCT_STRIP_REGEX, ' ')
# compress any remaining whitespace
author.strip!
author.gsub!(/\s+/, ' ')
return author
end
|
[
"def",
"normalized_author",
"(",
"author",
")",
"return",
"\"\"",
"if",
"author",
".",
"nil?",
"||",
"author",
".",
"empty?",
"author",
"=",
"author",
".",
"downcase",
"# Just take everything before the comma/semicolon if we have one --",
"# or before an \"and\", for stripping individuals out of 245c",
"# multiples. ",
"if",
"author",
"=~",
"/",
"\\A",
"\\s",
"\\s",
"/",
"author",
"=",
"$1",
"end",
"author",
".",
"gsub!",
"(",
"/",
"\\A",
"\\s",
"/",
",",
"''",
")",
"# We want to remove some punctuation that is better",
"# turned into a space in the query. Along with",
"# any kind of unicode space, why not. ",
"author",
".",
"gsub!",
"(",
"PUNCT_STRIP_REGEX",
",",
"' '",
")",
"# compress any remaining whitespace",
"author",
".",
"strip!",
"author",
".",
"gsub!",
"(",
"/",
"\\s",
"/",
",",
"' '",
")",
"return",
"author",
"end"
] |
Lowercase, and try to get just the last name out of something
that looks like a cataloging authorized heading.
Try to remove leading 'by' stuff when we're getting a 245c
|
[
"Lowercase",
"and",
"try",
"to",
"get",
"just",
"the",
"last",
"name",
"out",
"of",
"something",
"that",
"looks",
"like",
"a",
"cataloging",
"authorized",
"heading",
"."
] |
f2f53760e15d742a5c5584dd641f20dea315f99f
|
https://github.com/jrochkind/borrow_direct/blob/f2f53760e15d742a5c5584dd641f20dea315f99f/lib/borrow_direct/generate_query.rb#L129-L154
|
7,646 |
jduckett/duck_map
|
lib/duck_map/view_helpers.rb
|
DuckMap.ActionViewHelpers.sitemap_meta_keywords
|
def sitemap_meta_keywords
return controller.sitemap_meta_data[:keywords].blank? ? nil : tag(:meta, {name: :keywords, content: controller.sitemap_meta_data[:keywords]}, false, false)
end
|
ruby
|
def sitemap_meta_keywords
return controller.sitemap_meta_data[:keywords].blank? ? nil : tag(:meta, {name: :keywords, content: controller.sitemap_meta_data[:keywords]}, false, false)
end
|
[
"def",
"sitemap_meta_keywords",
"return",
"controller",
".",
"sitemap_meta_data",
"[",
":keywords",
"]",
".",
"blank?",
"?",
"nil",
":",
"tag",
"(",
":meta",
",",
"{",
"name",
":",
":keywords",
",",
"content",
":",
"controller",
".",
"sitemap_meta_data",
"[",
":keywords",
"]",
"}",
",",
"false",
",",
"false",
")",
"end"
] |
Generates a keywords meta tag for use inside HTML header area.
@return [String] HTML safe keywords meta tag.
|
[
"Generates",
"a",
"keywords",
"meta",
"tag",
"for",
"use",
"inside",
"HTML",
"header",
"area",
"."
] |
c510acfa95e8ad4afb1501366058ae88a73704df
|
https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/view_helpers.rb#L54-L56
|
7,647 |
jduckett/duck_map
|
lib/duck_map/view_helpers.rb
|
DuckMap.ActionViewHelpers.sitemap_meta_description
|
def sitemap_meta_description
return controller.sitemap_meta_data[:description].blank? ? nil : tag(:meta, {name: :description, content: controller.sitemap_meta_data[:description]}, false, false)
end
|
ruby
|
def sitemap_meta_description
return controller.sitemap_meta_data[:description].blank? ? nil : tag(:meta, {name: :description, content: controller.sitemap_meta_data[:description]}, false, false)
end
|
[
"def",
"sitemap_meta_description",
"return",
"controller",
".",
"sitemap_meta_data",
"[",
":description",
"]",
".",
"blank?",
"?",
"nil",
":",
"tag",
"(",
":meta",
",",
"{",
"name",
":",
":description",
",",
"content",
":",
"controller",
".",
"sitemap_meta_data",
"[",
":description",
"]",
"}",
",",
"false",
",",
"false",
")",
"end"
] |
Generates a description meta tag for use inside HTML header area.
@return [String] HTML safe description meta tag.
|
[
"Generates",
"a",
"description",
"meta",
"tag",
"for",
"use",
"inside",
"HTML",
"header",
"area",
"."
] |
c510acfa95e8ad4afb1501366058ae88a73704df
|
https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/view_helpers.rb#L65-L67
|
7,648 |
jduckett/duck_map
|
lib/duck_map/view_helpers.rb
|
DuckMap.ActionViewHelpers.sitemap_meta_lastmod
|
def sitemap_meta_lastmod
return controller.sitemap_meta_data[:lastmod].blank? ? nil : tag(:meta, {name: "Last-Modified", content: controller.sitemap_meta_data[:lastmod]}, false, false)
end
|
ruby
|
def sitemap_meta_lastmod
return controller.sitemap_meta_data[:lastmod].blank? ? nil : tag(:meta, {name: "Last-Modified", content: controller.sitemap_meta_data[:lastmod]}, false, false)
end
|
[
"def",
"sitemap_meta_lastmod",
"return",
"controller",
".",
"sitemap_meta_data",
"[",
":lastmod",
"]",
".",
"blank?",
"?",
"nil",
":",
"tag",
"(",
":meta",
",",
"{",
"name",
":",
"\"Last-Modified\"",
",",
"content",
":",
"controller",
".",
"sitemap_meta_data",
"[",
":lastmod",
"]",
"}",
",",
"false",
",",
"false",
")",
"end"
] |
Generates a Last-Modified meta tag for use inside HTML header area.
@return [String] HTML safe Last-Modified meta tag.
|
[
"Generates",
"a",
"Last",
"-",
"Modified",
"meta",
"tag",
"for",
"use",
"inside",
"HTML",
"header",
"area",
"."
] |
c510acfa95e8ad4afb1501366058ae88a73704df
|
https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/view_helpers.rb#L76-L78
|
7,649 |
jduckett/duck_map
|
lib/duck_map/view_helpers.rb
|
DuckMap.ActionViewHelpers.sitemap_meta_canonical
|
def sitemap_meta_canonical
return controller.sitemap_meta_data[:canonical].blank? ? nil : tag(:link, {rel: :canonical, href: controller.sitemap_meta_data[:canonical]}, false, false)
end
|
ruby
|
def sitemap_meta_canonical
return controller.sitemap_meta_data[:canonical].blank? ? nil : tag(:link, {rel: :canonical, href: controller.sitemap_meta_data[:canonical]}, false, false)
end
|
[
"def",
"sitemap_meta_canonical",
"return",
"controller",
".",
"sitemap_meta_data",
"[",
":canonical",
"]",
".",
"blank?",
"?",
"nil",
":",
"tag",
"(",
":link",
",",
"{",
"rel",
":",
":canonical",
",",
"href",
":",
"controller",
".",
"sitemap_meta_data",
"[",
":canonical",
"]",
"}",
",",
"false",
",",
"false",
")",
"end"
] |
Generates a canonical link tag for use inside HTML header area.
@return [String] HTML safe canonical link tag.
|
[
"Generates",
"a",
"canonical",
"link",
"tag",
"for",
"use",
"inside",
"HTML",
"header",
"area",
"."
] |
c510acfa95e8ad4afb1501366058ae88a73704df
|
https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/view_helpers.rb#L87-L89
|
7,650 |
asaaki/sjekksum
|
lib/sjekksum/primitive97.rb
|
Sjekksum.Primitive97.valid?
|
def valid? number
raise_on_type_mismatch number
num, check = split_number(number)
self.of(num) == check
end
|
ruby
|
def valid? number
raise_on_type_mismatch number
num, check = split_number(number)
self.of(num) == check
end
|
[
"def",
"valid?",
"number",
"raise_on_type_mismatch",
"number",
"num",
",",
"check",
"=",
"split_number",
"(",
"number",
")",
"self",
".",
"of",
"(",
"num",
")",
"==",
"check",
"end"
] |
Primitive97 validation of provided number
@example
Sjekksum::Primitive97.valid?(235695) #=> true
@param number [Integer, String] number with included checksum
@return [Boolean]
|
[
"Primitive97",
"validation",
"of",
"provided",
"number"
] |
47a21c19dcffc67a3bef11d4f2de7c167fd20087
|
https://github.com/asaaki/sjekksum/blob/47a21c19dcffc67a3bef11d4f2de7c167fd20087/lib/sjekksum/primitive97.rb#L35-L39
|
7,651 |
kamui/rack-accept_headers
|
lib/rack/accept_headers/context.rb
|
Rack::AcceptHeaders.Context.check!
|
def check!(request)
@check_headers.each do |header_name|
values = @checks[header_name]
header = request.send(header_name)
raise AcceptError unless values.any? {|v| header.accept?(v) }
end
end
|
ruby
|
def check!(request)
@check_headers.each do |header_name|
values = @checks[header_name]
header = request.send(header_name)
raise AcceptError unless values.any? {|v| header.accept?(v) }
end
end
|
[
"def",
"check!",
"(",
"request",
")",
"@check_headers",
".",
"each",
"do",
"|",
"header_name",
"|",
"values",
"=",
"@checks",
"[",
"header_name",
"]",
"header",
"=",
"request",
".",
"send",
"(",
"header_name",
")",
"raise",
"AcceptError",
"unless",
"values",
".",
"any?",
"{",
"|",
"v",
"|",
"header",
".",
"accept?",
"(",
"v",
")",
"}",
"end",
"end"
] |
Raises an AcceptError if this server is not able to serve an acceptable
response.
|
[
"Raises",
"an",
"AcceptError",
"if",
"this",
"server",
"is",
"not",
"able",
"to",
"serve",
"an",
"acceptable",
"response",
"."
] |
099bfbb919de86b5842c8e14be42b8b784e53f03
|
https://github.com/kamui/rack-accept_headers/blob/099bfbb919de86b5842c8e14be42b8b784e53f03/lib/rack/accept_headers/context.rb#L59-L65
|
7,652 |
asaaki/sjekksum
|
lib/sjekksum/verhoeff.rb
|
Sjekksum.Verhoeff.of
|
def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
INVERSE[digits.reverse_each.with_index.reduce(0) { |check, (digit, idx)|
d_row = DIHEDRAL_GROUP_D5[check]
d_row[ PERMUTATION[idx.next % 8][digit] ]
}]
end
|
ruby
|
def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
INVERSE[digits.reverse_each.with_index.reduce(0) { |check, (digit, idx)|
d_row = DIHEDRAL_GROUP_D5[check]
d_row[ PERMUTATION[idx.next % 8][digit] ]
}]
end
|
[
"def",
"of",
"number",
"raise_on_type_mismatch",
"number",
"digits",
"=",
"convert_number_to_digits",
"(",
"number",
")",
"INVERSE",
"[",
"digits",
".",
"reverse_each",
".",
"with_index",
".",
"reduce",
"(",
"0",
")",
"{",
"|",
"check",
",",
"(",
"digit",
",",
"idx",
")",
"|",
"d_row",
"=",
"DIHEDRAL_GROUP_D5",
"[",
"check",
"]",
"d_row",
"[",
"PERMUTATION",
"[",
"idx",
".",
"next",
"%",
"8",
"]",
"[",
"digit",
"]",
"]",
"}",
"]",
"end"
] |
Calculates Verhoeff checksum
@example
Sjekksum::Verhoeff.of(142857) #=> 0
@param number [Integer, String] number for which the checksum should be calculated
@return [Integer] calculated checksum
|
[
"Calculates",
"Verhoeff",
"checksum"
] |
47a21c19dcffc67a3bef11d4f2de7c167fd20087
|
https://github.com/asaaki/sjekksum/blob/47a21c19dcffc67a3bef11d4f2de7c167fd20087/lib/sjekksum/verhoeff.rb#L49-L57
|
7,653 |
sosedoff/lxc-ruby
|
lib/lxc/configuration.rb
|
LXC.Configuration.save_to_file
|
def save_to_file(path)
fullpath = File.expand_path(path)
lines = []
@content.each_pair do |key,value|
k = "lxc.#{key.gsub('_', '.')}"
if value.kind_of?(Array)
lines << value.map { |v| "#{k} = #{v}" }
else
lines << "#{k} = #{value}"
end
end
File.open(path, "w") do |f|
f.write(lines.flatten.join("\n"))
end
end
|
ruby
|
def save_to_file(path)
fullpath = File.expand_path(path)
lines = []
@content.each_pair do |key,value|
k = "lxc.#{key.gsub('_', '.')}"
if value.kind_of?(Array)
lines << value.map { |v| "#{k} = #{v}" }
else
lines << "#{k} = #{value}"
end
end
File.open(path, "w") do |f|
f.write(lines.flatten.join("\n"))
end
end
|
[
"def",
"save_to_file",
"(",
"path",
")",
"fullpath",
"=",
"File",
".",
"expand_path",
"(",
"path",
")",
"lines",
"=",
"[",
"]",
"@content",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"k",
"=",
"\"lxc.#{key.gsub('_', '.')}\"",
"if",
"value",
".",
"kind_of?",
"(",
"Array",
")",
"lines",
"<<",
"value",
".",
"map",
"{",
"|",
"v",
"|",
"\"#{k} = #{v}\"",
"}",
"else",
"lines",
"<<",
"\"#{k} = #{value}\"",
"end",
"end",
"File",
".",
"open",
"(",
"path",
",",
"\"w\"",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"lines",
".",
"flatten",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end"
] |
Save configuration into file
@param [path] path to output file
|
[
"Save",
"configuration",
"into",
"file"
] |
6d82c2ae3513789b2856d07a156e9131369f95fe
|
https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/configuration.rb#L47-L64
|
7,654 |
sportngin/typhoid
|
lib/typhoid/request_builder.rb
|
Typhoid.RequestBuilder.symbolize_keys
|
def symbolize_keys(hash)
hash = hash.to_hash
if hash.respond_to?(:symbolize_keys)
hash.symbolize_keys
else
hash.inject({}) do |new_hash, (key, value)|
new_hash[symbolize_key(key)] = value
new_hash
end
end
end
|
ruby
|
def symbolize_keys(hash)
hash = hash.to_hash
if hash.respond_to?(:symbolize_keys)
hash.symbolize_keys
else
hash.inject({}) do |new_hash, (key, value)|
new_hash[symbolize_key(key)] = value
new_hash
end
end
end
|
[
"def",
"symbolize_keys",
"(",
"hash",
")",
"hash",
"=",
"hash",
".",
"to_hash",
"if",
"hash",
".",
"respond_to?",
"(",
":symbolize_keys",
")",
"hash",
".",
"symbolize_keys",
"else",
"hash",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"new_hash",
",",
"(",
"key",
",",
"value",
")",
"|",
"new_hash",
"[",
"symbolize_key",
"(",
"key",
")",
"]",
"=",
"value",
"new_hash",
"end",
"end",
"end"
] |
Ethon hates on hash with indifferent access for some reason
|
[
"Ethon",
"hates",
"on",
"hash",
"with",
"indifferent",
"access",
"for",
"some",
"reason"
] |
c711dddf86ffc356ea4700626086daaf1567dc30
|
https://github.com/sportngin/typhoid/blob/c711dddf86ffc356ea4700626086daaf1567dc30/lib/typhoid/request_builder.rb#L30-L40
|
7,655 |
ghn/transprt
|
lib/transprt/rate_limiting.rb
|
Transprt.RateLimiting.get
|
def get(url)
begin
response = perform_get(url)
rescue RestClient::TooManyRequests => e
# API uses HTTP 429 to notify us,
# @see https://github.com/OpendataCH/Transport/blob/master/lib/Transport/Application.php
return nil unless wait_for_quota
sleep_until_quota_reset(e.response)
response = perform_get(url)
end
response
end
|
ruby
|
def get(url)
begin
response = perform_get(url)
rescue RestClient::TooManyRequests => e
# API uses HTTP 429 to notify us,
# @see https://github.com/OpendataCH/Transport/blob/master/lib/Transport/Application.php
return nil unless wait_for_quota
sleep_until_quota_reset(e.response)
response = perform_get(url)
end
response
end
|
[
"def",
"get",
"(",
"url",
")",
"begin",
"response",
"=",
"perform_get",
"(",
"url",
")",
"rescue",
"RestClient",
"::",
"TooManyRequests",
"=>",
"e",
"# API uses HTTP 429 to notify us,",
"# @see https://github.com/OpendataCH/Transport/blob/master/lib/Transport/Application.php",
"return",
"nil",
"unless",
"wait_for_quota",
"sleep_until_quota_reset",
"(",
"e",
".",
"response",
")",
"response",
"=",
"perform_get",
"(",
"url",
")",
"end",
"response",
"end"
] |
Performs HTTP queries while respecting the rate limit.
@param wait_for_quota [Boolean] whether to wait for quota reset
and query again if the rate limit (300 requests/s) is exceeded.
@return The HTTP response or nil if we're hitting the rate limit and
wait_for_quota is false (@see #initialize).
|
[
"Performs",
"HTTP",
"queries",
"while",
"respecting",
"the",
"rate",
"limit",
"."
] |
da609d39cd1907ec86814c7c5412e889a807193c
|
https://github.com/ghn/transprt/blob/da609d39cd1907ec86814c7c5412e889a807193c/lib/transprt/rate_limiting.rb#L13-L27
|
7,656 |
kamui/rack-accept_headers
|
lib/rack/accept_headers/language.rb
|
Rack::AcceptHeaders.Language.matches
|
def matches(language)
values.select {|v|
v = v.match(/^(.+?)-/) ? $1 : v if @first_level_match
v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
}.sort {|a, b|
# "*" gets least precedence, any others are compared based on length.
a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
}.reverse
end
|
ruby
|
def matches(language)
values.select {|v|
v = v.match(/^(.+?)-/) ? $1 : v if @first_level_match
v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
}.sort {|a, b|
# "*" gets least precedence, any others are compared based on length.
a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
}.reverse
end
|
[
"def",
"matches",
"(",
"language",
")",
"values",
".",
"select",
"{",
"|",
"v",
"|",
"v",
"=",
"v",
".",
"match",
"(",
"/",
"/",
")",
"?",
"$1",
":",
"v",
"if",
"@first_level_match",
"v",
"==",
"language",
"||",
"v",
"==",
"'*'",
"||",
"(",
"language",
".",
"match",
"(",
"/",
"/",
")",
"&&",
"v",
"==",
"$1",
")",
"}",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"# \"*\" gets least precedence, any others are compared based on length.",
"a",
"==",
"'*'",
"?",
"-",
"1",
":",
"(",
"b",
"==",
"'*'",
"?",
"1",
":",
"a",
".",
"length",
"<=>",
"b",
".",
"length",
")",
"}",
".",
"reverse",
"end"
] |
Returns an array of languages from this header that match the given
+language+, ordered by precedence.
|
[
"Returns",
"an",
"array",
"of",
"languages",
"from",
"this",
"header",
"that",
"match",
"the",
"given",
"+",
"language",
"+",
"ordered",
"by",
"precedence",
"."
] |
099bfbb919de86b5842c8e14be42b8b784e53f03
|
https://github.com/kamui/rack-accept_headers/blob/099bfbb919de86b5842c8e14be42b8b784e53f03/lib/rack/accept_headers/language.rb#L26-L34
|
7,657 |
dalehamel/ruby-pandoc
|
lib/ruby-pandoc/converter.rb
|
RubyPandoc.Converter.convert
|
def convert(*args)
@options += args if args
outputfile = @options.map{ |x| x[:output] }.compact
tmp_file = Tempfile.new('pandoc-conversion')
@options += [{ output: tmp_file.path }] if outputfile.empty?
@option_string = prepare_options(@options)
begin
run_pandoc
IO.binread(tmp_file)
ensure
tmp_file.close
tmp_file.unlink
end
end
|
ruby
|
def convert(*args)
@options += args if args
outputfile = @options.map{ |x| x[:output] }.compact
tmp_file = Tempfile.new('pandoc-conversion')
@options += [{ output: tmp_file.path }] if outputfile.empty?
@option_string = prepare_options(@options)
begin
run_pandoc
IO.binread(tmp_file)
ensure
tmp_file.close
tmp_file.unlink
end
end
|
[
"def",
"convert",
"(",
"*",
"args",
")",
"@options",
"+=",
"args",
"if",
"args",
"outputfile",
"=",
"@options",
".",
"map",
"{",
"|",
"x",
"|",
"x",
"[",
":output",
"]",
"}",
".",
"compact",
"tmp_file",
"=",
"Tempfile",
".",
"new",
"(",
"'pandoc-conversion'",
")",
"@options",
"+=",
"[",
"{",
"output",
":",
"tmp_file",
".",
"path",
"}",
"]",
"if",
"outputfile",
".",
"empty?",
"@option_string",
"=",
"prepare_options",
"(",
"@options",
")",
"begin",
"run_pandoc",
"IO",
".",
"binread",
"(",
"tmp_file",
")",
"ensure",
"tmp_file",
".",
"close",
"tmp_file",
".",
"unlink",
"end",
"end"
] |
Create a new RubyPandoc converter object. The first argument contains the
input either as string or as an array of filenames.
Any other arguments will be converted to pandoc options.
Usage:
new("# A String", :option1 => :value, :option2)
new(["/path/to/file.md"], :option1 => :value, :option2)
new(["/to/file1.html", "/to/file2.html"], :option1 => :value)
Run the conversion. The convert method can take any number of arguments,
which will be converted to pandoc options. If options were already
specified in an initializer or reader method, they will be combined with
any that are passed to this method.
Returns a string with the converted content.
Example:
RubyPandoc.new("# text").convert
# => "<h1 id=\"text\">text</h1>\n"
|
[
"Create",
"a",
"new",
"RubyPandoc",
"converter",
"object",
".",
"The",
"first",
"argument",
"contains",
"the",
"input",
"either",
"as",
"string",
"or",
"as",
"an",
"array",
"of",
"filenames",
"."
] |
43a4081c137bc9b7308651dd616e571b63b5ad6a
|
https://github.com/dalehamel/ruby-pandoc/blob/43a4081c137bc9b7308651dd616e571b63b5ad6a/lib/ruby-pandoc/converter.rb#L99-L112
|
7,658 |
dalehamel/ruby-pandoc
|
lib/ruby-pandoc/converter.rb
|
RubyPandoc.Converter.run_pandoc
|
def run_pandoc
command = unless @input_files.nil? || @input_files.empty?
"#{@@pandoc_path} #{@input_files} #{@option_string}"
else
"#{@@pandoc_path} #{@option_string}"
end
output = error = exit_status = nil
options = {}
options[:stdin_data] = @input_string if @input_string
output, error, exit_status = Open3.capture3(command, **options)
raise error unless exit_status && exit_status.success?
output
end
|
ruby
|
def run_pandoc
command = unless @input_files.nil? || @input_files.empty?
"#{@@pandoc_path} #{@input_files} #{@option_string}"
else
"#{@@pandoc_path} #{@option_string}"
end
output = error = exit_status = nil
options = {}
options[:stdin_data] = @input_string if @input_string
output, error, exit_status = Open3.capture3(command, **options)
raise error unless exit_status && exit_status.success?
output
end
|
[
"def",
"run_pandoc",
"command",
"=",
"unless",
"@input_files",
".",
"nil?",
"||",
"@input_files",
".",
"empty?",
"\"#{@@pandoc_path} #{@input_files} #{@option_string}\"",
"else",
"\"#{@@pandoc_path} #{@option_string}\"",
"end",
"output",
"=",
"error",
"=",
"exit_status",
"=",
"nil",
"options",
"=",
"{",
"}",
"options",
"[",
":stdin_data",
"]",
"=",
"@input_string",
"if",
"@input_string",
"output",
",",
"error",
",",
"exit_status",
"=",
"Open3",
".",
"capture3",
"(",
"command",
",",
"**",
"options",
")",
"raise",
"error",
"unless",
"exit_status",
"&&",
"exit_status",
".",
"success?",
"output",
"end"
] |
Wrapper to run pandoc in a consistent, DRY way
|
[
"Wrapper",
"to",
"run",
"pandoc",
"in",
"a",
"consistent",
"DRY",
"way"
] |
43a4081c137bc9b7308651dd616e571b63b5ad6a
|
https://github.com/dalehamel/ruby-pandoc/blob/43a4081c137bc9b7308651dd616e571b63b5ad6a/lib/ruby-pandoc/converter.rb#L156-L168
|
7,659 |
dalehamel/ruby-pandoc
|
lib/ruby-pandoc/converter.rb
|
RubyPandoc.Converter.prepare_options
|
def prepare_options(opts = [])
opts.inject('') do |string, (option, value)|
string += case
when value
create_option(option, value)
when option.respond_to?(:each_pair)
prepare_options(option)
else
create_option(option)
end
end
end
|
ruby
|
def prepare_options(opts = [])
opts.inject('') do |string, (option, value)|
string += case
when value
create_option(option, value)
when option.respond_to?(:each_pair)
prepare_options(option)
else
create_option(option)
end
end
end
|
[
"def",
"prepare_options",
"(",
"opts",
"=",
"[",
"]",
")",
"opts",
".",
"inject",
"(",
"''",
")",
"do",
"|",
"string",
",",
"(",
"option",
",",
"value",
")",
"|",
"string",
"+=",
"case",
"when",
"value",
"create_option",
"(",
"option",
",",
"value",
")",
"when",
"option",
".",
"respond_to?",
"(",
":each_pair",
")",
"prepare_options",
"(",
"option",
")",
"else",
"create_option",
"(",
"option",
")",
"end",
"end",
"end"
] |
Builds the option string to be passed to pandoc by iterating over the
opts passed in. Recursively calls itself in order to handle hash options.
|
[
"Builds",
"the",
"option",
"string",
"to",
"be",
"passed",
"to",
"pandoc",
"by",
"iterating",
"over",
"the",
"opts",
"passed",
"in",
".",
"Recursively",
"calls",
"itself",
"in",
"order",
"to",
"handle",
"hash",
"options",
"."
] |
43a4081c137bc9b7308651dd616e571b63b5ad6a
|
https://github.com/dalehamel/ruby-pandoc/blob/43a4081c137bc9b7308651dd616e571b63b5ad6a/lib/ruby-pandoc/converter.rb#L172-L183
|
7,660 |
dalehamel/ruby-pandoc
|
lib/ruby-pandoc/converter.rb
|
RubyPandoc.Converter.create_option
|
def create_option(flag, argument = nil)
return '' unless flag
flag = flag.to_s
return " #{argument}" if flag == 'extra'
set_pandoc_ruby_options(flag, argument)
if !argument.nil?
"#{format_flag(flag)} #{argument}"
else
format_flag(flag)
end
end
|
ruby
|
def create_option(flag, argument = nil)
return '' unless flag
flag = flag.to_s
return " #{argument}" if flag == 'extra'
set_pandoc_ruby_options(flag, argument)
if !argument.nil?
"#{format_flag(flag)} #{argument}"
else
format_flag(flag)
end
end
|
[
"def",
"create_option",
"(",
"flag",
",",
"argument",
"=",
"nil",
")",
"return",
"''",
"unless",
"flag",
"flag",
"=",
"flag",
".",
"to_s",
"return",
"\" #{argument}\"",
"if",
"flag",
"==",
"'extra'",
"set_pandoc_ruby_options",
"(",
"flag",
",",
"argument",
")",
"if",
"!",
"argument",
".",
"nil?",
"\"#{format_flag(flag)} #{argument}\"",
"else",
"format_flag",
"(",
"flag",
")",
"end",
"end"
] |
Takes a flag and optional argument, uses it to set any relevant options
used by the library, and returns string with the option formatted as a
command line options. If the option has an argument, it is also included.
|
[
"Takes",
"a",
"flag",
"and",
"optional",
"argument",
"uses",
"it",
"to",
"set",
"any",
"relevant",
"options",
"used",
"by",
"the",
"library",
"and",
"returns",
"string",
"with",
"the",
"option",
"formatted",
"as",
"a",
"command",
"line",
"options",
".",
"If",
"the",
"option",
"has",
"an",
"argument",
"it",
"is",
"also",
"included",
"."
] |
43a4081c137bc9b7308651dd616e571b63b5ad6a
|
https://github.com/dalehamel/ruby-pandoc/blob/43a4081c137bc9b7308651dd616e571b63b5ad6a/lib/ruby-pandoc/converter.rb#L188-L198
|
7,661 |
dalehamel/ruby-pandoc
|
lib/ruby-pandoc/converter.rb
|
RubyPandoc.Converter.set_pandoc_ruby_options
|
def set_pandoc_ruby_options(flag, argument = nil)
case flag
when 't', 'to'
@writer = argument.to_s
@binary_output = true if BINARY_WRITERS.keys.include?(@writer)
end
end
|
ruby
|
def set_pandoc_ruby_options(flag, argument = nil)
case flag
when 't', 'to'
@writer = argument.to_s
@binary_output = true if BINARY_WRITERS.keys.include?(@writer)
end
end
|
[
"def",
"set_pandoc_ruby_options",
"(",
"flag",
",",
"argument",
"=",
"nil",
")",
"case",
"flag",
"when",
"'t'",
",",
"'to'",
"@writer",
"=",
"argument",
".",
"to_s",
"@binary_output",
"=",
"true",
"if",
"BINARY_WRITERS",
".",
"keys",
".",
"include?",
"(",
"@writer",
")",
"end",
"end"
] |
Takes an option and optional argument and uses them to set any flags
used by RubyPandoc.
|
[
"Takes",
"an",
"option",
"and",
"optional",
"argument",
"and",
"uses",
"them",
"to",
"set",
"any",
"flags",
"used",
"by",
"RubyPandoc",
"."
] |
43a4081c137bc9b7308651dd616e571b63b5ad6a
|
https://github.com/dalehamel/ruby-pandoc/blob/43a4081c137bc9b7308651dd616e571b63b5ad6a/lib/ruby-pandoc/converter.rb#L212-L218
|
7,662 |
jarhart/rattler
|
lib/rattler/parsers/attributed_sequence.rb
|
Rattler::Parsers.AttributedSequence.parse
|
def parse(scanner, rules, scope = ParserScope.empty)
result = false
backtracking(scanner) do
if scope = parse_children(scanner, rules, scope.nest) {|r| result = r }
yield scope if block_given?
result
end
end
end
|
ruby
|
def parse(scanner, rules, scope = ParserScope.empty)
result = false
backtracking(scanner) do
if scope = parse_children(scanner, rules, scope.nest) {|r| result = r }
yield scope if block_given?
result
end
end
end
|
[
"def",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
"=",
"ParserScope",
".",
"empty",
")",
"result",
"=",
"false",
"backtracking",
"(",
"scanner",
")",
"do",
"if",
"scope",
"=",
"parse_children",
"(",
"scanner",
",",
"rules",
",",
"scope",
".",
"nest",
")",
"{",
"|",
"r",
"|",
"result",
"=",
"r",
"}",
"yield",
"scope",
"if",
"block_given?",
"result",
"end",
"end",
"end"
] |
Parse each parser in sequence, and if they all succeed return the result
of applying the semantic action to the captured results.
@param (see Match#parse)
@return the result of applying the semantic action to the captured
results of each parser, or +false
|
[
"Parse",
"each",
"parser",
"in",
"sequence",
"and",
"if",
"they",
"all",
"succeed",
"return",
"the",
"result",
"of",
"applying",
"the",
"semantic",
"action",
"to",
"the",
"captured",
"results",
"."
] |
8b4efde2a05e9e790955bb635d4a1a9615893719
|
https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/parsers/attributed_sequence.rb#L24-L32
|
7,663 |
evanrolfe/ruby-holdem
|
lib/ruby_holdem/deck.rb
|
RubyHoldem.Deck.burn
|
def burn(burn_cards)
return false if burn_cards.is_a?(Integer)
if burn_cards.is_a?(Card) || burn_cards.is_a?(String)
burn_cards = [burn_cards]
end
burn_cards.map! do |c|
c = Card.new(c) unless c.class == Card
@cards.delete(c)
end
true
end
|
ruby
|
def burn(burn_cards)
return false if burn_cards.is_a?(Integer)
if burn_cards.is_a?(Card) || burn_cards.is_a?(String)
burn_cards = [burn_cards]
end
burn_cards.map! do |c|
c = Card.new(c) unless c.class == Card
@cards.delete(c)
end
true
end
|
[
"def",
"burn",
"(",
"burn_cards",
")",
"return",
"false",
"if",
"burn_cards",
".",
"is_a?",
"(",
"Integer",
")",
"if",
"burn_cards",
".",
"is_a?",
"(",
"Card",
")",
"||",
"burn_cards",
".",
"is_a?",
"(",
"String",
")",
"burn_cards",
"=",
"[",
"burn_cards",
"]",
"end",
"burn_cards",
".",
"map!",
"do",
"|",
"c",
"|",
"c",
"=",
"Card",
".",
"new",
"(",
"c",
")",
"unless",
"c",
".",
"class",
"==",
"Card",
"@cards",
".",
"delete",
"(",
"c",
")",
"end",
"true",
"end"
] |
delete an array or a single card from the deck
converts a string to a new card, if a string is given
|
[
"delete",
"an",
"array",
"or",
"a",
"single",
"card",
"from",
"the",
"deck",
"converts",
"a",
"string",
"to",
"a",
"new",
"card",
"if",
"a",
"string",
"is",
"given"
] |
e0745c476de2c4bd50896433be24791420760e26
|
https://github.com/evanrolfe/ruby-holdem/blob/e0745c476de2c4bd50896433be24791420760e26/lib/ruby_holdem/deck.rb#L29-L40
|
7,664 |
robotex82/itsf_backend
|
app/concerns/routing/itsf_backend_resource_concern.rb
|
Routing.ItsfBackendResourceConcern.backend_resources
|
def backend_resources(*args, &block)
resources(*args, &block)
# additional_member_actions = (Itsf::Backend::Configuration.default_resource_pages - [:show])
# if additional_member_actions.any?
# resources_name = args.first
# resources resources_name, only: [] do
# member do
# additional_member_actions.each do |action|
# get action
# end
# end
# end
# end
additional_resource_route_blocks = Itsf::Backend::Configuration.additional_resource_route_blocks
if additional_resource_route_blocks.any?
resources_name = args.first
additional_resource_route_blocks.each do |route_block|
resources resources_name, only: [] do
route_block.call(self)
end
end
end
end
|
ruby
|
def backend_resources(*args, &block)
resources(*args, &block)
# additional_member_actions = (Itsf::Backend::Configuration.default_resource_pages - [:show])
# if additional_member_actions.any?
# resources_name = args.first
# resources resources_name, only: [] do
# member do
# additional_member_actions.each do |action|
# get action
# end
# end
# end
# end
additional_resource_route_blocks = Itsf::Backend::Configuration.additional_resource_route_blocks
if additional_resource_route_blocks.any?
resources_name = args.first
additional_resource_route_blocks.each do |route_block|
resources resources_name, only: [] do
route_block.call(self)
end
end
end
end
|
[
"def",
"backend_resources",
"(",
"*",
"args",
",",
"&",
"block",
")",
"resources",
"(",
"args",
",",
"block",
")",
"# additional_member_actions = (Itsf::Backend::Configuration.default_resource_pages - [:show])",
"# if additional_member_actions.any?",
"# resources_name = args.first",
"# resources resources_name, only: [] do",
"# member do",
"# additional_member_actions.each do |action|",
"# get action",
"# end",
"# end",
"# end",
"# end",
"additional_resource_route_blocks",
"=",
"Itsf",
"::",
"Backend",
"::",
"Configuration",
".",
"additional_resource_route_blocks",
"if",
"additional_resource_route_blocks",
".",
"any?",
"resources_name",
"=",
"args",
".",
"first",
"additional_resource_route_blocks",
".",
"each",
"do",
"|",
"route_block",
"|",
"resources",
"resources_name",
",",
"only",
":",
"[",
"]",
"do",
"route_block",
".",
"call",
"(",
"self",
")",
"end",
"end",
"end",
"end"
] |
Using this method instead of resources, adds member routes for pages added in the
itsf_backend configuration.
|
[
"Using",
"this",
"method",
"instead",
"of",
"resources",
"adds",
"member",
"routes",
"for",
"pages",
"added",
"in",
"the",
"itsf_backend",
"configuration",
"."
] |
24a531e204b1c3de173edeb1bb7cd3d9cdfae412
|
https://github.com/robotex82/itsf_backend/blob/24a531e204b1c3de173edeb1bb7cd3d9cdfae412/app/concerns/routing/itsf_backend_resource_concern.rb#L7-L32
|
7,665 |
hubertlepicki/apidocs
|
lib/apidocs.rb
|
Apidocs.ApiDocs.generate_html
|
def generate_html
FileUtils.rm_rf(Rails.root.join('tmp/apidocs'))
options = [Rails.root.join("app/controllers").to_s, "--op=#{Rails.root.join('tmp/apidocs')}"]
self.store = RDoc::Store.new
@options = load_options
@options.parse options
@exclude = @options.exclude
@last_modified = setup_output_dir @options.op_dir, @options.force_update
@store.encoding = @options.encoding if @options.respond_to? :encoding
@store.dry_run = @options.dry_run
@store.main = @options.main_page
@store.title = @options.title
@store.path = @options.op_dir
@start_time = Time.now
@store.load_cache
@options.default_title = "RDoc Documentation"
parse_files @options.files
@store.complete @options.visibility
formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new)
routes = routes_by_regex.map do |r|
{verb: r[:verb],
path: r[:path].sub('(.:format)', ''),
class_name: gen_class_name(r),
action_name: gen_action_name(r)
}
end.each do |r|
doc = document_route(r)
r[:html_comment] = doc ? doc.accept(formatter) : ""
end.select { |r| r[:class_name] != "ApidocsController" }
puts routes.inspect
routes
end
|
ruby
|
def generate_html
FileUtils.rm_rf(Rails.root.join('tmp/apidocs'))
options = [Rails.root.join("app/controllers").to_s, "--op=#{Rails.root.join('tmp/apidocs')}"]
self.store = RDoc::Store.new
@options = load_options
@options.parse options
@exclude = @options.exclude
@last_modified = setup_output_dir @options.op_dir, @options.force_update
@store.encoding = @options.encoding if @options.respond_to? :encoding
@store.dry_run = @options.dry_run
@store.main = @options.main_page
@store.title = @options.title
@store.path = @options.op_dir
@start_time = Time.now
@store.load_cache
@options.default_title = "RDoc Documentation"
parse_files @options.files
@store.complete @options.visibility
formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new)
routes = routes_by_regex.map do |r|
{verb: r[:verb],
path: r[:path].sub('(.:format)', ''),
class_name: gen_class_name(r),
action_name: gen_action_name(r)
}
end.each do |r|
doc = document_route(r)
r[:html_comment] = doc ? doc.accept(formatter) : ""
end.select { |r| r[:class_name] != "ApidocsController" }
puts routes.inspect
routes
end
|
[
"def",
"generate_html",
"FileUtils",
".",
"rm_rf",
"(",
"Rails",
".",
"root",
".",
"join",
"(",
"'tmp/apidocs'",
")",
")",
"options",
"=",
"[",
"Rails",
".",
"root",
".",
"join",
"(",
"\"app/controllers\"",
")",
".",
"to_s",
",",
"\"--op=#{Rails.root.join('tmp/apidocs')}\"",
"]",
"self",
".",
"store",
"=",
"RDoc",
"::",
"Store",
".",
"new",
"@options",
"=",
"load_options",
"@options",
".",
"parse",
"options",
"@exclude",
"=",
"@options",
".",
"exclude",
"@last_modified",
"=",
"setup_output_dir",
"@options",
".",
"op_dir",
",",
"@options",
".",
"force_update",
"@store",
".",
"encoding",
"=",
"@options",
".",
"encoding",
"if",
"@options",
".",
"respond_to?",
":encoding",
"@store",
".",
"dry_run",
"=",
"@options",
".",
"dry_run",
"@store",
".",
"main",
"=",
"@options",
".",
"main_page",
"@store",
".",
"title",
"=",
"@options",
".",
"title",
"@store",
".",
"path",
"=",
"@options",
".",
"op_dir",
"@start_time",
"=",
"Time",
".",
"now",
"@store",
".",
"load_cache",
"@options",
".",
"default_title",
"=",
"\"RDoc Documentation\"",
"parse_files",
"@options",
".",
"files",
"@store",
".",
"complete",
"@options",
".",
"visibility",
"formatter",
"=",
"RDoc",
"::",
"Markup",
"::",
"ToHtml",
".",
"new",
"(",
"RDoc",
"::",
"Options",
".",
"new",
")",
"routes",
"=",
"routes_by_regex",
".",
"map",
"do",
"|",
"r",
"|",
"{",
"verb",
":",
"r",
"[",
":verb",
"]",
",",
"path",
":",
"r",
"[",
":path",
"]",
".",
"sub",
"(",
"'(.:format)'",
",",
"''",
")",
",",
"class_name",
":",
"gen_class_name",
"(",
"r",
")",
",",
"action_name",
":",
"gen_action_name",
"(",
"r",
")",
"}",
"end",
".",
"each",
"do",
"|",
"r",
"|",
"doc",
"=",
"document_route",
"(",
"r",
")",
"r",
"[",
":html_comment",
"]",
"=",
"doc",
"?",
"doc",
".",
"accept",
"(",
"formatter",
")",
":",
"\"\"",
"end",
".",
"select",
"{",
"|",
"r",
"|",
"r",
"[",
":class_name",
"]",
"!=",
"\"ApidocsController\"",
"}",
"puts",
"routes",
".",
"inspect",
"routes",
"end"
] |
generate_html entry point for on fly document generation
|
[
"generate_html",
"entry",
"point",
"for",
"on",
"fly",
"document",
"generation"
] |
d8650776243fed5b64a5e14518eb7345cedf7ca2
|
https://github.com/hubertlepicki/apidocs/blob/d8650776243fed5b64a5e14518eb7345cedf7ca2/lib/apidocs.rb#L14-L54
|
7,666 |
marcmo/cxxproject
|
lib/cxxproject/buildingblocks/has_sources_mixin.rb
|
Cxxproject.HasSources.collect_sources_and_toolchains
|
def collect_sources_and_toolchains
sources_to_build = {}
exclude_files = Set.new
exclude_sources.each do |p|
if p.include?("..")
Printer.printError "Error: Exclude source file pattern '#{p}' must not include '..'"
return nil
end
Dir.glob(p).each {|f| exclude_files << f}
end
files = Set.new # do not build the same file twice
add_to_sources_to_build(sources_to_build, exclude_files, sources)
source_patterns.each do |p|
if p.include?("..")
Printer.printError "Error: Source file pattern '#{p}' must not include '..'"
return nil
end
globRes = Dir.glob(p)
if (globRes.length == 0)
Printer.printWarning "Warning: Source file pattern '#{p}' did not match to any file"
end
add_to_sources_to_build(sources_to_build, exclude_files, globRes, tcs4source(p))
end
return sources_to_build
end
|
ruby
|
def collect_sources_and_toolchains
sources_to_build = {}
exclude_files = Set.new
exclude_sources.each do |p|
if p.include?("..")
Printer.printError "Error: Exclude source file pattern '#{p}' must not include '..'"
return nil
end
Dir.glob(p).each {|f| exclude_files << f}
end
files = Set.new # do not build the same file twice
add_to_sources_to_build(sources_to_build, exclude_files, sources)
source_patterns.each do |p|
if p.include?("..")
Printer.printError "Error: Source file pattern '#{p}' must not include '..'"
return nil
end
globRes = Dir.glob(p)
if (globRes.length == 0)
Printer.printWarning "Warning: Source file pattern '#{p}' did not match to any file"
end
add_to_sources_to_build(sources_to_build, exclude_files, globRes, tcs4source(p))
end
return sources_to_build
end
|
[
"def",
"collect_sources_and_toolchains",
"sources_to_build",
"=",
"{",
"}",
"exclude_files",
"=",
"Set",
".",
"new",
"exclude_sources",
".",
"each",
"do",
"|",
"p",
"|",
"if",
"p",
".",
"include?",
"(",
"\"..\"",
")",
"Printer",
".",
"printError",
"\"Error: Exclude source file pattern '#{p}' must not include '..'\"",
"return",
"nil",
"end",
"Dir",
".",
"glob",
"(",
"p",
")",
".",
"each",
"{",
"|",
"f",
"|",
"exclude_files",
"<<",
"f",
"}",
"end",
"files",
"=",
"Set",
".",
"new",
"# do not build the same file twice",
"add_to_sources_to_build",
"(",
"sources_to_build",
",",
"exclude_files",
",",
"sources",
")",
"source_patterns",
".",
"each",
"do",
"|",
"p",
"|",
"if",
"p",
".",
"include?",
"(",
"\"..\"",
")",
"Printer",
".",
"printError",
"\"Error: Source file pattern '#{p}' must not include '..'\"",
"return",
"nil",
"end",
"globRes",
"=",
"Dir",
".",
"glob",
"(",
"p",
")",
"if",
"(",
"globRes",
".",
"length",
"==",
"0",
")",
"Printer",
".",
"printWarning",
"\"Warning: Source file pattern '#{p}' did not match to any file\"",
"end",
"add_to_sources_to_build",
"(",
"sources_to_build",
",",
"exclude_files",
",",
"globRes",
",",
"tcs4source",
"(",
"p",
")",
")",
"end",
"return",
"sources_to_build",
"end"
] |
returns a hash from all sources to the toolchain that should be used for a source
|
[
"returns",
"a",
"hash",
"from",
"all",
"sources",
"to",
"the",
"toolchain",
"that",
"should",
"be",
"used",
"for",
"a",
"source"
] |
3740a09d6a143acd96bde3d2ff79055a6b810da4
|
https://github.com/marcmo/cxxproject/blob/3740a09d6a143acd96bde3d2ff79055a6b810da4/lib/cxxproject/buildingblocks/has_sources_mixin.rb#L193-L222
|
7,667 |
marcmo/cxxproject
|
lib/cxxproject/buildingblocks/has_sources_mixin.rb
|
Cxxproject.HasSources.calc_dirs_with_files
|
def calc_dirs_with_files(sources)
filemap = {}
sources.keys.sort.reverse.each do |o|
d = File.dirname(o)
if filemap.include?(d)
filemap[d] << o
else
filemap[d] = [o]
end
end
return filemap
end
|
ruby
|
def calc_dirs_with_files(sources)
filemap = {}
sources.keys.sort.reverse.each do |o|
d = File.dirname(o)
if filemap.include?(d)
filemap[d] << o
else
filemap[d] = [o]
end
end
return filemap
end
|
[
"def",
"calc_dirs_with_files",
"(",
"sources",
")",
"filemap",
"=",
"{",
"}",
"sources",
".",
"keys",
".",
"sort",
".",
"reverse",
".",
"each",
"do",
"|",
"o",
"|",
"d",
"=",
"File",
".",
"dirname",
"(",
"o",
")",
"if",
"filemap",
".",
"include?",
"(",
"d",
")",
"filemap",
"[",
"d",
"]",
"<<",
"o",
"else",
"filemap",
"[",
"d",
"]",
"=",
"[",
"o",
"]",
"end",
"end",
"return",
"filemap",
"end"
] |
calcs a map from unique directories to array of sources within this dir
|
[
"calcs",
"a",
"map",
"from",
"unique",
"directories",
"to",
"array",
"of",
"sources",
"within",
"this",
"dir"
] |
3740a09d6a143acd96bde3d2ff79055a6b810da4
|
https://github.com/marcmo/cxxproject/blob/3740a09d6a143acd96bde3d2ff79055a6b810da4/lib/cxxproject/buildingblocks/has_sources_mixin.rb#L225-L236
|
7,668 |
postmodern/rprogram
|
lib/rprogram/argument.rb
|
RProgram.Argument.arguments
|
def arguments(value)
value = case value
when Hash
value.map do |key,sub_value|
if sub_value == true then key.to_s
elsif sub_value then "#{key}=#{sub_value}"
end
end
when false, nil
[]
else
Array(value)
end
return value.compact
end
|
ruby
|
def arguments(value)
value = case value
when Hash
value.map do |key,sub_value|
if sub_value == true then key.to_s
elsif sub_value then "#{key}=#{sub_value}"
end
end
when false, nil
[]
else
Array(value)
end
return value.compact
end
|
[
"def",
"arguments",
"(",
"value",
")",
"value",
"=",
"case",
"value",
"when",
"Hash",
"value",
".",
"map",
"do",
"|",
"key",
",",
"sub_value",
"|",
"if",
"sub_value",
"==",
"true",
"then",
"key",
".",
"to_s",
"elsif",
"sub_value",
"then",
"\"#{key}=#{sub_value}\"",
"end",
"end",
"when",
"false",
",",
"nil",
"[",
"]",
"else",
"Array",
"(",
"value",
")",
"end",
"return",
"value",
".",
"compact",
"end"
] |
Formats a value into an Array of arguments.
@param [Hash, Array, String] value
The value to format.
@return [Array]
The formatted arguments.
|
[
"Formats",
"a",
"value",
"into",
"an",
"Array",
"of",
"arguments",
"."
] |
94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be
|
https://github.com/postmodern/rprogram/blob/94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be/lib/rprogram/argument.rb#L13-L28
|
7,669 |
locks/halibut
|
lib/halibut/core/relation_map.rb
|
Halibut::Core.RelationMap.add
|
def add(relation, item)
unless item.respond_to?(:to_hash)
raise ArgumentError.new('only items that can be converted to hashes with #to_hash are permitted')
end
@relations[relation] = @relations.fetch(relation, []) << item
end
|
ruby
|
def add(relation, item)
unless item.respond_to?(:to_hash)
raise ArgumentError.new('only items that can be converted to hashes with #to_hash are permitted')
end
@relations[relation] = @relations.fetch(relation, []) << item
end
|
[
"def",
"add",
"(",
"relation",
",",
"item",
")",
"unless",
"item",
".",
"respond_to?",
"(",
":to_hash",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"'only items that can be converted to hashes with #to_hash are permitted'",
")",
"end",
"@relations",
"[",
"relation",
"]",
"=",
"@relations",
".",
"fetch",
"(",
"relation",
",",
"[",
"]",
")",
"<<",
"item",
"end"
] |
Adds an object to a relation.
@example
relations = RelationMap.new
relations.add 'self', Link.new('/resource/1')
relations['self']
# => [#<Halibut::Core::Link:0x007fa0ca5b92b8 @href=\"/resource/1\",
@options=#<Halibut::Core::Link::Options:0x007fa0ca5b9240
@templated=nil, @type=nil, @name=nil, @profile=nil,
@title=nil, @hreflang=nil>>]
@param [String] relation relation that the object belongs to
@param [Object] item the object to add to the relation
|
[
"Adds",
"an",
"object",
"to",
"a",
"relation",
"."
] |
b8da6aa0796c9db317b9cd3d377915499a52383c
|
https://github.com/locks/halibut/blob/b8da6aa0796c9db317b9cd3d377915499a52383c/lib/halibut/core/relation_map.rb#L31-L37
|
7,670 |
locks/halibut
|
lib/halibut/core/relation_map.rb
|
Halibut::Core.RelationMap.to_hash
|
def to_hash
@relations.each_with_object({}) do |(rel,val), obj|
rel = rel.to_s
hashed_val = val.map(&:to_hash)
if val.length == 1 && !single_item_arrays?
hashed_val = val.first.to_hash
end
obj[rel] = hashed_val
end
end
|
ruby
|
def to_hash
@relations.each_with_object({}) do |(rel,val), obj|
rel = rel.to_s
hashed_val = val.map(&:to_hash)
if val.length == 1 && !single_item_arrays?
hashed_val = val.first.to_hash
end
obj[rel] = hashed_val
end
end
|
[
"def",
"to_hash",
"@relations",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"rel",
",",
"val",
")",
",",
"obj",
"|",
"rel",
"=",
"rel",
".",
"to_s",
"hashed_val",
"=",
"val",
".",
"map",
"(",
":to_hash",
")",
"if",
"val",
".",
"length",
"==",
"1",
"&&",
"!",
"single_item_arrays?",
"hashed_val",
"=",
"val",
".",
"first",
".",
"to_hash",
"end",
"obj",
"[",
"rel",
"]",
"=",
"hashed_val",
"end",
"end"
] |
Returns a hash corresponding to the object.
RelationMap doens't just return @relations because it needs to convert
correctly when a relation only has a single item.
@return [Hash] relation map in hash format
|
[
"Returns",
"a",
"hash",
"corresponding",
"to",
"the",
"object",
"."
] |
b8da6aa0796c9db317b9cd3d377915499a52383c
|
https://github.com/locks/halibut/blob/b8da6aa0796c9db317b9cd3d377915499a52383c/lib/halibut/core/relation_map.rb#L45-L56
|
7,671 |
anthonator/dirigible
|
lib/dirigible/request.rb
|
Dirigible.Request.request
|
def request(method, path, options, headers)
headers.merge!({
'User-Agent' => user_agent,
'Accept' => 'application/vnd.urbanairship+json; version=3;',
})
response = connection.send(method) do |request|
request.url("#{endpoint}#{path}/")
if [:post, :put].member?(method)
request.body = options.to_json
else
request.params.merge!(options)
end
request.headers.merge!(headers)
end
Utils.handle_api_error(response) unless (200..399).include?(response.status)
Utils.parse_message(response)
end
|
ruby
|
def request(method, path, options, headers)
headers.merge!({
'User-Agent' => user_agent,
'Accept' => 'application/vnd.urbanairship+json; version=3;',
})
response = connection.send(method) do |request|
request.url("#{endpoint}#{path}/")
if [:post, :put].member?(method)
request.body = options.to_json
else
request.params.merge!(options)
end
request.headers.merge!(headers)
end
Utils.handle_api_error(response) unless (200..399).include?(response.status)
Utils.parse_message(response)
end
|
[
"def",
"request",
"(",
"method",
",",
"path",
",",
"options",
",",
"headers",
")",
"headers",
".",
"merge!",
"(",
"{",
"'User-Agent'",
"=>",
"user_agent",
",",
"'Accept'",
"=>",
"'application/vnd.urbanairship+json; version=3;'",
",",
"}",
")",
"response",
"=",
"connection",
".",
"send",
"(",
"method",
")",
"do",
"|",
"request",
"|",
"request",
".",
"url",
"(",
"\"#{endpoint}#{path}/\"",
")",
"if",
"[",
":post",
",",
":put",
"]",
".",
"member?",
"(",
"method",
")",
"request",
".",
"body",
"=",
"options",
".",
"to_json",
"else",
"request",
".",
"params",
".",
"merge!",
"(",
"options",
")",
"end",
"request",
".",
"headers",
".",
"merge!",
"(",
"headers",
")",
"end",
"Utils",
".",
"handle_api_error",
"(",
"response",
")",
"unless",
"(",
"200",
"..",
"399",
")",
".",
"include?",
"(",
"response",
".",
"status",
")",
"Utils",
".",
"parse_message",
"(",
"response",
")",
"end"
] |
Perform an HTTP request.
|
[
"Perform",
"an",
"HTTP",
"request",
"."
] |
829b265ae4e54e3d4b284900b2a51a707afb6105
|
https://github.com/anthonator/dirigible/blob/829b265ae4e54e3d4b284900b2a51a707afb6105/lib/dirigible/request.rb#L21-L42
|
7,672 |
alecguintu/mongoid_follow
|
lib/mongoid_follow/follower.rb
|
Mongoid.Follower.follow
|
def follow(model)
if self.id != model.id && !self.follows?(model)
model.before_followed_by(self) if model.respond_to?('before_followed_by')
model.followers.create!(:ff_type => self.class.name, :ff_id => self.id)
model.inc(:fferc, 1)
model.after_followed_by(self) if model.respond_to?('after_followed_by')
self.before_follow(model) if self.respond_to?('before_follow')
self.followees.create!(:ff_type => model.class.name, :ff_id => model.id)
self.inc(:ffeec, 1)
self.after_follow(model) if self.respond_to?('after_follow')
else
return false
end
end
|
ruby
|
def follow(model)
if self.id != model.id && !self.follows?(model)
model.before_followed_by(self) if model.respond_to?('before_followed_by')
model.followers.create!(:ff_type => self.class.name, :ff_id => self.id)
model.inc(:fferc, 1)
model.after_followed_by(self) if model.respond_to?('after_followed_by')
self.before_follow(model) if self.respond_to?('before_follow')
self.followees.create!(:ff_type => model.class.name, :ff_id => model.id)
self.inc(:ffeec, 1)
self.after_follow(model) if self.respond_to?('after_follow')
else
return false
end
end
|
[
"def",
"follow",
"(",
"model",
")",
"if",
"self",
".",
"id",
"!=",
"model",
".",
"id",
"&&",
"!",
"self",
".",
"follows?",
"(",
"model",
")",
"model",
".",
"before_followed_by",
"(",
"self",
")",
"if",
"model",
".",
"respond_to?",
"(",
"'before_followed_by'",
")",
"model",
".",
"followers",
".",
"create!",
"(",
":ff_type",
"=>",
"self",
".",
"class",
".",
"name",
",",
":ff_id",
"=>",
"self",
".",
"id",
")",
"model",
".",
"inc",
"(",
":fferc",
",",
"1",
")",
"model",
".",
"after_followed_by",
"(",
"self",
")",
"if",
"model",
".",
"respond_to?",
"(",
"'after_followed_by'",
")",
"self",
".",
"before_follow",
"(",
"model",
")",
"if",
"self",
".",
"respond_to?",
"(",
"'before_follow'",
")",
"self",
".",
"followees",
".",
"create!",
"(",
":ff_type",
"=>",
"model",
".",
"class",
".",
"name",
",",
":ff_id",
"=>",
"model",
".",
"id",
")",
"self",
".",
"inc",
"(",
":ffeec",
",",
"1",
")",
"self",
".",
"after_follow",
"(",
"model",
")",
"if",
"self",
".",
"respond_to?",
"(",
"'after_follow'",
")",
"else",
"return",
"false",
"end",
"end"
] |
follow a model
Example:
=> @bonnie.follow(@clyde)
|
[
"follow",
"a",
"model"
] |
18573ccdf3e24bdae72a7e25f03dc25c27752545
|
https://github.com/alecguintu/mongoid_follow/blob/18573ccdf3e24bdae72a7e25f03dc25c27752545/lib/mongoid_follow/follower.rb#L14-L30
|
7,673 |
alecguintu/mongoid_follow
|
lib/mongoid_follow/follower.rb
|
Mongoid.Follower.unfollow
|
def unfollow(model)
if self.id != model.id && self.follows?(model)
model.before_unfollowed_by(self) if model.respond_to?('before_unfollowed_by')
model.followers.where(:ff_type => self.class.name, :ff_id => self.id).destroy
model.inc(:fferc, -1)
model.after_unfollowed_by(self) if model.respond_to?('after_unfollowed_by')
self.before_unfollow(model) if self.respond_to?('before_unfollow')
self.followees.where(:ff_type => model.class.name, :ff_id => model.id).destroy
self.inc(:ffeec, -1)
self.after_unfollow(model) if self.respond_to?('after_unfollow')
else
return false
end
end
|
ruby
|
def unfollow(model)
if self.id != model.id && self.follows?(model)
model.before_unfollowed_by(self) if model.respond_to?('before_unfollowed_by')
model.followers.where(:ff_type => self.class.name, :ff_id => self.id).destroy
model.inc(:fferc, -1)
model.after_unfollowed_by(self) if model.respond_to?('after_unfollowed_by')
self.before_unfollow(model) if self.respond_to?('before_unfollow')
self.followees.where(:ff_type => model.class.name, :ff_id => model.id).destroy
self.inc(:ffeec, -1)
self.after_unfollow(model) if self.respond_to?('after_unfollow')
else
return false
end
end
|
[
"def",
"unfollow",
"(",
"model",
")",
"if",
"self",
".",
"id",
"!=",
"model",
".",
"id",
"&&",
"self",
".",
"follows?",
"(",
"model",
")",
"model",
".",
"before_unfollowed_by",
"(",
"self",
")",
"if",
"model",
".",
"respond_to?",
"(",
"'before_unfollowed_by'",
")",
"model",
".",
"followers",
".",
"where",
"(",
":ff_type",
"=>",
"self",
".",
"class",
".",
"name",
",",
":ff_id",
"=>",
"self",
".",
"id",
")",
".",
"destroy",
"model",
".",
"inc",
"(",
":fferc",
",",
"-",
"1",
")",
"model",
".",
"after_unfollowed_by",
"(",
"self",
")",
"if",
"model",
".",
"respond_to?",
"(",
"'after_unfollowed_by'",
")",
"self",
".",
"before_unfollow",
"(",
"model",
")",
"if",
"self",
".",
"respond_to?",
"(",
"'before_unfollow'",
")",
"self",
".",
"followees",
".",
"where",
"(",
":ff_type",
"=>",
"model",
".",
"class",
".",
"name",
",",
":ff_id",
"=>",
"model",
".",
"id",
")",
".",
"destroy",
"self",
".",
"inc",
"(",
":ffeec",
",",
"-",
"1",
")",
"self",
".",
"after_unfollow",
"(",
"model",
")",
"if",
"self",
".",
"respond_to?",
"(",
"'after_unfollow'",
")",
"else",
"return",
"false",
"end",
"end"
] |
unfollow a model
Example:
=> @bonnie.unfollow(@clyde)
|
[
"unfollow",
"a",
"model"
] |
18573ccdf3e24bdae72a7e25f03dc25c27752545
|
https://github.com/alecguintu/mongoid_follow/blob/18573ccdf3e24bdae72a7e25f03dc25c27752545/lib/mongoid_follow/follower.rb#L36-L52
|
7,674 |
jaredbeck/template_params
|
lib/template_params/assertion.rb
|
TemplateParams.Assertion.assert_type
|
def assert_type(value)
unless @type.nil? || value.is_a?(@type) || allow_nil && value.nil?
raise TypeError, format("Expected %s, got %s", @type, value.class)
end
end
|
ruby
|
def assert_type(value)
unless @type.nil? || value.is_a?(@type) || allow_nil && value.nil?
raise TypeError, format("Expected %s, got %s", @type, value.class)
end
end
|
[
"def",
"assert_type",
"(",
"value",
")",
"unless",
"@type",
".",
"nil?",
"||",
"value",
".",
"is_a?",
"(",
"@type",
")",
"||",
"allow_nil",
"&&",
"value",
".",
"nil?",
"raise",
"TypeError",
",",
"format",
"(",
"\"Expected %s, got %s\"",
",",
"@type",
",",
"value",
".",
"class",
")",
"end",
"end"
] |
Raises a `TypeError` if `value` is not of `@type`.
@api private
|
[
"Raises",
"a",
"TypeError",
"if",
"value",
"is",
"not",
"of"
] |
32dba5caef32646f663bc46a7a44b55de225e76e
|
https://github.com/jaredbeck/template_params/blob/32dba5caef32646f663bc46a7a44b55de225e76e/lib/template_params/assertion.rb#L48-L52
|
7,675 |
birarda/logan
|
lib/logan/todolist.rb
|
Logan.TodoList.todo_with_substring
|
def todo_with_substring(substring)
issue_todo = @remaining_todos.detect{ |t| !t.content.index(substring).nil? }
issue_todo ||= @completed_todos.detect { |t| !t.content.index(substring).nil? }
end
|
ruby
|
def todo_with_substring(substring)
issue_todo = @remaining_todos.detect{ |t| !t.content.index(substring).nil? }
issue_todo ||= @completed_todos.detect { |t| !t.content.index(substring).nil? }
end
|
[
"def",
"todo_with_substring",
"(",
"substring",
")",
"issue_todo",
"=",
"@remaining_todos",
".",
"detect",
"{",
"|",
"t",
"|",
"!",
"t",
".",
"content",
".",
"index",
"(",
"substring",
")",
".",
"nil?",
"}",
"issue_todo",
"||=",
"@completed_todos",
".",
"detect",
"{",
"|",
"t",
"|",
"!",
"t",
".",
"content",
".",
"index",
"(",
"substring",
")",
".",
"nil?",
"}",
"end"
] |
searches the remaining and completed todos for the first todo with the substring in its content
@param [String] substring substring to look for
@return [Logan::Todo] the matched todo, or nil if there wasn't one
|
[
"searches",
"the",
"remaining",
"and",
"completed",
"todos",
"for",
"the",
"first",
"todo",
"with",
"the",
"substring",
"in",
"its",
"content"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/todolist.rb#L81-L84
|
7,676 |
birarda/logan
|
lib/logan/todolist.rb
|
Logan.TodoList.create_todo
|
def create_todo(todo)
post_params = {
:body => todo.post_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@project_id}/todolists/#{@id}/todos.json", post_params
Logan::Todo.new response
end
|
ruby
|
def create_todo(todo)
post_params = {
:body => todo.post_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@project_id}/todolists/#{@id}/todos.json", post_params
Logan::Todo.new response
end
|
[
"def",
"create_todo",
"(",
"todo",
")",
"post_params",
"=",
"{",
":body",
"=>",
"todo",
".",
"post_json",
",",
":headers",
"=>",
"Logan",
"::",
"Client",
".",
"headers",
".",
"merge",
"(",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"}",
"response",
"=",
"Logan",
"::",
"Client",
".",
"post",
"\"/projects/#{@project_id}/todolists/#{@id}/todos.json\"",
",",
"post_params",
"Logan",
"::",
"Todo",
".",
"new",
"response",
"end"
] |
create a todo in this todo list via the Basecamp API
@param [Logan::Todo] todo the todo instance to create in this todo lost
@return [Logan::Todo] the created todo returned from the Basecamp API
|
[
"create",
"a",
"todo",
"in",
"this",
"todo",
"list",
"via",
"the",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/todolist.rb#L90-L98
|
7,677 |
birarda/logan
|
lib/logan/todolist.rb
|
Logan.TodoList.update_todo
|
def update_todo(todo)
put_params = {
:body => todo.put_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.put "/projects/#{@project_id}/todos/#{todo.id}.json", put_params
Logan::Todo.new response
end
|
ruby
|
def update_todo(todo)
put_params = {
:body => todo.put_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.put "/projects/#{@project_id}/todos/#{todo.id}.json", put_params
Logan::Todo.new response
end
|
[
"def",
"update_todo",
"(",
"todo",
")",
"put_params",
"=",
"{",
":body",
"=>",
"todo",
".",
"put_json",
",",
":headers",
"=>",
"Logan",
"::",
"Client",
".",
"headers",
".",
"merge",
"(",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"}",
"response",
"=",
"Logan",
"::",
"Client",
".",
"put",
"\"/projects/#{@project_id}/todos/#{todo.id}.json\"",
",",
"put_params",
"Logan",
"::",
"Todo",
".",
"new",
"response",
"end"
] |
update a todo in this todo list via the Basecamp API
@param [Logan::Todo] todo the todo instance to update in this todo list
@return [Logan::Todo] the updated todo instance returned from the Basecamp API
|
[
"update",
"a",
"todo",
"in",
"this",
"todo",
"list",
"via",
"the",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/todolist.rb#L104-L112
|
7,678 |
boost/safety_cone
|
lib/safety_cone/filter.rb
|
SafetyCone.Filter.safety_cone_filter
|
def safety_cone_filter
if cone = fetch_cone
if cone.type == 'notice'
flash.now["safetycone_#{notice_type(cone.type)}"] = cone.message
else
flash["safetycone_#{notice_type(cone.type)}"] = cone.message
end
redirect_to safety_redirect if cone.type == 'block'
end
end
|
ruby
|
def safety_cone_filter
if cone = fetch_cone
if cone.type == 'notice'
flash.now["safetycone_#{notice_type(cone.type)}"] = cone.message
else
flash["safetycone_#{notice_type(cone.type)}"] = cone.message
end
redirect_to safety_redirect if cone.type == 'block'
end
end
|
[
"def",
"safety_cone_filter",
"if",
"cone",
"=",
"fetch_cone",
"if",
"cone",
".",
"type",
"==",
"'notice'",
"flash",
".",
"now",
"[",
"\"safetycone_#{notice_type(cone.type)}\"",
"]",
"=",
"cone",
".",
"message",
"else",
"flash",
"[",
"\"safetycone_#{notice_type(cone.type)}\"",
"]",
"=",
"cone",
".",
"message",
"end",
"redirect_to",
"safety_redirect",
"if",
"cone",
".",
"type",
"==",
"'block'",
"end",
"end"
] |
Filter method that does the SafetyCone action
based on the configuration.
|
[
"Filter",
"method",
"that",
"does",
"the",
"SafetyCone",
"action",
"based",
"on",
"the",
"configuration",
"."
] |
45dfcb0a9f9702386f8f0af8254c72cb5162b0cb
|
https://github.com/boost/safety_cone/blob/45dfcb0a9f9702386f8f0af8254c72cb5162b0cb/lib/safety_cone/filter.rb#L17-L27
|
7,679 |
boost/safety_cone
|
lib/safety_cone/filter.rb
|
SafetyCone.Filter.fetch_cone
|
def fetch_cone
paths = SafetyCone.paths
if path = paths[request_action]
key = request_action
elsif cone = paths[request_method]
key = request_method
else
return false
end
path = Path.new(key, path)
path.fetch
%w[notice block].include?(path.type) ? path : false
end
|
ruby
|
def fetch_cone
paths = SafetyCone.paths
if path = paths[request_action]
key = request_action
elsif cone = paths[request_method]
key = request_method
else
return false
end
path = Path.new(key, path)
path.fetch
%w[notice block].include?(path.type) ? path : false
end
|
[
"def",
"fetch_cone",
"paths",
"=",
"SafetyCone",
".",
"paths",
"if",
"path",
"=",
"paths",
"[",
"request_action",
"]",
"key",
"=",
"request_action",
"elsif",
"cone",
"=",
"paths",
"[",
"request_method",
"]",
"key",
"=",
"request_method",
"else",
"return",
"false",
"end",
"path",
"=",
"Path",
".",
"new",
"(",
"key",
",",
"path",
")",
"path",
".",
"fetch",
"%w[",
"notice",
"block",
"]",
".",
"include?",
"(",
"path",
".",
"type",
")",
"?",
"path",
":",
"false",
"end"
] |
Fetches a configuration based on current request
|
[
"Fetches",
"a",
"configuration",
"based",
"on",
"current",
"request"
] |
45dfcb0a9f9702386f8f0af8254c72cb5162b0cb
|
https://github.com/boost/safety_cone/blob/45dfcb0a9f9702386f8f0af8254c72cb5162b0cb/lib/safety_cone/filter.rb#L32-L47
|
7,680 |
holman/stars
|
lib/stars/client.rb
|
Stars.Client.star_loop
|
def star_loop
selection = ''
while true
puts "Type the number of the post that you want to learn about"
print " (or hit return to view all again, you ego-maniac) >> "
selection = $stdin.gets.chomp
break if ['','q','quit','exit','fuckthis'].include?(selection.downcase)
show(selection)
end
display if selection == ''
end
|
ruby
|
def star_loop
selection = ''
while true
puts "Type the number of the post that you want to learn about"
print " (or hit return to view all again, you ego-maniac) >> "
selection = $stdin.gets.chomp
break if ['','q','quit','exit','fuckthis'].include?(selection.downcase)
show(selection)
end
display if selection == ''
end
|
[
"def",
"star_loop",
"selection",
"=",
"''",
"while",
"true",
"puts",
"\"Type the number of the post that you want to learn about\"",
"print",
"\" (or hit return to view all again, you ego-maniac) >> \"",
"selection",
"=",
"$stdin",
".",
"gets",
".",
"chomp",
"break",
"if",
"[",
"''",
",",
"'q'",
",",
"'quit'",
",",
"'exit'",
",",
"'fuckthis'",
"]",
".",
"include?",
"(",
"selection",
".",
"downcase",
")",
"show",
"(",
"selection",
")",
"end",
"display",
"if",
"selection",
"==",
"''",
"end"
] |
Initializes a new Client.
Returns nothing.
Run a loop FOREVER until we kill it or we make a selection.
Returns nothing.
|
[
"Initializes",
"a",
"new",
"Client",
"."
] |
4c12a7d2fa935fe746d263aad5208ed0630c0b1e
|
https://github.com/holman/stars/blob/4c12a7d2fa935fe746d263aad5208ed0630c0b1e/lib/stars/client.rb#L28-L38
|
7,681 |
holman/stars
|
lib/stars/client.rb
|
Stars.Client.show
|
def show(id)
post = @posts[id.to_i-1]
return puts("\nMake a valid selection. Pretty please?\n") unless post
puts post.more
display
end
|
ruby
|
def show(id)
post = @posts[id.to_i-1]
return puts("\nMake a valid selection. Pretty please?\n") unless post
puts post.more
display
end
|
[
"def",
"show",
"(",
"id",
")",
"post",
"=",
"@posts",
"[",
"id",
".",
"to_i",
"-",
"1",
"]",
"return",
"puts",
"(",
"\"\\nMake a valid selection. Pretty please?\\n\"",
")",
"unless",
"post",
"puts",
"post",
".",
"more",
"display",
"end"
] |
Displays all of the star tables and information we have.
Returns nothing.
Show more information about a particular post.
id - the Integer id entered by the user, which we map to a Post
Returns nothing (although does delegate to the Post to show #more).
|
[
"Displays",
"all",
"of",
"the",
"star",
"tables",
"and",
"information",
"we",
"have",
"."
] |
4c12a7d2fa935fe746d263aad5208ed0630c0b1e
|
https://github.com/holman/stars/blob/4c12a7d2fa935fe746d263aad5208ed0630c0b1e/lib/stars/client.rb#L66-L71
|
7,682 |
holman/stars
|
lib/stars/client.rb
|
Stars.Client.print_posts
|
def print_posts(posts)
table do |t|
t.headings = headings
posts.each_with_index do |post,i|
t << [
{ :value => i+1, :alignment => :right },
post.service.capitalize,
{ :value => post.stars_count, :alignment => :center },
post.short_name
]
end
end
end
|
ruby
|
def print_posts(posts)
table do |t|
t.headings = headings
posts.each_with_index do |post,i|
t << [
{ :value => i+1, :alignment => :right },
post.service.capitalize,
{ :value => post.stars_count, :alignment => :center },
post.short_name
]
end
end
end
|
[
"def",
"print_posts",
"(",
"posts",
")",
"table",
"do",
"|",
"t",
"|",
"t",
".",
"headings",
"=",
"headings",
"posts",
".",
"each_with_index",
"do",
"|",
"post",
",",
"i",
"|",
"t",
"<<",
"[",
"{",
":value",
"=>",
"i",
"+",
"1",
",",
":alignment",
"=>",
":right",
"}",
",",
"post",
".",
"service",
".",
"capitalize",
",",
"{",
":value",
"=>",
"post",
".",
"stars_count",
",",
":alignment",
"=>",
":center",
"}",
",",
"post",
".",
"short_name",
"]",
"end",
"end",
"end"
] |
This does the actual printing of posts.
posts - an Array of Post objects
It loops through the Array of posts and sends them to `terminal-table`.
|
[
"This",
"does",
"the",
"actual",
"printing",
"of",
"posts",
"."
] |
4c12a7d2fa935fe746d263aad5208ed0630c0b1e
|
https://github.com/holman/stars/blob/4c12a7d2fa935fe746d263aad5208ed0630c0b1e/lib/stars/client.rb#L78-L90
|
7,683 |
thejonanshow/gatherer
|
lib/gatherer/card_parser.rb
|
Gatherer.CardParser.loyalty
|
def loyalty(parsed_text = extract_power_toughness)
if parsed_text && !parsed_text.include?('/')
parsed_text.to_i if parsed_text.to_i > 0
end
end
|
ruby
|
def loyalty(parsed_text = extract_power_toughness)
if parsed_text && !parsed_text.include?('/')
parsed_text.to_i if parsed_text.to_i > 0
end
end
|
[
"def",
"loyalty",
"(",
"parsed_text",
"=",
"extract_power_toughness",
")",
"if",
"parsed_text",
"&&",
"!",
"parsed_text",
".",
"include?",
"(",
"'/'",
")",
"parsed_text",
".",
"to_i",
"if",
"parsed_text",
".",
"to_i",
">",
"0",
"end",
"end"
] |
gatherer uses the pt row to display loyalty
|
[
"gatherer",
"uses",
"the",
"pt",
"row",
"to",
"display",
"loyalty"
] |
b14b7a2cdf4fe536631dd16b6bd45bccccc0e5b6
|
https://github.com/thejonanshow/gatherer/blob/b14b7a2cdf4fe536631dd16b6bd45bccccc0e5b6/lib/gatherer/card_parser.rb#L203-L207
|
7,684 |
KDEJewellers/aptly-api
|
lib/aptly/repository.rb
|
Aptly.Repository.add_file
|
def add_file(path, **kwords)
# Don't mangle query, the file API is inconsistently using camelCase
# rather than CamelCase.
response = connection.send(:post, "/repos/#{self.Name}/file/#{path}",
query: kwords,
query_mangle: false)
hash = JSON.parse(response.body)
error = Errors::RepositoryFileError.from_hash(hash)
raise error if error
hash['Report']['Added']
end
|
ruby
|
def add_file(path, **kwords)
# Don't mangle query, the file API is inconsistently using camelCase
# rather than CamelCase.
response = connection.send(:post, "/repos/#{self.Name}/file/#{path}",
query: kwords,
query_mangle: false)
hash = JSON.parse(response.body)
error = Errors::RepositoryFileError.from_hash(hash)
raise error if error
hash['Report']['Added']
end
|
[
"def",
"add_file",
"(",
"path",
",",
"**",
"kwords",
")",
"# Don't mangle query, the file API is inconsistently using camelCase",
"# rather than CamelCase.",
"response",
"=",
"connection",
".",
"send",
"(",
":post",
",",
"\"/repos/#{self.Name}/file/#{path}\"",
",",
"query",
":",
"kwords",
",",
"query_mangle",
":",
"false",
")",
"hash",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"error",
"=",
"Errors",
"::",
"RepositoryFileError",
".",
"from_hash",
"(",
"hash",
")",
"raise",
"error",
"if",
"error",
"hash",
"[",
"'Report'",
"]",
"[",
"'Added'",
"]",
"end"
] |
Add a previously uploaded file to the Repository.
@return [Hash] report data as specified in the API.
FIXME: this should be called file
|
[
"Add",
"a",
"previously",
"uploaded",
"file",
"to",
"the",
"Repository",
"."
] |
71a13417618d81ca0dcb7834559de1f31ec46e29
|
https://github.com/KDEJewellers/aptly-api/blob/71a13417618d81ca0dcb7834559de1f31ec46e29/lib/aptly/repository.rb#L43-L53
|
7,685 |
KDEJewellers/aptly-api
|
lib/aptly/repository.rb
|
Aptly.Repository.packages
|
def packages(**kwords)
response = connection.send(:get, "/repos/#{self.Name}/packages",
query: kwords,
query_mangle: false)
JSON.parse(response.body)
end
|
ruby
|
def packages(**kwords)
response = connection.send(:get, "/repos/#{self.Name}/packages",
query: kwords,
query_mangle: false)
JSON.parse(response.body)
end
|
[
"def",
"packages",
"(",
"**",
"kwords",
")",
"response",
"=",
"connection",
".",
"send",
"(",
":get",
",",
"\"/repos/#{self.Name}/packages\"",
",",
"query",
":",
"kwords",
",",
"query_mangle",
":",
"false",
")",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"end"
] |
List all packages in the repository
@return [Array<String>] list of packages in the repository
|
[
"List",
"all",
"packages",
"in",
"the",
"repository"
] |
71a13417618d81ca0dcb7834559de1f31ec46e29
|
https://github.com/KDEJewellers/aptly-api/blob/71a13417618d81ca0dcb7834559de1f31ec46e29/lib/aptly/repository.rb#L65-L70
|
7,686 |
KDEJewellers/aptly-api
|
lib/aptly/repository.rb
|
Aptly.Repository.edit!
|
def edit!(**kwords)
response = connection.send(:put,
"/repos/#{self.Name}",
body: JSON.generate(kwords))
hash = JSON.parse(response.body, symbolize_names: true)
return nil if hash == marshal_dump
marshal_load(hash)
self
end
|
ruby
|
def edit!(**kwords)
response = connection.send(:put,
"/repos/#{self.Name}",
body: JSON.generate(kwords))
hash = JSON.parse(response.body, symbolize_names: true)
return nil if hash == marshal_dump
marshal_load(hash)
self
end
|
[
"def",
"edit!",
"(",
"**",
"kwords",
")",
"response",
"=",
"connection",
".",
"send",
"(",
":put",
",",
"\"/repos/#{self.Name}\"",
",",
"body",
":",
"JSON",
".",
"generate",
"(",
"kwords",
")",
")",
"hash",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
",",
"symbolize_names",
":",
"true",
")",
"return",
"nil",
"if",
"hash",
"==",
"marshal_dump",
"marshal_load",
"(",
"hash",
")",
"self",
"end"
] |
Edit this repository's attributes as per the parameters.
@note this possibly mutates the attributes depending on the HTTP response
@return [self] if the instance data was mutated
@return [nil] if the instance data was not mutated
|
[
"Edit",
"this",
"repository",
"s",
"attributes",
"as",
"per",
"the",
"parameters",
"."
] |
71a13417618d81ca0dcb7834559de1f31ec46e29
|
https://github.com/KDEJewellers/aptly-api/blob/71a13417618d81ca0dcb7834559de1f31ec46e29/lib/aptly/repository.rb#L110-L118
|
7,687 |
boston-library/mei
|
lib/mei/loc.rb
|
Mei.Loc.parse_authority_response
|
def parse_authority_response
threaded_responses = []
#end_response = Array.new(20)
end_response = []
position_counter = 0
@raw_response.select {|response| response[0] == "atom:entry"}.map do |response|
threaded_responses << Thread.new(position_counter) { |local_pos|
end_response[local_pos] = loc_response_to_qa(response_to_struct(response), position_counter)
}
position_counter+=1
#sleep(0.05)
#loc_response_to_qa(response_to_struct(response))
end
threaded_responses.each { |thr| thr.join }
end_response
end
|
ruby
|
def parse_authority_response
threaded_responses = []
#end_response = Array.new(20)
end_response = []
position_counter = 0
@raw_response.select {|response| response[0] == "atom:entry"}.map do |response|
threaded_responses << Thread.new(position_counter) { |local_pos|
end_response[local_pos] = loc_response_to_qa(response_to_struct(response), position_counter)
}
position_counter+=1
#sleep(0.05)
#loc_response_to_qa(response_to_struct(response))
end
threaded_responses.each { |thr| thr.join }
end_response
end
|
[
"def",
"parse_authority_response",
"threaded_responses",
"=",
"[",
"]",
"#end_response = Array.new(20)",
"end_response",
"=",
"[",
"]",
"position_counter",
"=",
"0",
"@raw_response",
".",
"select",
"{",
"|",
"response",
"|",
"response",
"[",
"0",
"]",
"==",
"\"atom:entry\"",
"}",
".",
"map",
"do",
"|",
"response",
"|",
"threaded_responses",
"<<",
"Thread",
".",
"new",
"(",
"position_counter",
")",
"{",
"|",
"local_pos",
"|",
"end_response",
"[",
"local_pos",
"]",
"=",
"loc_response_to_qa",
"(",
"response_to_struct",
"(",
"response",
")",
",",
"position_counter",
")",
"}",
"position_counter",
"+=",
"1",
"#sleep(0.05)",
"#loc_response_to_qa(response_to_struct(response))",
"end",
"threaded_responses",
".",
"each",
"{",
"|",
"thr",
"|",
"thr",
".",
"join",
"}",
"end_response",
"end"
] |
Reformats the data received from the LOC service
|
[
"Reformats",
"the",
"data",
"received",
"from",
"the",
"LOC",
"service"
] |
57279df72a2f45d0fb79fd31c22f495b3a0ae290
|
https://github.com/boston-library/mei/blob/57279df72a2f45d0fb79fd31c22f495b3a0ae290/lib/mei/loc.rb#L63-L79
|
7,688 |
boston-library/mei
|
lib/mei/loc.rb
|
Mei.Loc.loc_response_to_qa
|
def loc_response_to_qa(data, counter)
json_link = data.links.select { |link| link.first == 'application/json' }
if json_link.present?
json_link = json_link[0][1]
broader, narrower, variants = get_skos_concepts(json_link.gsub('.json',''))
end
#count = ActiveFedora::Base.find_with_conditions("subject_tesim:#{data.id.gsub('info:lc', 'http://id.loc.gov').gsub(':','\:')}", rows: '100', fl: 'id' ).length
#FIXME
count = ActiveFedora::Base.search_with_conditions("#{@solr_field}:#{solr_clean(data.id.gsub('info:lc', 'http://id.loc.gov'))}", rows: '100', fl: 'id' ).length
#count = 0
if count >= 99
count = "99+"
else
count = count.to_s
end
{
"uri_link" => data.id.gsub('info:lc', 'http://id.loc.gov') || data.title,
"label" => data.title,
"broader" => broader,
"narrower" => narrower,
"variants" => variants,
"count" => count
}
end
|
ruby
|
def loc_response_to_qa(data, counter)
json_link = data.links.select { |link| link.first == 'application/json' }
if json_link.present?
json_link = json_link[0][1]
broader, narrower, variants = get_skos_concepts(json_link.gsub('.json',''))
end
#count = ActiveFedora::Base.find_with_conditions("subject_tesim:#{data.id.gsub('info:lc', 'http://id.loc.gov').gsub(':','\:')}", rows: '100', fl: 'id' ).length
#FIXME
count = ActiveFedora::Base.search_with_conditions("#{@solr_field}:#{solr_clean(data.id.gsub('info:lc', 'http://id.loc.gov'))}", rows: '100', fl: 'id' ).length
#count = 0
if count >= 99
count = "99+"
else
count = count.to_s
end
{
"uri_link" => data.id.gsub('info:lc', 'http://id.loc.gov') || data.title,
"label" => data.title,
"broader" => broader,
"narrower" => narrower,
"variants" => variants,
"count" => count
}
end
|
[
"def",
"loc_response_to_qa",
"(",
"data",
",",
"counter",
")",
"json_link",
"=",
"data",
".",
"links",
".",
"select",
"{",
"|",
"link",
"|",
"link",
".",
"first",
"==",
"'application/json'",
"}",
"if",
"json_link",
".",
"present?",
"json_link",
"=",
"json_link",
"[",
"0",
"]",
"[",
"1",
"]",
"broader",
",",
"narrower",
",",
"variants",
"=",
"get_skos_concepts",
"(",
"json_link",
".",
"gsub",
"(",
"'.json'",
",",
"''",
")",
")",
"end",
"#count = ActiveFedora::Base.find_with_conditions(\"subject_tesim:#{data.id.gsub('info:lc', 'http://id.loc.gov').gsub(':','\\:')}\", rows: '100', fl: 'id' ).length",
"#FIXME",
"count",
"=",
"ActiveFedora",
"::",
"Base",
".",
"search_with_conditions",
"(",
"\"#{@solr_field}:#{solr_clean(data.id.gsub('info:lc', 'http://id.loc.gov'))}\"",
",",
"rows",
":",
"'100'",
",",
"fl",
":",
"'id'",
")",
".",
"length",
"#count = 0",
"if",
"count",
">=",
"99",
"count",
"=",
"\"99+\"",
"else",
"count",
"=",
"count",
".",
"to_s",
"end",
"{",
"\"uri_link\"",
"=>",
"data",
".",
"id",
".",
"gsub",
"(",
"'info:lc'",
",",
"'http://id.loc.gov'",
")",
"||",
"data",
".",
"title",
",",
"\"label\"",
"=>",
"data",
".",
"title",
",",
"\"broader\"",
"=>",
"broader",
",",
"\"narrower\"",
"=>",
"narrower",
",",
"\"variants\"",
"=>",
"variants",
",",
"\"count\"",
"=>",
"count",
"}",
"end"
] |
Simple conversion from LoC-based struct to QA hash
|
[
"Simple",
"conversion",
"from",
"LoC",
"-",
"based",
"struct",
"to",
"QA",
"hash"
] |
57279df72a2f45d0fb79fd31c22f495b3a0ae290
|
https://github.com/boston-library/mei/blob/57279df72a2f45d0fb79fd31c22f495b3a0ae290/lib/mei/loc.rb#L82-L110
|
7,689 |
postmodern/pullr
|
lib/pullr/remote_repository.rb
|
Pullr.RemoteRepository.name
|
def name
dirs = File.expand_path(@uri.path).split(File::SEPARATOR)
unless dirs.empty?
if @scm == :sub_version
if dirs[-1] == 'trunk'
dirs.pop
elsif (dirs[-2] == 'branches' || dirs[-2] == 'tags')
dirs.pop
dirs.pop
end
elsif @scm == :git
dirs.last.chomp!('.git')
end
end
return (dirs.last || @uri.host)
end
|
ruby
|
def name
dirs = File.expand_path(@uri.path).split(File::SEPARATOR)
unless dirs.empty?
if @scm == :sub_version
if dirs[-1] == 'trunk'
dirs.pop
elsif (dirs[-2] == 'branches' || dirs[-2] == 'tags')
dirs.pop
dirs.pop
end
elsif @scm == :git
dirs.last.chomp!('.git')
end
end
return (dirs.last || @uri.host)
end
|
[
"def",
"name",
"dirs",
"=",
"File",
".",
"expand_path",
"(",
"@uri",
".",
"path",
")",
".",
"split",
"(",
"File",
"::",
"SEPARATOR",
")",
"unless",
"dirs",
".",
"empty?",
"if",
"@scm",
"==",
":sub_version",
"if",
"dirs",
"[",
"-",
"1",
"]",
"==",
"'trunk'",
"dirs",
".",
"pop",
"elsif",
"(",
"dirs",
"[",
"-",
"2",
"]",
"==",
"'branches'",
"||",
"dirs",
"[",
"-",
"2",
"]",
"==",
"'tags'",
")",
"dirs",
".",
"pop",
"dirs",
".",
"pop",
"end",
"elsif",
"@scm",
"==",
":git",
"dirs",
".",
"last",
".",
"chomp!",
"(",
"'.git'",
")",
"end",
"end",
"return",
"(",
"dirs",
".",
"last",
"||",
"@uri",
".",
"host",
")",
"end"
] |
Initializes the remote repository.
@param [Hash] options
Options for the remote repository.
@option options [URI::Generic] :uri
The URI of the remote repository.
@option options [Symbol, String] :scm
The SCM used for the remote repository.
The name of the repository.
@return [String]
The remote repository name.
@since 0.1.2
|
[
"Initializes",
"the",
"remote",
"repository",
"."
] |
96993fdbf4765a75c539bdb3c4902373458093e7
|
https://github.com/postmodern/pullr/blob/96993fdbf4765a75c539bdb3c4902373458093e7/lib/pullr/remote_repository.rb#L48-L65
|
7,690 |
jeanlescure/hipster_sql_to_hbase
|
lib/executor.rb
|
HipsterSqlToHbase.Executor.execute
|
def execute(thrift_call_group,host_s=nil,port_n=nil,incr=false)
@@host = host_s if !host_s.nil?
@@port = port_n if !port_n.nil?
socket = Thrift::Socket.new(@@host, @@port)
transport = Thrift::BufferedTransport.new(socket)
transport.open
protocol = Thrift::BinaryProtocol.new(transport)
client = HBase::Client.new(protocol)
results = []
if incr
not_incr = true
c_row = 0
end
thrift_call_group.each do |thrift_call|
if incr
if not_incr
c_row = increment_table_row_index(thrift_call[:arguments][0],thrift_call_group.length,client)
not_incr = false
end
c_row += 1
thrift_call[:arguments][1] = c_row.to_s
end
results << client.send(thrift_call[:method],*thrift_call[:arguments])
end
results.flatten
end
|
ruby
|
def execute(thrift_call_group,host_s=nil,port_n=nil,incr=false)
@@host = host_s if !host_s.nil?
@@port = port_n if !port_n.nil?
socket = Thrift::Socket.new(@@host, @@port)
transport = Thrift::BufferedTransport.new(socket)
transport.open
protocol = Thrift::BinaryProtocol.new(transport)
client = HBase::Client.new(protocol)
results = []
if incr
not_incr = true
c_row = 0
end
thrift_call_group.each do |thrift_call|
if incr
if not_incr
c_row = increment_table_row_index(thrift_call[:arguments][0],thrift_call_group.length,client)
not_incr = false
end
c_row += 1
thrift_call[:arguments][1] = c_row.to_s
end
results << client.send(thrift_call[:method],*thrift_call[:arguments])
end
results.flatten
end
|
[
"def",
"execute",
"(",
"thrift_call_group",
",",
"host_s",
"=",
"nil",
",",
"port_n",
"=",
"nil",
",",
"incr",
"=",
"false",
")",
"@@host",
"=",
"host_s",
"if",
"!",
"host_s",
".",
"nil?",
"@@port",
"=",
"port_n",
"if",
"!",
"port_n",
".",
"nil?",
"socket",
"=",
"Thrift",
"::",
"Socket",
".",
"new",
"(",
"@@host",
",",
"@@port",
")",
"transport",
"=",
"Thrift",
"::",
"BufferedTransport",
".",
"new",
"(",
"socket",
")",
"transport",
".",
"open",
"protocol",
"=",
"Thrift",
"::",
"BinaryProtocol",
".",
"new",
"(",
"transport",
")",
"client",
"=",
"HBase",
"::",
"Client",
".",
"new",
"(",
"protocol",
")",
"results",
"=",
"[",
"]",
"if",
"incr",
"not_incr",
"=",
"true",
"c_row",
"=",
"0",
"end",
"thrift_call_group",
".",
"each",
"do",
"|",
"thrift_call",
"|",
"if",
"incr",
"if",
"not_incr",
"c_row",
"=",
"increment_table_row_index",
"(",
"thrift_call",
"[",
":arguments",
"]",
"[",
"0",
"]",
",",
"thrift_call_group",
".",
"length",
",",
"client",
")",
"not_incr",
"=",
"false",
"end",
"c_row",
"+=",
"1",
"thrift_call",
"[",
":arguments",
"]",
"[",
"1",
"]",
"=",
"c_row",
".",
"to_s",
"end",
"results",
"<<",
"client",
".",
"send",
"(",
"thrift_call",
"[",
":method",
"]",
",",
"thrift_call",
"[",
":arguments",
"]",
")",
"end",
"results",
".",
"flatten",
"end"
] |
Initialize a Thrift connection to the specified host and port
and execute the provided ThriftCallGroup object.
|
[
"Initialize",
"a",
"Thrift",
"connection",
"to",
"the",
"specified",
"host",
"and",
"port",
"and",
"execute",
"the",
"provided",
"ThriftCallGroup",
"object",
"."
] |
eb181f2f869606a8fd68e88bde0a485051f262b8
|
https://github.com/jeanlescure/hipster_sql_to_hbase/blob/eb181f2f869606a8fd68e88bde0a485051f262b8/lib/executor.rb#L52-L83
|
7,691 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.todolists
|
def todolists
active_response = Logan::Client.get "/projects/#{@id}/todolists.json"
lists_array = active_response.parsed_response.map do |h|
Logan::TodoList.new h.merge({ :project_id => @id })
end
end
|
ruby
|
def todolists
active_response = Logan::Client.get "/projects/#{@id}/todolists.json"
lists_array = active_response.parsed_response.map do |h|
Logan::TodoList.new h.merge({ :project_id => @id })
end
end
|
[
"def",
"todolists",
"active_response",
"=",
"Logan",
"::",
"Client",
".",
"get",
"\"/projects/#{@id}/todolists.json\"",
"lists_array",
"=",
"active_response",
".",
"parsed_response",
".",
"map",
"do",
"|",
"h",
"|",
"Logan",
"::",
"TodoList",
".",
"new",
"h",
".",
"merge",
"(",
"{",
":project_id",
"=>",
"@id",
"}",
")",
"end",
"end"
] |
get active todo lists for this project from Basecamp API
@return [Array<Logan::TodoList>] array of active todo lists for this project
|
[
"get",
"active",
"todo",
"lists",
"for",
"this",
"project",
"from",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L27-L32
|
7,692 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.publish
|
def publish
post_params = {
:body => {}.to_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/publish.json", post_params
end
|
ruby
|
def publish
post_params = {
:body => {}.to_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/publish.json", post_params
end
|
[
"def",
"publish",
"post_params",
"=",
"{",
":body",
"=>",
"{",
"}",
".",
"to_json",
",",
":headers",
"=>",
"Logan",
"::",
"Client",
".",
"headers",
".",
"merge",
"(",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"}",
"response",
"=",
"Logan",
"::",
"Client",
".",
"post",
"\"/projects/#{@id}/publish.json\"",
",",
"post_params",
"end"
] |
publish this project from Basecamp API
@return <Logan::Project> this project
|
[
"publish",
"this",
"project",
"from",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L37-L44
|
7,693 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.completed_todolists
|
def completed_todolists
completed_response = Logan::Client.get "/projects/#{@id}/todolists/completed.json"
lists_array = completed_response.parsed_response.map do |h|
Logan::TodoList.new h.merge({ :project_id => @id })
end
end
|
ruby
|
def completed_todolists
completed_response = Logan::Client.get "/projects/#{@id}/todolists/completed.json"
lists_array = completed_response.parsed_response.map do |h|
Logan::TodoList.new h.merge({ :project_id => @id })
end
end
|
[
"def",
"completed_todolists",
"completed_response",
"=",
"Logan",
"::",
"Client",
".",
"get",
"\"/projects/#{@id}/todolists/completed.json\"",
"lists_array",
"=",
"completed_response",
".",
"parsed_response",
".",
"map",
"do",
"|",
"h",
"|",
"Logan",
"::",
"TodoList",
".",
"new",
"h",
".",
"merge",
"(",
"{",
":project_id",
"=>",
"@id",
"}",
")",
"end",
"end"
] |
get completed todo lists for this project from Basecamp API
@return [Array<Logan::TodoList>] array of completed todo lists for this project
|
[
"get",
"completed",
"todo",
"lists",
"for",
"this",
"project",
"from",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L49-L54
|
7,694 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.todolist
|
def todolist(list_id)
response = Logan::Client.get "/projects/#{@id}/todolists/#{list_id}.json"
Logan::TodoList.new response.parsed_response.merge({ :project_id => @id })
end
|
ruby
|
def todolist(list_id)
response = Logan::Client.get "/projects/#{@id}/todolists/#{list_id}.json"
Logan::TodoList.new response.parsed_response.merge({ :project_id => @id })
end
|
[
"def",
"todolist",
"(",
"list_id",
")",
"response",
"=",
"Logan",
"::",
"Client",
".",
"get",
"\"/projects/#{@id}/todolists/#{list_id}.json\"",
"Logan",
"::",
"TodoList",
".",
"new",
"response",
".",
"parsed_response",
".",
"merge",
"(",
"{",
":project_id",
"=>",
"@id",
"}",
")",
"end"
] |
get an individual todo list for this project from Basecamp API
@param [String] list_id id for the todo list
@return [Logan::TodoList] todo list instance
|
[
"get",
"an",
"individual",
"todo",
"list",
"for",
"this",
"project",
"from",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L67-L70
|
7,695 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.create_todolist
|
def create_todolist(todo_list)
post_params = {
:body => todo_list.post_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/todolists.json", post_params
Logan::TodoList.new response.merge({ :project_id => @id })
end
|
ruby
|
def create_todolist(todo_list)
post_params = {
:body => todo_list.post_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/todolists.json", post_params
Logan::TodoList.new response.merge({ :project_id => @id })
end
|
[
"def",
"create_todolist",
"(",
"todo_list",
")",
"post_params",
"=",
"{",
":body",
"=>",
"todo_list",
".",
"post_json",
",",
":headers",
"=>",
"Logan",
"::",
"Client",
".",
"headers",
".",
"merge",
"(",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"}",
"response",
"=",
"Logan",
"::",
"Client",
".",
"post",
"\"/projects/#{@id}/todolists.json\"",
",",
"post_params",
"Logan",
"::",
"TodoList",
".",
"new",
"response",
".",
"merge",
"(",
"{",
":project_id",
"=>",
"@id",
"}",
")",
"end"
] |
create a todo list in this project via Basecamp API
@param [Logan::TodoList] todo_list todo list instance to be created
@return [Logan::TodoList] todo list instance from Basecamp API response
|
[
"create",
"a",
"todo",
"list",
"in",
"this",
"project",
"via",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L76-L84
|
7,696 |
birarda/logan
|
lib/logan/project.rb
|
Logan.Project.create_message
|
def create_message(subject, content, subscribers, private)
post_params = {
:body => {subject: subject, content: content, subscribers: subscribers, private: private}.to_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/messages.json", post_params
Logan::Project.new response
end
|
ruby
|
def create_message(subject, content, subscribers, private)
post_params = {
:body => {subject: subject, content: content, subscribers: subscribers, private: private}.to_json,
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
}
response = Logan::Client.post "/projects/#{@id}/messages.json", post_params
Logan::Project.new response
end
|
[
"def",
"create_message",
"(",
"subject",
",",
"content",
",",
"subscribers",
",",
"private",
")",
"post_params",
"=",
"{",
":body",
"=>",
"{",
"subject",
":",
"subject",
",",
"content",
":",
"content",
",",
"subscribers",
":",
"subscribers",
",",
"private",
":",
"private",
"}",
".",
"to_json",
",",
":headers",
"=>",
"Logan",
"::",
"Client",
".",
"headers",
".",
"merge",
"(",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"}",
"response",
"=",
"Logan",
"::",
"Client",
".",
"post",
"\"/projects/#{@id}/messages.json\"",
",",
"post_params",
"Logan",
"::",
"Project",
".",
"new",
"response",
"end"
] |
create a message via Basecamp API
@param [String] subject subject for the new message
@param [String] content content for the new message
@param [Array] subscribers array of subscriber ids for the new message
@param [Bool] private should the private flag be set for the new message
@return [Logan::Message] message instance from Basecamp API response
|
[
"create",
"a",
"message",
"via",
"Basecamp",
"API"
] |
c007081c7dbb5b98ef5312db78f84867c6075ab0
|
https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/project.rb#L134-L142
|
7,697 |
jarhart/rattler
|
lib/rattler/parsers/rule.rb
|
Rattler::Parsers.Rule.parse
|
def parse(scanner, rules, scope = ParserScope.empty)
catch(:rule_failed) do
return expr.parse(scanner, rules, scope)
end
false
end
|
ruby
|
def parse(scanner, rules, scope = ParserScope.empty)
catch(:rule_failed) do
return expr.parse(scanner, rules, scope)
end
false
end
|
[
"def",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
"=",
"ParserScope",
".",
"empty",
")",
"catch",
"(",
":rule_failed",
")",
"do",
"return",
"expr",
".",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
")",
"end",
"false",
"end"
] |
Parse using the rule body and on success return the result, on failure
return a false value.
@param (see Match#parse)
@return (see Match#parse)
|
[
"Parse",
"using",
"the",
"rule",
"body",
"and",
"on",
"success",
"return",
"the",
"result",
"on",
"failure",
"return",
"a",
"false",
"value",
"."
] |
8b4efde2a05e9e790955bb635d4a1a9615893719
|
https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/parsers/rule.rb#L26-L31
|
7,698 |
crashlog/crashlog
|
lib/crash_log/configuration.rb
|
CrashLog.Configuration.development_mode=
|
def development_mode=(flag)
self[:development_mode] = flag
self.level = Logger::DEBUG
if new_logger
new_logger.level = self.level if self.logger.respond_to?(:level=)
end
end
|
ruby
|
def development_mode=(flag)
self[:development_mode] = flag
self.level = Logger::DEBUG
if new_logger
new_logger.level = self.level if self.logger.respond_to?(:level=)
end
end
|
[
"def",
"development_mode",
"=",
"(",
"flag",
")",
"self",
"[",
":development_mode",
"]",
"=",
"flag",
"self",
".",
"level",
"=",
"Logger",
"::",
"DEBUG",
"if",
"new_logger",
"new_logger",
".",
"level",
"=",
"self",
".",
"level",
"if",
"self",
".",
"logger",
".",
"respond_to?",
"(",
":level=",
")",
"end",
"end"
] |
Helps to enable debug logging when in development mode
|
[
"Helps",
"to",
"enable",
"debug",
"logging",
"when",
"in",
"development",
"mode"
] |
a70a41b58ce53eb75b8ee0bed79ab421c7650ad4
|
https://github.com/crashlog/crashlog/blob/a70a41b58ce53eb75b8ee0bed79ab421c7650ad4/lib/crash_log/configuration.rb#L241-L247
|
7,699 |
Burgestrand/mellon
|
lib/mellon/keychain.rb
|
Mellon.Keychain.[]=
|
def []=(key, data)
info, _ = read(key)
info ||= {}
if data
write(key, data, info)
else
delete(key, info)
end
end
|
ruby
|
def []=(key, data)
info, _ = read(key)
info ||= {}
if data
write(key, data, info)
else
delete(key, info)
end
end
|
[
"def",
"[]=",
"(",
"key",
",",
"data",
")",
"info",
",",
"_",
"=",
"read",
"(",
"key",
")",
"info",
"||=",
"{",
"}",
"if",
"data",
"write",
"(",
"key",
",",
"data",
",",
"info",
")",
"else",
"delete",
"(",
"key",
",",
"info",
")",
"end",
"end"
] |
Write data to entry key, or updating existing one if it exists.
@param [String] key
@param [String] data
|
[
"Write",
"data",
"to",
"entry",
"key",
"or",
"updating",
"existing",
"one",
"if",
"it",
"exists",
"."
] |
4ded7e28fee192a777605e5f9dcd3b1bd05770ef
|
https://github.com/Burgestrand/mellon/blob/4ded7e28fee192a777605e5f9dcd3b1bd05770ef/lib/mellon/keychain.rb#L95-L104
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.