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
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,900 |
jgoizueta/numerals
|
lib/numerals/numeral.rb
|
Numerals.Numeral.approximate!
|
def approximate!(number_of_digits = nil)
if number_of_digits.nil?
if exact? && !repeating?
@repeat = nil
end
else
expand! number_of_digits
@digits.truncate! number_of_digits
@repeat = nil
end
self
end
|
ruby
|
def approximate!(number_of_digits = nil)
if number_of_digits.nil?
if exact? && !repeating?
@repeat = nil
end
else
expand! number_of_digits
@digits.truncate! number_of_digits
@repeat = nil
end
self
end
|
[
"def",
"approximate!",
"(",
"number_of_digits",
"=",
"nil",
")",
"if",
"number_of_digits",
".",
"nil?",
"if",
"exact?",
"&&",
"!",
"repeating?",
"@repeat",
"=",
"nil",
"end",
"else",
"expand!",
"number_of_digits",
"@digits",
".",
"truncate!",
"number_of_digits",
"@repeat",
"=",
"nil",
"end",
"self",
"end"
] |
Expand to the specified number of digits,
then truncate and remove repetitions.
If no number of digits is given, then it will be
converted to approximate numeral only if it is not
repeating.
|
[
"Expand",
"to",
"the",
"specified",
"number",
"of",
"digits",
"then",
"truncate",
"and",
"remove",
"repetitions",
".",
"If",
"no",
"number",
"of",
"digits",
"is",
"given",
"then",
"it",
"will",
"be",
"converted",
"to",
"approximate",
"numeral",
"only",
"if",
"it",
"is",
"not",
"repeating",
"."
] |
a195e75f689af926537f791441bf8d11590c99c0
|
https://github.com/jgoizueta/numerals/blob/a195e75f689af926537f791441bf8d11590c99c0/lib/numerals/numeral.rb#L632-L643
|
5,901 |
mova-rb/mova
|
lib/mova/scope.rb
|
Mova.Scope.flatten
|
def flatten(translations, current_scope = nil)
translations.each_with_object({}) do |(key, value), memo|
scope = current_scope ? join(current_scope, key) : key.to_s
if value.is_a?(Hash)
memo.merge!(flatten(value, scope))
else
memo[scope] = value
end
end
end
|
ruby
|
def flatten(translations, current_scope = nil)
translations.each_with_object({}) do |(key, value), memo|
scope = current_scope ? join(current_scope, key) : key.to_s
if value.is_a?(Hash)
memo.merge!(flatten(value, scope))
else
memo[scope] = value
end
end
end
|
[
"def",
"flatten",
"(",
"translations",
",",
"current_scope",
"=",
"nil",
")",
"translations",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"memo",
"|",
"scope",
"=",
"current_scope",
"?",
"join",
"(",
"current_scope",
",",
"key",
")",
":",
"key",
".",
"to_s",
"if",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"memo",
".",
"merge!",
"(",
"flatten",
"(",
"value",
",",
"scope",
")",
")",
"else",
"memo",
"[",
"scope",
"]",
"=",
"value",
"end",
"end",
"end"
] |
Recurrently flattens hash by converting its keys to fully scoped ones.
@return [Hash{String => String}]
@param translations [Hash{String/Symbol => String/Hash}] with multiple
roots allowed
@param current_scope for internal use
@example
Scope.flatten(en: {common: {hello: "hi"}}, de: {hello: "Hallo"}) #=>
{"en.common.hello" => "hi", "de.hello" => "Hallo"}
|
[
"Recurrently",
"flattens",
"hash",
"by",
"converting",
"its",
"keys",
"to",
"fully",
"scoped",
"ones",
"."
] |
27f981c1f29dc20e5d11068d9342088f0e6bb318
|
https://github.com/mova-rb/mova/blob/27f981c1f29dc20e5d11068d9342088f0e6bb318/lib/mova/scope.rb#L79-L88
|
5,902 |
mova-rb/mova
|
lib/mova/scope.rb
|
Mova.Scope.cross_join
|
def cross_join(locales, keys)
locales.flat_map do |locale|
keys.map { |key| join(locale, key) }
end
end
|
ruby
|
def cross_join(locales, keys)
locales.flat_map do |locale|
keys.map { |key| join(locale, key) }
end
end
|
[
"def",
"cross_join",
"(",
"locales",
",",
"keys",
")",
"locales",
".",
"flat_map",
"do",
"|",
"locale",
"|",
"keys",
".",
"map",
"{",
"|",
"key",
"|",
"join",
"(",
"locale",
",",
"key",
")",
"}",
"end",
"end"
] |
Combines each locale with all keys.
@return [Array<String>]
@param locales [Array<String, Symbol>]
@param keys [Array<String, Symbol>]
@example
Scope.cross_join([:de, :en], [:hello, :hi]) #=>
["de.hello", "de.hi", "en.hello", "en.hi"]
|
[
"Combines",
"each",
"locale",
"with",
"all",
"keys",
"."
] |
27f981c1f29dc20e5d11068d9342088f0e6bb318
|
https://github.com/mova-rb/mova/blob/27f981c1f29dc20e5d11068d9342088f0e6bb318/lib/mova/scope.rb#L99-L103
|
5,903 |
korczis/csv2psql
|
lib/csv2psql/analyzer/analyzer.rb
|
Csv2Psql.Analyzer.create_column
|
def create_column(data, column)
data[:columns][column] = {}
res = data[:columns][column]
analyzers.each do |analyzer|
analyzer_class = analyzer[:class]
res[analyzer[:name]] = {
class: analyzer_class.new,
results: create_results(analyzer_class)
}
end
res
end
|
ruby
|
def create_column(data, column)
data[:columns][column] = {}
res = data[:columns][column]
analyzers.each do |analyzer|
analyzer_class = analyzer[:class]
res[analyzer[:name]] = {
class: analyzer_class.new,
results: create_results(analyzer_class)
}
end
res
end
|
[
"def",
"create_column",
"(",
"data",
",",
"column",
")",
"data",
"[",
":columns",
"]",
"[",
"column",
"]",
"=",
"{",
"}",
"res",
"=",
"data",
"[",
":columns",
"]",
"[",
"column",
"]",
"analyzers",
".",
"each",
"do",
"|",
"analyzer",
"|",
"analyzer_class",
"=",
"analyzer",
"[",
":class",
"]",
"res",
"[",
"analyzer",
"[",
":name",
"]",
"]",
"=",
"{",
"class",
":",
"analyzer_class",
".",
"new",
",",
"results",
":",
"create_results",
"(",
"analyzer_class",
")",
"}",
"end",
"res",
"end"
] |
Create column analyzers
|
[
"Create",
"column",
"analyzers"
] |
dd1751516524b8218da229cd0587c4046e248133
|
https://github.com/korczis/csv2psql/blob/dd1751516524b8218da229cd0587c4046e248133/lib/csv2psql/analyzer/analyzer.rb#L64-L77
|
5,904 |
korczis/csv2psql
|
lib/csv2psql/analyzer/analyzer.rb
|
Csv2Psql.Analyzer.update_numeric_results
|
def update_numeric_results(ac, ar, val)
cval = ac.convert(val)
ar[:min] = cval if ar[:min].nil? || cval < ar[:min]
ar[:max] = cval if ar[:max].nil? || cval > ar[:max]
end
|
ruby
|
def update_numeric_results(ac, ar, val)
cval = ac.convert(val)
ar[:min] = cval if ar[:min].nil? || cval < ar[:min]
ar[:max] = cval if ar[:max].nil? || cval > ar[:max]
end
|
[
"def",
"update_numeric_results",
"(",
"ac",
",",
"ar",
",",
"val",
")",
"cval",
"=",
"ac",
".",
"convert",
"(",
"val",
")",
"ar",
"[",
":min",
"]",
"=",
"cval",
"if",
"ar",
"[",
":min",
"]",
".",
"nil?",
"||",
"cval",
"<",
"ar",
"[",
":min",
"]",
"ar",
"[",
":max",
"]",
"=",
"cval",
"if",
"ar",
"[",
":max",
"]",
".",
"nil?",
"||",
"cval",
">",
"ar",
"[",
":max",
"]",
"end"
] |
Update numeric results
@param ac analyzer class
@param ar analyzer results
@param val value to be analyzed
|
[
"Update",
"numeric",
"results"
] |
dd1751516524b8218da229cd0587c4046e248133
|
https://github.com/korczis/csv2psql/blob/dd1751516524b8218da229cd0587c4046e248133/lib/csv2psql/analyzer/analyzer.rb#L143-L147
|
5,905 |
Fingertips/peiji-san
|
lib/peiji_san/view_helper.rb
|
PeijiSan.ViewHelper.link_to_page
|
def link_to_page(page, paginated_set, options = {}, html_options = {})
page_parameter = peiji_san_option(:page_parameter, options)
# Sinatra/Rails differentiator
pageable_params = respond_to?(:controller) ? controller.params : self.params
url_options = (page == 1 ? pageable_params.except(page_parameter) : pageable_params.merge(page_parameter => page))
anchor = peiji_san_option(:anchor, options)
url_options[:anchor] = anchor if anchor
html_options[:class] = peiji_san_option(:current_class, options) if paginated_set.current_page?(page)
# Again a little fork here
normalized_url_options = if respond_to?(:controller) # Rails
url_for(url_options)
else # Sinatra
root_path = env['PATH_INFO'].blank? ? "/" : env["PATH_INFO"]
url_for(root_path, url_options)
end
link_to page, normalized_url_options, html_options
end
|
ruby
|
def link_to_page(page, paginated_set, options = {}, html_options = {})
page_parameter = peiji_san_option(:page_parameter, options)
# Sinatra/Rails differentiator
pageable_params = respond_to?(:controller) ? controller.params : self.params
url_options = (page == 1 ? pageable_params.except(page_parameter) : pageable_params.merge(page_parameter => page))
anchor = peiji_san_option(:anchor, options)
url_options[:anchor] = anchor if anchor
html_options[:class] = peiji_san_option(:current_class, options) if paginated_set.current_page?(page)
# Again a little fork here
normalized_url_options = if respond_to?(:controller) # Rails
url_for(url_options)
else # Sinatra
root_path = env['PATH_INFO'].blank? ? "/" : env["PATH_INFO"]
url_for(root_path, url_options)
end
link_to page, normalized_url_options, html_options
end
|
[
"def",
"link_to_page",
"(",
"page",
",",
"paginated_set",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
")",
"page_parameter",
"=",
"peiji_san_option",
"(",
":page_parameter",
",",
"options",
")",
"# Sinatra/Rails differentiator",
"pageable_params",
"=",
"respond_to?",
"(",
":controller",
")",
"?",
"controller",
".",
"params",
":",
"self",
".",
"params",
"url_options",
"=",
"(",
"page",
"==",
"1",
"?",
"pageable_params",
".",
"except",
"(",
"page_parameter",
")",
":",
"pageable_params",
".",
"merge",
"(",
"page_parameter",
"=>",
"page",
")",
")",
"anchor",
"=",
"peiji_san_option",
"(",
":anchor",
",",
"options",
")",
"url_options",
"[",
":anchor",
"]",
"=",
"anchor",
"if",
"anchor",
"html_options",
"[",
":class",
"]",
"=",
"peiji_san_option",
"(",
":current_class",
",",
"options",
")",
"if",
"paginated_set",
".",
"current_page?",
"(",
"page",
")",
"# Again a little fork here",
"normalized_url_options",
"=",
"if",
"respond_to?",
"(",
":controller",
")",
"# Rails",
"url_for",
"(",
"url_options",
")",
"else",
"# Sinatra",
"root_path",
"=",
"env",
"[",
"'PATH_INFO'",
"]",
".",
"blank?",
"?",
"\"/\"",
":",
"env",
"[",
"\"PATH_INFO\"",
"]",
"url_for",
"(",
"root_path",
",",
"url_options",
")",
"end",
"link_to",
"page",
",",
"normalized_url_options",
",",
"html_options",
"end"
] |
Creates a link using +link_to+ for a page in a pagination collection. If
the specified page is the current page then its class will be `current'.
Options:
[:page_parameter]
The name of the GET parameter used to indicate the page to display.
Defaults to <tt>:page</tt>.
[:current_class]
The CSS class name used when a page is the current page in a pagination
collection. Defaults to <tt>:current</tt>.
|
[
"Creates",
"a",
"link",
"using",
"+",
"link_to",
"+",
"for",
"a",
"page",
"in",
"a",
"pagination",
"collection",
".",
"If",
"the",
"specified",
"page",
"is",
"the",
"current",
"page",
"then",
"its",
"class",
"will",
"be",
"current",
"."
] |
6bd1bc7c152961dcde376a8bcb2ca393b5b45829
|
https://github.com/Fingertips/peiji-san/blob/6bd1bc7c152961dcde376a8bcb2ca393b5b45829/lib/peiji_san/view_helper.rb#L48-L68
|
5,906 |
Fingertips/peiji-san
|
lib/peiji_san/view_helper.rb
|
PeijiSan.ViewHelper.pages_to_link_to
|
def pages_to_link_to(paginated_set, options = {})
current, last = paginated_set.current_page, paginated_set.page_count
max = peiji_san_option(:max_visible, options)
separator = peiji_san_option(:separator, options)
if last <= max
(1..last).to_a
elsif current <= ((max / 2) + 1)
(1..(max - 2)).to_a + [separator, last]
elsif current >= (last - (max / 2))
[1, separator, *((last - (max - 3))..last)]
else
offset = (max - 4) / 2
[1, separator] + ((current - offset)..(current + offset)).to_a + [separator, last]
end
end
|
ruby
|
def pages_to_link_to(paginated_set, options = {})
current, last = paginated_set.current_page, paginated_set.page_count
max = peiji_san_option(:max_visible, options)
separator = peiji_san_option(:separator, options)
if last <= max
(1..last).to_a
elsif current <= ((max / 2) + 1)
(1..(max - 2)).to_a + [separator, last]
elsif current >= (last - (max / 2))
[1, separator, *((last - (max - 3))..last)]
else
offset = (max - 4) / 2
[1, separator] + ((current - offset)..(current + offset)).to_a + [separator, last]
end
end
|
[
"def",
"pages_to_link_to",
"(",
"paginated_set",
",",
"options",
"=",
"{",
"}",
")",
"current",
",",
"last",
"=",
"paginated_set",
".",
"current_page",
",",
"paginated_set",
".",
"page_count",
"max",
"=",
"peiji_san_option",
"(",
":max_visible",
",",
"options",
")",
"separator",
"=",
"peiji_san_option",
"(",
":separator",
",",
"options",
")",
"if",
"last",
"<=",
"max",
"(",
"1",
"..",
"last",
")",
".",
"to_a",
"elsif",
"current",
"<=",
"(",
"(",
"max",
"/",
"2",
")",
"+",
"1",
")",
"(",
"1",
"..",
"(",
"max",
"-",
"2",
")",
")",
".",
"to_a",
"+",
"[",
"separator",
",",
"last",
"]",
"elsif",
"current",
">=",
"(",
"last",
"-",
"(",
"max",
"/",
"2",
")",
")",
"[",
"1",
",",
"separator",
",",
"(",
"(",
"last",
"-",
"(",
"max",
"-",
"3",
")",
")",
"..",
"last",
")",
"]",
"else",
"offset",
"=",
"(",
"max",
"-",
"4",
")",
"/",
"2",
"[",
"1",
",",
"separator",
"]",
"+",
"(",
"(",
"current",
"-",
"offset",
")",
"..",
"(",
"current",
"+",
"offset",
")",
")",
".",
"to_a",
"+",
"[",
"separator",
",",
"last",
"]",
"end",
"end"
] |
Returns an array of pages to link to. This array includes the separator, so
make sure to keep this in mind when iterating over the array and creating
links.
For consistency’s sake, it is adviced to use an odd number for
<tt>:max_visible</tt>.
Options:
[:max_visible]
The maximum amount of elements in the array, this includes the
separator(s). Defaults to 11.
[:separator]
The separator string used to indicate a range between the first or last
page and the ones surrounding the current page.
collection = Model.all.page(40)
collection.page_count # => 80
pages_to_link_to(collection) # => [1, '…', 37, 38, 39, 40, 41, 42, 43, '…', 80]
|
[
"Returns",
"an",
"array",
"of",
"pages",
"to",
"link",
"to",
".",
"This",
"array",
"includes",
"the",
"separator",
"so",
"make",
"sure",
"to",
"keep",
"this",
"in",
"mind",
"when",
"iterating",
"over",
"the",
"array",
"and",
"creating",
"links",
"."
] |
6bd1bc7c152961dcde376a8bcb2ca393b5b45829
|
https://github.com/Fingertips/peiji-san/blob/6bd1bc7c152961dcde376a8bcb2ca393b5b45829/lib/peiji_san/view_helper.rb#L106-L121
|
5,907 |
gevans/expedition
|
lib/expedition/client.rb
|
Expedition.Client.devices
|
def devices
send(:devdetails) do |body|
body[:devdetails].collect { |attrs|
attrs.delete(:devdetails)
attrs[:variant] = attrs.delete(:name).downcase
attrs
}
end
end
|
ruby
|
def devices
send(:devdetails) do |body|
body[:devdetails].collect { |attrs|
attrs.delete(:devdetails)
attrs[:variant] = attrs.delete(:name).downcase
attrs
}
end
end
|
[
"def",
"devices",
"send",
"(",
":devdetails",
")",
"do",
"|",
"body",
"|",
"body",
"[",
":devdetails",
"]",
".",
"collect",
"{",
"|",
"attrs",
"|",
"attrs",
".",
"delete",
"(",
":devdetails",
")",
"attrs",
"[",
":variant",
"]",
"=",
"attrs",
".",
"delete",
"(",
":name",
")",
".",
"downcase",
"attrs",
"}",
"end",
"end"
] |
Initializes a new `Client` for executing commands.
@param [String] host
The host to connect to.
@param [Integer] port
The port to connect to.
Sends the `devdetails` command, returning an array of devices found in the
service's response.
@return [Response]
An array of devices.
|
[
"Initializes",
"a",
"new",
"Client",
"for",
"executing",
"commands",
"."
] |
a9ce897900002469ed57617d065a2bbdefd5ced5
|
https://github.com/gevans/expedition/blob/a9ce897900002469ed57617d065a2bbdefd5ced5/lib/expedition/client.rb#L38-L46
|
5,908 |
gevans/expedition
|
lib/expedition/client.rb
|
Expedition.Client.send
|
def send(command, *parameters, &block)
socket = TCPSocket.open(host, port)
socket.puts command_json(command, *parameters)
parse(socket.gets, &block)
ensure
socket.close if socket.respond_to?(:close)
end
|
ruby
|
def send(command, *parameters, &block)
socket = TCPSocket.open(host, port)
socket.puts command_json(command, *parameters)
parse(socket.gets, &block)
ensure
socket.close if socket.respond_to?(:close)
end
|
[
"def",
"send",
"(",
"command",
",",
"*",
"parameters",
",",
"&",
"block",
")",
"socket",
"=",
"TCPSocket",
".",
"open",
"(",
"host",
",",
"port",
")",
"socket",
".",
"puts",
"command_json",
"(",
"command",
",",
"parameters",
")",
"parse",
"(",
"socket",
".",
"gets",
",",
"block",
")",
"ensure",
"socket",
".",
"close",
"if",
"socket",
".",
"respond_to?",
"(",
":close",
")",
"end"
] |
Sends the supplied `command` with optionally supplied `parameters` to the
service and returns the result, if any.
**Note:** Since `Object#send` is overridden, use `Object#__send__` to call
an actual method.
@param [Symbol, String] command
The command to send to the service.
@param [Array] parameters
Optional parameters to send to the service.
@return [Response]
The service's response.
|
[
"Sends",
"the",
"supplied",
"command",
"with",
"optionally",
"supplied",
"parameters",
"to",
"the",
"service",
"and",
"returns",
"the",
"result",
"if",
"any",
"."
] |
a9ce897900002469ed57617d065a2bbdefd5ced5
|
https://github.com/gevans/expedition/blob/a9ce897900002469ed57617d065a2bbdefd5ced5/lib/expedition/client.rb#L87-L94
|
5,909 |
tatemae/muck-engine
|
lib/muck-engine/flash_errors.rb
|
MuckEngine.FlashErrors.output_errors
|
def output_errors(title, options = {}, fields = nil, flash_only = false)
fields = [fields] unless fields.is_a?(Array)
flash_html = render(:partial => 'shared/flash_messages')
flash.clear
css_class = "class=\"#{options[:class] || 'error'}\"" unless options[:class].nil?
field_errors = render(:partial => 'shared/field_error', :collection => fields)
if flash_only || (!flash_html.empty? && field_errors.empty?)
# Only flash. Don't render errors for any fields
render(:partial => 'shared/flash_error_box', :locals => {:flash_html => flash_html, :css_class => css_class})
elsif !field_errors.empty?
# Field errors and/or flash
render(:partial => 'shared/error_box', :locals => {:title => title,
:flash_html => flash_html,
:field_errors => field_errors,
:css_class => css_class,
:extra_html => options[:extra_html]})
else
#nothing
''
end
end
|
ruby
|
def output_errors(title, options = {}, fields = nil, flash_only = false)
fields = [fields] unless fields.is_a?(Array)
flash_html = render(:partial => 'shared/flash_messages')
flash.clear
css_class = "class=\"#{options[:class] || 'error'}\"" unless options[:class].nil?
field_errors = render(:partial => 'shared/field_error', :collection => fields)
if flash_only || (!flash_html.empty? && field_errors.empty?)
# Only flash. Don't render errors for any fields
render(:partial => 'shared/flash_error_box', :locals => {:flash_html => flash_html, :css_class => css_class})
elsif !field_errors.empty?
# Field errors and/or flash
render(:partial => 'shared/error_box', :locals => {:title => title,
:flash_html => flash_html,
:field_errors => field_errors,
:css_class => css_class,
:extra_html => options[:extra_html]})
else
#nothing
''
end
end
|
[
"def",
"output_errors",
"(",
"title",
",",
"options",
"=",
"{",
"}",
",",
"fields",
"=",
"nil",
",",
"flash_only",
"=",
"false",
")",
"fields",
"=",
"[",
"fields",
"]",
"unless",
"fields",
".",
"is_a?",
"(",
"Array",
")",
"flash_html",
"=",
"render",
"(",
":partial",
"=>",
"'shared/flash_messages'",
")",
"flash",
".",
"clear",
"css_class",
"=",
"\"class=\\\"#{options[:class] || 'error'}\\\"\"",
"unless",
"options",
"[",
":class",
"]",
".",
"nil?",
"field_errors",
"=",
"render",
"(",
":partial",
"=>",
"'shared/field_error'",
",",
":collection",
"=>",
"fields",
")",
"if",
"flash_only",
"||",
"(",
"!",
"flash_html",
".",
"empty?",
"&&",
"field_errors",
".",
"empty?",
")",
"# Only flash. Don't render errors for any fields",
"render",
"(",
":partial",
"=>",
"'shared/flash_error_box'",
",",
":locals",
"=>",
"{",
":flash_html",
"=>",
"flash_html",
",",
":css_class",
"=>",
"css_class",
"}",
")",
"elsif",
"!",
"field_errors",
".",
"empty?",
"# Field errors and/or flash",
"render",
"(",
":partial",
"=>",
"'shared/error_box'",
",",
":locals",
"=>",
"{",
":title",
"=>",
"title",
",",
":flash_html",
"=>",
"flash_html",
",",
":field_errors",
"=>",
"field_errors",
",",
":css_class",
"=>",
"css_class",
",",
":extra_html",
"=>",
"options",
"[",
":extra_html",
"]",
"}",
")",
"else",
"#nothing",
"''",
"end",
"end"
] |
Output flash and object errors
|
[
"Output",
"flash",
"and",
"object",
"errors"
] |
41fc072dce3a365b3ce4a73d4f60a4ff24026d51
|
https://github.com/tatemae/muck-engine/blob/41fc072dce3a365b3ce4a73d4f60a4ff24026d51/lib/muck-engine/flash_errors.rb#L10-L31
|
5,910 |
tatemae/muck-engine
|
lib/muck-engine/flash_errors.rb
|
MuckEngine.FlashErrors.output_admin_messages
|
def output_admin_messages(fields = nil, title = '', options = { :class => 'notify-box' }, flash_only = false)
output_errors_ajax('admin-messages', title, options, fields, flash_only)
end
|
ruby
|
def output_admin_messages(fields = nil, title = '', options = { :class => 'notify-box' }, flash_only = false)
output_errors_ajax('admin-messages', title, options, fields, flash_only)
end
|
[
"def",
"output_admin_messages",
"(",
"fields",
"=",
"nil",
",",
"title",
"=",
"''",
",",
"options",
"=",
"{",
":class",
"=>",
"'notify-box'",
"}",
",",
"flash_only",
"=",
"false",
")",
"output_errors_ajax",
"(",
"'admin-messages'",
",",
"title",
",",
"options",
",",
"fields",
",",
"flash_only",
")",
"end"
] |
Output a page update that will display messages in the flash
|
[
"Output",
"a",
"page",
"update",
"that",
"will",
"display",
"messages",
"in",
"the",
"flash"
] |
41fc072dce3a365b3ce4a73d4f60a4ff24026d51
|
https://github.com/tatemae/muck-engine/blob/41fc072dce3a365b3ce4a73d4f60a4ff24026d51/lib/muck-engine/flash_errors.rb#L42-L44
|
5,911 |
renz45/table_me
|
lib/table_me/table_pagination.rb
|
TableMe.TablePagination.pagination_number_list
|
def pagination_number_list
(0...page_button_count).to_a.map do |n|
link_number = n + page_number_offset
number_span(link_number)
end.join(' ')
end
|
ruby
|
def pagination_number_list
(0...page_button_count).to_a.map do |n|
link_number = n + page_number_offset
number_span(link_number)
end.join(' ')
end
|
[
"def",
"pagination_number_list",
"(",
"0",
"...",
"page_button_count",
")",
".",
"to_a",
".",
"map",
"do",
"|",
"n",
"|",
"link_number",
"=",
"n",
"+",
"page_number_offset",
"number_span",
"(",
"link_number",
")",
"end",
".",
"join",
"(",
"' '",
")",
"end"
] |
List of number links for the number range between next and previous
|
[
"List",
"of",
"number",
"links",
"for",
"the",
"number",
"range",
"between",
"next",
"and",
"previous"
] |
a04bd7c26497828b2f8f0178631253b6749025cf
|
https://github.com/renz45/table_me/blob/a04bd7c26497828b2f8f0178631253b6749025cf/lib/table_me/table_pagination.rb#L56-L61
|
5,912 |
riddopic/garcun
|
lib/garcon/task/copy_on_write_observer_set.rb
|
Garcon.CopyOnWriteObserverSet.add_observer
|
def add_observer(observer=nil, func=:update, &block)
if observer.nil? && block.nil?
raise ArgumentError, 'should pass observer as a first argument or block'
elsif observer && block
raise ArgumentError.new('cannot provide both an observer and a block')
end
if block
observer = block
func = :call
end
begin
@mutex.lock
new_observers = @observers.dup
new_observers[observer] = func
@observers = new_observers
observer
ensure
@mutex.unlock
end
end
|
ruby
|
def add_observer(observer=nil, func=:update, &block)
if observer.nil? && block.nil?
raise ArgumentError, 'should pass observer as a first argument or block'
elsif observer && block
raise ArgumentError.new('cannot provide both an observer and a block')
end
if block
observer = block
func = :call
end
begin
@mutex.lock
new_observers = @observers.dup
new_observers[observer] = func
@observers = new_observers
observer
ensure
@mutex.unlock
end
end
|
[
"def",
"add_observer",
"(",
"observer",
"=",
"nil",
",",
"func",
"=",
":update",
",",
"&",
"block",
")",
"if",
"observer",
".",
"nil?",
"&&",
"block",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'should pass observer as a first argument or block'",
"elsif",
"observer",
"&&",
"block",
"raise",
"ArgumentError",
".",
"new",
"(",
"'cannot provide both an observer and a block'",
")",
"end",
"if",
"block",
"observer",
"=",
"block",
"func",
"=",
":call",
"end",
"begin",
"@mutex",
".",
"lock",
"new_observers",
"=",
"@observers",
".",
"dup",
"new_observers",
"[",
"observer",
"]",
"=",
"func",
"@observers",
"=",
"new_observers",
"observer",
"ensure",
"@mutex",
".",
"unlock",
"end",
"end"
] |
Adds an observer to this set. If a block is passed, the observer will be
created by this method and no other params should be passed
@param [Object] observer
the observer to add
@param [Symbol] func
the function to call on the observer during notification. The default
is :update.
@return [Object]
the added observer
|
[
"Adds",
"an",
"observer",
"to",
"this",
"set",
".",
"If",
"a",
"block",
"is",
"passed",
"the",
"observer",
"will",
"be",
"created",
"by",
"this",
"method",
"and",
"no",
"other",
"params",
"should",
"be",
"passed"
] |
c2409bd8cf9c14b967a719810dab5269d69b42de
|
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/copy_on_write_observer_set.rb#L45-L66
|
5,913 |
rolandasb/gogcom
|
lib/gogcom/news.rb
|
Gogcom.News.parse
|
def parse(data)
rss = SimpleRSS.parse data
news = Array.new
rss.items.each do |item|
news_item = NewsItem.new(item.title, item.link, item.description.force_encoding("UTF-8"), item.pubDate)
news.push news_item
end
unless @limit.nil?
news.take(@limit)
else
news
end
end
|
ruby
|
def parse(data)
rss = SimpleRSS.parse data
news = Array.new
rss.items.each do |item|
news_item = NewsItem.new(item.title, item.link, item.description.force_encoding("UTF-8"), item.pubDate)
news.push news_item
end
unless @limit.nil?
news.take(@limit)
else
news
end
end
|
[
"def",
"parse",
"(",
"data",
")",
"rss",
"=",
"SimpleRSS",
".",
"parse",
"data",
"news",
"=",
"Array",
".",
"new",
"rss",
".",
"items",
".",
"each",
"do",
"|",
"item",
"|",
"news_item",
"=",
"NewsItem",
".",
"new",
"(",
"item",
".",
"title",
",",
"item",
".",
"link",
",",
"item",
".",
"description",
".",
"force_encoding",
"(",
"\"UTF-8\"",
")",
",",
"item",
".",
"pubDate",
")",
"news",
".",
"push",
"news_item",
"end",
"unless",
"@limit",
".",
"nil?",
"news",
".",
"take",
"(",
"@limit",
")",
"else",
"news",
"end",
"end"
] |
Parses raw data and returns news items
@return [Array]
|
[
"Parses",
"raw",
"data",
"and",
"returns",
"news",
"items"
] |
015de453bb214c9ccb51665ecadce1367e6d987d
|
https://github.com/rolandasb/gogcom/blob/015de453bb214c9ccb51665ecadce1367e6d987d/lib/gogcom/news.rb#L27-L42
|
5,914 |
kevgo/mortadella
|
lib/mortadella/horizontal.rb
|
Mortadella.Horizontal.columns_indeces_to_drop
|
def columns_indeces_to_drop columns
result = []
headers = @table[0]
headers.each_with_index do |header, i|
result << i unless columns.include? header
end
result
end
|
ruby
|
def columns_indeces_to_drop columns
result = []
headers = @table[0]
headers.each_with_index do |header, i|
result << i unless columns.include? header
end
result
end
|
[
"def",
"columns_indeces_to_drop",
"columns",
"result",
"=",
"[",
"]",
"headers",
"=",
"@table",
"[",
"0",
"]",
"headers",
".",
"each_with_index",
"do",
"|",
"header",
",",
"i",
"|",
"result",
"<<",
"i",
"unless",
"columns",
".",
"include?",
"header",
"end",
"result",
"end"
] |
Returns the column indeces to drop to make this table have the given columns
|
[
"Returns",
"the",
"column",
"indeces",
"to",
"drop",
"to",
"make",
"this",
"table",
"have",
"the",
"given",
"columns"
] |
723d06f7a74fb581bf2679505d9cb06e7b128c88
|
https://github.com/kevgo/mortadella/blob/723d06f7a74fb581bf2679505d9cb06e7b128c88/lib/mortadella/horizontal.rb#L56-L63
|
5,915 |
kevgo/mortadella
|
lib/mortadella/horizontal.rb
|
Mortadella.Horizontal.dry_up
|
def dry_up row
return row unless @previous_row
row.clone.tap do |result|
row.length.times do |i|
if can_dry?(@headers[i]) && row[i] == @previous_row[i]
result[i] = ''
else
break
end
end
end
end
|
ruby
|
def dry_up row
return row unless @previous_row
row.clone.tap do |result|
row.length.times do |i|
if can_dry?(@headers[i]) && row[i] == @previous_row[i]
result[i] = ''
else
break
end
end
end
end
|
[
"def",
"dry_up",
"row",
"return",
"row",
"unless",
"@previous_row",
"row",
".",
"clone",
".",
"tap",
"do",
"|",
"result",
"|",
"row",
".",
"length",
".",
"times",
"do",
"|",
"i",
"|",
"if",
"can_dry?",
"(",
"@headers",
"[",
"i",
"]",
")",
"&&",
"row",
"[",
"i",
"]",
"==",
"@previous_row",
"[",
"i",
"]",
"result",
"[",
"i",
"]",
"=",
"''",
"else",
"break",
"end",
"end",
"end",
"end"
] |
Returns a dried up version of the given row
based on the row that came before in the table
In a dried up row, any values that match the previous row are removed,
stopping on the first difference
|
[
"Returns",
"a",
"dried",
"up",
"version",
"of",
"the",
"given",
"row",
"based",
"on",
"the",
"row",
"that",
"came",
"before",
"in",
"the",
"table"
] |
723d06f7a74fb581bf2679505d9cb06e7b128c88
|
https://github.com/kevgo/mortadella/blob/723d06f7a74fb581bf2679505d9cb06e7b128c88/lib/mortadella/horizontal.rb#L71-L82
|
5,916 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.fetch
|
def fetch(data, keys, default = nil, format = false)
if keys.is_a?(String) || keys.is_a?(Symbol)
keys = [ keys ]
end
keys = keys.flatten.compact
key = keys.shift
if data.has_key?(key)
value = data[key]
if keys.empty?
return filter(value, format)
else
return fetch(data[key], keys, default, format) if data[key].is_a?(Hash)
end
end
return filter(default, format)
end
|
ruby
|
def fetch(data, keys, default = nil, format = false)
if keys.is_a?(String) || keys.is_a?(Symbol)
keys = [ keys ]
end
keys = keys.flatten.compact
key = keys.shift
if data.has_key?(key)
value = data[key]
if keys.empty?
return filter(value, format)
else
return fetch(data[key], keys, default, format) if data[key].is_a?(Hash)
end
end
return filter(default, format)
end
|
[
"def",
"fetch",
"(",
"data",
",",
"keys",
",",
"default",
"=",
"nil",
",",
"format",
"=",
"false",
")",
"if",
"keys",
".",
"is_a?",
"(",
"String",
")",
"||",
"keys",
".",
"is_a?",
"(",
"Symbol",
")",
"keys",
"=",
"[",
"keys",
"]",
"end",
"keys",
"=",
"keys",
".",
"flatten",
".",
"compact",
"key",
"=",
"keys",
".",
"shift",
"if",
"data",
".",
"has_key?",
"(",
"key",
")",
"value",
"=",
"data",
"[",
"key",
"]",
"if",
"keys",
".",
"empty?",
"return",
"filter",
"(",
"value",
",",
"format",
")",
"else",
"return",
"fetch",
"(",
"data",
"[",
"key",
"]",
",",
"keys",
",",
"default",
",",
"format",
")",
"if",
"data",
"[",
"key",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"end",
"end",
"return",
"filter",
"(",
"default",
",",
"format",
")",
"end"
] |
Recursively fetch value for key path in the configuration object.
This method serves as a base accessor to the properties that are defined in
the central property collection. It is used and built upon by other
accessors defined in the class.
Hash data is assumed to already be symbolized.
* *Parameters*
- [Hash] *data* Configuration property data
- [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
- [ANY] *default* Default value is no value is found for key path
- [false, Symbol, String] *format* Format to filter final returned value or false for none
* *Returns*
- [ANY] Filtered value for key path from configuration object
* *Errors*
See:
- #filter
- Nucleon::Util::Data::filter
|
[
"Recursively",
"fetch",
"value",
"for",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L336-L354
|
5,917 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.modify
|
def modify(data, keys, value = nil, delete_nil = false, &block) # :yields: key, value, existing
if keys.is_a?(String) || keys.is_a?(Symbol)
keys = [ keys ]
end
keys = keys.flatten.compact
key = keys.shift
has_key = data.has_key?(key)
existing = {
:key => key,
:value => ( has_key ? data[key] : nil )
}
if keys.empty?
if value.nil? && delete_nil
data.delete(key) if has_key
else
value = symbol_map(value) if value.is_a?(Hash)
data[key] = block ? block.call(key, value, existing[:value]) : value
end
else
data[key] = {} unless has_key
if data[key].is_a?(Hash)
existing = modify(data[key], keys, value, delete_nil, &block)
else
existing[:value] = nil
end
end
return existing
end
|
ruby
|
def modify(data, keys, value = nil, delete_nil = false, &block) # :yields: key, value, existing
if keys.is_a?(String) || keys.is_a?(Symbol)
keys = [ keys ]
end
keys = keys.flatten.compact
key = keys.shift
has_key = data.has_key?(key)
existing = {
:key => key,
:value => ( has_key ? data[key] : nil )
}
if keys.empty?
if value.nil? && delete_nil
data.delete(key) if has_key
else
value = symbol_map(value) if value.is_a?(Hash)
data[key] = block ? block.call(key, value, existing[:value]) : value
end
else
data[key] = {} unless has_key
if data[key].is_a?(Hash)
existing = modify(data[key], keys, value, delete_nil, &block)
else
existing[:value] = nil
end
end
return existing
end
|
[
"def",
"modify",
"(",
"data",
",",
"keys",
",",
"value",
"=",
"nil",
",",
"delete_nil",
"=",
"false",
",",
"&",
"block",
")",
"# :yields: key, value, existing",
"if",
"keys",
".",
"is_a?",
"(",
"String",
")",
"||",
"keys",
".",
"is_a?",
"(",
"Symbol",
")",
"keys",
"=",
"[",
"keys",
"]",
"end",
"keys",
"=",
"keys",
".",
"flatten",
".",
"compact",
"key",
"=",
"keys",
".",
"shift",
"has_key",
"=",
"data",
".",
"has_key?",
"(",
"key",
")",
"existing",
"=",
"{",
":key",
"=>",
"key",
",",
":value",
"=>",
"(",
"has_key",
"?",
"data",
"[",
"key",
"]",
":",
"nil",
")",
"}",
"if",
"keys",
".",
"empty?",
"if",
"value",
".",
"nil?",
"&&",
"delete_nil",
"data",
".",
"delete",
"(",
"key",
")",
"if",
"has_key",
"else",
"value",
"=",
"symbol_map",
"(",
"value",
")",
"if",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"data",
"[",
"key",
"]",
"=",
"block",
"?",
"block",
".",
"call",
"(",
"key",
",",
"value",
",",
"existing",
"[",
":value",
"]",
")",
":",
"value",
"end",
"else",
"data",
"[",
"key",
"]",
"=",
"{",
"}",
"unless",
"has_key",
"if",
"data",
"[",
"key",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"existing",
"=",
"modify",
"(",
"data",
"[",
"key",
"]",
",",
"keys",
",",
"value",
",",
"delete_nil",
",",
"block",
")",
"else",
"existing",
"[",
":value",
"]",
"=",
"nil",
"end",
"end",
"return",
"existing",
"end"
] |
Modify value for key path in the configuration object.
This method serves as a base modifier to the properties that are defined in
the central property collection. It is used and built upon by other
modifiers defined in the class.
Hash data is assumed to already be symbolized.
* *Parameters*
- [Hash] *data* Configuration property data
- [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
- [ANY] *value* Value to set for key path
- [Boolean] *delete_nil* Delete nil value (serves as an internal way to delete properties)
* *Returns*
- [ANY] Existing value for key path from configuration object (before update)
* *Errors*
* *Yields*
- [Symbol] *key* Configuration key to modify
- [ANY] *value* New value of configuration key
- [ANY] *existing* Existing value being replaced for the configuration key
See:
- #symbol_map
- Nucleon::Util::Data::symbol_map
|
[
"Modify",
"value",
"for",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L385-L416
|
5,918 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.get
|
def get(keys, default = nil, format = false)
return fetch(@properties, symbol_array(array(keys).flatten), default, format)
end
|
ruby
|
def get(keys, default = nil, format = false)
return fetch(@properties, symbol_array(array(keys).flatten), default, format)
end
|
[
"def",
"get",
"(",
"keys",
",",
"default",
"=",
"nil",
",",
"format",
"=",
"false",
")",
"return",
"fetch",
"(",
"@properties",
",",
"symbol_array",
"(",
"array",
"(",
"keys",
")",
".",
"flatten",
")",
",",
"default",
",",
"format",
")",
"end"
] |
Fetch value for key path in the configuration object.
* *Parameters*
- [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
- [ANY] *default* Default value is no value is found for key path
- [false, Symbol, String] *format* Format to filter final returned value or false for none
* *Returns*
- [ANY] Filtered value for key path from configuration object
* *Errors*
See:
- #fetch
See also:
- #array
|
[
"Fetch",
"value",
"for",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L437-L439
|
5,919 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.set
|
def set(keys, value, delete_nil = false, &code) # :yields: key, value, existing
modify(@properties, symbol_array(array(keys).flatten), value, delete_nil, &code)
return self
end
|
ruby
|
def set(keys, value, delete_nil = false, &code) # :yields: key, value, existing
modify(@properties, symbol_array(array(keys).flatten), value, delete_nil, &code)
return self
end
|
[
"def",
"set",
"(",
"keys",
",",
"value",
",",
"delete_nil",
"=",
"false",
",",
"&",
"code",
")",
"# :yields: key, value, existing",
"modify",
"(",
"@properties",
",",
"symbol_array",
"(",
"array",
"(",
"keys",
")",
".",
"flatten",
")",
",",
"value",
",",
"delete_nil",
",",
"code",
")",
"return",
"self",
"end"
] |
Set value for key path in the configuration object.
* *Parameters*
- [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
- [ANY] *value* Value to set for key path
- [Boolean] *delete_nil* Delete nil value (serves as an internal way to delete properties)
* *Returns*
- [Nucleon::Config] Returns reference to self for compound operations
* *Errors*
* *Yields*
- [Symbol] *key* Configuration key to modify
- [ANY] *value* New value of configuration key
- [ANY] *existing* Existing value being replaced for the configuration key
See:
- #modify
See also:
- #array
|
[
"Set",
"value",
"for",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L550-L553
|
5,920 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.append
|
def append(keys, value)
modify(@properties, symbol_array(array(keys).flatten), value, false) do |key, processed_value, existing|
if existing.is_a?(Array)
[ existing, processed_value ].flatten
else
[ processed_value ]
end
end
return self
end
|
ruby
|
def append(keys, value)
modify(@properties, symbol_array(array(keys).flatten), value, false) do |key, processed_value, existing|
if existing.is_a?(Array)
[ existing, processed_value ].flatten
else
[ processed_value ]
end
end
return self
end
|
[
"def",
"append",
"(",
"keys",
",",
"value",
")",
"modify",
"(",
"@properties",
",",
"symbol_array",
"(",
"array",
"(",
"keys",
")",
".",
"flatten",
")",
",",
"value",
",",
"false",
")",
"do",
"|",
"key",
",",
"processed_value",
",",
"existing",
"|",
"if",
"existing",
".",
"is_a?",
"(",
"Array",
")",
"[",
"existing",
",",
"processed_value",
"]",
".",
"flatten",
"else",
"[",
"processed_value",
"]",
"end",
"end",
"return",
"self",
"end"
] |
Append a value for an array key path in the configuration object.
* *Parameters*
- [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
- [ANY] *value* Value to set for key path
* *Returns*
- [Nucleon::Config] Returns reference to self for compound operations
* *Errors*
See:
- #modify
See also:
- #array
|
[
"Append",
"a",
"value",
"for",
"an",
"array",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L572-L581
|
5,921 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.prepend
|
def prepend(keys, value, reverse = false)
modify(@properties, symbol_array(array(keys).flatten), value, false) do |key, processed_value, existing|
processed_value = processed_value.reverse if reverse && processed_value.is_a?(Array)
if existing.is_a?(Array)
[ processed_value, existing ].flatten
else
[ processed_value ]
end
end
return self
end
|
ruby
|
def prepend(keys, value, reverse = false)
modify(@properties, symbol_array(array(keys).flatten), value, false) do |key, processed_value, existing|
processed_value = processed_value.reverse if reverse && processed_value.is_a?(Array)
if existing.is_a?(Array)
[ processed_value, existing ].flatten
else
[ processed_value ]
end
end
return self
end
|
[
"def",
"prepend",
"(",
"keys",
",",
"value",
",",
"reverse",
"=",
"false",
")",
"modify",
"(",
"@properties",
",",
"symbol_array",
"(",
"array",
"(",
"keys",
")",
".",
"flatten",
")",
",",
"value",
",",
"false",
")",
"do",
"|",
"key",
",",
"processed_value",
",",
"existing",
"|",
"processed_value",
"=",
"processed_value",
".",
"reverse",
"if",
"reverse",
"&&",
"processed_value",
".",
"is_a?",
"(",
"Array",
")",
"if",
"existing",
".",
"is_a?",
"(",
"Array",
")",
"[",
"processed_value",
",",
"existing",
"]",
".",
"flatten",
"else",
"[",
"processed_value",
"]",
"end",
"end",
"return",
"self",
"end"
] |
Prepend a value to an array key path in the configuration object.
* *Parameters*
- [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
- [ANY] *value* Value to set for key path
- [Boolean] *reverse* Whether or not to reverse any input value arrays given before prepending
* *Returns*
- [Nucleon::Config] Returns reference to self for compound operations
* *Errors*
See:
- #modify
See also:
- #array
|
[
"Prepend",
"a",
"value",
"to",
"an",
"array",
"key",
"path",
"in",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L601-L612
|
5,922 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.delete
|
def delete(keys, default = nil)
existing = modify(@properties, symbol_array(array(keys).flatten), nil, true)
return existing[:value] unless existing[:value].nil?
return default
end
|
ruby
|
def delete(keys, default = nil)
existing = modify(@properties, symbol_array(array(keys).flatten), nil, true)
return existing[:value] unless existing[:value].nil?
return default
end
|
[
"def",
"delete",
"(",
"keys",
",",
"default",
"=",
"nil",
")",
"existing",
"=",
"modify",
"(",
"@properties",
",",
"symbol_array",
"(",
"array",
"(",
"keys",
")",
".",
"flatten",
")",
",",
"nil",
",",
"true",
")",
"return",
"existing",
"[",
":value",
"]",
"unless",
"existing",
"[",
":value",
"]",
".",
"nil?",
"return",
"default",
"end"
] |
Delete key path from the configuration object.
* *Parameters*
- [Array<String, Symbol>, String, Symbol] *keys* Key path to remove
- [ANY] *default* Default value to return if no existing value found
* *Returns*
- [ANY] Returns default or last value removed from configuration object
* *Errors*
See:
- #modify
See also:
- #array
|
[
"Delete",
"key",
"path",
"from",
"the",
"configuration",
"object",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L652-L656
|
5,923 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.defaults
|
def defaults(defaults, options = {})
config = Config.new(options).set(:import_type, :default)
return import_base(defaults, config)
end
|
ruby
|
def defaults(defaults, options = {})
config = Config.new(options).set(:import_type, :default)
return import_base(defaults, config)
end
|
[
"def",
"defaults",
"(",
"defaults",
",",
"options",
"=",
"{",
"}",
")",
"config",
"=",
"Config",
".",
"new",
"(",
"options",
")",
".",
"set",
"(",
":import_type",
",",
":default",
")",
"return",
"import_base",
"(",
"defaults",
",",
"config",
")",
"end"
] |
Set default property values in the configuration object if they don't exist.
If defaults are given as a string or symbol and the configuration object
has a lookup method implemented (corl gem) then the defaults will be
dynamically looked up and set.
* *Parameters*
- [String, Symbol, Array, Hash] *defaults* Data to set as defaults
- [Hash] *options* Import options
* *Returns*
- [Nucleon::Config] Returns reference to self for compound operations
* *Errors*
See:
- #import_base
See also:
- ::new
- #set
|
[
"Set",
"default",
"property",
"values",
"in",
"the",
"configuration",
"object",
"if",
"they",
"don",
"t",
"exist",
"."
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L780-L783
|
5,924 |
coralnexus/nucleon
|
lib/core/config.rb
|
Nucleon.Config.symbol_array
|
def symbol_array(array)
result = []
array.each do |item|
result << item.to_sym unless item.nil?
end
result
end
|
ruby
|
def symbol_array(array)
result = []
array.each do |item|
result << item.to_sym unless item.nil?
end
result
end
|
[
"def",
"symbol_array",
"(",
"array",
")",
"result",
"=",
"[",
"]",
"array",
".",
"each",
"do",
"|",
"item",
"|",
"result",
"<<",
"item",
".",
"to_sym",
"unless",
"item",
".",
"nil?",
"end",
"result",
"end"
] |
Return a symbolized array
* *Parameters*
- [Array<String, Symbol>] *array* Array of strings or symbols
* *Returns*
- [Array<Symbol>] Returns array of symbols
* *Errors*
|
[
"Return",
"a",
"symbolized",
"array"
] |
3a3c489251139c184e0884feaa55269cf64cad44
|
https://github.com/coralnexus/nucleon/blob/3a3c489251139c184e0884feaa55269cf64cad44/lib/core/config.rb#L835-L841
|
5,925 |
OutlawAndy/stripe_local
|
lib/stripe_local/instance_delegation.rb
|
StripeLocal.InstanceDelegation.signup
|
def signup params
plan = params.delete( :plan )
lines = params.delete( :lines ) || []
_customer_ = Stripe::Customer.create( params )
lines.each do |(amount,desc)|
_customer_.add_invoice_item({currency: 'usd', amount: amount, description: desc})
end
_customer_.update_subscription({ plan: plan })
StripeLocal::Customer.create _customer_.to_hash.reverse_merge({model_id: self.id})
end
|
ruby
|
def signup params
plan = params.delete( :plan )
lines = params.delete( :lines ) || []
_customer_ = Stripe::Customer.create( params )
lines.each do |(amount,desc)|
_customer_.add_invoice_item({currency: 'usd', amount: amount, description: desc})
end
_customer_.update_subscription({ plan: plan })
StripeLocal::Customer.create _customer_.to_hash.reverse_merge({model_id: self.id})
end
|
[
"def",
"signup",
"params",
"plan",
"=",
"params",
".",
"delete",
"(",
":plan",
")",
"lines",
"=",
"params",
".",
"delete",
"(",
":lines",
")",
"||",
"[",
"]",
"_customer_",
"=",
"Stripe",
"::",
"Customer",
".",
"create",
"(",
"params",
")",
"lines",
".",
"each",
"do",
"|",
"(",
"amount",
",",
"desc",
")",
"|",
"_customer_",
".",
"add_invoice_item",
"(",
"{",
"currency",
":",
"'usd'",
",",
"amount",
":",
"amount",
",",
"description",
":",
"desc",
"}",
")",
"end",
"_customer_",
".",
"update_subscription",
"(",
"{",
"plan",
":",
"plan",
"}",
")",
"StripeLocal",
"::",
"Customer",
".",
"create",
"_customer_",
".",
"to_hash",
".",
"reverse_merge",
"(",
"{",
"model_id",
":",
"self",
".",
"id",
"}",
")",
"end"
] |
==this is the primary interface for subscribing.
params::
* +card+ (required) -> the token returned by stripe.js
* +plan+ (required) -> the id of the plan being subscribed to
* +email+ (optional) -> the client's email address
* +description+ (optional) -> a description to attach to the stripe object for future reference
* +coupon+ (optional) -> the id of a coupon if the subscription should be discounted
* +lines+ (optional) -> an array of (amount,description) tuples
example::
:card => "tok_abc123",
:plan => "MySaaS",
:email => subscriber.email,
:description => "a one year subscription to our flagship service at $99.00 per month"
:lines => [
[ 20000, "a one time setup fee of $200.00 for new members" ]
]
|
[
"==",
"this",
"is",
"the",
"primary",
"interface",
"for",
"subscribing",
"."
] |
78b685d1b35a848e02d19e4c57015f2a02fdc882
|
https://github.com/OutlawAndy/stripe_local/blob/78b685d1b35a848e02d19e4c57015f2a02fdc882/lib/stripe_local/instance_delegation.rb#L20-L32
|
5,926 |
barkerest/barkest_core
|
lib/barkest_core/extensions/axlsx_extenstions.rb
|
Axlsx.Package.simple
|
def simple(name = nil)
workbook.add_worksheet(name: name || 'Sheet 1') do |sheet|
yield sheet, workbook.predefined_styles if block_given?
sheet.add_row
end
end
|
ruby
|
def simple(name = nil)
workbook.add_worksheet(name: name || 'Sheet 1') do |sheet|
yield sheet, workbook.predefined_styles if block_given?
sheet.add_row
end
end
|
[
"def",
"simple",
"(",
"name",
"=",
"nil",
")",
"workbook",
".",
"add_worksheet",
"(",
"name",
":",
"name",
"||",
"'Sheet 1'",
")",
"do",
"|",
"sheet",
"|",
"yield",
"sheet",
",",
"workbook",
".",
"predefined_styles",
"if",
"block_given?",
"sheet",
".",
"add_row",
"end",
"end"
] |
Creates a simple workbook with one sheet.
Predefines multiple styles that can be used to format cells.
The +sheet+ and +styles+ are yielded to the provided block.
See Axlsx::Workbook#predefined_styles for a list of predefined styles.
|
[
"Creates",
"a",
"simple",
"workbook",
"with",
"one",
"sheet",
"."
] |
3eeb025ec870888cacbc9bae252a39ebf9295f61
|
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/lib/barkest_core/extensions/axlsx_extenstions.rb#L19-L24
|
5,927 |
barkerest/barkest_core
|
lib/barkest_core/extensions/axlsx_extenstions.rb
|
Axlsx.Workbook.predefined_styles
|
def predefined_styles
@predefined_styles ||=
begin
tmp = {}
styles do |s|
tmp = {
bold: s.add_style(b: true, alignment: { vertical: :top }),
date: s.add_style(format_code: 'mm/dd/yyyy', alignment: { vertical: :top }),
float: s.add_style(format_code: '#,##0.00', alignment: { vertical: :top }),
integer: s.add_style(format_code: '#,##0', alignment: { vertical: :top }),
percent: s.add_style(num_fmt: 9, alignment: { vertical: :top }),
currency: s.add_style(num_fmt: 7, alignment: { vertical: :top }),
text: s.add_style(format_code: '@', alignment: { vertical: :top }),
wrapped: s.add_style(alignment: { wrap_text: true, vertical: :top }),
normal: s.add_style(alignment: { vertical: :top })
}
end
tmp
end
end
|
ruby
|
def predefined_styles
@predefined_styles ||=
begin
tmp = {}
styles do |s|
tmp = {
bold: s.add_style(b: true, alignment: { vertical: :top }),
date: s.add_style(format_code: 'mm/dd/yyyy', alignment: { vertical: :top }),
float: s.add_style(format_code: '#,##0.00', alignment: { vertical: :top }),
integer: s.add_style(format_code: '#,##0', alignment: { vertical: :top }),
percent: s.add_style(num_fmt: 9, alignment: { vertical: :top }),
currency: s.add_style(num_fmt: 7, alignment: { vertical: :top }),
text: s.add_style(format_code: '@', alignment: { vertical: :top }),
wrapped: s.add_style(alignment: { wrap_text: true, vertical: :top }),
normal: s.add_style(alignment: { vertical: :top })
}
end
tmp
end
end
|
[
"def",
"predefined_styles",
"@predefined_styles",
"||=",
"begin",
"tmp",
"=",
"{",
"}",
"styles",
"do",
"|",
"s",
"|",
"tmp",
"=",
"{",
"bold",
":",
"s",
".",
"add_style",
"(",
"b",
":",
"true",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"date",
":",
"s",
".",
"add_style",
"(",
"format_code",
":",
"'mm/dd/yyyy'",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"float",
":",
"s",
".",
"add_style",
"(",
"format_code",
":",
"'#,##0.00'",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"integer",
":",
"s",
".",
"add_style",
"(",
"format_code",
":",
"'#,##0'",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"percent",
":",
"s",
".",
"add_style",
"(",
"num_fmt",
":",
"9",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"currency",
":",
"s",
".",
"add_style",
"(",
"num_fmt",
":",
"7",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"text",
":",
"s",
".",
"add_style",
"(",
"format_code",
":",
"'@'",
",",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
",",
"wrapped",
":",
"s",
".",
"add_style",
"(",
"alignment",
":",
"{",
"wrap_text",
":",
"true",
",",
"vertical",
":",
":top",
"}",
")",
",",
"normal",
":",
"s",
".",
"add_style",
"(",
"alignment",
":",
"{",
"vertical",
":",
":top",
"}",
")",
"}",
"end",
"tmp",
"end",
"end"
] |
Gets the predefined style list.
The +predefined_styles+ hash contains :bold, :date, :float, :integer, :percent, :currency, :text, :wrapped, and :normal
styles for you to use.
|
[
"Gets",
"the",
"predefined",
"style",
"list",
"."
] |
3eeb025ec870888cacbc9bae252a39ebf9295f61
|
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/lib/barkest_core/extensions/axlsx_extenstions.rb#L50-L69
|
5,928 |
barkerest/barkest_core
|
lib/barkest_core/extensions/axlsx_extenstions.rb
|
Axlsx.Worksheet.add_combined_row
|
def add_combined_row(row_data, keys = [ :value, :style, :type ])
val_index = keys.index(:value) || keys.index('value')
style_index = keys.index(:style) || keys.index('style')
type_index = keys.index(:type) || keys.index('type')
raise ArgumentError.new('Missing :value key') unless val_index
values = row_data.map{|v| v.is_a?(Array) ? v[val_index] : v }
styles = style_index ? row_data.map{ |v| v.is_a?(Array) ? v[style_index] : nil } : []
types = type_index ? row_data.map{ |v| v.is_a?(Array) ? v[type_index] : nil } : []
# allows specifying the style as just a symbol.
styles.each_with_index do |style,index|
if style.is_a?(String) || style.is_a?(Symbol)
styles[index] = workbook.predefined_styles[style.to_sym]
end
end
add_row values, style: styles, types: types
end
|
ruby
|
def add_combined_row(row_data, keys = [ :value, :style, :type ])
val_index = keys.index(:value) || keys.index('value')
style_index = keys.index(:style) || keys.index('style')
type_index = keys.index(:type) || keys.index('type')
raise ArgumentError.new('Missing :value key') unless val_index
values = row_data.map{|v| v.is_a?(Array) ? v[val_index] : v }
styles = style_index ? row_data.map{ |v| v.is_a?(Array) ? v[style_index] : nil } : []
types = type_index ? row_data.map{ |v| v.is_a?(Array) ? v[type_index] : nil } : []
# allows specifying the style as just a symbol.
styles.each_with_index do |style,index|
if style.is_a?(String) || style.is_a?(Symbol)
styles[index] = workbook.predefined_styles[style.to_sym]
end
end
add_row values, style: styles, types: types
end
|
[
"def",
"add_combined_row",
"(",
"row_data",
",",
"keys",
"=",
"[",
":value",
",",
":style",
",",
":type",
"]",
")",
"val_index",
"=",
"keys",
".",
"index",
"(",
":value",
")",
"||",
"keys",
".",
"index",
"(",
"'value'",
")",
"style_index",
"=",
"keys",
".",
"index",
"(",
":style",
")",
"||",
"keys",
".",
"index",
"(",
"'style'",
")",
"type_index",
"=",
"keys",
".",
"index",
"(",
":type",
")",
"||",
"keys",
".",
"index",
"(",
"'type'",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"'Missing :value key'",
")",
"unless",
"val_index",
"values",
"=",
"row_data",
".",
"map",
"{",
"|",
"v",
"|",
"v",
".",
"is_a?",
"(",
"Array",
")",
"?",
"v",
"[",
"val_index",
"]",
":",
"v",
"}",
"styles",
"=",
"style_index",
"?",
"row_data",
".",
"map",
"{",
"|",
"v",
"|",
"v",
".",
"is_a?",
"(",
"Array",
")",
"?",
"v",
"[",
"style_index",
"]",
":",
"nil",
"}",
":",
"[",
"]",
"types",
"=",
"type_index",
"?",
"row_data",
".",
"map",
"{",
"|",
"v",
"|",
"v",
".",
"is_a?",
"(",
"Array",
")",
"?",
"v",
"[",
"type_index",
"]",
":",
"nil",
"}",
":",
"[",
"]",
"# allows specifying the style as just a symbol.\r",
"styles",
".",
"each_with_index",
"do",
"|",
"style",
",",
"index",
"|",
"if",
"style",
".",
"is_a?",
"(",
"String",
")",
"||",
"style",
".",
"is_a?",
"(",
"Symbol",
")",
"styles",
"[",
"index",
"]",
"=",
"workbook",
".",
"predefined_styles",
"[",
"style",
".",
"to_sym",
"]",
"end",
"end",
"add_row",
"values",
",",
"style",
":",
"styles",
",",
"types",
":",
"types",
"end"
] |
Adds a row to the worksheet with combined data.
Currently we support specifying the +values+, +styles+, and +types+ using this method.
The +row_data+ value should be an array of arrays.
Each subarray represents a value in the row with up to three values specifying the +value+, +style+, and +type+.
Value is the only item required.
[['Value 1', :bold, :string], ['Value 2'], ['Value 3', nil, :string]]
In fact, if a subarray is replaced by a value, it is treated the same as an array only containing that value.
[['Value 1', :bold, :string], 'Value 2', ['Value 3', nil, :string]]
The +keys+ parameter defines the location of the data elements within the sub arrays.
The default would be [ :value, :style, :type ]. If your array happens to have additional data or data arranged
in a different format, you can set this to anything you like to get the method to process your data
appropriately.
keys = [ :ignored, :value, :ignored, :ignored, :style, :ignored, :type ]
Styles can be specified as a symbol to use the predefined styles, or as a style object you created.
|
[
"Adds",
"a",
"row",
"to",
"the",
"worksheet",
"with",
"combined",
"data",
"."
] |
3eeb025ec870888cacbc9bae252a39ebf9295f61
|
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/lib/barkest_core/extensions/axlsx_extenstions.rb#L135-L153
|
5,929 |
jinx/migrate
|
spec/csv/join/join_helper.rb
|
Jinx.JoinHelper.join
|
def join(source, target, *fields, &block)
FileUtils.rm_rf OUTPUT
sf = File.expand_path("#{source}.csv", File.dirname(__FILE__))
tf = File.expand_path("#{target}.csv", File.dirname(__FILE__))
Jinx::CsvIO.join(sf, :to => tf, :for => fields, :as => OUTPUT, &block)
if File.exists?(OUTPUT) then
File.readlines(OUTPUT).map do |line|
line.chomp.split(',').map { |s| s unless s.blank? }
end
else
Array::EMPTY_ARRAY
end
end
|
ruby
|
def join(source, target, *fields, &block)
FileUtils.rm_rf OUTPUT
sf = File.expand_path("#{source}.csv", File.dirname(__FILE__))
tf = File.expand_path("#{target}.csv", File.dirname(__FILE__))
Jinx::CsvIO.join(sf, :to => tf, :for => fields, :as => OUTPUT, &block)
if File.exists?(OUTPUT) then
File.readlines(OUTPUT).map do |line|
line.chomp.split(',').map { |s| s unless s.blank? }
end
else
Array::EMPTY_ARRAY
end
end
|
[
"def",
"join",
"(",
"source",
",",
"target",
",",
"*",
"fields",
",",
"&",
"block",
")",
"FileUtils",
".",
"rm_rf",
"OUTPUT",
"sf",
"=",
"File",
".",
"expand_path",
"(",
"\"#{source}.csv\"",
",",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
")",
"tf",
"=",
"File",
".",
"expand_path",
"(",
"\"#{target}.csv\"",
",",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
")",
"Jinx",
"::",
"CsvIO",
".",
"join",
"(",
"sf",
",",
":to",
"=>",
"tf",
",",
":for",
"=>",
"fields",
",",
":as",
"=>",
"OUTPUT",
",",
"block",
")",
"if",
"File",
".",
"exists?",
"(",
"OUTPUT",
")",
"then",
"File",
".",
"readlines",
"(",
"OUTPUT",
")",
".",
"map",
"do",
"|",
"line",
"|",
"line",
".",
"chomp",
".",
"split",
"(",
"','",
")",
".",
"map",
"{",
"|",
"s",
"|",
"s",
"unless",
"s",
".",
"blank?",
"}",
"end",
"else",
"Array",
"::",
"EMPTY_ARRAY",
"end",
"end"
] |
Joins the given source fixture to the target fixture on the specified fields.
@param [Symbol] source the source file fixture in the join spec directory
@param [Symbol] target the target file fixture in the join spec directory
@param [<String>] fields the source fields (default is all source fields)
@return [<<String>>] the output records
|
[
"Joins",
"the",
"given",
"source",
"fixture",
"to",
"the",
"target",
"fixture",
"on",
"the",
"specified",
"fields",
"."
] |
309957a470d72da3bd074f8173dbbe2f12449883
|
https://github.com/jinx/migrate/blob/309957a470d72da3bd074f8173dbbe2f12449883/spec/csv/join/join_helper.rb#L21-L33
|
5,930 |
tatemae/muck-engine
|
lib/muck-engine/form_builder.rb
|
MuckEngine.FormBuilder.state_select
|
def state_select(method, options = {}, html_options = {}, additional_state = nil)
country_id_field_name = options.delete(:country_id) || 'country_id'
country_id = get_instance_object_value(country_id_field_name)
@states = country_id.nil? ? [] : (additional_state ? [additional_state] : []) + State.find(:all, :conditions => ["country_id = ?", country_id], :order => "name asc")
self.menu_select(method, I18n.t('muck.engine.choose_state'), @states, options.merge(:prompt => I18n.t('muck.engine.select_state_prompt'), :wrapper_id => 'states-container'), html_options.merge(:id => 'states'))
end
|
ruby
|
def state_select(method, options = {}, html_options = {}, additional_state = nil)
country_id_field_name = options.delete(:country_id) || 'country_id'
country_id = get_instance_object_value(country_id_field_name)
@states = country_id.nil? ? [] : (additional_state ? [additional_state] : []) + State.find(:all, :conditions => ["country_id = ?", country_id], :order => "name asc")
self.menu_select(method, I18n.t('muck.engine.choose_state'), @states, options.merge(:prompt => I18n.t('muck.engine.select_state_prompt'), :wrapper_id => 'states-container'), html_options.merge(:id => 'states'))
end
|
[
"def",
"state_select",
"(",
"method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
",",
"additional_state",
"=",
"nil",
")",
"country_id_field_name",
"=",
"options",
".",
"delete",
"(",
":country_id",
")",
"||",
"'country_id'",
"country_id",
"=",
"get_instance_object_value",
"(",
"country_id_field_name",
")",
"@states",
"=",
"country_id",
".",
"nil?",
"?",
"[",
"]",
":",
"(",
"additional_state",
"?",
"[",
"additional_state",
"]",
":",
"[",
"]",
")",
"+",
"State",
".",
"find",
"(",
":all",
",",
":conditions",
"=>",
"[",
"\"country_id = ?\"",
",",
"country_id",
"]",
",",
":order",
"=>",
"\"name asc\"",
")",
"self",
".",
"menu_select",
"(",
"method",
",",
"I18n",
".",
"t",
"(",
"'muck.engine.choose_state'",
")",
",",
"@states",
",",
"options",
".",
"merge",
"(",
":prompt",
"=>",
"I18n",
".",
"t",
"(",
"'muck.engine.select_state_prompt'",
")",
",",
":wrapper_id",
"=>",
"'states-container'",
")",
",",
"html_options",
".",
"merge",
"(",
":id",
"=>",
"'states'",
")",
")",
"end"
] |
creates a select control with states. Default id is 'states'. If 'retain' is passed for the class value the value of this
control will be written into a cookie with the key 'states'.
|
[
"creates",
"a",
"select",
"control",
"with",
"states",
".",
"Default",
"id",
"is",
"states",
".",
"If",
"retain",
"is",
"passed",
"for",
"the",
"class",
"value",
"the",
"value",
"of",
"this",
"control",
"will",
"be",
"written",
"into",
"a",
"cookie",
"with",
"the",
"key",
"states",
"."
] |
41fc072dce3a365b3ce4a73d4f60a4ff24026d51
|
https://github.com/tatemae/muck-engine/blob/41fc072dce3a365b3ce4a73d4f60a4ff24026d51/lib/muck-engine/form_builder.rb#L149-L154
|
5,931 |
tatemae/muck-engine
|
lib/muck-engine/form_builder.rb
|
MuckEngine.FormBuilder.country_select
|
def country_select(method, options = {}, html_options = {}, additional_country = nil)
@countries ||= (additional_country ? [additional_country] : []) + Country.find(:all, :order => 'sort, name asc')
self.menu_select(method, I18n.t('muck.engine.choose_country'), @countries, options.merge(:prompt => I18n.t('muck.engine.select_country_prompt'), :wrapper_id => 'countries-container'), html_options.merge(:id => 'countries'))
end
|
ruby
|
def country_select(method, options = {}, html_options = {}, additional_country = nil)
@countries ||= (additional_country ? [additional_country] : []) + Country.find(:all, :order => 'sort, name asc')
self.menu_select(method, I18n.t('muck.engine.choose_country'), @countries, options.merge(:prompt => I18n.t('muck.engine.select_country_prompt'), :wrapper_id => 'countries-container'), html_options.merge(:id => 'countries'))
end
|
[
"def",
"country_select",
"(",
"method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
",",
"additional_country",
"=",
"nil",
")",
"@countries",
"||=",
"(",
"additional_country",
"?",
"[",
"additional_country",
"]",
":",
"[",
"]",
")",
"+",
"Country",
".",
"find",
"(",
":all",
",",
":order",
"=>",
"'sort, name asc'",
")",
"self",
".",
"menu_select",
"(",
"method",
",",
"I18n",
".",
"t",
"(",
"'muck.engine.choose_country'",
")",
",",
"@countries",
",",
"options",
".",
"merge",
"(",
":prompt",
"=>",
"I18n",
".",
"t",
"(",
"'muck.engine.select_country_prompt'",
")",
",",
":wrapper_id",
"=>",
"'countries-container'",
")",
",",
"html_options",
".",
"merge",
"(",
":id",
"=>",
"'countries'",
")",
")",
"end"
] |
creates a select control with countries. Default id is 'countries'. If 'retain' is passed for the class value the value of this
control will be written into a cookie with the key 'countries'.
|
[
"creates",
"a",
"select",
"control",
"with",
"countries",
".",
"Default",
"id",
"is",
"countries",
".",
"If",
"retain",
"is",
"passed",
"for",
"the",
"class",
"value",
"the",
"value",
"of",
"this",
"control",
"will",
"be",
"written",
"into",
"a",
"cookie",
"with",
"the",
"key",
"countries",
"."
] |
41fc072dce3a365b3ce4a73d4f60a4ff24026d51
|
https://github.com/tatemae/muck-engine/blob/41fc072dce3a365b3ce4a73d4f60a4ff24026d51/lib/muck-engine/form_builder.rb#L158-L161
|
5,932 |
tatemae/muck-engine
|
lib/muck-engine/form_builder.rb
|
MuckEngine.FormBuilder.language_select
|
def language_select(method, options = {}, html_options = {}, additional_language = nil)
@languages ||= (additional_language ? [additional_language] : []) + Language.find(:all, :order => 'name asc')
self.menu_select(method, I18n.t('muck.engine.choose_language'), @languages, options.merge(:prompt => I18n.t('muck.engine.select_language_prompt'), :wrapper_id => 'languages-container'), html_options.merge(:id => 'languages'))
end
|
ruby
|
def language_select(method, options = {}, html_options = {}, additional_language = nil)
@languages ||= (additional_language ? [additional_language] : []) + Language.find(:all, :order => 'name asc')
self.menu_select(method, I18n.t('muck.engine.choose_language'), @languages, options.merge(:prompt => I18n.t('muck.engine.select_language_prompt'), :wrapper_id => 'languages-container'), html_options.merge(:id => 'languages'))
end
|
[
"def",
"language_select",
"(",
"method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
",",
"additional_language",
"=",
"nil",
")",
"@languages",
"||=",
"(",
"additional_language",
"?",
"[",
"additional_language",
"]",
":",
"[",
"]",
")",
"+",
"Language",
".",
"find",
"(",
":all",
",",
":order",
"=>",
"'name asc'",
")",
"self",
".",
"menu_select",
"(",
"method",
",",
"I18n",
".",
"t",
"(",
"'muck.engine.choose_language'",
")",
",",
"@languages",
",",
"options",
".",
"merge",
"(",
":prompt",
"=>",
"I18n",
".",
"t",
"(",
"'muck.engine.select_language_prompt'",
")",
",",
":wrapper_id",
"=>",
"'languages-container'",
")",
",",
"html_options",
".",
"merge",
"(",
":id",
"=>",
"'languages'",
")",
")",
"end"
] |
creates a select control with languages. Default id is 'languages'. If 'retain' is passed for the class value the value of this
control will be written into a cookie with the key 'languages'.
|
[
"creates",
"a",
"select",
"control",
"with",
"languages",
".",
"Default",
"id",
"is",
"languages",
".",
"If",
"retain",
"is",
"passed",
"for",
"the",
"class",
"value",
"the",
"value",
"of",
"this",
"control",
"will",
"be",
"written",
"into",
"a",
"cookie",
"with",
"the",
"key",
"languages",
"."
] |
41fc072dce3a365b3ce4a73d4f60a4ff24026d51
|
https://github.com/tatemae/muck-engine/blob/41fc072dce3a365b3ce4a73d4f60a4ff24026d51/lib/muck-engine/form_builder.rb#L165-L168
|
5,933 |
barkerest/incline
|
lib/incline/auth_engine_base.rb
|
Incline.AuthEngineBase.add_success_to
|
def add_success_to(user, message, client_ip) # :doc:
Incline::Log::info "LOGIN(#{user}) SUCCESS FROM #{client_ip}: #{message}"
purge_old_history_for user
user.login_histories.create(ip_address: client_ip, successful: true, message: message)
end
|
ruby
|
def add_success_to(user, message, client_ip) # :doc:
Incline::Log::info "LOGIN(#{user}) SUCCESS FROM #{client_ip}: #{message}"
purge_old_history_for user
user.login_histories.create(ip_address: client_ip, successful: true, message: message)
end
|
[
"def",
"add_success_to",
"(",
"user",
",",
"message",
",",
"client_ip",
")",
"# :doc:",
"Incline",
"::",
"Log",
"::",
"info",
"\"LOGIN(#{user}) SUCCESS FROM #{client_ip}: #{message}\"",
"purge_old_history_for",
"user",
"user",
".",
"login_histories",
".",
"create",
"(",
"ip_address",
":",
"client_ip",
",",
"successful",
":",
"true",
",",
"message",
":",
"message",
")",
"end"
] |
Logs a success message for a user.
|
[
"Logs",
"a",
"success",
"message",
"for",
"a",
"user",
"."
] |
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
|
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/auth_engine_base.rb#L53-L57
|
5,934 |
khiemns54/sp2db
|
lib/sp2db/config.rb
|
Sp2db.Config.credential=
|
def credential=cr
if File.exist?(cr) && File.file?(cr)
cr = File.read cr
end
@credential = case cr
when Hash, ActiveSupport::HashWithIndifferentAccess
cr
when String
JSON.parse cr
else
raise "Invalid data type"
end
end
|
ruby
|
def credential=cr
if File.exist?(cr) && File.file?(cr)
cr = File.read cr
end
@credential = case cr
when Hash, ActiveSupport::HashWithIndifferentAccess
cr
when String
JSON.parse cr
else
raise "Invalid data type"
end
end
|
[
"def",
"credential",
"=",
"cr",
"if",
"File",
".",
"exist?",
"(",
"cr",
")",
"&&",
"File",
".",
"file?",
"(",
"cr",
")",
"cr",
"=",
"File",
".",
"read",
"cr",
"end",
"@credential",
"=",
"case",
"cr",
"when",
"Hash",
",",
"ActiveSupport",
"::",
"HashWithIndifferentAccess",
"cr",
"when",
"String",
"JSON",
".",
"parse",
"cr",
"else",
"raise",
"\"Invalid data type\"",
"end",
"end"
] |
File name or json string or hash
|
[
"File",
"name",
"or",
"json",
"string",
"or",
"hash"
] |
76c78df07ea19d6f1b5ff2e883ae206a0e94de27
|
https://github.com/khiemns54/sp2db/blob/76c78df07ea19d6f1b5ff2e883ae206a0e94de27/lib/sp2db/config.rb#L53-L66
|
5,935 |
PragTob/wingtips
|
lib/wingtips/slide.rb
|
Wingtips.Slide.method_missing
|
def method_missing(method, *args, &blk)
if app_should_handle_method? method
app.send(method, *args, &blk)
else
super
end
end
|
ruby
|
def method_missing(method, *args, &blk)
if app_should_handle_method? method
app.send(method, *args, &blk)
else
super
end
end
|
[
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"blk",
")",
"if",
"app_should_handle_method?",
"method",
"app",
".",
"send",
"(",
"method",
",",
"args",
",",
"blk",
")",
"else",
"super",
"end",
"end"
] |
copied from the URL implementation... weird but I want to have
classes not methods for this
|
[
"copied",
"from",
"the",
"URL",
"implementation",
"...",
"weird",
"but",
"I",
"want",
"to",
"have",
"classes",
"not",
"methods",
"for",
"this"
] |
df47ecdf19fdd9e7091e96232a24c2d7fb43a3ab
|
https://github.com/PragTob/wingtips/blob/df47ecdf19fdd9e7091e96232a24c2d7fb43a3ab/lib/wingtips/slide.rb#L43-L49
|
5,936 |
right-solutions/usman
|
app/helpers/usman/authentication_helper.rb
|
Usman.AuthenticationHelper.require_super_admin
|
def require_super_admin
unless @current_user.super_admin?
text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
set_flash_message(text, :error, false) if defined?(flash) && flash
redirect_or_popup_to_default_sign_in_page(false)
end
end
|
ruby
|
def require_super_admin
unless @current_user.super_admin?
text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
set_flash_message(text, :error, false) if defined?(flash) && flash
redirect_or_popup_to_default_sign_in_page(false)
end
end
|
[
"def",
"require_super_admin",
"unless",
"@current_user",
".",
"super_admin?",
"text",
"=",
"\"#{I18n.t(\"authentication.permission_denied.heading\")}: #{I18n.t(\"authentication.permission_denied.message\")}\"",
"set_flash_message",
"(",
"text",
",",
":error",
",",
"false",
")",
"if",
"defined?",
"(",
"flash",
")",
"&&",
"flash",
"redirect_or_popup_to_default_sign_in_page",
"(",
"false",
")",
"end",
"end"
] |
This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin
|
[
"This",
"method",
"is",
"usually",
"used",
"as",
"a",
"before",
"filter",
"from",
"admin",
"controllers",
"to",
"ensure",
"that",
"the",
"logged",
"in",
"user",
"is",
"a",
"super",
"admin"
] |
66bc427a03d0ed96ab7239c0b3969d566251a7f7
|
https://github.com/right-solutions/usman/blob/66bc427a03d0ed96ab7239c0b3969d566251a7f7/app/helpers/usman/authentication_helper.rb#L111-L117
|
5,937 |
pjb3/curtain
|
lib/curtain/rendering.rb
|
Curtain.Rendering.render
|
def render(*args)
name = get_template_name(*args)
locals = args.last.is_a?(Hash) ? args.last : {}
# TODO: Cache Template objects
template_file = self.class.find_template(name)
ext = template_file.split('.').last
orig_buffer = @output_buffer
@output_buffer = Curtain::OutputBuffer.new
case ext
when 'slim'
template = ::Slim::Template.new(template_file, :buffer => '@output_buffer', :use_html_safe => true, :disable_capture => true, :generator => Temple::Generators::RailsOutputBuffer )
when 'erb'
template = ::Curtain::ErubisTemplate.new(template_file, :buffer => '@output_buffer', :use_html_safe => true, :disable_capture => true, :generator => Temple::Generators::RailsOutputBuffer )
else
raise "Curtain cannot process .#{ext} templates"
end
template.render(self, variables.merge(locals))
@output_buffer
ensure
@output_buffer = orig_buffer
end
|
ruby
|
def render(*args)
name = get_template_name(*args)
locals = args.last.is_a?(Hash) ? args.last : {}
# TODO: Cache Template objects
template_file = self.class.find_template(name)
ext = template_file.split('.').last
orig_buffer = @output_buffer
@output_buffer = Curtain::OutputBuffer.new
case ext
when 'slim'
template = ::Slim::Template.new(template_file, :buffer => '@output_buffer', :use_html_safe => true, :disable_capture => true, :generator => Temple::Generators::RailsOutputBuffer )
when 'erb'
template = ::Curtain::ErubisTemplate.new(template_file, :buffer => '@output_buffer', :use_html_safe => true, :disable_capture => true, :generator => Temple::Generators::RailsOutputBuffer )
else
raise "Curtain cannot process .#{ext} templates"
end
template.render(self, variables.merge(locals))
@output_buffer
ensure
@output_buffer = orig_buffer
end
|
[
"def",
"render",
"(",
"*",
"args",
")",
"name",
"=",
"get_template_name",
"(",
"args",
")",
"locals",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"last",
":",
"{",
"}",
"# TODO: Cache Template objects",
"template_file",
"=",
"self",
".",
"class",
".",
"find_template",
"(",
"name",
")",
"ext",
"=",
"template_file",
".",
"split",
"(",
"'.'",
")",
".",
"last",
"orig_buffer",
"=",
"@output_buffer",
"@output_buffer",
"=",
"Curtain",
"::",
"OutputBuffer",
".",
"new",
"case",
"ext",
"when",
"'slim'",
"template",
"=",
"::",
"Slim",
"::",
"Template",
".",
"new",
"(",
"template_file",
",",
":buffer",
"=>",
"'@output_buffer'",
",",
":use_html_safe",
"=>",
"true",
",",
":disable_capture",
"=>",
"true",
",",
":generator",
"=>",
"Temple",
"::",
"Generators",
"::",
"RailsOutputBuffer",
")",
"when",
"'erb'",
"template",
"=",
"::",
"Curtain",
"::",
"ErubisTemplate",
".",
"new",
"(",
"template_file",
",",
":buffer",
"=>",
"'@output_buffer'",
",",
":use_html_safe",
"=>",
"true",
",",
":disable_capture",
"=>",
"true",
",",
":generator",
"=>",
"Temple",
"::",
"Generators",
"::",
"RailsOutputBuffer",
")",
"else",
"raise",
"\"Curtain cannot process .#{ext} templates\"",
"end",
"template",
".",
"render",
"(",
"self",
",",
"variables",
".",
"merge",
"(",
"locals",
")",
")",
"@output_buffer",
"ensure",
"@output_buffer",
"=",
"orig_buffer",
"end"
] |
Renders the template
@example Render the default template
view.render
@example Render the foo template
view.render "foo.slim"
@example You can use symbols and omit the extension
view.render :foo
@example You can specify what the local variables for the template should be
view.render :foo, :bar => "baz"
@example You can use the default template an specify locals
view.render :bar => "baz"
@param [String, Symbol] name The name of the template.
The extension can be omitted.
This parameter can be omiitted and the default template will be used.
@param [Hash] locals
@return [String] The result of rendering the template
@see #default_template_name
|
[
"Renders",
"the",
"template"
] |
ab4f3dccea9b887148689084137f1375278f2dcf
|
https://github.com/pjb3/curtain/blob/ab4f3dccea9b887148689084137f1375278f2dcf/lib/curtain/rendering.rb#L30-L53
|
5,938 |
Bastes/CellularMap
|
lib/cellular_map/map.rb
|
CellularMap.Map.[]
|
def [](x, y)
if x.respond_to?(:to_i) && y.respond_to?(:to_i)
Cell.new(x, y, self)
else
Zone.new(x, y, self)
end
end
|
ruby
|
def [](x, y)
if x.respond_to?(:to_i) && y.respond_to?(:to_i)
Cell.new(x, y, self)
else
Zone.new(x, y, self)
end
end
|
[
"def",
"[]",
"(",
"x",
",",
"y",
")",
"if",
"x",
".",
"respond_to?",
"(",
":to_i",
")",
"&&",
"y",
".",
"respond_to?",
"(",
":to_i",
")",
"Cell",
".",
"new",
"(",
"x",
",",
"y",
",",
"self",
")",
"else",
"Zone",
".",
"new",
"(",
"x",
",",
"y",
",",
"self",
")",
"end",
"end"
] |
Accessing a cell or a zone.
|
[
"Accessing",
"a",
"cell",
"or",
"a",
"zone",
"."
] |
e9cfa44ce820b16cdc5ca5b59291e80e53363d1f
|
https://github.com/Bastes/CellularMap/blob/e9cfa44ce820b16cdc5ca5b59291e80e53363d1f/lib/cellular_map/map.rb#L21-L27
|
5,939 |
Bastes/CellularMap
|
lib/cellular_map/map.rb
|
CellularMap.Map.[]=
|
def []=(x, y, content)
if content.nil?
@store.delete([x, y]) && nil
else
@store[[x, y]] = content
end
end
|
ruby
|
def []=(x, y, content)
if content.nil?
@store.delete([x, y]) && nil
else
@store[[x, y]] = content
end
end
|
[
"def",
"[]=",
"(",
"x",
",",
"y",
",",
"content",
")",
"if",
"content",
".",
"nil?",
"@store",
".",
"delete",
"(",
"[",
"x",
",",
"y",
"]",
")",
"&&",
"nil",
"else",
"@store",
"[",
"[",
"x",
",",
"y",
"]",
"]",
"=",
"content",
"end",
"end"
] |
Putting new content in a cell.
|
[
"Putting",
"new",
"content",
"in",
"a",
"cell",
"."
] |
e9cfa44ce820b16cdc5ca5b59291e80e53363d1f
|
https://github.com/Bastes/CellularMap/blob/e9cfa44ce820b16cdc5ca5b59291e80e53363d1f/lib/cellular_map/map.rb#L30-L36
|
5,940 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.create_new_node
|
def create_new_node(project_root, environment)
# Ask the hostname for node
hostname = ask_not_existing_hostname(project_root, environment)
# Ask IP for node
ip = ask_ip(environment)
# Node creation
node = Bebox::Node.new(environment, project_root, hostname, ip)
output = node.create
ok _('wizard.node.creation_success')
return output
end
|
ruby
|
def create_new_node(project_root, environment)
# Ask the hostname for node
hostname = ask_not_existing_hostname(project_root, environment)
# Ask IP for node
ip = ask_ip(environment)
# Node creation
node = Bebox::Node.new(environment, project_root, hostname, ip)
output = node.create
ok _('wizard.node.creation_success')
return output
end
|
[
"def",
"create_new_node",
"(",
"project_root",
",",
"environment",
")",
"# Ask the hostname for node",
"hostname",
"=",
"ask_not_existing_hostname",
"(",
"project_root",
",",
"environment",
")",
"# Ask IP for node",
"ip",
"=",
"ask_ip",
"(",
"environment",
")",
"# Node creation",
"node",
"=",
"Bebox",
"::",
"Node",
".",
"new",
"(",
"environment",
",",
"project_root",
",",
"hostname",
",",
"ip",
")",
"output",
"=",
"node",
".",
"create",
"ok",
"_",
"(",
"'wizard.node.creation_success'",
")",
"return",
"output",
"end"
] |
Create a new node
|
[
"Create",
"a",
"new",
"node"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L9-L19
|
5,941 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.remove_node
|
def remove_node(project_root, environment, hostname)
# Ask for a node to remove
nodes = Bebox::Node.list(project_root, environment, 'nodes')
if nodes.count > 0
hostname = choose_option(nodes, _('wizard.node.choose_node'))
else
error _('wizard.node.no_nodes')%{environment: environment}
return true
end
# Ask for deletion confirmation
return warn(_('wizard.no_changes')) unless confirm_action?(_('wizard.node.confirm_deletion'))
# Node deletion
node = Bebox::Node.new(environment, project_root, hostname, nil)
output = node.remove
ok _('wizard.node.deletion_success')
return output
end
|
ruby
|
def remove_node(project_root, environment, hostname)
# Ask for a node to remove
nodes = Bebox::Node.list(project_root, environment, 'nodes')
if nodes.count > 0
hostname = choose_option(nodes, _('wizard.node.choose_node'))
else
error _('wizard.node.no_nodes')%{environment: environment}
return true
end
# Ask for deletion confirmation
return warn(_('wizard.no_changes')) unless confirm_action?(_('wizard.node.confirm_deletion'))
# Node deletion
node = Bebox::Node.new(environment, project_root, hostname, nil)
output = node.remove
ok _('wizard.node.deletion_success')
return output
end
|
[
"def",
"remove_node",
"(",
"project_root",
",",
"environment",
",",
"hostname",
")",
"# Ask for a node to remove",
"nodes",
"=",
"Bebox",
"::",
"Node",
".",
"list",
"(",
"project_root",
",",
"environment",
",",
"'nodes'",
")",
"if",
"nodes",
".",
"count",
">",
"0",
"hostname",
"=",
"choose_option",
"(",
"nodes",
",",
"_",
"(",
"'wizard.node.choose_node'",
")",
")",
"else",
"error",
"_",
"(",
"'wizard.node.no_nodes'",
")",
"%",
"{",
"environment",
":",
"environment",
"}",
"return",
"true",
"end",
"# Ask for deletion confirmation",
"return",
"warn",
"(",
"_",
"(",
"'wizard.no_changes'",
")",
")",
"unless",
"confirm_action?",
"(",
"_",
"(",
"'wizard.node.confirm_deletion'",
")",
")",
"# Node deletion",
"node",
"=",
"Bebox",
"::",
"Node",
".",
"new",
"(",
"environment",
",",
"project_root",
",",
"hostname",
",",
"nil",
")",
"output",
"=",
"node",
".",
"remove",
"ok",
"_",
"(",
"'wizard.node.deletion_success'",
")",
"return",
"output",
"end"
] |
Removes an existing node
|
[
"Removes",
"an",
"existing",
"node"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L22-L38
|
5,942 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.set_role
|
def set_role(project_root, environment)
roles = Bebox::Role.list(project_root)
nodes = Bebox::Node.list(project_root, environment, 'nodes')
node = choose_option(nodes, _('wizard.choose_node'))
role = choose_option(roles, _('wizard.choose_role'))
output = Bebox::Provision.associate_node_role(project_root, environment, node, role)
ok _('wizard.node.role_set_success')
return output
end
|
ruby
|
def set_role(project_root, environment)
roles = Bebox::Role.list(project_root)
nodes = Bebox::Node.list(project_root, environment, 'nodes')
node = choose_option(nodes, _('wizard.choose_node'))
role = choose_option(roles, _('wizard.choose_role'))
output = Bebox::Provision.associate_node_role(project_root, environment, node, role)
ok _('wizard.node.role_set_success')
return output
end
|
[
"def",
"set_role",
"(",
"project_root",
",",
"environment",
")",
"roles",
"=",
"Bebox",
"::",
"Role",
".",
"list",
"(",
"project_root",
")",
"nodes",
"=",
"Bebox",
"::",
"Node",
".",
"list",
"(",
"project_root",
",",
"environment",
",",
"'nodes'",
")",
"node",
"=",
"choose_option",
"(",
"nodes",
",",
"_",
"(",
"'wizard.choose_node'",
")",
")",
"role",
"=",
"choose_option",
"(",
"roles",
",",
"_",
"(",
"'wizard.choose_role'",
")",
")",
"output",
"=",
"Bebox",
"::",
"Provision",
".",
"associate_node_role",
"(",
"project_root",
",",
"environment",
",",
"node",
",",
"role",
")",
"ok",
"_",
"(",
"'wizard.node.role_set_success'",
")",
"return",
"output",
"end"
] |
Associate a role with a node in a environment
|
[
"Associate",
"a",
"role",
"with",
"a",
"node",
"in",
"a",
"environment"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L41-L49
|
5,943 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.prepare
|
def prepare(project_root, environment)
# Check already prepared nodes
nodes_to_prepare = check_nodes_to_prepare(project_root, environment)
# Output the nodes to be prepared
if nodes_to_prepare.count > 0
title _('wizard.node.prepare_title')
nodes_to_prepare.each{|node| msg(node.hostname)}
linebreak
# For all environments regenerate the deploy file
Bebox::Node.regenerate_deploy_file(project_root, environment, nodes_to_prepare)
# If environment is 'vagrant' Prepare and Up the machines
up_vagrant_machines(project_root, nodes_to_prepare) if environment == 'vagrant'
# For all the environments do the preparation
nodes_to_prepare.each do |node|
node.prepare
ok _('wizard.node.preparation_success')
end
else
warn _('wizard.node.no_prepare_nodes')
end
return true
end
|
ruby
|
def prepare(project_root, environment)
# Check already prepared nodes
nodes_to_prepare = check_nodes_to_prepare(project_root, environment)
# Output the nodes to be prepared
if nodes_to_prepare.count > 0
title _('wizard.node.prepare_title')
nodes_to_prepare.each{|node| msg(node.hostname)}
linebreak
# For all environments regenerate the deploy file
Bebox::Node.regenerate_deploy_file(project_root, environment, nodes_to_prepare)
# If environment is 'vagrant' Prepare and Up the machines
up_vagrant_machines(project_root, nodes_to_prepare) if environment == 'vagrant'
# For all the environments do the preparation
nodes_to_prepare.each do |node|
node.prepare
ok _('wizard.node.preparation_success')
end
else
warn _('wizard.node.no_prepare_nodes')
end
return true
end
|
[
"def",
"prepare",
"(",
"project_root",
",",
"environment",
")",
"# Check already prepared nodes",
"nodes_to_prepare",
"=",
"check_nodes_to_prepare",
"(",
"project_root",
",",
"environment",
")",
"# Output the nodes to be prepared",
"if",
"nodes_to_prepare",
".",
"count",
">",
"0",
"title",
"_",
"(",
"'wizard.node.prepare_title'",
")",
"nodes_to_prepare",
".",
"each",
"{",
"|",
"node",
"|",
"msg",
"(",
"node",
".",
"hostname",
")",
"}",
"linebreak",
"# For all environments regenerate the deploy file",
"Bebox",
"::",
"Node",
".",
"regenerate_deploy_file",
"(",
"project_root",
",",
"environment",
",",
"nodes_to_prepare",
")",
"# If environment is 'vagrant' Prepare and Up the machines",
"up_vagrant_machines",
"(",
"project_root",
",",
"nodes_to_prepare",
")",
"if",
"environment",
"==",
"'vagrant'",
"# For all the environments do the preparation",
"nodes_to_prepare",
".",
"each",
"do",
"|",
"node",
"|",
"node",
".",
"prepare",
"ok",
"_",
"(",
"'wizard.node.preparation_success'",
")",
"end",
"else",
"warn",
"_",
"(",
"'wizard.node.no_prepare_nodes'",
")",
"end",
"return",
"true",
"end"
] |
Prepare the nodes in a environment
|
[
"Prepare",
"the",
"nodes",
"in",
"a",
"environment"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L52-L73
|
5,944 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.check_nodes_to_prepare
|
def check_nodes_to_prepare(project_root, environment)
nodes_to_prepare = []
nodes = Bebox::Node.nodes_in_environment(project_root, environment, 'nodes')
prepared_nodes = Bebox::Node.list(project_root, environment, 'prepared_nodes')
nodes.each do |node|
if prepared_nodes.include?(node.hostname)
message = _('wizard.node.confirm_preparation')%{hostname: node.hostname, start: node.checkpoint_parameter_from_file('prepared_nodes', 'started_at'), end: node.checkpoint_parameter_from_file('prepared_nodes', 'finished_at')}
nodes_to_prepare << node if confirm_action?(message)
else
nodes_to_prepare << node
end
end
nodes_to_prepare
end
|
ruby
|
def check_nodes_to_prepare(project_root, environment)
nodes_to_prepare = []
nodes = Bebox::Node.nodes_in_environment(project_root, environment, 'nodes')
prepared_nodes = Bebox::Node.list(project_root, environment, 'prepared_nodes')
nodes.each do |node|
if prepared_nodes.include?(node.hostname)
message = _('wizard.node.confirm_preparation')%{hostname: node.hostname, start: node.checkpoint_parameter_from_file('prepared_nodes', 'started_at'), end: node.checkpoint_parameter_from_file('prepared_nodes', 'finished_at')}
nodes_to_prepare << node if confirm_action?(message)
else
nodes_to_prepare << node
end
end
nodes_to_prepare
end
|
[
"def",
"check_nodes_to_prepare",
"(",
"project_root",
",",
"environment",
")",
"nodes_to_prepare",
"=",
"[",
"]",
"nodes",
"=",
"Bebox",
"::",
"Node",
".",
"nodes_in_environment",
"(",
"project_root",
",",
"environment",
",",
"'nodes'",
")",
"prepared_nodes",
"=",
"Bebox",
"::",
"Node",
".",
"list",
"(",
"project_root",
",",
"environment",
",",
"'prepared_nodes'",
")",
"nodes",
".",
"each",
"do",
"|",
"node",
"|",
"if",
"prepared_nodes",
".",
"include?",
"(",
"node",
".",
"hostname",
")",
"message",
"=",
"_",
"(",
"'wizard.node.confirm_preparation'",
")",
"%",
"{",
"hostname",
":",
"node",
".",
"hostname",
",",
"start",
":",
"node",
".",
"checkpoint_parameter_from_file",
"(",
"'prepared_nodes'",
",",
"'started_at'",
")",
",",
"end",
":",
"node",
".",
"checkpoint_parameter_from_file",
"(",
"'prepared_nodes'",
",",
"'finished_at'",
")",
"}",
"nodes_to_prepare",
"<<",
"node",
"if",
"confirm_action?",
"(",
"message",
")",
"else",
"nodes_to_prepare",
"<<",
"node",
"end",
"end",
"nodes_to_prepare",
"end"
] |
Check the nodes already prepared and ask confirmation to re-do-it
|
[
"Check",
"the",
"nodes",
"already",
"prepared",
"and",
"ask",
"confirmation",
"to",
"re",
"-",
"do",
"-",
"it"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L82-L95
|
5,945 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.ask_not_existing_hostname
|
def ask_not_existing_hostname(project_root, environment)
hostname = ask_hostname(project_root, environment)
# Check if the node not exist
if node_exists?(project_root, environment, hostname)
error _('wizard.node.hostname_exist')
ask_hostname(project_root, environment)
else
return hostname
end
end
|
ruby
|
def ask_not_existing_hostname(project_root, environment)
hostname = ask_hostname(project_root, environment)
# Check if the node not exist
if node_exists?(project_root, environment, hostname)
error _('wizard.node.hostname_exist')
ask_hostname(project_root, environment)
else
return hostname
end
end
|
[
"def",
"ask_not_existing_hostname",
"(",
"project_root",
",",
"environment",
")",
"hostname",
"=",
"ask_hostname",
"(",
"project_root",
",",
"environment",
")",
"# Check if the node not exist",
"if",
"node_exists?",
"(",
"project_root",
",",
"environment",
",",
"hostname",
")",
"error",
"_",
"(",
"'wizard.node.hostname_exist'",
")",
"ask_hostname",
"(",
"project_root",
",",
"environment",
")",
"else",
"return",
"hostname",
"end",
"end"
] |
Keep asking for a hostname that not exist
|
[
"Keep",
"asking",
"for",
"a",
"hostname",
"that",
"not",
"exist"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L103-L112
|
5,946 |
codescrum/bebox
|
lib/bebox/wizards/node_wizard.rb
|
Bebox.NodeWizard.ask_ip
|
def ask_ip(environment)
ip = write_input(_('wizard.node.ask_ip'), nil, /\.(.*)/, _('wizard.node.valid_ip'))
# If the environment is not vagrant don't check ip free
return ip if environment != 'vagrant'
# Check if the ip address is free
if free_ip?(ip)
return ip
else
error _('wizard.node.non_free_ip')
ask_ip(environment)
end
end
|
ruby
|
def ask_ip(environment)
ip = write_input(_('wizard.node.ask_ip'), nil, /\.(.*)/, _('wizard.node.valid_ip'))
# If the environment is not vagrant don't check ip free
return ip if environment != 'vagrant'
# Check if the ip address is free
if free_ip?(ip)
return ip
else
error _('wizard.node.non_free_ip')
ask_ip(environment)
end
end
|
[
"def",
"ask_ip",
"(",
"environment",
")",
"ip",
"=",
"write_input",
"(",
"_",
"(",
"'wizard.node.ask_ip'",
")",
",",
"nil",
",",
"/",
"\\.",
"/",
",",
"_",
"(",
"'wizard.node.valid_ip'",
")",
")",
"# If the environment is not vagrant don't check ip free",
"return",
"ip",
"if",
"environment",
"!=",
"'vagrant'",
"# Check if the ip address is free",
"if",
"free_ip?",
"(",
"ip",
")",
"return",
"ip",
"else",
"error",
"_",
"(",
"'wizard.node.non_free_ip'",
")",
"ask_ip",
"(",
"environment",
")",
"end",
"end"
] |
Ask for the ip until is valid
|
[
"Ask",
"for",
"the",
"ip",
"until",
"is",
"valid"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/node_wizard.rb#L120-L131
|
5,947 |
arscan/mintkit
|
lib/mintkit/client.rb
|
Mintkit.Client.transactions
|
def transactions
raw_transactions = @agent.get("https://wwws.mint.com/transactionDownload.event?").body
transos = []
raw_transactions.split("\n").each_with_index do |line,index|
if index > 1
line_array = line.split(",")
transaction = {
:date => Date.strptime(remove_quotes(line_array[0]), '%m/%d/%Y'),
:description=>remove_quotes(line_array[1]),
:original_description=>remove_quotes(line_array[2]),
:amount=>remove_quotes(line_array[3]).to_f,
:type=>remove_quotes(line_array[4]),
:category=>remove_quotes(line_array[5]),
:account=>remove_quotes(line_array[6]),
:labels=>remove_quotes(line_array[7]),
:notes=>remove_quotes(line_array[8])
}
transos << transaction
if block_given?
yield transaction
end
end
end
transos
end
|
ruby
|
def transactions
raw_transactions = @agent.get("https://wwws.mint.com/transactionDownload.event?").body
transos = []
raw_transactions.split("\n").each_with_index do |line,index|
if index > 1
line_array = line.split(",")
transaction = {
:date => Date.strptime(remove_quotes(line_array[0]), '%m/%d/%Y'),
:description=>remove_quotes(line_array[1]),
:original_description=>remove_quotes(line_array[2]),
:amount=>remove_quotes(line_array[3]).to_f,
:type=>remove_quotes(line_array[4]),
:category=>remove_quotes(line_array[5]),
:account=>remove_quotes(line_array[6]),
:labels=>remove_quotes(line_array[7]),
:notes=>remove_quotes(line_array[8])
}
transos << transaction
if block_given?
yield transaction
end
end
end
transos
end
|
[
"def",
"transactions",
"raw_transactions",
"=",
"@agent",
".",
"get",
"(",
"\"https://wwws.mint.com/transactionDownload.event?\"",
")",
".",
"body",
"transos",
"=",
"[",
"]",
"raw_transactions",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"each_with_index",
"do",
"|",
"line",
",",
"index",
"|",
"if",
"index",
">",
"1",
"line_array",
"=",
"line",
".",
"split",
"(",
"\",\"",
")",
"transaction",
"=",
"{",
":date",
"=>",
"Date",
".",
"strptime",
"(",
"remove_quotes",
"(",
"line_array",
"[",
"0",
"]",
")",
",",
"'%m/%d/%Y'",
")",
",",
":description",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"1",
"]",
")",
",",
":original_description",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"2",
"]",
")",
",",
":amount",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"3",
"]",
")",
".",
"to_f",
",",
":type",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"4",
"]",
")",
",",
":category",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"5",
"]",
")",
",",
":account",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"6",
"]",
")",
",",
":labels",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"7",
"]",
")",
",",
":notes",
"=>",
"remove_quotes",
"(",
"line_array",
"[",
"8",
"]",
")",
"}",
"transos",
"<<",
"transaction",
"if",
"block_given?",
"yield",
"transaction",
"end",
"end",
"end",
"transos",
"end"
] |
login to my account
get all the transactions
|
[
"login",
"to",
"my",
"account",
"get",
"all",
"the",
"transactions"
] |
b1f7a87b3f10f0e8d7144d6f3e7c778cfbd2b265
|
https://github.com/arscan/mintkit/blob/b1f7a87b3f10f0e8d7144d6f3e7c778cfbd2b265/lib/mintkit/client.rb#L19-L50
|
5,948 |
flyingmachine/whoops_logger
|
lib/whoops_logger/configuration.rb
|
WhoopsLogger.Configuration.set_with_string
|
def set_with_string(config)
if File.exists?(config)
set_with_yaml(File.read(config))
else
set_with_yaml(config)
end
end
|
ruby
|
def set_with_string(config)
if File.exists?(config)
set_with_yaml(File.read(config))
else
set_with_yaml(config)
end
end
|
[
"def",
"set_with_string",
"(",
"config",
")",
"if",
"File",
".",
"exists?",
"(",
"config",
")",
"set_with_yaml",
"(",
"File",
".",
"read",
"(",
"config",
")",
")",
"else",
"set_with_yaml",
"(",
"config",
")",
"end",
"end"
] |
String should be either a filename or YAML
|
[
"String",
"should",
"be",
"either",
"a",
"filename",
"or",
"YAML"
] |
e1db5362b67c58f60018c9e0d653094fbe286014
|
https://github.com/flyingmachine/whoops_logger/blob/e1db5362b67c58f60018c9e0d653094fbe286014/lib/whoops_logger/configuration.rb#L106-L112
|
5,949 |
kete/kete_trackable_items
|
lib/kete_trackable_items/list_management_controllers.rb
|
KeteTrackableItems.ListManagementControllers.remove_from_list
|
def remove_from_list
begin
matching_results_ids = session[:matching_results_ids]
matching_results_ids.delete(params[:remove_id].to_i)
session[:matching_results_ids] = matching_results_ids
render :nothing => true
rescue
render :nothing => true, :status => 500
end
end
|
ruby
|
def remove_from_list
begin
matching_results_ids = session[:matching_results_ids]
matching_results_ids.delete(params[:remove_id].to_i)
session[:matching_results_ids] = matching_results_ids
render :nothing => true
rescue
render :nothing => true, :status => 500
end
end
|
[
"def",
"remove_from_list",
"begin",
"matching_results_ids",
"=",
"session",
"[",
":matching_results_ids",
"]",
"matching_results_ids",
".",
"delete",
"(",
"params",
"[",
":remove_id",
"]",
".",
"to_i",
")",
"session",
"[",
":matching_results_ids",
"]",
"=",
"matching_results_ids",
"render",
":nothing",
"=>",
"true",
"rescue",
"render",
":nothing",
"=>",
"true",
",",
":status",
"=>",
"500",
"end",
"end"
] |
assumes matching_results_ids in the session
drops a given remove_id from the session variable
|
[
"assumes",
"matching_results_ids",
"in",
"the",
"session",
"drops",
"a",
"given",
"remove_id",
"from",
"the",
"session",
"variable"
] |
5998ecd83967108c1ed1378161e43feb80d6b886
|
https://github.com/kete/kete_trackable_items/blob/5998ecd83967108c1ed1378161e43feb80d6b886/lib/kete_trackable_items/list_management_controllers.rb#L7-L16
|
5,950 |
kete/kete_trackable_items
|
lib/kete_trackable_items/list_management_controllers.rb
|
KeteTrackableItems.ListManagementControllers.restore_to_list
|
def restore_to_list
begin
matching_results_ids = session[:matching_results_ids]
session[:matching_results_ids] = matching_results_ids << params[:restore_id].to_i
render :nothing => true
rescue
render :nothing => true, :status => 500
end
end
|
ruby
|
def restore_to_list
begin
matching_results_ids = session[:matching_results_ids]
session[:matching_results_ids] = matching_results_ids << params[:restore_id].to_i
render :nothing => true
rescue
render :nothing => true, :status => 500
end
end
|
[
"def",
"restore_to_list",
"begin",
"matching_results_ids",
"=",
"session",
"[",
":matching_results_ids",
"]",
"session",
"[",
":matching_results_ids",
"]",
"=",
"matching_results_ids",
"<<",
"params",
"[",
":restore_id",
"]",
".",
"to_i",
"render",
":nothing",
"=>",
"true",
"rescue",
"render",
":nothing",
"=>",
"true",
",",
":status",
"=>",
"500",
"end",
"end"
] |
assumes matching_results_ids in the session
puts back a given restore_id in the session variable
|
[
"assumes",
"matching_results_ids",
"in",
"the",
"session",
"puts",
"back",
"a",
"given",
"restore_id",
"in",
"the",
"session",
"variable"
] |
5998ecd83967108c1ed1378161e43feb80d6b886
|
https://github.com/kete/kete_trackable_items/blob/5998ecd83967108c1ed1378161e43feb80d6b886/lib/kete_trackable_items/list_management_controllers.rb#L20-L28
|
5,951 |
Thermatix/ruta
|
lib/ruta/context.rb
|
Ruta.Context.sub_context
|
def sub_context id,ref,attribs={}
@sub_contexts << ref
self.elements[id] = {
attributes: attribs,
type: :sub_context,
content: ref,
}
end
|
ruby
|
def sub_context id,ref,attribs={}
@sub_contexts << ref
self.elements[id] = {
attributes: attribs,
type: :sub_context,
content: ref,
}
end
|
[
"def",
"sub_context",
"id",
",",
"ref",
",",
"attribs",
"=",
"{",
"}",
"@sub_contexts",
"<<",
"ref",
"self",
".",
"elements",
"[",
"id",
"]",
"=",
"{",
"attributes",
":",
"attribs",
",",
"type",
":",
":sub_context",
",",
"content",
":",
"ref",
",",
"}",
"end"
] |
mount a context as a sub context here
@param [Symbol] id of component to mount context to
@param [Symbol] ref of context to be mounted
@param [{Symbol => String,Number,Boolean}] list of attributes to attach to tag
|
[
"mount",
"a",
"context",
"as",
"a",
"sub",
"context",
"here"
] |
b4a6e3bc7c0c4b66c804023d638b173e3f61e157
|
https://github.com/Thermatix/ruta/blob/b4a6e3bc7c0c4b66c804023d638b173e3f61e157/lib/ruta/context.rb#L50-L57
|
5,952 |
smartdict/smartdict-core
|
lib/smartdict/translator/base.rb
|
Smartdict.Translator::Base.call
|
def call(word, opts)
validate_opts!(opts)
driver = Smartdict::Core::DriverManager.find(opts[:driver])
translation_model = Models::Translation.find(word, opts[:from_lang], opts[:to_lang], opts[:driver])
unless translation_model
translation = driver.translate(word, opts[:from_lang], opts[:to_lang])
translation_model = Models::Translation.create_from_struct(translation)
end
log_query(translation_model) if opts[:log]
translation_model.to_struct
end
|
ruby
|
def call(word, opts)
validate_opts!(opts)
driver = Smartdict::Core::DriverManager.find(opts[:driver])
translation_model = Models::Translation.find(word, opts[:from_lang], opts[:to_lang], opts[:driver])
unless translation_model
translation = driver.translate(word, opts[:from_lang], opts[:to_lang])
translation_model = Models::Translation.create_from_struct(translation)
end
log_query(translation_model) if opts[:log]
translation_model.to_struct
end
|
[
"def",
"call",
"(",
"word",
",",
"opts",
")",
"validate_opts!",
"(",
"opts",
")",
"driver",
"=",
"Smartdict",
"::",
"Core",
"::",
"DriverManager",
".",
"find",
"(",
"opts",
"[",
":driver",
"]",
")",
"translation_model",
"=",
"Models",
"::",
"Translation",
".",
"find",
"(",
"word",
",",
"opts",
"[",
":from_lang",
"]",
",",
"opts",
"[",
":to_lang",
"]",
",",
"opts",
"[",
":driver",
"]",
")",
"unless",
"translation_model",
"translation",
"=",
"driver",
".",
"translate",
"(",
"word",
",",
"opts",
"[",
":from_lang",
"]",
",",
"opts",
"[",
":to_lang",
"]",
")",
"translation_model",
"=",
"Models",
"::",
"Translation",
".",
"create_from_struct",
"(",
"translation",
")",
"end",
"log_query",
"(",
"translation_model",
")",
"if",
"opts",
"[",
":log",
"]",
"translation_model",
".",
"to_struct",
"end"
] |
Just to make the interface compatible
|
[
"Just",
"to",
"make",
"the",
"interface",
"compatible"
] |
d2a83a7ca10daa085ffb740837891057a9c2bcea
|
https://github.com/smartdict/smartdict-core/blob/d2a83a7ca10daa085ffb740837891057a9c2bcea/lib/smartdict/translator/base.rb#L8-L19
|
5,953 |
mdoza/mongoid_multiparams
|
lib/mongoid_multiparams.rb
|
Mongoid.MultiParameterAttributes.process_attributes
|
def process_attributes(attrs = nil)
if attrs
errors = []
attributes = attrs.class.new
attributes.permit! if attrs.respond_to?(:permitted?) && attrs.permitted?
multi_parameter_attributes = {}
attrs.each_pair do |key, value|
if key =~ /\A([^\(]+)\((\d+)([if])\)$/
key, index = $1, $2.to_i
(multi_parameter_attributes[key] ||= {})[index] = value.empty? ? nil : value.send("to_#{$3}")
else
attributes[key] = value
end
end
multi_parameter_attributes.each_pair do |key, values|
begin
values = (values.keys.min..values.keys.max).map { |i| values[i] }
field = self.class.fields[database_field_name(key)]
attributes[key] = instantiate_object(field, values)
rescue => e
errors << Errors::AttributeAssignmentError.new(
"error on assignment #{values.inspect} to #{key}", e, key
)
end
end
unless errors.empty?
raise Errors::MultiparameterAssignmentErrors.new(errors),
"#{errors.size} error(s) on assignment of multiparameter attributes"
end
super(attributes)
else
super
end
end
|
ruby
|
def process_attributes(attrs = nil)
if attrs
errors = []
attributes = attrs.class.new
attributes.permit! if attrs.respond_to?(:permitted?) && attrs.permitted?
multi_parameter_attributes = {}
attrs.each_pair do |key, value|
if key =~ /\A([^\(]+)\((\d+)([if])\)$/
key, index = $1, $2.to_i
(multi_parameter_attributes[key] ||= {})[index] = value.empty? ? nil : value.send("to_#{$3}")
else
attributes[key] = value
end
end
multi_parameter_attributes.each_pair do |key, values|
begin
values = (values.keys.min..values.keys.max).map { |i| values[i] }
field = self.class.fields[database_field_name(key)]
attributes[key] = instantiate_object(field, values)
rescue => e
errors << Errors::AttributeAssignmentError.new(
"error on assignment #{values.inspect} to #{key}", e, key
)
end
end
unless errors.empty?
raise Errors::MultiparameterAssignmentErrors.new(errors),
"#{errors.size} error(s) on assignment of multiparameter attributes"
end
super(attributes)
else
super
end
end
|
[
"def",
"process_attributes",
"(",
"attrs",
"=",
"nil",
")",
"if",
"attrs",
"errors",
"=",
"[",
"]",
"attributes",
"=",
"attrs",
".",
"class",
".",
"new",
"attributes",
".",
"permit!",
"if",
"attrs",
".",
"respond_to?",
"(",
":permitted?",
")",
"&&",
"attrs",
".",
"permitted?",
"multi_parameter_attributes",
"=",
"{",
"}",
"attrs",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"key",
"=~",
"/",
"\\A",
"\\(",
"\\(",
"\\d",
"\\)",
"/",
"key",
",",
"index",
"=",
"$1",
",",
"$2",
".",
"to_i",
"(",
"multi_parameter_attributes",
"[",
"key",
"]",
"||=",
"{",
"}",
")",
"[",
"index",
"]",
"=",
"value",
".",
"empty?",
"?",
"nil",
":",
"value",
".",
"send",
"(",
"\"to_#{$3}\"",
")",
"else",
"attributes",
"[",
"key",
"]",
"=",
"value",
"end",
"end",
"multi_parameter_attributes",
".",
"each_pair",
"do",
"|",
"key",
",",
"values",
"|",
"begin",
"values",
"=",
"(",
"values",
".",
"keys",
".",
"min",
"..",
"values",
".",
"keys",
".",
"max",
")",
".",
"map",
"{",
"|",
"i",
"|",
"values",
"[",
"i",
"]",
"}",
"field",
"=",
"self",
".",
"class",
".",
"fields",
"[",
"database_field_name",
"(",
"key",
")",
"]",
"attributes",
"[",
"key",
"]",
"=",
"instantiate_object",
"(",
"field",
",",
"values",
")",
"rescue",
"=>",
"e",
"errors",
"<<",
"Errors",
"::",
"AttributeAssignmentError",
".",
"new",
"(",
"\"error on assignment #{values.inspect} to #{key}\"",
",",
"e",
",",
"key",
")",
"end",
"end",
"unless",
"errors",
".",
"empty?",
"raise",
"Errors",
"::",
"MultiparameterAssignmentErrors",
".",
"new",
"(",
"errors",
")",
",",
"\"#{errors.size} error(s) on assignment of multiparameter attributes\"",
"end",
"super",
"(",
"attributes",
")",
"else",
"super",
"end",
"end"
] |
Process the provided attributes casting them to their proper values if a
field exists for them on the document. This will be limited to only the
attributes provided in the suppied +Hash+ so that no extra nil values get
put into the document's attributes.
@example Process the attributes.
person.process_attributes(:title => "sir", :age => 40)
@param [ Hash ] attrs The attributes to set.
@since 2.0.0.rc.7
|
[
"Process",
"the",
"provided",
"attributes",
"casting",
"them",
"to",
"their",
"proper",
"values",
"if",
"a",
"field",
"exists",
"for",
"them",
"on",
"the",
"document",
".",
"This",
"will",
"be",
"limited",
"to",
"only",
"the",
"attributes",
"provided",
"in",
"the",
"suppied",
"+",
"Hash",
"+",
"so",
"that",
"no",
"extra",
"nil",
"values",
"get",
"put",
"into",
"the",
"document",
"s",
"attributes",
"."
] |
9cbc4ed87a27f6635184b472ef2e5c4fc4160f74
|
https://github.com/mdoza/mongoid_multiparams/blob/9cbc4ed87a27f6635184b472ef2e5c4fc4160f74/lib/mongoid_multiparams.rb#L79-L115
|
5,954 |
inside-track/remi
|
lib/remi/data_subjects/s3_file.rb
|
Remi.Loader::S3File.load
|
def load(data)
init_kms(@kms_opt)
@logger.info "Writing file #{data} to S3 #{@bucket_name} as #{@remote_path}"
s3.bucket(@bucket_name).object(@remote_path).upload_file(data, encrypt_args)
true
end
|
ruby
|
def load(data)
init_kms(@kms_opt)
@logger.info "Writing file #{data} to S3 #{@bucket_name} as #{@remote_path}"
s3.bucket(@bucket_name).object(@remote_path).upload_file(data, encrypt_args)
true
end
|
[
"def",
"load",
"(",
"data",
")",
"init_kms",
"(",
"@kms_opt",
")",
"@logger",
".",
"info",
"\"Writing file #{data} to S3 #{@bucket_name} as #{@remote_path}\"",
"s3",
".",
"bucket",
"(",
"@bucket_name",
")",
".",
"object",
"(",
"@remote_path",
")",
".",
"upload_file",
"(",
"data",
",",
"encrypt_args",
")",
"true",
"end"
] |
Copies data to S3
@param data [Object] The path to the file in the temporary work location
@return [true] On success
|
[
"Copies",
"data",
"to",
"S3"
] |
f7e5f28f08f8c0403e04cd82d6fc14b6b2c362a7
|
https://github.com/inside-track/remi/blob/f7e5f28f08f8c0403e04cd82d6fc14b6b2c362a7/lib/remi/data_subjects/s3_file.rb#L252-L258
|
5,955 |
OiNutter/skeletor
|
lib/skeletor/builder.rb
|
Skeletor.Builder.build_skeleton
|
def build_skeleton(dirs,path=@path)
dirs.each{
|node|
if node.kind_of?(Hash) && !node.empty?()
node.each_pair{
|dir,content|
dir = replace_tags(dir)
puts 'Creating directory ' + File.join(path,dir)
Dir.mkdir(File.join(path,dir))
if content.kind_of?(Array) && !content.empty?()
build_skeleton(content,File.join(path,dir))
end
}
elsif node.kind_of?(Array) && !node.empty?()
node.each{
|file|
write_file(file,path)
}
end
}
end
|
ruby
|
def build_skeleton(dirs,path=@path)
dirs.each{
|node|
if node.kind_of?(Hash) && !node.empty?()
node.each_pair{
|dir,content|
dir = replace_tags(dir)
puts 'Creating directory ' + File.join(path,dir)
Dir.mkdir(File.join(path,dir))
if content.kind_of?(Array) && !content.empty?()
build_skeleton(content,File.join(path,dir))
end
}
elsif node.kind_of?(Array) && !node.empty?()
node.each{
|file|
write_file(file,path)
}
end
}
end
|
[
"def",
"build_skeleton",
"(",
"dirs",
",",
"path",
"=",
"@path",
")",
"dirs",
".",
"each",
"{",
"|",
"node",
"|",
"if",
"node",
".",
"kind_of?",
"(",
"Hash",
")",
"&&",
"!",
"node",
".",
"empty?",
"(",
")",
"node",
".",
"each_pair",
"{",
"|",
"dir",
",",
"content",
"|",
"dir",
"=",
"replace_tags",
"(",
"dir",
")",
"puts",
"'Creating directory '",
"+",
"File",
".",
"join",
"(",
"path",
",",
"dir",
")",
"Dir",
".",
"mkdir",
"(",
"File",
".",
"join",
"(",
"path",
",",
"dir",
")",
")",
"if",
"content",
".",
"kind_of?",
"(",
"Array",
")",
"&&",
"!",
"content",
".",
"empty?",
"(",
")",
"build_skeleton",
"(",
"content",
",",
"File",
".",
"join",
"(",
"path",
",",
"dir",
")",
")",
"end",
"}",
"elsif",
"node",
".",
"kind_of?",
"(",
"Array",
")",
"&&",
"!",
"node",
".",
"empty?",
"(",
")",
"node",
".",
"each",
"{",
"|",
"file",
"|",
"write_file",
"(",
"file",
",",
"path",
")",
"}",
"end",
"}",
"end"
] |
Builds the directory structure
|
[
"Builds",
"the",
"directory",
"structure"
] |
c3996c346bbf8009f7135855aabfd4f411aaa2e1
|
https://github.com/OiNutter/skeletor/blob/c3996c346bbf8009f7135855aabfd4f411aaa2e1/lib/skeletor/builder.rb#L46-L76
|
5,956 |
OiNutter/skeletor
|
lib/skeletor/builder.rb
|
Skeletor.Builder.write_file
|
def write_file(file,path)
#if a pre-existing file is specified in the includes list, copy that, if not write a blank file
if @template.includes.has_key?(file)
begin
content = Includes.copy_include(@template.includes[file],@template.path)
file = replace_tags(file)
rescue TypeError => e
puts e.message
exit
end
else
file = replace_tags(file)
puts 'Creating blank file: ' + File.join(path,file)
content=''
end
File.open(File.join(path,file),'w'){|f| f.write(replace_tags(content))}
end
|
ruby
|
def write_file(file,path)
#if a pre-existing file is specified in the includes list, copy that, if not write a blank file
if @template.includes.has_key?(file)
begin
content = Includes.copy_include(@template.includes[file],@template.path)
file = replace_tags(file)
rescue TypeError => e
puts e.message
exit
end
else
file = replace_tags(file)
puts 'Creating blank file: ' + File.join(path,file)
content=''
end
File.open(File.join(path,file),'w'){|f| f.write(replace_tags(content))}
end
|
[
"def",
"write_file",
"(",
"file",
",",
"path",
")",
"#if a pre-existing file is specified in the includes list, copy that, if not write a blank file ",
"if",
"@template",
".",
"includes",
".",
"has_key?",
"(",
"file",
")",
"begin",
"content",
"=",
"Includes",
".",
"copy_include",
"(",
"@template",
".",
"includes",
"[",
"file",
"]",
",",
"@template",
".",
"path",
")",
"file",
"=",
"replace_tags",
"(",
"file",
")",
"rescue",
"TypeError",
"=>",
"e",
"puts",
"e",
".",
"message",
"exit",
"end",
"else",
"file",
"=",
"replace_tags",
"(",
"file",
")",
"puts",
"'Creating blank file: '",
"+",
"File",
".",
"join",
"(",
"path",
",",
"file",
")",
"content",
"=",
"''",
"end",
"File",
".",
"open",
"(",
"File",
".",
"join",
"(",
"path",
",",
"file",
")",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"replace_tags",
"(",
"content",
")",
")",
"}",
"end"
] |
Checks if file is listed in the includes list and if so copies it from
the given location. If not it creates a blank file.
|
[
"Checks",
"if",
"file",
"is",
"listed",
"in",
"the",
"includes",
"list",
"and",
"if",
"so",
"copies",
"it",
"from",
"the",
"given",
"location",
".",
"If",
"not",
"it",
"creates",
"a",
"blank",
"file",
"."
] |
c3996c346bbf8009f7135855aabfd4f411aaa2e1
|
https://github.com/OiNutter/skeletor/blob/c3996c346bbf8009f7135855aabfd4f411aaa2e1/lib/skeletor/builder.rb#L98-L114
|
5,957 |
OiNutter/skeletor
|
lib/skeletor/builder.rb
|
Skeletor.Builder.execute_tasks
|
def execute_tasks(tasks,template_path)
if File.exists?(File.expand_path(File.join(template_path,'tasks.rb')))
load File.expand_path(File.join(template_path,'tasks.rb'))
end
tasks.each{
|task|
puts 'Running Task: ' + task
task = replace_tags(task);
options = task.split(', ')
action = options.slice!(0)
if(Tasks.respond_to?(action))
Tasks.send action, options.join(', ')
else
send action, options.join(', ')
end
}
end
|
ruby
|
def execute_tasks(tasks,template_path)
if File.exists?(File.expand_path(File.join(template_path,'tasks.rb')))
load File.expand_path(File.join(template_path,'tasks.rb'))
end
tasks.each{
|task|
puts 'Running Task: ' + task
task = replace_tags(task);
options = task.split(', ')
action = options.slice!(0)
if(Tasks.respond_to?(action))
Tasks.send action, options.join(', ')
else
send action, options.join(', ')
end
}
end
|
[
"def",
"execute_tasks",
"(",
"tasks",
",",
"template_path",
")",
"if",
"File",
".",
"exists?",
"(",
"File",
".",
"expand_path",
"(",
"File",
".",
"join",
"(",
"template_path",
",",
"'tasks.rb'",
")",
")",
")",
"load",
"File",
".",
"expand_path",
"(",
"File",
".",
"join",
"(",
"template_path",
",",
"'tasks.rb'",
")",
")",
"end",
"tasks",
".",
"each",
"{",
"|",
"task",
"|",
"puts",
"'Running Task: '",
"+",
"task",
"task",
"=",
"replace_tags",
"(",
"task",
")",
";",
"options",
"=",
"task",
".",
"split",
"(",
"', '",
")",
"action",
"=",
"options",
".",
"slice!",
"(",
"0",
")",
"if",
"(",
"Tasks",
".",
"respond_to?",
"(",
"action",
")",
")",
"Tasks",
".",
"send",
"action",
",",
"options",
".",
"join",
"(",
"', '",
")",
"else",
"send",
"action",
",",
"options",
".",
"join",
"(",
"', '",
")",
"end",
"}",
"end"
] |
Parses the task string and runs the task.
Will check *Skeleton::Tasks* module first before running tasks
from the `tasks.rb` file in the template directory.
|
[
"Parses",
"the",
"task",
"string",
"and",
"runs",
"the",
"task",
"."
] |
c3996c346bbf8009f7135855aabfd4f411aaa2e1
|
https://github.com/OiNutter/skeletor/blob/c3996c346bbf8009f7135855aabfd4f411aaa2e1/lib/skeletor/builder.rb#L120-L144
|
5,958 |
wedesoft/multiarray
|
lib/multiarray/pointer.rb
|
Hornetseye.Pointer_.assign
|
def assign( value )
if @value.respond_to? :assign
@value.assign value.simplify.get
else
@value = value.simplify.get
end
value
end
|
ruby
|
def assign( value )
if @value.respond_to? :assign
@value.assign value.simplify.get
else
@value = value.simplify.get
end
value
end
|
[
"def",
"assign",
"(",
"value",
")",
"if",
"@value",
".",
"respond_to?",
":assign",
"@value",
".",
"assign",
"value",
".",
"simplify",
".",
"get",
"else",
"@value",
"=",
"value",
".",
"simplify",
".",
"get",
"end",
"value",
"end"
] |
Store a value in this native element
@param [Object] value New value for native element.
@return [Object] Returns +value+.
@private
|
[
"Store",
"a",
"value",
"in",
"this",
"native",
"element"
] |
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
|
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/pointer.rb#L178-L185
|
5,959 |
wedesoft/multiarray
|
lib/multiarray/pointer.rb
|
Hornetseye.Pointer_.store
|
def store( value )
result = value.simplify
self.class.target.new(result.get).write @value
result
end
|
ruby
|
def store( value )
result = value.simplify
self.class.target.new(result.get).write @value
result
end
|
[
"def",
"store",
"(",
"value",
")",
"result",
"=",
"value",
".",
"simplify",
"self",
".",
"class",
".",
"target",
".",
"new",
"(",
"result",
".",
"get",
")",
".",
"write",
"@value",
"result",
"end"
] |
Store new value in this pointer
@param [Object] value New value for this pointer object.
@return [Object] Returns +value+.
@private
|
[
"Store",
"new",
"value",
"in",
"this",
"pointer"
] |
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
|
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/pointer.rb#L194-L198
|
5,960 |
stormbrew/user_input
|
lib/user_input/option_parser.rb
|
UserInput.OptionParser.define_value
|
def define_value(short_name, long_name, description, flag, default_value, validate = nil)
short_name = short_name.to_s
long_name = long_name.to_s
if (short_name.length != 1)
raise ArgumentError, "Short name must be one character long (#{short_name})"
end
if (long_name.length < 2)
raise ArgumentError, "Long name must be more than one character long (#{long_name})"
end
info = Info.new(short_name, long_name, description, flag, default_value, nil, validate)
@options[long_name] = info
@options[short_name] = info
@order.push(info)
method_name = long_name.gsub('-','_')
method_name << "?" if (flag)
(class <<self; self; end).class_eval do
define_method(method_name.to_sym) do
return @options[long_name].value || @options[long_name].default_value
end
end
return self
end
|
ruby
|
def define_value(short_name, long_name, description, flag, default_value, validate = nil)
short_name = short_name.to_s
long_name = long_name.to_s
if (short_name.length != 1)
raise ArgumentError, "Short name must be one character long (#{short_name})"
end
if (long_name.length < 2)
raise ArgumentError, "Long name must be more than one character long (#{long_name})"
end
info = Info.new(short_name, long_name, description, flag, default_value, nil, validate)
@options[long_name] = info
@options[short_name] = info
@order.push(info)
method_name = long_name.gsub('-','_')
method_name << "?" if (flag)
(class <<self; self; end).class_eval do
define_method(method_name.to_sym) do
return @options[long_name].value || @options[long_name].default_value
end
end
return self
end
|
[
"def",
"define_value",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"flag",
",",
"default_value",
",",
"validate",
"=",
"nil",
")",
"short_name",
"=",
"short_name",
".",
"to_s",
"long_name",
"=",
"long_name",
".",
"to_s",
"if",
"(",
"short_name",
".",
"length",
"!=",
"1",
")",
"raise",
"ArgumentError",
",",
"\"Short name must be one character long (#{short_name})\"",
"end",
"if",
"(",
"long_name",
".",
"length",
"<",
"2",
")",
"raise",
"ArgumentError",
",",
"\"Long name must be more than one character long (#{long_name})\"",
"end",
"info",
"=",
"Info",
".",
"new",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"flag",
",",
"default_value",
",",
"nil",
",",
"validate",
")",
"@options",
"[",
"long_name",
"]",
"=",
"info",
"@options",
"[",
"short_name",
"]",
"=",
"info",
"@order",
".",
"push",
"(",
"info",
")",
"method_name",
"=",
"long_name",
".",
"gsub",
"(",
"'-'",
",",
"'_'",
")",
"method_name",
"<<",
"\"?\"",
"if",
"(",
"flag",
")",
"(",
"class",
"<<",
"self",
";",
"self",
";",
"end",
")",
".",
"class_eval",
"do",
"define_method",
"(",
"method_name",
".",
"to_sym",
")",
"do",
"return",
"@options",
"[",
"long_name",
"]",
".",
"value",
"||",
"@options",
"[",
"long_name",
"]",
".",
"default_value",
"end",
"end",
"return",
"self",
"end"
] |
If a block is passed in, it is given self.
|
[
"If",
"a",
"block",
"is",
"passed",
"in",
"it",
"is",
"given",
"self",
"."
] |
593a1deb08f0634089d25542971ad0ac57542259
|
https://github.com/stormbrew/user_input/blob/593a1deb08f0634089d25542971ad0ac57542259/lib/user_input/option_parser.rb#L52-L78
|
5,961 |
stormbrew/user_input
|
lib/user_input/option_parser.rb
|
UserInput.OptionParser.argument
|
def argument(short_name, long_name, description, default_value, validate = nil, &block)
return define_value(short_name, long_name, description, false, default_value, validate || block)
end
|
ruby
|
def argument(short_name, long_name, description, default_value, validate = nil, &block)
return define_value(short_name, long_name, description, false, default_value, validate || block)
end
|
[
"def",
"argument",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"default_value",
",",
"validate",
"=",
"nil",
",",
"&",
"block",
")",
"return",
"define_value",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"false",
",",
"default_value",
",",
"validate",
"||",
"block",
")",
"end"
] |
This defines a command line argument that takes a value.
|
[
"This",
"defines",
"a",
"command",
"line",
"argument",
"that",
"takes",
"a",
"value",
"."
] |
593a1deb08f0634089d25542971ad0ac57542259
|
https://github.com/stormbrew/user_input/blob/593a1deb08f0634089d25542971ad0ac57542259/lib/user_input/option_parser.rb#L89-L91
|
5,962 |
stormbrew/user_input
|
lib/user_input/option_parser.rb
|
UserInput.OptionParser.flag
|
def flag(short_name, long_name, description, &block)
return define_value(short_name, long_name, description, true, false, block)
end
|
ruby
|
def flag(short_name, long_name, description, &block)
return define_value(short_name, long_name, description, true, false, block)
end
|
[
"def",
"flag",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"&",
"block",
")",
"return",
"define_value",
"(",
"short_name",
",",
"long_name",
",",
"description",
",",
"true",
",",
"false",
",",
"block",
")",
"end"
] |
This defines a command line argument that's either on or off based on the presense
of the flag.
|
[
"This",
"defines",
"a",
"command",
"line",
"argument",
"that",
"s",
"either",
"on",
"or",
"off",
"based",
"on",
"the",
"presense",
"of",
"the",
"flag",
"."
] |
593a1deb08f0634089d25542971ad0ac57542259
|
https://github.com/stormbrew/user_input/blob/593a1deb08f0634089d25542971ad0ac57542259/lib/user_input/option_parser.rb#L95-L97
|
5,963 |
mrsimonfletcher/roroacms
|
app/controllers/roroacms/setup_controller.rb
|
Roroacms.SetupController.create
|
def create
# To do update this table we loop through the fields and update the key with the value.
# In order to do this we need to remove any unnecessary keys from the params hash
remove_unwanted_keys
# loop through the param fields and update the key with the value
validation = Setting.manual_validation(params)
respond_to do |format|
if validation.blank?
Setting.save_data(params)
clear_cache
format.html { redirect_to administrator_setup_index_path, notice: I18n.t("controllers.admin.setup.general.success") }
else
format.html {
# add breadcrumb and set title
@settings = params
@settings['errors'] = validation
render action: "index"
}
end
end
end
|
ruby
|
def create
# To do update this table we loop through the fields and update the key with the value.
# In order to do this we need to remove any unnecessary keys from the params hash
remove_unwanted_keys
# loop through the param fields and update the key with the value
validation = Setting.manual_validation(params)
respond_to do |format|
if validation.blank?
Setting.save_data(params)
clear_cache
format.html { redirect_to administrator_setup_index_path, notice: I18n.t("controllers.admin.setup.general.success") }
else
format.html {
# add breadcrumb and set title
@settings = params
@settings['errors'] = validation
render action: "index"
}
end
end
end
|
[
"def",
"create",
"# To do update this table we loop through the fields and update the key with the value.",
"# In order to do this we need to remove any unnecessary keys from the params hash",
"remove_unwanted_keys",
"# loop through the param fields and update the key with the value",
"validation",
"=",
"Setting",
".",
"manual_validation",
"(",
"params",
")",
"respond_to",
"do",
"|",
"format",
"|",
"if",
"validation",
".",
"blank?",
"Setting",
".",
"save_data",
"(",
"params",
")",
"clear_cache",
"format",
".",
"html",
"{",
"redirect_to",
"administrator_setup_index_path",
",",
"notice",
":",
"I18n",
".",
"t",
"(",
"\"controllers.admin.setup.general.success\"",
")",
"}",
"else",
"format",
".",
"html",
"{",
"# add breadcrumb and set title",
"@settings",
"=",
"params",
"@settings",
"[",
"'errors'",
"]",
"=",
"validation",
"render",
"action",
":",
"\"index\"",
"}",
"end",
"end",
"end"
] |
Create the settings for the Admin panel to work!
|
[
"Create",
"the",
"settings",
"for",
"the",
"Admin",
"panel",
"to",
"work!"
] |
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
|
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/setup_controller.rb#L22-L46
|
5,964 |
mrsimonfletcher/roroacms
|
app/controllers/roroacms/setup_controller.rb
|
Roroacms.SetupController.create_user
|
def create_user
@admin = Admin.new(administrator_params)
@admin.access_level = 'admin'
@admin.overlord = 'Y'
respond_to do |format|
if @admin.save
Setting.save_data({setup_complete: 'Y'})
clear_cache
session[:setup_complete] = true
format.html { redirect_to admin_path, notice: I18n.t("controllers.admin.setup.general.success") }
else
format.html { render action: "administrator" }
end
end
end
|
ruby
|
def create_user
@admin = Admin.new(administrator_params)
@admin.access_level = 'admin'
@admin.overlord = 'Y'
respond_to do |format|
if @admin.save
Setting.save_data({setup_complete: 'Y'})
clear_cache
session[:setup_complete] = true
format.html { redirect_to admin_path, notice: I18n.t("controllers.admin.setup.general.success") }
else
format.html { render action: "administrator" }
end
end
end
|
[
"def",
"create_user",
"@admin",
"=",
"Admin",
".",
"new",
"(",
"administrator_params",
")",
"@admin",
".",
"access_level",
"=",
"'admin'",
"@admin",
".",
"overlord",
"=",
"'Y'",
"respond_to",
"do",
"|",
"format",
"|",
"if",
"@admin",
".",
"save",
"Setting",
".",
"save_data",
"(",
"{",
"setup_complete",
":",
"'Y'",
"}",
")",
"clear_cache",
"session",
"[",
":setup_complete",
"]",
"=",
"true",
"format",
".",
"html",
"{",
"redirect_to",
"admin_path",
",",
"notice",
":",
"I18n",
".",
"t",
"(",
"\"controllers.admin.setup.general.success\"",
")",
"}",
"else",
"format",
".",
"html",
"{",
"render",
"action",
":",
"\"administrator\"",
"}",
"end",
"end",
"end"
] |
create a new admin user
|
[
"create",
"a",
"new",
"admin",
"user"
] |
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
|
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/setup_controller.rb#L50-L66
|
5,965 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.compare
|
def compare(&diff_block)
# Get a copy of the outputs before any transformations are applied
FileUtils.cp_r("#{temp_transformed_path}/.", temp_raw_path)
transform_paths!
glob_all(after_path).each do |relative_path|
expected = after_path + relative_path
next unless expected.file?
next if context.ignores?(relative_path)
block = context.preprocessors_for(relative_path).first
diff = diff_files(expected, relative_path, &block)
diff_block.call diff
end
end
|
ruby
|
def compare(&diff_block)
# Get a copy of the outputs before any transformations are applied
FileUtils.cp_r("#{temp_transformed_path}/.", temp_raw_path)
transform_paths!
glob_all(after_path).each do |relative_path|
expected = after_path + relative_path
next unless expected.file?
next if context.ignores?(relative_path)
block = context.preprocessors_for(relative_path).first
diff = diff_files(expected, relative_path, &block)
diff_block.call diff
end
end
|
[
"def",
"compare",
"(",
"&",
"diff_block",
")",
"# Get a copy of the outputs before any transformations are applied",
"FileUtils",
".",
"cp_r",
"(",
"\"#{temp_transformed_path}/.\"",
",",
"temp_raw_path",
")",
"transform_paths!",
"glob_all",
"(",
"after_path",
")",
".",
"each",
"do",
"|",
"relative_path",
"|",
"expected",
"=",
"after_path",
"+",
"relative_path",
"next",
"unless",
"expected",
".",
"file?",
"next",
"if",
"context",
".",
"ignores?",
"(",
"relative_path",
")",
"block",
"=",
"context",
".",
"preprocessors_for",
"(",
"relative_path",
")",
".",
"first",
"diff",
"=",
"diff_files",
"(",
"expected",
",",
"relative_path",
",",
"block",
")",
"diff_block",
".",
"call",
"diff",
"end",
"end"
] |
Compares the expected and produced directory by using the rules
defined in the context
@param [Block<(Diff)->()>] diff_block
The block, where you will likely define a test for each file to compare.
It will receive a Diff of each of the expected and produced files.
|
[
"Compares",
"the",
"expected",
"and",
"produced",
"directory",
"by",
"using",
"the",
"rules",
"defined",
"in",
"the",
"context"
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L121-L138
|
5,966 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.check_unexpected_files
|
def check_unexpected_files(&block)
expected_files = glob_all after_path
produced_files = glob_all
unexpected_files = produced_files - expected_files
# Select only files
unexpected_files.select! { |path| path.file? }
# Filter ignored paths
unexpected_files.reject! { |path| context.ignores?(path) }
block.call unexpected_files
end
|
ruby
|
def check_unexpected_files(&block)
expected_files = glob_all after_path
produced_files = glob_all
unexpected_files = produced_files - expected_files
# Select only files
unexpected_files.select! { |path| path.file? }
# Filter ignored paths
unexpected_files.reject! { |path| context.ignores?(path) }
block.call unexpected_files
end
|
[
"def",
"check_unexpected_files",
"(",
"&",
"block",
")",
"expected_files",
"=",
"glob_all",
"after_path",
"produced_files",
"=",
"glob_all",
"unexpected_files",
"=",
"produced_files",
"-",
"expected_files",
"# Select only files",
"unexpected_files",
".",
"select!",
"{",
"|",
"path",
"|",
"path",
".",
"file?",
"}",
"# Filter ignored paths",
"unexpected_files",
".",
"reject!",
"{",
"|",
"path",
"|",
"context",
".",
"ignores?",
"(",
"path",
")",
"}",
"block",
".",
"call",
"unexpected_files",
"end"
] |
Compares the expected and produced directory by using the rules
defined in the context for unexpected files.
This is separate because you probably don't want to define an extra
test case for each file, which wasn't expected at all. So you can
keep your test cases consistent.
@param [Block<(Array)->()>] diff_block
The block, where you will likely define a test that no unexpected files exists.
It will receive an Array.
|
[
"Compares",
"the",
"expected",
"and",
"produced",
"directory",
"by",
"using",
"the",
"rules",
"defined",
"in",
"the",
"context",
"for",
"unexpected",
"files",
"."
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L151-L163
|
5,967 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.prepare!
|
def prepare!
context.prepare!
temp_path.rmtree if temp_path.exist?
temp_path.mkdir
temp_raw_path.mkdir
temp_transformed_path.mkdir
end
|
ruby
|
def prepare!
context.prepare!
temp_path.rmtree if temp_path.exist?
temp_path.mkdir
temp_raw_path.mkdir
temp_transformed_path.mkdir
end
|
[
"def",
"prepare!",
"context",
".",
"prepare!",
"temp_path",
".",
"rmtree",
"if",
"temp_path",
".",
"exist?",
"temp_path",
".",
"mkdir",
"temp_raw_path",
".",
"mkdir",
"temp_transformed_path",
".",
"mkdir",
"end"
] |
Prepare the temporary directory
|
[
"Prepare",
"the",
"temporary",
"directory"
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L177-L184
|
5,968 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.copy_files!
|
def copy_files!
destination = temp_transformed_path
if has_base?
FileUtils.cp_r("#{base_spec.temp_raw_path}/.", destination)
end
begin
FileUtils.cp_r("#{before_path}/.", destination)
rescue Errno::ENOENT => e
raise e unless has_base?
end
end
|
ruby
|
def copy_files!
destination = temp_transformed_path
if has_base?
FileUtils.cp_r("#{base_spec.temp_raw_path}/.", destination)
end
begin
FileUtils.cp_r("#{before_path}/.", destination)
rescue Errno::ENOENT => e
raise e unless has_base?
end
end
|
[
"def",
"copy_files!",
"destination",
"=",
"temp_transformed_path",
"if",
"has_base?",
"FileUtils",
".",
"cp_r",
"(",
"\"#{base_spec.temp_raw_path}/.\"",
",",
"destination",
")",
"end",
"begin",
"FileUtils",
".",
"cp_r",
"(",
"\"#{before_path}/.\"",
",",
"destination",
")",
"rescue",
"Errno",
"::",
"ENOENT",
"=>",
"e",
"raise",
"e",
"unless",
"has_base?",
"end",
"end"
] |
Copies the before subdirectory of the given tests folder in the raw
directory.
|
[
"Copies",
"the",
"before",
"subdirectory",
"of",
"the",
"given",
"tests",
"folder",
"in",
"the",
"raw",
"directory",
"."
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L189-L201
|
5,969 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.transform_paths!
|
def transform_paths!
glob_all.each do |path|
context.transformers_for(path).each do |transformer|
transformer.call(path) if path.exist?
end
path.rmtree if context.ignores?(path) && path.exist?
end
end
|
ruby
|
def transform_paths!
glob_all.each do |path|
context.transformers_for(path).each do |transformer|
transformer.call(path) if path.exist?
end
path.rmtree if context.ignores?(path) && path.exist?
end
end
|
[
"def",
"transform_paths!",
"glob_all",
".",
"each",
"do",
"|",
"path",
"|",
"context",
".",
"transformers_for",
"(",
"path",
")",
".",
"each",
"do",
"|",
"transformer",
"|",
"transformer",
".",
"call",
"(",
"path",
")",
"if",
"path",
".",
"exist?",
"end",
"path",
".",
"rmtree",
"if",
"context",
".",
"ignores?",
"(",
"path",
")",
"&&",
"path",
".",
"exist?",
"end",
"end"
] |
Applies the in the context configured transformations.
|
[
"Applies",
"the",
"in",
"the",
"context",
"configured",
"transformations",
"."
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L205-L212
|
5,970 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.glob_all
|
def glob_all(path=nil)
Dir.chdir path || '.' do
Pathname.glob("**/*", context.include_hidden_files? ? File::FNM_DOTMATCH : 0).sort.reject do |p|
%w(. ..).include?(p.basename.to_s)
end
end
end
|
ruby
|
def glob_all(path=nil)
Dir.chdir path || '.' do
Pathname.glob("**/*", context.include_hidden_files? ? File::FNM_DOTMATCH : 0).sort.reject do |p|
%w(. ..).include?(p.basename.to_s)
end
end
end
|
[
"def",
"glob_all",
"(",
"path",
"=",
"nil",
")",
"Dir",
".",
"chdir",
"path",
"||",
"'.'",
"do",
"Pathname",
".",
"glob",
"(",
"\"**/*\"",
",",
"context",
".",
"include_hidden_files?",
"?",
"File",
"::",
"FNM_DOTMATCH",
":",
"0",
")",
".",
"sort",
".",
"reject",
"do",
"|",
"p",
"|",
"%w(",
".",
"..",
")",
".",
"include?",
"(",
"p",
".",
"basename",
".",
"to_s",
")",
"end",
"end",
"end"
] |
Searches recursively for all files and take care for including hidden files
if this is configured in the context.
@param [String] path
The relative or absolute path to search in (optional)
@return [Array<Pathname>]
|
[
"Searches",
"recursively",
"for",
"all",
"files",
"and",
"take",
"care",
"for",
"including",
"hidden",
"files",
"if",
"this",
"is",
"configured",
"in",
"the",
"context",
"."
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L222-L228
|
5,971 |
mrackwitz/CLIntegracon
|
lib/CLIntegracon/file_tree_spec.rb
|
CLIntegracon.FileTreeSpec.diff_files
|
def diff_files(expected, relative_path, &block)
produced = temp_transformed_path + relative_path
Diff.new(expected, produced, relative_path, &block)
end
|
ruby
|
def diff_files(expected, relative_path, &block)
produced = temp_transformed_path + relative_path
Diff.new(expected, produced, relative_path, &block)
end
|
[
"def",
"diff_files",
"(",
"expected",
",",
"relative_path",
",",
"&",
"block",
")",
"produced",
"=",
"temp_transformed_path",
"+",
"relative_path",
"Diff",
".",
"new",
"(",
"expected",
",",
"produced",
",",
"relative_path",
",",
"block",
")",
"end"
] |
Compares two files to check if they are identical and produces a clear diff
to highlight the differences.
@param [Pathname] expected
The file in the after directory
@param [Pathname] relative_path
The file in the temp directory
@param [Block<(Pathname)->(to_s)>] block
the block, which transforms the files in a better comparable form
@return [Diff]
An object holding a diff
|
[
"Compares",
"two",
"files",
"to",
"check",
"if",
"they",
"are",
"identical",
"and",
"produces",
"a",
"clear",
"diff",
"to",
"highlight",
"the",
"differences",
"."
] |
b675f23762d10e527487aa5576d6a77f9c623485
|
https://github.com/mrackwitz/CLIntegracon/blob/b675f23762d10e527487aa5576d6a77f9c623485/lib/CLIntegracon/file_tree_spec.rb#L245-L248
|
5,972 |
ladder/ladder
|
lib/ladder/resource.rb
|
Ladder.Resource.klass_from_predicate
|
def klass_from_predicate(predicate)
field_name = field_from_predicate(predicate)
return unless field_name
relation = relations[field_name]
return unless relation
relation.class_name.constantize
end
|
ruby
|
def klass_from_predicate(predicate)
field_name = field_from_predicate(predicate)
return unless field_name
relation = relations[field_name]
return unless relation
relation.class_name.constantize
end
|
[
"def",
"klass_from_predicate",
"(",
"predicate",
")",
"field_name",
"=",
"field_from_predicate",
"(",
"predicate",
")",
"return",
"unless",
"field_name",
"relation",
"=",
"relations",
"[",
"field_name",
"]",
"return",
"unless",
"relation",
"relation",
".",
"class_name",
".",
"constantize",
"end"
] |
Retrieve the class for a relation, based on its defined RDF predicate
@param [RDF::URI] predicate a URI for the RDF::Term
@return [Ladder::Resource, Ladder::File, nil] related class
|
[
"Retrieve",
"the",
"class",
"for",
"a",
"relation",
"based",
"on",
"its",
"defined",
"RDF",
"predicate"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/resource.rb#L63-L71
|
5,973 |
ladder/ladder
|
lib/ladder/resource.rb
|
Ladder.Resource.field_from_predicate
|
def field_from_predicate(predicate)
defined_prop = resource_class.properties.find { |_field_name, term| term.predicate == predicate }
return unless defined_prop
defined_prop.first
end
|
ruby
|
def field_from_predicate(predicate)
defined_prop = resource_class.properties.find { |_field_name, term| term.predicate == predicate }
return unless defined_prop
defined_prop.first
end
|
[
"def",
"field_from_predicate",
"(",
"predicate",
")",
"defined_prop",
"=",
"resource_class",
".",
"properties",
".",
"find",
"{",
"|",
"_field_name",
",",
"term",
"|",
"term",
".",
"predicate",
"==",
"predicate",
"}",
"return",
"unless",
"defined_prop",
"defined_prop",
".",
"first",
"end"
] |
Retrieve the attribute name for a field or relation,
based on its defined RDF predicate
@param [RDF::URI] predicate a URI for the RDF::Term
@return [String, nil] name for the attribute
|
[
"Retrieve",
"the",
"attribute",
"name",
"for",
"a",
"field",
"or",
"relation",
"based",
"on",
"its",
"defined",
"RDF",
"predicate"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/resource.rb#L79-L84
|
5,974 |
ladder/ladder
|
lib/ladder/resource.rb
|
Ladder.Resource.update_relation
|
def update_relation(field_name, *obj)
# Should be an Array of RDF::Term objects
return unless obj
obj.map! { |item| item.is_a?(RDF::URI) ? Ladder::Resource.from_uri(item) : item }
relation = send(field_name)
if Mongoid::Relations::Targets::Enumerable == relation.class
obj.map { |item| relation.send(:push, item) unless relation.include? item }
else
send("#{field_name}=", obj.size > 1 ? obj : obj.first)
end
end
|
ruby
|
def update_relation(field_name, *obj)
# Should be an Array of RDF::Term objects
return unless obj
obj.map! { |item| item.is_a?(RDF::URI) ? Ladder::Resource.from_uri(item) : item }
relation = send(field_name)
if Mongoid::Relations::Targets::Enumerable == relation.class
obj.map { |item| relation.send(:push, item) unless relation.include? item }
else
send("#{field_name}=", obj.size > 1 ? obj : obj.first)
end
end
|
[
"def",
"update_relation",
"(",
"field_name",
",",
"*",
"obj",
")",
"# Should be an Array of RDF::Term objects",
"return",
"unless",
"obj",
"obj",
".",
"map!",
"{",
"|",
"item",
"|",
"item",
".",
"is_a?",
"(",
"RDF",
"::",
"URI",
")",
"?",
"Ladder",
"::",
"Resource",
".",
"from_uri",
"(",
"item",
")",
":",
"item",
"}",
"relation",
"=",
"send",
"(",
"field_name",
")",
"if",
"Mongoid",
"::",
"Relations",
"::",
"Targets",
"::",
"Enumerable",
"==",
"relation",
".",
"class",
"obj",
".",
"map",
"{",
"|",
"item",
"|",
"relation",
".",
"send",
"(",
":push",
",",
"item",
")",
"unless",
"relation",
".",
"include?",
"item",
"}",
"else",
"send",
"(",
"\"#{field_name}=\"",
",",
"obj",
".",
"size",
">",
"1",
"?",
"obj",
":",
"obj",
".",
"first",
")",
"end",
"end"
] |
Set values on a defined relation
@param [String] field_name ActiveModel attribute name for the field
@param [Array<Object>] obj objects (usually Ladder::Resources) to be set
@return [Ladder::Resource, nil]
|
[
"Set",
"values",
"on",
"a",
"defined",
"relation"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/resource.rb#L94-L106
|
5,975 |
ladder/ladder
|
lib/ladder/resource.rb
|
Ladder.Resource.update_field
|
def update_field(field_name, *obj)
# Should be an Array of RDF::Term objects
return unless obj
if fields[field_name] && fields[field_name].localized?
trans = {}
obj.each do |item|
lang = item.is_a?(RDF::Literal) && item.has_language? ? item.language.to_s : I18n.locale.to_s
value = item.is_a?(RDF::URI) ? item.to_s : item.object # TODO: tidy this up
trans[lang] = trans[lang] ? [*trans[lang]] << value : value
end
send("#{field_name}_translations=", trans) unless trans.empty?
else
objects = obj.map { |item| item.is_a?(RDF::URI) ? item.to_s : item.object } # TODO: tidy this up
send("#{field_name}=", objects.size > 1 ? objects : objects.first)
end
end
|
ruby
|
def update_field(field_name, *obj)
# Should be an Array of RDF::Term objects
return unless obj
if fields[field_name] && fields[field_name].localized?
trans = {}
obj.each do |item|
lang = item.is_a?(RDF::Literal) && item.has_language? ? item.language.to_s : I18n.locale.to_s
value = item.is_a?(RDF::URI) ? item.to_s : item.object # TODO: tidy this up
trans[lang] = trans[lang] ? [*trans[lang]] << value : value
end
send("#{field_name}_translations=", trans) unless trans.empty?
else
objects = obj.map { |item| item.is_a?(RDF::URI) ? item.to_s : item.object } # TODO: tidy this up
send("#{field_name}=", objects.size > 1 ? objects : objects.first)
end
end
|
[
"def",
"update_field",
"(",
"field_name",
",",
"*",
"obj",
")",
"# Should be an Array of RDF::Term objects",
"return",
"unless",
"obj",
"if",
"fields",
"[",
"field_name",
"]",
"&&",
"fields",
"[",
"field_name",
"]",
".",
"localized?",
"trans",
"=",
"{",
"}",
"obj",
".",
"each",
"do",
"|",
"item",
"|",
"lang",
"=",
"item",
".",
"is_a?",
"(",
"RDF",
"::",
"Literal",
")",
"&&",
"item",
".",
"has_language?",
"?",
"item",
".",
"language",
".",
"to_s",
":",
"I18n",
".",
"locale",
".",
"to_s",
"value",
"=",
"item",
".",
"is_a?",
"(",
"RDF",
"::",
"URI",
")",
"?",
"item",
".",
"to_s",
":",
"item",
".",
"object",
"# TODO: tidy this up",
"trans",
"[",
"lang",
"]",
"=",
"trans",
"[",
"lang",
"]",
"?",
"[",
"trans",
"[",
"lang",
"]",
"]",
"<<",
"value",
":",
"value",
"end",
"send",
"(",
"\"#{field_name}_translations=\"",
",",
"trans",
")",
"unless",
"trans",
".",
"empty?",
"else",
"objects",
"=",
"obj",
".",
"map",
"{",
"|",
"item",
"|",
"item",
".",
"is_a?",
"(",
"RDF",
"::",
"URI",
")",
"?",
"item",
".",
"to_s",
":",
"item",
".",
"object",
"}",
"# TODO: tidy this up",
"send",
"(",
"\"#{field_name}=\"",
",",
"objects",
".",
"size",
">",
"1",
"?",
"objects",
":",
"objects",
".",
"first",
")",
"end",
"end"
] |
Set values on a field; this will cast values
from RDF types to persistable Mongoid types
@param [String] field_name ActiveModel attribute name for the field
@param [Array<Object>] obj objects (usually RDF::Terms) to be set
@return [Object, nil]
|
[
"Set",
"values",
"on",
"a",
"field",
";",
"this",
"will",
"cast",
"values",
"from",
"RDF",
"types",
"to",
"persistable",
"Mongoid",
"types"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/resource.rb#L115-L133
|
5,976 |
ladder/ladder
|
lib/ladder/resource.rb
|
Ladder.Resource.cast_value
|
def cast_value(value, opts = {})
case value
when Array
value.map { |v| cast_value(v, opts) }
when String
cast_uri = RDF::URI.new(value)
cast_uri.valid? ? cast_uri : RDF::Literal.new(value, opts)
when Time
# Cast DateTimes with 00:00:00 or Date stored as Times in Mongoid to xsd:date
# FIXME: this should NOT be applied for fields that are typed as Time
value.midnight == value ? RDF::Literal.new(value.to_date) : RDF::Literal.new(value.to_datetime)
else
RDF::Literal.new(value, opts)
end
end
|
ruby
|
def cast_value(value, opts = {})
case value
when Array
value.map { |v| cast_value(v, opts) }
when String
cast_uri = RDF::URI.new(value)
cast_uri.valid? ? cast_uri : RDF::Literal.new(value, opts)
when Time
# Cast DateTimes with 00:00:00 or Date stored as Times in Mongoid to xsd:date
# FIXME: this should NOT be applied for fields that are typed as Time
value.midnight == value ? RDF::Literal.new(value.to_date) : RDF::Literal.new(value.to_datetime)
else
RDF::Literal.new(value, opts)
end
end
|
[
"def",
"cast_value",
"(",
"value",
",",
"opts",
"=",
"{",
"}",
")",
"case",
"value",
"when",
"Array",
"value",
".",
"map",
"{",
"|",
"v",
"|",
"cast_value",
"(",
"v",
",",
"opts",
")",
"}",
"when",
"String",
"cast_uri",
"=",
"RDF",
"::",
"URI",
".",
"new",
"(",
"value",
")",
"cast_uri",
".",
"valid?",
"?",
"cast_uri",
":",
"RDF",
"::",
"Literal",
".",
"new",
"(",
"value",
",",
"opts",
")",
"when",
"Time",
"# Cast DateTimes with 00:00:00 or Date stored as Times in Mongoid to xsd:date",
"# FIXME: this should NOT be applied for fields that are typed as Time",
"value",
".",
"midnight",
"==",
"value",
"?",
"RDF",
"::",
"Literal",
".",
"new",
"(",
"value",
".",
"to_date",
")",
":",
"RDF",
"::",
"Literal",
".",
"new",
"(",
"value",
".",
"to_datetime",
")",
"else",
"RDF",
"::",
"Literal",
".",
"new",
"(",
"value",
",",
"opts",
")",
"end",
"end"
] |
Cast values from Mongoid types to RDF types
@param [Object] value ActiveModel attribute to be cast
@param [Hash] opts options to pass to RDF::Literal
@return [RDF::Term]
|
[
"Cast",
"values",
"from",
"Mongoid",
"types",
"to",
"RDF",
"types"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/resource.rb#L141-L155
|
5,977 |
ladder/ladder
|
lib/ladder/file.rb
|
Ladder.File.data
|
def data
@grid_file ||= self.class.grid.get(id) if persisted?
return @grid_file.data if @grid_file
file.rewind if file.respond_to? :rewind
file.read
end
|
ruby
|
def data
@grid_file ||= self.class.grid.get(id) if persisted?
return @grid_file.data if @grid_file
file.rewind if file.respond_to? :rewind
file.read
end
|
[
"def",
"data",
"@grid_file",
"||=",
"self",
".",
"class",
".",
"grid",
".",
"get",
"(",
"id",
")",
"if",
"persisted?",
"return",
"@grid_file",
".",
"data",
"if",
"@grid_file",
"file",
".",
"rewind",
"if",
"file",
".",
"respond_to?",
":rewind",
"file",
".",
"read",
"end"
] |
Output content of object from stored file or readable input
@return [String] string-encoded copy of binary data
|
[
"Output",
"content",
"of",
"object",
"from",
"stored",
"file",
"or",
"readable",
"input"
] |
fdb17fbeb93e89c670f3ca5d431f29be0a682fd2
|
https://github.com/ladder/ladder/blob/fdb17fbeb93e89c670f3ca5d431f29be0a682fd2/lib/ladder/file.rb#L41-L47
|
5,978 |
barkerest/incline
|
lib/incline/extensions/numeric.rb
|
Incline::Extensions.Numeric.to_human
|
def to_human
Incline::Extensions::Numeric::SHORT_SCALE.each do |(num,label)|
if self >= num
# Add 0.0001 to the value before rounding it off.
# This way we're telling the system that we want it to round up instead of round to even.
s = ('%.2f' % ((self.to_f / num) + 0.0001)).gsub(/\.?0+\z/,'')
return "#{s} #{label}"
end
end
if self.is_a?(::Rational)
if self.denominator == 1
return self.numerator.to_s
end
return self.to_s
elsif self.is_a?(::Integer)
return self.to_s
end
# Again we want to add the 0.0001 to the value before rounding.
('%.2f' % (self.to_f + 0.0001)).gsub(/\.?0+\z/,'')
end
|
ruby
|
def to_human
Incline::Extensions::Numeric::SHORT_SCALE.each do |(num,label)|
if self >= num
# Add 0.0001 to the value before rounding it off.
# This way we're telling the system that we want it to round up instead of round to even.
s = ('%.2f' % ((self.to_f / num) + 0.0001)).gsub(/\.?0+\z/,'')
return "#{s} #{label}"
end
end
if self.is_a?(::Rational)
if self.denominator == 1
return self.numerator.to_s
end
return self.to_s
elsif self.is_a?(::Integer)
return self.to_s
end
# Again we want to add the 0.0001 to the value before rounding.
('%.2f' % (self.to_f + 0.0001)).gsub(/\.?0+\z/,'')
end
|
[
"def",
"to_human",
"Incline",
"::",
"Extensions",
"::",
"Numeric",
"::",
"SHORT_SCALE",
".",
"each",
"do",
"|",
"(",
"num",
",",
"label",
")",
"|",
"if",
"self",
">=",
"num",
"# Add 0.0001 to the value before rounding it off.",
"# This way we're telling the system that we want it to round up instead of round to even.",
"s",
"=",
"(",
"'%.2f'",
"%",
"(",
"(",
"self",
".",
"to_f",
"/",
"num",
")",
"+",
"0.0001",
")",
")",
".",
"gsub",
"(",
"/",
"\\.",
"\\z",
"/",
",",
"''",
")",
"return",
"\"#{s} #{label}\"",
"end",
"end",
"if",
"self",
".",
"is_a?",
"(",
"::",
"Rational",
")",
"if",
"self",
".",
"denominator",
"==",
"1",
"return",
"self",
".",
"numerator",
".",
"to_s",
"end",
"return",
"self",
".",
"to_s",
"elsif",
"self",
".",
"is_a?",
"(",
"::",
"Integer",
")",
"return",
"self",
".",
"to_s",
"end",
"# Again we want to add the 0.0001 to the value before rounding.",
"(",
"'%.2f'",
"%",
"(",
"self",
".",
"to_f",
"+",
"0.0001",
")",
")",
".",
"gsub",
"(",
"/",
"\\.",
"\\z",
"/",
",",
"''",
")",
"end"
] |
Formats the number using the short scale for any number over 1 million.
|
[
"Formats",
"the",
"number",
"using",
"the",
"short",
"scale",
"for",
"any",
"number",
"over",
"1",
"million",
"."
] |
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
|
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/numeric.rb#L29-L50
|
5,979 |
tbpgr/sublime_sunippetter
|
lib/sublime_sunippetter.rb
|
SublimeSunippetter.Core.generate_sunippets
|
def generate_sunippets
sunippet_define = read_sunippetdefine
dsl = Dsl.new
dsl.instance_eval sunippet_define
output_methods(dsl)
output_requires(dsl)
end
|
ruby
|
def generate_sunippets
sunippet_define = read_sunippetdefine
dsl = Dsl.new
dsl.instance_eval sunippet_define
output_methods(dsl)
output_requires(dsl)
end
|
[
"def",
"generate_sunippets",
"sunippet_define",
"=",
"read_sunippetdefine",
"dsl",
"=",
"Dsl",
".",
"new",
"dsl",
".",
"instance_eval",
"sunippet_define",
"output_methods",
"(",
"dsl",
")",
"output_requires",
"(",
"dsl",
")",
"end"
] |
generate sublime text2 sunippets from Sunippetdefine
|
[
"generate",
"sublime",
"text2",
"sunippets",
"from",
"Sunippetdefine"
] |
a731a8a52fe457d742e78f50a4009b5b01f0640d
|
https://github.com/tbpgr/sublime_sunippetter/blob/a731a8a52fe457d742e78f50a4009b5b01f0640d/lib/sublime_sunippetter.rb#L21-L27
|
5,980 |
andreimaxim/active_metrics
|
lib/active_metrics/instrumentable.rb
|
ActiveMetrics.Instrumentable.count
|
def count(event, number = 1)
ActiveMetrics::Collector.record(event, { metric: 'count', value: number })
end
|
ruby
|
def count(event, number = 1)
ActiveMetrics::Collector.record(event, { metric: 'count', value: number })
end
|
[
"def",
"count",
"(",
"event",
",",
"number",
"=",
"1",
")",
"ActiveMetrics",
"::",
"Collector",
".",
"record",
"(",
"event",
",",
"{",
"metric",
":",
"'count'",
",",
"value",
":",
"number",
"}",
")",
"end"
] |
Count log lines are used to submit increments to Librato.
You can submit increments as frequently as desired and every minute the
current total will be flushed to Librato and reset to zero.
@param event [String] The name of the event
@param number [Integer] The number to increment the current count (defaults to 1)
|
[
"Count",
"log",
"lines",
"are",
"used",
"to",
"submit",
"increments",
"to",
"Librato",
"."
] |
b8ee011e9dccd88bb73f6cd52625106ac8ea5ff8
|
https://github.com/andreimaxim/active_metrics/blob/b8ee011e9dccd88bb73f6cd52625106ac8ea5ff8/lib/active_metrics/instrumentable.rb#L13-L15
|
5,981 |
andreimaxim/active_metrics
|
lib/active_metrics/instrumentable.rb
|
ActiveMetrics.Instrumentable.measure
|
def measure(event, value = 0)
if block_given?
time = Time.now
# Store the value returned by the block for future reference
value = yield
delta = Time.now - time
ActiveMetrics::Collector.record(event, { metric: 'measure', value: delta })
value
else
ActiveMetrics::Collector.record(event, { metric: 'measure', value: value })
end
end
|
ruby
|
def measure(event, value = 0)
if block_given?
time = Time.now
# Store the value returned by the block for future reference
value = yield
delta = Time.now - time
ActiveMetrics::Collector.record(event, { metric: 'measure', value: delta })
value
else
ActiveMetrics::Collector.record(event, { metric: 'measure', value: value })
end
end
|
[
"def",
"measure",
"(",
"event",
",",
"value",
"=",
"0",
")",
"if",
"block_given?",
"time",
"=",
"Time",
".",
"now",
"# Store the value returned by the block for future reference",
"value",
"=",
"yield",
"delta",
"=",
"Time",
".",
"now",
"-",
"time",
"ActiveMetrics",
"::",
"Collector",
".",
"record",
"(",
"event",
",",
"{",
"metric",
":",
"'measure'",
",",
"value",
":",
"delta",
"}",
")",
"value",
"else",
"ActiveMetrics",
"::",
"Collector",
".",
"record",
"(",
"event",
",",
"{",
"metric",
":",
"'measure'",
",",
"value",
":",
"value",
"}",
")",
"end",
"end"
] |
Measure log lines are used to submit individual measurements that comprise
a statistical distribution. The most common use case are timings i.e.
latency measurements, but it can also be used to represent non-temporal
distributions such as counts.
You can submit as many measures as you’d like (typically they are
submitted per-request) and every minute Librato will calculate/record a
complete set of summary statistics over the measures submitted in that
interval.
The `measure` method also accepts a block of code which will automatically
measure the amount of time spent running that block:
measure 'foo.bar.baz' do
Foo.bar #=> 'baz'
end
For convenience, when `measure` is used with a block it will return the
value returned by the block.
@param event [String] The name of the event
@param value [Integer, String] The value measured.
|
[
"Measure",
"log",
"lines",
"are",
"used",
"to",
"submit",
"individual",
"measurements",
"that",
"comprise",
"a",
"statistical",
"distribution",
".",
"The",
"most",
"common",
"use",
"case",
"are",
"timings",
"i",
".",
"e",
".",
"latency",
"measurements",
"but",
"it",
"can",
"also",
"be",
"used",
"to",
"represent",
"non",
"-",
"temporal",
"distributions",
"such",
"as",
"counts",
"."
] |
b8ee011e9dccd88bb73f6cd52625106ac8ea5ff8
|
https://github.com/andreimaxim/active_metrics/blob/b8ee011e9dccd88bb73f6cd52625106ac8ea5ff8/lib/active_metrics/instrumentable.rb#L39-L52
|
5,982 |
robfors/ruby-sumac
|
lib/sumac/connection.rb
|
Sumac.Connection.messenger_received_message
|
def messenger_received_message(message_string)
#puts "receive|#{message_string}"
begin
message = Messages.from_json(message_string)
rescue ProtocolError
@scheduler.receive(:invalid_message)
return
end
case message
when Messages::CallRequest then @scheduler.receive(:call_request_message, message)
when Messages::CallResponse then @scheduler.receive(:call_response_message, message)
when Messages::Compatibility then @scheduler.receive(:compatibility_message, message)
when Messages::Forget then @scheduler.receive(:forget_message, message)
when Messages::Initialization then @scheduler.receive(:initialization_message, message)
when Messages::Shutdown then @scheduler.receive(:shutdown_message)
end
end
|
ruby
|
def messenger_received_message(message_string)
#puts "receive|#{message_string}"
begin
message = Messages.from_json(message_string)
rescue ProtocolError
@scheduler.receive(:invalid_message)
return
end
case message
when Messages::CallRequest then @scheduler.receive(:call_request_message, message)
when Messages::CallResponse then @scheduler.receive(:call_response_message, message)
when Messages::Compatibility then @scheduler.receive(:compatibility_message, message)
when Messages::Forget then @scheduler.receive(:forget_message, message)
when Messages::Initialization then @scheduler.receive(:initialization_message, message)
when Messages::Shutdown then @scheduler.receive(:shutdown_message)
end
end
|
[
"def",
"messenger_received_message",
"(",
"message_string",
")",
"#puts \"receive|#{message_string}\"",
"begin",
"message",
"=",
"Messages",
".",
"from_json",
"(",
"message_string",
")",
"rescue",
"ProtocolError",
"@scheduler",
".",
"receive",
"(",
":invalid_message",
")",
"return",
"end",
"case",
"message",
"when",
"Messages",
"::",
"CallRequest",
"then",
"@scheduler",
".",
"receive",
"(",
":call_request_message",
",",
"message",
")",
"when",
"Messages",
"::",
"CallResponse",
"then",
"@scheduler",
".",
"receive",
"(",
":call_response_message",
",",
"message",
")",
"when",
"Messages",
"::",
"Compatibility",
"then",
"@scheduler",
".",
"receive",
"(",
":compatibility_message",
",",
"message",
")",
"when",
"Messages",
"::",
"Forget",
"then",
"@scheduler",
".",
"receive",
"(",
":forget_message",
",",
"message",
")",
"when",
"Messages",
"::",
"Initialization",
"then",
"@scheduler",
".",
"receive",
"(",
":initialization_message",
",",
"message",
")",
"when",
"Messages",
"::",
"Shutdown",
"then",
"@scheduler",
".",
"receive",
"(",
":shutdown_message",
")",
"end",
"end"
] |
Submit a message from the messenger.
The thread will wait its turn if another event is being processed.
@param message_string [String]
@return [void]
|
[
"Submit",
"a",
"message",
"from",
"the",
"messenger",
".",
"The",
"thread",
"will",
"wait",
"its",
"turn",
"if",
"another",
"event",
"is",
"being",
"processed",
"."
] |
524fa68b7d1bb10a74baa69cd594ab2b8cae20a3
|
https://github.com/robfors/ruby-sumac/blob/524fa68b7d1bb10a74baa69cd594ab2b8cae20a3/lib/sumac/connection.rb#L181-L197
|
5,983 |
MOZGIII/win-path-utils
|
lib/win-path-utils.rb
|
WinPathUtils.Path.add
|
def add(value, options = {})
# Set defaults
options[:duplication_filter] = :do_not_add unless options.key?(:duplication_filter)
# Get path
path = get_array
# Check duplicates
if path.member?(value)
case options[:duplication_filter]
when :do_not_add, :deny
# do nothing, we already have one in the list
return
when :remove_existing
path.delete!(value)
when :none
# just pass through
else
raise WrongOptionError, "Unknown :duplication_filter!"
end
end
# Change path array
case options[:where]
when :start, :left
path.unshift value
when :end, :right
path.push value
else
raise WrongOptionError, "Unknown :where!"
end
# Save new array
set_array(path)
end
|
ruby
|
def add(value, options = {})
# Set defaults
options[:duplication_filter] = :do_not_add unless options.key?(:duplication_filter)
# Get path
path = get_array
# Check duplicates
if path.member?(value)
case options[:duplication_filter]
when :do_not_add, :deny
# do nothing, we already have one in the list
return
when :remove_existing
path.delete!(value)
when :none
# just pass through
else
raise WrongOptionError, "Unknown :duplication_filter!"
end
end
# Change path array
case options[:where]
when :start, :left
path.unshift value
when :end, :right
path.push value
else
raise WrongOptionError, "Unknown :where!"
end
# Save new array
set_array(path)
end
|
[
"def",
"add",
"(",
"value",
",",
"options",
"=",
"{",
"}",
")",
"# Set defaults",
"options",
"[",
":duplication_filter",
"]",
"=",
":do_not_add",
"unless",
"options",
".",
"key?",
"(",
":duplication_filter",
")",
"# Get path",
"path",
"=",
"get_array",
"# Check duplicates",
"if",
"path",
".",
"member?",
"(",
"value",
")",
"case",
"options",
"[",
":duplication_filter",
"]",
"when",
":do_not_add",
",",
":deny",
"# do nothing, we already have one in the list",
"return",
"when",
":remove_existing",
"path",
".",
"delete!",
"(",
"value",
")",
"when",
":none",
"# just pass through",
"else",
"raise",
"WrongOptionError",
",",
"\"Unknown :duplication_filter!\"",
"end",
"end",
"# Change path array",
"case",
"options",
"[",
":where",
"]",
"when",
":start",
",",
":left",
"path",
".",
"unshift",
"value",
"when",
":end",
",",
":right",
"path",
".",
"push",
"value",
"else",
"raise",
"WrongOptionError",
",",
"\"Unknown :where!\"",
"end",
"# Save new array",
"set_array",
"(",
"path",
")",
"end"
] |
Adds value to the path
|
[
"Adds",
"value",
"to",
"the",
"path"
] |
7f12c8f68250bf9e09c7a826e44632fb66f43426
|
https://github.com/MOZGIII/win-path-utils/blob/7f12c8f68250bf9e09c7a826e44632fb66f43426/lib/win-path-utils.rb#L60-L94
|
5,984 |
MOZGIII/win-path-utils
|
lib/win-path-utils.rb
|
WinPathUtils.Path.with_reg
|
def with_reg(access_mask = Win32::Registry::Constants::KEY_ALL_ACCESS, &block)
@hkey.open(@reg_path, access_mask, &block)
end
|
ruby
|
def with_reg(access_mask = Win32::Registry::Constants::KEY_ALL_ACCESS, &block)
@hkey.open(@reg_path, access_mask, &block)
end
|
[
"def",
"with_reg",
"(",
"access_mask",
"=",
"Win32",
"::",
"Registry",
"::",
"Constants",
"::",
"KEY_ALL_ACCESS",
",",
"&",
"block",
")",
"@hkey",
".",
"open",
"(",
"@reg_path",
",",
"access_mask",
",",
"block",
")",
"end"
] |
Execute block with the current reg settings
|
[
"Execute",
"block",
"with",
"the",
"current",
"reg",
"settings"
] |
7f12c8f68250bf9e09c7a826e44632fb66f43426
|
https://github.com/MOZGIII/win-path-utils/blob/7f12c8f68250bf9e09c7a826e44632fb66f43426/lib/win-path-utils.rb#L144-L146
|
5,985 |
phildionne/associates
|
lib/associates/validations.rb
|
Associates.Validations.valid_with_associates?
|
def valid_with_associates?(context = nil)
# Model validations
valid_without_associates?(context)
# Associated models validations
self.class.associates.each do |associate|
model = send(associate.name)
model.valid?(context)
model.errors.each_entry do |attribute, message|
# Do not include association presence validation errors
if associate.dependent_names.include?(attribute.to_s)
next
elsif respond_to?(attribute)
errors.add(attribute, message)
else
errors.add(:base, model.errors.full_messages_for(attribute))
end
end
end
errors.messages.values.each(&:uniq!)
errors.none?
end
|
ruby
|
def valid_with_associates?(context = nil)
# Model validations
valid_without_associates?(context)
# Associated models validations
self.class.associates.each do |associate|
model = send(associate.name)
model.valid?(context)
model.errors.each_entry do |attribute, message|
# Do not include association presence validation errors
if associate.dependent_names.include?(attribute.to_s)
next
elsif respond_to?(attribute)
errors.add(attribute, message)
else
errors.add(:base, model.errors.full_messages_for(attribute))
end
end
end
errors.messages.values.each(&:uniq!)
errors.none?
end
|
[
"def",
"valid_with_associates?",
"(",
"context",
"=",
"nil",
")",
"# Model validations",
"valid_without_associates?",
"(",
"context",
")",
"# Associated models validations",
"self",
".",
"class",
".",
"associates",
".",
"each",
"do",
"|",
"associate",
"|",
"model",
"=",
"send",
"(",
"associate",
".",
"name",
")",
"model",
".",
"valid?",
"(",
"context",
")",
"model",
".",
"errors",
".",
"each_entry",
"do",
"|",
"attribute",
",",
"message",
"|",
"# Do not include association presence validation errors",
"if",
"associate",
".",
"dependent_names",
".",
"include?",
"(",
"attribute",
".",
"to_s",
")",
"next",
"elsif",
"respond_to?",
"(",
"attribute",
")",
"errors",
".",
"add",
"(",
"attribute",
",",
"message",
")",
"else",
"errors",
".",
"add",
"(",
":base",
",",
"model",
".",
"errors",
".",
"full_messages_for",
"(",
"attribute",
")",
")",
"end",
"end",
"end",
"errors",
".",
"messages",
".",
"values",
".",
"each",
"(",
":uniq!",
")",
"errors",
".",
"none?",
"end"
] |
Runs the model validations plus the associated models validations and
merges each messages in the errors hash
@return [Boolean]
|
[
"Runs",
"the",
"model",
"validations",
"plus",
"the",
"associated",
"models",
"validations",
"and",
"merges",
"each",
"messages",
"in",
"the",
"errors",
"hash"
] |
630edcc47340a73ad787feaf2cdf326b4487bb9f
|
https://github.com/phildionne/associates/blob/630edcc47340a73ad787feaf2cdf326b4487bb9f/lib/associates/validations.rb#L16-L39
|
5,986 |
aetherised/ark-util
|
lib/ark/log.rb
|
ARK.Log.say
|
def say(msg, sym='...', loud=false, indent=0)
return false if Conf[:quiet]
return false if loud && !Conf[:verbose]
unless msg == ''
time = ""
if Conf[:timed]
time = Timer.time.to_s.ljust(4, '0')
time = time + " "
end
indent = " " * indent
indent = " " if indent == ""
puts "#{time}#{sym}#{indent}#{msg}"
else
puts
end
end
|
ruby
|
def say(msg, sym='...', loud=false, indent=0)
return false if Conf[:quiet]
return false if loud && !Conf[:verbose]
unless msg == ''
time = ""
if Conf[:timed]
time = Timer.time.to_s.ljust(4, '0')
time = time + " "
end
indent = " " * indent
indent = " " if indent == ""
puts "#{time}#{sym}#{indent}#{msg}"
else
puts
end
end
|
[
"def",
"say",
"(",
"msg",
",",
"sym",
"=",
"'...'",
",",
"loud",
"=",
"false",
",",
"indent",
"=",
"0",
")",
"return",
"false",
"if",
"Conf",
"[",
":quiet",
"]",
"return",
"false",
"if",
"loud",
"&&",
"!",
"Conf",
"[",
":verbose",
"]",
"unless",
"msg",
"==",
"''",
"time",
"=",
"\"\"",
"if",
"Conf",
"[",
":timed",
"]",
"time",
"=",
"Timer",
".",
"time",
".",
"to_s",
".",
"ljust",
"(",
"4",
",",
"'0'",
")",
"time",
"=",
"time",
"+",
"\" \"",
"end",
"indent",
"=",
"\" \"",
"*",
"indent",
"indent",
"=",
"\" \"",
"if",
"indent",
"==",
"\"\"",
"puts",
"\"#{time}#{sym}#{indent}#{msg}\"",
"else",
"puts",
"end",
"end"
] |
Write +msg+ to standard output according to verbosity settings. Not meant
to be used directly
|
[
"Write",
"+",
"msg",
"+",
"to",
"standard",
"output",
"according",
"to",
"verbosity",
"settings",
".",
"Not",
"meant",
"to",
"be",
"used",
"directly"
] |
d7573ad0e44568a394808dfa895b9375de1bc3fd
|
https://github.com/aetherised/ark-util/blob/d7573ad0e44568a394808dfa895b9375de1bc3fd/lib/ark/log.rb#L18-L33
|
5,987 |
madwire/trooper
|
lib/trooper/configuration.rb
|
Trooper.Configuration.load_troopfile!
|
def load_troopfile!(options)
if troopfile?
eval troopfile.read
@loaded = true
load_environment!
set options
else
raise Trooper::NoConfigurationFileError, "No Configuration file (#{self[:file_name]}) can be found!"
end
end
|
ruby
|
def load_troopfile!(options)
if troopfile?
eval troopfile.read
@loaded = true
load_environment!
set options
else
raise Trooper::NoConfigurationFileError, "No Configuration file (#{self[:file_name]}) can be found!"
end
end
|
[
"def",
"load_troopfile!",
"(",
"options",
")",
"if",
"troopfile?",
"eval",
"troopfile",
".",
"read",
"@loaded",
"=",
"true",
"load_environment!",
"set",
"options",
"else",
"raise",
"Trooper",
"::",
"NoConfigurationFileError",
",",
"\"No Configuration file (#{self[:file_name]}) can be found!\"",
"end",
"end"
] |
loads the troopfile and sets the environment up
|
[
"loads",
"the",
"troopfile",
"and",
"sets",
"the",
"environment",
"up"
] |
ca953f9b78adf1614f7acf82c9076055540ee04c
|
https://github.com/madwire/trooper/blob/ca953f9b78adf1614f7acf82c9076055540ee04c/lib/trooper/configuration.rb#L127-L137
|
5,988 |
cknadler/rcomp
|
lib/rcomp/suite.rb
|
RComp.Suite.load
|
def load(pattern=nil)
tests = []
# Find all tests in the tests directory
Find.find @@conf.test_root do |path|
# recurse into all subdirectories
next if File.directory? path
# filter tests by pattern if present
if pattern
next unless rel_path(path).match(pattern)
end
# ignore dotfiles
next if File.basename(path).match(/^\..*/)
# ignore files in ignore filter
next if ignored?(path)
tests << Test.new(path)
end
return tests
end
|
ruby
|
def load(pattern=nil)
tests = []
# Find all tests in the tests directory
Find.find @@conf.test_root do |path|
# recurse into all subdirectories
next if File.directory? path
# filter tests by pattern if present
if pattern
next unless rel_path(path).match(pattern)
end
# ignore dotfiles
next if File.basename(path).match(/^\..*/)
# ignore files in ignore filter
next if ignored?(path)
tests << Test.new(path)
end
return tests
end
|
[
"def",
"load",
"(",
"pattern",
"=",
"nil",
")",
"tests",
"=",
"[",
"]",
"# Find all tests in the tests directory",
"Find",
".",
"find",
"@@conf",
".",
"test_root",
"do",
"|",
"path",
"|",
"# recurse into all subdirectories",
"next",
"if",
"File",
".",
"directory?",
"path",
"# filter tests by pattern if present",
"if",
"pattern",
"next",
"unless",
"rel_path",
"(",
"path",
")",
".",
"match",
"(",
"pattern",
")",
"end",
"# ignore dotfiles",
"next",
"if",
"File",
".",
"basename",
"(",
"path",
")",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"# ignore files in ignore filter",
"next",
"if",
"ignored?",
"(",
"path",
")",
"tests",
"<<",
"Test",
".",
"new",
"(",
"path",
")",
"end",
"return",
"tests",
"end"
] |
Create a test suite
pattern - A pattern to filter the tests that are added to the suite
Returns an Array of Test objects
|
[
"Create",
"a",
"test",
"suite"
] |
76fe71e1ef3b13923738ea6ab9cd502fe2f64f51
|
https://github.com/cknadler/rcomp/blob/76fe71e1ef3b13923738ea6ab9cd502fe2f64f51/lib/rcomp/suite.rb#L16-L39
|
5,989 |
cknadler/rcomp
|
lib/rcomp/suite.rb
|
RComp.Suite.ignored?
|
def ignored?(path)
@@conf.ignore.each do |ignore|
return true if rel_path(path).match(ignore)
end
return false
end
|
ruby
|
def ignored?(path)
@@conf.ignore.each do |ignore|
return true if rel_path(path).match(ignore)
end
return false
end
|
[
"def",
"ignored?",
"(",
"path",
")",
"@@conf",
".",
"ignore",
".",
"each",
"do",
"|",
"ignore",
"|",
"return",
"true",
"if",
"rel_path",
"(",
"path",
")",
".",
"match",
"(",
"ignore",
")",
"end",
"return",
"false",
"end"
] |
Checks all ignore patterns against a given relative path
path - A relative path of a test
Returns true if any patterns match the path, false otherwise
|
[
"Checks",
"all",
"ignore",
"patterns",
"against",
"a",
"given",
"relative",
"path"
] |
76fe71e1ef3b13923738ea6ab9cd502fe2f64f51
|
https://github.com/cknadler/rcomp/blob/76fe71e1ef3b13923738ea6ab9cd502fe2f64f51/lib/rcomp/suite.rb#L48-L53
|
5,990 |
wedesoft/multiarray
|
lib/multiarray/malloc.rb
|
Hornetseye.Malloc.save
|
def save( value )
write value.values.pack( value.typecode.directive )
value
end
|
ruby
|
def save( value )
write value.values.pack( value.typecode.directive )
value
end
|
[
"def",
"save",
"(",
"value",
")",
"write",
"value",
".",
"values",
".",
"pack",
"(",
"value",
".",
"typecode",
".",
"directive",
")",
"value",
"end"
] |
Write typed value to memory
@param [Node] value Value to write to memory.
@return [Node] Returns +value+.
|
[
"Write",
"typed",
"value",
"to",
"memory"
] |
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
|
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/malloc.rb#L39-L42
|
5,991 |
mrsimonfletcher/roroacms
|
app/controllers/roroacms/admin/themes_controller.rb
|
Roroacms.Admin::ThemesController.create
|
def create
# the theme used is set in the settings area - this does the update of the current theme used
Setting.where("setting_name = 'theme_folder'").update_all('setting' => params[:theme])
Setting.reload_settings
respond_to do |format|
format.html { redirect_to admin_themes_path, notice: I18n.t("controllers.admin.themes.create.flash.success") }
end
end
|
ruby
|
def create
# the theme used is set in the settings area - this does the update of the current theme used
Setting.where("setting_name = 'theme_folder'").update_all('setting' => params[:theme])
Setting.reload_settings
respond_to do |format|
format.html { redirect_to admin_themes_path, notice: I18n.t("controllers.admin.themes.create.flash.success") }
end
end
|
[
"def",
"create",
"# the theme used is set in the settings area - this does the update of the current theme used",
"Setting",
".",
"where",
"(",
"\"setting_name = 'theme_folder'\"",
")",
".",
"update_all",
"(",
"'setting'",
"=>",
"params",
"[",
":theme",
"]",
")",
"Setting",
".",
"reload_settings",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"{",
"redirect_to",
"admin_themes_path",
",",
"notice",
":",
"I18n",
".",
"t",
"(",
"\"controllers.admin.themes.create.flash.success\"",
")",
"}",
"end",
"end"
] |
update the currently used theme
|
[
"update",
"the",
"currently",
"used",
"theme"
] |
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
|
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/themes_controller.rb#L23-L30
|
5,992 |
mrsimonfletcher/roroacms
|
app/controllers/roroacms/admin/themes_controller.rb
|
Roroacms.Admin::ThemesController.destroy
|
def destroy
# remove the directory from the directory structure
destory_theme params[:id]
respond_to do |format|
format.html { redirect_to admin_themes_path, notice: I18n.t("controllers.admin.themes.destroy.flash.success") }
end
end
|
ruby
|
def destroy
# remove the directory from the directory structure
destory_theme params[:id]
respond_to do |format|
format.html { redirect_to admin_themes_path, notice: I18n.t("controllers.admin.themes.destroy.flash.success") }
end
end
|
[
"def",
"destroy",
"# remove the directory from the directory structure",
"destory_theme",
"params",
"[",
":id",
"]",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"{",
"redirect_to",
"admin_themes_path",
",",
"notice",
":",
"I18n",
".",
"t",
"(",
"\"controllers.admin.themes.destroy.flash.success\"",
")",
"}",
"end",
"end"
] |
remove the theme from the theme folder stopping any future usage.
|
[
"remove",
"the",
"theme",
"from",
"the",
"theme",
"folder",
"stopping",
"any",
"future",
"usage",
"."
] |
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
|
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/themes_controller.rb#L35-L42
|
5,993 |
tomash/blasphemy
|
lib/blasphemy.rb
|
Faker.CustomIpsum.sentence
|
def sentence
# Determine the number of comma-separated sections and number of words in
# each section for this sentence.
sections = []
1.upto(rand(5)+1) do
sections << (words(rand(9)+3).join(" "))
end
s = sections.join(", ")
return s.capitalize + ".?!".slice(rand(3),1)
end
|
ruby
|
def sentence
# Determine the number of comma-separated sections and number of words in
# each section for this sentence.
sections = []
1.upto(rand(5)+1) do
sections << (words(rand(9)+3).join(" "))
end
s = sections.join(", ")
return s.capitalize + ".?!".slice(rand(3),1)
end
|
[
"def",
"sentence",
"# Determine the number of comma-separated sections and number of words in",
"# each section for this sentence.",
"sections",
"=",
"[",
"]",
"1",
".",
"upto",
"(",
"rand",
"(",
"5",
")",
"+",
"1",
")",
"do",
"sections",
"<<",
"(",
"words",
"(",
"rand",
"(",
"9",
")",
"+",
"3",
")",
".",
"join",
"(",
"\" \"",
")",
")",
"end",
"s",
"=",
"sections",
".",
"join",
"(",
"\", \"",
")",
"return",
"s",
".",
"capitalize",
"+",
"\".?!\"",
".",
"slice",
"(",
"rand",
"(",
"3",
")",
",",
"1",
")",
"end"
] |
Returns a randomly generated sentence of lorem ipsum text.
The first word is capitalized, and the sentence ends in either a period or
question mark. Commas are added at random.
|
[
"Returns",
"a",
"randomly",
"generated",
"sentence",
"of",
"lorem",
"ipsum",
"text",
".",
"The",
"first",
"word",
"is",
"capitalized",
"and",
"the",
"sentence",
"ends",
"in",
"either",
"a",
"period",
"or",
"question",
"mark",
".",
"Commas",
"are",
"added",
"at",
"random",
"."
] |
00ba52fe24ec670df3dc45aaad0f99323fa362b4
|
https://github.com/tomash/blasphemy/blob/00ba52fe24ec670df3dc45aaad0f99323fa362b4/lib/blasphemy.rb#L17-L26
|
5,994 |
codescrum/bebox
|
lib/bebox/wizards/project_wizard.rb
|
Bebox.ProjectWizard.create_new_project
|
def create_new_project(project_name)
# Check project existence
(error(_('wizard.project.name_exist')); return false) if project_exists?(Dir.pwd, project_name)
# Setup the bebox boxes directory
bebox_boxes_setup
# Asks to choose an existing box
current_box = choose_box(get_existing_boxes)
vagrant_box_base = "#{BEBOX_BOXES_PATH}/#{get_valid_box_uri(current_box)}"
# Asks user to choose vagrant box provider
vagrant_box_provider = choose_option(%w{virtualbox vmware}, _('wizard.project.choose_box_provider'))
# Set default environments
default_environments = %w{vagrant staging production}
# Project creation
project = Bebox::Project.new(project_name, vagrant_box_base, Dir.pwd, vagrant_box_provider, default_environments)
output = project.create
ok _('wizard.project.creation_success')%{project_name: project_name}
return output
end
|
ruby
|
def create_new_project(project_name)
# Check project existence
(error(_('wizard.project.name_exist')); return false) if project_exists?(Dir.pwd, project_name)
# Setup the bebox boxes directory
bebox_boxes_setup
# Asks to choose an existing box
current_box = choose_box(get_existing_boxes)
vagrant_box_base = "#{BEBOX_BOXES_PATH}/#{get_valid_box_uri(current_box)}"
# Asks user to choose vagrant box provider
vagrant_box_provider = choose_option(%w{virtualbox vmware}, _('wizard.project.choose_box_provider'))
# Set default environments
default_environments = %w{vagrant staging production}
# Project creation
project = Bebox::Project.new(project_name, vagrant_box_base, Dir.pwd, vagrant_box_provider, default_environments)
output = project.create
ok _('wizard.project.creation_success')%{project_name: project_name}
return output
end
|
[
"def",
"create_new_project",
"(",
"project_name",
")",
"# Check project existence",
"(",
"error",
"(",
"_",
"(",
"'wizard.project.name_exist'",
")",
")",
";",
"return",
"false",
")",
"if",
"project_exists?",
"(",
"Dir",
".",
"pwd",
",",
"project_name",
")",
"# Setup the bebox boxes directory",
"bebox_boxes_setup",
"# Asks to choose an existing box",
"current_box",
"=",
"choose_box",
"(",
"get_existing_boxes",
")",
"vagrant_box_base",
"=",
"\"#{BEBOX_BOXES_PATH}/#{get_valid_box_uri(current_box)}\"",
"# Asks user to choose vagrant box provider",
"vagrant_box_provider",
"=",
"choose_option",
"(",
"%w{",
"virtualbox",
"vmware",
"}",
",",
"_",
"(",
"'wizard.project.choose_box_provider'",
")",
")",
"# Set default environments",
"default_environments",
"=",
"%w{",
"vagrant",
"staging",
"production",
"}",
"# Project creation",
"project",
"=",
"Bebox",
"::",
"Project",
".",
"new",
"(",
"project_name",
",",
"vagrant_box_base",
",",
"Dir",
".",
"pwd",
",",
"vagrant_box_provider",
",",
"default_environments",
")",
"output",
"=",
"project",
".",
"create",
"ok",
"_",
"(",
"'wizard.project.creation_success'",
")",
"%",
"{",
"project_name",
":",
"project_name",
"}",
"return",
"output",
"end"
] |
Asks for the project parameters and create the project skeleton
|
[
"Asks",
"for",
"the",
"project",
"parameters",
"and",
"create",
"the",
"project",
"skeleton"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/project_wizard.rb#L10-L27
|
5,995 |
codescrum/bebox
|
lib/bebox/wizards/project_wizard.rb
|
Bebox.ProjectWizard.uri_valid?
|
def uri_valid?(vbox_uri)
require 'uri'
uri = URI.parse(vbox_uri)
%w{http https}.include?(uri.scheme) ? http_uri_valid?(uri) : file_uri_valid?(uri)
end
|
ruby
|
def uri_valid?(vbox_uri)
require 'uri'
uri = URI.parse(vbox_uri)
%w{http https}.include?(uri.scheme) ? http_uri_valid?(uri) : file_uri_valid?(uri)
end
|
[
"def",
"uri_valid?",
"(",
"vbox_uri",
")",
"require",
"'uri'",
"uri",
"=",
"URI",
".",
"parse",
"(",
"vbox_uri",
")",
"%w{",
"http",
"https",
"}",
".",
"include?",
"(",
"uri",
".",
"scheme",
")",
"?",
"http_uri_valid?",
"(",
"uri",
")",
":",
"file_uri_valid?",
"(",
"uri",
")",
"end"
] |
Validate uri download or local box existence
|
[
"Validate",
"uri",
"download",
"or",
"local",
"box",
"existence"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/project_wizard.rb#L77-L81
|
5,996 |
codescrum/bebox
|
lib/bebox/wizards/project_wizard.rb
|
Bebox.ProjectWizard.get_existing_boxes
|
def get_existing_boxes
# Converts the bebox boxes directory to an absolute pathname
expanded_directory = File.expand_path("#{BEBOX_BOXES_PATH}")
# Get an array of bebox boxes paths
boxes = Dir["#{expanded_directory}/*"].reject {|f| File.directory? f}
boxes.map{|box| box.split('/').last}
end
|
ruby
|
def get_existing_boxes
# Converts the bebox boxes directory to an absolute pathname
expanded_directory = File.expand_path("#{BEBOX_BOXES_PATH}")
# Get an array of bebox boxes paths
boxes = Dir["#{expanded_directory}/*"].reject {|f| File.directory? f}
boxes.map{|box| box.split('/').last}
end
|
[
"def",
"get_existing_boxes",
"# Converts the bebox boxes directory to an absolute pathname",
"expanded_directory",
"=",
"File",
".",
"expand_path",
"(",
"\"#{BEBOX_BOXES_PATH}\"",
")",
"# Get an array of bebox boxes paths",
"boxes",
"=",
"Dir",
"[",
"\"#{expanded_directory}/*\"",
"]",
".",
"reject",
"{",
"|",
"f",
"|",
"File",
".",
"directory?",
"f",
"}",
"boxes",
".",
"map",
"{",
"|",
"box",
"|",
"box",
".",
"split",
"(",
"'/'",
")",
".",
"last",
"}",
"end"
] |
Obtain the current boxes downloaded or linked in the bebox user home
|
[
"Obtain",
"the",
"current",
"boxes",
"downloaded",
"or",
"linked",
"in",
"the",
"bebox",
"user",
"home"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/project_wizard.rb#L103-L109
|
5,997 |
codescrum/bebox
|
lib/bebox/wizards/project_wizard.rb
|
Bebox.ProjectWizard.choose_box
|
def choose_box(boxes)
# Menu to choose vagrant box provider
other_box_message = _('wizard.project.download_select_box')
boxes << other_box_message
current_box = choose_option(boxes, _('wizard.project.choose_box'))
current_box = (current_box == other_box_message) ? nil : current_box
end
|
ruby
|
def choose_box(boxes)
# Menu to choose vagrant box provider
other_box_message = _('wizard.project.download_select_box')
boxes << other_box_message
current_box = choose_option(boxes, _('wizard.project.choose_box'))
current_box = (current_box == other_box_message) ? nil : current_box
end
|
[
"def",
"choose_box",
"(",
"boxes",
")",
"# Menu to choose vagrant box provider",
"other_box_message",
"=",
"_",
"(",
"'wizard.project.download_select_box'",
")",
"boxes",
"<<",
"other_box_message",
"current_box",
"=",
"choose_option",
"(",
"boxes",
",",
"_",
"(",
"'wizard.project.choose_box'",
")",
")",
"current_box",
"=",
"(",
"current_box",
"==",
"other_box_message",
")",
"?",
"nil",
":",
"current_box",
"end"
] |
Asks to choose an existing box in the bebox boxes directory
|
[
"Asks",
"to",
"choose",
"an",
"existing",
"box",
"in",
"the",
"bebox",
"boxes",
"directory"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/project_wizard.rb#L112-L118
|
5,998 |
codescrum/bebox
|
lib/bebox/wizards/project_wizard.rb
|
Bebox.ProjectWizard.download_box
|
def download_box(uri)
require 'net/http'
require 'uri'
url = uri.path
# Download file to bebox boxes tmp
Net::HTTP.start(uri.host) do |http|
response = http.request_head(URI.escape(url))
write_remote_file(uri, http, response)
end
end
|
ruby
|
def download_box(uri)
require 'net/http'
require 'uri'
url = uri.path
# Download file to bebox boxes tmp
Net::HTTP.start(uri.host) do |http|
response = http.request_head(URI.escape(url))
write_remote_file(uri, http, response)
end
end
|
[
"def",
"download_box",
"(",
"uri",
")",
"require",
"'net/http'",
"require",
"'uri'",
"url",
"=",
"uri",
".",
"path",
"# Download file to bebox boxes tmp",
"Net",
"::",
"HTTP",
".",
"start",
"(",
"uri",
".",
"host",
")",
"do",
"|",
"http",
"|",
"response",
"=",
"http",
".",
"request_head",
"(",
"URI",
".",
"escape",
"(",
"url",
")",
")",
"write_remote_file",
"(",
"uri",
",",
"http",
",",
"response",
")",
"end",
"end"
] |
Download a box by the specified uri
|
[
"Download",
"a",
"box",
"by",
"the",
"specified",
"uri"
] |
0d19315847103341e599d32837ab0bd75524e5be
|
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/wizards/project_wizard.rb#L121-L130
|
5,999 |
riddopic/garcun
|
lib/garcon/task/executor.rb
|
Garcon.Executor.handle_fallback
|
def handle_fallback(*args)
case @fallback_policy
when :abort
raise RejectedExecutionError
when :discard
false
when :caller_runs
begin
yield(*args)
rescue => e
Chef::Log.debug "Caught exception => #{e}"
end
true
else
fail "Unknown fallback policy #{@fallback_policy}"
end
end
|
ruby
|
def handle_fallback(*args)
case @fallback_policy
when :abort
raise RejectedExecutionError
when :discard
false
when :caller_runs
begin
yield(*args)
rescue => e
Chef::Log.debug "Caught exception => #{e}"
end
true
else
fail "Unknown fallback policy #{@fallback_policy}"
end
end
|
[
"def",
"handle_fallback",
"(",
"*",
"args",
")",
"case",
"@fallback_policy",
"when",
":abort",
"raise",
"RejectedExecutionError",
"when",
":discard",
"false",
"when",
":caller_runs",
"begin",
"yield",
"(",
"args",
")",
"rescue",
"=>",
"e",
"Chef",
"::",
"Log",
".",
"debug",
"\"Caught exception => #{e}\"",
"end",
"true",
"else",
"fail",
"\"Unknown fallback policy #{@fallback_policy}\"",
"end",
"end"
] |
Handler which executes the `fallback_policy` once the queue size reaches
`max_queue`.
@param [Array] args
The arguments to the task which is being handled.
@!visibility private
|
[
"Handler",
"which",
"executes",
"the",
"fallback_policy",
"once",
"the",
"queue",
"size",
"reaches",
"max_queue",
"."
] |
c2409bd8cf9c14b967a719810dab5269d69b42de
|
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/executor.rb#L49-L65
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.