id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
7,200
timotheeguerin/clin
lib/clin/command_mixin/options.rb
Clin::CommandMixin::Options.ClassMethods.list_option
def list_option(name, description, **config) add_option Clin::OptionList.new(name, description, **config) end
ruby
def list_option(name, description, **config) add_option Clin::OptionList.new(name, description, **config) end
[ "def", "list_option", "(", "name", ",", "description", ",", "**", "config", ")", "add_option", "Clin", "::", "OptionList", ".", "new", "(", "name", ",", "description", ",", "**", "config", ")", "end" ]
Add a list option. @see Clin::OptionList#initialize
[ "Add", "a", "list", "option", "." ]
43d41c47f9c652065ab7ce636d48a9fe1754135e
https://github.com/timotheeguerin/clin/blob/43d41c47f9c652065ab7ce636d48a9fe1754135e/lib/clin/command_mixin/options.rb#L53-L55
7,201
timotheeguerin/clin
lib/clin/command_mixin/options.rb
Clin::CommandMixin::Options.ClassMethods.list_flag_option
def list_flag_option(name, description, **config) add_option Clin::OptionList.new(name, description, **config.merge(argument: false)) end
ruby
def list_flag_option(name, description, **config) add_option Clin::OptionList.new(name, description, **config.merge(argument: false)) end
[ "def", "list_flag_option", "(", "name", ",", "description", ",", "**", "config", ")", "add_option", "Clin", "::", "OptionList", ".", "new", "(", "name", ",", "description", ",", "**", "config", ".", "merge", "(", "argument", ":", "false", ")", ")", "end" ]
Add a list options that don't take arguments Same as .list_option but set +argument+ to false @see Clin::OptionList#initialize
[ "Add", "a", "list", "options", "that", "don", "t", "take", "arguments", "Same", "as", ".", "list_option", "but", "set", "+", "argument", "+", "to", "false" ]
43d41c47f9c652065ab7ce636d48a9fe1754135e
https://github.com/timotheeguerin/clin/blob/43d41c47f9c652065ab7ce636d48a9fe1754135e/lib/clin/command_mixin/options.rb#L60-L62
7,202
timotheeguerin/clin
lib/clin/command_mixin/options.rb
Clin::CommandMixin::Options.ClassMethods.general_option
def general_option(option_cls, config = {}) option_cls = option_cls.constantize if option_cls.is_a? String @general_options[option_cls] = option_cls.new(config) end
ruby
def general_option(option_cls, config = {}) option_cls = option_cls.constantize if option_cls.is_a? String @general_options[option_cls] = option_cls.new(config) end
[ "def", "general_option", "(", "option_cls", ",", "config", "=", "{", "}", ")", "option_cls", "=", "option_cls", ".", "constantize", "if", "option_cls", ".", "is_a?", "String", "@general_options", "[", "option_cls", "]", "=", "option_cls", ".", "new", "(", "config", ")", "end" ]
Add a general option @param option_cls [Class<GeneralOption>] Class inherited from GeneralOption @param config [Hash] General option config. Check the general option config.
[ "Add", "a", "general", "option" ]
43d41c47f9c652065ab7ce636d48a9fe1754135e
https://github.com/timotheeguerin/clin/blob/43d41c47f9c652065ab7ce636d48a9fe1754135e/lib/clin/command_mixin/options.rb#L78-L81
7,203
timotheeguerin/clin
lib/clin/command_mixin/options.rb
Clin::CommandMixin::Options.ClassMethods.remove_general_option
def remove_general_option(option_cls) option_cls = option_cls.constantize if option_cls.is_a? String @general_options.delete(option_cls) end
ruby
def remove_general_option(option_cls) option_cls = option_cls.constantize if option_cls.is_a? String @general_options.delete(option_cls) end
[ "def", "remove_general_option", "(", "option_cls", ")", "option_cls", "=", "option_cls", ".", "constantize", "if", "option_cls", ".", "is_a?", "String", "@general_options", ".", "delete", "(", "option_cls", ")", "end" ]
Remove a general option Might be useful if a parent added the option but is not needed in this child.
[ "Remove", "a", "general", "option", "Might", "be", "useful", "if", "a", "parent", "added", "the", "option", "but", "is", "not", "needed", "in", "this", "child", "." ]
43d41c47f9c652065ab7ce636d48a9fe1754135e
https://github.com/timotheeguerin/clin/blob/43d41c47f9c652065ab7ce636d48a9fe1754135e/lib/clin/command_mixin/options.rb#L85-L88
7,204
timotheeguerin/clin
lib/clin/command_mixin/options.rb
Clin::CommandMixin::Options.ClassMethods.option_defaults
def option_defaults out = {} @specific_options.each do |option| option.load_default(out) end @general_options.each do |_cls, option| out.merge! option.class.option_defaults end out end
ruby
def option_defaults out = {} @specific_options.each do |option| option.load_default(out) end @general_options.each do |_cls, option| out.merge! option.class.option_defaults end out end
[ "def", "option_defaults", "out", "=", "{", "}", "@specific_options", ".", "each", "do", "|", "option", "|", "option", ".", "load_default", "(", "out", ")", "end", "@general_options", ".", "each", "do", "|", "_cls", ",", "option", "|", "out", ".", "merge!", "option", ".", "class", ".", "option_defaults", "end", "out", "end" ]
To be called inside OptionParser block Extract the option in the command line using the OptionParser and map it to the out map. @return [Hash] Where the options shall be extracted
[ "To", "be", "called", "inside", "OptionParser", "block", "Extract", "the", "option", "in", "the", "command", "line", "using", "the", "OptionParser", "and", "map", "it", "to", "the", "out", "map", "." ]
43d41c47f9c652065ab7ce636d48a9fe1754135e
https://github.com/timotheeguerin/clin/blob/43d41c47f9c652065ab7ce636d48a9fe1754135e/lib/clin/command_mixin/options.rb#L93-L103
7,205
dmerrick/lights_app
lib/philips_hue/bridge.rb
PhilipsHue.Bridge.add_all_lights
def add_all_lights all_lights = [] overview["lights"].each do |id, light| all_lights << add_light(id.to_i, light["name"]) end all_lights end
ruby
def add_all_lights all_lights = [] overview["lights"].each do |id, light| all_lights << add_light(id.to_i, light["name"]) end all_lights end
[ "def", "add_all_lights", "all_lights", "=", "[", "]", "overview", "[", "\"lights\"", "]", ".", "each", "do", "|", "id", ",", "light", "|", "all_lights", "<<", "add_light", "(", "id", ".", "to_i", ",", "light", "[", "\"name\"", "]", ")", "end", "all_lights", "end" ]
loop through the available lights and make corresponding objects
[ "loop", "through", "the", "available", "lights", "and", "make", "corresponding", "objects" ]
0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d
https://github.com/dmerrick/lights_app/blob/0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d/lib/philips_hue/bridge.rb#L143-L149
7,206
ramhoj/table_for
lib/table_for/helper.rb
TableFor.Helper.table_for
def table_for(model_class, records, html = {}, &block) Table.new(self, model_class, records, html, block).render end
ruby
def table_for(model_class, records, html = {}, &block) Table.new(self, model_class, records, html, block).render end
[ "def", "table_for", "(", "model_class", ",", "records", ",", "html", "=", "{", "}", ",", "&", "block", ")", "Table", ".", "new", "(", "self", ",", "model_class", ",", "records", ",", "html", ",", "block", ")", ".", "render", "end" ]
Create a html table for records, using model class for naming things. Examples: <tt>table_for Product, @products do |table| table.head :name, :size, :description, :price table.body do |row| row.cell :name row.cells :size, :description row.cell number_to_currency(row.record.price) end table.foot do link_to "Add product", new_product_path end end</tt> <tt>table_for Product, @products do |table| table.columns :name, :size, :description, :price table.foot do link_to "Add product", new_product_path end end</tt> Returns: A string containing the html table (Call this method from your erb templates by wrapping each line in <%= %> or <% %>)
[ "Create", "a", "html", "table", "for", "records", "using", "model", "class", "for", "naming", "things", "." ]
be9f53834f0d2cb2e0d900d4a0340ede7302d7f1
https://github.com/ramhoj/table_for/blob/be9f53834f0d2cb2e0d900d4a0340ede7302d7f1/lib/table_for/helper.rb#L36-L38
7,207
jinx/core
lib/jinx/resource/unique.rb
Jinx.Unique.uniquify_attributes
def uniquify_attributes(attributes) attributes.each do |ka| oldval = send(ka) next unless String === oldval newval = UniquifierCache.instance.get(self, oldval) set_property_value(ka, newval) logger.debug { "Reset #{qp} #{ka} from #{oldval} to unique value #{newval}." } end end
ruby
def uniquify_attributes(attributes) attributes.each do |ka| oldval = send(ka) next unless String === oldval newval = UniquifierCache.instance.get(self, oldval) set_property_value(ka, newval) logger.debug { "Reset #{qp} #{ka} from #{oldval} to unique value #{newval}." } end end
[ "def", "uniquify_attributes", "(", "attributes", ")", "attributes", ".", "each", "do", "|", "ka", "|", "oldval", "=", "send", "(", "ka", ")", "next", "unless", "String", "===", "oldval", "newval", "=", "UniquifierCache", ".", "instance", ".", "get", "(", "self", ",", "oldval", ")", "set_property_value", "(", "ka", ",", "newval", ")", "logger", ".", "debug", "{", "\"Reset #{qp} #{ka} from #{oldval} to unique value #{newval}.\"", "}", "end", "end" ]
Makes this domain object's String values for the given attributes unique. @param [<Symbol>] the key attributes to uniquify
[ "Makes", "this", "domain", "object", "s", "String", "values", "for", "the", "given", "attributes", "unique", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/resource/unique.rb#L22-L30
7,208
hokstadconsulting/purecdb
lib/purecdb/writer.rb
PureCDB.Writer.store
def store key,value # In an attempt to save memory, we pack the hash data we gather into # strings of BER compressed integers... h = hash(key) hi = (h % num_hashes) @hashes[hi] ||= "" header = build_header(key.length, value.length) @io.syswrite(header+key+value) size = header.size + key.size + value.size @hashes[hi] += [h,@pos].pack("ww") # BER compressed @pos += size end
ruby
def store key,value # In an attempt to save memory, we pack the hash data we gather into # strings of BER compressed integers... h = hash(key) hi = (h % num_hashes) @hashes[hi] ||= "" header = build_header(key.length, value.length) @io.syswrite(header+key+value) size = header.size + key.size + value.size @hashes[hi] += [h,@pos].pack("ww") # BER compressed @pos += size end
[ "def", "store", "key", ",", "value", "# In an attempt to save memory, we pack the hash data we gather into", "# strings of BER compressed integers...", "h", "=", "hash", "(", "key", ")", "hi", "=", "(", "h", "%", "num_hashes", ")", "@hashes", "[", "hi", "]", "||=", "\"\"", "header", "=", "build_header", "(", "key", ".", "length", ",", "value", ".", "length", ")", "@io", ".", "syswrite", "(", "header", "+", "key", "+", "value", ")", "size", "=", "header", ".", "size", "+", "key", ".", "size", "+", "value", ".", "size", "@hashes", "[", "hi", "]", "+=", "[", "h", ",", "@pos", "]", ".", "pack", "(", "\"ww\"", ")", "# BER compressed", "@pos", "+=", "size", "end" ]
Store 'value' under 'key'. Multiple values can we stored for the same key by calling #store multiple times with the same key value.
[ "Store", "value", "under", "key", "." ]
d19102e5dffbb2f0de4fab4f86c603880c3ffea8
https://github.com/hokstadconsulting/purecdb/blob/d19102e5dffbb2f0de4fab4f86c603880c3ffea8/lib/purecdb/writer.rb#L92-L104
7,209
bordeeinc/ico
lib/ico/utils.rb
ICO.Utils.png_to_sizes
def png_to_sizes(input_filename, sizes_array, output_dirname=nil, append_filenames=APPEND_FILE_FORMAT, force_overwrite=false, clear=true, force_clear=false) basename = File.basename(input_filename, '.*') output_dirname ||= File.join(File.expand_path(File.dirname(input_filename)), "#{basename}_sizes") # ensure dir exists FileUtils.mkdir_p(output_dirname) # ensure dir empty if clear filename_array = Dir.glob(File.join(output_dirname, '**/*')) unless force_clear # protect from destructive action raise "more than ICO format files in #{output_dirname}" if contains_other_than_ext?(filename_array, :ico) end FileUtils.rm_rf(filename_array) end # import base image img = ChunkyPNG::Image.from_file(input_filename) # resize sizes_array.each do |x,y| y ||= x img_attrs = {:x => x, :y => y} bn = basename + Kernel.sprintf(append_filenames, img_attrs) fn = File.join(output_dirname, "#{bn}.png") img_out = img.resample_nearest_neighbor(x, y) unless force_overwrite raise "File exists: #{fn}" if File.exist?(fn) end IO.write(fn, img_out) end return output_dirname end
ruby
def png_to_sizes(input_filename, sizes_array, output_dirname=nil, append_filenames=APPEND_FILE_FORMAT, force_overwrite=false, clear=true, force_clear=false) basename = File.basename(input_filename, '.*') output_dirname ||= File.join(File.expand_path(File.dirname(input_filename)), "#{basename}_sizes") # ensure dir exists FileUtils.mkdir_p(output_dirname) # ensure dir empty if clear filename_array = Dir.glob(File.join(output_dirname, '**/*')) unless force_clear # protect from destructive action raise "more than ICO format files in #{output_dirname}" if contains_other_than_ext?(filename_array, :ico) end FileUtils.rm_rf(filename_array) end # import base image img = ChunkyPNG::Image.from_file(input_filename) # resize sizes_array.each do |x,y| y ||= x img_attrs = {:x => x, :y => y} bn = basename + Kernel.sprintf(append_filenames, img_attrs) fn = File.join(output_dirname, "#{bn}.png") img_out = img.resample_nearest_neighbor(x, y) unless force_overwrite raise "File exists: #{fn}" if File.exist?(fn) end IO.write(fn, img_out) end return output_dirname end
[ "def", "png_to_sizes", "(", "input_filename", ",", "sizes_array", ",", "output_dirname", "=", "nil", ",", "append_filenames", "=", "APPEND_FILE_FORMAT", ",", "force_overwrite", "=", "false", ",", "clear", "=", "true", ",", "force_clear", "=", "false", ")", "basename", "=", "File", ".", "basename", "(", "input_filename", ",", "'.*'", ")", "output_dirname", "||=", "File", ".", "join", "(", "File", ".", "expand_path", "(", "File", ".", "dirname", "(", "input_filename", ")", ")", ",", "\"#{basename}_sizes\"", ")", "# ensure dir exists", "FileUtils", ".", "mkdir_p", "(", "output_dirname", ")", "# ensure dir empty", "if", "clear", "filename_array", "=", "Dir", ".", "glob", "(", "File", ".", "join", "(", "output_dirname", ",", "'**/*'", ")", ")", "unless", "force_clear", "# protect from destructive action", "raise", "\"more than ICO format files in #{output_dirname}\"", "if", "contains_other_than_ext?", "(", "filename_array", ",", ":ico", ")", "end", "FileUtils", ".", "rm_rf", "(", "filename_array", ")", "end", "# import base image", "img", "=", "ChunkyPNG", "::", "Image", ".", "from_file", "(", "input_filename", ")", "# resize", "sizes_array", ".", "each", "do", "|", "x", ",", "y", "|", "y", "||=", "x", "img_attrs", "=", "{", ":x", "=>", "x", ",", ":y", "=>", "y", "}", "bn", "=", "basename", "+", "Kernel", ".", "sprintf", "(", "append_filenames", ",", "img_attrs", ")", "fn", "=", "File", ".", "join", "(", "output_dirname", ",", "\"#{bn}.png\"", ")", "img_out", "=", "img", ".", "resample_nearest_neighbor", "(", "x", ",", "y", ")", "unless", "force_overwrite", "raise", "\"File exists: #{fn}\"", "if", "File", ".", "exist?", "(", "fn", ")", "end", "IO", ".", "write", "(", "fn", ",", "img_out", ")", "end", "return", "output_dirname", "end" ]
resize PNG file and write new sizes to directory @see https://ruby-doc.org/core-2.2.0/Kernel.html#method-i-sprintf @param input_filename [String] input filename; required: file is PNG file format @param sizes_array [Array<Array<Integer,Integer]>>, Array<Integer>] rectangles use Array with XY: `[x,y]` squares use single Integer `N` mixed indices is valid example: `[24, [24,24], [480,270], 888] # a[0] => 24x24; a[1] => 24x24; a[2] => 480x270; a[3] => 888x888` @param output_dirname [String] (optional) directory name including expanded path default: new dir named input_filename's basename + "_sizes" in same dir as input_filename @param append_filenames [String] (optional,required-with-supplied-default) append resized filenames with Kernel#sprintf format_string available args: `{:x => N, :y => N}` default: `"-%<x>dx%<y>d"` @param force_overwrite [Boolean] overwrite existing resized images @param clear [Boolean] default: `true` @param force_clear [Boolean] clear output_dirname of contents before write; default: false @return [String] output_dirname; default: false
[ "resize", "PNG", "file", "and", "write", "new", "sizes", "to", "directory" ]
008760fafafbb3d3e561e97e3596ffe43f4c21ef
https://github.com/bordeeinc/ico/blob/008760fafafbb3d3e561e97e3596ffe43f4c21ef/lib/ico/utils.rb#L104-L143
7,210
jinx/core
lib/jinx/helpers/pretty_print.rb
Jinx.Hasher.qp
def qp qph = {} each { |k, v| qph[k.qp] = v.qp } qph.pp_s end
ruby
def qp qph = {} each { |k, v| qph[k.qp] = v.qp } qph.pp_s end
[ "def", "qp", "qph", "=", "{", "}", "each", "{", "|", "k", ",", "v", "|", "qph", "[", "k", ".", "qp", "]", "=", "v", ".", "qp", "}", "qph", ".", "pp_s", "end" ]
qp, short for quick-print, prints this Hasher with a filter that calls qp on each key and value. @return [String] the quick-print result
[ "qp", "short", "for", "quick", "-", "print", "prints", "this", "Hasher", "with", "a", "filter", "that", "calls", "qp", "on", "each", "key", "and", "value", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/pretty_print.rb#L161-L165
7,211
subimage/cashboard-rb
lib/cashboard/base.rb
Cashboard.Base.update
def update options = self.class.merge_options() options.merge!({:body => self.to_xml}) response = self.class.put(self.href, options) begin self.class.check_status_code(response) rescue return false end return true end
ruby
def update options = self.class.merge_options() options.merge!({:body => self.to_xml}) response = self.class.put(self.href, options) begin self.class.check_status_code(response) rescue return false end return true end
[ "def", "update", "options", "=", "self", ".", "class", ".", "merge_options", "(", ")", "options", ".", "merge!", "(", "{", ":body", "=>", "self", ".", "to_xml", "}", ")", "response", "=", "self", ".", "class", ".", "put", "(", "self", ".", "href", ",", "options", ")", "begin", "self", ".", "class", ".", "check_status_code", "(", "response", ")", "rescue", "return", "false", "end", "return", "true", "end" ]
Updates the object on server, after attributes have been set. Returns boolean if successful Example: te = Cashboard::TimeEntry.new_from_url(time_entry_url) te.minutes = 60 update_success = te.update
[ "Updates", "the", "object", "on", "server", "after", "attributes", "have", "been", "set", ".", "Returns", "boolean", "if", "successful" ]
320e311ea1549cdd0dada0f8a0a4f9942213b28f
https://github.com/subimage/cashboard-rb/blob/320e311ea1549cdd0dada0f8a0a4f9942213b28f/lib/cashboard/base.rb#L96-L106
7,212
subimage/cashboard-rb
lib/cashboard/base.rb
Cashboard.Base.delete
def delete options = self.class.merge_options() response = self.class.delete(self.href, options) begin self.class.check_status_code(response) rescue return false end return true end
ruby
def delete options = self.class.merge_options() response = self.class.delete(self.href, options) begin self.class.check_status_code(response) rescue return false end return true end
[ "def", "delete", "options", "=", "self", ".", "class", ".", "merge_options", "(", ")", "response", "=", "self", ".", "class", ".", "delete", "(", "self", ".", "href", ",", "options", ")", "begin", "self", ".", "class", ".", "check_status_code", "(", "response", ")", "rescue", "return", "false", "end", "return", "true", "end" ]
Destroys Cashboard object on the server. Returns boolean upon success.
[ "Destroys", "Cashboard", "object", "on", "the", "server", ".", "Returns", "boolean", "upon", "success", "." ]
320e311ea1549cdd0dada0f8a0a4f9942213b28f
https://github.com/subimage/cashboard-rb/blob/320e311ea1549cdd0dada0f8a0a4f9942213b28f/lib/cashboard/base.rb#L110-L119
7,213
subimage/cashboard-rb
lib/cashboard/base.rb
Cashboard.Base.to_xml
def to_xml(options={}) options[:indent] ||= 2 xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) xml.instruct! unless options[:skip_instruct] obj_name = self.class.resource_name.singularize # Turn our OpenStruct attributes into a hash we can export to XML obj_attrs = self.marshal_dump xml.tag!(obj_name) do obj_attrs.each do |key,value| next if key.to_sym == :link # Don't feed back links to server case value when ::Hash value.to_xml( options.merge({ :root => key, :skip_instruct => true }) ) when ::Array value.to_xml( options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true }) ) else xml.tag!(key, value) end end end end
ruby
def to_xml(options={}) options[:indent] ||= 2 xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) xml.instruct! unless options[:skip_instruct] obj_name = self.class.resource_name.singularize # Turn our OpenStruct attributes into a hash we can export to XML obj_attrs = self.marshal_dump xml.tag!(obj_name) do obj_attrs.each do |key,value| next if key.to_sym == :link # Don't feed back links to server case value when ::Hash value.to_xml( options.merge({ :root => key, :skip_instruct => true }) ) when ::Array value.to_xml( options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true }) ) else xml.tag!(key, value) end end end end
[ "def", "to_xml", "(", "options", "=", "{", "}", ")", "options", "[", ":indent", "]", "||=", "2", "xml", "=", "options", "[", ":builder", "]", "||=", "Builder", "::", "XmlMarkup", ".", "new", "(", ":indent", "=>", "options", "[", ":indent", "]", ")", "xml", ".", "instruct!", "unless", "options", "[", ":skip_instruct", "]", "obj_name", "=", "self", ".", "class", ".", "resource_name", ".", "singularize", "# Turn our OpenStruct attributes into a hash we can export to XML", "obj_attrs", "=", "self", ".", "marshal_dump", "xml", ".", "tag!", "(", "obj_name", ")", "do", "obj_attrs", ".", "each", "do", "|", "key", ",", "value", "|", "next", "if", "key", ".", "to_sym", "==", ":link", "# Don't feed back links to server", "case", "value", "when", "::", "Hash", "value", ".", "to_xml", "(", "options", ".", "merge", "(", "{", ":root", "=>", "key", ",", ":skip_instruct", "=>", "true", "}", ")", ")", "when", "::", "Array", "value", ".", "to_xml", "(", "options", ".", "merge", "(", "{", ":root", "=>", "key", ",", ":children", "=>", "key", ".", "to_s", ".", "singularize", ",", ":skip_instruct", "=>", "true", "}", ")", ")", "else", "xml", ".", "tag!", "(", "key", ",", "value", ")", "end", "end", "end", "end" ]
Utilizes ActiveSupport to turn our objects into XML that we can pass back to the server. General concept stolen from Rails CoreExtensions::Hash::Conversions
[ "Utilizes", "ActiveSupport", "to", "turn", "our", "objects", "into", "XML", "that", "we", "can", "pass", "back", "to", "the", "server", "." ]
320e311ea1549cdd0dada0f8a0a4f9942213b28f
https://github.com/subimage/cashboard-rb/blob/320e311ea1549cdd0dada0f8a0a4f9942213b28f/lib/cashboard/base.rb#L125-L159
7,214
tclaus/keytechkit.gem
lib/keytechKit/elements/element_handler.rb
KeytechKit.ElementHandler.delete
def delete(element_key) parameter = { basic_auth: @auth } response = self.class.delete("/elements/#{element_key}", parameter) unless response.success? puts "Could not save element: #{response.headers['x-errordescription']}" end response end
ruby
def delete(element_key) parameter = { basic_auth: @auth } response = self.class.delete("/elements/#{element_key}", parameter) unless response.success? puts "Could not save element: #{response.headers['x-errordescription']}" end response end
[ "def", "delete", "(", "element_key", ")", "parameter", "=", "{", "basic_auth", ":", "@auth", "}", "response", "=", "self", ".", "class", ".", "delete", "(", "\"/elements/#{element_key}\"", ",", "parameter", ")", "unless", "response", ".", "success?", "puts", "\"Could not save element: #{response.headers['x-errordescription']}\"", "end", "response", "end" ]
Deletes an element with the key It returns the http response.
[ "Deletes", "an", "element", "with", "the", "key", "It", "returns", "the", "http", "response", "." ]
caa7a6bee32b75ec18a4004179ae10cb69d148c2
https://github.com/tclaus/keytechkit.gem/blob/caa7a6bee32b75ec18a4004179ae10cb69d148c2/lib/keytechKit/elements/element_handler.rb#L76-L83
7,215
tclaus/keytechkit.gem
lib/keytechKit/elements/element_handler.rb
KeytechKit.ElementHandler.notes
def notes(element_key) parameter = { basic_auth: @auth } response = self.class.get("/elements/#{element_key}/notes", parameter) if response.success? search_response_header = SearchResponseHeader.new(response) search_response_header.elementList end end
ruby
def notes(element_key) parameter = { basic_auth: @auth } response = self.class.get("/elements/#{element_key}/notes", parameter) if response.success? search_response_header = SearchResponseHeader.new(response) search_response_header.elementList end end
[ "def", "notes", "(", "element_key", ")", "parameter", "=", "{", "basic_auth", ":", "@auth", "}", "response", "=", "self", ".", "class", ".", "get", "(", "\"/elements/#{element_key}/notes\"", ",", "parameter", ")", "if", "response", ".", "success?", "search_response_header", "=", "SearchResponseHeader", ".", "new", "(", "response", ")", "search_response_header", ".", "elementList", "end", "end" ]
It returns the notes of an element if anything are given Notes list can be empty It returns nil if no element with this elementKey was found
[ "It", "returns", "the", "notes", "of", "an", "element", "if", "anything", "are", "given", "Notes", "list", "can", "be", "empty", "It", "returns", "nil", "if", "no", "element", "with", "this", "elementKey", "was", "found" ]
caa7a6bee32b75ec18a4004179ae10cb69d148c2
https://github.com/tclaus/keytechkit.gem/blob/caa7a6bee32b75ec18a4004179ae10cb69d148c2/lib/keytechKit/elements/element_handler.rb#L144-L152
7,216
tclaus/keytechkit.gem
lib/keytechKit/elements/element_handler.rb
KeytechKit.ElementHandler.note_handler
def note_handler @_note_handler = NoteHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_note_handler.nil? @_note_handler end
ruby
def note_handler @_note_handler = NoteHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_note_handler.nil? @_note_handler end
[ "def", "note_handler", "@_note_handler", "=", "NoteHandler", ".", "new", "(", "keytechkit", ".", "base_url", ",", "keytechkit", ".", "username", ",", "keytechkit", ".", "password", ")", "if", "@_note_handler", ".", "nil?", "@_note_handler", "end" ]
Returns Notes resource. Every Element can have zero, one or more notes. You can notes only access in context of its element which ownes the notes
[ "Returns", "Notes", "resource", ".", "Every", "Element", "can", "have", "zero", "one", "or", "more", "notes", ".", "You", "can", "notes", "only", "access", "in", "context", "of", "its", "element", "which", "ownes", "the", "notes" ]
caa7a6bee32b75ec18a4004179ae10cb69d148c2
https://github.com/tclaus/keytechkit.gem/blob/caa7a6bee32b75ec18a4004179ae10cb69d148c2/lib/keytechKit/elements/element_handler.rb#L157-L160
7,217
tclaus/keytechkit.gem
lib/keytechKit/elements/element_handler.rb
KeytechKit.ElementHandler.file_handler
def file_handler @_element_file_handler = ElementFileHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_element_file_handler.nil? @_element_file_handler end
ruby
def file_handler @_element_file_handler = ElementFileHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_element_file_handler.nil? @_element_file_handler end
[ "def", "file_handler", "@_element_file_handler", "=", "ElementFileHandler", ".", "new", "(", "keytechkit", ".", "base_url", ",", "keytechkit", ".", "username", ",", "keytechkit", ".", "password", ")", "if", "@_element_file_handler", ".", "nil?", "@_element_file_handler", "end" ]
Returns the file object. Every element can have a Masterfile and one or more preview files
[ "Returns", "the", "file", "object", ".", "Every", "element", "can", "have", "a", "Masterfile", "and", "one", "or", "more", "preview", "files" ]
caa7a6bee32b75ec18a4004179ae10cb69d148c2
https://github.com/tclaus/keytechkit.gem/blob/caa7a6bee32b75ec18a4004179ae10cb69d148c2/lib/keytechKit/elements/element_handler.rb#L164-L167
7,218
treeder/quicky
lib/quicky/results_hash.rb
Quicky.ResultsHash.to_hash
def to_hash ret = {} self.each_pair do |k, v| ret[k] = v.to_hash() end ret end
ruby
def to_hash ret = {} self.each_pair do |k, v| ret[k] = v.to_hash() end ret end
[ "def", "to_hash", "ret", "=", "{", "}", "self", ".", "each_pair", "do", "|", "k", ",", "v", "|", "ret", "[", "k", "]", "=", "v", ".", "to_hash", "(", ")", "end", "ret", "end" ]
returns results in a straight up hash.
[ "returns", "results", "in", "a", "straight", "up", "hash", "." ]
4ac89408c28ca04745280a4cef2db4f97ed5b6d2
https://github.com/treeder/quicky/blob/4ac89408c28ca04745280a4cef2db4f97ed5b6d2/lib/quicky/results_hash.rb#L6-L12
7,219
treeder/quicky
lib/quicky/results_hash.rb
Quicky.ResultsHash.merge!
def merge!(rh) rh.each_pair do |k, v| # v is a TimeCollector if self.has_key?(k) self[k].merge!(v) else self[k] = v end end end
ruby
def merge!(rh) rh.each_pair do |k, v| # v is a TimeCollector if self.has_key?(k) self[k].merge!(v) else self[k] = v end end end
[ "def", "merge!", "(", "rh", ")", "rh", ".", "each_pair", "do", "|", "k", ",", "v", "|", "# v is a TimeCollector", "if", "self", ".", "has_key?", "(", "k", ")", "self", "[", "k", "]", ".", "merge!", "(", "v", ")", "else", "self", "[", "k", "]", "=", "v", "end", "end", "end" ]
merges multiple ResultsHash's
[ "merges", "multiple", "ResultsHash", "s" ]
4ac89408c28ca04745280a4cef2db4f97ed5b6d2
https://github.com/treeder/quicky/blob/4ac89408c28ca04745280a4cef2db4f97ed5b6d2/lib/quicky/results_hash.rb#L24-L33
7,220
wied03/opal-factory_girl
opal/opal/active_support/inflector/methods.rb
ActiveSupport.Inflector.titleize
def titleize(word) # negative lookbehind doesn't work in Firefox / Safari # humanize(underscore(word)).gsub(/\b(?<!['’`])[a-z]/) { |match| match.capitalize } humanized = humanize(underscore(word)) humanized.reverse.gsub(/[a-z](?!['’`])\b/) { |match| match.capitalize }.reverse end
ruby
def titleize(word) # negative lookbehind doesn't work in Firefox / Safari # humanize(underscore(word)).gsub(/\b(?<!['’`])[a-z]/) { |match| match.capitalize } humanized = humanize(underscore(word)) humanized.reverse.gsub(/[a-z](?!['’`])\b/) { |match| match.capitalize }.reverse end
[ "def", "titleize", "(", "word", ")", "# negative lookbehind doesn't work in Firefox / Safari", "# humanize(underscore(word)).gsub(/\\b(?<!['’`])[a-z]/) { |match| match.capitalize }", "humanized", "=", "humanize", "(", "underscore", "(", "word", ")", ")", "humanized", ".", "reverse", ".", "gsub", "(", "/", "/)", " ", "{", "|", "a", "tch| ", "m", "tch.c", "a", "pitalize }", "r", "e", "verse", "end" ]
Capitalizes all the words and replaces some characters in the string to create a nicer looking title. +titleize+ is meant for creating pretty output. It is not used in the Rails internals. +titleize+ is also aliased as +titlecase+. titleize('man from the boondocks') # => "Man From The Boondocks" titleize('x-men: the last stand') # => "X Men: The Last Stand" titleize('TheManWithoutAPast') # => "The Man Without A Past" titleize('raiders_of_the_lost_ark') # => "Raiders Of The Lost Ark"
[ "Capitalizes", "all", "the", "words", "and", "replaces", "some", "characters", "in", "the", "string", "to", "create", "a", "nicer", "looking", "title", ".", "+", "titleize", "+", "is", "meant", "for", "creating", "pretty", "output", ".", "It", "is", "not", "used", "in", "the", "Rails", "internals", "." ]
697114a8c63f4cba38b84d27d1f7b823c8d0bb38
https://github.com/wied03/opal-factory_girl/blob/697114a8c63f4cba38b84d27d1f7b823c8d0bb38/opal/opal/active_support/inflector/methods.rb#L160-L165
7,221
hck/filter_factory
lib/filter_factory/filter.rb
FilterFactory.Filter.attributes
def attributes fields.each_with_object(HashWithIndifferentAccess.new) do |field, acc| acc[field.alias] = field.value end end
ruby
def attributes fields.each_with_object(HashWithIndifferentAccess.new) do |field, acc| acc[field.alias] = field.value end end
[ "def", "attributes", "fields", ".", "each_with_object", "(", "HashWithIndifferentAccess", ".", "new", ")", "do", "|", "field", ",", "acc", "|", "acc", "[", "field", ".", "alias", "]", "=", "field", ".", "value", "end", "end" ]
Initializes new instance of Filter class. Returns list of filter attributes. @return [HashWithIndifferentAccess]
[ "Initializes", "new", "instance", "of", "Filter", "class", ".", "Returns", "list", "of", "filter", "attributes", "." ]
21f331ed3b1a9eae1a56727617e26407c96daebc
https://github.com/hck/filter_factory/blob/21f331ed3b1a9eae1a56727617e26407c96daebc/lib/filter_factory/filter.rb#L25-L29
7,222
mrsimonfletcher/roroacms
app/helpers/roroacms/routing_helper.rb
Roroacms.RoutingHelper.get_type_by_url
def get_type_by_url return 'P' if params[:slug].blank? # split the url up into segments segments = params[:slug].split('/') # general variables url = params[:slug] article_url = Setting.get('articles_slug') category_url = Setting.get('category_slug') tag_url = Setting.get('tag_slug') status = "(post_status = 'Published' AND post_date <= CURRENT_TIMESTAMP AND disabled = 'N')" # HACK: this needs to be optimised # is it a article post or a page post if segments[0] == article_url if !segments[1].blank? if segments[1] == category_url || segments[1] == tag_url # render a category or tag page return 'CT' elsif segments[1].match(/\A\+?\d+(?:\.\d+)?\Z/) # render the archive page return 'AR' else # otherwise render a single article page return 'A' end else # render the overall all the articles return 'C' end else # render a page return 'P' end end
ruby
def get_type_by_url return 'P' if params[:slug].blank? # split the url up into segments segments = params[:slug].split('/') # general variables url = params[:slug] article_url = Setting.get('articles_slug') category_url = Setting.get('category_slug') tag_url = Setting.get('tag_slug') status = "(post_status = 'Published' AND post_date <= CURRENT_TIMESTAMP AND disabled = 'N')" # HACK: this needs to be optimised # is it a article post or a page post if segments[0] == article_url if !segments[1].blank? if segments[1] == category_url || segments[1] == tag_url # render a category or tag page return 'CT' elsif segments[1].match(/\A\+?\d+(?:\.\d+)?\Z/) # render the archive page return 'AR' else # otherwise render a single article page return 'A' end else # render the overall all the articles return 'C' end else # render a page return 'P' end end
[ "def", "get_type_by_url", "return", "'P'", "if", "params", "[", ":slug", "]", ".", "blank?", "# split the url up into segments", "segments", "=", "params", "[", ":slug", "]", ".", "split", "(", "'/'", ")", "# general variables", "url", "=", "params", "[", ":slug", "]", "article_url", "=", "Setting", ".", "get", "(", "'articles_slug'", ")", "category_url", "=", "Setting", ".", "get", "(", "'category_slug'", ")", "tag_url", "=", "Setting", ".", "get", "(", "'tag_slug'", ")", "status", "=", "\"(post_status = 'Published' AND post_date <= CURRENT_TIMESTAMP AND disabled = 'N')\"", "# HACK: this needs to be optimised", "# is it a article post or a page post", "if", "segments", "[", "0", "]", "==", "article_url", "if", "!", "segments", "[", "1", "]", ".", "blank?", "if", "segments", "[", "1", "]", "==", "category_url", "||", "segments", "[", "1", "]", "==", "tag_url", "# render a category or tag page", "return", "'CT'", "elsif", "segments", "[", "1", "]", ".", "match", "(", "/", "\\A", "\\+", "\\d", "\\.", "\\d", "\\Z", "/", ")", "# render the archive page", "return", "'AR'", "else", "# otherwise render a single article page", "return", "'A'", "end", "else", "# render the overall all the articles", "return", "'C'", "end", "else", "# render a page", "return", "'P'", "end", "end" ]
returns that type of page that you are currenly viewing
[ "returns", "that", "type", "of", "page", "that", "you", "are", "currenly", "viewing" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/routing_helper.rb#L96-L136
7,223
houston/houston-conversations
lib/houston/conversations.rb
Houston.Conversations.hear
def hear(message, params={}) raise ArgumentError, "`message` must respond to :channel" unless message.respond_to?(:channel) raise ArgumentError, "`message` must respond to :sender" unless message.respond_to?(:sender) listeners.hear(message).each do |match| event = Houston::Conversations::Event.new(match) if block_given? yield event, match.listener else match.listener.call_async event end # Invoke only one listener per message return true end false end
ruby
def hear(message, params={}) raise ArgumentError, "`message` must respond to :channel" unless message.respond_to?(:channel) raise ArgumentError, "`message` must respond to :sender" unless message.respond_to?(:sender) listeners.hear(message).each do |match| event = Houston::Conversations::Event.new(match) if block_given? yield event, match.listener else match.listener.call_async event end # Invoke only one listener per message return true end false end
[ "def", "hear", "(", "message", ",", "params", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"`message` must respond to :channel\"", "unless", "message", ".", "respond_to?", "(", ":channel", ")", "raise", "ArgumentError", ",", "\"`message` must respond to :sender\"", "unless", "message", ".", "respond_to?", "(", ":sender", ")", "listeners", ".", "hear", "(", "message", ")", ".", "each", "do", "|", "match", "|", "event", "=", "Houston", "::", "Conversations", "::", "Event", ".", "new", "(", "match", ")", "if", "block_given?", "yield", "event", ",", "match", ".", "listener", "else", "match", ".", "listener", ".", "call_async", "event", "end", "# Invoke only one listener per message", "return", "true", "end", "false", "end" ]
Matches a message against all listeners and invokes the first listener that mathes
[ "Matches", "a", "message", "against", "all", "listeners", "and", "invokes", "the", "first", "listener", "that", "mathes" ]
b292c90c3a74c73e2a97e23e20fa640dc3e48c54
https://github.com/houston/houston-conversations/blob/b292c90c3a74c73e2a97e23e20fa640dc3e48c54/lib/houston/conversations.rb#L30-L48
7,224
robertwahler/mutagem
lib/mutagem/mutex.rb
Mutagem.Mutex.execute
def execute(&block) result = false raise ArgumentError, "missing block" unless block_given? begin open(lockfile, 'w') do |f| # exclusive non-blocking lock result = lock(f, File::LOCK_EX | File::LOCK_NB) do |f| yield end end ensure # clean up but only if we have a positive result meaning we wrote the lockfile FileUtils.rm(lockfile) if (result && File.exists?(lockfile)) end result end
ruby
def execute(&block) result = false raise ArgumentError, "missing block" unless block_given? begin open(lockfile, 'w') do |f| # exclusive non-blocking lock result = lock(f, File::LOCK_EX | File::LOCK_NB) do |f| yield end end ensure # clean up but only if we have a positive result meaning we wrote the lockfile FileUtils.rm(lockfile) if (result && File.exists?(lockfile)) end result end
[ "def", "execute", "(", "&", "block", ")", "result", "=", "false", "raise", "ArgumentError", ",", "\"missing block\"", "unless", "block_given?", "begin", "open", "(", "lockfile", ",", "'w'", ")", "do", "|", "f", "|", "# exclusive non-blocking lock", "result", "=", "lock", "(", "f", ",", "File", "::", "LOCK_EX", "|", "File", "::", "LOCK_NB", ")", "do", "|", "f", "|", "yield", "end", "end", "ensure", "# clean up but only if we have a positive result meaning we wrote the lockfile", "FileUtils", ".", "rm", "(", "lockfile", ")", "if", "(", "result", "&&", "File", ".", "exists?", "(", "lockfile", ")", ")", "end", "result", "end" ]
Creates a new Mutex @param [String] lockfile filename Protect a block @example require 'rubygems' require 'mutagem' mutex = Mutagem::Mutex.new("my_process_name.lck") mutex.execute do puts "this block is protected from recursion" end @param block the block of code to protect with the mutex @return [Boolean] 0 if lock sucessful, otherwise false
[ "Creates", "a", "new", "Mutex" ]
75ac2f7fd307f575d81114b32e1a3b09c526e01d
https://github.com/robertwahler/mutagem/blob/75ac2f7fd307f575d81114b32e1a3b09c526e01d/lib/mutagem/mutex.rb#L29-L46
7,225
webmonarch/movingsign_api
lib/movingsign_api/commands/command.rb
MovingsignApi.Command.to_bytes
def to_bytes # set defaults self.sender ||= :pc self.receiver ||= 1 bytes = [] bytes.concat [0x00] * 5 # start of command bytes.concat [0x01] # <SOH> bytes.concat self.sender.to_bytes # Sender Address bytes.concat self.receiver.to_bytes # Reciver Address bytes.concat [0x02] # <STX> bytes.concat string_to_ascii_bytes(command_code) # Command Code bytes.concat command_payload_bytes # command specific payload bytes.concat [0x03] # <ETX> bytes.concat generate_checksum_bytes(bytes[10..-1]) # Checksum bytes (4) bytes.concat [0x04] # <EOT> bytes end
ruby
def to_bytes # set defaults self.sender ||= :pc self.receiver ||= 1 bytes = [] bytes.concat [0x00] * 5 # start of command bytes.concat [0x01] # <SOH> bytes.concat self.sender.to_bytes # Sender Address bytes.concat self.receiver.to_bytes # Reciver Address bytes.concat [0x02] # <STX> bytes.concat string_to_ascii_bytes(command_code) # Command Code bytes.concat command_payload_bytes # command specific payload bytes.concat [0x03] # <ETX> bytes.concat generate_checksum_bytes(bytes[10..-1]) # Checksum bytes (4) bytes.concat [0x04] # <EOT> bytes end
[ "def", "to_bytes", "# set defaults", "self", ".", "sender", "||=", ":pc", "self", ".", "receiver", "||=", "1", "bytes", "=", "[", "]", "bytes", ".", "concat", "[", "0x00", "]", "*", "5", "# start of command", "bytes", ".", "concat", "[", "0x01", "]", "# <SOH>", "bytes", ".", "concat", "self", ".", "sender", ".", "to_bytes", "# Sender Address", "bytes", ".", "concat", "self", ".", "receiver", ".", "to_bytes", "# Reciver Address", "bytes", ".", "concat", "[", "0x02", "]", "# <STX>", "bytes", ".", "concat", "string_to_ascii_bytes", "(", "command_code", ")", "# Command Code", "bytes", ".", "concat", "command_payload_bytes", "# command specific payload", "bytes", ".", "concat", "[", "0x03", "]", "# <ETX>", "bytes", ".", "concat", "generate_checksum_bytes", "(", "bytes", "[", "10", "..", "-", "1", "]", ")", "# Checksum bytes (4)", "bytes", ".", "concat", "[", "0x04", "]", "# <EOT>", "bytes", "end" ]
Returns a byte array representing this command, appropriate for sending to the sign's serial port @return [Array<Byte>]
[ "Returns", "a", "byte", "array", "representing", "this", "command", "appropriate", "for", "sending", "to", "the", "sign", "s", "serial", "port" ]
11c820edcb5f3a367b341257dae4f6249ae6d0a3
https://github.com/webmonarch/movingsign_api/blob/11c820edcb5f3a367b341257dae4f6249ae6d0a3/lib/movingsign_api/commands/command.rb#L36-L55
7,226
trejkaz/futurocube
lib/futurocube/resource_file.rb
FuturoCube.ResourceFile.records
def records if !@records @io.seek(44, IO::SEEK_SET) records = [] header.record_count.times do records << ResourceRecord.read(@io) end @records = records end @records end
ruby
def records if !@records @io.seek(44, IO::SEEK_SET) records = [] header.record_count.times do records << ResourceRecord.read(@io) end @records = records end @records end
[ "def", "records", "if", "!", "@records", "@io", ".", "seek", "(", "44", ",", "IO", "::", "SEEK_SET", ")", "records", "=", "[", "]", "header", ".", "record_count", ".", "times", "do", "records", "<<", "ResourceRecord", ".", "read", "(", "@io", ")", "end", "@records", "=", "records", "end", "@records", "end" ]
Reads the list of records from the resource file.
[ "Reads", "the", "list", "of", "records", "from", "the", "resource", "file", "." ]
2000e3d9e301f27fd01a0f331045fae9d6cc1883
https://github.com/trejkaz/futurocube/blob/2000e3d9e301f27fd01a0f331045fae9d6cc1883/lib/futurocube/resource_file.rb#L42-L52
7,227
trejkaz/futurocube
lib/futurocube/resource_file.rb
FuturoCube.ResourceFile.data
def data(rec) @io.seek(rec.data_offset, IO::SEEK_SET) @io.read(rec.data_length) end
ruby
def data(rec) @io.seek(rec.data_offset, IO::SEEK_SET) @io.read(rec.data_length) end
[ "def", "data", "(", "rec", ")", "@io", ".", "seek", "(", "rec", ".", "data_offset", ",", "IO", "::", "SEEK_SET", ")", "@io", ".", "read", "(", "rec", ".", "data_length", ")", "end" ]
Reads the data for a given record. @param rec [ResourceRecord] the record to read the data for.
[ "Reads", "the", "data", "for", "a", "given", "record", "." ]
2000e3d9e301f27fd01a0f331045fae9d6cc1883
https://github.com/trejkaz/futurocube/blob/2000e3d9e301f27fd01a0f331045fae9d6cc1883/lib/futurocube/resource_file.rb#L57-L60
7,228
trejkaz/futurocube
lib/futurocube/resource_file.rb
FuturoCube.ResourceFile.compute_checksum
def compute_checksum(&block) crc = CRC.new # Have to read this first because it might change the seek position. file_size = header.file_size @io.seek(8, IO::SEEK_SET) pos = 8 length = 4096-8 buf = nil while true buf = @io.read(length, buf) break if !buf crc.update(buf) pos += buf.size block.call(pos) if block length = 4096 end crc.crc end
ruby
def compute_checksum(&block) crc = CRC.new # Have to read this first because it might change the seek position. file_size = header.file_size @io.seek(8, IO::SEEK_SET) pos = 8 length = 4096-8 buf = nil while true buf = @io.read(length, buf) break if !buf crc.update(buf) pos += buf.size block.call(pos) if block length = 4096 end crc.crc end
[ "def", "compute_checksum", "(", "&", "block", ")", "crc", "=", "CRC", ".", "new", "# Have to read this first because it might change the seek position.", "file_size", "=", "header", ".", "file_size", "@io", ".", "seek", "(", "8", ",", "IO", "::", "SEEK_SET", ")", "pos", "=", "8", "length", "=", "4096", "-", "8", "buf", "=", "nil", "while", "true", "buf", "=", "@io", ".", "read", "(", "length", ",", "buf", ")", "break", "if", "!", "buf", "crc", ".", "update", "(", "buf", ")", "pos", "+=", "buf", ".", "size", "block", ".", "call", "(", "pos", ")", "if", "block", "length", "=", "4096", "end", "crc", ".", "crc", "end" ]
Computes the checksum for the resource file. @yield [done] Provides feedback about the progress of the operation.
[ "Computes", "the", "checksum", "for", "the", "resource", "file", "." ]
2000e3d9e301f27fd01a0f331045fae9d6cc1883
https://github.com/trejkaz/futurocube/blob/2000e3d9e301f27fd01a0f331045fae9d6cc1883/lib/futurocube/resource_file.rb#L65-L82
7,229
Dahie/woro
lib/woro/task.rb
Woro.Task.build_task_template
def build_task_template b = binding ERB.new(Woro::TaskHelper.read_template_file).result(b) end
ruby
def build_task_template b = binding ERB.new(Woro::TaskHelper.read_template_file).result(b) end
[ "def", "build_task_template", "b", "=", "binding", "ERB", ".", "new", "(", "Woro", "::", "TaskHelper", ".", "read_template_file", ")", ".", "result", "(", "b", ")", "end" ]
Read template and inject new name @return [String] source code for new task
[ "Read", "template", "and", "inject", "new", "name" ]
796873cca145c61cd72c7363551e10d402f867c6
https://github.com/Dahie/woro/blob/796873cca145c61cd72c7363551e10d402f867c6/lib/woro/task.rb#L48-L51
7,230
barkerest/barkest_core
app/controllers/barkest_core/application_controller_base.rb
BarkestCore.ApplicationControllerBase.authorize!
def authorize!(*group_list) begin # an authenticated user must exist. unless logged_in? store_location raise_not_logged_in "You need to login to access '#{request.fullpath}'.", 'nobody is logged in' end # clean up the group list. group_list ||= [] group_list.delete false group_list.delete '' if group_list.include?(true) # group_list contains "true" so only a system admin may continue. unless system_admin? if show_denial_reason? flash[:info] = 'The requested path is only available to system administrators.' end raise_authorize_failure "Your are not authorized to access '#{request.fullpath}'.", 'requires system administrator' end log_authorize_success 'user is system admin' elsif group_list.blank? # group_list is empty or contained nothing but empty strings and boolean false. # everyone can continue. log_authorize_success 'only requires authenticated user' else # the group list contains one or more authorized groups. # we want them to all be uppercase strings. group_list = group_list.map{|v| v.to_s.upcase}.sort result = current_user.has_any_group?(*group_list) unless result message = group_list.join(', ') if show_denial_reason? flash[:info] = "The requested path requires one of these groups: #{message}" end raise_authorize_failure "You are not authorized to access '#{request.fullpath}'.", "requires one of: #{message}" end log_authorize_success "user has '#{result}' group" end rescue BarkestCore::AuthorizeFailure => err flash[:danger] = err.message redirect_to root_url and return false end true end
ruby
def authorize!(*group_list) begin # an authenticated user must exist. unless logged_in? store_location raise_not_logged_in "You need to login to access '#{request.fullpath}'.", 'nobody is logged in' end # clean up the group list. group_list ||= [] group_list.delete false group_list.delete '' if group_list.include?(true) # group_list contains "true" so only a system admin may continue. unless system_admin? if show_denial_reason? flash[:info] = 'The requested path is only available to system administrators.' end raise_authorize_failure "Your are not authorized to access '#{request.fullpath}'.", 'requires system administrator' end log_authorize_success 'user is system admin' elsif group_list.blank? # group_list is empty or contained nothing but empty strings and boolean false. # everyone can continue. log_authorize_success 'only requires authenticated user' else # the group list contains one or more authorized groups. # we want them to all be uppercase strings. group_list = group_list.map{|v| v.to_s.upcase}.sort result = current_user.has_any_group?(*group_list) unless result message = group_list.join(', ') if show_denial_reason? flash[:info] = "The requested path requires one of these groups: #{message}" end raise_authorize_failure "You are not authorized to access '#{request.fullpath}'.", "requires one of: #{message}" end log_authorize_success "user has '#{result}' group" end rescue BarkestCore::AuthorizeFailure => err flash[:danger] = err.message redirect_to root_url and return false end true end
[ "def", "authorize!", "(", "*", "group_list", ")", "begin", "# an authenticated user must exist.", "unless", "logged_in?", "store_location", "raise_not_logged_in", "\"You need to login to access '#{request.fullpath}'.\"", ",", "'nobody is logged in'", "end", "# clean up the group list.", "group_list", "||=", "[", "]", "group_list", ".", "delete", "false", "group_list", ".", "delete", "''", "if", "group_list", ".", "include?", "(", "true", ")", "# group_list contains \"true\" so only a system admin may continue.", "unless", "system_admin?", "if", "show_denial_reason?", "flash", "[", ":info", "]", "=", "'The requested path is only available to system administrators.'", "end", "raise_authorize_failure", "\"Your are not authorized to access '#{request.fullpath}'.\"", ",", "'requires system administrator'", "end", "log_authorize_success", "'user is system admin'", "elsif", "group_list", ".", "blank?", "# group_list is empty or contained nothing but empty strings and boolean false.", "# everyone can continue.", "log_authorize_success", "'only requires authenticated user'", "else", "# the group list contains one or more authorized groups.", "# we want them to all be uppercase strings.", "group_list", "=", "group_list", ".", "map", "{", "|", "v", "|", "v", ".", "to_s", ".", "upcase", "}", ".", "sort", "result", "=", "current_user", ".", "has_any_group?", "(", "group_list", ")", "unless", "result", "message", "=", "group_list", ".", "join", "(", "', '", ")", "if", "show_denial_reason?", "flash", "[", ":info", "]", "=", "\"The requested path requires one of these groups: #{message}\"", "end", "raise_authorize_failure", "\"You are not authorized to access '#{request.fullpath}'.\"", ",", "\"requires one of: #{message}\"", "end", "log_authorize_success", "\"user has '#{result}' group\"", "end", "rescue", "BarkestCore", "::", "AuthorizeFailure", "=>", "err", "flash", "[", ":danger", "]", "=", "err", ".", "message", "redirect_to", "root_url", "and", "return", "false", "end", "true", "end" ]
Authorize the current action. * If +group_list+ is not provided or only contains +false+ then any authenticated user will be authorized. * If +group_list+ contains +true+ then only system administrators will be authorized. * Otherwise the +group_list+ contains a list of accepted groups that will be authorized. Any user with one or more groups from the list will be granted access.
[ "Authorize", "the", "current", "action", "." ]
3eeb025ec870888cacbc9bae252a39ebf9295f61
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/app/controllers/barkest_core/application_controller_base.rb#L30-L83
7,231
flyingmachine/higml
lib/higml/applier.rb
Higml.Applier.selector_matches?
def selector_matches?(selector) selector.any? do |group| group.keys.all? do |key| input_has_key?(key) && (@input[key] == group[key] || group[key].nil?) end end end
ruby
def selector_matches?(selector) selector.any? do |group| group.keys.all? do |key| input_has_key?(key) && (@input[key] == group[key] || group[key].nil?) end end end
[ "def", "selector_matches?", "(", "selector", ")", "selector", ".", "any?", "do", "|", "group", "|", "group", ".", "keys", ".", "all?", "do", "|", "key", "|", "input_has_key?", "(", "key", ")", "&&", "(", "@input", "[", "key", "]", "==", "group", "[", "key", "]", "||", "group", "[", "key", "]", ".", "nil?", ")", "end", "end", "end" ]
REFACTOR to selector class
[ "REFACTOR", "to", "selector", "class" ]
0c83d236c8911fb8ce23fcd82b5691f9189f41ef
https://github.com/flyingmachine/higml/blob/0c83d236c8911fb8ce23fcd82b5691f9189f41ef/lib/higml/applier.rb#L43-L49
7,232
danlewis/encryptbot
lib/encryptbot/cert.rb
Encryptbot.Cert.ready_for_challenge
def ready_for_challenge(domain, dns_challenge) record = "#{dns_challenge.record_name}.#{domain}" challenge_value = dns_challenge.record_content txt_value = Resolv::DNS.open do |dns| records = dns.getresources(record, Resolv::DNS::Resource::IN::TXT); records.empty? ? nil : records.map(&:data).join(" ") end txt_value == challenge_value end
ruby
def ready_for_challenge(domain, dns_challenge) record = "#{dns_challenge.record_name}.#{domain}" challenge_value = dns_challenge.record_content txt_value = Resolv::DNS.open do |dns| records = dns.getresources(record, Resolv::DNS::Resource::IN::TXT); records.empty? ? nil : records.map(&:data).join(" ") end txt_value == challenge_value end
[ "def", "ready_for_challenge", "(", "domain", ",", "dns_challenge", ")", "record", "=", "\"#{dns_challenge.record_name}.#{domain}\"", "challenge_value", "=", "dns_challenge", ".", "record_content", "txt_value", "=", "Resolv", "::", "DNS", ".", "open", "do", "|", "dns", "|", "records", "=", "dns", ".", "getresources", "(", "record", ",", "Resolv", "::", "DNS", "::", "Resource", "::", "IN", "::", "TXT", ")", ";", "records", ".", "empty?", "?", "nil", ":", "records", ".", "map", "(", ":data", ")", ".", "join", "(", "\" \"", ")", "end", "txt_value", "==", "challenge_value", "end" ]
Check if TXT value has been set correctly
[ "Check", "if", "TXT", "value", "has", "been", "set", "correctly" ]
2badb7cfe3f7c3b416d7aa74bd3e339cc859edb2
https://github.com/danlewis/encryptbot/blob/2badb7cfe3f7c3b416d7aa74bd3e339cc859edb2/lib/encryptbot/cert.rb#L95-L103
7,233
kenjij/kajiki
lib/kajiki/handler.rb
Kajiki.Handler.check_existing_pid
def check_existing_pid return false unless pid_file_exists? pid = read_pid fail 'Existing process found.' if pid > 0 && pid_exists?(pid) delete_pid end
ruby
def check_existing_pid return false unless pid_file_exists? pid = read_pid fail 'Existing process found.' if pid > 0 && pid_exists?(pid) delete_pid end
[ "def", "check_existing_pid", "return", "false", "unless", "pid_file_exists?", "pid", "=", "read_pid", "fail", "'Existing process found.'", "if", "pid", ">", "0", "&&", "pid_exists?", "(", "pid", ")", "delete_pid", "end" ]
Check if process exists then fail, otherwise clean up. @return [Boolean] `false` if no PID file exists, `true` if it cleaned up.
[ "Check", "if", "process", "exists", "then", "fail", "otherwise", "clean", "up", "." ]
9b036f2741d515e9bfd158571a813987516d89ed
https://github.com/kenjij/kajiki/blob/9b036f2741d515e9bfd158571a813987516d89ed/lib/kajiki/handler.rb#L7-L12
7,234
kenjij/kajiki
lib/kajiki/handler.rb
Kajiki.Handler.trap_default_signals
def trap_default_signals Signal.trap('INT') do puts 'Interrupted. Terminating process...' exit end Signal.trap('HUP') do puts 'SIGHUP - Terminating process...' exit end Signal.trap('TERM') do puts 'SIGTERM - Terminating process...' exit end end
ruby
def trap_default_signals Signal.trap('INT') do puts 'Interrupted. Terminating process...' exit end Signal.trap('HUP') do puts 'SIGHUP - Terminating process...' exit end Signal.trap('TERM') do puts 'SIGTERM - Terminating process...' exit end end
[ "def", "trap_default_signals", "Signal", ".", "trap", "(", "'INT'", ")", "do", "puts", "'Interrupted. Terminating process...'", "exit", "end", "Signal", ".", "trap", "(", "'HUP'", ")", "do", "puts", "'SIGHUP - Terminating process...'", "exit", "end", "Signal", ".", "trap", "(", "'TERM'", ")", "do", "puts", "'SIGTERM - Terminating process...'", "exit", "end", "end" ]
Trap common signals as default.
[ "Trap", "common", "signals", "as", "default", "." ]
9b036f2741d515e9bfd158571a813987516d89ed
https://github.com/kenjij/kajiki/blob/9b036f2741d515e9bfd158571a813987516d89ed/lib/kajiki/handler.rb#L71-L84
7,235
cbetta/snapshotify
lib/snapshotify/document.rb
Snapshotify.Document.links
def links # Find all anchor elements doc.xpath('//a').map do |element| # extract all the href attributes element.attribute('href') end.compact.map(&:value).map do |href| # return them as new document objects Snapshotify::Document.new(href, url) end.compact end
ruby
def links # Find all anchor elements doc.xpath('//a').map do |element| # extract all the href attributes element.attribute('href') end.compact.map(&:value).map do |href| # return them as new document objects Snapshotify::Document.new(href, url) end.compact end
[ "def", "links", "# Find all anchor elements", "doc", ".", "xpath", "(", "'//a'", ")", ".", "map", "do", "|", "element", "|", "# extract all the href attributes", "element", ".", "attribute", "(", "'href'", ")", "end", ".", "compact", ".", "map", "(", ":value", ")", ".", "map", "do", "|", "href", "|", "# return them as new document objects", "Snapshotify", "::", "Document", ".", "new", "(", "href", ",", "url", ")", "end", ".", "compact", "end" ]
Initialize the document with a URL, and the parent page this URL was included on in case of assets Find the links in a page and extract all the hrefs
[ "Initialize", "the", "document", "with", "a", "URL", "and", "the", "parent", "page", "this", "URL", "was", "included", "on", "in", "case", "of", "assets", "Find", "the", "links", "in", "a", "page", "and", "extract", "all", "the", "hrefs" ]
7f5553f4281ffc5bf0e54da1141574bd15af45b6
https://github.com/cbetta/snapshotify/blob/7f5553f4281ffc5bf0e54da1141574bd15af45b6/lib/snapshotify/document.rb#L18-L27
7,236
cbetta/snapshotify
lib/snapshotify/document.rb
Snapshotify.Document.write!
def write! writer = Snapshotify::Writer.new(self) writer.emitter = emitter writer.write end
ruby
def write! writer = Snapshotify::Writer.new(self) writer.emitter = emitter writer.write end
[ "def", "write!", "writer", "=", "Snapshotify", "::", "Writer", ".", "new", "(", "self", ")", "writer", ".", "emitter", "=", "emitter", "writer", ".", "write", "end" ]
Write a document to file
[ "Write", "a", "document", "to", "file" ]
7f5553f4281ffc5bf0e54da1141574bd15af45b6
https://github.com/cbetta/snapshotify/blob/7f5553f4281ffc5bf0e54da1141574bd15af45b6/lib/snapshotify/document.rb#L35-L39
7,237
jgoizueta/sys_cmd
lib/sys_cmd.rb
SysCmd.Definition.option
def option(option, *args) options = args.pop if args.last.is_a?(Hash) options ||= {} raise "Invalid number of arguments (0 or 1 expected)" if args.size > 1 return unless @shell.applicable?(options) value = args.shift || options[:value] if options[:os_prefix] option = @shell.option_switch + option else option = option.dup end if @shell.requires_escaping?(option) option = @shell.escape_value(option) end option << ' ' << @shell.escape_value(value) if value option << @shell.escape_value(options[:join_value]) if options[:join_value] option << '=' << @shell.escape_value(options[:equal_value]) if options[:equal_value] if file = options[:file] file_sep = ' ' elsif file = options[:join_file] file_sep = '' elsif file = options[:equal_file] file_sep = '=' end if file option << file_sep << @shell.escape_filename(file) end @command << ' ' << option @last_arg = :option end
ruby
def option(option, *args) options = args.pop if args.last.is_a?(Hash) options ||= {} raise "Invalid number of arguments (0 or 1 expected)" if args.size > 1 return unless @shell.applicable?(options) value = args.shift || options[:value] if options[:os_prefix] option = @shell.option_switch + option else option = option.dup end if @shell.requires_escaping?(option) option = @shell.escape_value(option) end option << ' ' << @shell.escape_value(value) if value option << @shell.escape_value(options[:join_value]) if options[:join_value] option << '=' << @shell.escape_value(options[:equal_value]) if options[:equal_value] if file = options[:file] file_sep = ' ' elsif file = options[:join_file] file_sep = '' elsif file = options[:equal_file] file_sep = '=' end if file option << file_sep << @shell.escape_filename(file) end @command << ' ' << option @last_arg = :option end
[ "def", "option", "(", "option", ",", "*", "args", ")", "options", "=", "args", ".", "pop", "if", "args", ".", "last", ".", "is_a?", "(", "Hash", ")", "options", "||=", "{", "}", "raise", "\"Invalid number of arguments (0 or 1 expected)\"", "if", "args", ".", "size", ">", "1", "return", "unless", "@shell", ".", "applicable?", "(", "options", ")", "value", "=", "args", ".", "shift", "||", "options", "[", ":value", "]", "if", "options", "[", ":os_prefix", "]", "option", "=", "@shell", ".", "option_switch", "+", "option", "else", "option", "=", "option", ".", "dup", "end", "if", "@shell", ".", "requires_escaping?", "(", "option", ")", "option", "=", "@shell", ".", "escape_value", "(", "option", ")", "end", "option", "<<", "' '", "<<", "@shell", ".", "escape_value", "(", "value", ")", "if", "value", "option", "<<", "@shell", ".", "escape_value", "(", "options", "[", ":join_value", "]", ")", "if", "options", "[", ":join_value", "]", "option", "<<", "'='", "<<", "@shell", ".", "escape_value", "(", "options", "[", ":equal_value", "]", ")", "if", "options", "[", ":equal_value", "]", "if", "file", "=", "options", "[", ":file", "]", "file_sep", "=", "' '", "elsif", "file", "=", "options", "[", ":join_file", "]", "file_sep", "=", "''", "elsif", "file", "=", "options", "[", ":equal_file", "]", "file_sep", "=", "'='", "end", "if", "file", "option", "<<", "file_sep", "<<", "@shell", ".", "escape_filename", "(", "file", ")", "end", "@command", "<<", "' '", "<<", "option", "@last_arg", "=", ":option", "end" ]
Add an option to the command. option '-x' # flag-style option option '--y' # long option option '/z' # Windows-style option options 'abc' # unprefixed option If the option +:os_prefix+ is true then the default system option switch will be used. option 'x', os_prefix: true # will produce -x or /x A value can be given as an option and will be space-separated from the option name: option '-x', value: 123 # -x 123 To avoid spacing the value use the +:join_value+ option option '-x', join_value: 123 # -x123 And to use an equal sign as separator, use +:equal_value+ option '-x', equal_value: 123 # -x=123 If the option value is a file name, use the analogous +:file+, +:join_file+ or +:equal_file+ options: option '-i', file: 'path/filename' Several of this options can be given simoultaneusly: option '-d', join_value: 'x', equal_value: '1' # -dx=1
[ "Add", "an", "option", "to", "the", "command", "." ]
b7f0cb67502be7755679562f318c3aa66510ec63
https://github.com/jgoizueta/sys_cmd/blob/b7f0cb67502be7755679562f318c3aa66510ec63/lib/sys_cmd.rb#L70-L99
7,238
jgoizueta/sys_cmd
lib/sys_cmd.rb
SysCmd.Definition.os_option
def os_option(option, *args) options = args.pop if args.last.is_a?(Hash) options ||= {} args.push options.merge(os_prefix: true) option option, *args end
ruby
def os_option(option, *args) options = args.pop if args.last.is_a?(Hash) options ||= {} args.push options.merge(os_prefix: true) option option, *args end
[ "def", "os_option", "(", "option", ",", "*", "args", ")", "options", "=", "args", ".", "pop", "if", "args", ".", "last", ".", "is_a?", "(", "Hash", ")", "options", "||=", "{", "}", "args", ".", "push", "options", ".", "merge", "(", "os_prefix", ":", "true", ")", "option", "option", ",", "args", "end" ]
An +os_option+ has automatically a OS-dependent prefix
[ "An", "+", "os_option", "+", "has", "automatically", "a", "OS", "-", "dependent", "prefix" ]
b7f0cb67502be7755679562f318c3aa66510ec63
https://github.com/jgoizueta/sys_cmd/blob/b7f0cb67502be7755679562f318c3aa66510ec63/lib/sys_cmd.rb#L102-L107
7,239
jgoizueta/sys_cmd
lib/sys_cmd.rb
SysCmd.Definition.argument
def argument(value, options = {}) return unless @shell.applicable?(options) value = value.to_s if @shell.requires_escaping?(value) value = @shell.escape_value(value) end @command << ' ' << value @last_arg = :argument end
ruby
def argument(value, options = {}) return unless @shell.applicable?(options) value = value.to_s if @shell.requires_escaping?(value) value = @shell.escape_value(value) end @command << ' ' << value @last_arg = :argument end
[ "def", "argument", "(", "value", ",", "options", "=", "{", "}", ")", "return", "unless", "@shell", ".", "applicable?", "(", "options", ")", "value", "=", "value", ".", "to_s", "if", "@shell", ".", "requires_escaping?", "(", "value", ")", "value", "=", "@shell", ".", "escape_value", "(", "value", ")", "end", "@command", "<<", "' '", "<<", "value", "@last_arg", "=", ":argument", "end" ]
Add an unquoted argument to the command. This is not useful for commands executed directly, since the arguments are note interpreted by a shell in that case.
[ "Add", "an", "unquoted", "argument", "to", "the", "command", ".", "This", "is", "not", "useful", "for", "commands", "executed", "directly", "since", "the", "arguments", "are", "note", "interpreted", "by", "a", "shell", "in", "that", "case", "." ]
b7f0cb67502be7755679562f318c3aa66510ec63
https://github.com/jgoizueta/sys_cmd/blob/b7f0cb67502be7755679562f318c3aa66510ec63/lib/sys_cmd.rb#L185-L193
7,240
jgoizueta/sys_cmd
lib/sys_cmd.rb
SysCmd.Command.run
def run(options = {}) @output = @status = @error_output = @error = nil if options[:direct] command = @shell.split(@command) else command = [@command] end stdin_data = options[:stdin_data] || @input if stdin_data command << { stdin_data: stdin_data } end begin case options[:error_output] when :mix # mix stderr with stdout @output, @status = Open3.capture2e(*command) when :separate @output, @error_output, @status = Open3.capture3(*command) else # :console (do not capture stderr output) @output, @status = Open3.capture2(*command) end rescue => error @error = error.dup end case options[:return] when :status @status when :status_value status_value when :output @output when :error_output @error_output when :command self else @error ? nil : @status.success? ? true : false end end
ruby
def run(options = {}) @output = @status = @error_output = @error = nil if options[:direct] command = @shell.split(@command) else command = [@command] end stdin_data = options[:stdin_data] || @input if stdin_data command << { stdin_data: stdin_data } end begin case options[:error_output] when :mix # mix stderr with stdout @output, @status = Open3.capture2e(*command) when :separate @output, @error_output, @status = Open3.capture3(*command) else # :console (do not capture stderr output) @output, @status = Open3.capture2(*command) end rescue => error @error = error.dup end case options[:return] when :status @status when :status_value status_value when :output @output when :error_output @error_output when :command self else @error ? nil : @status.success? ? true : false end end
[ "def", "run", "(", "options", "=", "{", "}", ")", "@output", "=", "@status", "=", "@error_output", "=", "@error", "=", "nil", "if", "options", "[", ":direct", "]", "command", "=", "@shell", ".", "split", "(", "@command", ")", "else", "command", "=", "[", "@command", "]", "end", "stdin_data", "=", "options", "[", ":stdin_data", "]", "||", "@input", "if", "stdin_data", "command", "<<", "{", "stdin_data", ":", "stdin_data", "}", "end", "begin", "case", "options", "[", ":error_output", "]", "when", ":mix", "# mix stderr with stdout", "@output", ",", "@status", "=", "Open3", ".", "capture2e", "(", "command", ")", "when", ":separate", "@output", ",", "@error_output", ",", "@status", "=", "Open3", ".", "capture3", "(", "command", ")", "else", "# :console (do not capture stderr output)", "@output", ",", "@status", "=", "Open3", ".", "capture2", "(", "command", ")", "end", "rescue", "=>", "error", "@error", "=", "error", ".", "dup", "end", "case", "options", "[", ":return", "]", "when", ":status", "@status", "when", ":status_value", "status_value", "when", ":output", "@output", "when", ":error_output", "@error_output", "when", ":command", "self", "else", "@error", "?", "nil", ":", "@status", ".", "success?", "?", "true", ":", "false", "end", "end" ]
Execute the command. By default the command is executed by a shell. In this case, unquoted arguments are interpreted by the shell, e.g. SysCmd.command('echo $BASH').run # /bin/bash When the +:direct+ option is set to true, no shell is used and the command is directly executed; in this case unquoted arguments are not interpreted: SysCmd.command('echo $BASH').run # $BASH The exit status of the command is retained in the +status+ attribute (and its numeric value in the +status_value+ attribute). The standard output of the command is captured and retained in the +output+ attribute. By default, the standar error output of the command is not captured, so it will be shown on the console unless redirected. Standard error can be captured and interleaved with the standard output passing the option error_output: :mix Error output can be captured and keep separate inthe +error_output+ attribute with this option: error_output: :separate The value returned is by defaut, like in Kernel#system, true if the command gives zero exit status, false for non zero exit status, and nil if command execution fails. The +:return+ option can be used to make this method return other attribute of the executed command. The +:stdin_data+ option can be used to pass a String as the command's standar input.
[ "Execute", "the", "command", "." ]
b7f0cb67502be7755679562f318c3aa66510ec63
https://github.com/jgoizueta/sys_cmd/blob/b7f0cb67502be7755679562f318c3aa66510ec63/lib/sys_cmd.rb#L267-L304
7,241
gera-gas/iparser
lib/iparser/machine.rb
Iparser.Machine.interactive_parser
def interactive_parser ( ) puts 'Press <Enter> to exit...' # Цикл обработки ввода. loop do str = interactive_input( ) break if str == "" # Цикл посимвольной классификаци. str.bytes.each do |c| parse( c.chr ) puts 'parser: ' + @parserstate puts 'symbol: ' + interactive_output( c.chr ).to_s puts 'state: ' + @chain.last.statename puts end end end
ruby
def interactive_parser ( ) puts 'Press <Enter> to exit...' # Цикл обработки ввода. loop do str = interactive_input( ) break if str == "" # Цикл посимвольной классификаци. str.bytes.each do |c| parse( c.chr ) puts 'parser: ' + @parserstate puts 'symbol: ' + interactive_output( c.chr ).to_s puts 'state: ' + @chain.last.statename puts end end end
[ "def", "interactive_parser", "(", ")", "puts", "'Press <Enter> to exit...'", "# Цикл обработки ввода.", "loop", "do", "str", "=", "interactive_input", "(", ")", "break", "if", "str", "==", "\"\"", "# Цикл посимвольной классификаци.", "str", ".", "bytes", ".", "each", "do", "|", "c", "|", "parse", "(", "c", ".", "chr", ")", "puts", "'parser: '", "+", "@parserstate", "puts", "'symbol: '", "+", "interactive_output", "(", "c", ".", "chr", ")", ".", "to_s", "puts", "'state: '", "+", "@chain", ".", "last", ".", "statename", "puts", "end", "end", "end" ]
Run parser machine for check in interactive mode.
[ "Run", "parser", "machine", "for", "check", "in", "interactive", "mode", "." ]
bef722594541a406d361c6ff6dac8c15a7aa6d2a
https://github.com/gera-gas/iparser/blob/bef722594541a406d361c6ff6dac8c15a7aa6d2a/lib/iparser/machine.rb#L144-L161
7,242
MBO/attrtastic
lib/attrtastic/semantic_attributes_builder.rb
Attrtastic.SemanticAttributesBuilder.attributes
def attributes(*args, &block) options = args.extract_options! options[:html] ||= {} if args.first and args.first.is_a? String options[:name] = args.shift end if options[:for].blank? attributes_for(record, args, options, &block) else for_value = if options[:for].is_a? Symbol record.send(options[:for]) else options[:for] end [*for_value].map do |value| value_options = options.clone value_options[:html][:class] = [ options[:html][:class], value.class.to_s.underscore ].compact.join(" ") attributes_for(value, args, options, &block) end.join.html_safe end end
ruby
def attributes(*args, &block) options = args.extract_options! options[:html] ||= {} if args.first and args.first.is_a? String options[:name] = args.shift end if options[:for].blank? attributes_for(record, args, options, &block) else for_value = if options[:for].is_a? Symbol record.send(options[:for]) else options[:for] end [*for_value].map do |value| value_options = options.clone value_options[:html][:class] = [ options[:html][:class], value.class.to_s.underscore ].compact.join(" ") attributes_for(value, args, options, &block) end.join.html_safe end end
[ "def", "attributes", "(", "*", "args", ",", "&", "block", ")", "options", "=", "args", ".", "extract_options!", "options", "[", ":html", "]", "||=", "{", "}", "if", "args", ".", "first", "and", "args", ".", "first", ".", "is_a?", "String", "options", "[", ":name", "]", "=", "args", ".", "shift", "end", "if", "options", "[", ":for", "]", ".", "blank?", "attributes_for", "(", "record", ",", "args", ",", "options", ",", "block", ")", "else", "for_value", "=", "if", "options", "[", ":for", "]", ".", "is_a?", "Symbol", "record", ".", "send", "(", "options", "[", ":for", "]", ")", "else", "options", "[", ":for", "]", "end", "[", "for_value", "]", ".", "map", "do", "|", "value", "|", "value_options", "=", "options", ".", "clone", "value_options", "[", ":html", "]", "[", ":class", "]", "=", "[", "options", "[", ":html", "]", "[", ":class", "]", ",", "value", ".", "class", ".", "to_s", ".", "underscore", "]", ".", "compact", ".", "join", "(", "\" \"", ")", "attributes_for", "(", "value", ",", "args", ",", "options", ",", "block", ")", "end", ".", "join", ".", "html_safe", "end", "end" ]
Creates block of attributes with optional header. Attributes are surrounded with ordered list. @overload attributes(options = {}, &block) Creates attributes list without header, yields block to include each attribute @param [Hash] options Options for formating attributes block @option options [String] :name (nil) Optional header of attributes section @option options [String] :class ('') Name of html class to add to attributes block @option options [String] :header_class ('') Name of html class to add to header @yield Block which can call #attribute to include attribute value @example <%= attr.attributes do %> <%= attr.attribute :name %> <%= attr.attribute :email %> <% end %> @example <%= attr.attributes :name => "User" do %> <%= attr.attribute :name %> <%= attr.attribute :email %> <% end %> @example <%= attr.attributes :for => :user do |user| %> <%= user.attribute :name %> <%= user.attribute :email %> <%= user.attribute :profile do %> <%= link_to h(user.record.name), user_path(user.record) %> <% end %> <% end %> @example <%= attr.attributes :for => @user do |user| %> <%= user.attribute :name %> <%= user.attribute :email %> <%= user.attribute :profile do %> <%= link_to h(@user.name), user_path(@user) %> <% end %> <% end %> @example <%= attr.attributes :for => :posts do |post| %> <%= post.attribute :author %> <%= post.attribute :title %> <% end %> @example <%= attr.attributes :for => @posts do |post| %> <%= post.attribute :author %> <%= post.attribute :title %> <% end %> @example <%= attr.attributes :for => @posts do |post| %> <%= post.attribute :birthday, :format => false %> <% end %> @example <%= attr.attributes :for => @posts do |post| %> <%= post.attribute :birthday, :format => :my_fancy_birthday_formatter %> <% end %> @overload attributes(header, options = {}, &block) Creates attributes list with header and yields block to include each attribute @param [String] header Header of attributes section @param [Hash] options Options for formating attributes block @option options [String] :class ('') Name of html class to add to attributes block @option options [String] :header_class ('') Name of html class to add to header @option optinos [Symbol,Object] :for Optional new record for new builder passed as argument block. This new record can be symbol of method name for actual record, or any other object which is passed as new record for builder. @yield Block which can call #attribute to include attribute value @yieldparam builder Builder instance holding actual record (retivable via #record) @example <%= attr.attributes "User info" do %> <%= attr.attribute :name" %> <%= attr.attribute :email %> <% end %> @example <%= attr.attributes "User", :for => :user do |user| %> <%= user.attribute :name %> <%= user.attribute :email %> <%= user.attribute :profile do %> <%= link_to h(user.record.name), user_path(user.record) %> <% end %> <% end %> @example <% attr.attributes "User", :for => @user do |user| %> <%= user.attribute :name %> <%= user.attribute :email %> <%= user.attribute :profile do %> <%= link_to h(@user.name), user_path(@user) %> <% end %> <% end %> @example <%= attr.attributes "Post", :for => :posts do |post| %> <%= post.attribute :author %> <%= post.attribute :title %> <% end %> @example <%= attr.attributes "Post", :for => @posts do |post| %> <%= post.attribute :author %> <%= post.attribute :title %> <% end %> @overload attributes(*symbols, options = {}) Creates attributes list without header, attributes are given as list of symbols (record properties) @param [Symbol, ...] symbols List of attributes @param [Hash] options Options for formating attributes block @option options [String] :name (nil) Optional header of attributes section @option options [String] :class ('') Name of html class to add to attributes block @option options [String] :header_class ('') Name of html class to add to header @example <%= attr.attributes :name, :email %> @example <%= attr.attributes :name, :email, :for => :author %> @example <%= attr.attributes :name, :email, :for => @user %> @example <%= attr.attributes :title, :for => :posts %> @example <%= attr.attributes :title, :for => @posts %> @overload attributes(header, *symbols, options = {}) Creates attributes list with header, attributes are given as list of symbols (record properties) @param [String] header Header of attributes section @param [Symbol, ...] symbols Optional list of attributes @param [Hash] options Options for formating attributes block @option options [String] :class ('') Name of html class to add to attributes block @option options [String] :header_class ('') Name of html class to add to header @example <%= attr.attributes "User info" :name, :email %> @example <%= attr.attributes "Author", :name, :email, :for => :author %> @example <%= attr.attributes "Author", :name, :email, :for => @user %> @example <%= attr.attributes "Post", :title, :for => :posts %> @example <%= attr.attributes "Post", :title, :for => @posts %> @example All together <%= attr.attributes "User info", :name, :email, :class => "user_info", :header_class => "header important" %> @example With block <%= attr.attributes "User info" :class => "user_info", :header_class => "header important" do %> <%= attr.attribute :name %> <%= attr.attribute :email %> <% end %> @see #attribute
[ "Creates", "block", "of", "attributes", "with", "optional", "header", ".", "Attributes", "are", "surrounded", "with", "ordered", "list", "." ]
c024a1c42b665eed590004236e2d067d1ca59a4e
https://github.com/MBO/attrtastic/blob/c024a1c42b665eed590004236e2d067d1ca59a4e/lib/attrtastic/semantic_attributes_builder.rb#L187-L212
7,243
MBO/attrtastic
lib/attrtastic/semantic_attributes_builder.rb
Attrtastic.SemanticAttributesBuilder.attribute
def attribute(*args, &block) options = args.extract_options! options.reverse_merge!(Attrtastic.default_options) options[:html] ||= {} method = args.shift html_label_class = [ "label", options[:html][:label_class] ].compact.join(" ") html_value_class = [ "value", options[:html][:value_class] ].compact.join(" ") html_class = [ "attribute", options[:html][:class] ].compact.join(" ") label = options.key?(:label) ? options[:label] : label_for_attribute(method) if block_given? output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.tag(:span, {:class => html_value_class}, true) output << template.capture(&block) output.safe_concat("</span>") output.safe_concat("</li>") else value = if options.key?(:value) case options[:value] when Symbol attribute_value = value_of_attribute(method) case attribute_value when Hash attribute_value[options[:value]] else attribute_value.send(options[:value]) end else options[:value] end else value_of_attribute(method) end value = case options[:format] when false value when nil format_attribute_value(value) else format_attribute_value(value, options[:format]) end if value.present? || options[:display_empty] output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.content_tag(:span, value, :class => html_value_class) output.safe_concat("</li>") end end end
ruby
def attribute(*args, &block) options = args.extract_options! options.reverse_merge!(Attrtastic.default_options) options[:html] ||= {} method = args.shift html_label_class = [ "label", options[:html][:label_class] ].compact.join(" ") html_value_class = [ "value", options[:html][:value_class] ].compact.join(" ") html_class = [ "attribute", options[:html][:class] ].compact.join(" ") label = options.key?(:label) ? options[:label] : label_for_attribute(method) if block_given? output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.tag(:span, {:class => html_value_class}, true) output << template.capture(&block) output.safe_concat("</span>") output.safe_concat("</li>") else value = if options.key?(:value) case options[:value] when Symbol attribute_value = value_of_attribute(method) case attribute_value when Hash attribute_value[options[:value]] else attribute_value.send(options[:value]) end else options[:value] end else value_of_attribute(method) end value = case options[:format] when false value when nil format_attribute_value(value) else format_attribute_value(value, options[:format]) end if value.present? || options[:display_empty] output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.content_tag(:span, value, :class => html_value_class) output.safe_concat("</li>") end end end
[ "def", "attribute", "(", "*", "args", ",", "&", "block", ")", "options", "=", "args", ".", "extract_options!", "options", ".", "reverse_merge!", "(", "Attrtastic", ".", "default_options", ")", "options", "[", ":html", "]", "||=", "{", "}", "method", "=", "args", ".", "shift", "html_label_class", "=", "[", "\"label\"", ",", "options", "[", ":html", "]", "[", ":label_class", "]", "]", ".", "compact", ".", "join", "(", "\" \"", ")", "html_value_class", "=", "[", "\"value\"", ",", "options", "[", ":html", "]", "[", ":value_class", "]", "]", ".", "compact", ".", "join", "(", "\" \"", ")", "html_class", "=", "[", "\"attribute\"", ",", "options", "[", ":html", "]", "[", ":class", "]", "]", ".", "compact", ".", "join", "(", "\" \"", ")", "label", "=", "options", ".", "key?", "(", ":label", ")", "?", "options", "[", ":label", "]", ":", "label_for_attribute", "(", "method", ")", "if", "block_given?", "output", "=", "template", ".", "tag", "(", ":li", ",", "{", ":class", "=>", "html_class", "}", ",", "true", ")", "output", "<<", "template", ".", "content_tag", "(", ":span", ",", "label", ",", ":class", "=>", "html_label_class", ")", "output", "<<", "template", ".", "tag", "(", ":span", ",", "{", ":class", "=>", "html_value_class", "}", ",", "true", ")", "output", "<<", "template", ".", "capture", "(", "block", ")", "output", ".", "safe_concat", "(", "\"</span>\"", ")", "output", ".", "safe_concat", "(", "\"</li>\"", ")", "else", "value", "=", "if", "options", ".", "key?", "(", ":value", ")", "case", "options", "[", ":value", "]", "when", "Symbol", "attribute_value", "=", "value_of_attribute", "(", "method", ")", "case", "attribute_value", "when", "Hash", "attribute_value", "[", "options", "[", ":value", "]", "]", "else", "attribute_value", ".", "send", "(", "options", "[", ":value", "]", ")", "end", "else", "options", "[", ":value", "]", "end", "else", "value_of_attribute", "(", "method", ")", "end", "value", "=", "case", "options", "[", ":format", "]", "when", "false", "value", "when", "nil", "format_attribute_value", "(", "value", ")", "else", "format_attribute_value", "(", "value", ",", "options", "[", ":format", "]", ")", "end", "if", "value", ".", "present?", "||", "options", "[", ":display_empty", "]", "output", "=", "template", ".", "tag", "(", ":li", ",", "{", ":class", "=>", "html_class", "}", ",", "true", ")", "output", "<<", "template", ".", "content_tag", "(", ":span", ",", "label", ",", ":class", "=>", "html_label_class", ")", "output", "<<", "template", ".", "content_tag", "(", ":span", ",", "value", ",", ":class", "=>", "html_value_class", ")", "output", ".", "safe_concat", "(", "\"</li>\"", ")", "end", "end", "end" ]
Creates list entry for single record attribute @overload attribute(method, options = {}) Creates entry for record attribute @param [Symbol] method Attribute name of given record @param [Hash] options Options @option options [Hash] :html ({}) Hash with optional :class, :label_class and :value_class names of class for html @option options [String] :label Label for attribute entry, overrides default label name from symbol @option options [Symbol,Object] :value If it's Symbol, then it's used as either name of hash key to use on attribute (if it's hash) or method name to call on attribute. Otherwise it's used as value to use instead of actual attribute's. @option options [Boolean] :display_empty (false) Indicates if print value of given attribute even if it is blank? @option options [Symbol,false,nil] :format (nil) Type of formatter to use to display attribute's value. If it's false, then don't format at all (just call #to_s). If it's nil, then use default formatting (#l for dates, #number_with_precision/#number_with_delimiter for floats/integers). If it's Symbol, then use it to select view helper method and pass aattribute's value to it to format. @example <%= attr.attribute :name %> @example <%= attr.attribute :name, :label => "Full user name" %> @example <%= attr.attribute :name, :value => @user.full_name %> @example <%= attr.attribute :address, :value => :street %> @example <%= attr.attribute :avatar, :value => :url, :format => :image_tag %> @overload attribute(method, options = {}, &block) Creates entry for attribute given with block @param [Symbol] method Attribute name of given record @param [Hash] options Options @option options [Hash] :html ({}) Hash with optional :class, :label_class and :value_class names of classes for html @option options [String] :label Label for attribute entry, overrides default label name from symbol @yield Block which is executed in place of value for attribute @example <%= attr.attribute :name do %> <%= link_to @user.full_name, user_path(@user) %> @overload attribute(options = {}, &block) Creates entry for attribute with given block, options[:label] is mandatory in this case. @param [:Hash] options Options @option options [Hash] :html ({}) Hash with optional :class, :label_class and :value_class names of classes for html @option options [String] :label Mandatory label for attribute entry @yield Block which is executed in place of value for attribute @example <%= attr.attribute :label => "User link" do %> <%= link_to @user.full_name, user_path(@user) %> @example <%= attr.attribute :name, :display_empty => true %> @example <%= attr.attribute :label => "User link" do %> <%= link_to @user.full_name, user_path(@user) %> Options can be set globally with Attrtastic.default_options
[ "Creates", "list", "entry", "for", "single", "record", "attribute" ]
c024a1c42b665eed590004236e2d067d1ca59a4e
https://github.com/MBO/attrtastic/blob/c024a1c42b665eed590004236e2d067d1ca59a4e/lib/attrtastic/semantic_attributes_builder.rb#L281-L335
7,244
slate-studio/mongosteen
lib/mongosteen/base_helpers.rb
Mongosteen.BaseHelpers.collection
def collection get_collection_ivar || begin chain = end_of_association_chain # scopes chain = apply_scopes(chain) # search if params[:search] chain = chain.search(params[:search].to_s.downcase, match: :all) end # pagination if params[:page] per_page = params[:perPage] || 20 chain = chain.page(params[:page]).per(per_page) else chain = chain.all end set_collection_ivar(chain) end end
ruby
def collection get_collection_ivar || begin chain = end_of_association_chain # scopes chain = apply_scopes(chain) # search if params[:search] chain = chain.search(params[:search].to_s.downcase, match: :all) end # pagination if params[:page] per_page = params[:perPage] || 20 chain = chain.page(params[:page]).per(per_page) else chain = chain.all end set_collection_ivar(chain) end end
[ "def", "collection", "get_collection_ivar", "||", "begin", "chain", "=", "end_of_association_chain", "# scopes", "chain", "=", "apply_scopes", "(", "chain", ")", "# search", "if", "params", "[", ":search", "]", "chain", "=", "chain", ".", "search", "(", "params", "[", ":search", "]", ".", "to_s", ".", "downcase", ",", "match", ":", ":all", ")", "end", "# pagination", "if", "params", "[", ":page", "]", "per_page", "=", "params", "[", ":perPage", "]", "||", "20", "chain", "=", "chain", ".", "page", "(", "params", "[", ":page", "]", ")", ".", "per", "(", "per_page", ")", "else", "chain", "=", "chain", ".", "all", "end", "set_collection_ivar", "(", "chain", ")", "end", "end" ]
add support for scopes, search and pagination
[ "add", "support", "for", "scopes", "search", "and", "pagination" ]
f9745fcef269a1eb501b3d0d69b75cfc432d135d
https://github.com/slate-studio/mongosteen/blob/f9745fcef269a1eb501b3d0d69b75cfc432d135d/lib/mongosteen/base_helpers.rb#L7-L29
7,245
slate-studio/mongosteen
lib/mongosteen/base_helpers.rb
Mongosteen.BaseHelpers.get_resource_version
def get_resource_version resource = get_resource_ivar version = params[:version].try(:to_i) if version && version > 0 && version < resource.version resource.undo(nil, from: version + 1, to: resource.version) resource.version = version end return resource end
ruby
def get_resource_version resource = get_resource_ivar version = params[:version].try(:to_i) if version && version > 0 && version < resource.version resource.undo(nil, from: version + 1, to: resource.version) resource.version = version end return resource end
[ "def", "get_resource_version", "resource", "=", "get_resource_ivar", "version", "=", "params", "[", ":version", "]", ".", "try", "(", ":to_i", ")", "if", "version", "&&", "version", ">", "0", "&&", "version", "<", "resource", ".", "version", "resource", ".", "undo", "(", "nil", ",", "from", ":", "version", "+", "1", ",", "to", ":", "resource", ".", "version", ")", "resource", ".", "version", "=", "version", "end", "return", "resource", "end" ]
add support for history
[ "add", "support", "for", "history" ]
f9745fcef269a1eb501b3d0d69b75cfc432d135d
https://github.com/slate-studio/mongosteen/blob/f9745fcef269a1eb501b3d0d69b75cfc432d135d/lib/mongosteen/base_helpers.rb#L32-L43
7,246
notCalle/ruby-keytree
lib/key_tree/path.rb
KeyTree.Path.-
def -(other) other = other.to_key_path raise KeyError unless prefix?(other) super(other.length) end
ruby
def -(other) other = other.to_key_path raise KeyError unless prefix?(other) super(other.length) end
[ "def", "-", "(", "other", ")", "other", "=", "other", ".", "to_key_path", "raise", "KeyError", "unless", "prefix?", "(", "other", ")", "super", "(", "other", ".", "length", ")", "end" ]
Returns a key path without the leading +prefix+ :call-seq: Path - other => Path
[ "Returns", "a", "key", "path", "without", "the", "leading", "+", "prefix", "+" ]
1a88c902c8b5d14f21fd350338776fc094eae8e3
https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/path.rb#L68-L73
7,247
notCalle/ruby-keytree
lib/key_tree/path.rb
KeyTree.Path.prefix?
def prefix?(other) other = other.to_key_path return false if other.length > length key_enum = each other.all? { |other_key| key_enum.next == other_key } end
ruby
def prefix?(other) other = other.to_key_path return false if other.length > length key_enum = each other.all? { |other_key| key_enum.next == other_key } end
[ "def", "prefix?", "(", "other", ")", "other", "=", "other", ".", "to_key_path", "return", "false", "if", "other", ".", "length", ">", "length", "key_enum", "=", "each", "other", ".", "all?", "{", "|", "other_key", "|", "key_enum", ".", "next", "==", "other_key", "}", "end" ]
Is +other+ a prefix? :call-seq: prefix?(other) => boolean
[ "Is", "+", "other", "+", "a", "prefix?" ]
1a88c902c8b5d14f21fd350338776fc094eae8e3
https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/path.rb#L79-L85
7,248
gemeraldbeanstalk/stalk_climber
lib/stalk_climber/climber.rb
StalkClimber.Climber.max_job_ids
def max_job_ids connection_pairs = connection_pool.connections.map do |connection| [connection, connection.max_job_id] end return Hash[connection_pairs] end
ruby
def max_job_ids connection_pairs = connection_pool.connections.map do |connection| [connection, connection.max_job_id] end return Hash[connection_pairs] end
[ "def", "max_job_ids", "connection_pairs", "=", "connection_pool", ".", "connections", ".", "map", "do", "|", "connection", "|", "[", "connection", ",", "connection", ".", "max_job_id", "]", "end", "return", "Hash", "[", "connection_pairs", "]", "end" ]
Creates a new Climber instance, optionally yielding the instance for configuration if a block is given Climber.new('beanstalk://localhost:11300', 'stalk_climber') #=> #<StalkClimber::Job beanstalk_addresses="beanstalk://localhost:11300" test_tube="stalk_climber"> :call-seq: max_job_ids() => Hash{Beaneater::Connection => Integer} Returns a Hash with connections as keys and max_job_ids as values climber = Climber.new('beanstalk://localhost:11300', 'stalk_climber') climber.max_job_ids #=> {#<Beaneater::Connection host="localhost" port=11300>=>1183}
[ "Creates", "a", "new", "Climber", "instance", "optionally", "yielding", "the", "instance", "for", "configuration", "if", "a", "block", "is", "given" ]
d22f74bbae864ca2771d15621ccbf29d8e86521a
https://github.com/gemeraldbeanstalk/stalk_climber/blob/d22f74bbae864ca2771d15621ccbf29d8e86521a/lib/stalk_climber/climber.rb#L52-L57
7,249
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.task
def task(name, options = {}) options[:is] = options[:is].is_a?(Array) ? options[:is] : [options[:is]].compact @tasks[name] = Task.new(name,options) end
ruby
def task(name, options = {}) options[:is] = options[:is].is_a?(Array) ? options[:is] : [options[:is]].compact @tasks[name] = Task.new(name,options) end
[ "def", "task", "(", "name", ",", "options", "=", "{", "}", ")", "options", "[", ":is", "]", "=", "options", "[", ":is", "]", ".", "is_a?", "(", "Array", ")", "?", "options", "[", ":is", "]", ":", "[", "options", "[", ":is", "]", "]", ".", "compact", "@tasks", "[", "name", "]", "=", "Task", ".", "new", "(", "name", ",", "options", ")", "end" ]
Define a new task. @example Define an entirely new task task :push @example Define a publish task task :publish, :is => :update, :if => only_changed(:published) @example Define a joined manage task task :manage, :is => [:update, :create, :delete] @see #can More examples for the :if option @see DEFAULT_TASKS Default tasks @param [Symbol] name The name of the task. @param [Hash] options @option options [Symbol, Array<Symbol>] :is Optional parent tasks. The options of the parents will be inherited. @option options [String, Hash, Array<String,Hash>] :if The conditions for this task.
[ "Define", "a", "new", "task", "." ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L105-L108
7,250
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.add_permission
def add_permission(target, *args) raise '#can and #can_not have to be used inside a role block' unless @role options = args.last.is_a?(Hash) ? args.pop : {} tasks = [] models = [] models << args.pop if args.last == :any args.each {|arg| arg.is_a?(Symbol) ? tasks << arg : models << arg} tasks.each do |task| models.each do |model| if permission = target[task][model][@role] permission.load_options(options) else target[task][model][@role] = Permission.new(@role, task, model, options) end end end end
ruby
def add_permission(target, *args) raise '#can and #can_not have to be used inside a role block' unless @role options = args.last.is_a?(Hash) ? args.pop : {} tasks = [] models = [] models << args.pop if args.last == :any args.each {|arg| arg.is_a?(Symbol) ? tasks << arg : models << arg} tasks.each do |task| models.each do |model| if permission = target[task][model][@role] permission.load_options(options) else target[task][model][@role] = Permission.new(@role, task, model, options) end end end end
[ "def", "add_permission", "(", "target", ",", "*", "args", ")", "raise", "'#can and #can_not have to be used inside a role block'", "unless", "@role", "options", "=", "args", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "args", ".", "pop", ":", "{", "}", "tasks", "=", "[", "]", "models", "=", "[", "]", "models", "<<", "args", ".", "pop", "if", "args", ".", "last", "==", ":any", "args", ".", "each", "{", "|", "arg", "|", "arg", ".", "is_a?", "(", "Symbol", ")", "?", "tasks", "<<", "arg", ":", "models", "<<", "arg", "}", "tasks", ".", "each", "do", "|", "task", "|", "models", ".", "each", "do", "|", "model", "|", "if", "permission", "=", "target", "[", "task", "]", "[", "model", "]", "[", "@role", "]", "permission", ".", "load_options", "(", "options", ")", "else", "target", "[", "task", "]", "[", "model", "]", "[", "@role", "]", "=", "Permission", ".", "new", "(", "@role", ",", "task", ",", "model", ",", "options", ")", "end", "end", "end", "end" ]
Creates an internal Permission @param [Hash] target Either the permissions or the restrictions hash @param [Array] args The function arguments to the #can, #can_not methods
[ "Creates", "an", "internal", "Permission" ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L132-L150
7,251
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.process_tasks
def process_tasks @tasks.each_value do |task| task.options[:ancestors] = [] set_ancestor_tasks(task) set_alternative_tasks(task) if @permissions.key? task.name end end
ruby
def process_tasks @tasks.each_value do |task| task.options[:ancestors] = [] set_ancestor_tasks(task) set_alternative_tasks(task) if @permissions.key? task.name end end
[ "def", "process_tasks", "@tasks", ".", "each_value", "do", "|", "task", "|", "task", ".", "options", "[", ":ancestors", "]", "=", "[", "]", "set_ancestor_tasks", "(", "task", ")", "set_alternative_tasks", "(", "task", ")", "if", "@permissions", ".", "key?", "task", ".", "name", "end", "end" ]
Flattens the tasks. It sets the ancestors and the alternative tasks
[ "Flattens", "the", "tasks", ".", "It", "sets", "the", "ancestors", "and", "the", "alternative", "tasks" ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L153-L159
7,252
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.set_ancestor_tasks
def set_ancestor_tasks(task, ancestor = nil) task.options[:ancestors] += (ancestor || task).options[:is] (ancestor || task).options[:is].each do |parent_task| set_ancestor_tasks(task, @tasks[parent_task]) end end
ruby
def set_ancestor_tasks(task, ancestor = nil) task.options[:ancestors] += (ancestor || task).options[:is] (ancestor || task).options[:is].each do |parent_task| set_ancestor_tasks(task, @tasks[parent_task]) end end
[ "def", "set_ancestor_tasks", "(", "task", ",", "ancestor", "=", "nil", ")", "task", ".", "options", "[", ":ancestors", "]", "+=", "(", "ancestor", "||", "task", ")", ".", "options", "[", ":is", "]", "(", "ancestor", "||", "task", ")", ".", "options", "[", ":is", "]", ".", "each", "do", "|", "parent_task", "|", "set_ancestor_tasks", "(", "task", ",", "@tasks", "[", "parent_task", "]", ")", "end", "end" ]
Set the ancestors on task. @param [Task] task The task for which the ancestors are set @param [Task] ancestor The ancestor to process. This is the recursive parameter
[ "Set", "the", "ancestors", "on", "task", "." ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L165-L170
7,253
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.set_alternative_tasks
def set_alternative_tasks(task, ancestor = nil) (ancestor || task).options[:is].each do |task_name| if @permissions.key? task_name (@tasks[task_name].options[:alternatives] ||= []) << task.name else set_alternative_tasks(task, @tasks[task_name]) end end end
ruby
def set_alternative_tasks(task, ancestor = nil) (ancestor || task).options[:is].each do |task_name| if @permissions.key? task_name (@tasks[task_name].options[:alternatives] ||= []) << task.name else set_alternative_tasks(task, @tasks[task_name]) end end end
[ "def", "set_alternative_tasks", "(", "task", ",", "ancestor", "=", "nil", ")", "(", "ancestor", "||", "task", ")", ".", "options", "[", ":is", "]", ".", "each", "do", "|", "task_name", "|", "if", "@permissions", ".", "key?", "task_name", "(", "@tasks", "[", "task_name", "]", ".", "options", "[", ":alternatives", "]", "||=", "[", "]", ")", "<<", "task", ".", "name", "else", "set_alternative_tasks", "(", "task", ",", "@tasks", "[", "task_name", "]", ")", "end", "end", "end" ]
Set the alternatives of the task. Alternatives are the nearest ancestors, which are used in permission definitions. @param [Task] task The task for which the alternatives are set @param [Task] ancestor The ancestor to process. This is the recursive parameter
[ "Set", "the", "alternatives", "of", "the", "task", ".", "Alternatives", "are", "the", "nearest", "ancestors", "which", "are", "used", "in", "permission", "definitions", "." ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L177-L185
7,254
johnny/role-auth
lib/role-auth/parser.rb
RoleAuth.Parser.set_descendant_roles
def set_descendant_roles(descendant_role, ancestor_role = nil) role = ancestor_role || descendant_role return unless role[:is] role[:is].each do |role_name| (@roles[role_name][:descendants] ||= []) << descendant_role[:name] set_descendant_roles(descendant_role, @roles[role_name]) end end
ruby
def set_descendant_roles(descendant_role, ancestor_role = nil) role = ancestor_role || descendant_role return unless role[:is] role[:is].each do |role_name| (@roles[role_name][:descendants] ||= []) << descendant_role[:name] set_descendant_roles(descendant_role, @roles[role_name]) end end
[ "def", "set_descendant_roles", "(", "descendant_role", ",", "ancestor_role", "=", "nil", ")", "role", "=", "ancestor_role", "||", "descendant_role", "return", "unless", "role", "[", ":is", "]", "role", "[", ":is", "]", ".", "each", "do", "|", "role_name", "|", "(", "@roles", "[", "role_name", "]", "[", ":descendants", "]", "||=", "[", "]", ")", "<<", "descendant_role", "[", ":name", "]", "set_descendant_roles", "(", "descendant_role", ",", "@roles", "[", "role_name", "]", ")", "end", "end" ]
Set the descendant_role as a descendant of the ancestor
[ "Set", "the", "descendant_role", "as", "a", "descendant", "of", "the", "ancestor" ]
2f22e7e7766647483ca0f793be52e27fb8f96a87
https://github.com/johnny/role-auth/blob/2f22e7e7766647483ca0f793be52e27fb8f96a87/lib/role-auth/parser.rb#L193-L201
7,255
anga/BetterRailsDebugger
app/models/better_rails_debugger/group_instance.rb
BetterRailsDebugger.GroupInstance.big_classes
def big_classes(max_size=1.megabytes) return @big_classes if @big_classes @big_classes = {} ObjectInformation.where(:group_instance_id => self.id, :memsize.gt => max_size).all.each do |object| @big_classes[object.class_name] ||= {total_mem: 0, average: 0, count: 0} @big_classes[object.class_name][:total_mem] += object.memsize @big_classes[object.class_name][:count] += 1 end @big_classes.each_pair do |klass, hash| @big_classes[klass][:average] = @big_classes[klass][:total_mem] / @big_classes[klass][:count] end @big_classes end
ruby
def big_classes(max_size=1.megabytes) return @big_classes if @big_classes @big_classes = {} ObjectInformation.where(:group_instance_id => self.id, :memsize.gt => max_size).all.each do |object| @big_classes[object.class_name] ||= {total_mem: 0, average: 0, count: 0} @big_classes[object.class_name][:total_mem] += object.memsize @big_classes[object.class_name][:count] += 1 end @big_classes.each_pair do |klass, hash| @big_classes[klass][:average] = @big_classes[klass][:total_mem] / @big_classes[klass][:count] end @big_classes end
[ "def", "big_classes", "(", "max_size", "=", "1", ".", "megabytes", ")", "return", "@big_classes", "if", "@big_classes", "@big_classes", "=", "{", "}", "ObjectInformation", ".", "where", "(", ":group_instance_id", "=>", "self", ".", "id", ",", ":memsize", ".", "gt", "=>", "max_size", ")", ".", "all", ".", "each", "do", "|", "object", "|", "@big_classes", "[", "object", ".", "class_name", "]", "||=", "{", "total_mem", ":", "0", ",", "average", ":", "0", ",", "count", ":", "0", "}", "@big_classes", "[", "object", ".", "class_name", "]", "[", ":total_mem", "]", "+=", "object", ".", "memsize", "@big_classes", "[", "object", ".", "class_name", "]", "[", ":count", "]", "+=", "1", "end", "@big_classes", ".", "each_pair", "do", "|", "klass", ",", "hash", "|", "@big_classes", "[", "klass", "]", "[", ":average", "]", "=", "@big_classes", "[", "klass", "]", "[", ":total_mem", "]", "/", "@big_classes", "[", "klass", "]", "[", ":count", "]", "end", "@big_classes", "end" ]
Return an array of hashed that contains some information about the classes that consume more than `max_size` bytess
[ "Return", "an", "array", "of", "hashed", "that", "contains", "some", "information", "about", "the", "classes", "that", "consume", "more", "than", "max_size", "bytess" ]
2ac7af13b8ee12483bd9a92680d8f43042f1f1d5
https://github.com/anga/BetterRailsDebugger/blob/2ac7af13b8ee12483bd9a92680d8f43042f1f1d5/app/models/better_rails_debugger/group_instance.rb#L72-L84
7,256
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/terms_controller.rb
Roroacms.Admin::TermsController.categories
def categories # add breadcrumb and set title add_breadcrumb I18n.t("generic.categories"), :admin_article_categories_path, :title => I18n.t("controllers.admin.terms.categories.breadcrumb_title") set_title(I18n.t("generic.categories")) @type = 'category' @records = Term.term_cats('category', nil, true) # render view template as it is the same as the tag view render 'view' end
ruby
def categories # add breadcrumb and set title add_breadcrumb I18n.t("generic.categories"), :admin_article_categories_path, :title => I18n.t("controllers.admin.terms.categories.breadcrumb_title") set_title(I18n.t("generic.categories")) @type = 'category' @records = Term.term_cats('category', nil, true) # render view template as it is the same as the tag view render 'view' end
[ "def", "categories", "# add breadcrumb and set title", "add_breadcrumb", "I18n", ".", "t", "(", "\"generic.categories\"", ")", ",", ":admin_article_categories_path", ",", ":title", "=>", "I18n", ".", "t", "(", "\"controllers.admin.terms.categories.breadcrumb_title\"", ")", "set_title", "(", "I18n", ".", "t", "(", "\"generic.categories\"", ")", ")", "@type", "=", "'category'", "@records", "=", "Term", ".", "term_cats", "(", "'category'", ",", "nil", ",", "true", ")", "# render view template as it is the same as the tag view", "render", "'view'", "end" ]
displays all the current categories and creates a new category object for creating a new one
[ "displays", "all", "the", "current", "categories", "and", "creates", "a", "new", "category", "object", "for", "creating", "a", "new", "one" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/terms_controller.rb#L7-L16
7,257
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/terms_controller.rb
Roroacms.Admin::TermsController.create
def create @category = Term.new(term_params) redirect_url = Term.get_redirect_url(params) respond_to do |format| if @category.save @term_anatomy = @category.create_term_anatomy(:taxonomy => params[:type_taxonomy]) format.html { redirect_to URI.parse(redirect_url).path, only_path: true, notice: I18n.t("controllers.admin.terms.create.flash.success", term: Term.get_type_of_term(params)) } else flash[:error] = I18n.t("controllers.admin.terms.create.flash.error") format.html { redirect_to URI.parse(redirect_url).path, only_path: true } end end end
ruby
def create @category = Term.new(term_params) redirect_url = Term.get_redirect_url(params) respond_to do |format| if @category.save @term_anatomy = @category.create_term_anatomy(:taxonomy => params[:type_taxonomy]) format.html { redirect_to URI.parse(redirect_url).path, only_path: true, notice: I18n.t("controllers.admin.terms.create.flash.success", term: Term.get_type_of_term(params)) } else flash[:error] = I18n.t("controllers.admin.terms.create.flash.error") format.html { redirect_to URI.parse(redirect_url).path, only_path: true } end end end
[ "def", "create", "@category", "=", "Term", ".", "new", "(", "term_params", ")", "redirect_url", "=", "Term", ".", "get_redirect_url", "(", "params", ")", "respond_to", "do", "|", "format", "|", "if", "@category", ".", "save", "@term_anatomy", "=", "@category", ".", "create_term_anatomy", "(", ":taxonomy", "=>", "params", "[", ":type_taxonomy", "]", ")", "format", ".", "html", "{", "redirect_to", "URI", ".", "parse", "(", "redirect_url", ")", ".", "path", ",", "only_path", ":", "true", ",", "notice", ":", "I18n", ".", "t", "(", "\"controllers.admin.terms.create.flash.success\"", ",", "term", ":", "Term", ".", "get_type_of_term", "(", "params", ")", ")", "}", "else", "flash", "[", ":error", "]", "=", "I18n", ".", "t", "(", "\"controllers.admin.terms.create.flash.error\"", ")", "format", ".", "html", "{", "redirect_to", "URI", ".", "parse", "(", "redirect_url", ")", ".", "path", ",", "only_path", ":", "true", "}", "end", "end", "end" ]
create tag or category - this is set within the form
[ "create", "tag", "or", "category", "-", "this", "is", "set", "within", "the", "form" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/terms_controller.rb#L34-L53
7,258
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/terms_controller.rb
Roroacms.Admin::TermsController.update
def update @category = Term.find(params[:id]) @category.deal_with_cover(params[:has_cover_image]) respond_to do |format| # deal with abnormalaties - update the structure url if @category.update_attributes(term_params) format.html { redirect_to edit_admin_term_path(@category), notice: I18n.t("controllers.admin.terms.update.flash.success", term: Term.get_type_of_term(params)) } else format.html { render action: "edit" } end end end
ruby
def update @category = Term.find(params[:id]) @category.deal_with_cover(params[:has_cover_image]) respond_to do |format| # deal with abnormalaties - update the structure url if @category.update_attributes(term_params) format.html { redirect_to edit_admin_term_path(@category), notice: I18n.t("controllers.admin.terms.update.flash.success", term: Term.get_type_of_term(params)) } else format.html { render action: "edit" } end end end
[ "def", "update", "@category", "=", "Term", ".", "find", "(", "params", "[", ":id", "]", ")", "@category", ".", "deal_with_cover", "(", "params", "[", ":has_cover_image", "]", ")", "respond_to", "do", "|", "format", "|", "# deal with abnormalaties - update the structure url", "if", "@category", ".", "update_attributes", "(", "term_params", ")", "format", ".", "html", "{", "redirect_to", "edit_admin_term_path", "(", "@category", ")", ",", "notice", ":", "I18n", ".", "t", "(", "\"controllers.admin.terms.update.flash.success\"", ",", "term", ":", "Term", ".", "get_type_of_term", "(", "params", ")", ")", "}", "else", "format", ".", "html", "{", "render", "action", ":", "\"edit\"", "}", "end", "end", "end" ]
update the term record with the given parameters
[ "update", "the", "term", "record", "with", "the", "given", "parameters" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/terms_controller.rb#L67-L81
7,259
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/terms_controller.rb
Roroacms.Admin::TermsController.destroy
def destroy @term = Term.find(params[:id]) # return url will be different for either tag or category redirect_url = Term.get_redirect_url({ type_taxonomy: @term.term_anatomy.taxonomy }) @term.destroy respond_to do |format| format.html { redirect_to URI.parse(redirect_url).path, notice: I18n.t("controllers.admin.terms.destroy.flash.success") } end end
ruby
def destroy @term = Term.find(params[:id]) # return url will be different for either tag or category redirect_url = Term.get_redirect_url({ type_taxonomy: @term.term_anatomy.taxonomy }) @term.destroy respond_to do |format| format.html { redirect_to URI.parse(redirect_url).path, notice: I18n.t("controllers.admin.terms.destroy.flash.success") } end end
[ "def", "destroy", "@term", "=", "Term", ".", "find", "(", "params", "[", ":id", "]", ")", "# return url will be different for either tag or category", "redirect_url", "=", "Term", ".", "get_redirect_url", "(", "{", "type_taxonomy", ":", "@term", ".", "term_anatomy", ".", "taxonomy", "}", ")", "@term", ".", "destroy", "respond_to", "do", "|", "format", "|", "format", ".", "html", "{", "redirect_to", "URI", ".", "parse", "(", "redirect_url", ")", ".", "path", ",", "notice", ":", "I18n", ".", "t", "(", "\"controllers.admin.terms.destroy.flash.success\"", ")", "}", "end", "end" ]
delete the term
[ "delete", "the", "term" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/terms_controller.rb#L86-L95
7,260
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/terms_controller.rb
Roroacms.Admin::TermsController.edit_title
def edit_title if @category.term_anatomy.taxonomy == 'category' add_breadcrumb I18n.t("generic.categories"), :admin_article_categories_path, :title => I18n.t("controllers.admin.terms.edit_title.category.breadcrumb_title") add_breadcrumb I18n.t("controllers.admin.terms.edit_title.category.title") title = I18n.t("controllers.admin.terms.edit_title.category.title") else add_breadcrumb I18n.t("generic.tags"), :admin_article_tags_path, :title => I18n.t("controllers.admin.terms.edit_title.tag.breadcrumb_title") add_breadcrumb I18n.t("controllers.admin.terms.edit_title.tag.title") title = I18n.t("controllers.admin.terms.edit_title.tag.title") end return title end
ruby
def edit_title if @category.term_anatomy.taxonomy == 'category' add_breadcrumb I18n.t("generic.categories"), :admin_article_categories_path, :title => I18n.t("controllers.admin.terms.edit_title.category.breadcrumb_title") add_breadcrumb I18n.t("controllers.admin.terms.edit_title.category.title") title = I18n.t("controllers.admin.terms.edit_title.category.title") else add_breadcrumb I18n.t("generic.tags"), :admin_article_tags_path, :title => I18n.t("controllers.admin.terms.edit_title.tag.breadcrumb_title") add_breadcrumb I18n.t("controllers.admin.terms.edit_title.tag.title") title = I18n.t("controllers.admin.terms.edit_title.tag.title") end return title end
[ "def", "edit_title", "if", "@category", ".", "term_anatomy", ".", "taxonomy", "==", "'category'", "add_breadcrumb", "I18n", ".", "t", "(", "\"generic.categories\"", ")", ",", ":admin_article_categories_path", ",", ":title", "=>", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.category.breadcrumb_title\"", ")", "add_breadcrumb", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.category.title\"", ")", "title", "=", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.category.title\"", ")", "else", "add_breadcrumb", "I18n", ".", "t", "(", "\"generic.tags\"", ")", ",", ":admin_article_tags_path", ",", ":title", "=>", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.tag.breadcrumb_title\"", ")", "add_breadcrumb", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.tag.title\"", ")", "title", "=", "I18n", ".", "t", "(", "\"controllers.admin.terms.edit_title.tag.title\"", ")", "end", "return", "title", "end" ]
set the title and breadcrumbs for the edit screen
[ "set", "the", "title", "and", "breadcrumbs", "for", "the", "edit", "screen" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/terms_controller.rb#L116-L130
7,261
buzzware/yore
lib/yore/yore_core.rb
YoreCore.Yore.upload
def upload(aFile) #ensure_bucket() logger.debug "Uploading #{aFile} to S3 bucket #{config[:bucket]} ..." logger.info "Uploading #{File.basename(aFile)} to S3 bucket #{config[:bucket]} ..." s3client.upload_backup(aFile,config[:bucket],File.basename(aFile)) end
ruby
def upload(aFile) #ensure_bucket() logger.debug "Uploading #{aFile} to S3 bucket #{config[:bucket]} ..." logger.info "Uploading #{File.basename(aFile)} to S3 bucket #{config[:bucket]} ..." s3client.upload_backup(aFile,config[:bucket],File.basename(aFile)) end
[ "def", "upload", "(", "aFile", ")", "#ensure_bucket()", "logger", ".", "debug", "\"Uploading #{aFile} to S3 bucket #{config[:bucket]} ...\"", "logger", ".", "info", "\"Uploading #{File.basename(aFile)} to S3 bucket #{config[:bucket]} ...\"", "s3client", ".", "upload_backup", "(", "aFile", ",", "config", "[", ":bucket", "]", ",", "File", ".", "basename", "(", "aFile", ")", ")", "end" ]
uploads the given file to the current bucket as its basename
[ "uploads", "the", "given", "file", "to", "the", "current", "bucket", "as", "its", "basename" ]
96ace47e0574e1405becd4dafb5de0226896ea1e
https://github.com/buzzware/yore/blob/96ace47e0574e1405becd4dafb5de0226896ea1e/lib/yore/yore_core.rb#L308-L313
7,262
buzzware/yore
lib/yore/yore_core.rb
YoreCore.Yore.decode_file_name
def decode_file_name(aFilename) prefix,date,ext = aFilename.scan(/(.*?)\-(.*?)\.(.*)/).flatten return Time.from_date_numeric(date) end
ruby
def decode_file_name(aFilename) prefix,date,ext = aFilename.scan(/(.*?)\-(.*?)\.(.*)/).flatten return Time.from_date_numeric(date) end
[ "def", "decode_file_name", "(", "aFilename", ")", "prefix", ",", "date", ",", "ext", "=", "aFilename", ".", "scan", "(", "/", "\\-", "\\.", "/", ")", ".", "flatten", "return", "Time", ".", "from_date_numeric", "(", "date", ")", "end" ]
return date based on filename
[ "return", "date", "based", "on", "filename" ]
96ace47e0574e1405becd4dafb5de0226896ea1e
https://github.com/buzzware/yore/blob/96ace47e0574e1405becd4dafb5de0226896ea1e/lib/yore/yore_core.rb#L334-L337
7,263
Fire-Dragon-DoL/fried-schema
lib/fried/schema/attribute/define_reader.rb
Fried::Schema::Attribute.DefineReader.call
def call(definition, klass) variable = definition.instance_variable klass.instance_eval do define_method(definition.reader) { instance_variable_get(variable) } end end
ruby
def call(definition, klass) variable = definition.instance_variable klass.instance_eval do define_method(definition.reader) { instance_variable_get(variable) } end end
[ "def", "call", "(", "definition", ",", "klass", ")", "variable", "=", "definition", ".", "instance_variable", "klass", ".", "instance_eval", "do", "define_method", "(", "definition", ".", "reader", ")", "{", "instance_variable_get", "(", "variable", ")", "}", "end", "end" ]
Creates read method @param definition [Definition] @param klass [Class, Module] @return [Definition]
[ "Creates", "read", "method" ]
85c5a093f319fc0f0d242264fdd7a2acfd805eea
https://github.com/Fire-Dragon-DoL/fried-schema/blob/85c5a093f319fc0f0d242264fdd7a2acfd805eea/lib/fried/schema/attribute/define_reader.rb#L19-L25
7,264
barkerest/barkest_core
app/helpers/barkest_core/misc_helper.rb
BarkestCore.MiscHelper.fixed
def fixed(value, places = 2) value = value.to_s.to_f unless value.is_a?(Float) sprintf("%0.#{places}f", value.round(places)) end
ruby
def fixed(value, places = 2) value = value.to_s.to_f unless value.is_a?(Float) sprintf("%0.#{places}f", value.round(places)) end
[ "def", "fixed", "(", "value", ",", "places", "=", "2", ")", "value", "=", "value", ".", "to_s", ".", "to_f", "unless", "value", ".", "is_a?", "(", "Float", ")", "sprintf", "(", "\"%0.#{places}f\"", ",", "value", ".", "round", "(", "places", ")", ")", "end" ]
Formats a number to the specified number of decimal places. The +value+ can be either any valid numeric expression that can be converted to a float.
[ "Formats", "a", "number", "to", "the", "specified", "number", "of", "decimal", "places", "." ]
3eeb025ec870888cacbc9bae252a39ebf9295f61
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/app/helpers/barkest_core/misc_helper.rb#L27-L30
7,265
barkerest/barkest_core
app/helpers/barkest_core/misc_helper.rb
BarkestCore.MiscHelper.split_name
def split_name(name) name ||= '' if name.include?(',') last,first = name.split(',', 2) first,middle = first.to_s.strip.split(' ', 2) else first,middle,last = name.split(' ', 3) if middle && !last middle,last = last,middle end end [ first.to_s.strip, middle.to_s.strip, last.to_s.strip ] end
ruby
def split_name(name) name ||= '' if name.include?(',') last,first = name.split(',', 2) first,middle = first.to_s.strip.split(' ', 2) else first,middle,last = name.split(' ', 3) if middle && !last middle,last = last,middle end end [ first.to_s.strip, middle.to_s.strip, last.to_s.strip ] end
[ "def", "split_name", "(", "name", ")", "name", "||=", "''", "if", "name", ".", "include?", "(", "','", ")", "last", ",", "first", "=", "name", ".", "split", "(", "','", ",", "2", ")", "first", ",", "middle", "=", "first", ".", "to_s", ".", "strip", ".", "split", "(", "' '", ",", "2", ")", "else", "first", ",", "middle", ",", "last", "=", "name", ".", "split", "(", "' '", ",", "3", ")", "if", "middle", "&&", "!", "last", "middle", ",", "last", "=", "last", ",", "middle", "end", "end", "[", "first", ".", "to_s", ".", "strip", ",", "middle", ".", "to_s", ".", "strip", ",", "last", ".", "to_s", ".", "strip", "]", "end" ]
Splits a name into First, Middle, and Last parts. Returns an array containing [ First, Middle, Last ] Any part that is missing will be nil. 'John Doe' => [ 'John', nil, 'Doe' ] 'Doe, John' => [ 'John', nil, 'Doe' ] 'John A. Doe' => [ 'John', 'A.', 'Doe' ] 'Doe, John A.' => [ 'John', 'A.', 'Doe' ] 'John A. Doe Jr.' => [ 'John', 'A.', 'Doe Jr.' ] 'Doe Jr., John A.' => [ 'John', 'A.', 'Doe Jr.' ] Since it doesn't check very hard, there are some known bugs as well. 'John Doe Jr.' => [ 'John', 'Doe', 'Jr.' ] 'John Doe, Jr.' => [ 'Jr.', nil, 'John Doe' ] 'Doe, John A., Jr.' => [ 'John', 'A., Jr.', 'Doe' ] It should work in most cases.
[ "Splits", "a", "name", "into", "First", "Middle", "and", "Last", "parts", "." ]
3eeb025ec870888cacbc9bae252a39ebf9295f61
https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/app/helpers/barkest_core/misc_helper.rb#L53-L65
7,266
gabebw/pipio
lib/pipio/parsers/basic_parser.rb
Pipio.BasicParser.parse
def parse if pre_parse messages = @file_reader.other_lines.map do |line| basic_message_match = @line_regex.match(line) meta_message_match = @line_regex_status.match(line) if basic_message_match create_message(basic_message_match) elsif meta_message_match create_status_or_event_message(meta_message_match) end end Chat.new(messages, @metadata) end end
ruby
def parse if pre_parse messages = @file_reader.other_lines.map do |line| basic_message_match = @line_regex.match(line) meta_message_match = @line_regex_status.match(line) if basic_message_match create_message(basic_message_match) elsif meta_message_match create_status_or_event_message(meta_message_match) end end Chat.new(messages, @metadata) end end
[ "def", "parse", "if", "pre_parse", "messages", "=", "@file_reader", ".", "other_lines", ".", "map", "do", "|", "line", "|", "basic_message_match", "=", "@line_regex", ".", "match", "(", "line", ")", "meta_message_match", "=", "@line_regex_status", ".", "match", "(", "line", ")", "if", "basic_message_match", "create_message", "(", "basic_message_match", ")", "elsif", "meta_message_match", "create_status_or_event_message", "(", "meta_message_match", ")", "end", "end", "Chat", ".", "new", "(", "messages", ",", "@metadata", ")", "end", "end" ]
This method returns a Chat instance, or false if it could not parse the file.
[ "This", "method", "returns", "a", "Chat", "instance", "or", "false", "if", "it", "could", "not", "parse", "the", "file", "." ]
ce8abe90c9e75d916fd3a5a0f5d73e7ac9c4eacd
https://github.com/gabebw/pipio/blob/ce8abe90c9e75d916fd3a5a0f5d73e7ac9c4eacd/lib/pipio/parsers/basic_parser.rb#L14-L28
7,267
gabebw/pipio
lib/pipio/parsers/basic_parser.rb
Pipio.BasicParser.pre_parse
def pre_parse @file_reader.read metadata = Metadata.new(MetadataParser.new(@file_reader.first_line).parse) if metadata.valid? @metadata = metadata @alias_registry = AliasRegistry.new(@metadata.their_screen_name) @my_aliases.each do |my_alias| @alias_registry[my_alias] = @metadata.my_screen_name end end end
ruby
def pre_parse @file_reader.read metadata = Metadata.new(MetadataParser.new(@file_reader.first_line).parse) if metadata.valid? @metadata = metadata @alias_registry = AliasRegistry.new(@metadata.their_screen_name) @my_aliases.each do |my_alias| @alias_registry[my_alias] = @metadata.my_screen_name end end end
[ "def", "pre_parse", "@file_reader", ".", "read", "metadata", "=", "Metadata", ".", "new", "(", "MetadataParser", ".", "new", "(", "@file_reader", ".", "first_line", ")", ".", "parse", ")", "if", "metadata", ".", "valid?", "@metadata", "=", "metadata", "@alias_registry", "=", "AliasRegistry", ".", "new", "(", "@metadata", ".", "their_screen_name", ")", "@my_aliases", ".", "each", "do", "|", "my_alias", "|", "@alias_registry", "[", "my_alias", "]", "=", "@metadata", ".", "my_screen_name", "end", "end", "end" ]
Extract required data from the file. Run by parse.
[ "Extract", "required", "data", "from", "the", "file", ".", "Run", "by", "parse", "." ]
ce8abe90c9e75d916fd3a5a0f5d73e7ac9c4eacd
https://github.com/gabebw/pipio/blob/ce8abe90c9e75d916fd3a5a0f5d73e7ac9c4eacd/lib/pipio/parsers/basic_parser.rb#L31-L41
7,268
ajsharp/em-stathat
lib/em-stathat.rb
EventMachine.StatHat.time
def time(name, opts = {}) opts[:ez] ||= true start = Time.now yield if block_given? if opts[:ez] == true ez_value(name, (Time.now - start)) else value(name, (Time.now - start)) end end
ruby
def time(name, opts = {}) opts[:ez] ||= true start = Time.now yield if block_given? if opts[:ez] == true ez_value(name, (Time.now - start)) else value(name, (Time.now - start)) end end
[ "def", "time", "(", "name", ",", "opts", "=", "{", "}", ")", "opts", "[", ":ez", "]", "||=", "true", "start", "=", "Time", ".", "now", "yield", "if", "block_given?", "if", "opts", "[", ":ez", "]", "==", "true", "ez_value", "(", "name", ",", "(", "Time", ".", "now", "-", "start", ")", ")", "else", "value", "(", "name", ",", "(", "Time", ".", "now", "-", "start", ")", ")", "end", "end" ]
Time a block of code and send the duration as a value @example StatHat.new.time('some identifying name') do # code end @param [String] name the name of the stat @param [Hash] opts a hash of options @option [Symbol] :ez Send data via the ez api (default: true)
[ "Time", "a", "block", "of", "code", "and", "send", "the", "duration", "as", "a", "value" ]
a5b19339e9720f8b9858d65e020371511ca91b63
https://github.com/ajsharp/em-stathat/blob/a5b19339e9720f8b9858d65e020371511ca91b63/lib/em-stathat.rb#L47-L58
7,269
mudasobwa/qipowl
lib/qipowl/core/bowler.rb
Qipowl::Bowlers.Bowler.add_entity
def add_entity section, key, value, enclosure_value = null if (tags = self.class.const_get("#{section.upcase}_TAGS")) key = key.bowl.to_sym tags[key] = value.to_sym self.class.const_get("ENCLOSURES_TAGS")[key] = enclosure_value.to_sym if enclosure_value self.class.const_get("ENTITIES")[section.to_sym][key] = value.to_sym self.class.class_eval %Q{ alias_method :#{key}, :∀_#{section} } # unless self.class.instance_methods(true).include?(key.bowl) @shadows = nil else logger.warn "Trying to add key “#{key}” in an invalid section “#{section}”. Ignoring…" end end
ruby
def add_entity section, key, value, enclosure_value = null if (tags = self.class.const_get("#{section.upcase}_TAGS")) key = key.bowl.to_sym tags[key] = value.to_sym self.class.const_get("ENCLOSURES_TAGS")[key] = enclosure_value.to_sym if enclosure_value self.class.const_get("ENTITIES")[section.to_sym][key] = value.to_sym self.class.class_eval %Q{ alias_method :#{key}, :∀_#{section} } # unless self.class.instance_methods(true).include?(key.bowl) @shadows = nil else logger.warn "Trying to add key “#{key}” in an invalid section “#{section}”. Ignoring…" end end
[ "def", "add_entity", "section", ",", "key", ",", "value", ",", "enclosure_value", "=", "null", "if", "(", "tags", "=", "self", ".", "class", ".", "const_get", "(", "\"#{section.upcase}_TAGS\"", ")", ")", "key", "=", "key", ".", "bowl", ".", "to_sym", "tags", "[", "key", "]", "=", "value", ".", "to_sym", "self", ".", "class", ".", "const_get", "(", "\"ENCLOSURES_TAGS\"", ")", "[", "key", "]", "=", "enclosure_value", ".", "to_sym", "if", "enclosure_value", "self", ".", "class", ".", "const_get", "(", "\"ENTITIES\"", ")", "[", "section", ".", "to_sym", "]", "[", "key", "]", "=", "value", ".", "to_sym", "self", ".", "class", ".", "class_eval", "%Q{\n alias_method :#{key}, :∀_#{section}\n }", "# unless self.class.instance_methods(true).include?(key.bowl)", "@shadows", "=", "nil", "else", "logger", ".", "warn", "\"Trying to add key “#{key}” in an invalid section “#{section}”. Ignoring…\"", "end", "end" ]
Adds new +entity+ in the section specified. E. g., call to add_spice :linewide, :°, :deg, :degrees in HTML implementation adds a support for specifying something like: ° 15 ° 30 ° 45 which is to be converted to the following: <degrees> <deg>15</deg> <deg>30</deg> <deg>45</deg> </degrees> @param [Symbol] section the section (it must be one of {Mapping.SPICES}) to add new key to @param [Symbol] key the name for the key @param [Symbol] value the value @param [Symbol] enclosure_value optional value to be added for the key into enclosures section
[ "Adds", "new", "+", "entity", "+", "in", "the", "section", "specified", ".", "E", ".", "g", ".", "call", "to" ]
1d4643a53914d963daa73c649a043ad0ac0d71c8
https://github.com/mudasobwa/qipowl/blob/1d4643a53914d963daa73c649a043ad0ac0d71c8/lib/qipowl/core/bowler.rb#L99-L112
7,270
jinx/core
lib/jinx/metadata/property.rb
Jinx.Property.restrict_flags
def restrict_flags(declarer, *flags) copy = restrict(declarer) copy.qualify(*flags) copy end
ruby
def restrict_flags(declarer, *flags) copy = restrict(declarer) copy.qualify(*flags) copy end
[ "def", "restrict_flags", "(", "declarer", ",", "*", "flags", ")", "copy", "=", "restrict", "(", "declarer", ")", "copy", ".", "qualify", "(", "flags", ")", "copy", "end" ]
Creates a new declarer attribute which qualifies this attribute for the given declarer. @param declarer (see #restrict) @param [<Symbol>] flags the additional flags for the restricted attribute @return (see #restrict)
[ "Creates", "a", "new", "declarer", "attribute", "which", "qualifies", "this", "attribute", "for", "the", "given", "declarer", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/metadata/property.rb#L95-L99
7,271
jinx/core
lib/jinx/metadata/property.rb
Jinx.Property.inverse=
def inverse=(attribute) return if inverse == attribute # if no attribute, then the clear the existing inverse, if any return clear_inverse if attribute.nil? # the inverse attribute meta-data begin @inv_prop = type.property(attribute) rescue NameError => e raise MetadataError.new("#{@declarer.qp}.#{self} inverse attribute #{type.qp}.#{attribute} not found") end # the inverse of the inverse inv_inv_prop = @inv_prop.inverse_property # If the inverse of the inverse is already set to a different attribute, then raise an exception. if inv_inv_prop and not (inv_inv_prop == self or inv_inv_prop.restriction?(self)) raise MetadataError.new("Cannot set #{type.qp}.#{attribute} inverse attribute to #{@declarer.qp}.#{self}@#{object_id} since it conflicts with existing inverse #{inv_inv_prop.declarer.qp}.#{inv_inv_prop}@#{inv_inv_prop.object_id}") end # Set the inverse of the inverse to this attribute. @inv_prop.inverse = @attribute # If this attribute is disjoint, then so is the inverse. @inv_prop.qualify(:disjoint) if disjoint? logger.debug { "Assigned #{@declarer.qp}.#{self} attribute inverse to #{type.qp}.#{attribute}." } end
ruby
def inverse=(attribute) return if inverse == attribute # if no attribute, then the clear the existing inverse, if any return clear_inverse if attribute.nil? # the inverse attribute meta-data begin @inv_prop = type.property(attribute) rescue NameError => e raise MetadataError.new("#{@declarer.qp}.#{self} inverse attribute #{type.qp}.#{attribute} not found") end # the inverse of the inverse inv_inv_prop = @inv_prop.inverse_property # If the inverse of the inverse is already set to a different attribute, then raise an exception. if inv_inv_prop and not (inv_inv_prop == self or inv_inv_prop.restriction?(self)) raise MetadataError.new("Cannot set #{type.qp}.#{attribute} inverse attribute to #{@declarer.qp}.#{self}@#{object_id} since it conflicts with existing inverse #{inv_inv_prop.declarer.qp}.#{inv_inv_prop}@#{inv_inv_prop.object_id}") end # Set the inverse of the inverse to this attribute. @inv_prop.inverse = @attribute # If this attribute is disjoint, then so is the inverse. @inv_prop.qualify(:disjoint) if disjoint? logger.debug { "Assigned #{@declarer.qp}.#{self} attribute inverse to #{type.qp}.#{attribute}." } end
[ "def", "inverse", "=", "(", "attribute", ")", "return", "if", "inverse", "==", "attribute", "# if no attribute, then the clear the existing inverse, if any", "return", "clear_inverse", "if", "attribute", ".", "nil?", "# the inverse attribute meta-data", "begin", "@inv_prop", "=", "type", ".", "property", "(", "attribute", ")", "rescue", "NameError", "=>", "e", "raise", "MetadataError", ".", "new", "(", "\"#{@declarer.qp}.#{self} inverse attribute #{type.qp}.#{attribute} not found\"", ")", "end", "# the inverse of the inverse", "inv_inv_prop", "=", "@inv_prop", ".", "inverse_property", "# If the inverse of the inverse is already set to a different attribute, then raise an exception.", "if", "inv_inv_prop", "and", "not", "(", "inv_inv_prop", "==", "self", "or", "inv_inv_prop", ".", "restriction?", "(", "self", ")", ")", "raise", "MetadataError", ".", "new", "(", "\"Cannot set #{type.qp}.#{attribute} inverse attribute to #{@declarer.qp}.#{self}@#{object_id} since it conflicts with existing inverse #{inv_inv_prop.declarer.qp}.#{inv_inv_prop}@#{inv_inv_prop.object_id}\"", ")", "end", "# Set the inverse of the inverse to this attribute.", "@inv_prop", ".", "inverse", "=", "@attribute", "# If this attribute is disjoint, then so is the inverse.", "@inv_prop", ".", "qualify", "(", ":disjoint", ")", "if", "disjoint?", "logger", ".", "debug", "{", "\"Assigned #{@declarer.qp}.#{self} attribute inverse to #{type.qp}.#{attribute}.\"", "}", "end" ]
Sets the inverse of the subject attribute to the given attribute. The inverse relation is symmetric, i.e. the inverse of the referenced Property is set to this Property's subject attribute. @param [Symbol, nil] attribute the inverse attribute @raise [MetadataError] if the the inverse of the inverse is already set to a different attribute
[ "Sets", "the", "inverse", "of", "the", "subject", "attribute", "to", "the", "given", "attribute", ".", "The", "inverse", "relation", "is", "symmetric", "i", ".", "e", ".", "the", "inverse", "of", "the", "referenced", "Property", "is", "set", "to", "this", "Property", "s", "subject", "attribute", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/metadata/property.rb#L107-L128
7,272
jinx/core
lib/jinx/metadata/property.rb
Jinx.Property.owner_flag_set
def owner_flag_set if dependent? then raise MetadataError.new("#{declarer.qp}.#{self} cannot be set as a #{type.qp} owner since it is already defined as a #{type.qp} dependent") end inv_prop = inverse_property if inv_prop then inv_prop.qualify(:dependent) unless inv_prop.dependent? else inv_attr = type.dependent_attribute(@declarer) if inv_attr.nil? then raise MetadataError.new("The #{@declarer.qp} owner attribute #{self} of type #{type.qp} does not have an inverse") end logger.debug { "#{declarer.qp}.#{self} inverse is the #{type.qp} dependent attribute #{inv_attr}." } self.inverse = inv_attr end end
ruby
def owner_flag_set if dependent? then raise MetadataError.new("#{declarer.qp}.#{self} cannot be set as a #{type.qp} owner since it is already defined as a #{type.qp} dependent") end inv_prop = inverse_property if inv_prop then inv_prop.qualify(:dependent) unless inv_prop.dependent? else inv_attr = type.dependent_attribute(@declarer) if inv_attr.nil? then raise MetadataError.new("The #{@declarer.qp} owner attribute #{self} of type #{type.qp} does not have an inverse") end logger.debug { "#{declarer.qp}.#{self} inverse is the #{type.qp} dependent attribute #{inv_attr}." } self.inverse = inv_attr end end
[ "def", "owner_flag_set", "if", "dependent?", "then", "raise", "MetadataError", ".", "new", "(", "\"#{declarer.qp}.#{self} cannot be set as a #{type.qp} owner since it is already defined as a #{type.qp} dependent\"", ")", "end", "inv_prop", "=", "inverse_property", "if", "inv_prop", "then", "inv_prop", ".", "qualify", "(", ":dependent", ")", "unless", "inv_prop", ".", "dependent?", "else", "inv_attr", "=", "type", ".", "dependent_attribute", "(", "@declarer", ")", "if", "inv_attr", ".", "nil?", "then", "raise", "MetadataError", ".", "new", "(", "\"The #{@declarer.qp} owner attribute #{self} of type #{type.qp} does not have an inverse\"", ")", "end", "logger", ".", "debug", "{", "\"#{declarer.qp}.#{self} inverse is the #{type.qp} dependent attribute #{inv_attr}.\"", "}", "self", ".", "inverse", "=", "inv_attr", "end", "end" ]
This method is called when the owner flag is set. The inverse is inferred as the referenced owner type's dependent attribute which references this attribute's type. @raise [MetadataError] if this attribute is dependent or an inverse could not be inferred
[ "This", "method", "is", "called", "when", "the", "owner", "flag", "is", "set", ".", "The", "inverse", "is", "inferred", "as", "the", "referenced", "owner", "type", "s", "dependent", "attribute", "which", "references", "this", "attribute", "s", "type", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/metadata/property.rb#L285-L300
7,273
7compass/truncus
lib/truncus.rb
Truncus.Client.get_token
def get_token(url) req = Net::HTTP::Post.new('/', initheader = {'Content-Type' => 'application/json'}) req.body = {url: url, format: 'json'}.to_json res = @http.request(req) data = JSON::parse(res.body) data['trunct']['token'] end
ruby
def get_token(url) req = Net::HTTP::Post.new('/', initheader = {'Content-Type' => 'application/json'}) req.body = {url: url, format: 'json'}.to_json res = @http.request(req) data = JSON::parse(res.body) data['trunct']['token'] end
[ "def", "get_token", "(", "url", ")", "req", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "'/'", ",", "initheader", "=", "{", "'Content-Type'", "=>", "'application/json'", "}", ")", "req", ".", "body", "=", "{", "url", ":", "url", ",", "format", ":", "'json'", "}", ".", "to_json", "res", "=", "@http", ".", "request", "(", "req", ")", "data", "=", "JSON", "::", "parse", "(", "res", ".", "body", ")", "data", "[", "'trunct'", "]", "[", "'token'", "]", "end" ]
Shortens a URL, returns the shortened token
[ "Shortens", "a", "URL", "returns", "the", "shortened", "token" ]
504d1bbcb97a862da889fb22d120c070e1877650
https://github.com/7compass/truncus/blob/504d1bbcb97a862da889fb22d120c070e1877650/lib/truncus.rb#L44-L51
7,274
riddopic/garcun
lib/garcon/task/thread_pool/executor.rb
Garcon.ThreadPoolExecutor.on_worker_exit
def on_worker_exit(worker) mutex.synchronize do @pool.delete(worker) if @pool.empty? && !running? stop_event.set stopped_event.set end end end
ruby
def on_worker_exit(worker) mutex.synchronize do @pool.delete(worker) if @pool.empty? && !running? stop_event.set stopped_event.set end end end
[ "def", "on_worker_exit", "(", "worker", ")", "mutex", ".", "synchronize", "do", "@pool", ".", "delete", "(", "worker", ")", "if", "@pool", ".", "empty?", "&&", "!", "running?", "stop_event", ".", "set", "stopped_event", ".", "set", "end", "end", "end" ]
Run when a thread worker exits. @!visibility private
[ "Run", "when", "a", "thread", "worker", "exits", "." ]
c2409bd8cf9c14b967a719810dab5269d69b42de
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/thread_pool/executor.rb#L178-L186
7,275
riddopic/garcun
lib/garcon/task/thread_pool/executor.rb
Garcon.ThreadPoolExecutor.execute
def execute(*args, &task) if ensure_capacity? @scheduled_task_count += 1 @queue << [args, task] else if @max_queue != 0 && @queue.length >= @max_queue handle_fallback(*args, &task) end end prune_pool end
ruby
def execute(*args, &task) if ensure_capacity? @scheduled_task_count += 1 @queue << [args, task] else if @max_queue != 0 && @queue.length >= @max_queue handle_fallback(*args, &task) end end prune_pool end
[ "def", "execute", "(", "*", "args", ",", "&", "task", ")", "if", "ensure_capacity?", "@scheduled_task_count", "+=", "1", "@queue", "<<", "[", "args", ",", "task", "]", "else", "if", "@max_queue", "!=", "0", "&&", "@queue", ".", "length", ">=", "@max_queue", "handle_fallback", "(", "args", ",", "task", ")", "end", "end", "prune_pool", "end" ]
A T T E N Z I O N E A R E A P R O T E T T A @!visibility private
[ "A", "T", "T", "E", "N", "Z", "I", "O", "N", "E", "A", "R", "E", "A", "P", "R", "O", "T", "E", "T", "T", "A" ]
c2409bd8cf9c14b967a719810dab5269d69b42de
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/thread_pool/executor.rb#L191-L201
7,276
riddopic/garcun
lib/garcon/task/thread_pool/executor.rb
Garcon.ThreadPoolExecutor.ensure_capacity?
def ensure_capacity? additional = 0 capacity = true if @pool.size < @min_length additional = @min_length - @pool.size elsif @queue.empty? && @queue.num_waiting >= 1 additional = 0 elsif @pool.size == 0 && @min_length == 0 additional = 1 elsif @pool.size < @max_length || @max_length == 0 additional = 1 elsif @max_queue == 0 || @queue.size < @max_queue additional = 0 else capacity = false end additional.times do @pool << create_worker_thread end if additional > 0 @largest_length = [@largest_length, @pool.length].max end capacity end
ruby
def ensure_capacity? additional = 0 capacity = true if @pool.size < @min_length additional = @min_length - @pool.size elsif @queue.empty? && @queue.num_waiting >= 1 additional = 0 elsif @pool.size == 0 && @min_length == 0 additional = 1 elsif @pool.size < @max_length || @max_length == 0 additional = 1 elsif @max_queue == 0 || @queue.size < @max_queue additional = 0 else capacity = false end additional.times do @pool << create_worker_thread end if additional > 0 @largest_length = [@largest_length, @pool.length].max end capacity end
[ "def", "ensure_capacity?", "additional", "=", "0", "capacity", "=", "true", "if", "@pool", ".", "size", "<", "@min_length", "additional", "=", "@min_length", "-", "@pool", ".", "size", "elsif", "@queue", ".", "empty?", "&&", "@queue", ".", "num_waiting", ">=", "1", "additional", "=", "0", "elsif", "@pool", ".", "size", "==", "0", "&&", "@min_length", "==", "0", "additional", "=", "1", "elsif", "@pool", ".", "size", "<", "@max_length", "||", "@max_length", "==", "0", "additional", "=", "1", "elsif", "@max_queue", "==", "0", "||", "@queue", ".", "size", "<", "@max_queue", "additional", "=", "0", "else", "capacity", "=", "false", "end", "additional", ".", "times", "do", "@pool", "<<", "create_worker_thread", "end", "if", "additional", ">", "0", "@largest_length", "=", "[", "@largest_length", ",", "@pool", ".", "length", "]", ".", "max", "end", "capacity", "end" ]
Check the thread pool configuration and determine if the pool has enought capacity to handle the request. Will grow the size of the pool if necessary. @return [Boolean] true if the pool has enough capacity else false @!visibility private
[ "Check", "the", "thread", "pool", "configuration", "and", "determine", "if", "the", "pool", "has", "enought", "capacity", "to", "handle", "the", "request", ".", "Will", "grow", "the", "size", "of", "the", "pool", "if", "necessary", "." ]
c2409bd8cf9c14b967a719810dab5269d69b42de
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/thread_pool/executor.rb#L225-L252
7,277
riddopic/garcun
lib/garcon/task/thread_pool/executor.rb
Garcon.ThreadPoolExecutor.prune_pool
def prune_pool if Garcon.monotonic_time - @gc_interval >= @last_gc_time @pool.delete_if { |worker| worker.dead? } # send :stop for each thread over idletime @pool.select { |worker| @idletime != 0 && Garcon.monotonic_time - @idletime > worker.last_activity }.each { @queue << :stop } @last_gc_time = Garcon.monotonic_time end end
ruby
def prune_pool if Garcon.monotonic_time - @gc_interval >= @last_gc_time @pool.delete_if { |worker| worker.dead? } # send :stop for each thread over idletime @pool.select { |worker| @idletime != 0 && Garcon.monotonic_time - @idletime > worker.last_activity }.each { @queue << :stop } @last_gc_time = Garcon.monotonic_time end end
[ "def", "prune_pool", "if", "Garcon", ".", "monotonic_time", "-", "@gc_interval", ">=", "@last_gc_time", "@pool", ".", "delete_if", "{", "|", "worker", "|", "worker", ".", "dead?", "}", "# send :stop for each thread over idletime", "@pool", ".", "select", "{", "|", "worker", "|", "@idletime", "!=", "0", "&&", "Garcon", ".", "monotonic_time", "-", "@idletime", ">", "worker", ".", "last_activity", "}", ".", "each", "{", "@queue", "<<", ":stop", "}", "@last_gc_time", "=", "Garcon", ".", "monotonic_time", "end", "end" ]
Scan all threads in the pool and reclaim any that are dead or have been idle too long. Will check the last time the pool was pruned and only run if the configured garbage collection interval has passed. @!visibility private
[ "Scan", "all", "threads", "in", "the", "pool", "and", "reclaim", "any", "that", "are", "dead", "or", "have", "been", "idle", "too", "long", ".", "Will", "check", "the", "last", "time", "the", "pool", "was", "pruned", "and", "only", "run", "if", "the", "configured", "garbage", "collection", "interval", "has", "passed", "." ]
c2409bd8cf9c14b967a719810dab5269d69b42de
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/thread_pool/executor.rb#L260-L269
7,278
riddopic/garcun
lib/garcon/task/thread_pool/executor.rb
Garcon.ThreadPoolExecutor.create_worker_thread
def create_worker_thread wrkr = ThreadPoolWorker.new(@queue, self) Thread.new(wrkr, self) do |worker, parent| Thread.current.abort_on_exception = false worker.run parent.on_worker_exit(worker) end return wrkr end
ruby
def create_worker_thread wrkr = ThreadPoolWorker.new(@queue, self) Thread.new(wrkr, self) do |worker, parent| Thread.current.abort_on_exception = false worker.run parent.on_worker_exit(worker) end return wrkr end
[ "def", "create_worker_thread", "wrkr", "=", "ThreadPoolWorker", ".", "new", "(", "@queue", ",", "self", ")", "Thread", ".", "new", "(", "wrkr", ",", "self", ")", "do", "|", "worker", ",", "parent", "|", "Thread", ".", "current", ".", "abort_on_exception", "=", "false", "worker", ".", "run", "parent", ".", "on_worker_exit", "(", "worker", ")", "end", "return", "wrkr", "end" ]
Create a single worker thread to be added to the pool. @return [Thread] the new thread. @!visibility private
[ "Create", "a", "single", "worker", "thread", "to", "be", "added", "to", "the", "pool", "." ]
c2409bd8cf9c14b967a719810dab5269d69b42de
https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/thread_pool/executor.rb#L284-L292
7,279
omegainteractive/comfypress
lib/comfypress/tag.rb
ComfyPress::Tag.InstanceMethods.render
def render ignore = [ComfyPress::Tag::Partial, ComfyPress::Tag::Helper].member?(self.class) ComfyPress::Tag.sanitize_irb(content, ignore) end
ruby
def render ignore = [ComfyPress::Tag::Partial, ComfyPress::Tag::Helper].member?(self.class) ComfyPress::Tag.sanitize_irb(content, ignore) end
[ "def", "render", "ignore", "=", "[", "ComfyPress", "::", "Tag", "::", "Partial", ",", "ComfyPress", "::", "Tag", "::", "Helper", "]", ".", "member?", "(", "self", ".", "class", ")", "ComfyPress", "::", "Tag", ".", "sanitize_irb", "(", "content", ",", "ignore", ")", "end" ]
Content that is used during page rendering. Outputting existing content as a default.
[ "Content", "that", "is", "used", "during", "page", "rendering", ".", "Outputting", "existing", "content", "as", "a", "default", "." ]
3b64699bf16774b636cb13ecd89281f6e2acb264
https://github.com/omegainteractive/comfypress/blob/3b64699bf16774b636cb13ecd89281f6e2acb264/lib/comfypress/tag.rb#L83-L86
7,280
jinx/core
lib/jinx/resource/mergeable.rb
Jinx.Mergeable.merge_attributes
def merge_attributes(other, attributes=nil, matches=nil, &filter) return self if other.nil? or other.equal?(self) attributes = [attributes] if Symbol === attributes attributes ||= self.class.mergeable_attributes # If the source object is not a hash, then convert it to an attribute => value hash. vh = Hasher === other ? other : other.value_hash(attributes) # Merge the Java values hash. vh.each { |pa, value| merge_attribute(pa, value, matches, &filter) } self end
ruby
def merge_attributes(other, attributes=nil, matches=nil, &filter) return self if other.nil? or other.equal?(self) attributes = [attributes] if Symbol === attributes attributes ||= self.class.mergeable_attributes # If the source object is not a hash, then convert it to an attribute => value hash. vh = Hasher === other ? other : other.value_hash(attributes) # Merge the Java values hash. vh.each { |pa, value| merge_attribute(pa, value, matches, &filter) } self end
[ "def", "merge_attributes", "(", "other", ",", "attributes", "=", "nil", ",", "matches", "=", "nil", ",", "&", "filter", ")", "return", "self", "if", "other", ".", "nil?", "or", "other", ".", "equal?", "(", "self", ")", "attributes", "=", "[", "attributes", "]", "if", "Symbol", "===", "attributes", "attributes", "||=", "self", ".", "class", ".", "mergeable_attributes", "# If the source object is not a hash, then convert it to an attribute => value hash.", "vh", "=", "Hasher", "===", "other", "?", "other", ":", "other", ".", "value_hash", "(", "attributes", ")", "# Merge the Java values hash.", "vh", ".", "each", "{", "|", "pa", ",", "value", "|", "merge_attribute", "(", "pa", ",", "value", ",", "matches", ",", "filter", ")", "}", "self", "end" ]
Merges the values of the other attributes into this object and returns self. The other argument can be either a Hash or an object whose class responds to the +mergeable_attributes+ method. The optional attributes argument can be either a single attribute symbol or a collection of attribute symbols. A hash argument consists of attribute name => value associations. For example, given a Mergeable +person+ object with attributes +ssn+ and +children+, the call: person.merge_attributes(:ssn => '555-55-5555', :children => children) is equivalent to: person.ssn ||= '555-55-5555' person.children ||= [] person.children.merge(children, :deep) An unrecognized attribute is ignored. If other is not a Hash, then the other object's attributes values are merged into this object. The default attributes is this mergeable's class {Propertied#mergeable_attributes}. The merge is performed by calling {#merge_attribute} on each attribute with the matches and filter block given to this method. @param [Mergeable, {Symbol => Object}] other the source domain object or value hash to merge from @param [<Symbol>, nil] attributes the attributes to merge (default {Propertied#nondomain_attributes}) @param [{Resource => Resource}, nil] the optional merge source => target reference matches @yield [value] the optional filter block @yieldparam value the source merge attribute value @return [Mergeable] self @raise [ArgumentError] if none of the following are true: * other is a Hash * attributes is non-nil * the other class responds to +mergeable_attributes+
[ "Merges", "the", "values", "of", "the", "other", "attributes", "into", "this", "object", "and", "returns", "self", ".", "The", "other", "argument", "can", "be", "either", "a", "Hash", "or", "an", "object", "whose", "class", "responds", "to", "the", "+", "mergeable_attributes", "+", "method", ".", "The", "optional", "attributes", "argument", "can", "be", "either", "a", "single", "attribute", "symbol", "or", "a", "collection", "of", "attribute", "symbols", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/resource/mergeable.rb#L38-L47
7,281
jamescook/layabout
lib/layabout/slack_request.rb
Layabout.SlackRequest.perform_webhook
def perform_webhook http_request.body = {'text' => params[:text]}.to_json.to_s http_request.query = {'token' => params[:token]} HTTPI.post(http_request) end
ruby
def perform_webhook http_request.body = {'text' => params[:text]}.to_json.to_s http_request.query = {'token' => params[:token]} HTTPI.post(http_request) end
[ "def", "perform_webhook", "http_request", ".", "body", "=", "{", "'text'", "=>", "params", "[", ":text", "]", "}", ".", "to_json", ".", "to_s", "http_request", ".", "query", "=", "{", "'token'", "=>", "params", "[", ":token", "]", "}", "HTTPI", ".", "post", "(", "http_request", ")", "end" ]
Webhooks are handled in a non-compatible way with the other APIs
[ "Webhooks", "are", "handled", "in", "a", "non", "-", "compatible", "way", "with", "the", "other", "APIs" ]
87d4cf3f03cd617fba55112ef5339a43ddf828a3
https://github.com/jamescook/layabout/blob/87d4cf3f03cd617fba55112ef5339a43ddf828a3/lib/layabout/slack_request.rb#L25-L29
7,282
hinrik/ircsupport
lib/ircsupport/case.rb
IRCSupport.Case.irc_upcase!
def irc_upcase!(irc_string, casemapping = :rfc1459) case casemapping when :ascii irc_string.tr!(*@@ascii_map) when :rfc1459 irc_string.tr!(*@@rfc1459_map) when :'strict-rfc1459' irc_string.tr!(*@@strict_rfc1459_map) else raise ArgumentError, "Unsupported casemapping #{casemapping}" end return irc_string end
ruby
def irc_upcase!(irc_string, casemapping = :rfc1459) case casemapping when :ascii irc_string.tr!(*@@ascii_map) when :rfc1459 irc_string.tr!(*@@rfc1459_map) when :'strict-rfc1459' irc_string.tr!(*@@strict_rfc1459_map) else raise ArgumentError, "Unsupported casemapping #{casemapping}" end return irc_string end
[ "def", "irc_upcase!", "(", "irc_string", ",", "casemapping", "=", ":rfc1459", ")", "case", "casemapping", "when", ":ascii", "irc_string", ".", "tr!", "(", "@@ascii_map", ")", "when", ":rfc1459", "irc_string", ".", "tr!", "(", "@@rfc1459_map", ")", "when", ":'", "'", "irc_string", ".", "tr!", "(", "@@strict_rfc1459_map", ")", "else", "raise", "ArgumentError", ",", "\"Unsupported casemapping #{casemapping}\"", "end", "return", "irc_string", "end" ]
Turn a string into IRC upper case, modifying it in place. @param [String] irc_string An IRC string (nickname, channel, etc). @param [Symbol] casemapping An IRC casemapping. @return [String] An upper case version of the IRC string according to the casemapping.
[ "Turn", "a", "string", "into", "IRC", "upper", "case", "modifying", "it", "in", "place", "." ]
d028b7d5ccc604a6af175ee2264c18d25b1f7dff
https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/case.rb#L17-L30
7,283
hinrik/ircsupport
lib/ircsupport/case.rb
IRCSupport.Case.irc_upcase
def irc_upcase(irc_string, casemapping = :rfc1459) result = irc_string.dup irc_upcase!(result, casemapping) return result end
ruby
def irc_upcase(irc_string, casemapping = :rfc1459) result = irc_string.dup irc_upcase!(result, casemapping) return result end
[ "def", "irc_upcase", "(", "irc_string", ",", "casemapping", "=", ":rfc1459", ")", "result", "=", "irc_string", ".", "dup", "irc_upcase!", "(", "result", ",", "casemapping", ")", "return", "result", "end" ]
Turn a string into IRC upper case. @param [String] irc_string An IRC string (nickname, channel, etc) @param [Symbol] casemapping An IRC casemapping @return [String] An upper case version of the IRC string according to the casemapping.
[ "Turn", "a", "string", "into", "IRC", "upper", "case", "." ]
d028b7d5ccc604a6af175ee2264c18d25b1f7dff
https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/case.rb#L37-L41
7,284
hinrik/ircsupport
lib/ircsupport/case.rb
IRCSupport.Case.irc_downcase!
def irc_downcase!(irc_string, casemapping = :rfc1459) case casemapping when :ascii irc_string.tr!(*@@ascii_map.reverse) when :rfc1459 irc_string.tr!(*@@rfc1459_map.reverse) when :'strict-rfc1459' irc_string.tr!(*@@strict_rfc1459_map.reverse) else raise ArgumentError, "Unsupported casemapping #{casemapping}" end return irc_string end
ruby
def irc_downcase!(irc_string, casemapping = :rfc1459) case casemapping when :ascii irc_string.tr!(*@@ascii_map.reverse) when :rfc1459 irc_string.tr!(*@@rfc1459_map.reverse) when :'strict-rfc1459' irc_string.tr!(*@@strict_rfc1459_map.reverse) else raise ArgumentError, "Unsupported casemapping #{casemapping}" end return irc_string end
[ "def", "irc_downcase!", "(", "irc_string", ",", "casemapping", "=", ":rfc1459", ")", "case", "casemapping", "when", ":ascii", "irc_string", ".", "tr!", "(", "@@ascii_map", ".", "reverse", ")", "when", ":rfc1459", "irc_string", ".", "tr!", "(", "@@rfc1459_map", ".", "reverse", ")", "when", ":'", "'", "irc_string", ".", "tr!", "(", "@@strict_rfc1459_map", ".", "reverse", ")", "else", "raise", "ArgumentError", ",", "\"Unsupported casemapping #{casemapping}\"", "end", "return", "irc_string", "end" ]
Turn a string into IRC lower case, modifying it in place. @param [String] irc_string An IRC string (nickname, channel, etc) @param [Symbol] casemapping An IRC casemapping @return [String] A lower case version of the IRC string according to the casemapping
[ "Turn", "a", "string", "into", "IRC", "lower", "case", "modifying", "it", "in", "place", "." ]
d028b7d5ccc604a6af175ee2264c18d25b1f7dff
https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/case.rb#L48-L61
7,285
hinrik/ircsupport
lib/ircsupport/case.rb
IRCSupport.Case.irc_downcase
def irc_downcase(irc_string, casemapping = :rfc1459) result = irc_string.dup irc_downcase!(result, casemapping) return result end
ruby
def irc_downcase(irc_string, casemapping = :rfc1459) result = irc_string.dup irc_downcase!(result, casemapping) return result end
[ "def", "irc_downcase", "(", "irc_string", ",", "casemapping", "=", ":rfc1459", ")", "result", "=", "irc_string", ".", "dup", "irc_downcase!", "(", "result", ",", "casemapping", ")", "return", "result", "end" ]
Turn a string into IRC lower case. @param [String] irc_string An IRC string (nickname, channel, etc). @param [Symbol] casemapping An IRC casemapping. @return [String] A lower case version of the IRC string according to the casemapping
[ "Turn", "a", "string", "into", "IRC", "lower", "case", "." ]
d028b7d5ccc604a6af175ee2264c18d25b1f7dff
https://github.com/hinrik/ircsupport/blob/d028b7d5ccc604a6af175ee2264c18d25b1f7dff/lib/ircsupport/case.rb#L68-L72
7,286
paydro/js_message
lib/js_message/controller_methods.rb
JsMessage.ControllerMethods.render_js_message
def render_js_message(type, hash = {}) unless [ :ok, :redirect, :error ].include?(type) raise "Invalid js_message response type: #{type}" end js_message = { :status => type, :html => nil, :message => nil, :to => nil }.merge(hash) render_options = {:json => js_message} render_options[:status] = 400 if type == :error render(render_options) end
ruby
def render_js_message(type, hash = {}) unless [ :ok, :redirect, :error ].include?(type) raise "Invalid js_message response type: #{type}" end js_message = { :status => type, :html => nil, :message => nil, :to => nil }.merge(hash) render_options = {:json => js_message} render_options[:status] = 400 if type == :error render(render_options) end
[ "def", "render_js_message", "(", "type", ",", "hash", "=", "{", "}", ")", "unless", "[", ":ok", ",", ":redirect", ",", ":error", "]", ".", "include?", "(", "type", ")", "raise", "\"Invalid js_message response type: #{type}\"", "end", "js_message", "=", "{", ":status", "=>", "type", ",", ":html", "=>", "nil", ",", ":message", "=>", "nil", ",", ":to", "=>", "nil", "}", ".", "merge", "(", "hash", ")", "render_options", "=", "{", ":json", "=>", "js_message", "}", "render_options", "[", ":status", "]", "=", "400", "if", "type", "==", ":error", "render", "(", "render_options", ")", "end" ]
Helper to render the js_message response. Pass in a type of message (:ok, :error, :redirect) and any other data you need. Default data attributes in the response are: * html * message * to (used for redirects) Examples: # Send a successful response with some html render_js_message :ok, :html => "<p>It worked!</p>" # Send a redirect render_js_message :redirect, :to => "http://www.google.com" # Send an error response with a message render_js_message :error, :message => "Something broke!" Of course, if you don't need other data sent back in the response this works as well: render_js_message :ok
[ "Helper", "to", "render", "the", "js_message", "response", "." ]
6adda30f204ef917db3f3595f46f0db8208214e1
https://github.com/paydro/js_message/blob/6adda30f204ef917db3f3595f46f0db8208214e1/lib/js_message/controller_methods.rb#L28-L44
7,287
jgoizueta/numerals
lib/numerals/format/base_scaler.rb
Numerals.Format::BaseScaler.scaled_digit
def scaled_digit(group) unless group.size == @base_scale raise "Invalid digits group size for scaled_digit (is #{group.size}; should be #{@base_scale})" end v = 0 group.each do |digit| v *= @setter.base v += digit end v end
ruby
def scaled_digit(group) unless group.size == @base_scale raise "Invalid digits group size for scaled_digit (is #{group.size}; should be #{@base_scale})" end v = 0 group.each do |digit| v *= @setter.base v += digit end v end
[ "def", "scaled_digit", "(", "group", ")", "unless", "group", ".", "size", "==", "@base_scale", "raise", "\"Invalid digits group size for scaled_digit (is #{group.size}; should be #{@base_scale})\"", "end", "v", "=", "0", "group", ".", "each", "do", "|", "digit", "|", "v", "*=", "@setter", ".", "base", "v", "+=", "digit", "end", "v", "end" ]
Return the `scaled_base` digit corresponding to a group of `base_scale` `exponent_base` digits
[ "Return", "the", "scaled_base", "digit", "corresponding", "to", "a", "group", "of", "base_scale", "exponent_base", "digits" ]
a195e75f689af926537f791441bf8d11590c99c0
https://github.com/jgoizueta/numerals/blob/a195e75f689af926537f791441bf8d11590c99c0/lib/numerals/format/base_scaler.rb#L97-L107
7,288
jgoizueta/numerals
lib/numerals/format/base_scaler.rb
Numerals.Format::BaseScaler.grouped_digits
def grouped_digits(digits) unless (digits.size % @base_scale) == 0 raise "Invalid number of digits for group_digits (#{digits.size} is not a multiple of #{@base_scale})" end digits.each_slice(@base_scale).map{|group| scaled_digit(group)} end
ruby
def grouped_digits(digits) unless (digits.size % @base_scale) == 0 raise "Invalid number of digits for group_digits (#{digits.size} is not a multiple of #{@base_scale})" end digits.each_slice(@base_scale).map{|group| scaled_digit(group)} end
[ "def", "grouped_digits", "(", "digits", ")", "unless", "(", "digits", ".", "size", "%", "@base_scale", ")", "==", "0", "raise", "\"Invalid number of digits for group_digits (#{digits.size} is not a multiple of #{@base_scale})\"", "end", "digits", ".", "each_slice", "(", "@base_scale", ")", ".", "map", "{", "|", "group", "|", "scaled_digit", "(", "group", ")", "}", "end" ]
Convert base `exponent_base` digits to base `scaled_base` digits the number of digits must be a multiple of base_scale
[ "Convert", "base", "exponent_base", "digits", "to", "base", "scaled_base", "digits", "the", "number", "of", "digits", "must", "be", "a", "multiple", "of", "base_scale" ]
a195e75f689af926537f791441bf8d11590c99c0
https://github.com/jgoizueta/numerals/blob/a195e75f689af926537f791441bf8d11590c99c0/lib/numerals/format/base_scaler.rb#L111-L116
7,289
nrser/nrser.rb
lib/nrser/meta/lazy_attr.rb
NRSER.LazyAttr.call
def call target_method, receiver, *args, &block unless target_method.parameters.empty? raise NRSER::ArgumentError.new \ "{NRSER::LazyAttr} can only decorate methods with 0 params", receiver: receiver, target_method: target_method end unless args.empty? raise NRSER::ArgumentError.new \ "wrong number of arguments for", target_method, "(given", args.length, "expected 0)", receiver: receiver, target_method: target_method end unless block.nil? raise NRSER::ArgumentError.new \ "wrong number of arguments (given #{ args.length }, expected 0)", receiver: receiver, target_method: target_method end var_name = self.class.instance_var_name target_method unless receiver.instance_variable_defined? var_name receiver.instance_variable_set var_name, target_method.call end receiver.instance_variable_get var_name end
ruby
def call target_method, receiver, *args, &block unless target_method.parameters.empty? raise NRSER::ArgumentError.new \ "{NRSER::LazyAttr} can only decorate methods with 0 params", receiver: receiver, target_method: target_method end unless args.empty? raise NRSER::ArgumentError.new \ "wrong number of arguments for", target_method, "(given", args.length, "expected 0)", receiver: receiver, target_method: target_method end unless block.nil? raise NRSER::ArgumentError.new \ "wrong number of arguments (given #{ args.length }, expected 0)", receiver: receiver, target_method: target_method end var_name = self.class.instance_var_name target_method unless receiver.instance_variable_defined? var_name receiver.instance_variable_set var_name, target_method.call end receiver.instance_variable_get var_name end
[ "def", "call", "target_method", ",", "receiver", ",", "*", "args", ",", "&", "block", "unless", "target_method", ".", "parameters", ".", "empty?", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"{NRSER::LazyAttr} can only decorate methods with 0 params\"", ",", "receiver", ":", "receiver", ",", "target_method", ":", "target_method", "end", "unless", "args", ".", "empty?", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"wrong number of arguments for\"", ",", "target_method", ",", "\"(given\"", ",", "args", ".", "length", ",", "\"expected 0)\"", ",", "receiver", ":", "receiver", ",", "target_method", ":", "target_method", "end", "unless", "block", ".", "nil?", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"wrong number of arguments (given #{ args.length }, expected 0)\"", ",", "receiver", ":", "receiver", ",", "target_method", ":", "target_method", "end", "var_name", "=", "self", ".", "class", ".", "instance_var_name", "target_method", "unless", "receiver", ".", "instance_variable_defined?", "var_name", "receiver", ".", "instance_variable_set", "var_name", ",", "target_method", ".", "call", "end", "receiver", ".", "instance_variable_get", "var_name", "end" ]
.instance_var_name Execute the decorator. @param [Method] target_method The decorated method, already bound to the receiver. The `method_decorators` gem calls this `orig`, but I thought `target_method` made more sense. @param [*] receiver The object that will receive the call to `target`. The `method_decorators` gem calls this `this`, but I thought `receiver` made more sense. It's just `target.receiver`, but the API is how it is. @param [Array] args Any arguments the decorated method was called with. @param [Proc?] block The block the decorated method was called with (if any). @return Whatever `target_method` returns.
[ ".", "instance_var_name", "Execute", "the", "decorator", "." ]
7db9a729ec65894dfac13fd50851beae8b809738
https://github.com/nrser/nrser.rb/blob/7db9a729ec65894dfac13fd50851beae8b809738/lib/nrser/meta/lazy_attr.rb#L75-L106
7,290
renz45/table_me
lib/table_me/builder.rb
TableMe.Builder.column
def column name,options = {}, &block @columns << TableMe::Column.new(name,options, &block) @names << name end
ruby
def column name,options = {}, &block @columns << TableMe::Column.new(name,options, &block) @names << name end
[ "def", "column", "name", ",", "options", "=", "{", "}", ",", "&", "block", "@columns", "<<", "TableMe", "::", "Column", ".", "new", "(", "name", ",", "options", ",", "block", ")", "@names", "<<", "name", "end" ]
Define a column
[ "Define", "a", "column" ]
a04bd7c26497828b2f8f0178631253b6749025cf
https://github.com/renz45/table_me/blob/a04bd7c26497828b2f8f0178631253b6749025cf/lib/table_me/builder.rb#L17-L20
7,291
bossmc/milenage
lib/milenage.rb
Milenage.Kernel.op=
def op=(op) fail "OP must be 128 bits" unless op.each_byte.to_a.length == 16 @opc = xor(enc(op), op) end
ruby
def op=(op) fail "OP must be 128 bits" unless op.each_byte.to_a.length == 16 @opc = xor(enc(op), op) end
[ "def", "op", "=", "(", "op", ")", "fail", "\"OP must be 128 bits\"", "unless", "op", ".", "each_byte", ".", "to_a", ".", "length", "==", "16", "@opc", "=", "xor", "(", "enc", "(", "op", ")", ",", "op", ")", "end" ]
Create a single user's kernel instance, remember to set OP or OPc before attempting to use the security functions. To change the algorithm variables as described in TS 35.206 subclass this Kernel class and modify `@c`, `@r` or `@kernel` after calling super. E.G. class MyKernel < Kernel def initialize(key) super @r = [10, 20, 30, 40, 50] end end When doing this, `@kernel` should be set to a 128-bit MAC function with the same API as `OpenSSL::Cipher`, if this is not the case, you may need to overload {#enc} as well to match the API. Set the Operator Variant Algorithm Configuration field. Either this or {#opc=} must be called before any of the security functions are evaluated.
[ "Create", "a", "single", "user", "s", "kernel", "instance", "remember", "to", "set", "OP", "or", "OPc", "before", "attempting", "to", "use", "the", "security", "functions", "." ]
7966c0910f66232ea53a50512fd80d3a6b3ad18a
https://github.com/bossmc/milenage/blob/7966c0910f66232ea53a50512fd80d3a6b3ad18a/lib/milenage.rb#L59-L62
7,292
dbalatero/typhoeus_spec_cache
lib/typhoeus/spec_cache.rb
Typhoeus.SpecCache.remove_unnecessary_cache_files!
def remove_unnecessary_cache_files! current_keys = cache_files.map do |file| get_cache_key_from_filename(file) end inmemory_keys = responses.keys unneeded_keys = current_keys - inmemory_keys unneeded_keys.each do |key| File.unlink(filepath_for(key)) end end
ruby
def remove_unnecessary_cache_files! current_keys = cache_files.map do |file| get_cache_key_from_filename(file) end inmemory_keys = responses.keys unneeded_keys = current_keys - inmemory_keys unneeded_keys.each do |key| File.unlink(filepath_for(key)) end end
[ "def", "remove_unnecessary_cache_files!", "current_keys", "=", "cache_files", ".", "map", "do", "|", "file", "|", "get_cache_key_from_filename", "(", "file", ")", "end", "inmemory_keys", "=", "responses", ".", "keys", "unneeded_keys", "=", "current_keys", "-", "inmemory_keys", "unneeded_keys", ".", "each", "do", "|", "key", "|", "File", ".", "unlink", "(", "filepath_for", "(", "key", ")", ")", "end", "end" ]
Removes any cache files that aren't needed anymore
[ "Removes", "any", "cache", "files", "that", "aren", "t", "needed", "anymore" ]
7141c311c76fe001428c143d90ad927bd8b178e9
https://github.com/dbalatero/typhoeus_spec_cache/blob/7141c311c76fe001428c143d90ad927bd8b178e9/lib/typhoeus/spec_cache.rb#L35-L45
7,293
dbalatero/typhoeus_spec_cache
lib/typhoeus/spec_cache.rb
Typhoeus.SpecCache.read_cache_fixtures!
def read_cache_fixtures! files = cache_files files.each do |file| cache_key = get_cache_key_from_filename(file) responses[cache_key] = Marshal.load(File.read(file)) end end
ruby
def read_cache_fixtures! files = cache_files files.each do |file| cache_key = get_cache_key_from_filename(file) responses[cache_key] = Marshal.load(File.read(file)) end end
[ "def", "read_cache_fixtures!", "files", "=", "cache_files", "files", ".", "each", "do", "|", "file", "|", "cache_key", "=", "get_cache_key_from_filename", "(", "file", ")", "responses", "[", "cache_key", "]", "=", "Marshal", ".", "load", "(", "File", ".", "read", "(", "file", ")", ")", "end", "end" ]
Reads in the cache fixture files to in-memory cache.
[ "Reads", "in", "the", "cache", "fixture", "files", "to", "in", "-", "memory", "cache", "." ]
7141c311c76fe001428c143d90ad927bd8b178e9
https://github.com/dbalatero/typhoeus_spec_cache/blob/7141c311c76fe001428c143d90ad927bd8b178e9/lib/typhoeus/spec_cache.rb#L48-L54
7,294
dbalatero/typhoeus_spec_cache
lib/typhoeus/spec_cache.rb
Typhoeus.SpecCache.dump_cache_fixtures!
def dump_cache_fixtures! responses.each do |cache_key, response| path = filepath_for(cache_key) unless File.exist?(path) File.open(path, "wb") do |fp| fp.write(Marshal.dump(response)) end end end end
ruby
def dump_cache_fixtures! responses.each do |cache_key, response| path = filepath_for(cache_key) unless File.exist?(path) File.open(path, "wb") do |fp| fp.write(Marshal.dump(response)) end end end end
[ "def", "dump_cache_fixtures!", "responses", ".", "each", "do", "|", "cache_key", ",", "response", "|", "path", "=", "filepath_for", "(", "cache_key", ")", "unless", "File", ".", "exist?", "(", "path", ")", "File", ".", "open", "(", "path", ",", "\"wb\"", ")", "do", "|", "fp", "|", "fp", ".", "write", "(", "Marshal", ".", "dump", "(", "response", ")", ")", "end", "end", "end", "end" ]
Dumps out any cached items to disk.
[ "Dumps", "out", "any", "cached", "items", "to", "disk", "." ]
7141c311c76fe001428c143d90ad927bd8b178e9
https://github.com/dbalatero/typhoeus_spec_cache/blob/7141c311c76fe001428c143d90ad927bd8b178e9/lib/typhoeus/spec_cache.rb#L57-L66
7,295
mrsimonfletcher/roroacms
app/helpers/roroacms/admin_roroa_helper.rb
Roroacms.AdminRoroaHelper.get_theme_options
def get_theme_options hash = [] Dir.glob("#{Rails.root}/app/views/themes/*/") do |themes| opt = themes.split('/').last if File.exists?("#{themes}theme.yml") info = YAML.load(File.read("#{themes}theme.yml")) hash << info if !info['name'].blank? && !info['author'].blank? && !info['foldername'].blank? && !info['view_extension'].blank? end end hash end
ruby
def get_theme_options hash = [] Dir.glob("#{Rails.root}/app/views/themes/*/") do |themes| opt = themes.split('/').last if File.exists?("#{themes}theme.yml") info = YAML.load(File.read("#{themes}theme.yml")) hash << info if !info['name'].blank? && !info['author'].blank? && !info['foldername'].blank? && !info['view_extension'].blank? end end hash end
[ "def", "get_theme_options", "hash", "=", "[", "]", "Dir", ".", "glob", "(", "\"#{Rails.root}/app/views/themes/*/\"", ")", "do", "|", "themes", "|", "opt", "=", "themes", ".", "split", "(", "'/'", ")", ".", "last", "if", "File", ".", "exists?", "(", "\"#{themes}theme.yml\"", ")", "info", "=", "YAML", ".", "load", "(", "File", ".", "read", "(", "\"#{themes}theme.yml\"", ")", ")", "hash", "<<", "info", "if", "!", "info", "[", "'name'", "]", ".", "blank?", "&&", "!", "info", "[", "'author'", "]", ".", "blank?", "&&", "!", "info", "[", "'foldername'", "]", ".", "blank?", "&&", "!", "info", "[", "'view_extension'", "]", ".", "blank?", "end", "end", "hash", "end" ]
returns a hash of the different themes as a hash with the details kept in the theme.yml file
[ "returns", "a", "hash", "of", "the", "different", "themes", "as", "a", "hash", "with", "the", "details", "kept", "in", "the", "theme", ".", "yml", "file" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/admin_roroa_helper.rb#L15-L27
7,296
mrsimonfletcher/roroacms
app/helpers/roroacms/admin_roroa_helper.rb
Roroacms.AdminRoroaHelper.get_templates
def get_templates hash = [] current_theme = Setting.get('theme_folder') Dir.glob("#{Rails.root}/app/views/themes/#{current_theme}/template-*.html.erb") do |my_text_file| opt = my_text_file.split('/').last opt['template-'] = '' opt['.html.erb'] = '' # strips out the template- and .html.erb extention and returns the middle as the template name for the admin hash << opt.titleize end hash end
ruby
def get_templates hash = [] current_theme = Setting.get('theme_folder') Dir.glob("#{Rails.root}/app/views/themes/#{current_theme}/template-*.html.erb") do |my_text_file| opt = my_text_file.split('/').last opt['template-'] = '' opt['.html.erb'] = '' # strips out the template- and .html.erb extention and returns the middle as the template name for the admin hash << opt.titleize end hash end
[ "def", "get_templates", "hash", "=", "[", "]", "current_theme", "=", "Setting", ".", "get", "(", "'theme_folder'", ")", "Dir", ".", "glob", "(", "\"#{Rails.root}/app/views/themes/#{current_theme}/template-*.html.erb\"", ")", "do", "|", "my_text_file", "|", "opt", "=", "my_text_file", ".", "split", "(", "'/'", ")", ".", "last", "opt", "[", "'template-'", "]", "=", "''", "opt", "[", "'.html.erb'", "]", "=", "''", "# strips out the template- and .html.erb extention and returns the middle as the template name for the admin", "hash", "<<", "opt", ".", "titleize", "end", "hash", "end" ]
retuns a hash of the template files within the current theme
[ "retuns", "a", "hash", "of", "the", "template", "files", "within", "the", "current", "theme" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/admin_roroa_helper.rb#L41-L54
7,297
mrsimonfletcher/roroacms
app/helpers/roroacms/admin_roroa_helper.rb
Roroacms.AdminRoroaHelper.theme_exists
def theme_exists if !Dir.exists?("app/views/themes/#{Setting.get('theme_folder')}/") html = "<div class='alert alert-danger'><strong>" + I18n.t("helpers.admin_roroa_helper.theme_exists.warning") + "!</strong> " + I18n.t("helpers.admin_roroa_helper.theme_exists.message") + "!</div>" render :inline => html.html_safe end end
ruby
def theme_exists if !Dir.exists?("app/views/themes/#{Setting.get('theme_folder')}/") html = "<div class='alert alert-danger'><strong>" + I18n.t("helpers.admin_roroa_helper.theme_exists.warning") + "!</strong> " + I18n.t("helpers.admin_roroa_helper.theme_exists.message") + "!</div>" render :inline => html.html_safe end end
[ "def", "theme_exists", "if", "!", "Dir", ".", "exists?", "(", "\"app/views/themes/#{Setting.get('theme_folder')}/\"", ")", "html", "=", "\"<div class='alert alert-danger'><strong>\"", "+", "I18n", ".", "t", "(", "\"helpers.admin_roroa_helper.theme_exists.warning\"", ")", "+", "\"!</strong> \"", "+", "I18n", ".", "t", "(", "\"helpers.admin_roroa_helper.theme_exists.message\"", ")", "+", "\"!</div>\"", "render", ":inline", "=>", "html", ".", "html_safe", "end", "end" ]
checks if the current theme being used actually exists. If not it will return an error message to the user
[ "checks", "if", "the", "current", "theme", "being", "used", "actually", "exists", ".", "If", "not", "it", "will", "return", "an", "error", "message", "to", "the", "user" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/admin_roroa_helper.rb#L126-L133
7,298
mrsimonfletcher/roroacms
app/helpers/roroacms/admin_roroa_helper.rb
Roroacms.AdminRoroaHelper.get_notifications
def get_notifications html = '' if flash[:error] html += "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>x</button><strong>" + I18n.t("helpers.view_helper.generic.flash.error") + "!</strong> #{flash[:error]}</div>" end if flash[:notice] html += "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>x</button><strong>" + I18n.t("helpers.view_helper.generic.flash.success") + "!</strong> #{flash[:notice]}</div>" end render :inline => html.html_safe end
ruby
def get_notifications html = '' if flash[:error] html += "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>x</button><strong>" + I18n.t("helpers.view_helper.generic.flash.error") + "!</strong> #{flash[:error]}</div>" end if flash[:notice] html += "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>x</button><strong>" + I18n.t("helpers.view_helper.generic.flash.success") + "!</strong> #{flash[:notice]}</div>" end render :inline => html.html_safe end
[ "def", "get_notifications", "html", "=", "''", "if", "flash", "[", ":error", "]", "html", "+=", "\"<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>x</button><strong>\"", "+", "I18n", ".", "t", "(", "\"helpers.view_helper.generic.flash.error\"", ")", "+", "\"!</strong> #{flash[:error]}</div>\"", "end", "if", "flash", "[", ":notice", "]", "html", "+=", "\"<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>x</button><strong>\"", "+", "I18n", ".", "t", "(", "\"helpers.view_helper.generic.flash.success\"", ")", "+", "\"!</strong> #{flash[:notice]}</div>\"", "end", "render", ":inline", "=>", "html", ".", "html_safe", "end" ]
Returns generic notifications if the flash data exists
[ "Returns", "generic", "notifications", "if", "the", "flash", "data", "exists" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/admin_roroa_helper.rb#L302-L315
7,299
mrsimonfletcher/roroacms
app/helpers/roroacms/admin_roroa_helper.rb
Roroacms.AdminRoroaHelper.append_application_menu
def append_application_menu html = '' Roroacms.append_menu.each do |f| html += (render :partial => 'roroacms/admin/partials/append_sidebar_menu', :locals => { :menu_block => f }) end html.html_safe end
ruby
def append_application_menu html = '' Roroacms.append_menu.each do |f| html += (render :partial => 'roroacms/admin/partials/append_sidebar_menu', :locals => { :menu_block => f }) end html.html_safe end
[ "def", "append_application_menu", "html", "=", "''", "Roroacms", ".", "append_menu", ".", "each", "do", "|", "f", "|", "html", "+=", "(", "render", ":partial", "=>", "'roroacms/admin/partials/append_sidebar_menu'", ",", ":locals", "=>", "{", ":menu_block", "=>", "f", "}", ")", "end", "html", ".", "html_safe", "end" ]
appends any extra menu items that are set in the applications configurations
[ "appends", "any", "extra", "menu", "items", "that", "are", "set", "in", "the", "applications", "configurations" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/admin_roroa_helper.rb#L339-L345