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
17,100
zeisler/active_mocker
lib/active_mocker/mock/queries.rb
ActiveMocker.Queries.sum
def sum(key) values = values_by_key(key) values.inject(0) do |sum, n| sum + (n || 0) end end
ruby
def sum(key) values = values_by_key(key) values.inject(0) do |sum, n| sum + (n || 0) end end
[ "def", "sum", "(", "key", ")", "values", "=", "values_by_key", "(", "key", ")", "values", ".", "inject", "(", "0", ")", "do", "|", "sum", ",", "n", "|", "sum", "+", "(", "n", "||", "0", ")", "end", "end" ]
Calculates the sum of values on a given column. The value is returned with the same data type of the column, 0 if there's no row. Person.sum(:age) # => 4562
[ "Calculates", "the", "sum", "of", "values", "on", "a", "given", "column", ".", "The", "value", "is", "returned", "with", "the", "same", "data", "type", "of", "the", "column", "0", "if", "there", "s", "no", "row", "." ]
bb03387df80708817de2f4d7fc9ca2d3f4b161c3
https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/queries.rb#L278-L283
17,101
zeisler/active_mocker
lib/active_mocker/mock/queries.rb
ActiveMocker.Queries.average
def average(key) values = values_by_key(key) total = values.inject { |sum, n| sum + n } BigDecimal.new(total) / BigDecimal.new(values.count) end
ruby
def average(key) values = values_by_key(key) total = values.inject { |sum, n| sum + n } BigDecimal.new(total) / BigDecimal.new(values.count) end
[ "def", "average", "(", "key", ")", "values", "=", "values_by_key", "(", "key", ")", "total", "=", "values", ".", "inject", "{", "|", "sum", ",", "n", "|", "sum", "+", "n", "}", "BigDecimal", ".", "new", "(", "total", ")", "/", "BigDecimal", ".", ...
Calculates the average value on a given column. Returns +nil+ if there's no row. PersonMock.average(:age) # => 35.8
[ "Calculates", "the", "average", "value", "on", "a", "given", "column", ".", "Returns", "+", "nil", "+", "if", "there", "s", "no", "row", "." ]
bb03387df80708817de2f4d7fc9ca2d3f4b161c3
https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/queries.rb#L289-L293
17,102
zeisler/active_mocker
lib/active_mocker/mock/base.rb
ActiveMocker.Base.slice
def slice(*methods) Hash[methods.map! { |method| [method, public_send(method)] }].with_indifferent_access end
ruby
def slice(*methods) Hash[methods.map! { |method| [method, public_send(method)] }].with_indifferent_access end
[ "def", "slice", "(", "*", "methods", ")", "Hash", "[", "methods", ".", "map!", "{", "|", "method", "|", "[", "method", ",", "public_send", "(", "method", ")", "]", "}", "]", ".", "with_indifferent_access", "end" ]
Returns a hash of the given methods with their names as keys and returned values as values.
[ "Returns", "a", "hash", "of", "the", "given", "methods", "with", "their", "names", "as", "keys", "and", "returned", "values", "as", "values", "." ]
bb03387df80708817de2f4d7fc9ca2d3f4b161c3
https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/base.rb#L322-L324
17,103
diogot/danger-xcode_summary
lib/xcode_summary/plugin.rb
Danger.DangerXcodeSummary.warning_error_count
def warning_error_count(file_path) if File.file?(file_path) xcode_summary = JSON.parse(File.read(file_path), symbolize_names: true) warning_count = warnings(xcode_summary).count error_count = errors(xcode_summary).count result = { warnings: warning_count, errors: error_count } ...
ruby
def warning_error_count(file_path) if File.file?(file_path) xcode_summary = JSON.parse(File.read(file_path), symbolize_names: true) warning_count = warnings(xcode_summary).count error_count = errors(xcode_summary).count result = { warnings: warning_count, errors: error_count } ...
[ "def", "warning_error_count", "(", "file_path", ")", "if", "File", ".", "file?", "(", "file_path", ")", "xcode_summary", "=", "JSON", ".", "parse", "(", "File", ".", "read", "(", "file_path", ")", ",", "symbolize_names", ":", "true", ")", "warning_count", ...
Reads a file with JSON Xcode summary and reports its warning and error count. @param [String] file_path Path for Xcode summary in JSON format. @return [String] JSON string with warningCount and errorCount
[ "Reads", "a", "file", "with", "JSON", "Xcode", "summary", "and", "reports", "its", "warning", "and", "error", "count", "." ]
661bd0318e4dc719267422331def569088dde7bd
https://github.com/diogot/danger-xcode_summary/blob/661bd0318e4dc719267422331def569088dde7bd/lib/xcode_summary/plugin.rb#L118-L128
17,104
tom-lord/regexp-examples
lib/regexp-examples/groups.rb
RegexpExamples.MultiGroup.result
def result strings = @groups.map { |repeater| repeater.public_send(__callee__) } RegexpExamples.permutations_of_strings(strings).map do |result| GroupResult.new(result, group_id) end end
ruby
def result strings = @groups.map { |repeater| repeater.public_send(__callee__) } RegexpExamples.permutations_of_strings(strings).map do |result| GroupResult.new(result, group_id) end end
[ "def", "result", "strings", "=", "@groups", ".", "map", "{", "|", "repeater", "|", "repeater", ".", "public_send", "(", "__callee__", ")", "}", "RegexpExamples", ".", "permutations_of_strings", "(", "strings", ")", ".", "map", "do", "|", "result", "|", "Gr...
Generates the result of each contained group and adds the filled group of each result to itself
[ "Generates", "the", "result", "of", "each", "contained", "group", "and", "adds", "the", "filled", "group", "of", "each", "result", "to", "itself" ]
90229731daf8a40bf34b739a12e403d2bc45d272
https://github.com/tom-lord/regexp-examples/blob/90229731daf8a40bf34b739a12e403d2bc45d272/lib/regexp-examples/groups.rb#L127-L132
17,105
Fullscreen/bh
lib/bh/helpers/button_helper.rb
Bh.Helpers.button
def button(*args, &block) button = Bh::Button.new(self, *args, &block) button.extract! :context, :size, :layout button.append_class! :btn button.append_class! button.context_class button.append_class! button.size_class button.append_class! button.layout_class button.render_tag...
ruby
def button(*args, &block) button = Bh::Button.new(self, *args, &block) button.extract! :context, :size, :layout button.append_class! :btn button.append_class! button.context_class button.append_class! button.size_class button.append_class! button.layout_class button.render_tag...
[ "def", "button", "(", "*", "args", ",", "&", "block", ")", "button", "=", "Bh", "::", "Button", ".", "new", "(", "self", ",", "args", ",", "block", ")", "button", ".", "extract!", ":context", ",", ":size", ",", ":layout", "button", ".", "append_class...
Displays a Bootstrap-styled button. @see http://getbootstrap.com/css/#buttons @return [String] the HTML to display a Bootstrap-styled button. @overload button(caption, options = {}) @param [#to_s] caption the caption to display in the button. @param [Hash] options the options for the button. Any option not ...
[ "Displays", "a", "Bootstrap", "-", "styled", "button", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/button_helper.rb#L29-L38
17,106
Fullscreen/bh
lib/bh/helpers/panel_row_helper.rb
Bh.Helpers.panel_row
def panel_row(options = {}, &block) panel_row = Bh::PanelRow.new self, options, &block panel_row.extract! :column_class panel_row.append_class! :row panel_row.render_tag :div end
ruby
def panel_row(options = {}, &block) panel_row = Bh::PanelRow.new self, options, &block panel_row.extract! :column_class panel_row.append_class! :row panel_row.render_tag :div end
[ "def", "panel_row", "(", "options", "=", "{", "}", ",", "&", "block", ")", "panel_row", "=", "Bh", "::", "PanelRow", ".", "new", "self", ",", "options", ",", "block", "panel_row", ".", "extract!", ":column_class", "panel_row", ".", "append_class!", ":row",...
Wraps a set of Bootstrap-styled panels in a row. @see http://getbootstrap.com/components/#panels @see http://getbootstrap.com/css/#grid @return [String] the HTML to display a row of Bootstrap-styled panels. @param [Hash] options the options for the row. Any option not listed below is passed as an HTML attribute ...
[ "Wraps", "a", "set", "of", "Bootstrap", "-", "styled", "panels", "in", "a", "row", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/panel_row_helper.rb#L20-L26
17,107
Fullscreen/bh
lib/bh/helpers/panel_helper.rb
Bh.Helpers.panel
def panel(*args, &block) panel = Bh::Panel.new self, *args, &block panel.extract! :body, :context, :title, :heading, :tag panel.append_class! :panel panel.append_class! panel.context_class panel.merge_html! panel.body panel.prepend_html! panel.heading if panel_row = Bh::Stack...
ruby
def panel(*args, &block) panel = Bh::Panel.new self, *args, &block panel.extract! :body, :context, :title, :heading, :tag panel.append_class! :panel panel.append_class! panel.context_class panel.merge_html! panel.body panel.prepend_html! panel.heading if panel_row = Bh::Stack...
[ "def", "panel", "(", "*", "args", ",", "&", "block", ")", "panel", "=", "Bh", "::", "Panel", ".", "new", "self", ",", "args", ",", "block", "panel", ".", "extract!", ":body", ",", ":context", ",", ":title", ",", ":heading", ",", ":tag", "panel", "....
Displays a Bootstrap-styled panel. @see http://getbootstrap.com/components/#panels @return [String] the HTML to display a Bootstrap-styled panel. @overload panel(body, options = {}) @param [#to_s] body the content to display as the panel body. @param [Hash] options the options for the panel. Any option not ...
[ "Displays", "a", "Bootstrap", "-", "styled", "panel", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/panel_helper.rb#L35-L51
17,108
Fullscreen/bh
lib/bh/helpers/modal_helper.rb
Bh.Helpers.modal
def modal(*args, &block) modal = Bh::Modal.new self, *args, &block modal.extract! :button, :size, :body, :title, :id modal.extract_from :button, [:context, :size, :layout, :caption] modal.append_class_to! :button, :btn modal.append_class_to! :button, modal.button_context_class modal...
ruby
def modal(*args, &block) modal = Bh::Modal.new self, *args, &block modal.extract! :button, :size, :body, :title, :id modal.extract_from :button, [:context, :size, :layout, :caption] modal.append_class_to! :button, :btn modal.append_class_to! :button, modal.button_context_class modal...
[ "def", "modal", "(", "*", "args", ",", "&", "block", ")", "modal", "=", "Bh", "::", "Modal", ".", "new", "self", ",", "args", ",", "block", "modal", ".", "extract!", ":button", ",", ":size", ",", ":body", ",", ":title", ",", ":id", "modal", ".", ...
Displays a Bootstrap-styled modal. @see http://getbootstrap.com/javascript/#modals @return [String] the HTML to display a Bootstrap-styled modal. @overload modal(body, options = {}) @param [#to_s] body the content to display as the modal body. @param [Hash] options the options for the modal. Any option not lis...
[ "Displays", "a", "Bootstrap", "-", "styled", "modal", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/modal_helper.rb#L38-L53
17,109
Fullscreen/bh
lib/bh/helpers/nav_helper.rb
Bh.Helpers.nav
def nav(options = {}, &block) nav = Bh::Nav.new(self, options, &block) nav.extract! :as, :layout nav.append_class! :nav if Bh::Stack.find(Bh::Navbar) nav.append_class! :'navbar-nav' else nav.merge! role: :tablist nav.append_class! nav.style_class nav.append...
ruby
def nav(options = {}, &block) nav = Bh::Nav.new(self, options, &block) nav.extract! :as, :layout nav.append_class! :nav if Bh::Stack.find(Bh::Navbar) nav.append_class! :'navbar-nav' else nav.merge! role: :tablist nav.append_class! nav.style_class nav.append...
[ "def", "nav", "(", "options", "=", "{", "}", ",", "&", "block", ")", "nav", "=", "Bh", "::", "Nav", ".", "new", "(", "self", ",", "options", ",", "block", ")", "nav", ".", "extract!", ":as", ",", ":layout", "nav", ".", "append_class!", ":nav", "i...
Displays a Bootstrap-styled nav. @see http://getbootstrap.com/components/#nav @return [String] the HTML to display a Bootstrap-styled nav. @param [Hash] options the options for the nav. Any option not listed below is passed as an HTML attribute to the alert’s `<ul>`. @option options [#to_s] :as (:tabs) the style...
[ "Displays", "a", "Bootstrap", "-", "styled", "nav", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/nav_helper.rb#L20-L34
17,110
Fullscreen/bh
lib/bh/helpers/horizontal_helper.rb
Bh.Helpers.horizontal
def horizontal(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) horizontal = Bh::Base.new self, *args, &block horizontal.append_class! :'collapse navbar-collapse' horizontal.merge! id: navbar.id horizontal.render_tag :div end end
ruby
def horizontal(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) horizontal = Bh::Base.new self, *args, &block horizontal.append_class! :'collapse navbar-collapse' horizontal.merge! id: navbar.id horizontal.render_tag :div end end
[ "def", "horizontal", "(", "*", "args", ",", "&", "block", ")", "if", "navbar", "=", "Bh", "::", "Stack", ".", "find", "(", "Bh", "::", "Navbar", ")", "horizontal", "=", "Bh", "::", "Base", ".", "new", "self", ",", "args", ",", "block", "horizontal"...
Displays the collapsable portion of a Bootstrap-styled navbar. @see http://getbootstrap.com/components/#navbar @return [String] the HTML to display the collapsable portion of a Bootstrap-styled navbar. @overload horizontal(content, options = {}) @param [#to_s] content the collapsable content to display in the ...
[ "Displays", "the", "collapsable", "portion", "of", "a", "Bootstrap", "-", "styled", "navbar", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/horizontal_helper.rb#L26-L33
17,111
Fullscreen/bh
lib/bh/helpers/icon_helper.rb
Bh.Helpers.icon
def icon(name = nil, options = {}) icon = Bh::Icon.new self, nil, options.merge(name: name) icon.extract! :library, :name icon.append_class! icon.library_class icon.append_class! icon.name_class icon.render_tag :span end
ruby
def icon(name = nil, options = {}) icon = Bh::Icon.new self, nil, options.merge(name: name) icon.extract! :library, :name icon.append_class! icon.library_class icon.append_class! icon.name_class icon.render_tag :span end
[ "def", "icon", "(", "name", "=", "nil", ",", "options", "=", "{", "}", ")", "icon", "=", "Bh", "::", "Icon", ".", "new", "self", ",", "nil", ",", "options", ".", "merge", "(", "name", ":", "name", ")", "icon", ".", "extract!", ":library", ",", ...
Displays a Bootstrap-styled vector icon. @see http://getbootstrap.com/components/#glyphicons @see http://fortawesome.github.io/Font-Awesome/examples/#bootstrap @return [String] the HTML to display a vector (font) icon. @param [#to_s] name the name of the icon to display, with either dashes or underscores to sepa...
[ "Displays", "a", "Bootstrap", "-", "styled", "vector", "icon", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/icon_helper.rb#L18-L25
17,112
Fullscreen/bh
lib/bh/helpers/vertical_helper.rb
Bh.Helpers.vertical
def vertical(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) vertical = Bh::Vertical.new self, *args, &block vertical.append_class! :'navbar-header' vertical.prepend_html! vertical.toggle_button(navbar.id) vertical.render_tag :div end end
ruby
def vertical(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) vertical = Bh::Vertical.new self, *args, &block vertical.append_class! :'navbar-header' vertical.prepend_html! vertical.toggle_button(navbar.id) vertical.render_tag :div end end
[ "def", "vertical", "(", "*", "args", ",", "&", "block", ")", "if", "navbar", "=", "Bh", "::", "Stack", ".", "find", "(", "Bh", "::", "Navbar", ")", "vertical", "=", "Bh", "::", "Vertical", ".", "new", "self", ",", "args", ",", "block", "vertical", ...
Displays the non-collapsable portion of a Bootstrap-styled navbar. @see http://getbootstrap.com/components/#navbar @return [String] the HTML to display the non-collapsable portion of a Bootstrap-styled navbar. @overload vertical(content, options = {}) @param [#to_s] content the non-collapsable content to displ...
[ "Displays", "the", "non", "-", "collapsable", "portion", "of", "a", "Bootstrap", "-", "styled", "navbar", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/vertical_helper.rb#L24-L31
17,113
Fullscreen/bh
lib/bh/helpers/progress_bar_helper.rb
Bh.Helpers.progress_bar
def progress_bar(args = nil, container_options = {}) progress_bars = Array.wrap(args).map do |options| progress_bar = Bh::ProgressBar.new self, nil, options progress_bar.extract! :percentage, :context, :striped, :animated, :label progress_bar.merge! progress_bar.aria_values progre...
ruby
def progress_bar(args = nil, container_options = {}) progress_bars = Array.wrap(args).map do |options| progress_bar = Bh::ProgressBar.new self, nil, options progress_bar.extract! :percentage, :context, :striped, :animated, :label progress_bar.merge! progress_bar.aria_values progre...
[ "def", "progress_bar", "(", "args", "=", "nil", ",", "container_options", "=", "{", "}", ")", "progress_bars", "=", "Array", ".", "wrap", "(", "args", ")", ".", "map", "do", "|", "options", "|", "progress_bar", "=", "Bh", "::", "ProgressBar", ".", "new...
Displays one or more Bootstrap-styled progress bars. @see http://getbootstrap.com/components/#progress @return [String] the HTML to display Bootstrap-styled progress bars. @overload progress_bar(bar_options = {}, container_options = {}) @param [Hash] bar_options the options to display a single progress bar. ...
[ "Displays", "one", "or", "more", "Bootstrap", "-", "styled", "progress", "bars", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/progress_bar_helper.rb#L35-L53
17,114
Fullscreen/bh
lib/bh/helpers/navbar_helper.rb
Bh.Helpers.navbar
def navbar(options = {}, &block) navbar = Bh::Navbar.new(self, options, &block) navbar.extract! :inverted, :position, :padding, :fluid, :id navbar.append_class_to! :navigation, :navbar navbar.append_class_to! :navigation, navbar.style_class navbar.append_class_to! :navigation, navbar.posi...
ruby
def navbar(options = {}, &block) navbar = Bh::Navbar.new(self, options, &block) navbar.extract! :inverted, :position, :padding, :fluid, :id navbar.append_class_to! :navigation, :navbar navbar.append_class_to! :navigation, navbar.style_class navbar.append_class_to! :navigation, navbar.posi...
[ "def", "navbar", "(", "options", "=", "{", "}", ",", "&", "block", ")", "navbar", "=", "Bh", "::", "Navbar", ".", "new", "(", "self", ",", "options", ",", "block", ")", "navbar", ".", "extract!", ":inverted", ",", ":position", ",", ":padding", ",", ...
Displays a Bootstrap-styled navbar. @see http://getbootstrap.com/components/#navbar @return [String] the HTML to display a Bootstrap-styled navbar. @param [Hash] options the options for the navbar. Any option not listed below is ignored, except for `:id` which is passed as an HTML attribute to the navbar’s col...
[ "Displays", "a", "Bootstrap", "-", "styled", "navbar", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/navbar_helper.rb#L35-L46
17,115
Fullscreen/bh
lib/bh/helpers/link_to_helper.rb
Bh.Helpers.link_to
def link_to(*args, &block) link_to = Bh::LinkTo.new self, *args, &block link_to.append_class! :'alert-link' if Bh::Stack.find(Bh::AlertBox) link_to.append_class! :'navbar-brand' if Bh::Stack.find(Bh::Vertical) link_to.merge! role: :menuitem if Bh::Stack.find(Bh::Dropdown) link_to.merge! t...
ruby
def link_to(*args, &block) link_to = Bh::LinkTo.new self, *args, &block link_to.append_class! :'alert-link' if Bh::Stack.find(Bh::AlertBox) link_to.append_class! :'navbar-brand' if Bh::Stack.find(Bh::Vertical) link_to.merge! role: :menuitem if Bh::Stack.find(Bh::Dropdown) link_to.merge! t...
[ "def", "link_to", "(", "*", "args", ",", "&", "block", ")", "link_to", "=", "Bh", "::", "LinkTo", ".", "new", "self", ",", "args", ",", "block", "link_to", ".", "append_class!", ":'", "'", "if", "Bh", "::", "Stack", ".", "find", "(", "Bh", "::", ...
Overrides `link_to` to display a Bootstrap-styled link. Can only be used in Ruby frameworks that provide the `link_to` method. @see http://getbootstrap.com/components/#dropdowns @see http://getbootstrap.com/components/#nav @see http://getbootstrap.com/components/#navbar-brand-image @see http://getbootstrap.com/com...
[ "Overrides", "link_to", "to", "display", "a", "Bootstrap", "-", "styled", "link", ".", "Can", "only", "be", "used", "in", "Ruby", "frameworks", "that", "provide", "the", "link_to", "method", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/link_to_helper.rb#L37-L57
17,116
Fullscreen/bh
lib/bh/helpers/alert_box_helper.rb
Bh.Helpers.alert_box
def alert_box(*args, &block) alert_box = Bh::AlertBox.new(self, *args, &block) alert_box.extract! :context, :priority, :dismissible alert_box.append_class! :alert alert_box.append_class! alert_box.context_class alert_box.merge! role: :alert alert_box.prepend_html! alert_box.dismissi...
ruby
def alert_box(*args, &block) alert_box = Bh::AlertBox.new(self, *args, &block) alert_box.extract! :context, :priority, :dismissible alert_box.append_class! :alert alert_box.append_class! alert_box.context_class alert_box.merge! role: :alert alert_box.prepend_html! alert_box.dismissi...
[ "def", "alert_box", "(", "*", "args", ",", "&", "block", ")", "alert_box", "=", "Bh", "::", "AlertBox", ".", "new", "(", "self", ",", "args", ",", "block", ")", "alert_box", ".", "extract!", ":context", ",", ":priority", ",", ":dismissible", "alert_box",...
Displays a Bootstrap-styled alert message. @see http://getbootstrap.com/components/#alerts @return [String] the HTML to display a Bootstrap-styled alert message. @overload alert_box(content, options = {}) @param [#to_s] content the content to display in the alert. @param [Hash] options the options for the aler...
[ "Displays", "a", "Bootstrap", "-", "styled", "alert", "message", "." ]
b9ad77bf9435dfbc4522958ea9a81415418433e6
https://github.com/Fullscreen/bh/blob/b9ad77bf9435dfbc4522958ea9a81415418433e6/lib/bh/helpers/alert_box_helper.rb#L29-L38
17,117
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.otherwise
def otherwise(first, second) first = first.to_s first.empty? ? second : first end
ruby
def otherwise(first, second) first = first.to_s first.empty? ? second : first end
[ "def", "otherwise", "(", "first", ",", "second", ")", "first", "=", "first", ".", "to_s", "first", ".", "empty?", "?", "second", ":", "first", "end" ]
Returns the first argument if it's not nil or empty otherwise it returns the second one. {{ post.author | otherwise:site.author }}
[ "Returns", "the", "first", "argument", "if", "it", "s", "not", "nil", "or", "empty", "otherwise", "it", "returns", "the", "second", "one", "." ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L47-L50
17,118
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.audio
def audio(hsh, key = nil) if !hsh.nil? && hsh.length if key.nil? hsh['mp3'] ? hsh['mp3'] : hsh['m4a'] ? hsh['m4a'] : hsh['ogg'] ? hsh['ogg'] : hsh['opus'] ? hsh['opus'] : hsh.values.first else hsh[key] end end end
ruby
def audio(hsh, key = nil) if !hsh.nil? && hsh.length if key.nil? hsh['mp3'] ? hsh['mp3'] : hsh['m4a'] ? hsh['m4a'] : hsh['ogg'] ? hsh['ogg'] : hsh['opus'] ? hsh['opus'] : hsh.values.first else hsh[key] end end end
[ "def", "audio", "(", "hsh", ",", "key", "=", "nil", ")", "if", "!", "hsh", ".", "nil?", "&&", "hsh", ".", "length", "if", "key", ".", "nil?", "hsh", "[", "'mp3'", "]", "?", "hsh", "[", "'mp3'", "]", ":", "hsh", "[", "'m4a'", "]", "?", "hsh", ...
Returns the audio file name of a given hash. Is no key as second parameter given, it trys first "mp3", than "m4a" and than it will return a more or less random value. {{ post.audio | audio:"m4a" }} => "my-episode.m4a"
[ "Returns", "the", "audio", "file", "name", "of", "a", "given", "hash", ".", "Is", "no", "key", "as", "second", "parameter", "given", "it", "trys", "first", "mp3", "than", "m4a", "and", "than", "it", "will", "return", "a", "more", "or", "less", "random"...
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L57-L65
17,119
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.audio_type
def audio_type(hsh) if !hsh.nil? && hsh.length hsh['mp3'] ? mime_type('mp3') : hsh['m4a'] ? mime_type('m4a') : hsh['ogg'] ? mime_type('ogg') : mime_type('opus') end end
ruby
def audio_type(hsh) if !hsh.nil? && hsh.length hsh['mp3'] ? mime_type('mp3') : hsh['m4a'] ? mime_type('m4a') : hsh['ogg'] ? mime_type('ogg') : mime_type('opus') end end
[ "def", "audio_type", "(", "hsh", ")", "if", "!", "hsh", ".", "nil?", "&&", "hsh", ".", "length", "hsh", "[", "'mp3'", "]", "?", "mime_type", "(", "'mp3'", ")", ":", "hsh", "[", "'m4a'", "]", "?", "mime_type", "(", "'m4a'", ")", ":", "hsh", "[", ...
Returns the audio-type of a given hash. Is no key as second parameter given, it trys first "mp3", than "m4a" and than it will return a more or less random value. {{ post.audio | audiotype }} => "my-episode.m4a"
[ "Returns", "the", "audio", "-", "type", "of", "a", "given", "hash", ".", "Is", "no", "key", "as", "second", "parameter", "given", "it", "trys", "first", "mp3", "than", "m4a", "and", "than", "it", "will", "return", "a", "more", "or", "less", "random", ...
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L73-L77
17,120
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.split_chapter
def split_chapter(chapter_str, attribute = nil) attributes = chapter_str.split(/ /, 2) return nil unless attributes.first.match(/\A(\d|:|\.)+\z/) if attribute.nil? { 'start' => attributes.first, 'title' => attributes.last } else attribute == 'start' ? attributes.first : attribut...
ruby
def split_chapter(chapter_str, attribute = nil) attributes = chapter_str.split(/ /, 2) return nil unless attributes.first.match(/\A(\d|:|\.)+\z/) if attribute.nil? { 'start' => attributes.first, 'title' => attributes.last } else attribute == 'start' ? attributes.first : attribut...
[ "def", "split_chapter", "(", "chapter_str", ",", "attribute", "=", "nil", ")", "attributes", "=", "chapter_str", ".", "split", "(", "/", "/", ",", "2", ")", "return", "nil", "unless", "attributes", ".", "first", ".", "match", "(", "/", "\\A", "\\d", "\...
Splits a chapter, like it is written to the post YAML front matter into the components 'start' which refers to a single point in time relative to the beginning of the media file nad 'title' which defines the text to be the title of the chapter. {{ '00:00:00.000 Welcome to Octopod!' | split_chapter }} => { '...
[ "Splits", "a", "chapter", "like", "it", "is", "written", "to", "the", "post", "YAML", "front", "matter", "into", "the", "components", "start", "which", "refers", "to", "a", "single", "point", "in", "time", "relative", "to", "the", "beginning", "of", "the",...
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L147-L156
17,121
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.string_of_size
def string_of_size(bytes) bytes = bytes.to_i.to_f out = '0' return out if bytes == 0.0 jedec = %w[b K M G] [3, 2, 1, 0].each { |i| if bytes > 1024 ** i out = "%.1f#{jedec[i]}" % (bytes / 1024 ** i) break end } return out end
ruby
def string_of_size(bytes) bytes = bytes.to_i.to_f out = '0' return out if bytes == 0.0 jedec = %w[b K M G] [3, 2, 1, 0].each { |i| if bytes > 1024 ** i out = "%.1f#{jedec[i]}" % (bytes / 1024 ** i) break end } return out end
[ "def", "string_of_size", "(", "bytes", ")", "bytes", "=", "bytes", ".", "to_i", ".", "to_f", "out", "=", "'0'", "return", "out", "if", "bytes", "==", "0.0", "jedec", "=", "%w[", "b", "K", "M", "G", "]", "[", "3", ",", "2", ",", "1", ",", "0", ...
Gets a number of bytes and returns an human readable string of it. {{ 1252251 | string_of_size }} => "1.19M"
[ "Gets", "a", "number", "of", "bytes", "and", "returns", "an", "human", "readable", "string", "of", "it", "." ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L174-L188
17,122
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.disqus_config
def disqus_config(site, page = nil) if page disqus_vars = { 'disqus_identifier' => page['url'], 'disqus_url' => "#{site['url']}#{page['url']}", 'disqus_category_id' => page['disqus_category_id'] || site['disqus_category_id'], 'disqus_title' => j(page[...
ruby
def disqus_config(site, page = nil) if page disqus_vars = { 'disqus_identifier' => page['url'], 'disqus_url' => "#{site['url']}#{page['url']}", 'disqus_category_id' => page['disqus_category_id'] || site['disqus_category_id'], 'disqus_title' => j(page[...
[ "def", "disqus_config", "(", "site", ",", "page", "=", "nil", ")", "if", "page", "disqus_vars", "=", "{", "'disqus_identifier'", "=>", "page", "[", "'url'", "]", ",", "'disqus_url'", "=>", "\"#{site['url']}#{page['url']}\"", ",", "'disqus_category_id'", "=>", "p...
Generates the config for disqus integration If a page object is given, it generates the config variables only for this page. Otherwise it generate only the global config variables. {{ site | disqus_config }} {{ site | disqus_config:page }}
[ "Generates", "the", "config", "for", "disqus", "integration", "If", "a", "page", "object", "is", "given", "it", "generates", "the", "config", "variables", "only", "for", "this", "page", ".", "Otherwise", "it", "generate", "only", "the", "global", "config", "...
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L203-L220
17,123
jekyll-octopod/jekyll-octopod
lib/jekyll/octopod_filters.rb
Jekyll.OctopodFilters.sha1
def sha1(str, lenght = 8) sha1 = Digest::SHA1.hexdigest(str) sha1[0, lenght.to_i] end
ruby
def sha1(str, lenght = 8) sha1 = Digest::SHA1.hexdigest(str) sha1[0, lenght.to_i] end
[ "def", "sha1", "(", "str", ",", "lenght", "=", "8", ")", "sha1", "=", "Digest", "::", "SHA1", ".", "hexdigest", "(", "str", ")", "sha1", "[", "0", ",", "lenght", ".", "to_i", "]", "end" ]
Returns the hex-encoded hash value of a given string. The optional second argument defines the length of the returned string. {{ "Octopod" | sha1 }} => "8b20a59c" {{ "Octopod" | sha1:23 }} => "8b20a59c8e2dcb5e1f845ba"
[ "Returns", "the", "hex", "-", "encoded", "hash", "value", "of", "a", "given", "string", ".", "The", "optional", "second", "argument", "defines", "the", "length", "of", "the", "returned", "string", "." ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/octopod_filters.rb#L227-L230
17,124
jekyll-octopod/jekyll-octopod
lib/jekyll/date_de.rb
Jekyll.DateDe.format_date
def format_date(date, format) date = datetime(date) if format.nil? || format.empty? || format == "ordinal" date_formatted = ordinalize(date) else format.gsub!(/%a/, ABBR_DAYNAMES_DE[date.wday]) format.gsub!(/%A/, DAYNAMES_DE[date.wday]) format.gsub!(/%b/, AB...
ruby
def format_date(date, format) date = datetime(date) if format.nil? || format.empty? || format == "ordinal" date_formatted = ordinalize(date) else format.gsub!(/%a/, ABBR_DAYNAMES_DE[date.wday]) format.gsub!(/%A/, DAYNAMES_DE[date.wday]) format.gsub!(/%b/, AB...
[ "def", "format_date", "(", "date", ",", "format", ")", "date", "=", "datetime", "(", "date", ")", "if", "format", ".", "nil?", "||", "format", ".", "empty?", "||", "format", "==", "\"ordinal\"", "date_formatted", "=", "ordinalize", "(", "date", ")", "els...
Formats date by given date format
[ "Formats", "date", "by", "given", "date", "format" ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/date_de.rb#L32-L44
17,125
jekyll-octopod/jekyll-octopod
lib/jekyll/flattr_filters.rb
Jekyll.FlattrFilters.flattr_loader_options
def flattr_loader_options(site) return if site['flattr_uid'].nil? keys = %w[mode https popout uid button language category] options = flattr_options(site, nil, keys).delete_if { |_, v| v.to_s.empty? } options.map { |k, v| "#{k}=#{ERB::Util.url_encode(v)}" }.join('&') end
ruby
def flattr_loader_options(site) return if site['flattr_uid'].nil? keys = %w[mode https popout uid button language category] options = flattr_options(site, nil, keys).delete_if { |_, v| v.to_s.empty? } options.map { |k, v| "#{k}=#{ERB::Util.url_encode(v)}" }.join('&') end
[ "def", "flattr_loader_options", "(", "site", ")", "return", "if", "site", "[", "'flattr_uid'", "]", ".", "nil?", "keys", "=", "%w[", "mode", "https", "popout", "uid", "button", "language", "category", "]", "options", "=", "flattr_options", "(", "site", ",", ...
Generates the query string part for the flattr load.js from the configurations in _config.yml {{ site | flattr_loader_options }}
[ "Generates", "the", "query", "string", "part", "for", "the", "flattr", "load", ".", "js", "from", "the", "configurations", "in", "_config", ".", "yml" ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/flattr_filters.rb#L9-L15
17,126
jekyll-octopod/jekyll-octopod
lib/jekyll/flattr_filters.rb
Jekyll.FlattrFilters.flattr_button
def flattr_button(site, page = nil) return if site['flattr_uid'].nil? keys = %w[url title description uid popout button category language tags] options = flattr_options(site, page, keys) button = '<a class="FlattrButton" style="display:none;" ' button << %Q{title="#{options.delete('titl...
ruby
def flattr_button(site, page = nil) return if site['flattr_uid'].nil? keys = %w[url title description uid popout button category language tags] options = flattr_options(site, page, keys) button = '<a class="FlattrButton" style="display:none;" ' button << %Q{title="#{options.delete('titl...
[ "def", "flattr_button", "(", "site", ",", "page", "=", "nil", ")", "return", "if", "site", "[", "'flattr_uid'", "]", ".", "nil?", "keys", "=", "%w[", "url", "title", "description", "uid", "popout", "button", "category", "language", "tags", "]", "options", ...
Returns a flattr button {{ site | flattr_button:page }}
[ "Returns", "a", "flattr", "button" ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/flattr_filters.rb#L20-L32
17,127
jekyll-octopod/jekyll-octopod
lib/jekyll/flattr_filters.rb
Jekyll.FlattrFilters.flattrize
def flattrize(hsh) config = {} hsh.to_hash.each { |k, v| if new_key = k.to_s.match(/\Aflattr_(.*)\z/) config[new_key[1]] = v else config[k] = v end } config end
ruby
def flattrize(hsh) config = {} hsh.to_hash.each { |k, v| if new_key = k.to_s.match(/\Aflattr_(.*)\z/) config[new_key[1]] = v else config[k] = v end } config end
[ "def", "flattrize", "(", "hsh", ")", "config", "=", "{", "}", "hsh", ".", "to_hash", ".", "each", "{", "|", "k", ",", "v", "|", "if", "new_key", "=", "k", ".", "to_s", ".", "match", "(", "/", "\\A", "\\z", "/", ")", "config", "[", "new_key", ...
Removes all leading "flattr_" from the keys of the given hash. flattrize({ 'octopod' => 'awesome', 'flattr_uid' => 'pattex' }) => { "octopod" => "awesome", "uid" => "pattex" }
[ "Removes", "all", "leading", "flattr_", "from", "the", "keys", "of", "the", "given", "hash", "." ]
bc01a6b1d0b809dbd458bc7cec762c453a7a9be5
https://github.com/jekyll-octopod/jekyll-octopod/blob/bc01a6b1d0b809dbd458bc7cec762c453a7a9be5/lib/jekyll/flattr_filters.rb#L56-L67
17,128
gocardless/prius
lib/prius/registry.rb
Prius.Registry.load
def load(name, options = {}) env_var = options.fetch(:env_var, name.to_s.upcase) type = options.fetch(:type, :string) required = options.fetch(:required, true) @registry[name] = case type when :string then load_string(env_var, required) when :int ...
ruby
def load(name, options = {}) env_var = options.fetch(:env_var, name.to_s.upcase) type = options.fetch(:type, :string) required = options.fetch(:required, true) @registry[name] = case type when :string then load_string(env_var, required) when :int ...
[ "def", "load", "(", "name", ",", "options", "=", "{", "}", ")", "env_var", "=", "options", ".", "fetch", "(", ":env_var", ",", "name", ".", "to_s", ".", "upcase", ")", "type", "=", "options", ".", "fetch", "(", ":type", ",", ":string", ")", "requir...
Initialise a Registry. env - A Hash used as a source for environment variables. Usually, ENV will be used. See Prius.load for documentation.
[ "Initialise", "a", "Registry", "." ]
786656cc97ca6d8b613e4f41495715296290d07f
https://github.com/gocardless/prius/blob/786656cc97ca6d8b613e4f41495715296290d07f/lib/prius/registry.rb#L15-L25
17,129
airbnb/interferon
lib/interferon.rb
Interferon.Interferon.run
def run start_time = Time.new.to_f Signal.trap('TERM') do log.info('SIGTERM received. shutting down gracefully...') @request_shutdown = true end run_desc = @dry_run ? 'dry run' : 'run' log.info("beginning alerts #{run_desc}") alerts = read_alerts(@alert_sources) ...
ruby
def run start_time = Time.new.to_f Signal.trap('TERM') do log.info('SIGTERM received. shutting down gracefully...') @request_shutdown = true end run_desc = @dry_run ? 'dry run' : 'run' log.info("beginning alerts #{run_desc}") alerts = read_alerts(@alert_sources) ...
[ "def", "run", "start_time", "=", "Time", ".", "new", ".", "to_f", "Signal", ".", "trap", "(", "'TERM'", ")", "do", "log", ".", "info", "(", "'SIGTERM received. shutting down gracefully...'", ")", "@request_shutdown", "=", "true", "end", "run_desc", "=", "@dry_...
groups_sources is a hash from type => options for each group source host_sources is a hash from type => options for each host source destinations is a similar hash from type => options for each alerter
[ "groups_sources", "is", "a", "hash", "from", "type", "=", ">", "options", "for", "each", "group", "source", "host_sources", "is", "a", "hash", "from", "type", "=", ">", "options", "for", "each", "host", "source", "destinations", "is", "a", "similar", "hash...
4f91dc782ce1b818e2cd35146d565847fe4e023d
https://github.com/airbnb/interferon/blob/4f91dc782ce1b818e2cd35146d565847fe4e023d/lib/interferon.rb#L39-L66
17,130
airbnb/interferon
lib/interferon/host_sources/aws_rds.rb
Interferon::HostSources.AwsRds.account_number
def account_number return @account_number if @account_number begin my_arn = AWS::IAM.new( access_key_id: @access_key_id, secret_access_key: @secret_access_key ).client.get_user[:user][:arn] rescue AWS::IAM::Errors::AccessDenied => e my_arn = e.message.split...
ruby
def account_number return @account_number if @account_number begin my_arn = AWS::IAM.new( access_key_id: @access_key_id, secret_access_key: @secret_access_key ).client.get_user[:user][:arn] rescue AWS::IAM::Errors::AccessDenied => e my_arn = e.message.split...
[ "def", "account_number", "return", "@account_number", "if", "@account_number", "begin", "my_arn", "=", "AWS", "::", "IAM", ".", "new", "(", "access_key_id", ":", "@access_key_id", ",", "secret_access_key", ":", "@secret_access_key", ")", ".", "client", ".", "get_u...
unfortunately, this appears to be the only way to get your account number
[ "unfortunately", "this", "appears", "to", "be", "the", "only", "way", "to", "get", "your", "account", "number" ]
4f91dc782ce1b818e2cd35146d565847fe4e023d
https://github.com/airbnb/interferon/blob/4f91dc782ce1b818e2cd35146d565847fe4e023d/lib/interferon/host_sources/aws_rds.rb#L78-L91
17,131
zverok/time_math2
lib/time_math/op.rb
TimeMath.Op.call
def call(*tms) unless @arguments.empty? tms.empty? or raise(ArgumentError, 'Op arguments is already set, use call()') tms = @arguments end res = [*tms].flatten.map(&method(:perform)) tms.count == 1 && Util.timey?(tms.first) ? res.first : res end
ruby
def call(*tms) unless @arguments.empty? tms.empty? or raise(ArgumentError, 'Op arguments is already set, use call()') tms = @arguments end res = [*tms].flatten.map(&method(:perform)) tms.count == 1 && Util.timey?(tms.first) ? res.first : res end
[ "def", "call", "(", "*", "tms", ")", "unless", "@arguments", ".", "empty?", "tms", ".", "empty?", "or", "raise", "(", "ArgumentError", ",", "'Op arguments is already set, use call()'", ")", "tms", "=", "@arguments", "end", "res", "=", "[", "tms", "]", ".", ...
Performs op. If an Op was created with arguments, just performs all operations on them and returns the result. If it was created without arguments, performs all operations on arguments provided to `call`. @param tms one, or several, or an array of time-y values; should not be passed if Op was created with argume...
[ "Performs", "op", ".", "If", "an", "Op", "was", "created", "with", "arguments", "just", "performs", "all", "operations", "on", "them", "and", "returns", "the", "result", ".", "If", "it", "was", "created", "without", "arguments", "performs", "all", "operation...
e9a3eef689f85f8711b49eebe3dad494eb2489dc
https://github.com/zverok/time_math2/blob/e9a3eef689f85f8711b49eebe3dad494eb2489dc/lib/time_math/op.rb#L177-L184
17,132
karmi/retire
lib/tire/alias.rb
Tire.Alias.indices
def indices(*names) names = Array(names).flatten names.compact.empty? ? @attributes[:indices] : (names.each { |n| @attributes[:indices].push(n) } and return self) end
ruby
def indices(*names) names = Array(names).flatten names.compact.empty? ? @attributes[:indices] : (names.each { |n| @attributes[:indices].push(n) } and return self) end
[ "def", "indices", "(", "*", "names", ")", "names", "=", "Array", "(", "names", ")", ".", "flatten", "names", ".", "compact", ".", "empty?", "?", "@attributes", "[", ":indices", "]", ":", "(", "names", ".", "each", "{", "|", "n", "|", "@attributes", ...
Get or set the alias indices
[ "Get", "or", "set", "the", "alias", "indices" ]
1016449cd5bcfd52853f1728452e26962c18790e
https://github.com/karmi/retire/blob/1016449cd5bcfd52853f1728452e26962c18790e/lib/tire/alias.rb#L142-L145
17,133
karmi/retire
lib/tire/alias.rb
Tire.Alias.filter
def filter(type=nil, *options) type ? (@attributes[:filter] = Search::Filter.new(type, *options).to_hash and return self ) : @attributes[:filter] end
ruby
def filter(type=nil, *options) type ? (@attributes[:filter] = Search::Filter.new(type, *options).to_hash and return self ) : @attributes[:filter] end
[ "def", "filter", "(", "type", "=", "nil", ",", "*", "options", ")", "type", "?", "(", "@attributes", "[", ":filter", "]", "=", "Search", "::", "Filter", ".", "new", "(", "type", ",", "options", ")", ".", "to_hash", "and", "return", "self", ")", ":"...
Get or set the alias routing
[ "Get", "or", "set", "the", "alias", "routing" ]
1016449cd5bcfd52853f1728452e26962c18790e
https://github.com/karmi/retire/blob/1016449cd5bcfd52853f1728452e26962c18790e/lib/tire/alias.rb#L155-L157
17,134
karmi/retire
lib/tire/alias.rb
Tire.Alias.as_json
def as_json(options=nil) actions = [] indices.add_indices.each do |index| operation = { :index => index, :alias => name } operation.update( { :routing => routing } ) if respond_to?(:routing) and routing operation.update( { :filter => filter } ) if respond_to?(:filter) and filter ...
ruby
def as_json(options=nil) actions = [] indices.add_indices.each do |index| operation = { :index => index, :alias => name } operation.update( { :routing => routing } ) if respond_to?(:routing) and routing operation.update( { :filter => filter } ) if respond_to?(:filter) and filter ...
[ "def", "as_json", "(", "options", "=", "nil", ")", "actions", "=", "[", "]", "indices", ".", "add_indices", ".", "each", "do", "|", "index", "|", "operation", "=", "{", ":index", "=>", "index", ",", ":alias", "=>", "name", "}", "operation", ".", "upd...
Return a Hash suitable for JSON serialization
[ "Return", "a", "Hash", "suitable", "for", "JSON", "serialization" ]
1016449cd5bcfd52853f1728452e26962c18790e
https://github.com/karmi/retire/blob/1016449cd5bcfd52853f1728452e26962c18790e/lib/tire/alias.rb#L170-L185
17,135
karmi/retire
lib/tire/index.rb
Tire.Index.mapping!
def mapping!(*args) mapping(*args) raise RuntimeError, response.body unless response.success? end
ruby
def mapping!(*args) mapping(*args) raise RuntimeError, response.body unless response.success? end
[ "def", "mapping!", "(", "*", "args", ")", "mapping", "(", "args", ")", "raise", "RuntimeError", ",", "response", ".", "body", "unless", "response", ".", "success?", "end" ]
Raises an exception for unsuccessful responses
[ "Raises", "an", "exception", "for", "unsuccessful", "responses" ]
1016449cd5bcfd52853f1728452e26962c18790e
https://github.com/karmi/retire/blob/1016449cd5bcfd52853f1728452e26962c18790e/lib/tire/index.rb#L75-L78
17,136
optoro/amazon_seller_central
lib/amazon_seller_central/inventory_page.rb
AmazonSellerCentral.InventoryPage.listing_row_to_object
def listing_row_to_object(row) l = Listing.new row.css('td').each_with_index do |td, i| txt = td.text.strip # yes, slightly slower to do this here, but I type less. case i when 4 l.sku = txt when 5 l.asin = txt when 6 ...
ruby
def listing_row_to_object(row) l = Listing.new row.css('td').each_with_index do |td, i| txt = td.text.strip # yes, slightly slower to do this here, but I type less. case i when 4 l.sku = txt when 5 l.asin = txt when 6 ...
[ "def", "listing_row_to_object", "(", "row", ")", "l", "=", "Listing", ".", "new", "row", ".", "css", "(", "'td'", ")", ".", "each_with_index", "do", "|", "td", ",", "i", "|", "txt", "=", "td", ".", "text", ".", "strip", "# yes, slightly slower to do this...
0 - hidden input of sku 1 - checkbox itemOffer 2 - actions 3 - status 4 - sku 5 - asin 6 - product name 7 - date created 8 - qty 9 - your price 10 - condition 11 - low price 12 - buy-box price 13 - fulfilled by
[ "0", "-", "hidden", "input", "of", "sku", "1", "-", "checkbox", "itemOffer", "2", "-", "actions", "3", "-", "status", "4", "-", "sku", "5", "-", "asin", "6", "-", "product", "name", "7", "-", "date", "created", "8", "-", "qty", "9", "-", "your", ...
8e994034b797d73745731991903c574ce36a5b39
https://github.com/optoro/amazon_seller_central/blob/8e994034b797d73745731991903c574ce36a5b39/lib/amazon_seller_central/inventory_page.rb#L82-L110
17,137
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.theme=
def theme=(options) reset_themes defaults = { :colors => %w(black white), :additional_line_colors => [], :marker_color => 'white', :marker_shadow_color => nil, :font_color => 'black', :background_colors => nil, :background_image => nil ...
ruby
def theme=(options) reset_themes defaults = { :colors => %w(black white), :additional_line_colors => [], :marker_color => 'white', :marker_shadow_color => nil, :font_color => 'black', :background_colors => nil, :background_image => nil ...
[ "def", "theme", "=", "(", "options", ")", "reset_themes", "defaults", "=", "{", ":colors", "=>", "%w(", "black", "white", ")", ",", ":additional_line_colors", "=>", "[", "]", ",", ":marker_color", "=>", "'white'", ",", ":marker_shadow_color", "=>", "nil", ",...
You can set a theme manually. Assign a hash to this method before you send your data. graph.theme = { :colors => %w(orange purple green white red), :marker_color => 'blue', :background_colors => ['black', 'grey', :top_bottom] } :background_image => 'squirrel.png' is also possible. (Or hopefully so...
[ "You", "can", "set", "a", "theme", "manually", ".", "Assign", "a", "hash", "to", "this", "method", "before", "you", "send", "your", "data", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L347-L368
17,138
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.data
def data(name, data_points=[], color=nil) data_points = Array(data_points) # make sure it's an array @data << [name, data_points, color] # Set column count if this is larger than previous counts @column_count = (data_points.length > @column_count) ? data_points.l...
ruby
def data(name, data_points=[], color=nil) data_points = Array(data_points) # make sure it's an array @data << [name, data_points, color] # Set column count if this is larger than previous counts @column_count = (data_points.length > @column_count) ? data_points.l...
[ "def", "data", "(", "name", ",", "data_points", "=", "[", "]", ",", "color", "=", "nil", ")", "data_points", "=", "Array", "(", "data_points", ")", "# make sure it's an array", "@data", "<<", "[", "name", ",", "data_points", ",", "color", "]", "# Set colum...
Parameters are an array where the first element is the name of the dataset and the value is an array of values to plot. Can be called multiple times with different datasets for a multi-valued graph. If the color argument is nil, the next color from the default theme will be used. NOTE: If you want to use a pre...
[ "Parameters", "are", "an", "array", "where", "the", "first", "element", "is", "the", "name", "of", "the", "dataset", "and", "the", "value", "is", "an", "array", "of", "values", "to", "plot", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L408-L431
17,139
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw
def draw # Maybe should be done in one of the following functions for more granularity. unless @has_data draw_no_data return end setup_data setup_drawing debug { # Outer margin @d.rectangle(@left_margin, @top_margin, @raw_columns...
ruby
def draw # Maybe should be done in one of the following functions for more granularity. unless @has_data draw_no_data return end setup_data setup_drawing debug { # Outer margin @d.rectangle(@left_margin, @top_margin, @raw_columns...
[ "def", "draw", "# Maybe should be done in one of the following functions for more granularity.", "unless", "@has_data", "draw_no_data", "return", "end", "setup_data", "setup_drawing", "debug", "{", "# Outer margin", "@d", ".", "rectangle", "(", "@left_margin", ",", "@top_margin...
Overridden by subclasses to do the actual plotting of the graph. Subclasses should start by calling super() for this method.
[ "Overridden", "by", "subclasses", "to", "do", "the", "actual", "plotting", "of", "the", "graph", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L456-L478
17,140
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.normalize
def normalize(force=false) if @norm_data.nil? || force @norm_data = [] return unless @has_data @data.each do |data_row| norm_data_points = [] data_row[DATA_VALUES_INDEX].each do |data_point| if data_point.nil? norm_data_points << nil ...
ruby
def normalize(force=false) if @norm_data.nil? || force @norm_data = [] return unless @has_data @data.each do |data_row| norm_data_points = [] data_row[DATA_VALUES_INDEX].each do |data_point| if data_point.nil? norm_data_points << nil ...
[ "def", "normalize", "(", "force", "=", "false", ")", "if", "@norm_data", ".", "nil?", "||", "force", "@norm_data", "=", "[", "]", "return", "unless", "@has_data", "@data", ".", "each", "do", "|", "data_row", "|", "norm_data_points", "=", "[", "]", "data_...
Make copy of data with values scaled between 0-100
[ "Make", "copy", "of", "data", "with", "values", "scaled", "between", "0", "-", "100" ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L504-L525
17,141
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.setup_graph_measurements
def setup_graph_measurements @marker_caps_height = @hide_line_markers ? 0 : calculate_caps_height(@marker_font_size) @title_caps_height = (@hide_title || @title.nil?) ? 0 : calculate_caps_height(@title_font_size) * @title.lines.to_a.size @legend_caps_height = @hide_legend ? 0 : ...
ruby
def setup_graph_measurements @marker_caps_height = @hide_line_markers ? 0 : calculate_caps_height(@marker_font_size) @title_caps_height = (@hide_title || @title.nil?) ? 0 : calculate_caps_height(@title_font_size) * @title.lines.to_a.size @legend_caps_height = @hide_legend ? 0 : ...
[ "def", "setup_graph_measurements", "@marker_caps_height", "=", "@hide_line_markers", "?", "0", ":", "calculate_caps_height", "(", "@marker_font_size", ")", "@title_caps_height", "=", "(", "@hide_title", "||", "@title", ".", "nil?", ")", "?", "0", ":", "calculate_caps_...
Calculates size of drawable area, general font dimensions, etc.
[ "Calculates", "size", "of", "drawable", "area", "general", "font", "dimensions", "etc", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L535-L591
17,142
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_axis_labels
def draw_axis_labels unless @x_axis_label.nil? # X Axis # Centered vertically and horizontally by setting the # height to 1.0 and the width to the width of the graph. x_axis_label_y_coordinate = @graph_bottom + LABEL_MARGIN * 2 + @marker_caps_height # TODO Center between g...
ruby
def draw_axis_labels unless @x_axis_label.nil? # X Axis # Centered vertically and horizontally by setting the # height to 1.0 and the width to the width of the graph. x_axis_label_y_coordinate = @graph_bottom + LABEL_MARGIN * 2 + @marker_caps_height # TODO Center between g...
[ "def", "draw_axis_labels", "unless", "@x_axis_label", ".", "nil?", "# X Axis", "# Centered vertically and horizontally by setting the", "# height to 1.0 and the width to the width of the graph.", "x_axis_label_y_coordinate", "=", "@graph_bottom", "+", "LABEL_MARGIN", "*", "2", "+", ...
Draw the optional labels for the x axis and y axis.
[ "Draw", "the", "optional", "labels", "for", "the", "x", "axis", "and", "y", "axis", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L594-L624
17,143
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_line_markers
def draw_line_markers return if @hide_line_markers @d = @d.stroke_antialias false if @y_axis_increment.nil? # Try to use a number of horizontal lines that will come out even. # # TODO Do the same for larger numbers...100, 75, 50, 25 if @marker_count.nil? (3....
ruby
def draw_line_markers return if @hide_line_markers @d = @d.stroke_antialias false if @y_axis_increment.nil? # Try to use a number of horizontal lines that will come out even. # # TODO Do the same for larger numbers...100, 75, 50, 25 if @marker_count.nil? (3....
[ "def", "draw_line_markers", "return", "if", "@hide_line_markers", "@d", "=", "@d", ".", "stroke_antialias", "false", "if", "@y_axis_increment", ".", "nil?", "# Try to use a number of horizontal lines that will come out even.", "#", "# TODO Do the same for larger numbers...100, 75, ...
Draws horizontal background lines and labels
[ "Draws", "horizontal", "background", "lines", "and", "labels" ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L627-L715
17,144
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_legend
def draw_legend return if @hide_legend @legend_labels = @data.collect { |item| item[DATA_LABEL_INDEX] } legend_square_width = @legend_box_size # small square with color of this item # May fix legend drawing problem at small sizes @d.font = @font if @font @d.pointsize = @legend_fon...
ruby
def draw_legend return if @hide_legend @legend_labels = @data.collect { |item| item[DATA_LABEL_INDEX] } legend_square_width = @legend_box_size # small square with color of this item # May fix legend drawing problem at small sizes @d.font = @font if @font @d.pointsize = @legend_fon...
[ "def", "draw_legend", "return", "if", "@hide_legend", "@legend_labels", "=", "@data", ".", "collect", "{", "|", "item", "|", "item", "[", "DATA_LABEL_INDEX", "]", "}", "legend_square_width", "=", "@legend_box_size", "# small square with color of this item", "# May fix l...
Draws a legend with the names of the datasets matched to the colors used to draw them.
[ "Draws", "a", "legend", "with", "the", "names", "of", "the", "datasets", "matched", "to", "the", "colors", "used", "to", "draw", "them", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L737-L809
17,145
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_title
def draw_title return if (@hide_title || @title.nil?) @d.fill = @font_color @d.font = @title_font || @font if @title_font || @font @d.stroke('transparent') @d.pointsize = scale_fontsize(@title_font_size) @d.font_weight = if @bold_title then BoldWeight else NormalWeight end @d....
ruby
def draw_title return if (@hide_title || @title.nil?) @d.fill = @font_color @d.font = @title_font || @font if @title_font || @font @d.stroke('transparent') @d.pointsize = scale_fontsize(@title_font_size) @d.font_weight = if @bold_title then BoldWeight else NormalWeight end @d....
[ "def", "draw_title", "return", "if", "(", "@hide_title", "||", "@title", ".", "nil?", ")", "@d", ".", "fill", "=", "@font_color", "@d", ".", "font", "=", "@title_font", "||", "@font", "if", "@title_font", "||", "@font", "@d", ".", "stroke", "(", "'transp...
Draws a title on the graph.
[ "Draws", "a", "title", "on", "the", "graph", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L812-L825
17,146
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_value_label
def draw_value_label(x_offset, y_offset, data_point, bar_value=false) return if @hide_line_markers && !bar_value #y_offset = @graph_bottom + LABEL_MARGIN @d.fill = @font_color @d.font = @font if @font @d.stroke('transparent') @d.font_weight = NormalWeight @d.pointsize = scale...
ruby
def draw_value_label(x_offset, y_offset, data_point, bar_value=false) return if @hide_line_markers && !bar_value #y_offset = @graph_bottom + LABEL_MARGIN @d.fill = @font_color @d.font = @font if @font @d.stroke('transparent') @d.font_weight = NormalWeight @d.pointsize = scale...
[ "def", "draw_value_label", "(", "x_offset", ",", "y_offset", ",", "data_point", ",", "bar_value", "=", "false", ")", "return", "if", "@hide_line_markers", "&&", "!", "bar_value", "#y_offset = @graph_bottom + LABEL_MARGIN", "@d", ".", "fill", "=", "@font_color", "@d"...
Draws the data value over the data point in bar graphs
[ "Draws", "the", "data", "value", "over", "the", "data", "point", "in", "bar", "graphs" ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L875-L892
17,147
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.draw_no_data
def draw_no_data @d.fill = @font_color @d.font = @font if @font @d.stroke('transparent') @d.font_weight = NormalWeight @d.pointsize = scale_fontsize(80) @d.gravity = CenterGravity @d = @d.annotate_scaled(@base_image, @raw_columns, @raw_rows/2.0, ...
ruby
def draw_no_data @d.fill = @font_color @d.font = @font if @font @d.stroke('transparent') @d.font_weight = NormalWeight @d.pointsize = scale_fontsize(80) @d.gravity = CenterGravity @d = @d.annotate_scaled(@base_image, @raw_columns, @raw_rows/2.0, ...
[ "def", "draw_no_data", "@d", ".", "fill", "=", "@font_color", "@d", ".", "font", "=", "@font", "if", "@font", "@d", ".", "stroke", "(", "'transparent'", ")", "@d", ".", "font_weight", "=", "NormalWeight", "@d", ".", "pointsize", "=", "scale_fontsize", "(",...
Shows an error message because you have no data.
[ "Shows", "an", "error", "message", "because", "you", "have", "no", "data", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L895-L906
17,148
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.render_gradiated_background
def render_gradiated_background(top_color, bottom_color, direct = :top_bottom) case direct when :bottom_top gradient_fill = GradientFill.new(0, 0, 100, 0, bottom_color, top_color) when :left_right gradient_fill = GradientFill.new(0, 0, 0, 100, top_color, bottom_color) when :right...
ruby
def render_gradiated_background(top_color, bottom_color, direct = :top_bottom) case direct when :bottom_top gradient_fill = GradientFill.new(0, 0, 100, 0, bottom_color, top_color) when :left_right gradient_fill = GradientFill.new(0, 0, 0, 100, top_color, bottom_color) when :right...
[ "def", "render_gradiated_background", "(", "top_color", ",", "bottom_color", ",", "direct", "=", ":top_bottom", ")", "case", "direct", "when", ":bottom_top", "gradient_fill", "=", "GradientFill", ".", "new", "(", "0", ",", "0", ",", "100", ",", "0", ",", "bo...
Use with a theme definition method to draw a gradiated background.
[ "Use", "with", "a", "theme", "definition", "method", "to", "draw", "a", "gradiated", "background", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L930-L946
17,149
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.sort_data
def sort_data @data = @data.sort_by { |a| -a[DATA_VALUES_INDEX].inject(0) { |sum, num| sum + num.to_f } } end
ruby
def sort_data @data = @data.sort_by { |a| -a[DATA_VALUES_INDEX].inject(0) { |sum, num| sum + num.to_f } } end
[ "def", "sort_data", "@data", "=", "@data", ".", "sort_by", "{", "|", "a", "|", "-", "a", "[", "DATA_VALUES_INDEX", "]", ".", "inject", "(", "0", ")", "{", "|", "sum", ",", "num", "|", "sum", "+", "num", ".", "to_f", "}", "}", "end" ]
Sort with largest overall summed value at front of array.
[ "Sort", "with", "largest", "overall", "summed", "value", "at", "front", "of", "array", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1020-L1022
17,150
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.sort_norm_data
def sort_norm_data @norm_data = @norm_data.sort_by { |a| -a[DATA_VALUES_INDEX].inject(0) { |sum, num| sum + num.to_f } } end
ruby
def sort_norm_data @norm_data = @norm_data.sort_by { |a| -a[DATA_VALUES_INDEX].inject(0) { |sum, num| sum + num.to_f } } end
[ "def", "sort_norm_data", "@norm_data", "=", "@norm_data", ".", "sort_by", "{", "|", "a", "|", "-", "a", "[", "DATA_VALUES_INDEX", "]", ".", "inject", "(", "0", ")", "{", "|", "sum", ",", "num", "|", "sum", "+", "num", ".", "to_f", "}", "}", "end" ]
Sort with largest overall summed value at front of array so it shows up correctly in the drawn graph.
[ "Sort", "with", "largest", "overall", "summed", "value", "at", "front", "of", "array", "so", "it", "shows", "up", "correctly", "in", "the", "drawn", "graph", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1031-L1034
17,151
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.get_maximum_by_stack
def get_maximum_by_stack # Get sum of each stack max_hash = {} @data.each do |data_set| data_set[DATA_VALUES_INDEX].each_with_index do |data_point, i| max_hash[i] = 0.0 unless max_hash[i] max_hash[i] += data_point.to_f end end # @maximum_value = 0 ...
ruby
def get_maximum_by_stack # Get sum of each stack max_hash = {} @data.each do |data_set| data_set[DATA_VALUES_INDEX].each_with_index do |data_point, i| max_hash[i] = 0.0 unless max_hash[i] max_hash[i] += data_point.to_f end end # @maximum_value = 0 ...
[ "def", "get_maximum_by_stack", "# Get sum of each stack", "max_hash", "=", "{", "}", "@data", ".", "each", "do", "|", "data_set", "|", "data_set", "[", "DATA_VALUES_INDEX", "]", ".", "each_with_index", "do", "|", "data_point", ",", "i", "|", "max_hash", "[", "...
Used by StackedBar and child classes. May need to be moved to the StackedBar class.
[ "Used", "by", "StackedBar", "and", "child", "classes", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1039-L1054
17,152
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.label
def label(value, increment) label = if increment if increment >= 10 || (increment * 1) == (increment * 1).to_i.to_f sprintf('%0i', value) elsif increment >= 1.0 || (increment * 10) == (increment * 10).to_i.to_f sprintf('%0.1f', value) ...
ruby
def label(value, increment) label = if increment if increment >= 10 || (increment * 1) == (increment * 1).to_i.to_f sprintf('%0i', value) elsif increment >= 1.0 || (increment * 10) == (increment * 10).to_i.to_f sprintf('%0.1f', value) ...
[ "def", "label", "(", "value", ",", "increment", ")", "label", "=", "if", "increment", "if", "increment", ">=", "10", "||", "(", "increment", "*", "1", ")", "==", "(", "increment", "*", "1", ")", ".", "to_i", ".", "to_f", "sprintf", "(", "'%0i'", ",...
Return a formatted string representing a number value that should be printed as a label.
[ "Return", "a", "formatted", "string", "representing", "a", "number", "value", "that", "should", "be", "printed", "as", "a", "label", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1088-L1116
17,153
topfunky/gruff
lib/gruff/base.rb
Gruff.Base.calculate_width
def calculate_width(font_size, text) return 0 if text.nil? @d.pointsize = font_size @d.font = @font if @font @d.get_type_metrics(@base_image, text.to_s).width end
ruby
def calculate_width(font_size, text) return 0 if text.nil? @d.pointsize = font_size @d.font = @font if @font @d.get_type_metrics(@base_image, text.to_s).width end
[ "def", "calculate_width", "(", "font_size", ",", "text", ")", "return", "0", "if", "text", ".", "nil?", "@d", ".", "pointsize", "=", "font_size", "@d", ".", "font", "=", "@font", "if", "@font", "@d", ".", "get_type_metrics", "(", "@base_image", ",", "tex...
Returns the width of a string at this pointsize. Not scaled since it deals with dimensions that the regular scaling will handle.
[ "Returns", "the", "width", "of", "a", "string", "at", "this", "pointsize", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1133-L1138
17,154
topfunky/gruff
lib/gruff/base.rb
Magick.Draw.annotate_scaled
def annotate_scaled(img, width, height, x, y, text, scale) scaled_width = (width * scale) >= 1 ? (width * scale) : 1 scaled_height = (height * scale) >= 1 ? (height * scale) : 1 self.annotate(img, scaled_width, scaled_height, x * scale, y * scale, ...
ruby
def annotate_scaled(img, width, height, x, y, text, scale) scaled_width = (width * scale) >= 1 ? (width * scale) : 1 scaled_height = (height * scale) >= 1 ? (height * scale) : 1 self.annotate(img, scaled_width, scaled_height, x * scale, y * scale, ...
[ "def", "annotate_scaled", "(", "img", ",", "width", ",", "height", ",", "x", ",", "y", ",", "text", ",", "scale", ")", "scaled_width", "=", "(", "width", "*", "scale", ")", ">=", "1", "?", "(", "width", "*", "scale", ")", ":", "1", "scaled_height",...
Additional method to scale annotation text since Draw.scale doesn't.
[ "Additional", "method", "to", "scale", "annotation", "text", "since", "Draw", ".", "scale", "doesn", "t", "." ]
0625ec81f37908d519e6a725a3140a42fb9aa2ee
https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/lib/gruff/base.rb#L1157-L1165
17,155
coinbase/traffic_jam
lib/traffic_jam/configuration.rb
TrafficJam.Configuration.limits
def limits(action) @limits ||= {} limits = @limits[action.to_sym] raise TrafficJam::LimitNotFound.new(action) if limits.nil? limits end
ruby
def limits(action) @limits ||= {} limits = @limits[action.to_sym] raise TrafficJam::LimitNotFound.new(action) if limits.nil? limits end
[ "def", "limits", "(", "action", ")", "@limits", "||=", "{", "}", "limits", "=", "@limits", "[", "action", ".", "to_sym", "]", "raise", "TrafficJam", "::", "LimitNotFound", ".", "new", "(", "action", ")", "if", "limits", ".", "nil?", "limits", "end" ]
Get registered limit parameters for an action. @see #register @param action [Symbol] action name @return [Hash] max and period parameters in a hash @raise [TrafficJam::LimitNotFound] if action is not registered
[ "Get", "registered", "limit", "parameters", "for", "an", "action", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/configuration.rb#L56-L61
17,156
coinbase/traffic_jam
lib/traffic_jam/limit_group.rb
TrafficJam.LimitGroup.increment
def increment(amount = 1, time: Time.now) exceeded_index = limits.find_index do |limit| !limit.increment(amount, time: time) end if exceeded_index limits[0...exceeded_index].each do |limit| limit.decrement(amount, time: time) end end exceeded_index.nil? ...
ruby
def increment(amount = 1, time: Time.now) exceeded_index = limits.find_index do |limit| !limit.increment(amount, time: time) end if exceeded_index limits[0...exceeded_index].each do |limit| limit.decrement(amount, time: time) end end exceeded_index.nil? ...
[ "def", "increment", "(", "amount", "=", "1", ",", "time", ":", "Time", ".", "now", ")", "exceeded_index", "=", "limits", ".", "find_index", "do", "|", "limit", "|", "!", "limit", ".", "increment", "(", "amount", ",", "time", ":", "time", ")", "end", ...
Attempt to increment the limits by the given amount. Does not increment if incrementing would exceed any limit. @param amount [Integer] amount to increment by @param time [Time] optional time of increment @return [Boolean] whether increment operation was successful
[ "Attempt", "to", "increment", "the", "limits", "by", "the", "given", "amount", ".", "Does", "not", "increment", "if", "incrementing", "would", "exceed", "any", "limit", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/limit_group.rb#L39-L49
17,157
coinbase/traffic_jam
lib/traffic_jam/limit_group.rb
TrafficJam.LimitGroup.increment!
def increment!(amount = 1, time: Time.now) exception = nil exceeded_index = limits.find_index do |limit| begin limit.increment!(amount, time: time) rescue TrafficJam::LimitExceededError => e exception = e true end end if exceeded_index ...
ruby
def increment!(amount = 1, time: Time.now) exception = nil exceeded_index = limits.find_index do |limit| begin limit.increment!(amount, time: time) rescue TrafficJam::LimitExceededError => e exception = e true end end if exceeded_index ...
[ "def", "increment!", "(", "amount", "=", "1", ",", "time", ":", "Time", ".", "now", ")", "exception", "=", "nil", "exceeded_index", "=", "limits", ".", "find_index", "do", "|", "limit", "|", "begin", "limit", ".", "increment!", "(", "amount", ",", "tim...
Increment the limits by the given amount. Raises an error and does not increment if doing so would exceed any limit. @param amount [Integer] amount to increment by @param time [Time] optional time of increment @return [nil] @raise [TrafficJam::LimitExceededError] if increment would exceed any limits
[ "Increment", "the", "limits", "by", "the", "given", "amount", ".", "Raises", "an", "error", "and", "does", "not", "increment", "if", "doing", "so", "would", "exceed", "any", "limit", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/limit_group.rb#L59-L75
17,158
coinbase/traffic_jam
lib/traffic_jam/limit_group.rb
TrafficJam.LimitGroup.decrement
def decrement(amount = 1, time: Time.now) limits.all? { |limit| limit.decrement(amount, time: time) } end
ruby
def decrement(amount = 1, time: Time.now) limits.all? { |limit| limit.decrement(amount, time: time) } end
[ "def", "decrement", "(", "amount", "=", "1", ",", "time", ":", "Time", ".", "now", ")", "limits", ".", "all?", "{", "|", "limit", "|", "limit", ".", "decrement", "(", "amount", ",", "time", ":", "time", ")", "}", "end" ]
Decrement the limits by the given amount. @param amount [Integer] amount to decrement by @param time [Time] optional time of decrement @return [true]
[ "Decrement", "the", "limits", "by", "the", "given", "amount", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/limit_group.rb#L82-L84
17,159
coinbase/traffic_jam
lib/traffic_jam/limit_group.rb
TrafficJam.LimitGroup.limit_exceeded
def limit_exceeded(amount = 1) limits.each do |limit| limit_exceeded = limit.limit_exceeded(amount) return limit_exceeded if limit_exceeded end nil end
ruby
def limit_exceeded(amount = 1) limits.each do |limit| limit_exceeded = limit.limit_exceeded(amount) return limit_exceeded if limit_exceeded end nil end
[ "def", "limit_exceeded", "(", "amount", "=", "1", ")", "limits", ".", "each", "do", "|", "limit", "|", "limit_exceeded", "=", "limit", ".", "limit_exceeded", "(", "amount", ")", "return", "limit_exceeded", "if", "limit_exceeded", "end", "nil", "end" ]
Return the first limit to be exceeded if incrementing by the given amount, or nil otherwise. Does not change amount used for any limit. @param amount [Integer] @return [TrafficJam::Limit, nil]
[ "Return", "the", "first", "limit", "to", "be", "exceeded", "if", "incrementing", "by", "the", "given", "amount", "or", "nil", "otherwise", ".", "Does", "not", "change", "amount", "used", "for", "any", "limit", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/limit_group.rb#L100-L106
17,160
coinbase/traffic_jam
lib/traffic_jam/gcra_limit.rb
TrafficJam.GCRALimit.increment
def increment(amount = 1, time: Time.now) return true if amount == 0 return false if max == 0 raise ArgumentError.new("Amount must be positive") if amount < 0 if amount != amount.to_i raise ArgumentError.new("Amount must be an integer") end return false if amount > max ...
ruby
def increment(amount = 1, time: Time.now) return true if amount == 0 return false if max == 0 raise ArgumentError.new("Amount must be positive") if amount < 0 if amount != amount.to_i raise ArgumentError.new("Amount must be an integer") end return false if amount > max ...
[ "def", "increment", "(", "amount", "=", "1", ",", "time", ":", "Time", ".", "now", ")", "return", "true", "if", "amount", "==", "0", "return", "false", "if", "max", "==", "0", "raise", "ArgumentError", ".", "new", "(", "\"Amount must be positive\"", ")",...
Increment the amount used by the given number. Does not perform increment if the operation would exceed the limit. Returns whether the operation was successful. @param amount [Integer] amount to increment by @param time [Time] time is ignored @return [Boolean] true if increment succeded and false if incrementing ...
[ "Increment", "the", "amount", "used", "by", "the", "given", "number", ".", "Does", "not", "perform", "increment", "if", "the", "operation", "would", "exceed", "the", "limit", ".", "Returns", "whether", "the", "operation", "was", "successful", "." ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/gcra_limit.rb#L35-L69
17,161
coinbase/traffic_jam
lib/traffic_jam/limit.rb
TrafficJam.Limit.increment
def increment(amount = 1, time: Time.now) return amount <= 0 if max.zero? if amount != amount.to_i raise ArgumentError.new("Amount must be an integer") end timestamp = (time.to_f * 1000).to_i argv = [timestamp, amount.to_i, max, period * 1000] result = begin ...
ruby
def increment(amount = 1, time: Time.now) return amount <= 0 if max.zero? if amount != amount.to_i raise ArgumentError.new("Amount must be an integer") end timestamp = (time.to_f * 1000).to_i argv = [timestamp, amount.to_i, max, period * 1000] result = begin ...
[ "def", "increment", "(", "amount", "=", "1", ",", "time", ":", "Time", ".", "now", ")", "return", "amount", "<=", "0", "if", "max", ".", "zero?", "if", "amount", "!=", "amount", ".", "to_i", "raise", "ArgumentError", ".", "new", "(", "\"Amount must be ...
Increment the amount used by the given number. Does not perform increment if the operation would exceed the limit. Returns whether the operation was successful. Time of increment can be specified optionally with a keyword argument, which is useful for rolling back with a decrement. @param amount [Integer] amount t...
[ "Increment", "the", "amount", "used", "by", "the", "given", "number", ".", "Does", "not", "perform", "increment", "if", "the", "operation", "would", "exceed", "the", "limit", ".", "Returns", "whether", "the", "operation", "was", "successful", ".", "Time", "o...
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/limit.rb#L67-L86
17,162
coinbase/traffic_jam
lib/traffic_jam/lifetime_limit.rb
TrafficJam.LifetimeLimit.used
def used return 0 if max.zero? amount = redis.get(key) || 0 [amount.to_i, max].min end
ruby
def used return 0 if max.zero? amount = redis.get(key) || 0 [amount.to_i, max].min end
[ "def", "used", "return", "0", "if", "max", ".", "zero?", "amount", "=", "redis", ".", "get", "(", "key", ")", "||", "0", "[", "amount", ".", "to_i", ",", "max", "]", ".", "min", "end" ]
Return amount of limit used @return [Integer] amount used
[ "Return", "amount", "of", "limit", "used" ]
2b90aa596fdb384086a5a39a203effed14a01756
https://github.com/coinbase/traffic_jam/blob/2b90aa596fdb384086a5a39a203effed14a01756/lib/traffic_jam/lifetime_limit.rb#L36-L40
17,163
voltrb/volt
lib/volt/tasks/dispatcher.rb
Volt.Dispatcher.dispatch
def dispatch(channel, message) # Dispatch the task in the worker pool. Pas in the meta data @worker_pool.post do begin dispatch_in_thread(channel, message) rescue => e err = "Worker Thread Exception for #{message}\n" err += e.inspect err += e.backtrac...
ruby
def dispatch(channel, message) # Dispatch the task in the worker pool. Pas in the meta data @worker_pool.post do begin dispatch_in_thread(channel, message) rescue => e err = "Worker Thread Exception for #{message}\n" err += e.inspect err += e.backtrac...
[ "def", "dispatch", "(", "channel", ",", "message", ")", "# Dispatch the task in the worker pool. Pas in the meta data", "@worker_pool", ".", "post", "do", "begin", "dispatch_in_thread", "(", "channel", ",", "message", ")", "rescue", "=>", "e", "err", "=", "\"Worker T...
Dispatch takes an incoming Task from the client and runs it on the server, returning the result to the client. Tasks returning a promise will wait to return.
[ "Dispatch", "takes", "an", "incoming", "Task", "from", "the", "client", "and", "runs", "it", "on", "the", "server", "returning", "the", "result", "to", "the", "client", ".", "Tasks", "returning", "a", "promise", "will", "wait", "to", "return", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/tasks/dispatcher.rb#L53-L66
17,164
voltrb/volt
lib/volt/tasks/dispatcher.rb
Volt.Dispatcher.safe_method?
def safe_method?(klass, method_name) # Make sure the class being called is a Task. return false unless klass.ancestors.include?(Task) # Make sure the method is defined on the klass we're using and not up the hiearchy. # ^ This check prevents methods like #send, #eval, #instance_eval, #class_e...
ruby
def safe_method?(klass, method_name) # Make sure the class being called is a Task. return false unless klass.ancestors.include?(Task) # Make sure the method is defined on the klass we're using and not up the hiearchy. # ^ This check prevents methods like #send, #eval, #instance_eval, #class_e...
[ "def", "safe_method?", "(", "klass", ",", "method_name", ")", "# Make sure the class being called is a Task.", "return", "false", "unless", "klass", ".", "ancestors", ".", "include?", "(", "Task", ")", "# Make sure the method is defined on the klass we're using and not up the h...
Check if it is safe to use this method
[ "Check", "if", "it", "is", "safe", "to", "use", "this", "method" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/tasks/dispatcher.rb#L70-L87
17,165
voltrb/volt
lib/volt/tasks/dispatcher.rb
Volt.Dispatcher.dispatch_in_thread
def dispatch_in_thread(channel, message) callback_id, class_name, method_name, meta_data, *args = message method_name = method_name.to_sym # Get the class klass = Object.send(:const_get, class_name) promise = Promise.new cookies = nil start_time = Time.now.to_f # Chec...
ruby
def dispatch_in_thread(channel, message) callback_id, class_name, method_name, meta_data, *args = message method_name = method_name.to_sym # Get the class klass = Object.send(:const_get, class_name) promise = Promise.new cookies = nil start_time = Time.now.to_f # Chec...
[ "def", "dispatch_in_thread", "(", "channel", ",", "message", ")", "callback_id", ",", "class_name", ",", "method_name", ",", "meta_data", ",", "*", "args", "=", "message", "method_name", "=", "method_name", ".", "to_sym", "# Get the class", "klass", "=", "Object...
Do the actual dispatching, should be running inside of a worker thread at this point.
[ "Do", "the", "actual", "dispatching", "should", "be", "running", "inside", "of", "a", "worker", "thread", "at", "this", "point", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/tasks/dispatcher.rb#L97-L178
17,166
voltrb/volt
lib/volt/models/validations/validations.rb
Volt.Validations.validate
def validate(field_name = nil, options = nil, &block) if block # Setup a custom validation inside of the current validations block. if field_name || options fail 'validate should be passed a field name and options or a block, not both.' end @instance_custom_validations <<...
ruby
def validate(field_name = nil, options = nil, &block) if block # Setup a custom validation inside of the current validations block. if field_name || options fail 'validate should be passed a field name and options or a block, not both.' end @instance_custom_validations <<...
[ "def", "validate", "(", "field_name", "=", "nil", ",", "options", "=", "nil", ",", "&", "block", ")", "if", "block", "# Setup a custom validation inside of the current validations block.", "if", "field_name", "||", "options", "fail", "'validate should be passed a field na...
Called on the model inside of a validations block. Allows the user to control if validations should be run.
[ "Called", "on", "the", "model", "inside", "of", "a", "validations", "block", ".", "Allows", "the", "user", "to", "control", "if", "validations", "should", "be", "run", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validations/validations.rb#L64-L75
17,167
voltrb/volt
lib/volt/models/validations/validations.rb
Volt.Validations.mark_all_fields!
def mark_all_fields! # TODO: We can use a Set here, but set was having issues. Check in a # later version of opal. fields_to_mark = [] # Look at each validation validations = self.class.validations_to_run if validations fields_to_mark += validations.keys end # ...
ruby
def mark_all_fields! # TODO: We can use a Set here, but set was having issues. Check in a # later version of opal. fields_to_mark = [] # Look at each validation validations = self.class.validations_to_run if validations fields_to_mark += validations.keys end # ...
[ "def", "mark_all_fields!", "# TODO: We can use a Set here, but set was having issues. Check in a", "# later version of opal.", "fields_to_mark", "=", "[", "]", "# Look at each validation", "validations", "=", "self", ".", "class", ".", "validations_to_run", "if", "validations", ...
Marks all fields, useful for when a model saves.
[ "Marks", "all", "fields", "useful", "for", "when", "a", "model", "saves", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validations/validations.rb#L93-L110
17,168
voltrb/volt
lib/volt/models/validations/validations.rb
Volt.Validations.error_in_changed_attributes?
def error_in_changed_attributes? errs = errors changed_attributes.each_pair do |key, _| # If any of the fields with errors are also the ones that were return true if errs[key] end false end
ruby
def error_in_changed_attributes? errs = errors changed_attributes.each_pair do |key, _| # If any of the fields with errors are also the ones that were return true if errs[key] end false end
[ "def", "error_in_changed_attributes?", "errs", "=", "errors", "changed_attributes", ".", "each_pair", "do", "|", "key", ",", "_", "|", "# If any of the fields with errors are also the ones that were", "return", "true", "if", "errs", "[", "key", "]", "end", "false", "e...
Returns true if any of the changed fields now has an error @return [Boolean] true if one of the changed fields has an error.
[ "Returns", "true", "if", "any", "of", "the", "changed", "fields", "now", "has", "an", "error" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validations/validations.rb#L161-L170
17,169
voltrb/volt
lib/volt/models/validations/validations.rb
Volt.Validations.run_validations
def run_validations(validations = nil) # Default to running the class level validations validations ||= self.class.validations_to_run promise = Promise.new.resolve(nil) if validations # Run through each validation validations.each_pair do |field_name, options| promise...
ruby
def run_validations(validations = nil) # Default to running the class level validations validations ||= self.class.validations_to_run promise = Promise.new.resolve(nil) if validations # Run through each validation validations.each_pair do |field_name, options| promise...
[ "def", "run_validations", "(", "validations", "=", "nil", ")", "# Default to running the class level validations", "validations", "||=", "self", ".", "class", ".", "validations_to_run", "promise", "=", "Promise", ".", "new", ".", "resolve", "(", "nil", ")", "if", ...
Runs through each of the normal validations. @param [Array] An array of validations to run @return [Promise] a promsie to run all validations
[ "Runs", "through", "each", "of", "the", "normal", "validations", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validations/validations.rb#L177-L191
17,170
voltrb/volt
lib/volt/models/validations/validations.rb
Volt.Validations.run_validation
def run_validation(field_name, options) promise = Promise.new.resolve(nil) options.each_pair do |validation, args| # Call the specific validator, then merge the results back # into one large errors hash. klass = validation_class(validation, args) if klass # Chain o...
ruby
def run_validation(field_name, options) promise = Promise.new.resolve(nil) options.each_pair do |validation, args| # Call the specific validator, then merge the results back # into one large errors hash. klass = validation_class(validation, args) if klass # Chain o...
[ "def", "run_validation", "(", "field_name", ",", "options", ")", "promise", "=", "Promise", ".", "new", ".", "resolve", "(", "nil", ")", "options", ".", "each_pair", "do", "|", "validation", ",", "args", "|", "# Call the specific validator, then merge the results ...
Runs an individual validation @returns [Promise]
[ "Runs", "an", "individual", "validation" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validations/validations.rb#L195-L215
17,171
voltrb/volt
lib/volt/reactive/reactive_array.rb
Volt.ReactiveArray.__clear
def __clear old_size = @array.size deps = @array_deps @array_deps = [] # Trigger remove for each cell old_size.times do |index| trigger_removed!(old_size - index - 1) end # Trigger on each cell since we are clearing out the array if deps deps.eac...
ruby
def __clear old_size = @array.size deps = @array_deps @array_deps = [] # Trigger remove for each cell old_size.times do |index| trigger_removed!(old_size - index - 1) end # Trigger on each cell since we are clearing out the array if deps deps.eac...
[ "def", "__clear", "old_size", "=", "@array", ".", "size", "deps", "=", "@array_deps", "@array_deps", "=", "[", "]", "# Trigger remove for each cell", "old_size", ".", "times", "do", "|", "index", "|", "trigger_removed!", "(", "old_size", "-", "index", "-", "1"...
used internally, clears out the array, triggers the change events, but does not call clear on the persistors. Used when models are updated externally.
[ "used", "internally", "clears", "out", "the", "array", "triggers", "the", "change", "events", "but", "does", "not", "call", "clear", "on", "the", "persistors", ".", "Used", "when", "models", "are", "updated", "externally", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/reactive/reactive_array.rb#L248-L268
17,172
voltrb/volt
lib/volt/models/buffer.rb
Volt.Buffer.promise_for_errors
def promise_for_errors(errors) mark_all_fields! # Wrap in an Errors class unless it already is one errors = errors.is_a?(Errors) ? errors : Errors.new(errors) Promise.new.reject(errors) end
ruby
def promise_for_errors(errors) mark_all_fields! # Wrap in an Errors class unless it already is one errors = errors.is_a?(Errors) ? errors : Errors.new(errors) Promise.new.reject(errors) end
[ "def", "promise_for_errors", "(", "errors", ")", "mark_all_fields!", "# Wrap in an Errors class unless it already is one", "errors", "=", "errors", ".", "is_a?", "(", "Errors", ")", "?", "errors", ":", "Errors", ".", "new", "(", "errors", ")", "Promise", ".", "new...
When errors come in, we mark all fields and return a rejected promise.
[ "When", "errors", "come", "in", "we", "mark", "all", "fields", "and", "return", "a", "rejected", "promise", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/buffer.rb#L75-L82
17,173
voltrb/volt
lib/volt/models/buffer.rb
Volt.Buffer.buffer
def buffer model_path = options[:path] model_klass = self.class new_options = options.merge(path: model_path, save_to: self, buffer: true).reject { |k, _| k.to_sym == :persistor } model = nil Volt::Model.no_validate do model = model_klass.new(attributes, new_options, :loaded) ...
ruby
def buffer model_path = options[:path] model_klass = self.class new_options = options.merge(path: model_path, save_to: self, buffer: true).reject { |k, _| k.to_sym == :persistor } model = nil Volt::Model.no_validate do model = model_klass.new(attributes, new_options, :loaded) ...
[ "def", "buffer", "model_path", "=", "options", "[", ":path", "]", "model_klass", "=", "self", ".", "class", "new_options", "=", "options", ".", "merge", "(", "path", ":", "model_path", ",", "save_to", ":", "self", ",", "buffer", ":", "true", ")", ".", ...
Returns a buffered version of the model
[ "Returns", "a", "buffered", "version", "of", "the", "model" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/buffer.rb#L89-L104
17,174
voltrb/volt
lib/volt/models/model_hash_behaviour.rb
Volt.ModelHashBehaviour.to_h
def to_h @size_dep.depend if @attributes.nil? nil else hash = {} @attributes.each_pair do |key, value| hash[key] = deep_unwrap(value) end hash end end
ruby
def to_h @size_dep.depend if @attributes.nil? nil else hash = {} @attributes.each_pair do |key, value| hash[key] = deep_unwrap(value) end hash end end
[ "def", "to_h", "@size_dep", ".", "depend", "if", "@attributes", ".", "nil?", "nil", "else", "hash", "=", "{", "}", "@attributes", ".", "each_pair", "do", "|", "key", ",", "value", "|", "hash", "[", "key", "]", "=", "deep_unwrap", "(", "value", ")", "...
Convert the model to a hash all of the way down.
[ "Convert", "the", "model", "to", "a", "hash", "all", "of", "the", "way", "down", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/model_hash_behaviour.rb#L80-L92
17,175
voltrb/volt
lib/volt/models/array_model.rb
Volt.ArrayModel.to_a
def to_a @size_dep.depend array = [] Volt.run_in_mode(:no_model_promises) do attributes.size.times do |index| array << deep_unwrap(self[index]) end end array end
ruby
def to_a @size_dep.depend array = [] Volt.run_in_mode(:no_model_promises) do attributes.size.times do |index| array << deep_unwrap(self[index]) end end array end
[ "def", "to_a", "@size_dep", ".", "depend", "array", "=", "[", "]", "Volt", ".", "run_in_mode", "(", ":no_model_promises", ")", "do", "attributes", ".", "size", ".", "times", "do", "|", "index", "|", "array", "<<", "deep_unwrap", "(", "self", "[", "index"...
Convert the model to an array all of the way down
[ "Convert", "the", "model", "to", "an", "array", "all", "of", "the", "way", "down" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/array_model.rb#L251-L260
17,176
voltrb/volt
lib/volt/models/array_model.rb
Volt.ArrayModel.create_new_model
def create_new_model(model, from_method) if model.is_a?(Model) if model.buffer? fail "The #{from_method} does not take a buffer. Call .save! on buffer's to persist them." end # Set the new path and the persistor. model.options = @options.merge(parent: self, path: @optio...
ruby
def create_new_model(model, from_method) if model.is_a?(Model) if model.buffer? fail "The #{from_method} does not take a buffer. Call .save! on buffer's to persist them." end # Set the new path and the persistor. model.options = @options.merge(parent: self, path: @optio...
[ "def", "create_new_model", "(", "model", ",", "from_method", ")", "if", "model", ".", "is_a?", "(", "Model", ")", "if", "model", ".", "buffer?", "fail", "\"The #{from_method} does not take a buffer. Call .save! on buffer's to persist them.\"", "end", "# Set the new path an...
called form <<, append, and create. If a hash is passed in, it converts it to a model. Then it takes the model and inserts it into the ArrayModel then persists it.
[ "called", "form", "<<", "append", "and", "create", ".", "If", "a", "hash", "is", "passed", "in", "it", "converts", "it", "to", "a", "model", ".", "Then", "it", "takes", "the", "model", "and", "inserts", "it", "into", "the", "ArrayModel", "then", "persi...
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/array_model.rb#L319-L387
17,177
voltrb/volt
lib/volt/models/url.rb
Volt.URL.url_for
def url_for(params) host_with_port = host || location.host host_with_port += ":#{port}" if port && port != 80 scheme = scheme || location.scheme unless RUBY_PLATFORM == 'opal' # lazy load routes and views on the server if !@router && @routes_loader # Load the templates...
ruby
def url_for(params) host_with_port = host || location.host host_with_port += ":#{port}" if port && port != 80 scheme = scheme || location.scheme unless RUBY_PLATFORM == 'opal' # lazy load routes and views on the server if !@router && @routes_loader # Load the templates...
[ "def", "url_for", "(", "params", ")", "host_with_port", "=", "host", "||", "location", ".", "host", "host_with_port", "+=", "\":#{port}\"", "if", "port", "&&", "port", "!=", "80", "scheme", "=", "scheme", "||", "location", ".", "scheme", "unless", "RUBY_PLAT...
Full url rebuilds the url from it's constituent parts. The params passed in are used to generate the urls.
[ "Full", "url", "rebuilds", "the", "url", "from", "it", "s", "constituent", "parts", ".", "The", "params", "passed", "in", "are", "used", "to", "generate", "the", "urls", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/url.rb#L72-L114
17,178
voltrb/volt
lib/volt/models/url.rb
Volt.URL.assign_query_hash_to_params
def assign_query_hash_to_params # Get a nested hash representing the current url params. query_hash = parse_query # Get the params that are in the route new_params = @router.url_to_params(path) fail "no routes match path: #{path}" if new_params == false return false if new_params ...
ruby
def assign_query_hash_to_params # Get a nested hash representing the current url params. query_hash = parse_query # Get the params that are in the route new_params = @router.url_to_params(path) fail "no routes match path: #{path}" if new_params == false return false if new_params ...
[ "def", "assign_query_hash_to_params", "# Get a nested hash representing the current url params.", "query_hash", "=", "parse_query", "# Get the params that are in the route", "new_params", "=", "@router", ".", "url_to_params", "(", "path", ")", "fail", "\"no routes match path: #{path}...
Assigning the params is tricky since we don't want to trigger changed on any values that have not changed. So we first loop through all current url params, removing any not present in the params, while also removing them from the list of new params as added. Then we loop through the remaining new parameters and a...
[ "Assigning", "the", "params", "is", "tricky", "since", "we", "don", "t", "want", "to", "trigger", "changed", "on", "any", "values", "that", "have", "not", "changed", ".", "So", "we", "first", "loop", "through", "all", "current", "url", "params", "removing"...
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/url.rb#L173-L192
17,179
voltrb/volt
lib/volt/models/url.rb
Volt.URL.assign_new
def assign_new(params, new_params) new_params.each_pair do |name, value| if value.is_a?(Hash) assign_new(params.get(name), value) else # assign params.set(name, value) end end end
ruby
def assign_new(params, new_params) new_params.each_pair do |name, value| if value.is_a?(Hash) assign_new(params.get(name), value) else # assign params.set(name, value) end end end
[ "def", "assign_new", "(", "params", ",", "new_params", ")", "new_params", ".", "each_pair", "do", "|", "name", ",", "value", "|", "if", "value", ".", "is_a?", "(", "Hash", ")", "assign_new", "(", "params", ".", "get", "(", "name", ")", ",", "value", ...
Assign any new params, which weren't in the old params.
[ "Assign", "any", "new", "params", "which", "weren", "t", "in", "the", "old", "params", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/url.rb#L220-L229
17,180
voltrb/volt
lib/volt/models/url.rb
Volt.URL.query_key
def query_key(path) i = 0 path.map do |v| i += 1 if i != 1 "[#{v}]" else v end end.join('') end
ruby
def query_key(path) i = 0 path.map do |v| i += 1 if i != 1 "[#{v}]" else v end end.join('') end
[ "def", "query_key", "(", "path", ")", "i", "=", "0", "path", ".", "map", "do", "|", "v", "|", "i", "+=", "1", "if", "i", "!=", "1", "\"[#{v}]\"", "else", "v", "end", "end", ".", "join", "(", "''", ")", "end" ]
Generate the key for a nested param attribute
[ "Generate", "the", "key", "for", "a", "nested", "param", "attribute" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/url.rb#L265-L275
17,181
voltrb/volt
lib/volt/page/bindings/view_binding.rb
Volt.ViewBinding.create_controller_handler
def create_controller_handler(full_path, controller_path) # If arguments is nil, then an blank SubContext will be created args = [SubContext.new(@arguments, nil, true)] # get the controller class and action controller_class, action = ControllerHandler.get_controller_and_action(controller_path) ...
ruby
def create_controller_handler(full_path, controller_path) # If arguments is nil, then an blank SubContext will be created args = [SubContext.new(@arguments, nil, true)] # get the controller class and action controller_class, action = ControllerHandler.get_controller_and_action(controller_path) ...
[ "def", "create_controller_handler", "(", "full_path", ",", "controller_path", ")", "# If arguments is nil, then an blank SubContext will be created", "args", "=", "[", "SubContext", ".", "new", "(", "@arguments", ",", "nil", ",", "true", ")", "]", "# get the controller cl...
Create controller handler loads up a controller inside of the controller handler for the paths
[ "Create", "controller", "handler", "loads", "up", "a", "controller", "inside", "of", "the", "controller", "handler", "for", "the", "paths" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/bindings/view_binding.rb#L181-L218
17,182
voltrb/volt
lib/volt/server/rack/component_paths.rb
Volt.ComponentPaths.app_folders
def app_folders # Find all app folders @app_folders ||= begin volt_app = File.expand_path(File.join(File.dirname(__FILE__), '../../../../app')) app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map { |f| File.expand_path(f) } # Gem folders with volt in them ...
ruby
def app_folders # Find all app folders @app_folders ||= begin volt_app = File.expand_path(File.join(File.dirname(__FILE__), '../../../../app')) app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map { |f| File.expand_path(f) } # Gem folders with volt in them ...
[ "def", "app_folders", "# Find all app folders", "@app_folders", "||=", "begin", "volt_app", "=", "File", ".", "expand_path", "(", "File", ".", "join", "(", "File", ".", "dirname", "(", "__FILE__", ")", ",", "'../../../../app'", ")", ")", "app_folders", "=", "[...
Yield for every folder where we might find components
[ "Yield", "for", "every", "folder", "where", "we", "might", "find", "components" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/rack/component_paths.rb#L11-L35
17,183
voltrb/volt
lib/volt/server/rack/component_paths.rb
Volt.ComponentPaths.components
def components return @components if @components @components = {} app_folders do |app_folder| Dir["#{app_folder}/*"].sort.each do |folder| if File.directory?(folder) folder_name = folder[/[^\/]+$/] # Add in the folder if it's not alreay in there ...
ruby
def components return @components if @components @components = {} app_folders do |app_folder| Dir["#{app_folder}/*"].sort.each do |folder| if File.directory?(folder) folder_name = folder[/[^\/]+$/] # Add in the folder if it's not alreay in there ...
[ "def", "components", "return", "@components", "if", "@components", "@components", "=", "{", "}", "app_folders", "do", "|", "app_folder", "|", "Dir", "[", "\"#{app_folder}/*\"", "]", ".", "sort", ".", "each", "do", "|", "folder", "|", "if", "File", ".", "di...
returns an array of every folder that is a component
[ "returns", "an", "array", "of", "every", "folder", "that", "is", "a", "component" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/rack/component_paths.rb#L38-L55
17,184
voltrb/volt
lib/volt/server/rack/component_paths.rb
Volt.ComponentPaths.asset_folders
def asset_folders folders = [] app_folders do |app_folder| Dir["#{app_folder}/*/assets"].sort.each do |asset_folder| folders << yield(asset_folder) end end folders.flatten end
ruby
def asset_folders folders = [] app_folders do |app_folder| Dir["#{app_folder}/*/assets"].sort.each do |asset_folder| folders << yield(asset_folder) end end folders.flatten end
[ "def", "asset_folders", "folders", "=", "[", "]", "app_folders", "do", "|", "app_folder", "|", "Dir", "[", "\"#{app_folder}/*/assets\"", "]", ".", "sort", ".", "each", "do", "|", "asset_folder", "|", "folders", "<<", "yield", "(", "asset_folder", ")", "end",...
Return every asset folder we need to serve from
[ "Return", "every", "asset", "folder", "we", "need", "to", "serve", "from" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/rack/component_paths.rb#L117-L126
17,185
voltrb/volt
lib/volt/page/targets/dom_template.rb
Volt.DomTemplate.track_binding_anchors
def track_binding_anchors @binding_anchors = {} # Loop through the bindings, find in nodes. @bindings.each_pair do |name, binding| if name.is_a?(String) # Find the dom node for an attribute anchor node = nil ` node = self.nodes.querySelector('#' + nam...
ruby
def track_binding_anchors @binding_anchors = {} # Loop through the bindings, find in nodes. @bindings.each_pair do |name, binding| if name.is_a?(String) # Find the dom node for an attribute anchor node = nil ` node = self.nodes.querySelector('#' + nam...
[ "def", "track_binding_anchors", "@binding_anchors", "=", "{", "}", "# Loop through the bindings, find in nodes.", "@bindings", ".", "each_pair", "do", "|", "name", ",", "binding", "|", "if", "name", ".", "is_a?", "(", "String", ")", "# Find the dom node for an attribute...
Finds each of the binding anchors in the temp dom, then stores a reference to them so they can be quickly updated without using xpath to find them again.
[ "Finds", "each", "of", "the", "binding", "anchors", "in", "the", "temp", "dom", "then", "stores", "a", "reference", "to", "them", "so", "they", "can", "be", "quickly", "updated", "without", "using", "xpath", "to", "find", "them", "again", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/targets/dom_template.rb#L39-L59
17,186
voltrb/volt
lib/volt/page/bindings/view_binding/view_lookup_for_path.rb
Volt.ViewLookupForPath.path_for_template
def path_for_template(lookup_path, force_section = nil) parts = lookup_path.split('/') parts_size = parts.size return nil, nil if parts_size == 0 default_parts = %w(main main index body) # When forcing a sub template, we can default the sub template section default_parts[...
ruby
def path_for_template(lookup_path, force_section = nil) parts = lookup_path.split('/') parts_size = parts.size return nil, nil if parts_size == 0 default_parts = %w(main main index body) # When forcing a sub template, we can default the sub template section default_parts[...
[ "def", "path_for_template", "(", "lookup_path", ",", "force_section", "=", "nil", ")", "parts", "=", "lookup_path", ".", "split", "(", "'/'", ")", "parts_size", "=", "parts", ".", "size", "return", "nil", ",", "nil", "if", "parts_size", "==", "0", "default...
Takes in a lookup path and returns the full path for the matching template. Also returns the controller and action name if applicable. Looking up a path is fairly simple. There are 4 parts needed to find the html to be rendered. File paths look like this: app/{component}/views/{controller_name}/{view}.html Wit...
[ "Takes", "in", "a", "lookup", "path", "and", "returns", "the", "full", "path", "for", "the", "matching", "template", ".", "Also", "returns", "the", "controller", "and", "action", "name", "if", "applicable", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/bindings/view_binding/view_lookup_for_path.rb#L44-L91
17,187
voltrb/volt
lib/volt/controllers/model_controller.rb
Volt.ModelController.first_element
def first_element check_section!('first_element') range = dom_nodes nodes = `range.startContainer.childNodes` start_index = `range.startOffset` end_index = `range.endOffset` start_index.upto(end_index) do |index| node = `nodes[index]` # Return if an element ...
ruby
def first_element check_section!('first_element') range = dom_nodes nodes = `range.startContainer.childNodes` start_index = `range.startOffset` end_index = `range.endOffset` start_index.upto(end_index) do |index| node = `nodes[index]` # Return if an element ...
[ "def", "first_element", "check_section!", "(", "'first_element'", ")", "range", "=", "dom_nodes", "nodes", "=", "`", "`", "start_index", "=", "`", "`", "end_index", "=", "`", "`", "start_index", ".", "upto", "(", "end_index", ")", "do", "|", "index", "|", ...
Walks the dom_nodes range until it finds an element. Typically this will be the container element without the whitespace text nodes.
[ "Walks", "the", "dom_nodes", "range", "until", "it", "finds", "an", "element", ".", "Typically", "this", "will", "be", "the", "container", "element", "without", "the", "whitespace", "text", "nodes", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/model_controller.rb#L41-L59
17,188
voltrb/volt
lib/volt/controllers/model_controller.rb
Volt.ModelController.yield_html
def yield_html if (template_path = attrs.content_template_path) @yield_renderer ||= StringTemplateRenderer.new(@volt_app, attrs.content_controller, template_path) @yield_renderer.html else # no template, empty string '' end end
ruby
def yield_html if (template_path = attrs.content_template_path) @yield_renderer ||= StringTemplateRenderer.new(@volt_app, attrs.content_controller, template_path) @yield_renderer.html else # no template, empty string '' end end
[ "def", "yield_html", "if", "(", "template_path", "=", "attrs", ".", "content_template_path", ")", "@yield_renderer", "||=", "StringTemplateRenderer", ".", "new", "(", "@volt_app", ",", "attrs", ".", "content_controller", ",", "template_path", ")", "@yield_renderer", ...
yield_html renders the content passed into a tag as a string. You can ```.watch!``` ```yield_html``` and it will be run again when anything in the template changes.
[ "yield_html", "renders", "the", "content", "passed", "into", "a", "tag", "as", "a", "string", ".", "You", "can", ".", "watch!", "yield_html", "and", "it", "will", "be", "run", "again", "when", "anything", "in", "the", "template", "changes", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/model_controller.rb#L72-L80
17,189
voltrb/volt
lib/volt/controllers/model_controller.rb
Volt.ModelController.model=
def model=(val) if val.is_a?(Promise) # Resolve the promise before setting self.last_promise = val val.then do |result| # Only assign if nothing else has been assigned since we started the resolve self.model = result if last_promise == val end.fail do |err| ...
ruby
def model=(val) if val.is_a?(Promise) # Resolve the promise before setting self.last_promise = val val.then do |result| # Only assign if nothing else has been assigned since we started the resolve self.model = result if last_promise == val end.fail do |err| ...
[ "def", "model", "=", "(", "val", ")", "if", "val", ".", "is_a?", "(", "Promise", ")", "# Resolve the promise before setting", "self", ".", "last_promise", "=", "val", "val", ".", "then", "do", "|", "result", "|", "# Only assign if nothing else has been assigned si...
Sets the current model on this controller
[ "Sets", "the", "current", "model", "on", "this", "controller" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/model_controller.rb#L105-L136
17,190
voltrb/volt
lib/volt/controllers/model_controller.rb
Volt.ModelController.loaded?
def loaded? if model.respond_to?(:loaded?) # There is a model and it is loaded return model.loaded? elsif last_promise || model.is_a?(Promise) # The model is a promise or is resolving return false else # Otherwise, its loaded return true end en...
ruby
def loaded? if model.respond_to?(:loaded?) # There is a model and it is loaded return model.loaded? elsif last_promise || model.is_a?(Promise) # The model is a promise or is resolving return false else # Otherwise, its loaded return true end en...
[ "def", "loaded?", "if", "model", ".", "respond_to?", "(", ":loaded?", ")", "# There is a model and it is loaded", "return", "model", ".", "loaded?", "elsif", "last_promise", "||", "model", ".", "is_a?", "(", "Promise", ")", "# The model is a promise or is resolving", ...
loaded? is a quick way to see if the model for the controller is loaded yet. If the model is there, it asks the model if its loaded. If the model was set to a promise, it waits for the promise to resolve.
[ "loaded?", "is", "a", "quick", "way", "to", "see", "if", "the", "model", "for", "the", "controller", "is", "loaded", "yet", ".", "If", "the", "model", "is", "there", "it", "asks", "the", "model", "if", "its", "loaded", ".", "If", "the", "model", "was...
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/model_controller.rb#L207-L218
17,191
voltrb/volt
lib/volt/controllers/model_controller.rb
Volt.ModelController.raw
def raw(str) # Promises need to have .to_s called using .then, since .to_s is a promise # method, so it won't be passed down to the value. if str.is_a?(Promise) str = str.then(&:to_s) else str = str.to_s unless str.is_a?(String) end str.html_safe end
ruby
def raw(str) # Promises need to have .to_s called using .then, since .to_s is a promise # method, so it won't be passed down to the value. if str.is_a?(Promise) str = str.then(&:to_s) else str = str.to_s unless str.is_a?(String) end str.html_safe end
[ "def", "raw", "(", "str", ")", "# Promises need to have .to_s called using .then, since .to_s is a promise", "# method, so it won't be passed down to the value.", "if", "str", ".", "is_a?", "(", "Promise", ")", "str", "=", "str", ".", "then", "(", ":to_s", ")", "else", ...
Raw marks a string as html safe, so bindings can be rendered as html. With great power comes great responsibility.
[ "Raw", "marks", "a", "string", "as", "html", "safe", "so", "bindings", "can", "be", "rendered", "as", "html", ".", "With", "great", "power", "comes", "great", "responsibility", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/model_controller.rb#L231-L241
17,192
voltrb/volt
lib/volt/models/validators/numericality_validator.rb
Volt.NumericalityValidator.check_errors
def check_errors if @value && @value.is_a?(Numeric) if @args.is_a?(Hash) @args.each do |arg, val| case arg when :min add_error("number must be greater than #{val}") if @value < val when :max add_error("number must be less than #{va...
ruby
def check_errors if @value && @value.is_a?(Numeric) if @args.is_a?(Hash) @args.each do |arg, val| case arg when :min add_error("number must be greater than #{val}") if @value < val when :max add_error("number must be less than #{va...
[ "def", "check_errors", "if", "@value", "&&", "@value", ".", "is_a?", "(", "Numeric", ")", "if", "@args", ".", "is_a?", "(", "Hash", ")", "@args", ".", "each", "do", "|", "arg", ",", "val", "|", "case", "arg", "when", ":min", "add_error", "(", "\"numb...
Looks at the value
[ "Looks", "at", "the", "value" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/models/validators/numericality_validator.rb#L37-L55
17,193
voltrb/volt
lib/volt/controllers/http_controller.rb
Volt.HttpController.params
def params @params ||= begin params = request.params.symbolize_keys.merge(@initial_params) Volt::Model.new(params, persistor: Volt::Persistors::Params) end end
ruby
def params @params ||= begin params = request.params.symbolize_keys.merge(@initial_params) Volt::Model.new(params, persistor: Volt::Persistors::Params) end end
[ "def", "params", "@params", "||=", "begin", "params", "=", "request", ".", "params", ".", "symbolize_keys", ".", "merge", "(", "@initial_params", ")", "Volt", "::", "Model", ".", "new", "(", "params", ",", "persistor", ":", "Volt", "::", "Persistors", "::"...
Initialzed with the params parsed from the route and the HttpRequest
[ "Initialzed", "with", "the", "params", "parsed", "from", "the", "route", "and", "the", "HttpRequest" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/controllers/http_controller.rb#L25-L30
17,194
voltrb/volt
lib/volt/page/targets/attribute_section.rb
Volt.AttributeSection.rezero_bindings
def rezero_bindings(html, bindings) @@base_binding_id ||= 20_000 # rezero parts = html.split(/(\<\!\-\- \$\/?[0-9]+ \-\-\>)/).reject { |v| v == '' } new_html = [] new_bindings = {} id_map = {} parts.each do |part| case part when /\<\!\-\- \$[0-9]+ \-\-\>/ ...
ruby
def rezero_bindings(html, bindings) @@base_binding_id ||= 20_000 # rezero parts = html.split(/(\<\!\-\- \$\/?[0-9]+ \-\-\>)/).reject { |v| v == '' } new_html = [] new_bindings = {} id_map = {} parts.each do |part| case part when /\<\!\-\- \$[0-9]+ \-\-\>/ ...
[ "def", "rezero_bindings", "(", "html", ",", "bindings", ")", "@@base_binding_id", "||=", "20_000", "# rezero", "parts", "=", "html", ".", "split", "(", "/", "\\<", "\\!", "\\-", "\\-", "\\$", "\\/", "\\-", "\\-", "\\>", "/", ")", ".", "reject", "{", "|...
When using bindings, we have to change the binding id so we don't reuse the same id when rendering a binding multiple times.
[ "When", "using", "bindings", "we", "have", "to", "change", "the", "binding", "id", "so", "we", "don", "t", "reuse", "the", "same", "id", "when", "rendering", "a", "binding", "multiple", "times", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/targets/attribute_section.rb#L33-L71
17,195
voltrb/volt
lib/volt/page/targets/attribute_section.rb
Volt.AttributeSection.set_content_and_rezero_bindings
def set_content_and_rezero_bindings(html, bindings) html, bindings = rezero_bindings(html, bindings) if @binding_name == 'main' @target.html = html else @target.find_by_binding_id(@binding_name).html = html end bindings end
ruby
def set_content_and_rezero_bindings(html, bindings) html, bindings = rezero_bindings(html, bindings) if @binding_name == 'main' @target.html = html else @target.find_by_binding_id(@binding_name).html = html end bindings end
[ "def", "set_content_and_rezero_bindings", "(", "html", ",", "bindings", ")", "html", ",", "bindings", "=", "rezero_bindings", "(", "html", ",", "bindings", ")", "if", "@binding_name", "==", "'main'", "@target", ".", "html", "=", "html", "else", "@target", ".",...
Takes in our html and bindings, and rezero's the comment names, and the bindings. Returns an updated bindings hash
[ "Takes", "in", "our", "html", "and", "bindings", "and", "rezero", "s", "the", "comment", "names", "and", "the", "bindings", ".", "Returns", "an", "updated", "bindings", "hash" ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/targets/attribute_section.rb#L75-L85
17,196
voltrb/volt
lib/volt/server/html_parser/view_parser.rb
Volt.ViewParser.code
def code(app_reference) code = '' templates.each_pair do |name, template| binding_code = [] if template['bindings'] template['bindings'].each_pair do |key, value| binding_code << "#{key.inspect} => [#{value.join(', ')}]" end end binding_code ...
ruby
def code(app_reference) code = '' templates.each_pair do |name, template| binding_code = [] if template['bindings'] template['bindings'].each_pair do |key, value| binding_code << "#{key.inspect} => [#{value.join(', ')}]" end end binding_code ...
[ "def", "code", "(", "app_reference", ")", "code", "=", "''", "templates", ".", "each_pair", "do", "|", "name", ",", "template", "|", "binding_code", "=", "[", "]", "if", "template", "[", "'bindings'", "]", "template", "[", "'bindings'", "]", ".", "each_p...
Generate code for the view that can be evaled.
[ "Generate", "code", "for", "the", "view", "that", "can", "be", "evaled", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/view_parser.rb#L48-L65
17,197
voltrb/volt
lib/volt/helpers/time/distance.rb
Volt.Duration.duration_in_words
def duration_in_words(places=2, min_unit=:minutes, recent_message='just now') parts = [] secs = to_i UNIT_MAP.each_pair do |unit, count| val = (secs / count).floor secs = secs % count parts << [val, unit] if val > 0 break if unit == min_unit end # Trim num...
ruby
def duration_in_words(places=2, min_unit=:minutes, recent_message='just now') parts = [] secs = to_i UNIT_MAP.each_pair do |unit, count| val = (secs / count).floor secs = secs % count parts << [val, unit] if val > 0 break if unit == min_unit end # Trim num...
[ "def", "duration_in_words", "(", "places", "=", "2", ",", "min_unit", "=", ":minutes", ",", "recent_message", "=", "'just now'", ")", "parts", "=", "[", "]", "secs", "=", "to_i", "UNIT_MAP", ".", "each_pair", "do", "|", "unit", ",", "count", "|", "val", ...
Returns a string representation of the duration. @param How many places in time units to show. @param The minimum unit to show, anything below will be ignored. Results will be rounded up the the nearest min_unit.
[ "Returns", "a", "string", "representation", "of", "the", "duration", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/helpers/time/distance.rb#L18-L43
17,198
voltrb/volt
lib/volt/page/tasks.rb
Volt.Tasks.response
def response(promise_id, result, error, cookies) # Set the cookies if cookies cookies.each do |key, value| @volt_app.cookies.set(key, value) end end promise = @promises.delete(promise_id) if promise if error # TODO: full error handling ...
ruby
def response(promise_id, result, error, cookies) # Set the cookies if cookies cookies.each do |key, value| @volt_app.cookies.set(key, value) end end promise = @promises.delete(promise_id) if promise if error # TODO: full error handling ...
[ "def", "response", "(", "promise_id", ",", "result", ",", "error", ",", "cookies", ")", "# Set the cookies", "if", "cookies", "cookies", ".", "each", "do", "|", "key", ",", "value", "|", "@volt_app", ".", "cookies", ".", "set", "(", "key", ",", "value", ...
When a request is sent to the backend, it can attach a callback, this is called from the backend to pass to the callback.
[ "When", "a", "request", "is", "sent", "to", "the", "backend", "it", "can", "attach", "a", "callback", "this", "is", "called", "from", "the", "backend", "to", "pass", "to", "the", "callback", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/tasks.rb#L44-L65
17,199
voltrb/volt
lib/volt/page/tasks.rb
Volt.Tasks.notify_query
def notify_query(method_name, collection, query, *args) query_obj = Persistors::ArrayStore.query_pool.lookup(collection, query) query_obj.send(method_name, *args) end
ruby
def notify_query(method_name, collection, query, *args) query_obj = Persistors::ArrayStore.query_pool.lookup(collection, query) query_obj.send(method_name, *args) end
[ "def", "notify_query", "(", "method_name", ",", "collection", ",", "query", ",", "*", "args", ")", "query_obj", "=", "Persistors", "::", "ArrayStore", ".", "query_pool", ".", "lookup", "(", "collection", ",", "query", ")", "query_obj", ".", "send", "(", "m...
Called when the backend sends a notification to change the results of a query.
[ "Called", "when", "the", "backend", "sends", "a", "notification", "to", "change", "the", "results", "of", "a", "query", "." ]
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/page/tasks.rb#L69-L72