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
6,700
kenjij/kajiki
lib/kajiki/runner.rb
Kajiki.Runner.stop
def stop(&block) block.call('stop') unless block.nil? pid = read_pid fail 'No valid PID file.' unless pid && pid > 0 Process.kill('TERM', pid) delete_pid puts 'Process terminated.' end
ruby
def stop(&block) block.call('stop') unless block.nil? pid = read_pid fail 'No valid PID file.' unless pid && pid > 0 Process.kill('TERM', pid) delete_pid puts 'Process terminated.' end
[ "def", "stop", "(", "&", "block", ")", "block", ".", "call", "(", "'stop'", ")", "unless", "block", ".", "nil?", "pid", "=", "read_pid", "fail", "'No valid PID file.'", "unless", "pid", "&&", "pid", ">", "0", "Process", ".", "kill", "(", "'TERM'", ",", "pid", ")", "delete_pid", "puts", "'Process terminated.'", "end" ]
Stop the process. @param [Block] will execute prior to shutdown, if given.
[ "Stop", "the", "process", "." ]
9b036f2741d515e9bfd158571a813987516d89ed
https://github.com/kenjij/kajiki/blob/9b036f2741d515e9bfd158571a813987516d89ed/lib/kajiki/runner.rb#L67-L74
6,701
raygao/rforce-raygao
lib/rforce/soap_pullable.rb
RForce.SoapPullable.local
def local(tag) first, second = tag.split ':' return first if second.nil? @namespaces.include?(first) ? second : tag end
ruby
def local(tag) first, second = tag.split ':' return first if second.nil? @namespaces.include?(first) ? second : tag end
[ "def", "local", "(", "tag", ")", "first", ",", "second", "=", "tag", ".", "split", "':'", "return", "first", "if", "second", ".", "nil?", "@namespaces", ".", "include?", "(", "first", ")", "?", "second", ":", "tag", "end" ]
Split off the local name portion of an XML tag.
[ "Split", "off", "the", "local", "name", "portion", "of", "an", "XML", "tag", "." ]
21bf35db2844f3e43b1cf8d290bfc0f413384fbf
https://github.com/raygao/rforce-raygao/blob/21bf35db2844f3e43b1cf8d290bfc0f413384fbf/lib/rforce/soap_pullable.rb#L8-L12
6,702
khiemns54/sp2db
lib/sp2db/base_table.rb
Sp2db.BaseTable.to_csv
def to_csv data attributes = data.first&.keys || [] CSV.generate(headers: true) do |csv| csv << attributes data.each do |row| csv << attributes.map do |att| row[att] end end end end
ruby
def to_csv data attributes = data.first&.keys || [] CSV.generate(headers: true) do |csv| csv << attributes data.each do |row| csv << attributes.map do |att| row[att] end end end end
[ "def", "to_csv", "data", "attributes", "=", "data", ".", "first", "&.", "keys", "||", "[", "]", "CSV", ".", "generate", "(", "headers", ":", "true", ")", "do", "|", "csv", "|", "csv", "<<", "attributes", "data", ".", "each", "do", "|", "row", "|", "csv", "<<", "attributes", ".", "map", "do", "|", "att", "|", "row", "[", "att", "]", "end", "end", "end", "end" ]
Array of hash data to csv format
[ "Array", "of", "hash", "data", "to", "csv", "format" ]
76c78df07ea19d6f1b5ff2e883ae206a0e94de27
https://github.com/khiemns54/sp2db/blob/76c78df07ea19d6f1b5ff2e883ae206a0e94de27/lib/sp2db/base_table.rb#L113-L125
6,703
khiemns54/sp2db
lib/sp2db/base_table.rb
Sp2db.BaseTable.standardize_cell_val
def standardize_cell_val v v = ((float = Float(v)) && (float % 1.0 == 0) ? float.to_i : float) rescue v v = v.force_encoding("UTF-8") if v.is_a?(String) v end
ruby
def standardize_cell_val v v = ((float = Float(v)) && (float % 1.0 == 0) ? float.to_i : float) rescue v v = v.force_encoding("UTF-8") if v.is_a?(String) v end
[ "def", "standardize_cell_val", "v", "v", "=", "(", "(", "float", "=", "Float", "(", "v", ")", ")", "&&", "(", "float", "%", "1.0", "==", "0", ")", "?", "float", ".", "to_i", ":", "float", ")", "rescue", "v", "v", "=", "v", ".", "force_encoding", "(", "\"UTF-8\"", ")", "if", "v", ".", "is_a?", "(", "String", ")", "v", "end" ]
Convert number string to number
[ "Convert", "number", "string", "to", "number" ]
76c78df07ea19d6f1b5ff2e883ae206a0e94de27
https://github.com/khiemns54/sp2db/blob/76c78df07ea19d6f1b5ff2e883ae206a0e94de27/lib/sp2db/base_table.rb#L161-L165
6,704
khiemns54/sp2db
lib/sp2db/base_table.rb
Sp2db.BaseTable.raw_filter
def raw_filter raw_data, opts={} raw_header = raw_data[header_row].map.with_index do |h, idx| is_valid = valid_header?(h) { idx: idx, is_remove: !is_valid, is_required: require_header?(h), name: is_valid && h.gsub(/\s*/, '').gsub(/!/, '').downcase } end rows = raw_data[(header_row + 1)..-1].map.with_index do |raw, rdx| row = {}.with_indifferent_access raw_header.each do |h| val = raw[h[:idx]] next if h[:is_remove] if h[:is_required] && val.blank? row = {} break end row[h[:name]] = standardize_cell_val val end next if row.values.all?(&:blank?) row[:id] = rdx + 1 if find_columns.include?(:id) && row[:id].blank? row end.compact .reject(&:blank?) rows = rows.select do |row| if required_columns.present? required_columns.all? {|col| row[col].present? } else true end end rows end
ruby
def raw_filter raw_data, opts={} raw_header = raw_data[header_row].map.with_index do |h, idx| is_valid = valid_header?(h) { idx: idx, is_remove: !is_valid, is_required: require_header?(h), name: is_valid && h.gsub(/\s*/, '').gsub(/!/, '').downcase } end rows = raw_data[(header_row + 1)..-1].map.with_index do |raw, rdx| row = {}.with_indifferent_access raw_header.each do |h| val = raw[h[:idx]] next if h[:is_remove] if h[:is_required] && val.blank? row = {} break end row[h[:name]] = standardize_cell_val val end next if row.values.all?(&:blank?) row[:id] = rdx + 1 if find_columns.include?(:id) && row[:id].blank? row end.compact .reject(&:blank?) rows = rows.select do |row| if required_columns.present? required_columns.all? {|col| row[col].present? } else true end end rows end
[ "def", "raw_filter", "raw_data", ",", "opts", "=", "{", "}", "raw_header", "=", "raw_data", "[", "header_row", "]", ".", "map", ".", "with_index", "do", "|", "h", ",", "idx", "|", "is_valid", "=", "valid_header?", "(", "h", ")", "{", "idx", ":", "idx", ",", "is_remove", ":", "!", "is_valid", ",", "is_required", ":", "require_header?", "(", "h", ")", ",", "name", ":", "is_valid", "&&", "h", ".", "gsub", "(", "/", "\\s", "/", ",", "''", ")", ".", "gsub", "(", "/", "/", ",", "''", ")", ".", "downcase", "}", "end", "rows", "=", "raw_data", "[", "(", "header_row", "+", "1", ")", "..", "-", "1", "]", ".", "map", ".", "with_index", "do", "|", "raw", ",", "rdx", "|", "row", "=", "{", "}", ".", "with_indifferent_access", "raw_header", ".", "each", "do", "|", "h", "|", "val", "=", "raw", "[", "h", "[", ":idx", "]", "]", "next", "if", "h", "[", ":is_remove", "]", "if", "h", "[", ":is_required", "]", "&&", "val", ".", "blank?", "row", "=", "{", "}", "break", "end", "row", "[", "h", "[", ":name", "]", "]", "=", "standardize_cell_val", "val", "end", "next", "if", "row", ".", "values", ".", "all?", "(", ":blank?", ")", "row", "[", ":id", "]", "=", "rdx", "+", "1", "if", "find_columns", ".", "include?", "(", ":id", ")", "&&", "row", "[", ":id", "]", ".", "blank?", "row", "end", ".", "compact", ".", "reject", "(", ":blank?", ")", "rows", "=", "rows", ".", "select", "do", "|", "row", "|", "if", "required_columns", ".", "present?", "required_columns", ".", "all?", "{", "|", "col", "|", "row", "[", "col", "]", ".", "present?", "}", "else", "true", "end", "end", "rows", "end" ]
Remove uncessary columns and invalid rows from csv format data
[ "Remove", "uncessary", "columns", "and", "invalid", "rows", "from", "csv", "format", "data" ]
76c78df07ea19d6f1b5ff2e883ae206a0e94de27
https://github.com/khiemns54/sp2db/blob/76c78df07ea19d6f1b5ff2e883ae206a0e94de27/lib/sp2db/base_table.rb#L176-L215
6,705
ihoka/friendly-attributes
lib/friendly_attributes/class_methods.rb
FriendlyAttributes.ClassMethods.friendly_details
def friendly_details(*args, &block) klass = args.shift options = args.extract_options! attributes = args.extract_options! if attributes.empty? attributes = options options = {} end DetailsDelegator.new(klass, self, attributes, options, &block).tap do |dd| dd.setup_delegated_attributes dd.instance_eval(&block) if block_given? end end
ruby
def friendly_details(*args, &block) klass = args.shift options = args.extract_options! attributes = args.extract_options! if attributes.empty? attributes = options options = {} end DetailsDelegator.new(klass, self, attributes, options, &block).tap do |dd| dd.setup_delegated_attributes dd.instance_eval(&block) if block_given? end end
[ "def", "friendly_details", "(", "*", "args", ",", "&", "block", ")", "klass", "=", "args", ".", "shift", "options", "=", "args", ".", "extract_options!", "attributes", "=", "args", ".", "extract_options!", "if", "attributes", ".", "empty?", "attributes", "=", "options", "options", "=", "{", "}", "end", "DetailsDelegator", ".", "new", "(", "klass", ",", "self", ",", "attributes", ",", "options", ",", "block", ")", ".", "tap", "do", "|", "dd", "|", "dd", ".", "setup_delegated_attributes", "dd", ".", "instance_eval", "(", "block", ")", "if", "block_given?", "end", "end" ]
Configure a Friendly Base model associated with an ActiveRecord model. @overload friendly_details(klass, attributes) @param [Class] klass FriendlyAttributes::Base instance used to extend the ActiveRecord model @param [Hash] attributes hash of types and attributes names with which to extend the ActiveRecord, through FriendlyAttributes::Base @overload friendly_details(klass, attributes, options) @param [Hash] options configuration options for extending the FriendlyAttributes extension (see {DetailsDelegator#initialize}) @return [DetailsDelegator]
[ "Configure", "a", "Friendly", "Base", "model", "associated", "with", "an", "ActiveRecord", "model", "." ]
52c70a4028aa915f791d121bcf905a01989cad84
https://github.com/ihoka/friendly-attributes/blob/52c70a4028aa915f791d121bcf905a01989cad84/lib/friendly_attributes/class_methods.rb#L13-L26
6,706
codescrum/bebox
lib/bebox/cli.rb
Bebox.Cli.inside_project?
def inside_project? project_found = false cwd = Pathname(Dir.pwd) home_directory = File.expand_path('~') cwd.ascend do |current_path| project_found = File.file?("#{current_path.to_s}/.bebox") self.project_root = current_path.to_s if project_found break if project_found || (current_path.to_s == home_directory) end project_found end
ruby
def inside_project? project_found = false cwd = Pathname(Dir.pwd) home_directory = File.expand_path('~') cwd.ascend do |current_path| project_found = File.file?("#{current_path.to_s}/.bebox") self.project_root = current_path.to_s if project_found break if project_found || (current_path.to_s == home_directory) end project_found end
[ "def", "inside_project?", "project_found", "=", "false", "cwd", "=", "Pathname", "(", "Dir", ".", "pwd", ")", "home_directory", "=", "File", ".", "expand_path", "(", "'~'", ")", "cwd", ".", "ascend", "do", "|", "current_path", "|", "project_found", "=", "File", ".", "file?", "(", "\"#{current_path.to_s}/.bebox\"", ")", "self", ".", "project_root", "=", "current_path", ".", "to_s", "if", "project_found", "break", "if", "project_found", "||", "(", "current_path", ".", "to_s", "==", "home_directory", ")", "end", "project_found", "end" ]
Search recursively for .bebox file to see if current directory is a bebox project or not
[ "Search", "recursively", "for", ".", "bebox", "file", "to", "see", "if", "current", "directory", "is", "a", "bebox", "project", "or", "not" ]
0d19315847103341e599d32837ab0bd75524e5be
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/cli.rb#L31-L41
6,707
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_post
def get_post(user_name, intra_hash) response = @conn.get @url_post.expand({ :user_name => user_name, :intra_hash => intra_hash, :format => @format }) if @parse attributes = JSON.parse(response.body) return Post.new(attributes["post"]) end return response.body end
ruby
def get_post(user_name, intra_hash) response = @conn.get @url_post.expand({ :user_name => user_name, :intra_hash => intra_hash, :format => @format }) if @parse attributes = JSON.parse(response.body) return Post.new(attributes["post"]) end return response.body end
[ "def", "get_post", "(", "user_name", ",", "intra_hash", ")", "response", "=", "@conn", ".", "get", "@url_post", ".", "expand", "(", "{", ":user_name", "=>", "user_name", ",", ":intra_hash", "=>", "intra_hash", ",", ":format", "=>", "@format", "}", ")", "if", "@parse", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "return", "Post", ".", "new", "(", "attributes", "[", "\"post\"", "]", ")", "end", "return", "response", ".", "body", "end" ]
Initializes the client with the given credentials. @param user_name [String] the name of the user account used for accessing the API @param api_key [String] the API key corresponding to the user account - can be obtained from http://www.bibsonomy.org/settings?selTab=1 @param format [String] The requested return format. One of: 'xml', 'json', 'ruby', 'csl', 'bibtex'. The default is 'ruby' which returns Ruby objects defined by this library. Currently, 'csl' and 'bibtex' are only available for publications. Get a single post @param user_name [String] the name of the post's owner @param intra_hash [String] the intrag hash of the post @return [BibSonomy::Post, String] the requested post
[ "Initializes", "the", "client", "with", "the", "given", "credentials", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L78-L90
6,708
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_posts_for_user
def get_posts_for_user(user_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) return get_posts("user", user_name, resource_type, tags, start, endc) end
ruby
def get_posts_for_user(user_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) return get_posts("user", user_name, resource_type, tags, start, endc) end
[ "def", "get_posts_for_user", "(", "user_name", ",", "resource_type", ",", "tags", "=", "nil", ",", "start", "=", "0", ",", "endc", "=", "$MAX_POSTS_PER_REQUEST", ")", "return", "get_posts", "(", "\"user\"", ",", "user_name", ",", "resource_type", ",", "tags", ",", "start", ",", "endc", ")", "end" ]
Get posts owned by a user, optionally filtered by tags. @param user_name [String] the name of the posts' owner @param resource_type [String] the type of the post. Currently supported are 'bookmark' and 'publication'. @param tags [Array<String>] the tags that all posts must contain (can be empty) @param start [Integer] number of first post to download @param endc [Integer] number of last post to download @return [Array<BibSonomy::Post>, String] the requested posts
[ "Get", "posts", "owned", "by", "a", "user", "optionally", "filtered", "by", "tags", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L101-L103
6,709
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_posts_for_group
def get_posts_for_group(group_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) return get_posts("group", group_name, resource_type, tags, start, endc) end
ruby
def get_posts_for_group(group_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) return get_posts("group", group_name, resource_type, tags, start, endc) end
[ "def", "get_posts_for_group", "(", "group_name", ",", "resource_type", ",", "tags", "=", "nil", ",", "start", "=", "0", ",", "endc", "=", "$MAX_POSTS_PER_REQUEST", ")", "return", "get_posts", "(", "\"group\"", ",", "group_name", ",", "resource_type", ",", "tags", ",", "start", ",", "endc", ")", "end" ]
Get the posts of the users of a group, optionally filtered by tags. @param group_name [String] the name of the group @param resource_type [String] the type of the post. Currently supported are 'bookmark' and 'publication'. @param tags [Array<String>] the tags that all posts must contain (can be empty) @param start [Integer] number of first post to download @param endc [Integer] number of last post to download @return [Array<BibSonomy::Post>, String] the requested posts
[ "Get", "the", "posts", "of", "the", "users", "of", "a", "group", "optionally", "filtered", "by", "tags", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L114-L116
6,710
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_posts
def get_posts(grouping, name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) url = @url_posts.partial_expand({ :format => @format, :resourcetype => get_resource_type(resource_type), :start => start, :end => endc }) # decide what to get if grouping == "user" url = url.partial_expand({:user => name}) elsif grouping == "group" url = url.partial_expand({:group => name}) end # add tags, if requested if tags != nil url = url.partial_expand({:tags => tags.join(" ")}) end response = @conn.get url.expand({}) if @parse posts = JSON.parse(response.body)["posts"]["post"] return posts.map { |attributes| Post.new(attributes) } end return response.body end
ruby
def get_posts(grouping, name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST) url = @url_posts.partial_expand({ :format => @format, :resourcetype => get_resource_type(resource_type), :start => start, :end => endc }) # decide what to get if grouping == "user" url = url.partial_expand({:user => name}) elsif grouping == "group" url = url.partial_expand({:group => name}) end # add tags, if requested if tags != nil url = url.partial_expand({:tags => tags.join(" ")}) end response = @conn.get url.expand({}) if @parse posts = JSON.parse(response.body)["posts"]["post"] return posts.map { |attributes| Post.new(attributes) } end return response.body end
[ "def", "get_posts", "(", "grouping", ",", "name", ",", "resource_type", ",", "tags", "=", "nil", ",", "start", "=", "0", ",", "endc", "=", "$MAX_POSTS_PER_REQUEST", ")", "url", "=", "@url_posts", ".", "partial_expand", "(", "{", ":format", "=>", "@format", ",", ":resourcetype", "=>", "get_resource_type", "(", "resource_type", ")", ",", ":start", "=>", "start", ",", ":end", "=>", "endc", "}", ")", "# decide what to get", "if", "grouping", "==", "\"user\"", "url", "=", "url", ".", "partial_expand", "(", "{", ":user", "=>", "name", "}", ")", "elsif", "grouping", "==", "\"group\"", "url", "=", "url", ".", "partial_expand", "(", "{", ":group", "=>", "name", "}", ")", "end", "# add tags, if requested", "if", "tags", "!=", "nil", "url", "=", "url", ".", "partial_expand", "(", "{", ":tags", "=>", "tags", ".", "join", "(", "\" \"", ")", "}", ")", "end", "response", "=", "@conn", ".", "get", "url", ".", "expand", "(", "{", "}", ")", "if", "@parse", "posts", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "[", "\"posts\"", "]", "[", "\"post\"", "]", "return", "posts", ".", "map", "{", "|", "attributes", "|", "Post", ".", "new", "(", "attributes", ")", "}", "end", "return", "response", ".", "body", "end" ]
Get posts for a user or group, optionally filtered by tags. @param grouping [String] the type of the name (either "user" or "group") @param name [String] the name of the group or user @param resource_type [String] the type of the post. Currently supported are 'bookmark' and 'publication'. @param tags [Array<String>] the tags that all posts must contain (can be empty) @param start [Integer] number of first post to download @param endc [Integer] number of last post to download @return [Array<BibSonomy::Post>, String] the requested posts
[ "Get", "posts", "for", "a", "user", "or", "group", "optionally", "filtered", "by", "tags", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L128-L153
6,711
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_document
def get_document(user_name, intra_hash, file_name) response = @conn.get get_document_href(user_name, intra_hash, file_name) if response.status == 200 return [response.body, response.headers['content-type']] end return nil, nil end
ruby
def get_document(user_name, intra_hash, file_name) response = @conn.get get_document_href(user_name, intra_hash, file_name) if response.status == 200 return [response.body, response.headers['content-type']] end return nil, nil end
[ "def", "get_document", "(", "user_name", ",", "intra_hash", ",", "file_name", ")", "response", "=", "@conn", ".", "get", "get_document_href", "(", "user_name", ",", "intra_hash", ",", "file_name", ")", "if", "response", ".", "status", "==", "200", "return", "[", "response", ".", "body", ",", "response", ".", "headers", "[", "'content-type'", "]", "]", "end", "return", "nil", ",", "nil", "end" ]
Get a document belonging to a post. @param user_name @param intra_hash @param file_name @return the document and the content type
[ "Get", "a", "document", "belonging", "to", "a", "post", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L171-L177
6,712
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_document_preview
def get_document_preview(user_name, intra_hash, file_name, size) response = @conn.get get_document_href(user_name, intra_hash, file_name), { :preview => size } if response.status == 200 return [response.body, 'image/jpeg'] end return nil, nil end
ruby
def get_document_preview(user_name, intra_hash, file_name, size) response = @conn.get get_document_href(user_name, intra_hash, file_name), { :preview => size } if response.status == 200 return [response.body, 'image/jpeg'] end return nil, nil end
[ "def", "get_document_preview", "(", "user_name", ",", "intra_hash", ",", "file_name", ",", "size", ")", "response", "=", "@conn", ".", "get", "get_document_href", "(", "user_name", ",", "intra_hash", ",", "file_name", ")", ",", "{", ":preview", "=>", "size", "}", "if", "response", ".", "status", "==", "200", "return", "[", "response", ".", "body", ",", "'image/jpeg'", "]", "end", "return", "nil", ",", "nil", "end" ]
Get the preview for a document belonging to a post. @param user_name @param intra_hash @param file_name @param size [String] requested preview size (allowed values: SMALL, MEDIUM, LARGE) @return the preview image and the content type `image/jpeg`
[ "Get", "the", "preview", "for", "a", "document", "belonging", "to", "a", "post", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L187-L193
6,713
rjoberon/bibsonomy-ruby
lib/bibsonomy/api.rb
BibSonomy.API.get_resource_type
def get_resource_type(resource_type) if $resource_types_bookmark.include? resource_type.downcase() return "bookmark" end if $resource_types_bibtex.include? resource_type.downcase() return "bibtex" end raise ArgumentError.new("Unknown resource type: #{resource_type}. Supported resource types are ") end
ruby
def get_resource_type(resource_type) if $resource_types_bookmark.include? resource_type.downcase() return "bookmark" end if $resource_types_bibtex.include? resource_type.downcase() return "bibtex" end raise ArgumentError.new("Unknown resource type: #{resource_type}. Supported resource types are ") end
[ "def", "get_resource_type", "(", "resource_type", ")", "if", "$resource_types_bookmark", ".", "include?", "resource_type", ".", "downcase", "(", ")", "return", "\"bookmark\"", "end", "if", "$resource_types_bibtex", ".", "include?", "resource_type", ".", "downcase", "(", ")", "return", "\"bibtex\"", "end", "raise", "ArgumentError", ".", "new", "(", "\"Unknown resource type: #{resource_type}. Supported resource types are \"", ")", "end" ]
Convenience method to allow sloppy specification of the resource type.
[ "Convenience", "method", "to", "allow", "sloppy", "specification", "of", "the", "resource", "type", "." ]
15afed3f32e434d28576ac62ecf3cfd8a392e055
https://github.com/rjoberon/bibsonomy-ruby/blob/15afed3f32e434d28576ac62ecf3cfd8a392e055/lib/bibsonomy/api.rb#L203-L213
6,714
LifebookerInc/table_renamable
lib/table_renamable/deprecated_table.rb
TableRenamable.DeprecatedTable.get_current_table_name
def get_current_table_name [self.old_name, self.new_name].each do |name| return name.to_s if self.table_exists?(name) end # raise exception if we don't have a valid table self.raise_no_table_error end
ruby
def get_current_table_name [self.old_name, self.new_name].each do |name| return name.to_s if self.table_exists?(name) end # raise exception if we don't have a valid table self.raise_no_table_error end
[ "def", "get_current_table_name", "[", "self", ".", "old_name", ",", "self", ".", "new_name", "]", ".", "each", "do", "|", "name", "|", "return", "name", ".", "to_s", "if", "self", ".", "table_exists?", "(", "name", ")", "end", "# raise exception if we don't have a valid table", "self", ".", "raise_no_table_error", "end" ]
Constructor - sets up the record and tries to connect to the correct database @param klass [Class] Class whose table we are renaming @param old_name [String, Symbol] The old table name @param new_name [String, Symbol] The new table name Returns the name of the table that currently exists of our two options (old or new) @return [String] The name of the existing table
[ "Constructor", "-", "sets", "up", "the", "record", "and", "tries", "to", "connect", "to", "the", "correct", "database" ]
337eaa4e71173c242df1d830776d3f72f0f4554f
https://github.com/LifebookerInc/table_renamable/blob/337eaa4e71173c242df1d830776d3f72f0f4554f/lib/table_renamable/deprecated_table.rb#L45-L51
6,715
LifebookerInc/table_renamable
lib/table_renamable/deprecated_table.rb
TableRenamable.DeprecatedTable.set_table_name
def set_table_name [self.old_name, self.new_name].each do |name| # make sure this table exists if self.table_exists?(name) # return true if we are already using this table return true if self.klass.table_name == name.to_s # otherwise we can change the table name self.klass.table_name = name return true end end self.raise_no_table_error end
ruby
def set_table_name [self.old_name, self.new_name].each do |name| # make sure this table exists if self.table_exists?(name) # return true if we are already using this table return true if self.klass.table_name == name.to_s # otherwise we can change the table name self.klass.table_name = name return true end end self.raise_no_table_error end
[ "def", "set_table_name", "[", "self", ".", "old_name", ",", "self", ".", "new_name", "]", ".", "each", "do", "|", "name", "|", "# make sure this table exists", "if", "self", ".", "table_exists?", "(", "name", ")", "# return true if we are already using this table", "return", "true", "if", "self", ".", "klass", ".", "table_name", "==", "name", ".", "to_s", "# otherwise we can change the table name", "self", ".", "klass", ".", "table_name", "=", "name", "return", "true", "end", "end", "self", ".", "raise_no_table_error", "end" ]
Set the correct table name for the Class we are controlling @raise [TableRenamable::NoTableError] Error if neither name works @return [Boolean] True if we set the table name
[ "Set", "the", "correct", "table", "name", "for", "the", "Class", "we", "are", "controlling" ]
337eaa4e71173c242df1d830776d3f72f0f4554f
https://github.com/LifebookerInc/table_renamable/blob/337eaa4e71173c242df1d830776d3f72f0f4554f/lib/table_renamable/deprecated_table.rb#L68-L80
6,716
dmerrick/lights_app
lib/philips_hue/light.rb
PhilipsHue.Light.set
def set(options) json_body = options.to_json request_uri = "#{base_request_uri}/state" HTTParty.put(request_uri, :body => json_body) end
ruby
def set(options) json_body = options.to_json request_uri = "#{base_request_uri}/state" HTTParty.put(request_uri, :body => json_body) end
[ "def", "set", "(", "options", ")", "json_body", "=", "options", ".", "to_json", "request_uri", "=", "\"#{base_request_uri}/state\"", "HTTParty", ".", "put", "(", "request_uri", ",", ":body", "=>", "json_body", ")", "end" ]
change the state of a light note that colormode will automagically update
[ "change", "the", "state", "of", "a", "light", "note", "that", "colormode", "will", "automagically", "update" ]
0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d
https://github.com/dmerrick/lights_app/blob/0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d/lib/philips_hue/light.rb#L23-L27
6,717
dmerrick/lights_app
lib/philips_hue/light.rb
PhilipsHue.Light.rename
def rename(new_name) json_body = { :name => new_name }.to_json HTTParty.put(base_request_uri, :body => json_body) @name = new_name end
ruby
def rename(new_name) json_body = { :name => new_name }.to_json HTTParty.put(base_request_uri, :body => json_body) @name = new_name end
[ "def", "rename", "(", "new_name", ")", "json_body", "=", "{", ":name", "=>", "new_name", "}", ".", "to_json", "HTTParty", ".", "put", "(", "base_request_uri", ",", ":body", "=>", "json_body", ")", "@name", "=", "new_name", "end" ]
change the name of the light
[ "change", "the", "name", "of", "the", "light" ]
0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d
https://github.com/dmerrick/lights_app/blob/0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d/lib/philips_hue/light.rb#L30-L34
6,718
dmerrick/lights_app
lib/philips_hue/light.rb
PhilipsHue.Light.to_s
def to_s pretty_name = @name.to_s.split(/_/).map(&:capitalize).join(" ") on_or_off = on? ? "on" : "off" reachable = reachable? ? "reachable" : "unreachable" "#{pretty_name} is #{on_or_off} and #{reachable}" end
ruby
def to_s pretty_name = @name.to_s.split(/_/).map(&:capitalize).join(" ") on_or_off = on? ? "on" : "off" reachable = reachable? ? "reachable" : "unreachable" "#{pretty_name} is #{on_or_off} and #{reachable}" end
[ "def", "to_s", "pretty_name", "=", "@name", ".", "to_s", ".", "split", "(", "/", "/", ")", ".", "map", "(", ":capitalize", ")", ".", "join", "(", "\" \"", ")", "on_or_off", "=", "on?", "?", "\"on\"", ":", "\"off\"", "reachable", "=", "reachable?", "?", "\"reachable\"", ":", "\"unreachable\"", "\"#{pretty_name} is #{on_or_off} and #{reachable}\"", "end" ]
pretty-print the light's status
[ "pretty", "-", "print", "the", "light", "s", "status" ]
0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d
https://github.com/dmerrick/lights_app/blob/0bcbc566fa3964c74f7cfe73708d5ad1a7ce696d/lib/philips_hue/light.rb#L154-L159
6,719
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/pages_controller.rb
Roroacms.Admin::PagesController.edit
def edit @edit = true @record = Post.find(params[:id]) # add breadcrumb and set title add_breadcrumb I18n.t("controllers.admin.pages.edit.breadcrumb") set_title(I18n.t("controllers.admin.pages.edit.title", post_title: @record.post_title)) @action = 'update' end
ruby
def edit @edit = true @record = Post.find(params[:id]) # add breadcrumb and set title add_breadcrumb I18n.t("controllers.admin.pages.edit.breadcrumb") set_title(I18n.t("controllers.admin.pages.edit.title", post_title: @record.post_title)) @action = 'update' end
[ "def", "edit", "@edit", "=", "true", "@record", "=", "Post", ".", "find", "(", "params", "[", ":id", "]", ")", "# add breadcrumb and set title", "add_breadcrumb", "I18n", ".", "t", "(", "\"controllers.admin.pages.edit.breadcrumb\"", ")", "set_title", "(", "I18n", ".", "t", "(", "\"controllers.admin.pages.edit.title\"", ",", "post_title", ":", "@record", ".", "post_title", ")", ")", "@action", "=", "'update'", "end" ]
gets and displays the post object with the necessary dependencies
[ "gets", "and", "displays", "the", "post", "object", "with", "the", "necessary", "dependencies" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/pages_controller.rb#L57-L65
6,720
mrsimonfletcher/roroacms
app/controllers/roroacms/admin/pages_controller.rb
Roroacms.Admin::PagesController.destroy
def destroy Post.disable_post(params[:id]) respond_to do |format| format.html { redirect_to admin_pages_path, notice: I18n.t("controllers.admin.pages.destroy.flash.success") } end end
ruby
def destroy Post.disable_post(params[:id]) respond_to do |format| format.html { redirect_to admin_pages_path, notice: I18n.t("controllers.admin.pages.destroy.flash.success") } end end
[ "def", "destroy", "Post", ".", "disable_post", "(", "params", "[", ":id", "]", ")", "respond_to", "do", "|", "format", "|", "format", ".", "html", "{", "redirect_to", "admin_pages_path", ",", "notice", ":", "I18n", ".", "t", "(", "\"controllers.admin.pages.destroy.flash.success\"", ")", "}", "end", "end" ]
deletes the post
[ "deletes", "the", "post" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/pages_controller.rb#L98-L103
6,721
tilsammans/nilly_vanilly
lib/nilly_vanilly/inspect.rb
NillyVanilly.Inspect.results
def results ActiveRecord::Base.connection.tables.each do |table| model = table.classify.constantize rescue next model.columns.each do |column| present = model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym) @results << [present, model.name, column.name] if include_column(column) end end @results end
ruby
def results ActiveRecord::Base.connection.tables.each do |table| model = table.classify.constantize rescue next model.columns.each do |column| present = model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym) @results << [present, model.name, column.name] if include_column(column) end end @results end
[ "def", "results", "ActiveRecord", "::", "Base", ".", "connection", ".", "tables", ".", "each", "do", "|", "table", "|", "model", "=", "table", ".", "classify", ".", "constantize", "rescue", "next", "model", ".", "columns", ".", "each", "do", "|", "column", "|", "present", "=", "model", ".", "respond_to?", "(", ":nillify_attributes", ")", "&&", "model", ".", "nillify_attributes", ".", "include?", "(", "column", ".", "name", ".", "to_sym", ")", "@results", "<<", "[", "present", ",", "model", ".", "name", ",", "column", ".", "name", "]", "if", "include_column", "(", "column", ")", "end", "end", "@results", "end" ]
A nested array with one row for each column suitable for nillification.
[ "A", "nested", "array", "with", "one", "row", "for", "each", "column", "suitable", "for", "nillification", "." ]
5b95d8ae8a849272ec8bcf9036bb6bd99a86204c
https://github.com/tilsammans/nilly_vanilly/blob/5b95d8ae8a849272ec8bcf9036bb6bd99a86204c/lib/nilly_vanilly/inspect.rb#L9-L21
6,722
tongueroo/chap
lib/chap/config.rb
Chap.Config.load_json
def load_json(key) path = if yaml[key] =~ %r{^/} # root path given yaml[key] else # relative path dirname = File.dirname(options[:config]) "#{dirname}/#{yaml[key]}" end if File.exist?(path) Mash.from_hash(JSON.parse(IO.read(path))) else puts "ERROR: #{key}.json config does not exist at: #{path}" exit 1 end end
ruby
def load_json(key) path = if yaml[key] =~ %r{^/} # root path given yaml[key] else # relative path dirname = File.dirname(options[:config]) "#{dirname}/#{yaml[key]}" end if File.exist?(path) Mash.from_hash(JSON.parse(IO.read(path))) else puts "ERROR: #{key}.json config does not exist at: #{path}" exit 1 end end
[ "def", "load_json", "(", "key", ")", "path", "=", "if", "yaml", "[", "key", "]", "=~", "%r{", "}", "# root path given", "yaml", "[", "key", "]", "else", "# relative path", "dirname", "=", "File", ".", "dirname", "(", "options", "[", ":config", "]", ")", "\"#{dirname}/#{yaml[key]}\"", "end", "if", "File", ".", "exist?", "(", "path", ")", "Mash", ".", "from_hash", "(", "JSON", ".", "parse", "(", "IO", ".", "read", "(", "path", ")", ")", ")", "else", "puts", "\"ERROR: #{key}.json config does not exist at: #{path}\"", "exit", "1", "end", "end" ]
the chap.json and node.json is assumed to be in th same folder as chap.yml if a relative path is given
[ "the", "chap", ".", "json", "and", "node", ".", "json", "is", "assumed", "to", "be", "in", "th", "same", "folder", "as", "chap", ".", "yml", "if", "a", "relative", "path", "is", "given" ]
317cebeace6cbae793ecd0e4a3d357c671ac1106
https://github.com/tongueroo/chap/blob/317cebeace6cbae793ecd0e4a3d357c671ac1106/lib/chap/config.rb#L35-L48
6,723
kukushkin/mimi-config
lib/mimi/config.rb
Mimi.Config.load
def load(manifest_filename, opts = {}) opts = self.class.module_options.deep_merge(opts) manifest_filename = Pathname.new(manifest_filename).expand_path load_manifest(manifest_filename, opts) load_params(opts) if opts[:raise_on_missing_params] && !missing_params.empty? raise "Missing required configurable parameters: #{missing_params.join(', ')}" end self end
ruby
def load(manifest_filename, opts = {}) opts = self.class.module_options.deep_merge(opts) manifest_filename = Pathname.new(manifest_filename).expand_path load_manifest(manifest_filename, opts) load_params(opts) if opts[:raise_on_missing_params] && !missing_params.empty? raise "Missing required configurable parameters: #{missing_params.join(', ')}" end self end
[ "def", "load", "(", "manifest_filename", ",", "opts", "=", "{", "}", ")", "opts", "=", "self", ".", "class", ".", "module_options", ".", "deep_merge", "(", "opts", ")", "manifest_filename", "=", "Pathname", ".", "new", "(", "manifest_filename", ")", ".", "expand_path", "load_manifest", "(", "manifest_filename", ",", "opts", ")", "load_params", "(", "opts", ")", "if", "opts", "[", ":raise_on_missing_params", "]", "&&", "!", "missing_params", ".", "empty?", "raise", "\"Missing required configurable parameters: #{missing_params.join(', ')}\"", "end", "self", "end" ]
Creates a Config object. Loads and parses manifest.yml, reads and sets configurable parameters from ENV. Raises an error if any of the required configurable parameters are missing. @param manifest_filename [String,nil] path to the manifest.yml or nil to skip loading manifest Loads and parses manifest.yml, reads and sets configurable parameters from ENV.
[ "Creates", "a", "Config", "object", "." ]
0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20
https://github.com/kukushkin/mimi-config/blob/0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20/lib/mimi/config.rb#L48-L57
6,724
kukushkin/mimi-config
lib/mimi/config.rb
Mimi.Config.missing_params
def missing_params required_params = manifest.select { |p| p[:required] }.map { |p| p[:name] } required_params - @params.keys end
ruby
def missing_params required_params = manifest.select { |p| p[:required] }.map { |p| p[:name] } required_params - @params.keys end
[ "def", "missing_params", "required_params", "=", "manifest", ".", "select", "{", "|", "p", "|", "p", "[", ":required", "]", "}", ".", "map", "{", "|", "p", "|", "p", "[", ":name", "]", "}", "required_params", "-", "@params", ".", "keys", "end" ]
Returns list of missing required params
[ "Returns", "list", "of", "missing", "required", "params" ]
0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20
https://github.com/kukushkin/mimi-config/blob/0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20/lib/mimi/config.rb#L61-L64
6,725
kukushkin/mimi-config
lib/mimi/config.rb
Mimi.Config.manifest
def manifest @manifest.map do |k, v| { name: k, desc: v[:desc], required: !v.key?(:default), const: v[:const], default: v[:default] } end end
ruby
def manifest @manifest.map do |k, v| { name: k, desc: v[:desc], required: !v.key?(:default), const: v[:const], default: v[:default] } end end
[ "def", "manifest", "@manifest", ".", "map", "do", "|", "k", ",", "v", "|", "{", "name", ":", "k", ",", "desc", ":", "v", "[", ":desc", "]", ",", "required", ":", "!", "v", ".", "key?", "(", ":default", ")", ",", "const", ":", "v", "[", ":const", "]", ",", "default", ":", "v", "[", ":default", "]", "}", "end", "end" ]
Returns annotated manifest
[ "Returns", "annotated", "manifest" ]
0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20
https://github.com/kukushkin/mimi-config/blob/0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20/lib/mimi/config.rb#L68-L78
6,726
kukushkin/mimi-config
lib/mimi/config.rb
Mimi.Config.load_params
def load_params(opts = {}) Dotenv.load if opts[:use_dotenv] manifest.each do |p| env_name = p[:name].to_s if p[:const] # const @params[p[:name]] = p[:default] elsif p[:required] # required configurable @params[p[:name]] = ENV[env_name] if ENV.key?(env_name) else # optional configurable @params[p[:name]] = ENV.key?(env_name) ? ENV[env_name] : p[:default] end end @params end
ruby
def load_params(opts = {}) Dotenv.load if opts[:use_dotenv] manifest.each do |p| env_name = p[:name].to_s if p[:const] # const @params[p[:name]] = p[:default] elsif p[:required] # required configurable @params[p[:name]] = ENV[env_name] if ENV.key?(env_name) else # optional configurable @params[p[:name]] = ENV.key?(env_name) ? ENV[env_name] : p[:default] end end @params end
[ "def", "load_params", "(", "opts", "=", "{", "}", ")", "Dotenv", ".", "load", "if", "opts", "[", ":use_dotenv", "]", "manifest", ".", "each", "do", "|", "p", "|", "env_name", "=", "p", "[", ":name", "]", ".", "to_s", "if", "p", "[", ":const", "]", "# const", "@params", "[", "p", "[", ":name", "]", "]", "=", "p", "[", ":default", "]", "elsif", "p", "[", ":required", "]", "# required configurable", "@params", "[", "p", "[", ":name", "]", "]", "=", "ENV", "[", "env_name", "]", "if", "ENV", ".", "key?", "(", "env_name", ")", "else", "# optional configurable", "@params", "[", "p", "[", ":name", "]", "]", "=", "ENV", ".", "key?", "(", "env_name", ")", "?", "ENV", "[", "env_name", "]", ":", "p", "[", ":default", "]", "end", "end", "@params", "end" ]
Reads parameters from the ENV according to the current manifest
[ "Reads", "parameters", "from", "the", "ENV", "according", "to", "the", "current", "manifest" ]
0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20
https://github.com/kukushkin/mimi-config/blob/0dc0a733b8442abe2684e0b9e9bd1ccb872f9b20/lib/mimi/config.rb#L150-L166
6,727
Raybeam/myreplicator
lib/transporter/parallelizer.rb
Myreplicator.Parallelizer.run
def run @done = false @manager_running = false reaper = nil while @queue.size > 0 if @threads.size <= @max_threads @threads << Thread.new(@queue.pop) do |proc| Thread.current[:thread_state] = "running" @klass.new.instance_exec(proc[:params], &proc[:block]) Thread.current[:thread_state] = "done" end else unless @manager_running reaper = manage_threads @manager_running = true end sleep 1 end end # Run manager if thread size never reached max reaper = manage_threads unless @manager_running # Waits until all threads are completed # Before exiting reaper.join end
ruby
def run @done = false @manager_running = false reaper = nil while @queue.size > 0 if @threads.size <= @max_threads @threads << Thread.new(@queue.pop) do |proc| Thread.current[:thread_state] = "running" @klass.new.instance_exec(proc[:params], &proc[:block]) Thread.current[:thread_state] = "done" end else unless @manager_running reaper = manage_threads @manager_running = true end sleep 1 end end # Run manager if thread size never reached max reaper = manage_threads unless @manager_running # Waits until all threads are completed # Before exiting reaper.join end
[ "def", "run", "@done", "=", "false", "@manager_running", "=", "false", "reaper", "=", "nil", "while", "@queue", ".", "size", ">", "0", "if", "@threads", ".", "size", "<=", "@max_threads", "@threads", "<<", "Thread", ".", "new", "(", "@queue", ".", "pop", ")", "do", "|", "proc", "|", "Thread", ".", "current", "[", ":thread_state", "]", "=", "\"running\"", "@klass", ".", "new", ".", "instance_exec", "(", "proc", "[", ":params", "]", ",", "proc", "[", ":block", "]", ")", "Thread", ".", "current", "[", ":thread_state", "]", "=", "\"done\"", "end", "else", "unless", "@manager_running", "reaper", "=", "manage_threads", "@manager_running", "=", "true", "end", "sleep", "1", "end", "end", "# Run manager if thread size never reached max", "reaper", "=", "manage_threads", "unless", "@manager_running", "# Waits until all threads are completed", "# Before exiting", "reaper", ".", "join", "end" ]
Runs while there are jobs in the queue Waits for a second and checks for available threads Exits when all jobs are allocated in threads
[ "Runs", "while", "there", "are", "jobs", "in", "the", "queue", "Waits", "for", "a", "second", "and", "checks", "for", "available", "threads", "Exits", "when", "all", "jobs", "are", "allocated", "in", "threads" ]
470938e70f46886b525c65a4a464b4cf8383d00d
https://github.com/Raybeam/myreplicator/blob/470938e70f46886b525c65a4a464b4cf8383d00d/lib/transporter/parallelizer.rb#L29-L56
6,728
Raybeam/myreplicator
lib/transporter/parallelizer.rb
Myreplicator.Parallelizer.manage_threads
def manage_threads Thread.new do while(@threads.size > 0) done = [] @threads.each do |t| done << t if t[:thread_state] == "done" || !t.status # puts t.object_id.to_s + "--" + t.status.to_s + "--" + t.to_s # raise "Nil Thread State" if t[:thread_state].nil? end done.each{|d| @threads.delete(d)} # Clear dead threads # If no more jobs are left, mark done if done? @done = true else puts "Sleeping for 2" sleep 2 # Wait for more threads to spawn end end end end
ruby
def manage_threads Thread.new do while(@threads.size > 0) done = [] @threads.each do |t| done << t if t[:thread_state] == "done" || !t.status # puts t.object_id.to_s + "--" + t.status.to_s + "--" + t.to_s # raise "Nil Thread State" if t[:thread_state].nil? end done.each{|d| @threads.delete(d)} # Clear dead threads # If no more jobs are left, mark done if done? @done = true else puts "Sleeping for 2" sleep 2 # Wait for more threads to spawn end end end end
[ "def", "manage_threads", "Thread", ".", "new", "do", "while", "(", "@threads", ".", "size", ">", "0", ")", "done", "=", "[", "]", "@threads", ".", "each", "do", "|", "t", "|", "done", "<<", "t", "if", "t", "[", ":thread_state", "]", "==", "\"done\"", "||", "!", "t", ".", "status", "# puts t.object_id.to_s + \"--\" + t.status.to_s + \"--\" + t.to_s", "# raise \"Nil Thread State\" if t[:thread_state].nil?", "end", "done", ".", "each", "{", "|", "d", "|", "@threads", ".", "delete", "(", "d", ")", "}", "# Clear dead threads", "# If no more jobs are left, mark done", "if", "done?", "@done", "=", "true", "else", "puts", "\"Sleeping for 2\"", "sleep", "2", "# Wait for more threads to spawn", "end", "end", "end", "end" ]
Clears dead threads, frees thread pool for more jobs Exits when no more threads are left
[ "Clears", "dead", "threads", "frees", "thread", "pool", "for", "more", "jobs", "Exits", "when", "no", "more", "threads", "are", "left" ]
470938e70f46886b525c65a4a464b4cf8383d00d
https://github.com/Raybeam/myreplicator/blob/470938e70f46886b525c65a4a464b4cf8383d00d/lib/transporter/parallelizer.rb#L63-L85
6,729
syborg/mme_tools
lib/mme_tools/debug.rb
MMETools.Debug.print_debug
def print_debug(stck_lvls, *vars) @mutex ||= Mutex.new # instance mutex created the first time it is called referers = caller[0...stck_lvls] if stck_lvls > 0 @mutex.synchronize do referers.each { |r| puts "#{r}:"} vars.each { |v| pp v } if vars end end
ruby
def print_debug(stck_lvls, *vars) @mutex ||= Mutex.new # instance mutex created the first time it is called referers = caller[0...stck_lvls] if stck_lvls > 0 @mutex.synchronize do referers.each { |r| puts "#{r}:"} vars.each { |v| pp v } if vars end end
[ "def", "print_debug", "(", "stck_lvls", ",", "*", "vars", ")", "@mutex", "||=", "Mutex", ".", "new", "# instance mutex created the first time it is called", "referers", "=", "caller", "[", "0", "...", "stck_lvls", "]", "if", "stck_lvls", ">", "0", "@mutex", ".", "synchronize", "do", "referers", ".", "each", "{", "|", "r", "|", "puts", "\"#{r}:\"", "}", "vars", ".", "each", "{", "|", "v", "|", "pp", "v", "}", "if", "vars", "end", "end" ]
outputs a debug message and details of each one of the +vars+ if included. +stck_lvls+ is the number of stack levels to be showed +vars+ is a list of vars to be pretty printed. It is convenient to make the first to be a String with an informative message.
[ "outputs", "a", "debug", "message", "and", "details", "of", "each", "one", "of", "the", "+", "vars", "+", "if", "included", ".", "+", "stck_lvls", "+", "is", "the", "number", "of", "stack", "levels", "to", "be", "showed", "+", "vars", "+", "is", "a", "list", "of", "vars", "to", "be", "pretty", "printed", ".", "It", "is", "convenient", "to", "make", "the", "first", "to", "be", "a", "String", "with", "an", "informative", "message", "." ]
e93919f7fcfb408b941d6144290991a7feabaa7d
https://github.com/syborg/mme_tools/blob/e93919f7fcfb408b941d6144290991a7feabaa7d/lib/mme_tools/debug.rb#L18-L25
6,730
ihoka/friendly-attributes
lib/friendly_attributes/instance_methods.rb
FriendlyAttributes.InstanceMethods.friendly_instance_for_attribute
def friendly_instance_for_attribute(attr) klass = friendly_attributes_configuration.model_for_attribute(attr) send DetailsDelegator.friendly_model_reader(klass) end
ruby
def friendly_instance_for_attribute(attr) klass = friendly_attributes_configuration.model_for_attribute(attr) send DetailsDelegator.friendly_model_reader(klass) end
[ "def", "friendly_instance_for_attribute", "(", "attr", ")", "klass", "=", "friendly_attributes_configuration", ".", "model_for_attribute", "(", "attr", ")", "send", "DetailsDelegator", ".", "friendly_model_reader", "(", "klass", ")", "end" ]
Returns the Friendly instance corresponding to the specified attribute @param [Symbol, String] attr name of the attribute @return [Class] FriendyAttributes::Base instance
[ "Returns", "the", "Friendly", "instance", "corresponding", "to", "the", "specified", "attribute" ]
52c70a4028aa915f791d121bcf905a01989cad84
https://github.com/ihoka/friendly-attributes/blob/52c70a4028aa915f791d121bcf905a01989cad84/lib/friendly_attributes/instance_methods.rb#L23-L26
6,731
ihoka/friendly-attributes
lib/friendly_attributes/instance_methods.rb
FriendlyAttributes.InstanceMethods.friendly_instance_present?
def friendly_instance_present?(friendly_model) friendly_model_ivar = DetailsDelegator.friendly_model_ivar(friendly_model) val = instance_variable_get(friendly_model_ivar) val.present? end
ruby
def friendly_instance_present?(friendly_model) friendly_model_ivar = DetailsDelegator.friendly_model_ivar(friendly_model) val = instance_variable_get(friendly_model_ivar) val.present? end
[ "def", "friendly_instance_present?", "(", "friendly_model", ")", "friendly_model_ivar", "=", "DetailsDelegator", ".", "friendly_model_ivar", "(", "friendly_model", ")", "val", "=", "instance_variable_get", "(", "friendly_model_ivar", ")", "val", ".", "present?", "end" ]
Returns true if the FriendlyAttributes specified instance is loaded. @param [Class, Symbol, String] friendly_model Class or name of the FriendlyAttributes model @return [true, false] is the FriendlyAttributes instance loaded
[ "Returns", "true", "if", "the", "FriendlyAttributes", "specified", "instance", "is", "loaded", "." ]
52c70a4028aa915f791d121bcf905a01989cad84
https://github.com/ihoka/friendly-attributes/blob/52c70a4028aa915f791d121bcf905a01989cad84/lib/friendly_attributes/instance_methods.rb#L90-L94
6,732
dabassett/shibbolite
app/controllers/shibbolite/shibboleth_controller.rb
Shibbolite.ShibbolethController.load_session
def load_session unless logged_in? session[Shibbolite.pid] = request.env[Shibbolite.pid.to_s] current_user.update(get_attributes) if registered_user? end end
ruby
def load_session unless logged_in? session[Shibbolite.pid] = request.env[Shibbolite.pid.to_s] current_user.update(get_attributes) if registered_user? end end
[ "def", "load_session", "unless", "logged_in?", "session", "[", "Shibbolite", ".", "pid", "]", "=", "request", ".", "env", "[", "Shibbolite", ".", "pid", ".", "to_s", "]", "current_user", ".", "update", "(", "get_attributes", ")", "if", "registered_user?", "end", "end" ]
loads the session data created by shibboleth ensures that the user's id is set in session and updates the user's shibboleth attributes
[ "loads", "the", "session", "data", "created", "by", "shibboleth", "ensures", "that", "the", "user", "s", "id", "is", "set", "in", "session", "and", "updates", "the", "user", "s", "shibboleth", "attributes" ]
cbd679c88de4ab238c40029447715f6ff22f3f50
https://github.com/dabassett/shibbolite/blob/cbd679c88de4ab238c40029447715f6ff22f3f50/app/controllers/shibbolite/shibboleth_controller.rb#L39-L44
6,733
techiferous/rack-plastic
lib/rack-plastic.rb
Rack.Plastic.create_node
def create_node(doc, node_name, content=nil) #:doc: node = Nokogiri::XML::Node.new(node_name, doc) node.content = content if content node end
ruby
def create_node(doc, node_name, content=nil) #:doc: node = Nokogiri::XML::Node.new(node_name, doc) node.content = content if content node end
[ "def", "create_node", "(", "doc", ",", "node_name", ",", "content", "=", "nil", ")", "#:doc:", "node", "=", "Nokogiri", "::", "XML", "::", "Node", ".", "new", "(", "node_name", ",", "doc", ")", "node", ".", "content", "=", "content", "if", "content", "node", "end" ]
a convenience method for quickly creating a new HTML element
[ "a", "convenience", "method", "for", "quickly", "creating", "a", "new", "HTML", "element" ]
581c299d85ef1c8b5fea32713e353a125f7619d4
https://github.com/techiferous/rack-plastic/blob/581c299d85ef1c8b5fea32713e353a125f7619d4/lib/rack-plastic.rb#L71-L75
6,734
cknadler/rcomp
lib/rcomp/process.rb
RComp.Process.run
def run begin @process.start rescue ChildProcess::LaunchError => e raise StandardError.new(e.message) end begin @process.poll_for_exit(@timeout) rescue ChildProcess::TimeoutError @timedout = true @process.stop(@timeout) end end
ruby
def run begin @process.start rescue ChildProcess::LaunchError => e raise StandardError.new(e.message) end begin @process.poll_for_exit(@timeout) rescue ChildProcess::TimeoutError @timedout = true @process.stop(@timeout) end end
[ "def", "run", "begin", "@process", ".", "start", "rescue", "ChildProcess", "::", "LaunchError", "=>", "e", "raise", "StandardError", ".", "new", "(", "e", ".", "message", ")", "end", "begin", "@process", ".", "poll_for_exit", "(", "@timeout", ")", "rescue", "ChildProcess", "::", "TimeoutError", "@timedout", "=", "true", "@process", ".", "stop", "(", "@timeout", ")", "end", "end" ]
Initialize a new process cmd - An array of shellwords of a command timeout - Time until the process is automatically killed out - Path to send stdout of process err - Path to send stderr of process Runs a process and with a specified command and timeout Returns nothing
[ "Initialize", "a", "new", "process" ]
76fe71e1ef3b13923738ea6ab9cd502fe2f64f51
https://github.com/cknadler/rcomp/blob/76fe71e1ef3b13923738ea6ab9cd502fe2f64f51/lib/rcomp/process.rb#L24-L37
6,735
mrsimonfletcher/roroacms
app/helpers/roroacms/general_helper.rb
Roroacms.GeneralHelper.rewrite_theme_helper
def rewrite_theme_helper if File.exists?("#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb") # get the theme helper from the theme folder file = File.open("#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb", "rb") contents = file.read # check if the first line starts with the module name or not parts = contents.split(/[\r\n]+/) if parts[0] != 'module ThemeHelper' contents = "module ThemeHelper\n\n" + contents + "\n\nend" end # write the contents to the actual file file File.open("#{Rails.root}/app/helpers/theme_helper.rb", 'w') { |file| file.write(contents) } else contents = "module ThemeHelper\n\nend" File.open("#{Rails.root}/app/helpers/theme_helper.rb", 'w') { |file| file.write(contents) } end load("#{Rails.root}/app/helpers/theme_helper.rb") end
ruby
def rewrite_theme_helper if File.exists?("#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb") # get the theme helper from the theme folder file = File.open("#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb", "rb") contents = file.read # check if the first line starts with the module name or not parts = contents.split(/[\r\n]+/) if parts[0] != 'module ThemeHelper' contents = "module ThemeHelper\n\n" + contents + "\n\nend" end # write the contents to the actual file file File.open("#{Rails.root}/app/helpers/theme_helper.rb", 'w') { |file| file.write(contents) } else contents = "module ThemeHelper\n\nend" File.open("#{Rails.root}/app/helpers/theme_helper.rb", 'w') { |file| file.write(contents) } end load("#{Rails.root}/app/helpers/theme_helper.rb") end
[ "def", "rewrite_theme_helper", "if", "File", ".", "exists?", "(", "\"#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb\"", ")", "# get the theme helper from the theme folder", "file", "=", "File", ".", "open", "(", "\"#{Rails.root}/app/views/themes/#{current_theme}/theme_helper.rb\"", ",", "\"rb\"", ")", "contents", "=", "file", ".", "read", "# check if the first line starts with the module name or not", "parts", "=", "contents", ".", "split", "(", "/", "\\r", "\\n", "/", ")", "if", "parts", "[", "0", "]", "!=", "'module ThemeHelper'", "contents", "=", "\"module ThemeHelper\\n\\n\"", "+", "contents", "+", "\"\\n\\nend\"", "end", "# write the contents to the actual file file", "File", ".", "open", "(", "\"#{Rails.root}/app/helpers/theme_helper.rb\"", ",", "'w'", ")", "{", "|", "file", "|", "file", ".", "write", "(", "contents", ")", "}", "else", "contents", "=", "\"module ThemeHelper\\n\\nend\"", "File", ".", "open", "(", "\"#{Rails.root}/app/helpers/theme_helper.rb\"", ",", "'w'", ")", "{", "|", "file", "|", "file", ".", "write", "(", "contents", ")", "}", "end", "load", "(", "\"#{Rails.root}/app/helpers/theme_helper.rb\"", ")", "end" ]
rewrite the theme helper to use the themes function file
[ "rewrite", "the", "theme", "helper", "to", "use", "the", "themes", "function", "file" ]
62654a2f2a48e3adb3105f4dafb6e315b460eaf4
https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/helpers/roroacms/general_helper.rb#L19-L44
6,736
janx/factom-ruby
lib/factom-ruby/client.rb
Factom.Client.address_to_pubkey
def address_to_pubkey(addr) return unless addr.size == 52 prefix = ADDRESS_PREFIX[addr[0,2]] return unless prefix v = Bitcoin.decode_base58(addr) return if v[0,4] != prefix bytes = [v[0, 68]].pack('H*') return if v[68, 8] != sha256d(bytes)[0, 8] v[4, 64] end
ruby
def address_to_pubkey(addr) return unless addr.size == 52 prefix = ADDRESS_PREFIX[addr[0,2]] return unless prefix v = Bitcoin.decode_base58(addr) return if v[0,4] != prefix bytes = [v[0, 68]].pack('H*') return if v[68, 8] != sha256d(bytes)[0, 8] v[4, 64] end
[ "def", "address_to_pubkey", "(", "addr", ")", "return", "unless", "addr", ".", "size", "==", "52", "prefix", "=", "ADDRESS_PREFIX", "[", "addr", "[", "0", ",", "2", "]", "]", "return", "unless", "prefix", "v", "=", "Bitcoin", ".", "decode_base58", "(", "addr", ")", "return", "if", "v", "[", "0", ",", "4", "]", "!=", "prefix", "bytes", "=", "[", "v", "[", "0", ",", "68", "]", "]", ".", "pack", "(", "'H*'", ")", "return", "if", "v", "[", "68", ",", "8", "]", "!=", "sha256d", "(", "bytes", ")", "[", "0", ",", "8", "]", "v", "[", "4", ",", "64", "]", "end" ]
to pubkey in hex, 32 bytes
[ "to", "pubkey", "in", "hex", "32", "bytes" ]
54d9fafeeed106b37e73671f276ce622f6fd77a3
https://github.com/janx/factom-ruby/blob/54d9fafeeed106b37e73671f276ce622f6fd77a3/lib/factom-ruby/client.rb#L236-L249
6,737
codescrum/bebox
lib/bebox/vagrant_helper.rb
Bebox.VagrantHelper.prepare_vagrant
def prepare_vagrant(node) project_name = Bebox::Project.name_from_file(node.project_root) vagrant_box_base = Bebox::Project.vagrant_box_base_from_file(node.project_root) configure_local_hosts(project_name, node) add_vagrant_node(project_name, vagrant_box_base, node) end
ruby
def prepare_vagrant(node) project_name = Bebox::Project.name_from_file(node.project_root) vagrant_box_base = Bebox::Project.vagrant_box_base_from_file(node.project_root) configure_local_hosts(project_name, node) add_vagrant_node(project_name, vagrant_box_base, node) end
[ "def", "prepare_vagrant", "(", "node", ")", "project_name", "=", "Bebox", "::", "Project", ".", "name_from_file", "(", "node", ".", "project_root", ")", "vagrant_box_base", "=", "Bebox", "::", "Project", ".", "vagrant_box_base_from_file", "(", "node", ".", "project_root", ")", "configure_local_hosts", "(", "project_name", ",", "node", ")", "add_vagrant_node", "(", "project_name", ",", "vagrant_box_base", ",", "node", ")", "end" ]
Prepare the vagrant nodes
[ "Prepare", "the", "vagrant", "nodes" ]
0d19315847103341e599d32837ab0bd75524e5be
https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/vagrant_helper.rb#L56-L61
6,738
kui/active_window_x
lib/active_window_x/window.rb
ActiveWindowX.Window.prop
def prop atom val, format, nitems = prop_raw atom case format when 32; val.unpack("l!#{nitems}") when 16; val.unpack("s#{nitems}") when 8; val[0, nitems] when 0; nil end end
ruby
def prop atom val, format, nitems = prop_raw atom case format when 32; val.unpack("l!#{nitems}") when 16; val.unpack("s#{nitems}") when 8; val[0, nitems] when 0; nil end end
[ "def", "prop", "atom", "val", ",", "format", ",", "nitems", "=", "prop_raw", "atom", "case", "format", "when", "32", ";", "val", ".", "unpack", "(", "\"l!#{nitems}\"", ")", "when", "16", ";", "val", ".", "unpack", "(", "\"s#{nitems}\"", ")", "when", "8", ";", "val", "[", "0", ",", "nitems", "]", "when", "0", ";", "nil", "end", "end" ]
window property getter with easy way for XGetWindowProperty which return nil, if the specified property name does not exist, a String or a Array of Number
[ "window", "property", "getter", "with", "easy", "way", "for", "XGetWindowProperty", "which", "return", "nil", "if", "the", "specified", "property", "name", "does", "not", "exist", "a", "String", "or", "a", "Array", "of", "Number" ]
9c571aeaace5e739d6c577917234e708541f5216
https://github.com/kui/active_window_x/blob/9c571aeaace5e739d6c577917234e708541f5216/lib/active_window_x/window.rb#L75-L83
6,739
chrisjones-tripletri/action_command
lib/action_command/input_output.rb
ActionCommand.InputOutput.validate_input
def validate_input(dest, args) return true unless should_validate(dest) @input.each do |p| val = args[p[:symbol]] # if the argument has a value, no need to test whether it is optional. next unless !val || val == '*' || val == '' opts = p[:opts] unless opts[:optional] raise ArgumentError, "You must specify the required input #{p[:symbol]}" end end return true end
ruby
def validate_input(dest, args) return true unless should_validate(dest) @input.each do |p| val = args[p[:symbol]] # if the argument has a value, no need to test whether it is optional. next unless !val || val == '*' || val == '' opts = p[:opts] unless opts[:optional] raise ArgumentError, "You must specify the required input #{p[:symbol]}" end end return true end
[ "def", "validate_input", "(", "dest", ",", "args", ")", "return", "true", "unless", "should_validate", "(", "dest", ")", "@input", ".", "each", "do", "|", "p", "|", "val", "=", "args", "[", "p", "[", ":symbol", "]", "]", "# if the argument has a value, no need to test whether it is optional.", "next", "unless", "!", "val", "||", "val", "==", "'*'", "||", "val", "==", "''", "opts", "=", "p", "[", ":opts", "]", "unless", "opts", "[", ":optional", "]", "raise", "ArgumentError", ",", "\"You must specify the required input #{p[:symbol]}\"", "end", "end", "return", "true", "end" ]
Validates that the specified parameters are valid for this input description. @param args [Hash] the arguments to validate
[ "Validates", "that", "the", "specified", "parameters", "are", "valid", "for", "this", "input", "description", "." ]
9b9a8ba30e407ca6d88a62a164d1dc22ba149874
https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/input_output.rb#L37-L51
6,740
chrisjones-tripletri/action_command
lib/action_command/input_output.rb
ActionCommand.InputOutput.process_input
def process_input(dest, args) # pass down predefined attributes. dest.parent = args[:parent] dest.test = args[:test] return unless validate_input(dest, args) @input.each do |param| sym = param[:symbol] if args.key? sym sym_assign = "#{sym}=".to_sym dest.send(sym_assign, args[sym]) end end end
ruby
def process_input(dest, args) # pass down predefined attributes. dest.parent = args[:parent] dest.test = args[:test] return unless validate_input(dest, args) @input.each do |param| sym = param[:symbol] if args.key? sym sym_assign = "#{sym}=".to_sym dest.send(sym_assign, args[sym]) end end end
[ "def", "process_input", "(", "dest", ",", "args", ")", "# pass down predefined attributes.", "dest", ".", "parent", "=", "args", "[", ":parent", "]", "dest", ".", "test", "=", "args", "[", ":test", "]", "return", "unless", "validate_input", "(", "dest", ",", "args", ")", "@input", ".", "each", "do", "|", "param", "|", "sym", "=", "param", "[", ":symbol", "]", "if", "args", ".", "key?", "sym", "sym_assign", "=", "\"#{sym}=\"", ".", "to_sym", "dest", ".", "send", "(", "sym_assign", ",", "args", "[", "sym", "]", ")", "end", "end", "end" ]
Goes through, and assigns the value for each declared parameter to an accessor with the same name, validating that required parameters are not missing
[ "Goes", "through", "and", "assigns", "the", "value", "for", "each", "declared", "parameter", "to", "an", "accessor", "with", "the", "same", "name", "validating", "that", "required", "parameters", "are", "not", "missing" ]
9b9a8ba30e407ca6d88a62a164d1dc22ba149874
https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/input_output.rb#L55-L69
6,741
chrisjones-tripletri/action_command
lib/action_command/input_output.rb
ActionCommand.InputOutput.process_output
def process_output(dest, result) return unless result.ok? && should_validate(dest) @output.each do |param| sym = param[:symbol] unless result.key?(sym) opts = param[:opts] raise ArgumentError, "Missing required value #{sym} in output" unless opts[:optional] end end end
ruby
def process_output(dest, result) return unless result.ok? && should_validate(dest) @output.each do |param| sym = param[:symbol] unless result.key?(sym) opts = param[:opts] raise ArgumentError, "Missing required value #{sym} in output" unless opts[:optional] end end end
[ "def", "process_output", "(", "dest", ",", "result", ")", "return", "unless", "result", ".", "ok?", "&&", "should_validate", "(", "dest", ")", "@output", ".", "each", "do", "|", "param", "|", "sym", "=", "param", "[", ":symbol", "]", "unless", "result", ".", "key?", "(", "sym", ")", "opts", "=", "param", "[", ":opts", "]", "raise", "ArgumentError", ",", "\"Missing required value #{sym} in output\"", "unless", "opts", "[", ":optional", "]", "end", "end", "end" ]
Goes through, and makes sure that required output parameters exist
[ "Goes", "through", "and", "makes", "sure", "that", "required", "output", "parameters", "exist" ]
9b9a8ba30e407ca6d88a62a164d1dc22ba149874
https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/input_output.rb#L72-L82
6,742
chrisjones-tripletri/action_command
lib/action_command/input_output.rb
ActionCommand.InputOutput.rake_input
def rake_input(rake_arg) params = {} rake_arg.each do |key, val| params[key] = val end # by default, use human logging if a logger is enabled. params[:logger] = Logger.new(STDOUT) unless params.key?(:logger) params[:log_format] = :human unless params.key?(:log_format) return params end
ruby
def rake_input(rake_arg) params = {} rake_arg.each do |key, val| params[key] = val end # by default, use human logging if a logger is enabled. params[:logger] = Logger.new(STDOUT) unless params.key?(:logger) params[:log_format] = :human unless params.key?(:log_format) return params end
[ "def", "rake_input", "(", "rake_arg", ")", "params", "=", "{", "}", "rake_arg", ".", "each", "do", "|", "key", ",", "val", "|", "params", "[", "key", "]", "=", "val", "end", "# by default, use human logging if a logger is enabled.", "params", "[", ":logger", "]", "=", "Logger", ".", "new", "(", "STDOUT", ")", "unless", "params", ".", "key?", "(", ":logger", ")", "params", "[", ":log_format", "]", "=", ":human", "unless", "params", ".", "key?", "(", ":log_format", ")", "return", "params", "end" ]
convert rake task arguments to a standard hash.
[ "convert", "rake", "task", "arguments", "to", "a", "standard", "hash", "." ]
9b9a8ba30e407ca6d88a62a164d1dc22ba149874
https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/input_output.rb#L85-L95
6,743
jkotests/watir-wait_with_refresh
lib/watir/wait_with_refresh/element.rb
Watir.Element.refresh_until_present
def refresh_until_present(timeout = 30) message = "waiting for #{@selector.inspect} to become present" Watir::WaitWithRefresh.refresh_until(browser, timeout, message) { present? } end
ruby
def refresh_until_present(timeout = 30) message = "waiting for #{@selector.inspect} to become present" Watir::WaitWithRefresh.refresh_until(browser, timeout, message) { present? } end
[ "def", "refresh_until_present", "(", "timeout", "=", "30", ")", "message", "=", "\"waiting for #{@selector.inspect} to become present\"", "Watir", "::", "WaitWithRefresh", ".", "refresh_until", "(", "browser", ",", "timeout", ",", "message", ")", "{", "present?", "}", "end" ]
Refresh the page until the element is present. @example browser.button(:id => 'foo').refresh_until_present @param [Fixnum] timeout seconds to wait before timing out @see Watir::WaitWithRefresh @see Watir::Element#present?
[ "Refresh", "the", "page", "until", "the", "element", "is", "present", "." ]
f8f6e202cc5d9843dd6ecb657f65b904b46fe048
https://github.com/jkotests/watir-wait_with_refresh/blob/f8f6e202cc5d9843dd6ecb657f65b904b46fe048/lib/watir/wait_with_refresh/element.rb#L17-L20
6,744
jkotests/watir-wait_with_refresh
lib/watir/wait_with_refresh/element.rb
Watir.Element.refresh_while_present
def refresh_while_present(timeout = 30) message = "waiting for #{@selector.inspect} to disappear" Watir::WaitWithRefresh.refresh_while(browser, timeout, message) { present? } end
ruby
def refresh_while_present(timeout = 30) message = "waiting for #{@selector.inspect} to disappear" Watir::WaitWithRefresh.refresh_while(browser, timeout, message) { present? } end
[ "def", "refresh_while_present", "(", "timeout", "=", "30", ")", "message", "=", "\"waiting for #{@selector.inspect} to disappear\"", "Watir", "::", "WaitWithRefresh", ".", "refresh_while", "(", "browser", ",", "timeout", ",", "message", ")", "{", "present?", "}", "end" ]
Refresh the page while the element is present. @example browser.button(:id => 'foo').refresh_while_present @param [Integer] timeout seconds to wait before timing out @see Watir::WaitWithRefresh @see Watir::Element#present?
[ "Refresh", "the", "page", "while", "the", "element", "is", "present", "." ]
f8f6e202cc5d9843dd6ecb657f65b904b46fe048
https://github.com/jkotests/watir-wait_with_refresh/blob/f8f6e202cc5d9843dd6ecb657f65b904b46fe048/lib/watir/wait_with_refresh/element.rb#L34-L37
6,745
jkotests/watir-wait_with_refresh
lib/watir/wait_with_refresh/element.rb
Watir.Element.when_present_after_refresh
def when_present_after_refresh(timeout = 30) message = "waiting for #{@selector.inspect} to become present" if block_given? Watir::WaitWithRefresh.refresh_until(browser, timeout, message) { present? } yield self else WhenPresentAfterRefreshDecorator.new(self, timeout, message) end end
ruby
def when_present_after_refresh(timeout = 30) message = "waiting for #{@selector.inspect} to become present" if block_given? Watir::WaitWithRefresh.refresh_until(browser, timeout, message) { present? } yield self else WhenPresentAfterRefreshDecorator.new(self, timeout, message) end end
[ "def", "when_present_after_refresh", "(", "timeout", "=", "30", ")", "message", "=", "\"waiting for #{@selector.inspect} to become present\"", "if", "block_given?", "Watir", "::", "WaitWithRefresh", ".", "refresh_until", "(", "browser", ",", "timeout", ",", "message", ")", "{", "present?", "}", "yield", "self", "else", "WhenPresentAfterRefreshDecorator", ".", "new", "(", "self", ",", "timeout", ",", "message", ")", "end", "end" ]
Refreshes the page until the element is present. @example browser.button(:id => 'foo').when_present_after_refresh.click browser.div(:id => 'bar').when_present_after_refresh { |div| ... } browser.p(:id => 'baz').when_present_after_refresh(60).text @param [Fixnum] timeout seconds to wait before timing out @see Watir::WaitWithRefresh @see Watir::Element#present?
[ "Refreshes", "the", "page", "until", "the", "element", "is", "present", "." ]
f8f6e202cc5d9843dd6ecb657f65b904b46fe048
https://github.com/jkotests/watir-wait_with_refresh/blob/f8f6e202cc5d9843dd6ecb657f65b904b46fe048/lib/watir/wait_with_refresh/element.rb#L53-L62
6,746
robertwahler/mutagem
lib/mutagem/lockfile.rb
Mutagem.Lockfile.locked?
def locked? return false unless File.exists?(lockfile) result = false open(lockfile, 'w') do |f| # exclusive non-blocking lock result = !lock(f, File::LOCK_EX | File::LOCK_NB) end result end
ruby
def locked? return false unless File.exists?(lockfile) result = false open(lockfile, 'w') do |f| # exclusive non-blocking lock result = !lock(f, File::LOCK_EX | File::LOCK_NB) end result end
[ "def", "locked?", "return", "false", "unless", "File", ".", "exists?", "(", "lockfile", ")", "result", "=", "false", "open", "(", "lockfile", ",", "'w'", ")", "do", "|", "f", "|", "# exclusive non-blocking lock", "result", "=", "!", "lock", "(", "f", ",", "File", "::", "LOCK_EX", "|", "File", "::", "LOCK_NB", ")", "end", "result", "end" ]
Create a new LockFile @param [String] lockfile filename Does another process have a lock? True if we can't get an exclusive lock
[ "Create", "a", "new", "LockFile" ]
75ac2f7fd307f575d81114b32e1a3b09c526e01d
https://github.com/robertwahler/mutagem/blob/75ac2f7fd307f575d81114b32e1a3b09c526e01d/lib/mutagem/lockfile.rb#L18-L26
6,747
akerl/basiccache
lib/basiccache/caches/cache.rb
BasicCache.Cache.[]
def [](key = nil) key ||= BasicCache.caller_name raise KeyError, 'Key not cached' unless include? key.to_sym @store[key.to_sym] end
ruby
def [](key = nil) key ||= BasicCache.caller_name raise KeyError, 'Key not cached' unless include? key.to_sym @store[key.to_sym] end
[ "def", "[]", "(", "key", "=", "nil", ")", "key", "||=", "BasicCache", ".", "caller_name", "raise", "KeyError", ",", "'Key not cached'", "unless", "include?", "key", ".", "to_sym", "@store", "[", "key", ".", "to_sym", "]", "end" ]
Retrieve cached value
[ "Retrieve", "cached", "value" ]
ac9c60218f2479aedf7f398f1dc2bae70b6d7fa3
https://github.com/akerl/basiccache/blob/ac9c60218f2479aedf7f398f1dc2bae70b6d7fa3/lib/basiccache/caches/cache.rb#L50-L54
6,748
TonFw/br_open_data
lib/br_open_data/chamber/service.rb
BROpenData::Chamber.Service.setup_propositions
def setup_propositions(params) self.params = { sigla: params[:sigla], numero: params[:numero], ano: params[:ano], datApresentacaoIni: params[:datApresentacaoIni], generoAutor: params[:generoAutor], datApresentacaoFim: params[:datApresentacaoFim], parteNomeAutor: params[:parteNomeAutor], idTipoAutor: params[:idTipoAutor], siglaUFAutor: params[:siglaUFAutor], codEstado: params[:codEstado], codOrgaoEstado: params[:codOrgaoEstado], emTramitacao: params[:emTramitacao], siglaPartidoAutor: params[:siglaPartidoAutor] } end
ruby
def setup_propositions(params) self.params = { sigla: params[:sigla], numero: params[:numero], ano: params[:ano], datApresentacaoIni: params[:datApresentacaoIni], generoAutor: params[:generoAutor], datApresentacaoFim: params[:datApresentacaoFim], parteNomeAutor: params[:parteNomeAutor], idTipoAutor: params[:idTipoAutor], siglaUFAutor: params[:siglaUFAutor], codEstado: params[:codEstado], codOrgaoEstado: params[:codOrgaoEstado], emTramitacao: params[:emTramitacao], siglaPartidoAutor: params[:siglaPartidoAutor] } end
[ "def", "setup_propositions", "(", "params", ")", "self", ".", "params", "=", "{", "sigla", ":", "params", "[", ":sigla", "]", ",", "numero", ":", "params", "[", ":numero", "]", ",", "ano", ":", "params", "[", ":ano", "]", ",", "datApresentacaoIni", ":", "params", "[", ":datApresentacaoIni", "]", ",", "generoAutor", ":", "params", "[", ":generoAutor", "]", ",", "datApresentacaoFim", ":", "params", "[", ":datApresentacaoFim", "]", ",", "parteNomeAutor", ":", "params", "[", ":parteNomeAutor", "]", ",", "idTipoAutor", ":", "params", "[", ":idTipoAutor", "]", ",", "siglaUFAutor", ":", "params", "[", ":siglaUFAutor", "]", ",", "codEstado", ":", "params", "[", ":codEstado", "]", ",", "codOrgaoEstado", ":", "params", "[", ":codOrgaoEstado", "]", ",", "emTramitacao", ":", "params", "[", ":emTramitacao", "]", ",", "siglaPartidoAutor", ":", "params", "[", ":siglaPartidoAutor", "]", "}", "end" ]
SetUp the params to be not nil
[ "SetUp", "the", "params", "to", "be", "not", "nil" ]
c0ddfbf0b38137aa4246d634468520a755248dae
https://github.com/TonFw/br_open_data/blob/c0ddfbf0b38137aa4246d634468520a755248dae/lib/br_open_data/chamber/service.rb#L21-L28
6,749
barkerest/incline
lib/incline/extensions/jbuilder_template.rb
Incline::Extensions.JbuilderTemplate.api_errors!
def api_errors!(model_name, model_errors) base_error = model_errors[:base] field_errors = model_errors.reject{ |k,_| k == :base } unless base_error.blank? set! 'error', "#{model_name.humanize} #{base_error.map{|e| h(e.to_s)}.join("<br>\n#{model_name.humanize} ")}" end unless field_errors.blank? set! 'fieldErrors' do array! field_errors do |k,v| set! 'name', "#{model_name}.#{k}" set! 'status', v.is_a?(::Array) ? "#{k.to_s.humanize} #{v.map{|e| h(e.to_s)}.join("<br>\n#{k.to_s.humanize} ")}" : "#{k.to_s.humanize} #{h v.to_s}" end end end end
ruby
def api_errors!(model_name, model_errors) base_error = model_errors[:base] field_errors = model_errors.reject{ |k,_| k == :base } unless base_error.blank? set! 'error', "#{model_name.humanize} #{base_error.map{|e| h(e.to_s)}.join("<br>\n#{model_name.humanize} ")}" end unless field_errors.blank? set! 'fieldErrors' do array! field_errors do |k,v| set! 'name', "#{model_name}.#{k}" set! 'status', v.is_a?(::Array) ? "#{k.to_s.humanize} #{v.map{|e| h(e.to_s)}.join("<br>\n#{k.to_s.humanize} ")}" : "#{k.to_s.humanize} #{h v.to_s}" end end end end
[ "def", "api_errors!", "(", "model_name", ",", "model_errors", ")", "base_error", "=", "model_errors", "[", ":base", "]", "field_errors", "=", "model_errors", ".", "reject", "{", "|", "k", ",", "_", "|", "k", "==", ":base", "}", "unless", "base_error", ".", "blank?", "set!", "'error'", ",", "\"#{model_name.humanize} #{base_error.map{|e| h(e.to_s)}.join(\"<br>\\n#{model_name.humanize} \")}\"", "end", "unless", "field_errors", ".", "blank?", "set!", "'fieldErrors'", "do", "array!", "field_errors", "do", "|", "k", ",", "v", "|", "set!", "'name'", ",", "\"#{model_name}.#{k}\"", "set!", "'status'", ",", "v", ".", "is_a?", "(", "::", "Array", ")", "?", "\"#{k.to_s.humanize} #{v.map{|e| h(e.to_s)}.join(\"<br>\\n#{k.to_s.humanize} \")}\"", ":", "\"#{k.to_s.humanize} #{h v.to_s}\"", "end", "end", "end", "end" ]
List out the errors for the model. model_name:: The singular name for the model (e.g. - "user_account") model_errors:: The errors collection from the model. json.api_errors! "user_account", user.errors
[ "List", "out", "the", "errors", "for", "the", "model", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/jbuilder_template.rb#L17-L33
6,750
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.RGB_.assign
def assign(value) value = value.simplify if @value.r.respond_to? :assign @value.r.assign value.get.r else @value.r = value.get.r end if @value.g.respond_to? :assign @value.g.assign value.get.g else @value.g = value.get.g end if @value.b.respond_to? :assign @value.b.assign value.get.b else @value.b = value.get.b end value end
ruby
def assign(value) value = value.simplify if @value.r.respond_to? :assign @value.r.assign value.get.r else @value.r = value.get.r end if @value.g.respond_to? :assign @value.g.assign value.get.g else @value.g = value.get.g end if @value.b.respond_to? :assign @value.b.assign value.get.b else @value.b = value.get.b end value end
[ "def", "assign", "(", "value", ")", "value", "=", "value", ".", "simplify", "if", "@value", ".", "r", ".", "respond_to?", ":assign", "@value", ".", "r", ".", "assign", "value", ".", "get", ".", "r", "else", "@value", ".", "r", "=", "value", ".", "get", ".", "r", "end", "if", "@value", ".", "g", ".", "respond_to?", ":assign", "@value", ".", "g", ".", "assign", "value", ".", "get", ".", "g", "else", "@value", ".", "g", "=", "value", ".", "get", ".", "g", "end", "if", "@value", ".", "b", ".", "respond_to?", ":assign", "@value", ".", "b", ".", "assign", "value", ".", "get", ".", "b", "else", "@value", ".", "b", "=", "value", ".", "get", ".", "b", "end", "value", "end" ]
Constructor for native RGB value @param [RGB] value Initial RGB value. Duplicate object @return [RGB_] Duplicate of +self+. Store new value in this object @param [Object] value New value for this object. @return [Object] Returns +value+. @private
[ "Constructor", "for", "native", "RGB", "value" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L428-L446
6,751
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.r_with_decompose
def r_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] r_without_decompose elsif typecode < RGB_ decompose 0 else self end end
ruby
def r_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] r_without_decompose elsif typecode < RGB_ decompose 0 else self end end
[ "def", "r_with_decompose", "if", "typecode", "==", "OBJECT", "or", "is_a?", "(", "Variable", ")", "or", "Thread", ".", "current", "[", ":lazy", "]", "r_without_decompose", "elsif", "typecode", "<", "RGB_", "decompose", "0", "else", "self", "end", "end" ]
Fast extraction for red channel of RGB array @return [Node] Array with red channel.
[ "Fast", "extraction", "for", "red", "channel", "of", "RGB", "array" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L531-L539
6,752
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.g_with_decompose
def g_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] g_without_decompose elsif typecode < RGB_ decompose 1 else self end end
ruby
def g_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] g_without_decompose elsif typecode < RGB_ decompose 1 else self end end
[ "def", "g_with_decompose", "if", "typecode", "==", "OBJECT", "or", "is_a?", "(", "Variable", ")", "or", "Thread", ".", "current", "[", ":lazy", "]", "g_without_decompose", "elsif", "typecode", "<", "RGB_", "decompose", "1", "else", "self", "end", "end" ]
Fast extraction for green channel of RGB array @return [Node] Array with green channel.
[ "Fast", "extraction", "for", "green", "channel", "of", "RGB", "array" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L563-L571
6,753
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.b_with_decompose
def b_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] b_without_decompose elsif typecode < RGB_ decompose 2 else self end end
ruby
def b_with_decompose if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy] b_without_decompose elsif typecode < RGB_ decompose 2 else self end end
[ "def", "b_with_decompose", "if", "typecode", "==", "OBJECT", "or", "is_a?", "(", "Variable", ")", "or", "Thread", ".", "current", "[", ":lazy", "]", "b_without_decompose", "elsif", "typecode", "<", "RGB_", "decompose", "2", "else", "self", "end", "end" ]
Fast extraction for blue channel of RGB array @return [Node] Array with blue channel.
[ "Fast", "extraction", "for", "blue", "channel", "of", "RGB", "array" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L595-L603
6,754
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.b=
def b=(value) if typecode < RGB_ decompose( 2 )[] = value elsif typecode == OBJECT self[] = Hornetseye::lazy do r * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + value * RGB.new( 0, 0, 1 ) end else raise "Cannot assign blue channel to elements of type #{typecode.inspect}" end end
ruby
def b=(value) if typecode < RGB_ decompose( 2 )[] = value elsif typecode == OBJECT self[] = Hornetseye::lazy do r * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + value * RGB.new( 0, 0, 1 ) end else raise "Cannot assign blue channel to elements of type #{typecode.inspect}" end end
[ "def", "b", "=", "(", "value", ")", "if", "typecode", "<", "RGB_", "decompose", "(", "2", ")", "[", "]", "=", "value", "elsif", "typecode", "==", "OBJECT", "self", "[", "]", "=", "Hornetseye", "::", "lazy", "do", "r", "*", "RGB", ".", "new", "(", "1", ",", "0", ",", "0", ")", "+", "g", "*", "RGB", ".", "new", "(", "0", ",", "1", ",", "0", ")", "+", "value", "*", "RGB", ".", "new", "(", "0", ",", "0", ",", "1", ")", "end", "else", "raise", "\"Cannot assign blue channel to elements of type #{typecode.inspect}\"", "end", "end" ]
Assignment for blue channel values of RGB array @param [Object] Value or array of values to assign to blue channel. @return [Object] Returns +value+.
[ "Assignment", "for", "blue", "channel", "values", "of", "RGB", "array" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L612-L622
6,755
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.histogram_with_rgb
def histogram_with_rgb( *ret_shape ) if typecode < RGB_ [ r, g, b ].histogram *ret_shape else histogram_without_rgb *ret_shape end end
ruby
def histogram_with_rgb( *ret_shape ) if typecode < RGB_ [ r, g, b ].histogram *ret_shape else histogram_without_rgb *ret_shape end end
[ "def", "histogram_with_rgb", "(", "*", "ret_shape", ")", "if", "typecode", "<", "RGB_", "[", "r", ",", "g", ",", "b", "]", ".", "histogram", "ret_shape", "else", "histogram_without_rgb", "ret_shape", "end", "end" ]
Compute colour histogram of this array The array is decomposed to its colour channels and a histogram is computed. @overload histogram( *ret_shape, options = {} ) @param [Array<Integer>] ret_shape Dimensions of resulting histogram. @option options [Node] :weight (Hornetseye::UINT(1)) Weights for computing the histogram. @option options [Boolean] :safe (true) Do a boundary check before creating the histogram. @return [Node] The histogram.
[ "Compute", "colour", "histogram", "of", "this", "array" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L649-L655
6,756
wedesoft/multiarray
lib/multiarray/rgb.rb
Hornetseye.Node.lut_with_rgb
def lut_with_rgb( table, options = {} ) if typecode < RGB_ [ r, g, b ].lut table, options else lut_without_rgb table, options end end
ruby
def lut_with_rgb( table, options = {} ) if typecode < RGB_ [ r, g, b ].lut table, options else lut_without_rgb table, options end end
[ "def", "lut_with_rgb", "(", "table", ",", "options", "=", "{", "}", ")", "if", "typecode", "<", "RGB_", "[", "r", ",", "g", ",", "b", "]", ".", "lut", "table", ",", "options", "else", "lut_without_rgb", "table", ",", "options", "end", "end" ]
Perform element-wise lookup with colour values @param [Node] table The lookup table (LUT). @option options [Boolean] :safe (true) Do a boundary check before creating the element-wise lookup. @return [Node] The result of the lookup operation.
[ "Perform", "element", "-", "wise", "lookup", "with", "colour", "values" ]
1ae1d98bacb4b941d6f406e44ccb184de12f83d9
https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/rgb.rb#L666-L672
6,757
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.currency_field
def currency_field(method, options = {}) # get the symbol for the field. sym = options.delete(:currency_symbol) || '$' # get the value if (val = object.send(method)) options[:value] = number_with_precision val, precision: 2, delimiter: ',' end # build the field fld = text_field(method, options) # return the value. "<div class=\"input-symbol\"><span>#{CGI::escape_html sym}</span>#{fld}</div>".html_safe end
ruby
def currency_field(method, options = {}) # get the symbol for the field. sym = options.delete(:currency_symbol) || '$' # get the value if (val = object.send(method)) options[:value] = number_with_precision val, precision: 2, delimiter: ',' end # build the field fld = text_field(method, options) # return the value. "<div class=\"input-symbol\"><span>#{CGI::escape_html sym}</span>#{fld}</div>".html_safe end
[ "def", "currency_field", "(", "method", ",", "options", "=", "{", "}", ")", "# get the symbol for the field.", "sym", "=", "options", ".", "delete", "(", ":currency_symbol", ")", "||", "'$'", "# get the value", "if", "(", "val", "=", "object", ".", "send", "(", "method", ")", ")", "options", "[", ":value", "]", "=", "number_with_precision", "val", ",", "precision", ":", "2", ",", "delimiter", ":", "','", "end", "# build the field", "fld", "=", "text_field", "(", "method", ",", "options", ")", "# return the value.", "\"<div class=\\\"input-symbol\\\"><span>#{CGI::escape_html sym}</span>#{fld}</div>\"", ".", "html_safe", "end" ]
Creates a currency entry field. *Valid options:* currency_symbol:: A string used to prefix the input field. Defaults to '$'. All other options will be passed through to the {FormHelper#text_field}[http://apidock.com/rails/ActionView/Helpers/FormHelper/text_field] method. The value will be formatted with comma delimiters and two decimal places. f.currency :pay_rate
[ "Creates", "a", "currency", "entry", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L247-L261
6,758
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.text_form_group
def text_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(text_field(method, fopt)) form_group lbl, fld, gopt end
ruby
def text_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(text_field(method, fopt)) form_group lbl, fld, gopt end
[ "def", "text_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "(", "method", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "text_field", "(", "method", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a label and text field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see {FormHelper#text_field}[http://apidock.com/rails/ActionView/Helpers/FormHelper/text_field].
[ "Creates", "a", "standard", "form", "group", "with", "a", "label", "and", "text", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L302-L307
6,759
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.password_form_group
def password_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(password_field(method, fopt)) form_group lbl, fld, gopt end
ruby
def password_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(password_field(method, fopt)) form_group lbl, fld, gopt end
[ "def", "password_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "(", "method", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "password_field", "(", "method", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a label and password field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see {FormHelper#password_field}[http://apidock.com/rails/ActionView/Helpers/FormHelper/password_field].
[ "Creates", "a", "standard", "form", "group", "with", "a", "label", "and", "password", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L327-L332
6,760
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.textarea_form_group
def textarea_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small method, lopt fld = gopt[:wrap].call(text_area(method, fopt)) form_group lbl, fld, gopt end
ruby
def textarea_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small method, lopt fld = gopt[:wrap].call(text_area(method, fopt)) form_group lbl, fld, gopt end
[ "def", "textarea_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "method", ",", "lopt", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "text_area", "(", "method", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a form group including a label and a text area. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see {FormHelper#text_area}[http://apidock.com/rails/ActionView/Helpers/FormHelper/text_area].
[ "Creates", "a", "form", "group", "including", "a", "label", "and", "a", "text", "area", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L352-L357
6,761
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.currency_form_group
def currency_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(currency_field(method, fopt)) form_group lbl, fld, gopt end
ruby
def currency_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(currency_field(method, fopt)) form_group lbl, fld, gopt end
[ "def", "currency_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "(", "method", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "currency_field", "(", "method", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a label and currency field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see #currency_field.
[ "Creates", "a", "standard", "form", "group", "with", "a", "label", "and", "currency", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L377-L382
6,762
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.static_form_group
def static_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call("<input type=\"text\" class=\"form-control disabled\" readonly=\"readonly\" value=\"#{CGI::escape_html(fopt[:value] || object.send(method))}\">") form_group lbl, fld, gopt end
ruby
def static_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call("<input type=\"text\" class=\"form-control disabled\" readonly=\"readonly\" value=\"#{CGI::escape_html(fopt[:value] || object.send(method))}\">") form_group lbl, fld, gopt end
[ "def", "static_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "(", "method", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "\"<input type=\\\"text\\\" class=\\\"form-control disabled\\\" readonly=\\\"readonly\\\" value=\\\"#{CGI::escape_html(fopt[:value] || object.send(method))}\\\">\"", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a label and a static text field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. Field options: value:: Allows you to specify a value for the static field, otherwise the value from +method+ will be used.
[ "Creates", "a", "standard", "form", "group", "with", "a", "label", "and", "a", "static", "text", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L406-L411
6,763
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.datepicker_form_group
def datepicker_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(date_picker(method, fopt)) form_group lbl, fld, gopt end
ruby
def datepicker_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options(options) lbl = label_w_small(method, lopt) fld = gopt[:wrap].call(date_picker(method, fopt)) form_group lbl, fld, gopt end
[ "def", "datepicker_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lbl", "=", "label_w_small", "(", "method", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "date_picker", "(", "method", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a datepicker field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see #date_picker.
[ "Creates", "a", "standard", "form", "group", "with", "a", "datepicker", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L431-L436
6,764
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.multi_input_form_group
def multi_input_form_group(methods, options = {}) gopt, lopt, fopt = split_form_group_options(options) lopt[:text] ||= gopt[:label] if lopt[:text].blank? lopt[:text] = methods.map {|k,_| k.to_s.humanize }.join(', ') end lbl = label_w_small(methods.map{|k,_| k}.first, lopt) fld = gopt[:wrap].call(multi_input(methods, fopt)) form_group lbl, fld, gopt end
ruby
def multi_input_form_group(methods, options = {}) gopt, lopt, fopt = split_form_group_options(options) lopt[:text] ||= gopt[:label] if lopt[:text].blank? lopt[:text] = methods.map {|k,_| k.to_s.humanize }.join(', ') end lbl = label_w_small(methods.map{|k,_| k}.first, lopt) fld = gopt[:wrap].call(multi_input(methods, fopt)) form_group lbl, fld, gopt end
[ "def", "multi_input_form_group", "(", "methods", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "options", ")", "lopt", "[", ":text", "]", "||=", "gopt", "[", ":label", "]", "if", "lopt", "[", ":text", "]", ".", "blank?", "lopt", "[", ":text", "]", "=", "methods", ".", "map", "{", "|", "k", ",", "_", "|", "k", ".", "to_s", ".", "humanize", "}", ".", "join", "(", "', '", ")", "end", "lbl", "=", "label_w_small", "(", "methods", ".", "map", "{", "|", "k", ",", "_", "|", "k", "}", ".", "first", ",", "lopt", ")", "fld", "=", "gopt", "[", ":wrap", "]", ".", "call", "(", "multi_input", "(", "methods", ",", "fopt", ")", ")", "form_group", "lbl", ",", "fld", ",", "gopt", "end" ]
Creates a standard form group with a multiple input control. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. Defaults to 'form-group'. style:: Any styles to apply to the form group. For label options, see #label_w_small. For field options, see #multi_input_field.
[ "Creates", "a", "standard", "form", "group", "with", "a", "multiple", "input", "control", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L456-L465
6,765
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.check_box_form_group
def check_box_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options({ class: 'checkbox', field_class: ''}.merge(options)) if gopt[:h_align] gopt[:class] = gopt[:class].blank? ? "col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}" : "#{gopt[:class]} col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}" end lbl = label method do check_box(method, fopt) + CGI::escape_html(lopt[:text] || method.to_s.humanize) + (lopt[:small_text] ? " <small>(#{CGI::escape_html lopt[:small_text]})</small>" : '').html_safe end "<div class=\"#{gopt[:h_align] ? 'row' : 'form-group'}\"><div class=\"#{gopt[:class]}\">#{lbl}</div></div>".html_safe end
ruby
def check_box_form_group(method, options = {}) gopt, lopt, fopt = split_form_group_options({ class: 'checkbox', field_class: ''}.merge(options)) if gopt[:h_align] gopt[:class] = gopt[:class].blank? ? "col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}" : "#{gopt[:class]} col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}" end lbl = label method do check_box(method, fopt) + CGI::escape_html(lopt[:text] || method.to_s.humanize) + (lopt[:small_text] ? " <small>(#{CGI::escape_html lopt[:small_text]})</small>" : '').html_safe end "<div class=\"#{gopt[:h_align] ? 'row' : 'form-group'}\"><div class=\"#{gopt[:class]}\">#{lbl}</div></div>".html_safe end
[ "def", "check_box_form_group", "(", "method", ",", "options", "=", "{", "}", ")", "gopt", ",", "lopt", ",", "fopt", "=", "split_form_group_options", "(", "{", "class", ":", "'checkbox'", ",", "field_class", ":", "''", "}", ".", "merge", "(", "options", ")", ")", "if", "gopt", "[", ":h_align", "]", "gopt", "[", ":class", "]", "=", "gopt", "[", ":class", "]", ".", "blank?", "?", "\"col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}\"", ":", "\"#{gopt[:class]} col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}\"", "end", "lbl", "=", "label", "method", "do", "check_box", "(", "method", ",", "fopt", ")", "+", "CGI", "::", "escape_html", "(", "lopt", "[", ":text", "]", "||", "method", ".", "to_s", ".", "humanize", ")", "+", "(", "lopt", "[", ":small_text", "]", "?", "\" <small>(#{CGI::escape_html lopt[:small_text]})</small>\"", ":", "''", ")", ".", "html_safe", "end", "\"<div class=\\\"#{gopt[:h_align] ? 'row' : 'form-group'}\\\"><div class=\\\"#{gopt[:class]}\\\">#{lbl}</div></div>\"", ".", "html_safe", "end" ]
Creates a standard form group with a checkbox field. The +options+ is a hash containing label, field, and group options. Prefix label options with +label_+ and field options with +field_+. All other options will apply to the group itself. Group options: class:: The CSS class for the form group. h_align:: Create a checkbox aligned to a certain column (1-12) if set. If not set, then a regular form group is generated. For label options, see #label_w_small. For field options, see {FormHelper#check_box}[http://apidock.com/rails/ActionView/Helpers/FormHelper/check_box].
[ "Creates", "a", "standard", "form", "group", "with", "a", "checkbox", "field", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L486-L502
6,766
barkerest/incline
lib/incline/extensions/form_builder.rb
Incline::Extensions.FormBuilder.recaptcha
def recaptcha(method, options = {}) Incline::Recaptcha::Tag.new(@object_name, method, @template, options).render end
ruby
def recaptcha(method, options = {}) Incline::Recaptcha::Tag.new(@object_name, method, @template, options).render end
[ "def", "recaptcha", "(", "method", ",", "options", "=", "{", "}", ")", "Incline", "::", "Recaptcha", "::", "Tag", ".", "new", "(", "@object_name", ",", "method", ",", "@template", ",", "options", ")", ".", "render", "end" ]
Adds a recaptcha challenge to the form configured to set the specified attribute to the recaptcha response. Valid options: theme:: Can be :dark or :light, defaults to :light. type:: Can be :image or :audio, defaults to :image. size:: Can be :compact or :normal, defaults to :normal. tab_index:: Can be any valid integer if you want a specific tab order, defaults to 0.
[ "Adds", "a", "recaptcha", "challenge", "to", "the", "form", "configured", "to", "set", "the", "specified", "attribute", "to", "the", "recaptcha", "response", "." ]
1ff08db7aa8ab7f86b223268b700bc67d15bb8aa
https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/form_builder.rb#L557-L559
6,767
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.addopt
def addopt ( opt ) raise TypeError, 'Incorrectly types for option object.' unless opt.instance_of? Cmdlib::Option @options[opt.longname.to_sym] = opt end
ruby
def addopt ( opt ) raise TypeError, 'Incorrectly types for option object.' unless opt.instance_of? Cmdlib::Option @options[opt.longname.to_sym] = opt end
[ "def", "addopt", "(", "opt", ")", "raise", "TypeError", ",", "'Incorrectly types for option object.'", "unless", "opt", ".", "instance_of?", "Cmdlib", "::", "Option", "@options", "[", "opt", ".", "longname", ".", "to_sym", "]", "=", "opt", "end" ]
Add CLICommand object to CLIHandler.
[ "Add", "CLICommand", "object", "to", "CLIHandler", "." ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L36-L41
6,768
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.display_commands
def display_commands( cmdlist ) maxlen = 0 cmdlist.each do |cmd| maxlen = cmd.name.length if cmd.name.length > maxlen end cmdlist.each do |cmd| print ' ' + cmd.name print "#{' ' * (maxlen - cmd.name.length)} # " puts cmd.brief end end
ruby
def display_commands( cmdlist ) maxlen = 0 cmdlist.each do |cmd| maxlen = cmd.name.length if cmd.name.length > maxlen end cmdlist.each do |cmd| print ' ' + cmd.name print "#{' ' * (maxlen - cmd.name.length)} # " puts cmd.brief end end
[ "def", "display_commands", "(", "cmdlist", ")", "maxlen", "=", "0", "cmdlist", ".", "each", "do", "|", "cmd", "|", "maxlen", "=", "cmd", ".", "name", ".", "length", "if", "cmd", ".", "name", ".", "length", ">", "maxlen", "end", "cmdlist", ".", "each", "do", "|", "cmd", "|", "print", "' '", "+", "cmd", ".", "name", "print", "\"#{' ' * (maxlen - cmd.name.length)} # \"", "puts", "cmd", ".", "brief", "end", "end" ]
Display commands info
[ "Display", "commands", "info" ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L54-L64
6,769
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.display_options
def display_options( optlist ) maxlen = 0 listout = [] optlist.each_value do |opt| optnames = '' if opt.shortname.length == 0 optnames += ' ' else optnames += OPTION_PREFIX_SHORT + opt.shortname end optnames += ',' optnames += OPTION_PREFIX_LONG + opt.longname if opt.longname.length != 0 optnames += '=[...]' if opt.param == true listout << { :n => optnames, :b => opt.brief } maxlen = optnames.length if optnames.length > maxlen end listout.each do |opt| print ' ' + opt[:n] print "#{' ' * (maxlen - opt[:n].length)} # " puts opt[:b] end end
ruby
def display_options( optlist ) maxlen = 0 listout = [] optlist.each_value do |opt| optnames = '' if opt.shortname.length == 0 optnames += ' ' else optnames += OPTION_PREFIX_SHORT + opt.shortname end optnames += ',' optnames += OPTION_PREFIX_LONG + opt.longname if opt.longname.length != 0 optnames += '=[...]' if opt.param == true listout << { :n => optnames, :b => opt.brief } maxlen = optnames.length if optnames.length > maxlen end listout.each do |opt| print ' ' + opt[:n] print "#{' ' * (maxlen - opt[:n].length)} # " puts opt[:b] end end
[ "def", "display_options", "(", "optlist", ")", "maxlen", "=", "0", "listout", "=", "[", "]", "optlist", ".", "each_value", "do", "|", "opt", "|", "optnames", "=", "''", "if", "opt", ".", "shortname", ".", "length", "==", "0", "optnames", "+=", "' '", "else", "optnames", "+=", "OPTION_PREFIX_SHORT", "+", "opt", ".", "shortname", "end", "optnames", "+=", "','", "optnames", "+=", "OPTION_PREFIX_LONG", "+", "opt", ".", "longname", "if", "opt", ".", "longname", ".", "length", "!=", "0", "optnames", "+=", "'=[...]'", "if", "opt", ".", "param", "==", "true", "listout", "<<", "{", ":n", "=>", "optnames", ",", ":b", "=>", "opt", ".", "brief", "}", "maxlen", "=", "optnames", ".", "length", "if", "optnames", ".", "length", ">", "maxlen", "end", "listout", ".", "each", "do", "|", "opt", "|", "print", "' '", "+", "opt", "[", ":n", "]", "print", "\"#{' ' * (maxlen - opt[:n].length)} # \"", "puts", "opt", "[", ":b", "]", "end", "end" ]
Display options info
[ "Display", "options", "info" ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L68-L89
6,770
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.run
def run option_parser @options # Check on include version request. if @options[:version].value then puts "#{@name}, version #{@version}" exit end # Check on include help request. if ARGV[0] == 'help' or ARGV[0] == '--help' or ARGV[0] == '-h' then # Help arguments apsent, well then display information about application. if ARGV.size == 1 then puts puts "*** #{@name} ***".center(80) # Display about info. if @about.size > 0 then puts '** ABOUT:' @about.each do |line| puts " #{line}" end end # Display usage info. if @usage.size > 0 then puts puts '** USAGE:' @usage.each do |line| puts " #{line}" end end # Display options info. puts puts '** OPTIONS:' display_options @options # Display commands info if @commands.size > 0 then @commands.each do |c| c.init end puts puts '** COMMANDS:' display_commands @commands puts puts "For details, type: help [COMMAND]" end puts # Help arguments exist, find command in application command list. else ARGV.delete_at( 0 ) cmd = command_select if ARGV.size != 0 then puts "fatal error: unknown command '#{ARGV[0]}'" exit end # Display describe information on command. puts puts Cmdlib::Describe.outtitle( cmd.name ) puts " #{cmd.brief}" if cmd.details.size > 0 then puts puts '** DETAILS:' cmd.details.each do |e| puts " #{e}" end end if cmd.example.size > 0 then puts puts '** EXAMPLE:' cmd.example.each do |e| puts " #{e}" end end # Display options info. if cmd.options.size > 0 then puts puts '** OPTIONS:' display_options cmd.options end # Display commands info. if cmd.subcmd.size > 0 then cmd.subcmd.each do |c| c.init end puts puts '** SUBCOMMANDS:' display_commands cmd.subcmd puts puts "For details, type: help #{cmd.name} [SUBCOMMAND]" end puts end exit end # Handling default command (if exist her). if @default != nil then option_excess if ARGV.size < @default.argnum then puts "fatal error: to few arguments for programm, use <help>." else @default.handler( @options, ARGV ) end exit end # Handling commands. cmd = command_select if cmd == nil then puts "fatal error: unknown command or command miss, use <help>." exit end if ARGV.size < cmd.argnum then puts "fatal error: to few arguments for command, use: <help> <command name>." exit end # Scaning options fir this command option_parser cmd.options option_excess #cmd.init cmd.handler( @options, ARGV ) exit end
ruby
def run option_parser @options # Check on include version request. if @options[:version].value then puts "#{@name}, version #{@version}" exit end # Check on include help request. if ARGV[0] == 'help' or ARGV[0] == '--help' or ARGV[0] == '-h' then # Help arguments apsent, well then display information about application. if ARGV.size == 1 then puts puts "*** #{@name} ***".center(80) # Display about info. if @about.size > 0 then puts '** ABOUT:' @about.each do |line| puts " #{line}" end end # Display usage info. if @usage.size > 0 then puts puts '** USAGE:' @usage.each do |line| puts " #{line}" end end # Display options info. puts puts '** OPTIONS:' display_options @options # Display commands info if @commands.size > 0 then @commands.each do |c| c.init end puts puts '** COMMANDS:' display_commands @commands puts puts "For details, type: help [COMMAND]" end puts # Help arguments exist, find command in application command list. else ARGV.delete_at( 0 ) cmd = command_select if ARGV.size != 0 then puts "fatal error: unknown command '#{ARGV[0]}'" exit end # Display describe information on command. puts puts Cmdlib::Describe.outtitle( cmd.name ) puts " #{cmd.brief}" if cmd.details.size > 0 then puts puts '** DETAILS:' cmd.details.each do |e| puts " #{e}" end end if cmd.example.size > 0 then puts puts '** EXAMPLE:' cmd.example.each do |e| puts " #{e}" end end # Display options info. if cmd.options.size > 0 then puts puts '** OPTIONS:' display_options cmd.options end # Display commands info. if cmd.subcmd.size > 0 then cmd.subcmd.each do |c| c.init end puts puts '** SUBCOMMANDS:' display_commands cmd.subcmd puts puts "For details, type: help #{cmd.name} [SUBCOMMAND]" end puts end exit end # Handling default command (if exist her). if @default != nil then option_excess if ARGV.size < @default.argnum then puts "fatal error: to few arguments for programm, use <help>." else @default.handler( @options, ARGV ) end exit end # Handling commands. cmd = command_select if cmd == nil then puts "fatal error: unknown command or command miss, use <help>." exit end if ARGV.size < cmd.argnum then puts "fatal error: to few arguments for command, use: <help> <command name>." exit end # Scaning options fir this command option_parser cmd.options option_excess #cmd.init cmd.handler( @options, ARGV ) exit end
[ "def", "run", "option_parser", "@options", "# Check on include version request.\r", "if", "@options", "[", ":version", "]", ".", "value", "then", "puts", "\"#{@name}, version #{@version}\"", "exit", "end", "# Check on include help request.\r", "if", "ARGV", "[", "0", "]", "==", "'help'", "or", "ARGV", "[", "0", "]", "==", "'--help'", "or", "ARGV", "[", "0", "]", "==", "'-h'", "then", "# Help arguments apsent, well then display information about application.\r", "if", "ARGV", ".", "size", "==", "1", "then", "puts", "puts", "\"*** #{@name} ***\"", ".", "center", "(", "80", ")", "# Display about info.\r", "if", "@about", ".", "size", ">", "0", "then", "puts", "'** ABOUT:'", "@about", ".", "each", "do", "|", "line", "|", "puts", "\" #{line}\"", "end", "end", "# Display usage info.\r", "if", "@usage", ".", "size", ">", "0", "then", "puts", "puts", "'** USAGE:'", "@usage", ".", "each", "do", "|", "line", "|", "puts", "\" #{line}\"", "end", "end", "# Display options info.\r", "puts", "puts", "'** OPTIONS:'", "display_options", "@options", "# Display commands info\r", "if", "@commands", ".", "size", ">", "0", "then", "@commands", ".", "each", "do", "|", "c", "|", "c", ".", "init", "end", "puts", "puts", "'** COMMANDS:'", "display_commands", "@commands", "puts", "puts", "\"For details, type: help [COMMAND]\"", "end", "puts", "# Help arguments exist, find command in application command list.\r", "else", "ARGV", ".", "delete_at", "(", "0", ")", "cmd", "=", "command_select", "if", "ARGV", ".", "size", "!=", "0", "then", "puts", "\"fatal error: unknown command '#{ARGV[0]}'\"", "exit", "end", "# Display describe information on command.\r", "puts", "puts", "Cmdlib", "::", "Describe", ".", "outtitle", "(", "cmd", ".", "name", ")", "puts", "\" #{cmd.brief}\"", "if", "cmd", ".", "details", ".", "size", ">", "0", "then", "puts", "puts", "'** DETAILS:'", "cmd", ".", "details", ".", "each", "do", "|", "e", "|", "puts", "\" #{e}\"", "end", "end", "if", "cmd", ".", "example", ".", "size", ">", "0", "then", "puts", "puts", "'** EXAMPLE:'", "cmd", ".", "example", ".", "each", "do", "|", "e", "|", "puts", "\" #{e}\"", "end", "end", "# Display options info.\r", "if", "cmd", ".", "options", ".", "size", ">", "0", "then", "puts", "puts", "'** OPTIONS:'", "display_options", "cmd", ".", "options", "end", "# Display commands info.\r", "if", "cmd", ".", "subcmd", ".", "size", ">", "0", "then", "cmd", ".", "subcmd", ".", "each", "do", "|", "c", "|", "c", ".", "init", "end", "puts", "puts", "'** SUBCOMMANDS:'", "display_commands", "cmd", ".", "subcmd", "puts", "puts", "\"For details, type: help #{cmd.name} [SUBCOMMAND]\"", "end", "puts", "end", "exit", "end", "# Handling default command (if exist her).\r", "if", "@default", "!=", "nil", "then", "option_excess", "if", "ARGV", ".", "size", "<", "@default", ".", "argnum", "then", "puts", "\"fatal error: to few arguments for programm, use <help>.\"", "else", "@default", ".", "handler", "(", "@options", ",", "ARGV", ")", "end", "exit", "end", "# Handling commands.\r", "cmd", "=", "command_select", "if", "cmd", "==", "nil", "then", "puts", "\"fatal error: unknown command or command miss, use <help>.\"", "exit", "end", "if", "ARGV", ".", "size", "<", "cmd", ".", "argnum", "then", "puts", "\"fatal error: to few arguments for command, use: <help> <command name>.\"", "exit", "end", "# Scaning options fir this command\r", "option_parser", "cmd", ".", "options", "option_excess", "#cmd.init\r", "cmd", ".", "handler", "(", "@options", ",", "ARGV", ")", "exit", "end" ]
Main method to run application.
[ "Main", "method", "to", "run", "application", "." ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L93-L210
6,771
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.command_select
def command_select command = command_search( @commands, ARGV[0] ) if command != nil then # remove command name from ARGV and search next. ARGV.delete_at( 0 ) ARGV.each do |arg| cmd = command_search( command.subcmd, arg ) break if cmd == nil ARGV.delete_at( 0 ) command = cmd end end return command end
ruby
def command_select command = command_search( @commands, ARGV[0] ) if command != nil then # remove command name from ARGV and search next. ARGV.delete_at( 0 ) ARGV.each do |arg| cmd = command_search( command.subcmd, arg ) break if cmd == nil ARGV.delete_at( 0 ) command = cmd end end return command end
[ "def", "command_select", "command", "=", "command_search", "(", "@commands", ",", "ARGV", "[", "0", "]", ")", "if", "command", "!=", "nil", "then", "# remove command name from ARGV and search next.\r", "ARGV", ".", "delete_at", "(", "0", ")", "ARGV", ".", "each", "do", "|", "arg", "|", "cmd", "=", "command_search", "(", "command", ".", "subcmd", ",", "arg", ")", "break", "if", "cmd", "==", "nil", "ARGV", ".", "delete_at", "(", "0", ")", "command", "=", "cmd", "end", "end", "return", "command", "end" ]
Select and return command object in application.
[ "Select", "and", "return", "command", "object", "in", "application", "." ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L228-L241
6,772
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.option_excess
def option_excess ARGV.each do |opt| o = getopt( opt ) if o[:n] != '' then puts "fatal error: unknown option '#{o[:t]}#{o[:n]}'" exit end end end
ruby
def option_excess ARGV.each do |opt| o = getopt( opt ) if o[:n] != '' then puts "fatal error: unknown option '#{o[:t]}#{o[:n]}'" exit end end end
[ "def", "option_excess", "ARGV", ".", "each", "do", "|", "opt", "|", "o", "=", "getopt", "(", "opt", ")", "if", "o", "[", ":n", "]", "!=", "''", "then", "puts", "\"fatal error: unknown option '#{o[:t]}#{o[:n]}'\"", "exit", "end", "end", "end" ]
Check ARGV to exess options.
[ "Check", "ARGV", "to", "exess", "options", "." ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L268-L276
6,773
gera-gas/cmdlib
lib/cmdlib/application.rb
Cmdlib.App.option_parser
def option_parser( optlist ) return if optlist.size == 0 deletelist = [] # search option in argument list. ARGV.each_with_index do |opt,i| o = getopt( opt ) if o[:n] != '' and o[:n] != 'h' and o[:n] != 'help' o[:i] = i # Search in application list result = option_search( o, optlist ) if result != nil then deletelist << opt result = option_set( o, optlist[result] ) deletelist << result if result != '' end end end # delete option from ARGV. deletelist.each do |n| ARGV.delete( n ) end end
ruby
def option_parser( optlist ) return if optlist.size == 0 deletelist = [] # search option in argument list. ARGV.each_with_index do |opt,i| o = getopt( opt ) if o[:n] != '' and o[:n] != 'h' and o[:n] != 'help' o[:i] = i # Search in application list result = option_search( o, optlist ) if result != nil then deletelist << opt result = option_set( o, optlist[result] ) deletelist << result if result != '' end end end # delete option from ARGV. deletelist.each do |n| ARGV.delete( n ) end end
[ "def", "option_parser", "(", "optlist", ")", "return", "if", "optlist", ".", "size", "==", "0", "deletelist", "=", "[", "]", "# search option in argument list.\r", "ARGV", ".", "each_with_index", "do", "|", "opt", ",", "i", "|", "o", "=", "getopt", "(", "opt", ")", "if", "o", "[", ":n", "]", "!=", "''", "and", "o", "[", ":n", "]", "!=", "'h'", "and", "o", "[", ":n", "]", "!=", "'help'", "o", "[", ":i", "]", "=", "i", "# Search in application list\r", "result", "=", "option_search", "(", "o", ",", "optlist", ")", "if", "result", "!=", "nil", "then", "deletelist", "<<", "opt", "result", "=", "option_set", "(", "o", ",", "optlist", "[", "result", "]", ")", "deletelist", "<<", "result", "if", "result", "!=", "''", "end", "end", "end", "# delete option from ARGV.\r", "deletelist", ".", "each", "do", "|", "n", "|", "ARGV", ".", "delete", "(", "n", ")", "end", "end" ]
Parsing options in command line.
[ "Parsing", "options", "in", "command", "line", "." ]
2f2a4f99f2de75224bdf02d90ee04112980392b3
https://github.com/gera-gas/cmdlib/blob/2f2a4f99f2de75224bdf02d90ee04112980392b3/lib/cmdlib/application.rb#L345-L366
6,774
outcomesinsights/dbtap
lib/dbtap/tapper.rb
Dbtap.Tapper.run
def run puts (1..tests.length).to_s tests.each_with_index do |test, i| begin if test.is_ok? ok(test, i) else not_ok(test, i) end rescue Sequel::DatabaseError puts $!.sql raise $! end end end
ruby
def run puts (1..tests.length).to_s tests.each_with_index do |test, i| begin if test.is_ok? ok(test, i) else not_ok(test, i) end rescue Sequel::DatabaseError puts $!.sql raise $! end end end
[ "def", "run", "puts", "(", "1", "..", "tests", ".", "length", ")", ".", "to_s", "tests", ".", "each_with_index", "do", "|", "test", ",", "i", "|", "begin", "if", "test", ".", "is_ok?", "ok", "(", "test", ",", "i", ")", "else", "not_ok", "(", "test", ",", "i", ")", "end", "rescue", "Sequel", "::", "DatabaseError", "puts", "$!", ".", "sql", "raise", "$!", "end", "end", "end" ]
Drives the evaluation of each test, emitting TAP-compliant messages for each test
[ "Drives", "the", "evaluation", "of", "each", "test", "emitting", "TAP", "-", "compliant", "messages", "for", "each", "test" ]
aa3b623fd7fc0668098c1c73dd69141afbbc1ea3
https://github.com/outcomesinsights/dbtap/blob/aa3b623fd7fc0668098c1c73dd69141afbbc1ea3/lib/dbtap/tapper.rb#L18-L32
6,775
outcomesinsights/dbtap
lib/dbtap/tapper.rb
Dbtap.Tapper.ok
def ok(test, i) message = "ok #{i + 1}" message += ' - ' + test.name if test.name puts message end
ruby
def ok(test, i) message = "ok #{i + 1}" message += ' - ' + test.name if test.name puts message end
[ "def", "ok", "(", "test", ",", "i", ")", "message", "=", "\"ok #{i + 1}\"", "message", "+=", "' - '", "+", "test", ".", "name", "if", "test", ".", "name", "puts", "message", "end" ]
Emits a TAP-compliant OK message
[ "Emits", "a", "TAP", "-", "compliant", "OK", "message" ]
aa3b623fd7fc0668098c1c73dd69141afbbc1ea3
https://github.com/outcomesinsights/dbtap/blob/aa3b623fd7fc0668098c1c73dd69141afbbc1ea3/lib/dbtap/tapper.rb#L36-L40
6,776
outcomesinsights/dbtap
lib/dbtap/tapper.rb
Dbtap.Tapper.not_ok
def not_ok(test, i) message = "not ok #{i + 1}" message += ' - ' + test.name if test.name message += "\n " + test.errors.join("\n ") if test.errors puts message end
ruby
def not_ok(test, i) message = "not ok #{i + 1}" message += ' - ' + test.name if test.name message += "\n " + test.errors.join("\n ") if test.errors puts message end
[ "def", "not_ok", "(", "test", ",", "i", ")", "message", "=", "\"not ok #{i + 1}\"", "message", "+=", "' - '", "+", "test", ".", "name", "if", "test", ".", "name", "message", "+=", "\"\\n \"", "+", "test", ".", "errors", ".", "join", "(", "\"\\n \"", ")", "if", "test", ".", "errors", "puts", "message", "end" ]
Emits a TAP-compliant NOT OK message
[ "Emits", "a", "TAP", "-", "compliant", "NOT", "OK", "message" ]
aa3b623fd7fc0668098c1c73dd69141afbbc1ea3
https://github.com/outcomesinsights/dbtap/blob/aa3b623fd7fc0668098c1c73dd69141afbbc1ea3/lib/dbtap/tapper.rb#L43-L48
6,777
nrser/nrser.rb
lib/nrser/decorate.rb
NRSER.Decorate.resolve_method
def resolve_method name:, default_type: nil name_string = name.to_s # .gsub( /\A\@\@/, '.' ).gsub( /\A\@/, '#' ) case name_string when Meta::Names::Method::Bare bare_name = Meta::Names::Method::Bare.new name_string case default_type&.to_sym when nil raise NRSER::ArgumentError.new \ "When `default_type:` param is `nil` `name:` must start with '.'", "or '#'", name: name when :singleton, :class method bare_name when :instance instance_method bare_name else raise NRSER::ArgumentError.new \ "`default_type:` param must be `nil`, `:instance`, `:singleton` or", "`:class`, found", default_type.inspect, name: name, default_type: default_type end when Meta::Names::Method::Singleton method Meta::Names::Method::Singleton.new( name_string ).bare_name when Meta::Names::Method::Instance instance_method Meta::Names::Method::Instance.new( name_string ).bare_name else raise NRSER::ArgumentError.new \ "`name:` does not look like a method name:", name.inspect end end
ruby
def resolve_method name:, default_type: nil name_string = name.to_s # .gsub( /\A\@\@/, '.' ).gsub( /\A\@/, '#' ) case name_string when Meta::Names::Method::Bare bare_name = Meta::Names::Method::Bare.new name_string case default_type&.to_sym when nil raise NRSER::ArgumentError.new \ "When `default_type:` param is `nil` `name:` must start with '.'", "or '#'", name: name when :singleton, :class method bare_name when :instance instance_method bare_name else raise NRSER::ArgumentError.new \ "`default_type:` param must be `nil`, `:instance`, `:singleton` or", "`:class`, found", default_type.inspect, name: name, default_type: default_type end when Meta::Names::Method::Singleton method Meta::Names::Method::Singleton.new( name_string ).bare_name when Meta::Names::Method::Instance instance_method Meta::Names::Method::Instance.new( name_string ).bare_name else raise NRSER::ArgumentError.new \ "`name:` does not look like a method name:", name.inspect end end
[ "def", "resolve_method", "name", ":", ",", "default_type", ":", "nil", "name_string", "=", "name", ".", "to_s", "# .gsub( /\\A\\@\\@/, '.' ).gsub( /\\A\\@/, '#' )", "case", "name_string", "when", "Meta", "::", "Names", "::", "Method", "::", "Bare", "bare_name", "=", "Meta", "::", "Names", "::", "Method", "::", "Bare", ".", "new", "name_string", "case", "default_type", "&.", "to_sym", "when", "nil", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"When `default_type:` param is `nil` `name:` must start with '.'\"", ",", "\"or '#'\"", ",", "name", ":", "name", "when", ":singleton", ",", ":class", "method", "bare_name", "when", ":instance", "instance_method", "bare_name", "else", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"`default_type:` param must be `nil`, `:instance`, `:singleton` or\"", ",", "\"`:class`, found\"", ",", "default_type", ".", "inspect", ",", "name", ":", "name", ",", "default_type", ":", "default_type", "end", "when", "Meta", "::", "Names", "::", "Method", "::", "Singleton", "method", "Meta", "::", "Names", "::", "Method", "::", "Singleton", ".", "new", "(", "name_string", ")", ".", "bare_name", "when", "Meta", "::", "Names", "::", "Method", "::", "Instance", "instance_method", "Meta", "::", "Names", "::", "Method", "::", "Instance", ".", "new", "(", "name_string", ")", ".", "bare_name", "else", "raise", "NRSER", "::", "ArgumentError", ".", "new", "\"`name:` does not look like a method name:\"", ",", "name", ".", "inspect", "end", "end" ]
Resolve a method name to a reference object. @param [#to_s] name The method name, preferably prefixed with `.` or `#` to indicate if it's a singleton or class method. @param [nil | :singleton | :class | :instance | #to_sym ] default_type Identifies singleton/instance methods when the name doesn't. `:singleton` and `:class` mean the same thing. Tries to convert values to symbols before matching them. If `nil`, `name:` **MUST** identify the method type by prefix. @return [ ::Method | ::UnboundMethod ] The method object. @raise [NRSER::ArgumentError]
[ "Resolve", "a", "method", "name", "to", "a", "reference", "object", "." ]
7db9a729ec65894dfac13fd50851beae8b809738
https://github.com/nrser/nrser.rb/blob/7db9a729ec65894dfac13fd50851beae8b809738/lib/nrser/decorate.rb#L49-L88
6,778
cbetta/snapshotify
lib/snapshotify/url.rb
Snapshotify.Url.parse_uri
def parse_uri self.uri = URI.parse(raw_url) uri.path = "/" if uri.path.empty? uri.fragment = nil # if this fails, mark the URL as invalid rescue self.valid = false end
ruby
def parse_uri self.uri = URI.parse(raw_url) uri.path = "/" if uri.path.empty? uri.fragment = nil # if this fails, mark the URL as invalid rescue self.valid = false end
[ "def", "parse_uri", "self", ".", "uri", "=", "URI", ".", "parse", "(", "raw_url", ")", "uri", ".", "path", "=", "\"/\"", "if", "uri", ".", "path", ".", "empty?", "uri", ".", "fragment", "=", "nil", "# if this fails, mark the URL as invalid", "rescue", "self", ".", "valid", "=", "false", "end" ]
Parse the raw URL as a URI object
[ "Parse", "the", "raw", "URL", "as", "a", "URI", "object" ]
7f5553f4281ffc5bf0e54da1141574bd15af45b6
https://github.com/cbetta/snapshotify/blob/7f5553f4281ffc5bf0e54da1141574bd15af45b6/lib/snapshotify/url.rb#L76-L83
6,779
bblack16/bblib-ruby
lib/bblib/core/mixins/family_tree.rb
BBLib.FamilyTree.descendants
def descendants(include_singletons = false) return _inherited_by.map { |c| [c, c.descendants] }.flatten.uniq if BBLib.in_opal? ObjectSpace.each_object(Class).select do |c| (include_singletons || !c.singleton_class?) && c < self end end
ruby
def descendants(include_singletons = false) return _inherited_by.map { |c| [c, c.descendants] }.flatten.uniq if BBLib.in_opal? ObjectSpace.each_object(Class).select do |c| (include_singletons || !c.singleton_class?) && c < self end end
[ "def", "descendants", "(", "include_singletons", "=", "false", ")", "return", "_inherited_by", ".", "map", "{", "|", "c", "|", "[", "c", ",", "c", ".", "descendants", "]", "}", ".", "flatten", ".", "uniq", "if", "BBLib", ".", "in_opal?", "ObjectSpace", ".", "each_object", "(", "Class", ")", ".", "select", "do", "|", "c", "|", "(", "include_singletons", "||", "!", "c", ".", "singleton_class?", ")", "&&", "c", "<", "self", "end", "end" ]
Return all classes that inherit from this class
[ "Return", "all", "classes", "that", "inherit", "from", "this", "class" ]
274eedeb583cc56243884fd041645488d5bd08a9
https://github.com/bblack16/bblib-ruby/blob/274eedeb583cc56243884fd041645488d5bd08a9/lib/bblib/core/mixins/family_tree.rb#L8-L13
6,780
bblack16/bblib-ruby
lib/bblib/core/mixins/family_tree.rb
BBLib.FamilyTree.direct_descendants
def direct_descendants(include_singletons = false) return _inherited_by if BBLib.in_opal? ObjectSpace.each_object(Class).select do |c| (include_singletons || !c.singleton_class?) && c.ancestors[1..-1].find { |k| k.is_a?(Class) } == self end end
ruby
def direct_descendants(include_singletons = false) return _inherited_by if BBLib.in_opal? ObjectSpace.each_object(Class).select do |c| (include_singletons || !c.singleton_class?) && c.ancestors[1..-1].find { |k| k.is_a?(Class) } == self end end
[ "def", "direct_descendants", "(", "include_singletons", "=", "false", ")", "return", "_inherited_by", "if", "BBLib", ".", "in_opal?", "ObjectSpace", ".", "each_object", "(", "Class", ")", ".", "select", "do", "|", "c", "|", "(", "include_singletons", "||", "!", "c", ".", "singleton_class?", ")", "&&", "c", ".", "ancestors", "[", "1", "..", "-", "1", "]", ".", "find", "{", "|", "k", "|", "k", ".", "is_a?", "(", "Class", ")", "}", "==", "self", "end", "end" ]
Return all classes that directly inherit from this class
[ "Return", "all", "classes", "that", "directly", "inherit", "from", "this", "class" ]
274eedeb583cc56243884fd041645488d5bd08a9
https://github.com/bblack16/bblib-ruby/blob/274eedeb583cc56243884fd041645488d5bd08a9/lib/bblib/core/mixins/family_tree.rb#L18-L23
6,781
bblack16/bblib-ruby
lib/bblib/core/mixins/family_tree.rb
BBLib.FamilyTree.instances
def instances(descendants = true) inst = ObjectSpace.each_object(self).to_a descendants ? inst : inst.select { |i| i.class == self } end
ruby
def instances(descendants = true) inst = ObjectSpace.each_object(self).to_a descendants ? inst : inst.select { |i| i.class == self } end
[ "def", "instances", "(", "descendants", "=", "true", ")", "inst", "=", "ObjectSpace", ".", "each_object", "(", "self", ")", ".", "to_a", "descendants", "?", "inst", ":", "inst", ".", "select", "{", "|", "i", "|", "i", ".", "class", "==", "self", "}", "end" ]
Return all live instances of the class Passing false will not include instances of sub classes
[ "Return", "all", "live", "instances", "of", "the", "class", "Passing", "false", "will", "not", "include", "instances", "of", "sub", "classes" ]
274eedeb583cc56243884fd041645488d5bd08a9
https://github.com/bblack16/bblib-ruby/blob/274eedeb583cc56243884fd041645488d5bd08a9/lib/bblib/core/mixins/family_tree.rb#L27-L30
6,782
DigitPaint/html_mockup
lib/html_mockup/release/scm/git.rb
HtmlMockup::Release::Scm.Git.find_git_dir
def find_git_dir(path) path = Pathname.new(path).realpath while path.parent != path && !(path + ".git").directory? path = path.parent end path = path + ".git" raise "Could not find suitable .git dir in #{path}" if !path.directory? path end
ruby
def find_git_dir(path) path = Pathname.new(path).realpath while path.parent != path && !(path + ".git").directory? path = path.parent end path = path + ".git" raise "Could not find suitable .git dir in #{path}" if !path.directory? path end
[ "def", "find_git_dir", "(", "path", ")", "path", "=", "Pathname", ".", "new", "(", "path", ")", ".", "realpath", "while", "path", ".", "parent", "!=", "path", "&&", "!", "(", "path", "+", "\".git\"", ")", ".", "directory?", "path", "=", "path", ".", "parent", "end", "path", "=", "path", "+", "\".git\"", "raise", "\"Could not find suitable .git dir in #{path}\"", "if", "!", "path", ".", "directory?", "path", "end" ]
Find the git dir
[ "Find", "the", "git", "dir" ]
976edadc01216b82a8cea177f53fb32559eaf41e
https://github.com/DigitPaint/html_mockup/blob/976edadc01216b82a8cea177f53fb32559eaf41e/lib/html_mockup/release/scm/git.rb#L86-L97
6,783
davidrichards/gearbox
lib/gearbox/rdf_collection.rb
Gearbox.RDFCollection.has_key?
def has_key?(key, opts={}) key = normalize_key(key) if opts.fetch(:normalize, true) @source.has_key?(key) end
ruby
def has_key?(key, opts={}) key = normalize_key(key) if opts.fetch(:normalize, true) @source.has_key?(key) end
[ "def", "has_key?", "(", "key", ",", "opts", "=", "{", "}", ")", "key", "=", "normalize_key", "(", "key", ")", "if", "opts", ".", "fetch", "(", ":normalize", ",", "true", ")", "@source", ".", "has_key?", "(", "key", ")", "end" ]
Lookup whether the key exists. @param [String, Symbol] key @param [Hash, nil] opts. :normalize => false will lookup the key as provided. @return [Boolean]
[ "Lookup", "whether", "the", "key", "exists", "." ]
322e1a44394b6323d849c5e65acad66cdf284aac
https://github.com/davidrichards/gearbox/blob/322e1a44394b6323d849c5e65acad66cdf284aac/lib/gearbox/rdf_collection.rb#L55-L58
6,784
jinx/core
lib/jinx/importer.rb
Jinx.Importer.const_missing
def const_missing(sym) # Load the class definitions in the source directory, if necessary. # If a load is performed as a result of referencing the given symbol, # then dereference the class constant again after the load, since the class # might have been loaded or referenced during the load. unless defined? @introspected then configure_importer load_definitions return const_get(sym) end # Append the symbol to the package to make the Java class name. logger.debug { "Detecting whether #{sym} is a #{self} Java class..." } klass = @packages.detect_value do |pkg| begin java_import "#{pkg}.#{sym}" rescue NameError nil end end if klass then logger.debug { "Added #{klass} to the #{self} module." } else # Not a Java class; print a log message and pass along the error. logger.debug { "#{sym} is not recognized as a #{self} Java class." } super end # Introspect the Java class meta-data, if necessary. unless introspected?(klass) then add_metadata(klass) # Print the class meta-data. logger.info(klass.pp_s) end klass end
ruby
def const_missing(sym) # Load the class definitions in the source directory, if necessary. # If a load is performed as a result of referencing the given symbol, # then dereference the class constant again after the load, since the class # might have been loaded or referenced during the load. unless defined? @introspected then configure_importer load_definitions return const_get(sym) end # Append the symbol to the package to make the Java class name. logger.debug { "Detecting whether #{sym} is a #{self} Java class..." } klass = @packages.detect_value do |pkg| begin java_import "#{pkg}.#{sym}" rescue NameError nil end end if klass then logger.debug { "Added #{klass} to the #{self} module." } else # Not a Java class; print a log message and pass along the error. logger.debug { "#{sym} is not recognized as a #{self} Java class." } super end # Introspect the Java class meta-data, if necessary. unless introspected?(klass) then add_metadata(klass) # Print the class meta-data. logger.info(klass.pp_s) end klass end
[ "def", "const_missing", "(", "sym", ")", "# Load the class definitions in the source directory, if necessary.", "# If a load is performed as a result of referencing the given symbol,", "# then dereference the class constant again after the load, since the class", "# might have been loaded or referenced during the load.", "unless", "defined?", "@introspected", "then", "configure_importer", "load_definitions", "return", "const_get", "(", "sym", ")", "end", "# Append the symbol to the package to make the Java class name.", "logger", ".", "debug", "{", "\"Detecting whether #{sym} is a #{self} Java class...\"", "}", "klass", "=", "@packages", ".", "detect_value", "do", "|", "pkg", "|", "begin", "java_import", "\"#{pkg}.#{sym}\"", "rescue", "NameError", "nil", "end", "end", "if", "klass", "then", "logger", ".", "debug", "{", "\"Added #{klass} to the #{self} module.\"", "}", "else", "# Not a Java class; print a log message and pass along the error.", "logger", ".", "debug", "{", "\"#{sym} is not recognized as a #{self} Java class.\"", "}", "super", "end", "# Introspect the Java class meta-data, if necessary.", "unless", "introspected?", "(", "klass", ")", "then", "add_metadata", "(", "klass", ")", "# Print the class meta-data.", "logger", ".", "info", "(", "klass", ".", "pp_s", ")", "end", "klass", "end" ]
Imports a Java class constant on demand. If the class does not already include this module's mixin, then the mixin is included in the class. @param [Symbol, String] sym the missing constant @return [Class] the imported class @raise [NameError] if the symbol is not an importable Java class
[ "Imports", "a", "Java", "class", "constant", "on", "demand", ".", "If", "the", "class", "does", "not", "already", "include", "this", "module", "s", "mixin", "then", "the", "mixin", "is", "included", "in", "the", "class", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/importer.rb#L48-L84
6,785
jinx/core
lib/jinx/importer.rb
Jinx.Importer.configure_importer
def configure_importer # The default package conforms to the JRuby convention for mapping a package name # to a module name. @packages ||= [name.split('::').map { |n| n.downcase }.join('.')] @packages.each do |pkg| begin eval "java_package Java::#{pkg}" rescue Exception => e raise ArgumentError.new("#{self} Java package #{pkg} not found - #{$!}") end end # The introspected classes. @introspected = Set.new # The name => file hash for file definitions that are not in the packages. @unresolved_defs = {} end
ruby
def configure_importer # The default package conforms to the JRuby convention for mapping a package name # to a module name. @packages ||= [name.split('::').map { |n| n.downcase }.join('.')] @packages.each do |pkg| begin eval "java_package Java::#{pkg}" rescue Exception => e raise ArgumentError.new("#{self} Java package #{pkg} not found - #{$!}") end end # The introspected classes. @introspected = Set.new # The name => file hash for file definitions that are not in the packages. @unresolved_defs = {} end
[ "def", "configure_importer", "# The default package conforms to the JRuby convention for mapping a package name", "# to a module name.", "@packages", "||=", "[", "name", ".", "split", "(", "'::'", ")", ".", "map", "{", "|", "n", "|", "n", ".", "downcase", "}", ".", "join", "(", "'.'", ")", "]", "@packages", ".", "each", "do", "|", "pkg", "|", "begin", "eval", "\"java_package Java::#{pkg}\"", "rescue", "Exception", "=>", "e", "raise", "ArgumentError", ".", "new", "(", "\"#{self} Java package #{pkg} not found - #{$!}\"", ")", "end", "end", "# The introspected classes.", "@introspected", "=", "Set", ".", "new", "# The name => file hash for file definitions that are not in the packages.", "@unresolved_defs", "=", "{", "}", "end" ]
Initializes this importer on demand. This method is called the first time a class is referenced.
[ "Initializes", "this", "importer", "on", "demand", ".", "This", "method", "is", "called", "the", "first", "time", "a", "class", "is", "referenced", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/importer.rb#L109-L124
6,786
jinx/core
lib/jinx/importer.rb
Jinx.Importer.load_dir
def load_dir(dir) logger.debug { "Loading the class definitions in #{dir}..." } # Import the classes. srcs = sources(dir) # Introspect and load the classes in reverse class order, i.e. superclass before subclass. klasses = srcs.keys.transitive_closure { |k| [k.superclass] }.select { |k| srcs[k] }.reverse # Introspect the classes as necessary. klasses.each { |klass| add_metadata(klass) unless introspected?(klass) } # Load the classes. klasses.each do |klass| file = srcs[klass] load_definition(klass, file) end logger.debug { "Loaded the class definitions in #{dir}." } end
ruby
def load_dir(dir) logger.debug { "Loading the class definitions in #{dir}..." } # Import the classes. srcs = sources(dir) # Introspect and load the classes in reverse class order, i.e. superclass before subclass. klasses = srcs.keys.transitive_closure { |k| [k.superclass] }.select { |k| srcs[k] }.reverse # Introspect the classes as necessary. klasses.each { |klass| add_metadata(klass) unless introspected?(klass) } # Load the classes. klasses.each do |klass| file = srcs[klass] load_definition(klass, file) end logger.debug { "Loaded the class definitions in #{dir}." } end
[ "def", "load_dir", "(", "dir", ")", "logger", ".", "debug", "{", "\"Loading the class definitions in #{dir}...\"", "}", "# Import the classes.", "srcs", "=", "sources", "(", "dir", ")", "# Introspect and load the classes in reverse class order, i.e. superclass before subclass.", "klasses", "=", "srcs", ".", "keys", ".", "transitive_closure", "{", "|", "k", "|", "[", "k", ".", "superclass", "]", "}", ".", "select", "{", "|", "k", "|", "srcs", "[", "k", "]", "}", ".", "reverse", "# Introspect the classes as necessary.", "klasses", ".", "each", "{", "|", "klass", "|", "add_metadata", "(", "klass", ")", "unless", "introspected?", "(", "klass", ")", "}", "# Load the classes.", "klasses", ".", "each", "do", "|", "klass", "|", "file", "=", "srcs", "[", "klass", "]", "load_definition", "(", "klass", ",", "file", ")", "end", "logger", ".", "debug", "{", "\"Loaded the class definitions in #{dir}.\"", "}", "end" ]
Loads the Ruby source files in the given directory. @param [String] dir the source directory
[ "Loads", "the", "Ruby", "source", "files", "in", "the", "given", "directory", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/importer.rb#L160-L174
6,787
jinx/core
lib/jinx/importer.rb
Jinx.Importer.add_metadata
def add_metadata(klass) logger.debug("Adding #{self}::#{klass.qp} metadata...") # Mark the class as introspected. Do this first to preclude a recursive loop back # into this method when the references are introspected below. @introspected << klass # Add the superclass meta-data if necessary. add_superclass_metadata(klass) # Include this resource module into the class, unless this has already occurred. unless klass < self then m = self klass.class_eval { include m } end # Import the class into this resource module, unless this has already occurred. name = klass.name.demodulize unless const_defined?(name) then java_import(klass.java_class.name) end # Add introspection capability to the class. md_mod = @metadata_module || Metadata logger.debug { "Extending #{self}::#{klass.qp} with #{md_mod.name}..." } klass.extend(md_mod) # Set the class domain module. klass.domain_module = self # Introspect the Java properties. klass.introspect # Add the {attribute => value} initializer. klass.add_attribute_value_initializer if Class === klass # Add referenced domain class metadata as necessary. klass.each_property do |prop| ref = prop.type if ref.nil? then raise MetadataError.new("#{self} #{prop} domain type is unknown.") end if introspectible?(ref) then logger.debug { "Introspecting the #{klass.qp} #{prop} reference type #{ref.qp}..." } add_metadata(ref) end end # If the class has a definition file but does not resolve to a standard package, then # load it now based on the demodulized class name match. file = @unresolved_defs[name] load_definition(klass, file) if file logger.debug("#{self}::#{klass.qp} metadata added.") end
ruby
def add_metadata(klass) logger.debug("Adding #{self}::#{klass.qp} metadata...") # Mark the class as introspected. Do this first to preclude a recursive loop back # into this method when the references are introspected below. @introspected << klass # Add the superclass meta-data if necessary. add_superclass_metadata(klass) # Include this resource module into the class, unless this has already occurred. unless klass < self then m = self klass.class_eval { include m } end # Import the class into this resource module, unless this has already occurred. name = klass.name.demodulize unless const_defined?(name) then java_import(klass.java_class.name) end # Add introspection capability to the class. md_mod = @metadata_module || Metadata logger.debug { "Extending #{self}::#{klass.qp} with #{md_mod.name}..." } klass.extend(md_mod) # Set the class domain module. klass.domain_module = self # Introspect the Java properties. klass.introspect # Add the {attribute => value} initializer. klass.add_attribute_value_initializer if Class === klass # Add referenced domain class metadata as necessary. klass.each_property do |prop| ref = prop.type if ref.nil? then raise MetadataError.new("#{self} #{prop} domain type is unknown.") end if introspectible?(ref) then logger.debug { "Introspecting the #{klass.qp} #{prop} reference type #{ref.qp}..." } add_metadata(ref) end end # If the class has a definition file but does not resolve to a standard package, then # load it now based on the demodulized class name match. file = @unresolved_defs[name] load_definition(klass, file) if file logger.debug("#{self}::#{klass.qp} metadata added.") end
[ "def", "add_metadata", "(", "klass", ")", "logger", ".", "debug", "(", "\"Adding #{self}::#{klass.qp} metadata...\"", ")", "# Mark the class as introspected. Do this first to preclude a recursive loop back", "# into this method when the references are introspected below.", "@introspected", "<<", "klass", "# Add the superclass meta-data if necessary.", "add_superclass_metadata", "(", "klass", ")", "# Include this resource module into the class, unless this has already occurred.", "unless", "klass", "<", "self", "then", "m", "=", "self", "klass", ".", "class_eval", "{", "include", "m", "}", "end", "# Import the class into this resource module, unless this has already occurred.", "name", "=", "klass", ".", "name", ".", "demodulize", "unless", "const_defined?", "(", "name", ")", "then", "java_import", "(", "klass", ".", "java_class", ".", "name", ")", "end", "# Add introspection capability to the class.", "md_mod", "=", "@metadata_module", "||", "Metadata", "logger", ".", "debug", "{", "\"Extending #{self}::#{klass.qp} with #{md_mod.name}...\"", "}", "klass", ".", "extend", "(", "md_mod", ")", "# Set the class domain module.", "klass", ".", "domain_module", "=", "self", "# Introspect the Java properties.", "klass", ".", "introspect", "# Add the {attribute => value} initializer.", "klass", ".", "add_attribute_value_initializer", "if", "Class", "===", "klass", "# Add referenced domain class metadata as necessary.", "klass", ".", "each_property", "do", "|", "prop", "|", "ref", "=", "prop", ".", "type", "if", "ref", ".", "nil?", "then", "raise", "MetadataError", ".", "new", "(", "\"#{self} #{prop} domain type is unknown.\"", ")", "end", "if", "introspectible?", "(", "ref", ")", "then", "logger", ".", "debug", "{", "\"Introspecting the #{klass.qp} #{prop} reference type #{ref.qp}...\"", "}", "add_metadata", "(", "ref", ")", "end", "end", "# If the class has a definition file but does not resolve to a standard package, then", "# load it now based on the demodulized class name match.", "file", "=", "@unresolved_defs", "[", "name", "]", "load_definition", "(", "klass", ",", "file", ")", "if", "file", "logger", ".", "debug", "(", "\"#{self}::#{klass.qp} metadata added.\"", ")", "end" ]
Introspects the given class meta-data. @param [Class] klass the Java class or interface to introspect
[ "Introspects", "the", "given", "class", "meta", "-", "data", "." ]
964a274cc9d7ab74613910e8375e12ed210a434d
https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/importer.rb#L230-L272
6,788
Thermatix/ruta
lib/ruta/route.rb
Ruta.Route.get
def get params=nil path = if params paramaterize params.dup else @url end { path: path, title: self.flags.fetch(:title){nil}, params: params_hash(params), route: self } end
ruby
def get params=nil path = if params paramaterize params.dup else @url end { path: path, title: self.flags.fetch(:title){nil}, params: params_hash(params), route: self } end
[ "def", "get", "params", "=", "nil", "path", "=", "if", "params", "paramaterize", "params", ".", "dup", "else", "@url", "end", "{", "path", ":", "path", ",", "title", ":", "self", ".", "flags", ".", "fetch", "(", ":title", ")", "{", "nil", "}", ",", "params", ":", "params_hash", "(", "params", ")", ",", "route", ":", "self", "}", "end" ]
get route hash and paramaterize url if needed @param [Array<String,Number,Boolean>] params to replace named params in the returned url @return [Symbol => Number,String,Route] hash specificly formatted: { url: of the route with named params replaced, title: the name of page if the url has one, params: a list of all the params used in the route, route: the #Route object }
[ "get", "route", "hash", "and", "paramaterize", "url", "if", "needed" ]
b4a6e3bc7c0c4b66c804023d638b173e3f61e157
https://github.com/Thermatix/ruta/blob/b4a6e3bc7c0c4b66c804023d638b173e3f61e157/lib/ruta/route.rb#L78-L90
6,789
Thermatix/ruta
lib/ruta/route.rb
Ruta.Route.match
def match(path) if match = @regexp.match(path) params = {} @named.each_with_index { |name, i| params[name] = match[i + 1] } if @type == :handlers { path: path, title: self.flags.fetch(:title){nil}, params: params, route: self } else false end end
ruby
def match(path) if match = @regexp.match(path) params = {} @named.each_with_index { |name, i| params[name] = match[i + 1] } if @type == :handlers { path: path, title: self.flags.fetch(:title){nil}, params: params, route: self } else false end end
[ "def", "match", "(", "path", ")", "if", "match", "=", "@regexp", ".", "match", "(", "path", ")", "params", "=", "{", "}", "@named", ".", "each_with_index", "{", "|", "name", ",", "i", "|", "params", "[", "name", "]", "=", "match", "[", "i", "+", "1", "]", "}", "if", "@type", "==", ":handlers", "{", "path", ":", "path", ",", "title", ":", "self", ".", "flags", ".", "fetch", "(", ":title", ")", "{", "nil", "}", ",", "params", ":", "params", ",", "route", ":", "self", "}", "else", "false", "end", "end" ]
match this route against a given path @param [String,Regex] path to match against @return [Hash,false] (see #get) or false if there is no match
[ "match", "this", "route", "against", "a", "given", "path" ]
b4a6e3bc7c0c4b66c804023d638b173e3f61e157
https://github.com/Thermatix/ruta/blob/b4a6e3bc7c0c4b66c804023d638b173e3f61e157/lib/ruta/route.rb#L96-L109
6,790
Thermatix/ruta
lib/ruta/route.rb
Ruta.Route.execute_handler
def execute_handler params={},path=nil case @type when :handlers @handlers.each do |handler_ident| handler = @context_ref.handlers.fetch(handler_ident) {raise "handler #{handler_ident} doesn't exist in context #{@context_ref.ref}"} component = handler.(params,path||@url,&:call) Context.current_context = @context_ref.ref if component.class == Proc component.call else Context.renderer.call(component,handler_ident) end Context.current_context = :no_context end when :context Context.wipe Context.render handlers History.push(@context_ref.ref,"",[],@context_ref.ref) end end
ruby
def execute_handler params={},path=nil case @type when :handlers @handlers.each do |handler_ident| handler = @context_ref.handlers.fetch(handler_ident) {raise "handler #{handler_ident} doesn't exist in context #{@context_ref.ref}"} component = handler.(params,path||@url,&:call) Context.current_context = @context_ref.ref if component.class == Proc component.call else Context.renderer.call(component,handler_ident) end Context.current_context = :no_context end when :context Context.wipe Context.render handlers History.push(@context_ref.ref,"",[],@context_ref.ref) end end
[ "def", "execute_handler", "params", "=", "{", "}", ",", "path", "=", "nil", "case", "@type", "when", ":handlers", "@handlers", ".", "each", "do", "|", "handler_ident", "|", "handler", "=", "@context_ref", ".", "handlers", ".", "fetch", "(", "handler_ident", ")", "{", "raise", "\"handler #{handler_ident} doesn't exist in context #{@context_ref.ref}\"", "}", "component", "=", "handler", ".", "(", "params", ",", "path", "||", "@url", ",", ":call", ")", "Context", ".", "current_context", "=", "@context_ref", ".", "ref", "if", "component", ".", "class", "==", "Proc", "component", ".", "call", "else", "Context", ".", "renderer", ".", "call", "(", "component", ",", "handler_ident", ")", "end", "Context", ".", "current_context", "=", ":no_context", "end", "when", ":context", "Context", ".", "wipe", "Context", ".", "render", "handlers", "History", ".", "push", "(", "@context_ref", ".", "ref", ",", "\"\"", ",", "[", "]", ",", "@context_ref", ".", "ref", ")", "end", "end" ]
execute's route's associated handlers @param [Symbol => String] params from the route with there respective keys @param [String] path containing params placed into there respective named positions
[ "execute", "s", "route", "s", "associated", "handlers" ]
b4a6e3bc7c0c4b66c804023d638b173e3f61e157
https://github.com/Thermatix/ruta/blob/b4a6e3bc7c0c4b66c804023d638b173e3f61e157/lib/ruta/route.rb#L115-L134
6,791
sealink/dependent_restrict
lib/dependent_restrict.rb
DependentRestrict.ClassMethods.has_one
def has_one(*args, &extension) options = args.extract_options! || {} if VALID_DEPENDENTS.include?(options[:dependent].try(:to_sym)) reflection = if active_record_4? association_id, scope = *args restrict_create_reflection(:has_one, association_id, scope || {}, options, self) else association_id = args[0] create_reflection(:has_one, association_id, options, self) end add_dependency_callback!(reflection, options) end args << options super(*args, &extension) end
ruby
def has_one(*args, &extension) options = args.extract_options! || {} if VALID_DEPENDENTS.include?(options[:dependent].try(:to_sym)) reflection = if active_record_4? association_id, scope = *args restrict_create_reflection(:has_one, association_id, scope || {}, options, self) else association_id = args[0] create_reflection(:has_one, association_id, options, self) end add_dependency_callback!(reflection, options) end args << options super(*args, &extension) end
[ "def", "has_one", "(", "*", "args", ",", "&", "extension", ")", "options", "=", "args", ".", "extract_options!", "||", "{", "}", "if", "VALID_DEPENDENTS", ".", "include?", "(", "options", "[", ":dependent", "]", ".", "try", "(", ":to_sym", ")", ")", "reflection", "=", "if", "active_record_4?", "association_id", ",", "scope", "=", "args", "restrict_create_reflection", "(", ":has_one", ",", "association_id", ",", "scope", "||", "{", "}", ",", "options", ",", "self", ")", "else", "association_id", "=", "args", "[", "0", "]", "create_reflection", "(", ":has_one", ",", "association_id", ",", "options", ",", "self", ")", "end", "add_dependency_callback!", "(", "reflection", ",", "options", ")", "end", "args", "<<", "options", "super", "(", "args", ",", "extension", ")", "end" ]
We should be aliasing configure_dependency_for_has_many but that method is private so we can't. We alias has_many instead trying to be as fair as we can to the original behaviour.
[ "We", "should", "be", "aliasing", "configure_dependency_for_has_many", "but", "that", "method", "is", "private", "so", "we", "can", "t", ".", "We", "alias", "has_many", "instead", "trying", "to", "be", "as", "fair", "as", "we", "can", "to", "the", "original", "behaviour", "." ]
443a0c30194eaa262ff07cb05cfd499d20a76fb9
https://github.com/sealink/dependent_restrict/blob/443a0c30194eaa262ff07cb05cfd499d20a76fb9/lib/dependent_restrict.rb#L19-L33
6,792
robertwahler/mutagem
lib/mutagem/task.rb
Mutagem.Task.run
def run pipe = IO.popen(@cmd + " 2>&1") @pid = pipe.pid begin @output = pipe.readlines pipe.close @exitstatus = $?.exitstatus rescue => e @exception = e end end
ruby
def run pipe = IO.popen(@cmd + " 2>&1") @pid = pipe.pid begin @output = pipe.readlines pipe.close @exitstatus = $?.exitstatus rescue => e @exception = e end end
[ "def", "run", "pipe", "=", "IO", ".", "popen", "(", "@cmd", "+", "\" 2>&1\"", ")", "@pid", "=", "pipe", ".", "pid", "begin", "@output", "=", "pipe", ".", "readlines", "pipe", ".", "close", "@exitstatus", "=", "$?", ".", "exitstatus", "rescue", "=>", "e", "@exception", "=", "e", "end", "end" ]
run the cmd
[ "run", "the", "cmd" ]
75ac2f7fd307f575d81114b32e1a3b09c526e01d
https://github.com/robertwahler/mutagem/blob/75ac2f7fd307f575d81114b32e1a3b09c526e01d/lib/mutagem/task.rb#L49-L59
6,793
zeke/ratpack
lib/sinatra/ratpack.rb
Sinatra.Ratpack.link_to
def link_to(content,href=nil,options={}) href ||= content options.update :href => url_for(href) content_tag :a, content, options end
ruby
def link_to(content,href=nil,options={}) href ||= content options.update :href => url_for(href) content_tag :a, content, options end
[ "def", "link_to", "(", "content", ",", "href", "=", "nil", ",", "options", "=", "{", "}", ")", "href", "||=", "content", "options", ".", "update", ":href", "=>", "url_for", "(", "href", ")", "content_tag", ":a", ",", "content", ",", "options", "end" ]
Works like link_to, but href is optional. If no href supplied, content is used as href link_to "grub", "/food", :class => "eats" # <a href="/food" class="eats">grub</a> link_to "http://foo.com" # <a href="http://foo.com">http://foo.com</a> link_to "home" # <a href="/home">home</a>
[ "Works", "like", "link_to", "but", "href", "is", "optional", ".", "If", "no", "href", "supplied", "content", "is", "used", "as", "href" ]
51a8b329fe0af4c24441cc5ed6d836111ba9c0a3
https://github.com/zeke/ratpack/blob/51a8b329fe0af4c24441cc5ed6d836111ba9c0a3/lib/sinatra/ratpack.rb#L64-L68
6,794
kukushkin/aerogel-core
lib/aerogel/core/reloader.rb
Aerogel.Reloader.check!
def check! return unless @files @file_list = file_list( @files ) new_signature = signature( @file_list ) if @signature != new_signature # reload file list puts "* Aerogel::Reloader reloading: #{@file_list}, group: #{@group}" if @group # invoke :before group actions Aerogel::Reloader.reloaders.select{|r| r.group == @group && r.opts[:before] }.each do |r| r.action.call @file_list end end @action.call @file_list @signature = new_signature if @group # invoke :after group actions Aerogel::Reloader.reloaders.select{|r| r.group == @group && r.opts[:after] }.each do |r| r.action.call @file_list end end end end
ruby
def check! return unless @files @file_list = file_list( @files ) new_signature = signature( @file_list ) if @signature != new_signature # reload file list puts "* Aerogel::Reloader reloading: #{@file_list}, group: #{@group}" if @group # invoke :before group actions Aerogel::Reloader.reloaders.select{|r| r.group == @group && r.opts[:before] }.each do |r| r.action.call @file_list end end @action.call @file_list @signature = new_signature if @group # invoke :after group actions Aerogel::Reloader.reloaders.select{|r| r.group == @group && r.opts[:after] }.each do |r| r.action.call @file_list end end end end
[ "def", "check!", "return", "unless", "@files", "@file_list", "=", "file_list", "(", "@files", ")", "new_signature", "=", "signature", "(", "@file_list", ")", "if", "@signature", "!=", "new_signature", "# reload file list", "puts", "\"* Aerogel::Reloader reloading: #{@file_list}, group: #{@group}\"", "if", "@group", "# invoke :before group actions", "Aerogel", "::", "Reloader", ".", "reloaders", ".", "select", "{", "|", "r", "|", "r", ".", "group", "==", "@group", "&&", "r", ".", "opts", "[", ":before", "]", "}", ".", "each", "do", "|", "r", "|", "r", ".", "action", ".", "call", "@file_list", "end", "end", "@action", ".", "call", "@file_list", "@signature", "=", "new_signature", "if", "@group", "# invoke :after group actions", "Aerogel", "::", "Reloader", ".", "reloaders", ".", "select", "{", "|", "r", "|", "r", ".", "group", "==", "@group", "&&", "r", ".", "opts", "[", ":after", "]", "}", ".", "each", "do", "|", "r", "|", "r", ".", "action", ".", "call", "@file_list", "end", "end", "end", "end" ]
Checks if files are changed and reloads if so.
[ "Checks", "if", "files", "are", "changed", "and", "reloads", "if", "so", "." ]
e156af6b237c410c1ee75e5cdf1b10075e7fbb8b
https://github.com/kukushkin/aerogel-core/blob/e156af6b237c410c1ee75e5cdf1b10075e7fbb8b/lib/aerogel/core/reloader.rb#L68-L90
6,795
kukushkin/aerogel-core
lib/aerogel/core/reloader.rb
Aerogel.Reloader.file_list
def file_list( files ) case files when String [files] when Array files when Proc files.call # result should respond to #each else [] end end
ruby
def file_list( files ) case files when String [files] when Array files when Proc files.call # result should respond to #each else [] end end
[ "def", "file_list", "(", "files", ")", "case", "files", "when", "String", "[", "files", "]", "when", "Array", "files", "when", "Proc", "files", ".", "call", "# result should respond to #each", "else", "[", "]", "end", "end" ]
Re-calculates file list
[ "Re", "-", "calculates", "file", "list" ]
e156af6b237c410c1ee75e5cdf1b10075e7fbb8b
https://github.com/kukushkin/aerogel-core/blob/e156af6b237c410c1ee75e5cdf1b10075e7fbb8b/lib/aerogel/core/reloader.rb#L94-L105
6,796
inside-track/remi
lib/remi/dsl.rb
Remi.Dsl.dsl_eval
def dsl_eval(dsl, fallback_dsl, *args, &block) exec_in_proxy_context(dsl, fallback_dsl, Docile::FallbackContextProxy, *args, &block) dsl end
ruby
def dsl_eval(dsl, fallback_dsl, *args, &block) exec_in_proxy_context(dsl, fallback_dsl, Docile::FallbackContextProxy, *args, &block) dsl end
[ "def", "dsl_eval", "(", "dsl", ",", "fallback_dsl", ",", "*", "args", ",", "&", "block", ")", "exec_in_proxy_context", "(", "dsl", ",", "fallback_dsl", ",", "Docile", "::", "FallbackContextProxy", ",", "args", ",", "block", ")", "dsl", "end" ]
Execute a block in the context of an object whose methods represent the commands in a DSL. @note Use with an *imperative* DSL (commands modify the context object) Use this method to execute an *imperative* DSL, which means that: 1. Each command mutates the state of the DSL context object 2. The return value of each command is ignored 3. The final return value is the original context object @param dsl [Object] context object whose methods make up the DSL @param fallback_dsl [Object] context object that the DSL should fallback to @param args [Array] arguments to be passed to the block @param block [Proc] the block of DSL commands to be executed against the `dsl` context object @return [Object] the `dsl` context object after executing the block
[ "Execute", "a", "block", "in", "the", "context", "of", "an", "object", "whose", "methods", "represent", "the", "commands", "in", "a", "DSL", "." ]
f7e5f28f08f8c0403e04cd82d6fc14b6b2c362a7
https://github.com/inside-track/remi/blob/f7e5f28f08f8c0403e04cd82d6fc14b6b2c362a7/lib/remi/dsl.rb#L63-L66
6,797
LAS-IT/equitrac_utilities
lib/equitrac_utilities/user_actions.rb
EquitracUtilities.UserActions.user_modify
def user_modify(attribs) defaults = {user_name: "!", min_bal: "!", email: "!", dept_name: "!", pimary_pin: "!", secondary_pin: "!", quota: "!", alternate_pin: "!", home_server: "!", locked: "!", location: "!", default_bc: "!", additional_info: "!", home_folder: "!"} attribs = defaults.merge(attribs) attribs = check_atrribs(attribs) "modify ur #{attribs[:user_id]} \"#{attribs[:user_name]}\"" + " #{attribs[:min_bal]} #{attribs[:email]} #{attribs[:dept_name]}" + " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" + " #{attribs[:quota]} #{attribs[:alternate_pin]}" + " #{attribs[:home_server]} #{attribs[:locked]}" + " #{attribs[:location]} #{attribs[:default_bc]}" + " #{attribs[:additional_info]} #{attribs[:home_folder]}" end
ruby
def user_modify(attribs) defaults = {user_name: "!", min_bal: "!", email: "!", dept_name: "!", pimary_pin: "!", secondary_pin: "!", quota: "!", alternate_pin: "!", home_server: "!", locked: "!", location: "!", default_bc: "!", additional_info: "!", home_folder: "!"} attribs = defaults.merge(attribs) attribs = check_atrribs(attribs) "modify ur #{attribs[:user_id]} \"#{attribs[:user_name]}\"" + " #{attribs[:min_bal]} #{attribs[:email]} #{attribs[:dept_name]}" + " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" + " #{attribs[:quota]} #{attribs[:alternate_pin]}" + " #{attribs[:home_server]} #{attribs[:locked]}" + " #{attribs[:location]} #{attribs[:default_bc]}" + " #{attribs[:additional_info]} #{attribs[:home_folder]}" end
[ "def", "user_modify", "(", "attribs", ")", "defaults", "=", "{", "user_name", ":", "\"!\"", ",", "min_bal", ":", "\"!\"", ",", "email", ":", "\"!\"", ",", "dept_name", ":", "\"!\"", ",", "pimary_pin", ":", "\"!\"", ",", "secondary_pin", ":", "\"!\"", ",", "quota", ":", "\"!\"", ",", "alternate_pin", ":", "\"!\"", ",", "home_server", ":", "\"!\"", ",", "locked", ":", "\"!\"", ",", "location", ":", "\"!\"", ",", "default_bc", ":", "\"!\"", ",", "additional_info", ":", "\"!\"", ",", "home_folder", ":", "\"!\"", "}", "attribs", "=", "defaults", ".", "merge", "(", "attribs", ")", "attribs", "=", "check_atrribs", "(", "attribs", ")", "\"modify ur #{attribs[:user_id]} \\\"#{attribs[:user_name]}\\\"\"", "+", "\" #{attribs[:min_bal]} #{attribs[:email]} #{attribs[:dept_name]}\"", "+", "\" #{attribs[:primary_pin]} #{attribs[:secondary_pin]}\"", "+", "\" #{attribs[:quota]} #{attribs[:alternate_pin]}\"", "+", "\" #{attribs[:home_server]} #{attribs[:locked]}\"", "+", "\" #{attribs[:location]} #{attribs[:default_bc]}\"", "+", "\" #{attribs[:additional_info]} #{attribs[:home_folder]}\"", "end" ]
Process to lock a user in the Equitrac System @param attr [Hash] this attribute MUST include: { user_id: "userid" } @return [String] Formatted for EQCmd.exe command execution
[ "Process", "to", "lock", "a", "user", "in", "the", "Equitrac", "System" ]
98eb25da612ccd0c1010c18d5a726e130184df66
https://github.com/LAS-IT/equitrac_utilities/blob/98eb25da612ccd0c1010c18d5a726e130184df66/lib/equitrac_utilities/user_actions.rb#L130-L145
6,798
LAS-IT/equitrac_utilities
lib/equitrac_utilities/user_actions.rb
EquitracUtilities.UserActions.user_adjust_set
def user_adjust_set(attribs) defaults = {new_bal: 0.0, description: nil} attribs = defaults.merge(attribs) attribs = check_atrribs(attribs) "adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}" end
ruby
def user_adjust_set(attribs) defaults = {new_bal: 0.0, description: nil} attribs = defaults.merge(attribs) attribs = check_atrribs(attribs) "adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}" end
[ "def", "user_adjust_set", "(", "attribs", ")", "defaults", "=", "{", "new_bal", ":", "0.0", ",", "description", ":", "nil", "}", "attribs", "=", "defaults", ".", "merge", "(", "attribs", ")", "attribs", "=", "check_atrribs", "(", "attribs", ")", "\"adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}\"", "end" ]
Process to set a new balance for a user in the Equitrac System @param attr [Hash] this attribute MUST include: { user_id: "userid" } @note attr new_bal defaults to 0, if not included in the attributes @return [String] Formatted for EQCmd.exe command execution
[ "Process", "to", "set", "a", "new", "balance", "for", "a", "user", "in", "the", "Equitrac", "System" ]
98eb25da612ccd0c1010c18d5a726e130184df66
https://github.com/LAS-IT/equitrac_utilities/blob/98eb25da612ccd0c1010c18d5a726e130184df66/lib/equitrac_utilities/user_actions.rb#L152-L157
6,799
fwolfst/kalindar
lib/kalindar/event.rb
Kalindar.Event.start_time_f
def start_time_f day #puts "start #{start_time} : #{start_time.class} #{start_time.to_date} #{day}" if dtstart.class == Date # whole day "" elsif start_time.to_date == day.to_date start_time.strftime('%H:%M') else "..." end end
ruby
def start_time_f day #puts "start #{start_time} : #{start_time.class} #{start_time.to_date} #{day}" if dtstart.class == Date # whole day "" elsif start_time.to_date == day.to_date start_time.strftime('%H:%M') else "..." end end
[ "def", "start_time_f", "day", "#puts \"start #{start_time} : #{start_time.class} #{start_time.to_date} #{day}\"", "if", "dtstart", ".", "class", "==", "Date", "# whole day", "\"\"", "elsif", "start_time", ".", "to_date", "==", "day", ".", "to_date", "start_time", ".", "strftime", "(", "'%H:%M'", ")", "else", "\"...\"", "end", "end" ]
Time it starts at day, or '...'
[ "Time", "it", "starts", "at", "day", "or", "..." ]
8c81f0bc85ac8f7d0fc43b8e25eff6c08329b2c9
https://github.com/fwolfst/kalindar/blob/8c81f0bc85ac8f7d0fc43b8e25eff6c08329b2c9/lib/kalindar/event.rb#L20-L30