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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8,500 | pwnall/file_blobs_rails | lib/file_blobs_rails/action_controller_data_streaming_extensions.rb | FileBlobs.ActionControllerDataStreamingExtensions.send_file_blob | def send_file_blob(proxy, options = {})
if request.get_header(HTTP_IF_NONE_MATCH) == proxy.blob_id
head :not_modified
else
response.headers[ETAG] = proxy.blob_id
send_options = { type: proxy.mime_type, filename: proxy.original_name }
send_options.merge! options
send_data proxy.data... | ruby | def send_file_blob(proxy, options = {})
if request.get_header(HTTP_IF_NONE_MATCH) == proxy.blob_id
head :not_modified
else
response.headers[ETAG] = proxy.blob_id
send_options = { type: proxy.mime_type, filename: proxy.original_name }
send_options.merge! options
send_data proxy.data... | [
"def",
"send_file_blob",
"(",
"proxy",
",",
"options",
"=",
"{",
"}",
")",
"if",
"request",
".",
"get_header",
"(",
"HTTP_IF_NONE_MATCH",
")",
"==",
"proxy",
".",
"blob_id",
"head",
":not_modified",
"else",
"response",
".",
"headers",
"[",
"ETAG",
"]",
"="... | Sends a file blob to the browser.
This method uses HTTP's strong etag feature to facilitate serving the files
from a cache whenever possible.
@param [FileBlobs::FileBlobProxy] proxy a proxy for a collection of
attributes generated by has_file_blob
@param [Hash<Symbol, Object>] options tweaks the options pass... | [
"Sends",
"a",
"file",
"blob",
"to",
"the",
"browser",
"."
] | 688d43ec8547856f3572b0e6716e6faeff56345b | https://github.com/pwnall/file_blobs_rails/blob/688d43ec8547856f3572b0e6716e6faeff56345b/lib/file_blobs_rails/action_controller_data_streaming_extensions.rb#L21-L30 |
8,501 | richhollis/diversion | lib/diversion/configurable.rb | Diversion.Configurable.validate_configuration! | def validate_configuration!
unless @host.is_a?(String) && @host.length > 0
raise(Error::ConfigurationError, "Invalid host specified: Host must contain the host to redirect to.")
end
if @host.end_with?('/')
raise(Error::ConfigurationError, "Invalid host specified: #{@host} should not en... | ruby | def validate_configuration!
unless @host.is_a?(String) && @host.length > 0
raise(Error::ConfigurationError, "Invalid host specified: Host must contain the host to redirect to.")
end
if @host.end_with?('/')
raise(Error::ConfigurationError, "Invalid host specified: #{@host} should not en... | [
"def",
"validate_configuration!",
"unless",
"@host",
".",
"is_a?",
"(",
"String",
")",
"&&",
"@host",
".",
"length",
">",
"0",
"raise",
"(",
"Error",
"::",
"ConfigurationError",
",",
"\"Invalid host specified: Host must contain the host to redirect to.\"",
")",
"end",
... | Ensures that all configuration parameters are of an expected type.
@raise [Diversion::Error::ConfigurationError] Error is raised when
supplied configuration is not of expected type | [
"Ensures",
"that",
"all",
"configuration",
"parameters",
"are",
"of",
"an",
"expected",
"type",
"."
] | 87d1845d6cecbb5e1cc3048df1c8a6f3c8773131 | https://github.com/richhollis/diversion/blob/87d1845d6cecbb5e1cc3048df1c8a6f3c8773131/lib/diversion/configurable.rb#L59-L97 |
8,502 | airblade/brocade | lib/brocade/has_barcode.rb | Brocade.InstanceMethods.barcode | def barcode(opts = {})
data = format_for_subset_c_if_applicable send(barcodable)
if (subset = opts[:subset])
case subset
when 'A'; Barby::Code128A.new data
when 'B'; Barby::Code128B.new data
when 'C'; Barby::Code128C.new data
end
else
most_efficient_barc... | ruby | def barcode(opts = {})
data = format_for_subset_c_if_applicable send(barcodable)
if (subset = opts[:subset])
case subset
when 'A'; Barby::Code128A.new data
when 'B'; Barby::Code128B.new data
when 'C'; Barby::Code128C.new data
end
else
most_efficient_barc... | [
"def",
"barcode",
"(",
"opts",
"=",
"{",
"}",
")",
"data",
"=",
"format_for_subset_c_if_applicable",
"send",
"(",
"barcodable",
")",
"if",
"(",
"subset",
"=",
"opts",
"[",
":subset",
"]",
")",
"case",
"subset",
"when",
"'A'",
";",
"Barby",
"::",
"Code128... | Returns a Code128 barcode instance.
opts:
:subset - specify the Code128 subset to use ('A', 'B', or 'C'). | [
"Returns",
"a",
"Code128",
"barcode",
"instance",
"."
] | 1c4291a508d8b896003d5de3a4a22639c2b91839 | https://github.com/airblade/brocade/blob/1c4291a508d8b896003d5de3a4a22639c2b91839/lib/brocade/has_barcode.rb#L44-L55 |
8,503 | airblade/brocade | lib/brocade/has_barcode.rb | Brocade.InstanceMethods.create_barcode | def create_barcode(opts = {})
path = barcode_path
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb') do |f|
f.write barcode(opts).to_png(self.class.options.merge(opts))
end
FileUtils.chmod(0666 &~ File.umask, path)
end | ruby | def create_barcode(opts = {})
path = barcode_path
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb') do |f|
f.write barcode(opts).to_png(self.class.options.merge(opts))
end
FileUtils.chmod(0666 &~ File.umask, path)
end | [
"def",
"create_barcode",
"(",
"opts",
"=",
"{",
"}",
")",
"path",
"=",
"barcode_path",
"FileUtils",
".",
"mkdir_p",
"File",
".",
"dirname",
"(",
"path",
")",
"File",
".",
"open",
"(",
"path",
",",
"'wb'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write"... | Writes a barcode PNG image.
opts:
:subset - specify the Code128 subset to use ('A', 'B', or 'C').
remaining options passed through to PNGOutputter. | [
"Writes",
"a",
"barcode",
"PNG",
"image",
"."
] | 1c4291a508d8b896003d5de3a4a22639c2b91839 | https://github.com/airblade/brocade/blob/1c4291a508d8b896003d5de3a4a22639c2b91839/lib/brocade/has_barcode.rb#L62-L69 |
8,504 | checkdin/checkdin-ruby | lib/checkdin/leaderboard.rb | Checkdin.Leaderboard.classification_leaderboard | def classification_leaderboard(campaign_id)
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/classification_leaderboard"
end
return_error_or_body(response)
end | ruby | def classification_leaderboard(campaign_id)
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/classification_leaderboard"
end
return_error_or_body(response)
end | [
"def",
"classification_leaderboard",
"(",
"campaign_id",
")",
"response",
"=",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"campaigns/#{campaign_id}/classification_leaderboard\"",
"end",
"return_error_or_body",
"(",
"response",
")",
"end"
] | Get the classification leaderboard for a given campaign
param [Integer] campaign_id The ID of the campaign to fetch the leaderboard for. | [
"Get",
"the",
"classification",
"leaderboard",
"for",
"a",
"given",
"campaign"
] | c3c4b38b0f8c710e1f805100dcf3a70649215b48 | https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/leaderboard.rb#L33-L38 |
8,505 | mattherick/dummy_text | lib/dummy_text/base.rb | DummyText.Base.character | def character(count, template)
out_of_order("c", count, template)
raw Character.new.render(count, template)
end | ruby | def character(count, template)
out_of_order("c", count, template)
raw Character.new.render(count, template)
end | [
"def",
"character",
"(",
"count",
",",
"template",
")",
"out_of_order",
"(",
"\"c\"",
",",
"count",
",",
"template",
")",
"raw",
"Character",
".",
"new",
".",
"render",
"(",
"count",
",",
"template",
")",
"end"
] | select "count characters" | [
"select",
"count",
"characters"
] | 9167261a974413a885dfe2abef1bdd40529fb500 | https://github.com/mattherick/dummy_text/blob/9167261a974413a885dfe2abef1bdd40529fb500/lib/dummy_text/base.rb#L32-L35 |
8,506 | mattherick/dummy_text | lib/dummy_text/base.rb | DummyText.Base.word | def word(count, template)
out_of_order("w", count, template)
raw Word.new.render(count, template)
end | ruby | def word(count, template)
out_of_order("w", count, template)
raw Word.new.render(count, template)
end | [
"def",
"word",
"(",
"count",
",",
"template",
")",
"out_of_order",
"(",
"\"w\"",
",",
"count",
",",
"template",
")",
"raw",
"Word",
".",
"new",
".",
"render",
"(",
"count",
",",
"template",
")",
"end"
] | select "count" words | [
"select",
"count",
"words"
] | 9167261a974413a885dfe2abef1bdd40529fb500 | https://github.com/mattherick/dummy_text/blob/9167261a974413a885dfe2abef1bdd40529fb500/lib/dummy_text/base.rb#L38-L41 |
8,507 | mattherick/dummy_text | lib/dummy_text/base.rb | DummyText.Base.paragraph | def paragraph(count, template)
out_of_order("p", count, template)
i = 0
result = ""
data = Paragraph.new.render(template)
while i < count
result += "<p>#{data[i]}</p>"
i += 1
end
raw result
end | ruby | def paragraph(count, template)
out_of_order("p", count, template)
i = 0
result = ""
data = Paragraph.new.render(template)
while i < count
result += "<p>#{data[i]}</p>"
i += 1
end
raw result
end | [
"def",
"paragraph",
"(",
"count",
",",
"template",
")",
"out_of_order",
"(",
"\"p\"",
",",
"count",
",",
"template",
")",
"i",
"=",
"0",
"result",
"=",
"\"\"",
"data",
"=",
"Paragraph",
".",
"new",
".",
"render",
"(",
"template",
")",
"while",
"i",
"... | select "count" paragraphs, wrap in p-tags | [
"select",
"count",
"paragraphs",
"wrap",
"in",
"p",
"-",
"tags"
] | 9167261a974413a885dfe2abef1bdd40529fb500 | https://github.com/mattherick/dummy_text/blob/9167261a974413a885dfe2abef1bdd40529fb500/lib/dummy_text/base.rb#L50-L60 |
8,508 | caruby/core | lib/caruby/database.rb | CaRuby.Database.open | def open(user=nil, password=nil)
raise ArgumentError.new("Database open requires an execution block") unless block_given?
raise DatabaseError.new("The caRuby application database is already in use.") if open?
# reset the execution timers
persistence_services.each { |svc| svc.timer.reset }
... | ruby | def open(user=nil, password=nil)
raise ArgumentError.new("Database open requires an execution block") unless block_given?
raise DatabaseError.new("The caRuby application database is already in use.") if open?
# reset the execution timers
persistence_services.each { |svc| svc.timer.reset }
... | [
"def",
"open",
"(",
"user",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Database open requires an execution block\"",
")",
"unless",
"block_given?",
"raise",
"DatabaseError",
".",
"new",
"(",
"\"The caRuby application ... | Calls the block given to this method with this database as an argument, and closes the
database when done.
@param [String, nil] user the application login user
@param [String, nil] password the application login password
@yield [database] the operation to perform on the database
@yieldparam [Database] database se... | [
"Calls",
"the",
"block",
"given",
"to",
"this",
"method",
"with",
"this",
"database",
"as",
"an",
"argument",
"and",
"closes",
"the",
"database",
"when",
"done",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L122-L131 |
8,509 | caruby/core | lib/caruby/database.rb | CaRuby.Database.close | def close
return if @session.nil?
begin
@session.terminate_session
rescue Exception => e
logger.error("Session termination unsuccessful - #{e.message}")
end
# clear the cache
clear
logger.info("Disconnected from application server.")
@session = nil
end | ruby | def close
return if @session.nil?
begin
@session.terminate_session
rescue Exception => e
logger.error("Session termination unsuccessful - #{e.message}")
end
# clear the cache
clear
logger.info("Disconnected from application server.")
@session = nil
end | [
"def",
"close",
"return",
"if",
"@session",
".",
"nil?",
"begin",
"@session",
".",
"terminate_session",
"rescue",
"Exception",
"=>",
"e",
"logger",
".",
"error",
"(",
"\"Session termination unsuccessful - #{e.message}\"",
")",
"end",
"# clear the cache",
"clear",
"log... | Releases database resources. This method should be called when database interaction
is completed. | [
"Releases",
"database",
"resources",
".",
"This",
"method",
"should",
"be",
"called",
"when",
"database",
"interaction",
"is",
"completed",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L181-L192 |
8,510 | caruby/core | lib/caruby/database.rb | CaRuby.Database.perform | def perform(op, obj, opts=nil, &block)
op_s = op.to_s.capitalize_first
pa = Options.get(:attribute, opts)
attr_s = " #{pa}" if pa
ag_s = " autogenerated" if Options.get(:autogenerated, opts)
ctxt_s = " in context #{print_operations}" unless @operations.empty?
logger.info(">> #{op_s}#... | ruby | def perform(op, obj, opts=nil, &block)
op_s = op.to_s.capitalize_first
pa = Options.get(:attribute, opts)
attr_s = " #{pa}" if pa
ag_s = " autogenerated" if Options.get(:autogenerated, opts)
ctxt_s = " in context #{print_operations}" unless @operations.empty?
logger.info(">> #{op_s}#... | [
"def",
"perform",
"(",
"op",
",",
"obj",
",",
"opts",
"=",
"nil",
",",
"&",
"block",
")",
"op_s",
"=",
"op",
".",
"to_s",
".",
"capitalize_first",
"pa",
"=",
"Options",
".",
"get",
"(",
":attribute",
",",
"opts",
")",
"attr_s",
"=",
"\" #{pa}\"",
"... | Performs the operation given by the given op symbol on obj by calling the block given to this method.
Lazy loading is suspended during the operation.
@param [:find, :query, :create, :update, :delete] op the database operation type
@param [Resource] obj the domain object on which the operation is performed
@param o... | [
"Performs",
"the",
"operation",
"given",
"by",
"the",
"given",
"op",
"symbol",
"on",
"obj",
"by",
"calling",
"the",
"block",
"given",
"to",
"this",
"method",
".",
"Lazy",
"loading",
"is",
"suspended",
"during",
"the",
"operation",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L228-L259 |
8,511 | caruby/core | lib/caruby/database.rb | CaRuby.Database.start_session | def start_session(user=nil, password=nil)
user ||= @user
password ||= @password
if user.nil? then raise DatabaseError.new('The caRuby application is missing the login user') end
if password.nil? then raise DatabaseError.new('The caRuby application is missing the login password') end
@sessi... | ruby | def start_session(user=nil, password=nil)
user ||= @user
password ||= @password
if user.nil? then raise DatabaseError.new('The caRuby application is missing the login user') end
if password.nil? then raise DatabaseError.new('The caRuby application is missing the login password') end
@sessi... | [
"def",
"start_session",
"(",
"user",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"user",
"||=",
"@user",
"password",
"||=",
"@password",
"if",
"user",
".",
"nil?",
"then",
"raise",
"DatabaseError",
".",
"new",
"(",
"'The caRuby application is missing the login... | Initializes the default application service. | [
"Initializes",
"the",
"default",
"application",
"service",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L279-L286 |
8,512 | caruby/core | lib/caruby/database.rb | CaRuby.Database.print_operations | def print_operations
ops = @operations.reverse.map do |op|
attr_s = " #{op.attribute}" if op.attribute
"#{op.type.to_s.capitalize_first} #{op.subject.qp}#{attr_s}"
end
ops.qp
end | ruby | def print_operations
ops = @operations.reverse.map do |op|
attr_s = " #{op.attribute}" if op.attribute
"#{op.type.to_s.capitalize_first} #{op.subject.qp}#{attr_s}"
end
ops.qp
end | [
"def",
"print_operations",
"ops",
"=",
"@operations",
".",
"reverse",
".",
"map",
"do",
"|",
"op",
"|",
"attr_s",
"=",
"\" #{op.attribute}\"",
"if",
"op",
".",
"attribute",
"\"#{op.type.to_s.capitalize_first} #{op.subject.qp}#{attr_s}\"",
"end",
"ops",
".",
"qp",
"e... | Returns the current database operation stack as a String. | [
"Returns",
"the",
"current",
"database",
"operation",
"stack",
"as",
"a",
"String",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L289-L295 |
8,513 | caruby/core | lib/caruby/database.rb | CaRuby.Database.connect | def connect(user, password)
logger.debug { "Connecting to application server with login id #{user}..." }
begin
@session.start_session(user, password)
rescue Exception => e
logger.error("Login of #{user} with password #{password} was unsuccessful - #{e.message}")
raise e
e... | ruby | def connect(user, password)
logger.debug { "Connecting to application server with login id #{user}..." }
begin
@session.start_session(user, password)
rescue Exception => e
logger.error("Login of #{user} with password #{password} was unsuccessful - #{e.message}")
raise e
e... | [
"def",
"connect",
"(",
"user",
",",
"password",
")",
"logger",
".",
"debug",
"{",
"\"Connecting to application server with login id #{user}...\"",
"}",
"begin",
"@session",
".",
"start_session",
"(",
"user",
",",
"password",
")",
"rescue",
"Exception",
"=>",
"e",
... | Connects to the database. | [
"Connects",
"to",
"the",
"database",
"."
] | a682dc57c6fa31aef765cdd206ed3d4b4c289c60 | https://github.com/caruby/core/blob/a682dc57c6fa31aef765cdd206ed3d4b4c289c60/lib/caruby/database.rb#L298-L307 |
8,514 | exploration/markov_words | lib/markov_words/file_store.rb | MarkovWords.FileStore.retrieve_data | def retrieve_data(key = '')
key = key.to_s unless key.is_a? String
data_array = @db.execute 'SELECT value FROM data WHERE key = ?', key
Marshal.load(data_array[0][0]) unless data_array[0].nil?
end | ruby | def retrieve_data(key = '')
key = key.to_s unless key.is_a? String
data_array = @db.execute 'SELECT value FROM data WHERE key = ?', key
Marshal.load(data_array[0][0]) unless data_array[0].nil?
end | [
"def",
"retrieve_data",
"(",
"key",
"=",
"''",
")",
"key",
"=",
"key",
".",
"to_s",
"unless",
"key",
".",
"is_a?",
"String",
"data_array",
"=",
"@db",
".",
"execute",
"'SELECT value FROM data WHERE key = ?'",
",",
"key",
"Marshal",
".",
"load",
"(",
"data_ar... | Retrieve whatever data is stored in at `key`, and return it! | [
"Retrieve",
"whatever",
"data",
"is",
"stored",
"in",
"at",
"key",
"and",
"return",
"it!"
] | 0fa71955bed0d027633a6d4ed42b50179c17132e | https://github.com/exploration/markov_words/blob/0fa71955bed0d027633a6d4ed42b50179c17132e/lib/markov_words/file_store.rb#L34-L38 |
8,515 | nellshamrell/git_org_file_scanner | lib/git_org_file_scanner.rb | GitOrgFileScanner.Scanner.setup_client | def setup_client(token)
client = Octokit::Client.new(access_token: token)
client.auto_paginate = true
client
end | ruby | def setup_client(token)
client = Octokit::Client.new(access_token: token)
client.auto_paginate = true
client
end | [
"def",
"setup_client",
"(",
"token",
")",
"client",
"=",
"Octokit",
"::",
"Client",
".",
"new",
"(",
"access_token",
":",
"token",
")",
"client",
".",
"auto_paginate",
"=",
"true",
"client",
"end"
] | setup an oktokit client with auto_pagination turned on so we get all the repos
returned even in large organizations
@param token [String] the github access token
@return [Octokit::Client] the oktokit client object | [
"setup",
"an",
"oktokit",
"client",
"with",
"auto_pagination",
"turned",
"on",
"so",
"we",
"get",
"all",
"the",
"repos",
"returned",
"even",
"in",
"large",
"organizations"
] | a5681e3e8b065ecf1978ccb57f5455455436b011 | https://github.com/nellshamrell/git_org_file_scanner/blob/a5681e3e8b065ecf1978ccb57f5455455436b011/lib/git_org_file_scanner.rb#L21-L25 |
8,516 | bradfeehan/derelict | lib/derelict/parser/plugin_list.rb | Derelict.Parser::PluginList.plugins | def plugins
raise NeedsReinstall, output if needs_reinstall?
plugin_lines.map {|l| parse_line l.match(PARSE_PLUGIN) }.to_set
end | ruby | def plugins
raise NeedsReinstall, output if needs_reinstall?
plugin_lines.map {|l| parse_line l.match(PARSE_PLUGIN) }.to_set
end | [
"def",
"plugins",
"raise",
"NeedsReinstall",
",",
"output",
"if",
"needs_reinstall?",
"plugin_lines",
".",
"map",
"{",
"|",
"l",
"|",
"parse_line",
"l",
".",
"match",
"(",
"PARSE_PLUGIN",
")",
"}",
".",
"to_set",
"end"
] | Retrieves a Set containing all the plugins from the output | [
"Retrieves",
"a",
"Set",
"containing",
"all",
"the",
"plugins",
"from",
"the",
"output"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/plugin_list.rb#L33-L36 |
8,517 | bradfeehan/derelict | lib/derelict/parser/plugin_list.rb | Derelict.Parser::PluginList.parse_line | def parse_line(match)
raise InvalidFormat.new "Couldn't parse plugin" if match.nil?
Derelict::Plugin.new *match.captures[0..1]
end | ruby | def parse_line(match)
raise InvalidFormat.new "Couldn't parse plugin" if match.nil?
Derelict::Plugin.new *match.captures[0..1]
end | [
"def",
"parse_line",
"(",
"match",
")",
"raise",
"InvalidFormat",
".",
"new",
"\"Couldn't parse plugin\"",
"if",
"match",
".",
"nil?",
"Derelict",
"::",
"Plugin",
".",
"new",
"match",
".",
"captures",
"[",
"0",
"..",
"1",
"]",
"end"
] | Parses a single line of the output into a Plugin object | [
"Parses",
"a",
"single",
"line",
"of",
"the",
"output",
"into",
"a",
"Plugin",
"object"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/plugin_list.rb#L58-L61 |
8,518 | ranmocy/xiami_sauce | lib/xiami_sauce/track.rb | XiamiSauce.Track.sospa | def sospa(location)
string = location[1..-1]
col = location[0].to_i
row = (string.length.to_f / col).floor
remainder = string.length % col
address = [[nil]*col]*(row+1)
sizes = [row+1] * remainder + [row] * (col - remainder)
pos = 0
sizes.each_with_index... | ruby | def sospa(location)
string = location[1..-1]
col = location[0].to_i
row = (string.length.to_f / col).floor
remainder = string.length % col
address = [[nil]*col]*(row+1)
sizes = [row+1] * remainder + [row] * (col - remainder)
pos = 0
sizes.each_with_index... | [
"def",
"sospa",
"(",
"location",
")",
"string",
"=",
"location",
"[",
"1",
"..",
"-",
"1",
"]",
"col",
"=",
"location",
"[",
"0",
"]",
".",
"to_i",
"row",
"=",
"(",
"string",
".",
"length",
".",
"to_f",
"/",
"col",
")",
".",
"floor",
"remainder",... | Rewrite the algorithm, much much more better. | [
"Rewrite",
"the",
"algorithm",
"much",
"much",
"more",
"better",
"."
] | e261b073319e691d71463f86cc996347e389b2a8 | https://github.com/ranmocy/xiami_sauce/blob/e261b073319e691d71463f86cc996347e389b2a8/lib/xiami_sauce/track.rb#L54-L71 |
8,519 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client._post_json | def _post_json(path, object_to_post)
resp = @rawclient.post(url(path), JSON.dump(object_to_post), {'Content-type' => 'application/json'})
JSON.parse(resp.content)
end | ruby | def _post_json(path, object_to_post)
resp = @rawclient.post(url(path), JSON.dump(object_to_post), {'Content-type' => 'application/json'})
JSON.parse(resp.content)
end | [
"def",
"_post_json",
"(",
"path",
",",
"object_to_post",
")",
"resp",
"=",
"@rawclient",
".",
"post",
"(",
"url",
"(",
"path",
")",
",",
"JSON",
".",
"dump",
"(",
"object_to_post",
")",
",",
"{",
"'Content-type'",
"=>",
"'application/json'",
"}",
")",
"J... | post JSON data.
@param [String] path The parts of the URL that comes after the core
@param [Hash,Array] object_to_post The data to post as json
@return [Hash] the parsed-out response | [
"post",
"JSON",
"data",
"."
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L109-L112 |
8,520 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client.get | def get(path, args = {}, response_type = nil)
response_type = SimpleSolrClient::Response::GenericResponse if response_type.nil?
response_type.new(_get(path, args))
end | ruby | def get(path, args = {}, response_type = nil)
response_type = SimpleSolrClient::Response::GenericResponse if response_type.nil?
response_type.new(_get(path, args))
end | [
"def",
"get",
"(",
"path",
",",
"args",
"=",
"{",
"}",
",",
"response_type",
"=",
"nil",
")",
"response_type",
"=",
"SimpleSolrClient",
"::",
"Response",
"::",
"GenericResponse",
"if",
"response_type",
".",
"nil?",
"response_type",
".",
"new",
"(",
"_get",
... | Get from solr, and return a Response object of some sort
@return [SimpleSolrClient::Response, response_type] | [
"Get",
"from",
"solr",
"and",
"return",
"a",
"Response",
"object",
"of",
"some",
"sort"
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L116-L119 |
8,521 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client.post_json | def post_json(path, object_to_post, response_type = nil)
response_type = SimpleSolrClient::Response::GenericResponse if response_type.nil?
response_type.new(_post_json(path, object_to_post))
end | ruby | def post_json(path, object_to_post, response_type = nil)
response_type = SimpleSolrClient::Response::GenericResponse if response_type.nil?
response_type.new(_post_json(path, object_to_post))
end | [
"def",
"post_json",
"(",
"path",
",",
"object_to_post",
",",
"response_type",
"=",
"nil",
")",
"response_type",
"=",
"SimpleSolrClient",
"::",
"Response",
"::",
"GenericResponse",
"if",
"response_type",
".",
"nil?",
"response_type",
".",
"new",
"(",
"_post_json",
... | Post an object as JSON and return a Response object
@return [SimpleSolrClient::Response, response_type] | [
"Post",
"an",
"object",
"as",
"JSON",
"and",
"return",
"a",
"Response",
"object"
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L123-L126 |
8,522 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client.core | def core(corename)
raise "Core #{corename} not found" unless cores.include? corename.to_s
SimpleSolrClient::Core.new(@base_url, corename.to_s)
end | ruby | def core(corename)
raise "Core #{corename} not found" unless cores.include? corename.to_s
SimpleSolrClient::Core.new(@base_url, corename.to_s)
end | [
"def",
"core",
"(",
"corename",
")",
"raise",
"\"Core #{corename} not found\"",
"unless",
"cores",
".",
"include?",
"corename",
".",
"to_s",
"SimpleSolrClient",
"::",
"Core",
".",
"new",
"(",
"@base_url",
",",
"corename",
".",
"to_s",
")",
"end"
] | Get a client specific to the given core2
@param [String] corename The name of the core (which must already exist!)
@return [SimpleSolrClient::Core] | [
"Get",
"a",
"client",
"specific",
"to",
"the",
"given",
"core2"
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L132-L135 |
8,523 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client.new_core | def new_core(corename)
dir = temp_core_dir_setup(corename)
args = {
:wt => 'json',
:action => 'CREATE',
:name => corename,
:instanceDir => dir
}
get('admin/cores', args)
core(corename)
end | ruby | def new_core(corename)
dir = temp_core_dir_setup(corename)
args = {
:wt => 'json',
:action => 'CREATE',
:name => corename,
:instanceDir => dir
}
get('admin/cores', args)
core(corename)
end | [
"def",
"new_core",
"(",
"corename",
")",
"dir",
"=",
"temp_core_dir_setup",
"(",
"corename",
")",
"args",
"=",
"{",
":wt",
"=>",
"'json'",
",",
":action",
"=>",
"'CREATE'",
",",
":name",
"=>",
"corename",
",",
":instanceDir",
"=>",
"dir",
"}",
"get",
"("... | Create a new, temporary core
noinspection RubyWrongHash | [
"Create",
"a",
"new",
"temporary",
"core",
"noinspection",
"RubyWrongHash"
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L146-L159 |
8,524 | billdueber/simple_solr_client | lib/simple_solr_client/client.rb | SimpleSolrClient.Client.temp_core_dir_setup | def temp_core_dir_setup(corename)
dest = Dir.mktmpdir("simple_solr_#{corename}_#{SecureRandom.uuid}")
src = SAMPLE_CORE_DIR
FileUtils.cp_r File.join(src, '.'), dest
dest
end | ruby | def temp_core_dir_setup(corename)
dest = Dir.mktmpdir("simple_solr_#{corename}_#{SecureRandom.uuid}")
src = SAMPLE_CORE_DIR
FileUtils.cp_r File.join(src, '.'), dest
dest
end | [
"def",
"temp_core_dir_setup",
"(",
"corename",
")",
"dest",
"=",
"Dir",
".",
"mktmpdir",
"(",
"\"simple_solr_#{corename}_#{SecureRandom.uuid}\"",
")",
"src",
"=",
"SAMPLE_CORE_DIR",
"FileUtils",
".",
"cp_r",
"File",
".",
"join",
"(",
"src",
",",
"'.'",
")",
",",... | Set up files for a temp core | [
"Set",
"up",
"files",
"for",
"a",
"temp",
"core"
] | 51fab6319e7f295c081e77584b66996b73bc5355 | https://github.com/billdueber/simple_solr_client/blob/51fab6319e7f295c081e77584b66996b73bc5355/lib/simple_solr_client/client.rb#L166-L171 |
8,525 | Syncano/syncano-ruby | lib/syncano/jimson_client.rb | Jimson.ClientHelper.send_single_request | def send_single_request(method, args)
post_data = {
'jsonrpc' => JSON_RPC_VERSION,
'method' => method,
'params' => args,
'id' => self.class.make_id
}.to_json
resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ru... | ruby | def send_single_request(method, args)
post_data = {
'jsonrpc' => JSON_RPC_VERSION,
'method' => method,
'params' => args,
'id' => self.class.make_id
}.to_json
resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ru... | [
"def",
"send_single_request",
"(",
"method",
",",
"args",
")",
"post_data",
"=",
"{",
"'jsonrpc'",
"=>",
"JSON_RPC_VERSION",
",",
"'method'",
"=>",
"method",
",",
"'params'",
"=>",
"args",
",",
"'id'",
"=>",
"self",
".",
"class",
".",
"make_id",
"}",
".",
... | Overwritten send_single_request method, so it now adds header with the user agent
@return [Array] collection of responses | [
"Overwritten",
"send_single_request",
"method",
"so",
"it",
"now",
"adds",
"header",
"with",
"the",
"user",
"agent"
] | 59155f8afd7a19dd1a168716c4409270a7edc0d3 | https://github.com/Syncano/syncano-ruby/blob/59155f8afd7a19dd1a168716c4409270a7edc0d3/lib/syncano/jimson_client.rb#L7-L23 |
8,526 | Syncano/syncano-ruby | lib/syncano/jimson_client.rb | Jimson.ClientHelper.send_batch_request | def send_batch_request(batch)
post_data = batch.to_json
resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ruby-#{Syncano::VERSION}")
if resp.nil? || resp.body.nil? || resp.body.empty?
raise Jimson::ClientError::InvalidResponse.new
end
r... | ruby | def send_batch_request(batch)
post_data = batch.to_json
resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ruby-#{Syncano::VERSION}")
if resp.nil? || resp.body.nil? || resp.body.empty?
raise Jimson::ClientError::InvalidResponse.new
end
r... | [
"def",
"send_batch_request",
"(",
"batch",
")",
"post_data",
"=",
"batch",
".",
"to_json",
"resp",
"=",
"RestClient",
".",
"post",
"(",
"@url",
",",
"post_data",
",",
"content_type",
":",
"'application/json'",
",",
"user_agent",
":",
"\"syncano-ruby-#{Syncano::VER... | Overwritten send_batch_request method, so it now adds header with the user agent
@return [Array] collection of responses | [
"Overwritten",
"send_batch_request",
"method",
"so",
"it",
"now",
"adds",
"header",
"with",
"the",
"user",
"agent"
] | 59155f8afd7a19dd1a168716c4409270a7edc0d3 | https://github.com/Syncano/syncano-ruby/blob/59155f8afd7a19dd1a168716c4409270a7edc0d3/lib/syncano/jimson_client.rb#L27-L35 |
8,527 | Syncano/syncano-ruby | lib/syncano/jimson_client.rb | Jimson.ClientHelper.send_batch | def send_batch
batch = @batch.map(&:first) # get the requests
response = send_batch_request(batch)
begin
responses = JSON.parse(response)
rescue
raise Jimson::ClientError::InvalidJSON.new(json)
end
process_batch_response(responses)
responses = @batch
@b... | ruby | def send_batch
batch = @batch.map(&:first) # get the requests
response = send_batch_request(batch)
begin
responses = JSON.parse(response)
rescue
raise Jimson::ClientError::InvalidJSON.new(json)
end
process_batch_response(responses)
responses = @batch
@b... | [
"def",
"send_batch",
"batch",
"=",
"@batch",
".",
"map",
"(",
":first",
")",
"# get the requests",
"response",
"=",
"send_batch_request",
"(",
"batch",
")",
"begin",
"responses",
"=",
"JSON",
".",
"parse",
"(",
"response",
")",
"rescue",
"raise",
"Jimson",
"... | Overwritten send_batch method, so it now returns collection of responses
@return [Array] collection of responses | [
"Overwritten",
"send_batch",
"method",
"so",
"it",
"now",
"returns",
"collection",
"of",
"responses"
] | 59155f8afd7a19dd1a168716c4409270a7edc0d3 | https://github.com/Syncano/syncano-ruby/blob/59155f8afd7a19dd1a168716c4409270a7edc0d3/lib/syncano/jimson_client.rb#L39-L55 |
8,528 | smsified/smsified-ruby | lib/smsified/helpers.rb | Smsified.Helpers.camelcase_keys | def camelcase_keys(options)
options = options.clone
if options[:destination_address]
options[:destinationAddress] = options[:destination_address]
options.delete(:destination_address)
end
if options[:notify_url]
options[:notifyURL] = options[:notify_url]
... | ruby | def camelcase_keys(options)
options = options.clone
if options[:destination_address]
options[:destinationAddress] = options[:destination_address]
options.delete(:destination_address)
end
if options[:notify_url]
options[:notifyURL] = options[:notify_url]
... | [
"def",
"camelcase_keys",
"(",
"options",
")",
"options",
"=",
"options",
".",
"clone",
"if",
"options",
"[",
":destination_address",
"]",
"options",
"[",
":destinationAddress",
"]",
"=",
"options",
"[",
":destination_address",
"]",
"options",
".",
"delete",
"(",... | Camelcases the options | [
"Camelcases",
"the",
"options"
] | 1c7a0f445ffe7fe0fb035a1faf44ac55687a4488 | https://github.com/smsified/smsified-ruby/blob/1c7a0f445ffe7fe0fb035a1faf44ac55687a4488/lib/smsified/helpers.rb#L7-L31 |
8,529 | smsified/smsified-ruby | lib/smsified/helpers.rb | Smsified.Helpers.build_query_string | def build_query_string(options)
options = camelcase_keys(options)
query = ''
options.each do |k,v|
if k == :address
if RUBY_VERSION.to_f >= 1.9
if v.instance_of?(String)
v.each_line { |address| query += "#{ '&' if query != '' }address=#{CGI.escape ad... | ruby | def build_query_string(options)
options = camelcase_keys(options)
query = ''
options.each do |k,v|
if k == :address
if RUBY_VERSION.to_f >= 1.9
if v.instance_of?(String)
v.each_line { |address| query += "#{ '&' if query != '' }address=#{CGI.escape ad... | [
"def",
"build_query_string",
"(",
"options",
")",
"options",
"=",
"camelcase_keys",
"(",
"options",
")",
"query",
"=",
"''",
"options",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"if",
"k",
"==",
":address",
"if",
"RUBY_VERSION",
".",
"to_f",
">=",
"1... | Builds the necessary query string | [
"Builds",
"the",
"necessary",
"query",
"string"
] | 1c7a0f445ffe7fe0fb035a1faf44ac55687a4488 | https://github.com/smsified/smsified-ruby/blob/1c7a0f445ffe7fe0fb035a1faf44ac55687a4488/lib/smsified/helpers.rb#L35-L57 |
8,530 | cordawyn/redlander | lib/redlander/serializing.rb | Redlander.Serializing.to | def to(options = {})
format = options[:format].to_s
mime_type = options[:mime_type] && options[:mime_type].to_s
type_uri = options[:type_uri] && options[:type_uri].to_s
base_uri = options[:base_uri] && options[:base_uri].to_s
rdf_serializer = Redland.librdf_new_serializer(Redlander.rdf_wo... | ruby | def to(options = {})
format = options[:format].to_s
mime_type = options[:mime_type] && options[:mime_type].to_s
type_uri = options[:type_uri] && options[:type_uri].to_s
base_uri = options[:base_uri] && options[:base_uri].to_s
rdf_serializer = Redland.librdf_new_serializer(Redlander.rdf_wo... | [
"def",
"to",
"(",
"options",
"=",
"{",
"}",
")",
"format",
"=",
"options",
"[",
":format",
"]",
".",
"to_s",
"mime_type",
"=",
"options",
"[",
":mime_type",
"]",
"&&",
"options",
"[",
":mime_type",
"]",
".",
"to_s",
"type_uri",
"=",
"options",
"[",
"... | Serialize model into a string
@param [Hash] options
@option options [String] :format name of the serializer to use,
@option options [String] :mime_type MIME type of the syntax, if applicable,
@option options [String, URI] :type_uri URI of syntax, if applicable,
@option options [String, URI] :base_uri base URI,
... | [
"Serialize",
"model",
"into",
"a",
"string"
] | a5c84e15a7602c674606e531bda6a616b1237c44 | https://github.com/cordawyn/redlander/blob/a5c84e15a7602c674606e531bda6a616b1237c44/lib/redlander/serializing.rb#L14-L32 |
8,531 | craigp/djinn | lib/djinn/base.rb | Djinn.Base.start | def start config={}, &block
@config.update(config).update(load_config)
#@config = (config.empty?) ? load_config : config
log "Starting #{name} in the background.."
logfile = get_logfile(config)
daemonize(logfile, get_pidfile(config)) do
yield(self) if block_given?
trap('TER... | ruby | def start config={}, &block
@config.update(config).update(load_config)
#@config = (config.empty?) ? load_config : config
log "Starting #{name} in the background.."
logfile = get_logfile(config)
daemonize(logfile, get_pidfile(config)) do
yield(self) if block_given?
trap('TER... | [
"def",
"start",
"config",
"=",
"{",
"}",
",",
"&",
"block",
"@config",
".",
"update",
"(",
"config",
")",
".",
"update",
"(",
"load_config",
")",
"#@config = (config.empty?) ? load_config : config",
"log",
"\"Starting #{name} in the background..\"",
"logfile",
"=",
... | Starts the Djinn in the background. | [
"Starts",
"the",
"Djinn",
"in",
"the",
"background",
"."
] | 4683a3f6d95db54c87e02bd0780d8148c4f8ab7d | https://github.com/craigp/djinn/blob/4683a3f6d95db54c87e02bd0780d8148c4f8ab7d/lib/djinn/base.rb#L39-L53 |
8,532 | craigp/djinn | lib/djinn/base.rb | Djinn.Base.run | def run config={}, &block
@config.update(config).update(load_config)
# @config = (config.empty?) ? load_config : config
log "Starting #{name} in the foreground.."
trap('TERM') { handle_exit }
trap('INT') { handle_exit }
yield(self) if block_given?
(respond_to?(:__start!)) ? __... | ruby | def run config={}, &block
@config.update(config).update(load_config)
# @config = (config.empty?) ? load_config : config
log "Starting #{name} in the foreground.."
trap('TERM') { handle_exit }
trap('INT') { handle_exit }
yield(self) if block_given?
(respond_to?(:__start!)) ? __... | [
"def",
"run",
"config",
"=",
"{",
"}",
",",
"&",
"block",
"@config",
".",
"update",
"(",
"config",
")",
".",
"update",
"(",
"load_config",
")",
"# @config = (config.empty?) ? load_config : config",
"log",
"\"Starting #{name} in the foreground..\"",
"trap",
"(",
"'TE... | Starts the Djinn in the foreground, which is often useful for
testing or other noble pursuits. | [
"Starts",
"the",
"Djinn",
"in",
"the",
"foreground",
"which",
"is",
"often",
"useful",
"for",
"testing",
"or",
"other",
"noble",
"pursuits",
"."
] | 4683a3f6d95db54c87e02bd0780d8148c4f8ab7d | https://github.com/craigp/djinn/blob/4683a3f6d95db54c87e02bd0780d8148c4f8ab7d/lib/djinn/base.rb#L57-L68 |
8,533 | userhello/bit_magic | lib/bit_magic/bit_field.rb | BitMagic.BitField.read_bits | def read_bits(*args)
{}.tap do |m|
args.each { |bit| m[bit] = @value[bit] }
end
end | ruby | def read_bits(*args)
{}.tap do |m|
args.each { |bit| m[bit] = @value[bit] }
end
end | [
"def",
"read_bits",
"(",
"*",
"args",
")",
"{",
"}",
".",
"tap",
"do",
"|",
"m",
"|",
"args",
".",
"each",
"{",
"|",
"bit",
"|",
"m",
"[",
"bit",
"]",
"=",
"@value",
"[",
"bit",
"]",
"}",
"end",
"end"
] | Initialize the BitField with an optional value. Default is 0
@param [Integer] value the integer that contains the bit fields
Read the specified bit indices into a hash with bit index as key
@param [Integer] bits one or more bit indices to read.
@example Read a list of bits into a hash
bit_field = BitField.new... | [
"Initialize",
"the",
"BitField",
"with",
"an",
"optional",
"value",
".",
"Default",
"is",
"0"
] | 78b7fc28313af9c9506220812573576d229186bb | https://github.com/userhello/bit_magic/blob/78b7fc28313af9c9506220812573576d229186bb/lib/bit_magic/bit_field.rb#L35-L39 |
8,534 | userhello/bit_magic | lib/bit_magic/bit_field.rb | BitMagic.BitField.read_field | def read_field(*args)
m = 0
args.flatten.each_with_index do |bit, i|
if bit.is_a?(Integer)
m |= ((@value[bit] || 0) << i)
end
end
m
end | ruby | def read_field(*args)
m = 0
args.flatten.each_with_index do |bit, i|
if bit.is_a?(Integer)
m |= ((@value[bit] || 0) << i)
end
end
m
end | [
"def",
"read_field",
"(",
"*",
"args",
")",
"m",
"=",
"0",
"args",
".",
"flatten",
".",
"each_with_index",
"do",
"|",
"bit",
",",
"i",
"|",
"if",
"bit",
".",
"is_a?",
"(",
"Integer",
")",
"m",
"|=",
"(",
"(",
"@value",
"[",
"bit",
"]",
"||",
"0... | Read the specified bit indices as a group, in the order given
@param [Integer] bits one or more bit indices to read. Order matters!
@example Read bits or a list of bits into an integer
bit_field = BitField.new(101) # 1100101 in binary, lsb on the right
bit_field.read_field(0, 1, 2) #=> 5 # or 101
bit_field... | [
"Read",
"the",
"specified",
"bit",
"indices",
"as",
"a",
"group",
"in",
"the",
"order",
"given"
] | 78b7fc28313af9c9506220812573576d229186bb | https://github.com/userhello/bit_magic/blob/78b7fc28313af9c9506220812573576d229186bb/lib/bit_magic/bit_field.rb#L52-L60 |
8,535 | giraffi/zcloudjp | lib/zcloudjp/utils.rb | Zcloudjp.Utils.parse_params | def parse_params(params, key_word)
body = params.has_key?(:path) ? load_file(params[:path], key_word) : params
body = { key_word => body } unless body.has_key?(key_word.to_sym)
body
end | ruby | def parse_params(params, key_word)
body = params.has_key?(:path) ? load_file(params[:path], key_word) : params
body = { key_word => body } unless body.has_key?(key_word.to_sym)
body
end | [
"def",
"parse_params",
"(",
"params",
",",
"key_word",
")",
"body",
"=",
"params",
".",
"has_key?",
"(",
":path",
")",
"?",
"load_file",
"(",
"params",
"[",
":path",
"]",
",",
"key_word",
")",
":",
"params",
"body",
"=",
"{",
"key_word",
"=>",
"body",
... | Parses given params or file and returns Hash including the given key. | [
"Parses",
"given",
"params",
"or",
"file",
"and",
"returns",
"Hash",
"including",
"the",
"given",
"key",
"."
] | 0ee8dd49cf469fd182a48856fae63f606a959de5 | https://github.com/giraffi/zcloudjp/blob/0ee8dd49cf469fd182a48856fae63f606a959de5/lib/zcloudjp/utils.rb#L7-L11 |
8,536 | giraffi/zcloudjp | lib/zcloudjp/utils.rb | Zcloudjp.Utils.load_file | def load_file(path, key_word)
begin
data = MultiJson.load(IO.read(File.expand_path(path)), symbolize_keys: true)
rescue RuntimeError, Errno::ENOENT => e
raise e.message
rescue MultiJson::LoadError => e
raise e.message
end
if data.has_key?(key_word)
data[ke... | ruby | def load_file(path, key_word)
begin
data = MultiJson.load(IO.read(File.expand_path(path)), symbolize_keys: true)
rescue RuntimeError, Errno::ENOENT => e
raise e.message
rescue MultiJson::LoadError => e
raise e.message
end
if data.has_key?(key_word)
data[ke... | [
"def",
"load_file",
"(",
"path",
",",
"key_word",
")",
"begin",
"data",
"=",
"MultiJson",
".",
"load",
"(",
"IO",
".",
"read",
"(",
"File",
".",
"expand_path",
"(",
"path",
")",
")",
",",
"symbolize_keys",
":",
"true",
")",
"rescue",
"RuntimeError",
",... | Loads a specified file and returns Hash including the given key. | [
"Loads",
"a",
"specified",
"file",
"and",
"returns",
"Hash",
"including",
"the",
"given",
"key",
"."
] | 0ee8dd49cf469fd182a48856fae63f606a959de5 | https://github.com/giraffi/zcloudjp/blob/0ee8dd49cf469fd182a48856fae63f606a959de5/lib/zcloudjp/utils.rb#L14-L26 |
8,537 | cespare/pinion | lib/pinion/server.rb | Pinion.Server.bundle_url | def bundle_url(name)
bundle = Bundle[name]
raise "No such bundle: #{name}" unless bundle
return bundle.paths.map { |p| asset_url(p) } unless Pinion.environment == "production"
["#{@mount_point}/#{bundle.name}-#{bundle.checksum}.#{bundle.extension}"]
end | ruby | def bundle_url(name)
bundle = Bundle[name]
raise "No such bundle: #{name}" unless bundle
return bundle.paths.map { |p| asset_url(p) } unless Pinion.environment == "production"
["#{@mount_point}/#{bundle.name}-#{bundle.checksum}.#{bundle.extension}"]
end | [
"def",
"bundle_url",
"(",
"name",
")",
"bundle",
"=",
"Bundle",
"[",
"name",
"]",
"raise",
"\"No such bundle: #{name}\"",
"unless",
"bundle",
"return",
"bundle",
".",
"paths",
".",
"map",
"{",
"|",
"p",
"|",
"asset_url",
"(",
"p",
")",
"}",
"unless",
"Pi... | Return the bundle url. In production, the single bundled result is produced; otherwise, each individual
asset_url is returned. | [
"Return",
"the",
"bundle",
"url",
".",
"In",
"production",
"the",
"single",
"bundled",
"result",
"is",
"produced",
";",
"otherwise",
"each",
"individual",
"asset_url",
"is",
"returned",
"."
] | 6dea89da573cef93793a8d9b76e2e692581bddcf | https://github.com/cespare/pinion/blob/6dea89da573cef93793a8d9b76e2e692581bddcf/lib/pinion/server.rb#L148-L153 |
8,538 | yjchen/easy_tag | lib/easy_tag/taggable.rb | EasyTag.Taggable.set_tags | def set_tags(tag_list, options = {})
options.reverse_merge! :context => nil,
:tagger => nil,
:downcase => true,
:delimiter => ','
if block_given?
tags = yield(klass)
else
tags = EasyTag::Tag.compa... | ruby | def set_tags(tag_list, options = {})
options.reverse_merge! :context => nil,
:tagger => nil,
:downcase => true,
:delimiter => ','
if block_given?
tags = yield(klass)
else
tags = EasyTag::Tag.compa... | [
"def",
"set_tags",
"(",
"tag_list",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"reverse_merge!",
":context",
"=>",
"nil",
",",
":tagger",
"=>",
"nil",
",",
":downcase",
"=>",
"true",
",",
":delimiter",
"=>",
"','",
"if",
"block_given?",
"tags",
... | end of class methods | [
"end",
"of",
"class",
"methods"
] | 960c4cc2407e4f5d7c1a84c2855b936e42626ec0 | https://github.com/yjchen/easy_tag/blob/960c4cc2407e4f5d7c1a84c2855b936e42626ec0/lib/easy_tag/taggable.rb#L67-L93 |
8,539 | caimano/rlocu2 | lib/rlocu2/objects.rb | Rlocu2.Venue.external= | def external=(externals_list)
@external = []
externals_list.each { |external_id| @external << Rlocu2::ExternalID.new(id: external_id['id'], url: external_id['url'], mobile_url: external_id['mobile_url'])}
end | ruby | def external=(externals_list)
@external = []
externals_list.each { |external_id| @external << Rlocu2::ExternalID.new(id: external_id['id'], url: external_id['url'], mobile_url: external_id['mobile_url'])}
end | [
"def",
"external",
"=",
"(",
"externals_list",
")",
"@external",
"=",
"[",
"]",
"externals_list",
".",
"each",
"{",
"|",
"external_id",
"|",
"@external",
"<<",
"Rlocu2",
"::",
"ExternalID",
".",
"new",
"(",
"id",
":",
"external_id",
"[",
"'id'",
"]",
","... | BUILD sub structures | [
"BUILD",
"sub",
"structures"
] | 8117bc034816c03a435160301c99c9a1b4e603df | https://github.com/caimano/rlocu2/blob/8117bc034816c03a435160301c99c9a1b4e603df/lib/rlocu2/objects.rb#L17-L20 |
8,540 | indeep-xyz/ruby-file-char-licker | lib/file_char_licker/licker/licker.rb | FileCharLicker.Licker.forward_lines | def forward_lines(size = 10)
file = @file
result = ""
while result.scan(/\r\n|\r|\n/).size < size && !file.eof?
result += file.gets
end
result
end | ruby | def forward_lines(size = 10)
file = @file
result = ""
while result.scan(/\r\n|\r|\n/).size < size && !file.eof?
result += file.gets
end
result
end | [
"def",
"forward_lines",
"(",
"size",
"=",
"10",
")",
"file",
"=",
"@file",
"result",
"=",
"\"\"",
"while",
"result",
".",
"scan",
"(",
"/",
"\\r",
"\\n",
"\\r",
"\\n",
"/",
")",
".",
"size",
"<",
"size",
"&&",
"!",
"file",
".",
"eof?",
"result",
... | get forward lines
args
size ... number of lines
returner
String object as lines | [
"get",
"forward",
"lines"
] | 06d9cee1bf0a40a1f90f35e6b43e211609a03b08 | https://github.com/indeep-xyz/ruby-file-char-licker/blob/06d9cee1bf0a40a1f90f35e6b43e211609a03b08/lib/file_char_licker/licker/licker.rb#L118-L129 |
8,541 | mirego/parole | lib/parole/comment.rb | Parole.Comment.ensure_valid_role_for_commentable | def ensure_valid_role_for_commentable
allowed_roles = commentable.class.commentable_options[:roles]
if allowed_roles.any?
errors.add(:role, :invalid) unless allowed_roles.include?(self.role)
else
errors.add(:role, :invalid) unless self.role.blank?
end
end | ruby | def ensure_valid_role_for_commentable
allowed_roles = commentable.class.commentable_options[:roles]
if allowed_roles.any?
errors.add(:role, :invalid) unless allowed_roles.include?(self.role)
else
errors.add(:role, :invalid) unless self.role.blank?
end
end | [
"def",
"ensure_valid_role_for_commentable",
"allowed_roles",
"=",
"commentable",
".",
"class",
".",
"commentable_options",
"[",
":roles",
"]",
"if",
"allowed_roles",
".",
"any?",
"errors",
".",
"add",
"(",
":role",
",",
":invalid",
")",
"unless",
"allowed_roles",
... | Make sure that the value of the `role` attribute is a valid role
for the commentable.
If the commentable doesn't have any comment roles, we make sure
that the value is blank. | [
"Make",
"sure",
"that",
"the",
"value",
"of",
"the",
"role",
"attribute",
"is",
"a",
"valid",
"role",
"for",
"the",
"commentable",
"."
] | b8fb33dc14ef2d2af37c92ed0d0cddec52575951 | https://github.com/mirego/parole/blob/b8fb33dc14ef2d2af37c92ed0d0cddec52575951/lib/parole/comment.rb#L51-L59 |
8,542 | fotonauts/activr | lib/activr/dispatcher.rb | Activr.Dispatcher.route | def route(activity)
raise "Activity must be stored before routing: #{activity.inspect}" if !activity.stored?
result = 0
activity.run_callbacks(:route) do
# iterate on all timelines
Activr.registry.timelines.values.each do |timeline_class|
# check if timeline refuses that ac... | ruby | def route(activity)
raise "Activity must be stored before routing: #{activity.inspect}" if !activity.stored?
result = 0
activity.run_callbacks(:route) do
# iterate on all timelines
Activr.registry.timelines.values.each do |timeline_class|
# check if timeline refuses that ac... | [
"def",
"route",
"(",
"activity",
")",
"raise",
"\"Activity must be stored before routing: #{activity.inspect}\"",
"if",
"!",
"activity",
".",
"stored?",
"result",
"=",
"0",
"activity",
".",
"run_callbacks",
"(",
":route",
")",
"do",
"# iterate on all timelines",
"Activr... | Route an activity
@param activity [Activity] Activity to route
@return [Integer] The number of resolved recipients that will handle activity | [
"Route",
"an",
"activity"
] | 92c071ad18a76d4130661da3ce47c1f0fb8ae913 | https://github.com/fotonauts/activr/blob/92c071ad18a76d4130661da3ce47c1f0fb8ae913/lib/activr/dispatcher.rb#L14-L38 |
8,543 | fotonauts/activr | lib/activr/dispatcher.rb | Activr.Dispatcher.recipients_for_timeline | def recipients_for_timeline(timeline_class, activity)
result = { }
routes = timeline_class.routes_for_activity(activity.class)
routes.each do |route|
route.resolve(activity).each do |recipient|
recipient_id = timeline_class.recipient_id(recipient)
# keep only one route pe... | ruby | def recipients_for_timeline(timeline_class, activity)
result = { }
routes = timeline_class.routes_for_activity(activity.class)
routes.each do |route|
route.resolve(activity).each do |recipient|
recipient_id = timeline_class.recipient_id(recipient)
# keep only one route pe... | [
"def",
"recipients_for_timeline",
"(",
"timeline_class",
",",
"activity",
")",
"result",
"=",
"{",
"}",
"routes",
"=",
"timeline_class",
".",
"routes_for_activity",
"(",
"activity",
".",
"class",
")",
"routes",
".",
"each",
"do",
"|",
"route",
"|",
"route",
... | Find recipients for given activity in given timeline
@api private
@param timeline_class [Class] Timeline class
@param activity [Activity] Activity instance
@return [Hash{Object=>Timeline::Route}] Recipients with corresponding Routes | [
"Find",
"recipients",
"for",
"given",
"activity",
"in",
"given",
"timeline"
] | 92c071ad18a76d4130661da3ce47c1f0fb8ae913 | https://github.com/fotonauts/activr/blob/92c071ad18a76d4130661da3ce47c1f0fb8ae913/lib/activr/dispatcher.rb#L47-L66 |
8,544 | agios/simple_form-dojo | lib/simple_form-dojo/dojo_props_methods.rb | SimpleFormDojo.DojoPropsMethods.get_and_merge_dojo_props! | def get_and_merge_dojo_props!
add_dojo_options_to_dojo_props
if object.id.present?
add_dojo_compliant_id
else
input_html_options["id"] = nil #let dojo generate internal id
end
input_html_options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(@dojo_p... | ruby | def get_and_merge_dojo_props!
add_dojo_options_to_dojo_props
if object.id.present?
add_dojo_compliant_id
else
input_html_options["id"] = nil #let dojo generate internal id
end
input_html_options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(@dojo_p... | [
"def",
"get_and_merge_dojo_props!",
"add_dojo_options_to_dojo_props",
"if",
"object",
".",
"id",
".",
"present?",
"add_dojo_compliant_id",
"else",
"input_html_options",
"[",
"\"id\"",
"]",
"=",
"nil",
"#let dojo generate internal id",
"end",
"input_html_options",
"[",
":'",... | Retrieves and merges all dojo_props | [
"Retrieves",
"and",
"merges",
"all",
"dojo_props"
] | c4b134f56f4cb68cba81d583038965360c70fba4 | https://github.com/agios/simple_form-dojo/blob/c4b134f56f4cb68cba81d583038965360c70fba4/lib/simple_form-dojo/dojo_props_methods.rb#L5-L13 |
8,545 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.store | def store(data)
request_data = {:value => data}
request_data[:expire] = @expire if @expire
request = prepare_request :POST, request_data.to_json
Response.new(execute_request(request))
end | ruby | def store(data)
request_data = {:value => data}
request_data[:expire] = @expire if @expire
request = prepare_request :POST, request_data.to_json
Response.new(execute_request(request))
end | [
"def",
"store",
"(",
"data",
")",
"request_data",
"=",
"{",
":value",
"=>",
"data",
"}",
"request_data",
"[",
":expire",
"]",
"=",
"@expire",
"if",
"@expire",
"request",
"=",
"prepare_request",
":POST",
",",
"request_data",
".",
"to_json",
"Response",
".",
... | Initialize a client to a SAM node hosted at a specific url
@param [Hash] optional hash with user, password, host and port of the SAM node
@return [Client] the object itself
@example
nsisam = NSISam::Client.new user: 'username' password: 'pass',
host: 'localhost', port: '8888'
Stor... | [
"Initialize",
"a",
"client",
"to",
"a",
"SAM",
"node",
"hosted",
"at",
"a",
"specific",
"url"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L42-L47 |
8,546 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.store_file | def store_file(file_content, filename, type=:file)
store(type => Base64.encode64(file_content), :filename => filename)
end | ruby | def store_file(file_content, filename, type=:file)
store(type => Base64.encode64(file_content), :filename => filename)
end | [
"def",
"store_file",
"(",
"file_content",
",",
"filename",
",",
"type",
"=",
":file",
")",
"store",
"(",
"type",
"=>",
"Base64",
".",
"encode64",
"(",
"file_content",
")",
",",
":filename",
"=>",
"filename",
")",
"end"
] | Store a file in SAM. If the file will be used by other NSI's service
you should pass an additional 'type' parameter.
@param [Object] file_content json serializable object
@param [Symbol] type of the file to be stored. Can be either :doc and :video.
@return [Response] object with access to the key and the sha512 ch... | [
"Store",
"a",
"file",
"in",
"SAM",
".",
"If",
"the",
"file",
"will",
"be",
"used",
"by",
"other",
"NSI",
"s",
"service",
"you",
"should",
"pass",
"an",
"additional",
"type",
"parameter",
"."
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L61-L63 |
8,547 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.delete | def delete(key)
request_data = {:key => key}.to_json
request = prepare_request :DELETE, request_data
Response.new(execute_request(request))
end | ruby | def delete(key)
request_data = {:key => key}.to_json
request = prepare_request :DELETE, request_data
Response.new(execute_request(request))
end | [
"def",
"delete",
"(",
"key",
")",
"request_data",
"=",
"{",
":key",
"=>",
"key",
"}",
".",
"to_json",
"request",
"=",
"prepare_request",
":DELETE",
",",
"request_data",
"Response",
".",
"new",
"(",
"execute_request",
"(",
"request",
")",
")",
"end"
] | Delete data at a given SAM key
@param [Sring] key of the value to delete
@return [Hash] response
* "deleted" [Boolean] true if the key was successfully deleted
@raise [NSISam::Errors::Client::KeyNotFoundError] when the key doesn't exists
@raise [NSISam::Errors::Client::AuthenticationError] when user and passwo... | [
"Delete",
"data",
"at",
"a",
"given",
"SAM",
"key"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L76-L80 |
8,548 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.get | def get(key, expected_checksum=nil)
request_data = {:key => key}.to_json
request = prepare_request :GET, request_data
response = execute_request(request)
verify_checksum(response["data"], expected_checksum) unless expected_checksum.nil?
Response.new(response)
end | ruby | def get(key, expected_checksum=nil)
request_data = {:key => key}.to_json
request = prepare_request :GET, request_data
response = execute_request(request)
verify_checksum(response["data"], expected_checksum) unless expected_checksum.nil?
Response.new(response)
end | [
"def",
"get",
"(",
"key",
",",
"expected_checksum",
"=",
"nil",
")",
"request_data",
"=",
"{",
":key",
"=>",
"key",
"}",
".",
"to_json",
"request",
"=",
"prepare_request",
":GET",
",",
"request_data",
"response",
"=",
"execute_request",
"(",
"request",
")",
... | Recover data stored at a given SAM key
@param [String] key of the value to acess
@return [Response] response object holding the file and some metadata
@raise [NSISam::Errors::Client::KeyNotFoundError] when the key doesn't exists
@raise [NSISam::Errors::Client::AuthenticationError] when user and password doesn't m... | [
"Recover",
"data",
"stored",
"at",
"a",
"given",
"SAM",
"key"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L92-L98 |
8,549 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.get_file | def get_file(key, type=:file, expected_checksum = nil)
response = get(key, expected_checksum)
response = Response.new(
'key' => response.key,
'checksum' => response.checksum,
'filename' => response.data['filename'],
'file' => Base64.decode64(response.data[type.to_s]),
... | ruby | def get_file(key, type=:file, expected_checksum = nil)
response = get(key, expected_checksum)
response = Response.new(
'key' => response.key,
'checksum' => response.checksum,
'filename' => response.data['filename'],
'file' => Base64.decode64(response.data[type.to_s]),
... | [
"def",
"get_file",
"(",
"key",
",",
"type",
"=",
":file",
",",
"expected_checksum",
"=",
"nil",
")",
"response",
"=",
"get",
"(",
"key",
",",
"expected_checksum",
")",
"response",
"=",
"Response",
".",
"new",
"(",
"'key'",
"=>",
"response",
".",
"key",
... | Recover a file stored at a given SAM key
@param [String] key of the file to access
@param [Symbol] type of the file to be recovered. Can be either :doc and :video.
@return [Response] response object holding the file and some metadata
@raise [NSISam::Errors::Client::KeyNotFoundError] when the key doesn't exists
@... | [
"Recover",
"a",
"file",
"stored",
"at",
"a",
"given",
"SAM",
"key"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L115-L123 |
8,550 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.update | def update(key, value)
request_data = {:key => key, :value => value}
request_data[:expire] = @expire if @expire
request = prepare_request :PUT, request_data.to_json
Response.new(execute_request(request))
end | ruby | def update(key, value)
request_data = {:key => key, :value => value}
request_data[:expire] = @expire if @expire
request = prepare_request :PUT, request_data.to_json
Response.new(execute_request(request))
end | [
"def",
"update",
"(",
"key",
",",
"value",
")",
"request_data",
"=",
"{",
":key",
"=>",
"key",
",",
":value",
"=>",
"value",
"}",
"request_data",
"[",
":expire",
"]",
"=",
"@expire",
"if",
"@expire",
"request",
"=",
"prepare_request",
":PUT",
",",
"reque... | Update data stored at a given SAM key
@param [String] key of the data to update
@param [String, Hash, Array] data to be stored at the key
@return [Response] response object holding the file and some metadata
@raise [NSISam::Errors::Client::KeyNotFoundError] when the key doesn't exists
@raise [NSISam::Errors::Cli... | [
"Update",
"data",
"stored",
"at",
"a",
"given",
"SAM",
"key"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L136-L141 |
8,551 | nsi-iff/nsisam-ruby | lib/nsisam/client.rb | NSISam.Client.update_file | def update_file(key, type=:file, new_content, filename)
encoded = Base64.encode64(new_content)
update(key, type => encoded, filename: filename)
end | ruby | def update_file(key, type=:file, new_content, filename)
encoded = Base64.encode64(new_content)
update(key, type => encoded, filename: filename)
end | [
"def",
"update_file",
"(",
"key",
",",
"type",
"=",
":file",
",",
"new_content",
",",
"filename",
")",
"encoded",
"=",
"Base64",
".",
"encode64",
"(",
"new_content",
")",
"update",
"(",
"key",
",",
"type",
"=>",
"encoded",
",",
"filename",
":",
"filename... | Update file stored at a given SAM key
@param [String] key of the file to update
@param [Symbol] type of the file to be recovered. Can be either :doc and :video.
@param [String] new_content content of the new file
@return [Response] response object holding the file and some metadata
@raise [NSISam::Errors::Client... | [
"Update",
"file",
"stored",
"at",
"a",
"given",
"SAM",
"key"
] | 344725ba119899f4ac5b869d31f555a2e365cadb | https://github.com/nsi-iff/nsisam-ruby/blob/344725ba119899f4ac5b869d31f555a2e365cadb/lib/nsisam/client.rb#L157-L160 |
8,552 | finn-francis/ruby-edit | lib/ruby_edit/cli.rb | RubyEdit.CLI.configure | def configure(*)
if options[:help]
invoke :help, ['configure']
else
require_relative 'commands/configure'
RubyEdit::Commands::Configure.new(options).execute
end
end | ruby | def configure(*)
if options[:help]
invoke :help, ['configure']
else
require_relative 'commands/configure'
RubyEdit::Commands::Configure.new(options).execute
end
end | [
"def",
"configure",
"(",
"*",
")",
"if",
"options",
"[",
":help",
"]",
"invoke",
":help",
",",
"[",
"'configure'",
"]",
"else",
"require_relative",
"'commands/configure'",
"RubyEdit",
"::",
"Commands",
"::",
"Configure",
".",
"new",
"(",
"options",
")",
".",... | Set and view configuration options
# editor [-e --editor]
ruby-edit configure --editor
=> vim
ruby-edit configure --editor emacs
=> emacs
# grep options [-o --grep_options]
ruby-edit configure --grep_options
=> irn
ruby-edit configure --grep_options h
=> Hn | [
"Set",
"and",
"view",
"configuration",
"options"
] | 90022f4de01b420f5321f12c490566d0a1e19a29 | https://github.com/finn-francis/ruby-edit/blob/90022f4de01b420f5321f12c490566d0a1e19a29/lib/ruby_edit/cli.rb#L44-L51 |
8,553 | redding/dassets | lib/dassets/server.rb | Dassets.Server.call! | def call!(env)
if (request = Request.new(env)).for_asset_file?
Response.new(env, request.asset_file).to_rack
else
@app.call(env)
end
end | ruby | def call!(env)
if (request = Request.new(env)).for_asset_file?
Response.new(env, request.asset_file).to_rack
else
@app.call(env)
end
end | [
"def",
"call!",
"(",
"env",
")",
"if",
"(",
"request",
"=",
"Request",
".",
"new",
"(",
"env",
")",
")",
".",
"for_asset_file?",
"Response",
".",
"new",
"(",
"env",
",",
"request",
".",
"asset_file",
")",
".",
"to_rack",
"else",
"@app",
".",
"call",
... | The real Rack call interface.
if an asset file is being requested, this is an endpoint - otherwise, call
on up to the app as normal | [
"The",
"real",
"Rack",
"call",
"interface",
".",
"if",
"an",
"asset",
"file",
"is",
"being",
"requested",
"this",
"is",
"an",
"endpoint",
"-",
"otherwise",
"call",
"on",
"up",
"to",
"the",
"app",
"as",
"normal"
] | d63ea7c6200057c932079493df26c647fdac8957 | https://github.com/redding/dassets/blob/d63ea7c6200057c932079493df26c647fdac8957/lib/dassets/server.rb#L28-L34 |
8,554 | medcat/brandish | lib/brandish/path_set.rb | Brandish.PathSet.find_all | def find_all(short, options = {})
return to_enum(:find_all, short, options) unless block_given?
short = ::Pathname.new(short)
options = DEFAULT_FIND_OPTIONS.merge(options)
@paths.reverse.each do |path|
joined = path_join(path, short, options)
yield joined if (options[:file] && j... | ruby | def find_all(short, options = {})
return to_enum(:find_all, short, options) unless block_given?
short = ::Pathname.new(short)
options = DEFAULT_FIND_OPTIONS.merge(options)
@paths.reverse.each do |path|
joined = path_join(path, short, options)
yield joined if (options[:file] && j... | [
"def",
"find_all",
"(",
"short",
",",
"options",
"=",
"{",
"}",
")",
"return",
"to_enum",
"(",
":find_all",
",",
"short",
",",
"options",
")",
"unless",
"block_given?",
"short",
"=",
"::",
"Pathname",
".",
"new",
"(",
"short",
")",
"options",
"=",
"DEF... | Finds all versions of the short path name in the paths in the path
sets. If no block is given, it returns an enumerable; otherwise, if
a block is given, it yields the joined path if it exists.
@raise NoFileError If no file could be found.
@param short [::String, ::Pathname] The "short" path to resolve.
@param op... | [
"Finds",
"all",
"versions",
"of",
"the",
"short",
"path",
"name",
"in",
"the",
"paths",
"in",
"the",
"path",
"sets",
".",
"If",
"no",
"block",
"is",
"given",
"it",
"returns",
"an",
"enumerable",
";",
"otherwise",
"if",
"a",
"block",
"is",
"given",
"it"... | c63f91dbb356aa0958351ad9bcbdab0c57e7f649 | https://github.com/medcat/brandish/blob/c63f91dbb356aa0958351ad9bcbdab0c57e7f649/lib/brandish/path_set.rb#L142-L153 |
8,555 | rixth/tay | lib/tay/builder.rb | Tay.Builder.get_compiled_file_content | def get_compiled_file_content(path)
begin
Tilt.new(path.to_s).render({}, {
:spec => spec
})
rescue RuntimeError
File.read(path)
end
end | ruby | def get_compiled_file_content(path)
begin
Tilt.new(path.to_s).render({}, {
:spec => spec
})
rescue RuntimeError
File.read(path)
end
end | [
"def",
"get_compiled_file_content",
"(",
"path",
")",
"begin",
"Tilt",
".",
"new",
"(",
"path",
".",
"to_s",
")",
".",
"render",
"(",
"{",
"}",
",",
"{",
":spec",
"=>",
"spec",
"}",
")",
"rescue",
"RuntimeError",
"File",
".",
"read",
"(",
"path",
")"... | Given a path, run it through tilt and return the compiled version.
If there's no known engine for it, just return the content verbatim.
If we know the type buy are missing the gem, raise an exception. | [
"Given",
"a",
"path",
"run",
"it",
"through",
"tilt",
"and",
"return",
"the",
"compiled",
"version",
".",
"If",
"there",
"s",
"no",
"known",
"engine",
"for",
"it",
"just",
"return",
"the",
"content",
"verbatim",
".",
"If",
"we",
"know",
"the",
"type",
... | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/builder.rb#L56-L64 |
8,556 | rixth/tay | lib/tay/builder.rb | Tay.Builder.simple_compile_directory | def simple_compile_directory(directory)
if directory.is_a?(String)
# If we just have a single dirname, assume it's under src
from_directory = (directory[/\//] ? '' : 'src/') + directory
directory = {
:from => from_directory,
:as => directory
}
end
... | ruby | def simple_compile_directory(directory)
if directory.is_a?(String)
# If we just have a single dirname, assume it's under src
from_directory = (directory[/\//] ? '' : 'src/') + directory
directory = {
:from => from_directory,
:as => directory
}
end
... | [
"def",
"simple_compile_directory",
"(",
"directory",
")",
"if",
"directory",
".",
"is_a?",
"(",
"String",
")",
"# If we just have a single dirname, assume it's under src",
"from_directory",
"=",
"(",
"directory",
"[",
"/",
"\\/",
"/",
"]",
"?",
"''",
":",
"'src/'",
... | Copy all the files from a directory to the output, compiling
them if they are familiar to us. Does not do any sprocketing. | [
"Copy",
"all",
"the",
"files",
"from",
"a",
"directory",
"to",
"the",
"output",
"compiling",
"them",
"if",
"they",
"are",
"familiar",
"to",
"us",
".",
"Does",
"not",
"do",
"any",
"sprocketing",
"."
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/builder.rb#L75-L107 |
8,557 | rixth/tay | lib/tay/builder.rb | Tay.Builder.compile_files | def compile_files(files)
files.each do |base_path|
# We do this second glob in case the path provided in the tayfile
# references a compiled version
Dir[@base_dir.join('src', base_path + '*')].each do |path|
path = Pathname.new(path).relative_path_from(@base_dir.join('src'))
... | ruby | def compile_files(files)
files.each do |base_path|
# We do this second glob in case the path provided in the tayfile
# references a compiled version
Dir[@base_dir.join('src', base_path + '*')].each do |path|
path = Pathname.new(path).relative_path_from(@base_dir.join('src'))
... | [
"def",
"compile_files",
"(",
"files",
")",
"files",
".",
"each",
"do",
"|",
"base_path",
"|",
"# We do this second glob in case the path provided in the tayfile",
"# references a compiled version",
"Dir",
"[",
"@base_dir",
".",
"join",
"(",
"'src'",
",",
"base_path",
"+... | Process all the files in the directory through sprockets before writing
them to the output directory | [
"Process",
"all",
"the",
"files",
"in",
"the",
"directory",
"through",
"sprockets",
"before",
"writing",
"them",
"to",
"the",
"output",
"directory"
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/builder.rb#L112-L133 |
8,558 | rixth/tay | lib/tay/builder.rb | Tay.Builder.write_manifest | def write_manifest
generator = ManifestGenerator.new(spec)
File.open(@output_dir.join('manifest.json'), 'w') do |f|
f.write JSON.pretty_generate(generator.spec_as_json)
end
end | ruby | def write_manifest
generator = ManifestGenerator.new(spec)
File.open(@output_dir.join('manifest.json'), 'w') do |f|
f.write JSON.pretty_generate(generator.spec_as_json)
end
end | [
"def",
"write_manifest",
"generator",
"=",
"ManifestGenerator",
".",
"new",
"(",
"spec",
")",
"File",
".",
"open",
"(",
"@output_dir",
".",
"join",
"(",
"'manifest.json'",
")",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"JSON",
".",
"pret... | Generate the manifest from the spec and write it to disk | [
"Generate",
"the",
"manifest",
"from",
"the",
"spec",
"and",
"write",
"it",
"to",
"disk"
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/builder.rb#L137-L143 |
8,559 | rixth/tay | lib/tay/builder.rb | Tay.Builder.create_sprockets_environment | def create_sprockets_environment
@sprockets = Sprockets::Environment.new
@sprockets.append_path(@base_dir.join('src/javascripts').to_s)
@sprockets.append_path(@base_dir.join('src/templates').to_s)
@sprockets.append_path(@base_dir.join('src/stylesheets').to_s)
@sprockets.append_path(@base_d... | ruby | def create_sprockets_environment
@sprockets = Sprockets::Environment.new
@sprockets.append_path(@base_dir.join('src/javascripts').to_s)
@sprockets.append_path(@base_dir.join('src/templates').to_s)
@sprockets.append_path(@base_dir.join('src/stylesheets').to_s)
@sprockets.append_path(@base_d... | [
"def",
"create_sprockets_environment",
"@sprockets",
"=",
"Sprockets",
"::",
"Environment",
".",
"new",
"@sprockets",
".",
"append_path",
"(",
"@base_dir",
".",
"join",
"(",
"'src/javascripts'",
")",
".",
"to_s",
")",
"@sprockets",
".",
"append_path",
"(",
"@base_... | Set up the sprockets environment for munging all the things | [
"Set",
"up",
"the",
"sprockets",
"environment",
"for",
"munging",
"all",
"the",
"things"
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/builder.rb#L147-L154 |
8,560 | jrobertson/xmpp-agent | lib/xmpp4r-simple.rb | Jabber.Simple.deliver | def deliver(jid, message, type=:chat)
contacts(jid) do |friend|
unless subscribed_to? friend
add(friend.jid)
return deliver_deferred(friend.jid, message, type)
end
if message.kind_of?(Jabber::Message)
msg = message
msg.to = friend.jid
else
... | ruby | def deliver(jid, message, type=:chat)
contacts(jid) do |friend|
unless subscribed_to? friend
add(friend.jid)
return deliver_deferred(friend.jid, message, type)
end
if message.kind_of?(Jabber::Message)
msg = message
msg.to = friend.jid
else
... | [
"def",
"deliver",
"(",
"jid",
",",
"message",
",",
"type",
"=",
":chat",
")",
"contacts",
"(",
"jid",
")",
"do",
"|",
"friend",
"|",
"unless",
"subscribed_to?",
"friend",
"add",
"(",
"friend",
".",
"jid",
")",
"return",
"deliver_deferred",
"(",
"friend",... | Send a message to jabber user jid.
Valid message types are:
* :normal (default): a normal message.
* :chat: a one-to-one chat message.
* :groupchat: a group-chat message.
* :headline: a "headline" message.
* :error: an error message.
If the recipient is not in your contacts list, the message will be... | [
"Send",
"a",
"message",
"to",
"jabber",
"user",
"jid",
"."
] | 9078fa8e05d6c580d082a1cecb6f5ffd9157e12f | https://github.com/jrobertson/xmpp-agent/blob/9078fa8e05d6c580d082a1cecb6f5ffd9157e12f/lib/xmpp4r-simple.rb#L114-L130 |
8,561 | jrobertson/xmpp-agent | lib/xmpp4r-simple.rb | Jabber.Simple.status | def status(presence, message)
@presence = presence
@status_message = message
stat_msg = Presence.new(@presence, @status_message)
send!(stat_msg)
end | ruby | def status(presence, message)
@presence = presence
@status_message = message
stat_msg = Presence.new(@presence, @status_message)
send!(stat_msg)
end | [
"def",
"status",
"(",
"presence",
",",
"message",
")",
"@presence",
"=",
"presence",
"@status_message",
"=",
"message",
"stat_msg",
"=",
"Presence",
".",
"new",
"(",
"@presence",
",",
"@status_message",
")",
"send!",
"(",
"stat_msg",
")",
"end"
] | Set your presence, with a message.
Available values for presence are:
* nil: online.
* :chat: free for chat.
* :away: away from the computer.
* :dnd: do not disturb.
* :xa: extended away.
It's not possible to set an offline status - to do that, disconnect! :-) | [
"Set",
"your",
"presence",
"with",
"a",
"message",
"."
] | 9078fa8e05d6c580d082a1cecb6f5ffd9157e12f | https://github.com/jrobertson/xmpp-agent/blob/9078fa8e05d6c580d082a1cecb6f5ffd9157e12f/lib/xmpp4r-simple.rb#L143-L148 |
8,562 | jrobertson/xmpp-agent | lib/xmpp4r-simple.rb | Jabber.Simple.send! | def send!(msg)
attempts = 0
begin
attempts += 1
client.send(msg)
rescue Errno::EPIPE, IOError => e
sleep 1
disconnect
reconnect
retry unless attempts > 3
raise e
rescue Errno::ECONNRESET => e
sleep (attempts^2) * 60 + 60
dis... | ruby | def send!(msg)
attempts = 0
begin
attempts += 1
client.send(msg)
rescue Errno::EPIPE, IOError => e
sleep 1
disconnect
reconnect
retry unless attempts > 3
raise e
rescue Errno::ECONNRESET => e
sleep (attempts^2) * 60 + 60
dis... | [
"def",
"send!",
"(",
"msg",
")",
"attempts",
"=",
"0",
"begin",
"attempts",
"+=",
"1",
"client",
".",
"send",
"(",
"msg",
")",
"rescue",
"Errno",
"::",
"EPIPE",
",",
"IOError",
"=>",
"e",
"sleep",
"1",
"disconnect",
"reconnect",
"retry",
"unless",
"att... | Send a Jabber stanza over-the-wire. | [
"Send",
"a",
"Jabber",
"stanza",
"over",
"-",
"the",
"-",
"wire",
"."
] | 9078fa8e05d6c580d082a1cecb6f5ffd9157e12f | https://github.com/jrobertson/xmpp-agent/blob/9078fa8e05d6c580d082a1cecb6f5ffd9157e12f/lib/xmpp4r-simple.rb#L327-L345 |
8,563 | jrobertson/xmpp-agent | lib/xmpp4r-simple.rb | Jabber.Simple.deliver_deferred | def deliver_deferred(jid, message, type)
msg = {:to => jid, :message => message, :type => type}
queue(:pending_messages) << [msg]
end | ruby | def deliver_deferred(jid, message, type)
msg = {:to => jid, :message => message, :type => type}
queue(:pending_messages) << [msg]
end | [
"def",
"deliver_deferred",
"(",
"jid",
",",
"message",
",",
"type",
")",
"msg",
"=",
"{",
":to",
"=>",
"jid",
",",
":message",
"=>",
"message",
",",
":type",
"=>",
"type",
"}",
"queue",
"(",
":pending_messages",
")",
"<<",
"[",
"msg",
"]",
"end"
] | Queue messages for delivery once a user has accepted our authorization
request. Works in conjunction with the deferred delivery thread.
You can use this method if you want to manually add friends and still
have the message queued for later delivery. | [
"Queue",
"messages",
"for",
"delivery",
"once",
"a",
"user",
"has",
"accepted",
"our",
"authorization",
"request",
".",
"Works",
"in",
"conjunction",
"with",
"the",
"deferred",
"delivery",
"thread",
"."
] | 9078fa8e05d6c580d082a1cecb6f5ffd9157e12f | https://github.com/jrobertson/xmpp-agent/blob/9078fa8e05d6c580d082a1cecb6f5ffd9157e12f/lib/xmpp4r-simple.rb#L364-L367 |
8,564 | jrobertson/xmpp-agent | lib/xmpp4r-simple.rb | Jabber.Simple.start_deferred_delivery_thread | def start_deferred_delivery_thread #:nodoc:
Thread.new {
loop {
messages = [queue(:pending_messages).pop].flatten
messages.each do |message|
if subscribed_to?(message[:to])
deliver(message[:to], message[:message], message[:type])
else
... | ruby | def start_deferred_delivery_thread #:nodoc:
Thread.new {
loop {
messages = [queue(:pending_messages).pop].flatten
messages.each do |message|
if subscribed_to?(message[:to])
deliver(message[:to], message[:message], message[:type])
else
... | [
"def",
"start_deferred_delivery_thread",
"#:nodoc:",
"Thread",
".",
"new",
"{",
"loop",
"{",
"messages",
"=",
"[",
"queue",
"(",
":pending_messages",
")",
".",
"pop",
"]",
".",
"flatten",
"messages",
".",
"each",
"do",
"|",
"message",
"|",
"if",
"subscribed_... | This thread facilitates the delivery of messages to users who haven't yet
accepted an invitation from us. When we attempt to deliver a message, if
the user hasn't subscribed, we place the message in a queue for later
delivery. Once a user has accepted our authorization request, we deliver
any messages that have bee... | [
"This",
"thread",
"facilitates",
"the",
"delivery",
"of",
"messages",
"to",
"users",
"who",
"haven",
"t",
"yet",
"accepted",
"an",
"invitation",
"from",
"us",
".",
"When",
"we",
"attempt",
"to",
"deliver",
"a",
"message",
"if",
"the",
"user",
"hasn",
"t",
... | 9078fa8e05d6c580d082a1cecb6f5ffd9157e12f | https://github.com/jrobertson/xmpp-agent/blob/9078fa8e05d6c580d082a1cecb6f5ffd9157e12f/lib/xmpp4r-simple.rb#L461-L474 |
8,565 | fenton-project/fenton_shell | lib/fenton_shell/key.rb | FentonShell.Key.create | def create(options)
status, body = key_create(options)
if status
save_message('Key': ['created!'])
true
else
save_message(body)
false
end
end | ruby | def create(options)
status, body = key_create(options)
if status
save_message('Key': ['created!'])
true
else
save_message(body)
false
end
end | [
"def",
"create",
"(",
"options",
")",
"status",
",",
"body",
"=",
"key_create",
"(",
"options",
")",
"if",
"status",
"save_message",
"(",
"'Key'",
":",
"[",
"'created!'",
"]",
")",
"true",
"else",
"save_message",
"(",
"body",
")",
"false",
"end",
"end"
] | Creates a new key on the local client
@param options [Hash] fields to send to ssh key pair generation
@return [String] success or failure message | [
"Creates",
"a",
"new",
"key",
"on",
"the",
"local",
"client"
] | 6e1d76186fa7ee7a3be141afad9361e3a3e0ec91 | https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/key.rb#L13-L23 |
8,566 | fenton-project/fenton_shell | lib/fenton_shell/key.rb | FentonShell.Key.key_create | def key_create(options)
ssh_key = key_generation(options)
ssh_private_key_file = options[:private_key]
ssh_public_key_file = "#{ssh_private_key_file}.pub"
# TODO: - add to .fenton/config file
File.write(ssh_private_key_file, ssh_key.private_key)
File.chmod(0o600, ssh_private_key_fil... | ruby | def key_create(options)
ssh_key = key_generation(options)
ssh_private_key_file = options[:private_key]
ssh_public_key_file = "#{ssh_private_key_file}.pub"
# TODO: - add to .fenton/config file
File.write(ssh_private_key_file, ssh_key.private_key)
File.chmod(0o600, ssh_private_key_fil... | [
"def",
"key_create",
"(",
"options",
")",
"ssh_key",
"=",
"key_generation",
"(",
"options",
")",
"ssh_private_key_file",
"=",
"options",
"[",
":private_key",
"]",
"ssh_public_key_file",
"=",
"\"#{ssh_private_key_file}.pub\"",
"# TODO: - add to .fenton/config file",
"File",
... | Sends a post request with json from the command line key
@param options [Hash] fields from fenton command line
@return [Object] true or false
@return [String] message on success or failure | [
"Sends",
"a",
"post",
"request",
"with",
"json",
"from",
"the",
"command",
"line",
"key"
] | 6e1d76186fa7ee7a3be141afad9361e3a3e0ec91 | https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/key.rb#L32-L44 |
8,567 | fenton-project/fenton_shell | lib/fenton_shell/key.rb | FentonShell.Key.key_generation | def key_generation(options)
SSHKey.generate(
type: options[:type],
bits: options[:bits],
comment: 'ssh@fenton_shell',
passphrase: options[:passphrase]
)
end | ruby | def key_generation(options)
SSHKey.generate(
type: options[:type],
bits: options[:bits],
comment: 'ssh@fenton_shell',
passphrase: options[:passphrase]
)
end | [
"def",
"key_generation",
"(",
"options",
")",
"SSHKey",
".",
"generate",
"(",
"type",
":",
"options",
"[",
":type",
"]",
",",
"bits",
":",
"options",
"[",
":bits",
"]",
",",
"comment",
":",
"'ssh@fenton_shell'",
",",
"passphrase",
":",
"options",
"[",
":... | Generates the SSH key pair
@param options [Hash] fields from fenton command line
@return [String] ssh key pair object created from the options hash | [
"Generates",
"the",
"SSH",
"key",
"pair"
] | 6e1d76186fa7ee7a3be141afad9361e3a3e0ec91 | https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/key.rb#L50-L57 |
8,568 | conversation/raca | lib/raca/containers.rb | Raca.Containers.metadata | def metadata
log "retrieving containers metadata from #{storage_path}"
response = storage_client.head(storage_path)
{
:containers => response["X-Account-Container-Count"].to_i,
:objects => response["X-Account-Object-Count"].to_i,
:bytes => response["X-Account-Bytes-U... | ruby | def metadata
log "retrieving containers metadata from #{storage_path}"
response = storage_client.head(storage_path)
{
:containers => response["X-Account-Container-Count"].to_i,
:objects => response["X-Account-Object-Count"].to_i,
:bytes => response["X-Account-Bytes-U... | [
"def",
"metadata",
"log",
"\"retrieving containers metadata from #{storage_path}\"",
"response",
"=",
"storage_client",
".",
"head",
"(",
"storage_path",
")",
"{",
":containers",
"=>",
"response",
"[",
"\"X-Account-Container-Count\"",
"]",
".",
"to_i",
",",
":objects",
... | Return metadata on all containers | [
"Return",
"metadata",
"on",
"all",
"containers"
] | fa69dfde22359cc0e06f655055be4eadcc7019c0 | https://github.com/conversation/raca/blob/fa69dfde22359cc0e06f655055be4eadcc7019c0/lib/raca/containers.rb#L24-L32 |
8,569 | celldee/ffi-rxs | lib/ffi-rxs/context.rb | XS.Context.setctxopt | def setctxopt name, value
length = 4
pointer = LibC.malloc length
pointer.write_int value
rc = LibXS.xs_setctxopt @context, name, pointer, length
LibC.free(pointer) unless pointer.nil? || pointer.null?
rc
end | ruby | def setctxopt name, value
length = 4
pointer = LibC.malloc length
pointer.write_int value
rc = LibXS.xs_setctxopt @context, name, pointer, length
LibC.free(pointer) unless pointer.nil? || pointer.null?
rc
end | [
"def",
"setctxopt",
"name",
",",
"value",
"length",
"=",
"4",
"pointer",
"=",
"LibC",
".",
"malloc",
"length",
"pointer",
".",
"write_int",
"value",
"rc",
"=",
"LibXS",
".",
"xs_setctxopt",
"@context",
",",
"name",
",",
"pointer",
",",
"length",
"LibC",
... | Initialize context object
Sets options on a context.
It is recommended to use the default for +io_threads+
(which is 1) since most programs will not saturate I/O.
The rule of thumb is to make io_threads equal to the number
of gigabits per second that the application will produce.
The io_threads number specifie... | [
"Initialize",
"context",
"object",
"Sets",
"options",
"on",
"a",
"context",
"."
] | 95378f3a5e5b5b3f1f726a9a1620f41ab4ee7f0e | https://github.com/celldee/ffi-rxs/blob/95378f3a5e5b5b3f1f726a9a1620f41ab4ee7f0e/lib/ffi-rxs/context.rb#L79-L87 |
8,570 | celldee/ffi-rxs | lib/ffi-rxs/context.rb | XS.Context.socket | def socket type
sock = nil
begin
sock = Socket.new @context, type
rescue ContextError => e
sock = nil
end
sock
end | ruby | def socket type
sock = nil
begin
sock = Socket.new @context, type
rescue ContextError => e
sock = nil
end
sock
end | [
"def",
"socket",
"type",
"sock",
"=",
"nil",
"begin",
"sock",
"=",
"Socket",
".",
"new",
"@context",
",",
"type",
"rescue",
"ContextError",
"=>",
"e",
"sock",
"=",
"nil",
"end",
"sock",
"end"
] | Allocates a socket for context
@param [Constant] type
One of @XS::REQ@, @XS::REP@, @XS::PUB@, @XS::SUB@, @XS::PAIR@,
@XS::PULL@, @XS::PUSH@, @XS::DEALER@, or @XS::ROUTER@
@return [Socket] when the allocation succeeds
@return nil when call fails | [
"Allocates",
"a",
"socket",
"for",
"context"
] | 95378f3a5e5b5b3f1f726a9a1620f41ab4ee7f0e | https://github.com/celldee/ffi-rxs/blob/95378f3a5e5b5b3f1f726a9a1620f41ab4ee7f0e/lib/ffi-rxs/context.rb#L116-L125 |
8,571 | parrish/attention | lib/attention/instance.rb | Attention.Instance.publish | def publish
publisher.publish('instance', added: info) do |redis|
redis.setex "instance_#{ @id }", Attention.options[:ttl], JSON.dump(info)
end
heartbeat
end | ruby | def publish
publisher.publish('instance', added: info) do |redis|
redis.setex "instance_#{ @id }", Attention.options[:ttl], JSON.dump(info)
end
heartbeat
end | [
"def",
"publish",
"publisher",
".",
"publish",
"(",
"'instance'",
",",
"added",
":",
"info",
")",
"do",
"|",
"redis",
"|",
"redis",
".",
"setex",
"\"instance_#{ @id }\"",
",",
"Attention",
".",
"options",
"[",
":ttl",
"]",
",",
"JSON",
".",
"dump",
"(",
... | Creates an Instance
@param ip [String] Optionally override the IP of the server
@param port [Fixnum, Numeric] Optionally specify the port of the server
Publishes this server and starts the {#heartbeat} | [
"Creates",
"an",
"Instance"
] | ff5bd780b946636ba0e22f66bae3fb41b9c4353d | https://github.com/parrish/attention/blob/ff5bd780b946636ba0e22f66bae3fb41b9c4353d/lib/attention/instance.rb#L42-L47 |
8,572 | elight/coulda_web_steps | lib/coulda_web_steps.rb | Coulda.WebSteps.given_a | def given_a(factory_name, args = {})
Given "a #{factory_name} #{humanize args}" do
args.each do |key, value|
if value.is_a? Symbol
instance_var_named_value = instance_variable_get("@#{value}")
args[key] = instance_var_named_value if instance_var_named_value
end
... | ruby | def given_a(factory_name, args = {})
Given "a #{factory_name} #{humanize args}" do
args.each do |key, value|
if value.is_a? Symbol
instance_var_named_value = instance_variable_get("@#{value}")
args[key] = instance_var_named_value if instance_var_named_value
end
... | [
"def",
"given_a",
"(",
"factory_name",
",",
"args",
"=",
"{",
"}",
")",
"Given",
"\"a #{factory_name} #{humanize args}\"",
"do",
"args",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"value",
".",
"is_a?",
"Symbol",
"instance_var_named_value",
"=",
... | Creates an object using a factory_girl factory and creates a Given step that reads like
"Given a gi_joe with a name of 'Blowtorch' and habit of 'swearing'"
@param factory_name A Symbol or String for the name of the factory_girl factory to use
@param args Arguments to supply to the *factory_name* factory_girl factory | [
"Creates",
"an",
"object",
"using",
"a",
"factory_girl",
"factory",
"and",
"creates",
"a",
"Given",
"step",
"that",
"reads",
"like",
"Given",
"a",
"gi_joe",
"with",
"a",
"name",
"of",
"Blowtorch",
"and",
"habit",
"of",
"swearing"
] | 0926325a105983351d8865fbb40751e5f3fa3431 | https://github.com/elight/coulda_web_steps/blob/0926325a105983351d8865fbb40751e5f3fa3431/lib/coulda_web_steps.rb#L10-L21 |
8,573 | octoai/gem-octocore-mongo | lib/octocore-mongo/models/enterprise.rb | Octo.Enterprise.setup_notification_categories | def setup_notification_categories
templates = Octo.get_config(:push_templates)
if templates
templates.each do |t|
args = {
enterprise_id: self._id,
category_type: t[:name],
template_text: t[:text],
active: true
}
Octo::Tem... | ruby | def setup_notification_categories
templates = Octo.get_config(:push_templates)
if templates
templates.each do |t|
args = {
enterprise_id: self._id,
category_type: t[:name],
template_text: t[:text],
active: true
}
Octo::Tem... | [
"def",
"setup_notification_categories",
"templates",
"=",
"Octo",
".",
"get_config",
"(",
":push_templates",
")",
"if",
"templates",
"templates",
".",
"each",
"do",
"|",
"t",
"|",
"args",
"=",
"{",
"enterprise_id",
":",
"self",
".",
"_id",
",",
"category_type"... | Setup the notification categories for the enterprise | [
"Setup",
"the",
"notification",
"categories",
"for",
"the",
"enterprise"
] | bf7fa833fd7e08947697d0341ab5e80e89c8d05a | https://github.com/octoai/gem-octocore-mongo/blob/bf7fa833fd7e08947697d0341ab5e80e89c8d05a/lib/octocore-mongo/models/enterprise.rb#L36-L50 |
8,574 | octoai/gem-octocore-mongo | lib/octocore-mongo/models/enterprise.rb | Octo.Enterprise.setup_intelligent_segments | def setup_intelligent_segments
segments = Octo.get_config(:intelligent_segments)
if segments
segments.each do |seg|
args = {
enterprise_id: self._id,
name: seg[:name],
type: seg[:type].constantize,
dimensions: seg[:dimensions].collect(&:const... | ruby | def setup_intelligent_segments
segments = Octo.get_config(:intelligent_segments)
if segments
segments.each do |seg|
args = {
enterprise_id: self._id,
name: seg[:name],
type: seg[:type].constantize,
dimensions: seg[:dimensions].collect(&:const... | [
"def",
"setup_intelligent_segments",
"segments",
"=",
"Octo",
".",
"get_config",
"(",
":intelligent_segments",
")",
"if",
"segments",
"segments",
".",
"each",
"do",
"|",
"seg",
"|",
"args",
"=",
"{",
"enterprise_id",
":",
"self",
".",
"_id",
",",
"name",
":"... | Setup the intelligent segments for the enterprise | [
"Setup",
"the",
"intelligent",
"segments",
"for",
"the",
"enterprise"
] | bf7fa833fd7e08947697d0341ab5e80e89c8d05a | https://github.com/octoai/gem-octocore-mongo/blob/bf7fa833fd7e08947697d0341ab5e80e89c8d05a/lib/octocore-mongo/models/enterprise.rb#L53-L71 |
8,575 | songgz/fast_ext | app/controllers/fast_ext/sessions_controller.rb | FastExt.SessionsController.forgot_password | def forgot_password
klass = params[:type] || 'FastExt::MPerson'
@user = klass.constantize.where(username:params[:username])
random_password = Array.new(10).map { (65 + rand(58)).chr }.join
@user.password = random_password
@user.save!
#Mailer.create_and_deliver_password_change(@user, ... | ruby | def forgot_password
klass = params[:type] || 'FastExt::MPerson'
@user = klass.constantize.where(username:params[:username])
random_password = Array.new(10).map { (65 + rand(58)).chr }.join
@user.password = random_password
@user.save!
#Mailer.create_and_deliver_password_change(@user, ... | [
"def",
"forgot_password",
"klass",
"=",
"params",
"[",
":type",
"]",
"||",
"'FastExt::MPerson'",
"@user",
"=",
"klass",
".",
"constantize",
".",
"where",
"(",
"username",
":",
"params",
"[",
":username",
"]",
")",
"random_password",
"=",
"Array",
".",
"new",... | assign them a random one and mail it to them, asking them to change it | [
"assign",
"them",
"a",
"random",
"one",
"and",
"mail",
"it",
"to",
"them",
"asking",
"them",
"to",
"change",
"it"
] | 05c6bee1c4f7f841ecf16359af2765751a818c2a | https://github.com/songgz/fast_ext/blob/05c6bee1c4f7f841ecf16359af2765751a818c2a/app/controllers/fast_ext/sessions_controller.rb#L36-L43 |
8,576 | 26fe/sem4r | spec/helpers/rspec_hash.rb | Sem4rSpecHelper.Hash.except | def except(*keys)
self.reject { |k,v| keys.include?(k || k.to_sym) }
end | ruby | def except(*keys)
self.reject { |k,v| keys.include?(k || k.to_sym) }
end | [
"def",
"except",
"(",
"*",
"keys",
")",
"self",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"keys",
".",
"include?",
"(",
"k",
"||",
"k",
".",
"to_sym",
")",
"}",
"end"
] | Filter keys out of a Hash.
{ :a => 1, :b => 2, :c => 3 }.except(:a)
=> { :b => 2, :c => 3 } | [
"Filter",
"keys",
"out",
"of",
"a",
"Hash",
"."
] | 2326404f98b9c2833549fcfda078d39c9954a0fa | https://github.com/26fe/sem4r/blob/2326404f98b9c2833549fcfda078d39c9954a0fa/spec/helpers/rspec_hash.rb#L42-L44 |
8,577 | 26fe/sem4r | spec/helpers/rspec_hash.rb | Sem4rSpecHelper.Hash.only | def only(*keys)
self.reject { |k,v| !keys.include?(k || k.to_sym) }
end | ruby | def only(*keys)
self.reject { |k,v| !keys.include?(k || k.to_sym) }
end | [
"def",
"only",
"(",
"*",
"keys",
")",
"self",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"!",
"keys",
".",
"include?",
"(",
"k",
"||",
"k",
".",
"to_sym",
")",
"}",
"end"
] | Returns a Hash with only the pairs identified by +keys+.
{ :a => 1, :b => 2, :c => 3 }.only(:a)
=> { :a => 1 } | [
"Returns",
"a",
"Hash",
"with",
"only",
"the",
"pairs",
"identified",
"by",
"+",
"keys",
"+",
"."
] | 2326404f98b9c2833549fcfda078d39c9954a0fa | https://github.com/26fe/sem4r/blob/2326404f98b9c2833549fcfda078d39c9954a0fa/spec/helpers/rspec_hash.rb#L62-L64 |
8,578 | medcat/brandish | lib/brandish/configure.rb | Brandish.Configure.build | def build(which = :all)
return to_enum(:build, which) unless block_given?
select_forms(which).each { |f| yield proc { f.build(self) } }
end | ruby | def build(which = :all)
return to_enum(:build, which) unless block_given?
select_forms(which).each { |f| yield proc { f.build(self) } }
end | [
"def",
"build",
"(",
"which",
"=",
":all",
")",
"return",
"to_enum",
"(",
":build",
",",
"which",
")",
"unless",
"block_given?",
"select_forms",
"(",
"which",
")",
".",
"each",
"{",
"|",
"f",
"|",
"yield",
"proc",
"{",
"f",
".",
"build",
"(",
"self",... | Given a set of forms to build, it yields blocks that can be called to
build a form.
@param which [::Symbol, <::Symbol>] If this is `:all`, all of the forms
available are built; otherwise, it only builds the forms whose names
are listed.
@yield [build] Yields for each form that can be built.
@yieldparam build... | [
"Given",
"a",
"set",
"of",
"forms",
"to",
"build",
"it",
"yields",
"blocks",
"that",
"can",
"be",
"called",
"to",
"build",
"a",
"form",
"."
] | c63f91dbb356aa0958351ad9bcbdab0c57e7f649 | https://github.com/medcat/brandish/blob/c63f91dbb356aa0958351ad9bcbdab0c57e7f649/lib/brandish/configure.rb#L133-L136 |
8,579 | medcat/brandish | lib/brandish/configure.rb | Brandish.Configure.roots | def roots
@_roots ||= ::Hash.new do |h, k|
h[k] = nil
h[k] = parse_from(k)
end
end | ruby | def roots
@_roots ||= ::Hash.new do |h, k|
h[k] = nil
h[k] = parse_from(k)
end
end | [
"def",
"roots",
"@_roots",
"||=",
"::",
"Hash",
".",
"new",
"do",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"nil",
"h",
"[",
"k",
"]",
"=",
"parse_from",
"(",
"k",
")",
"end",
"end"
] | A cache for all of the root nodes. This is a regular hash; however, upon
attempt to access an item that isn't already in the hash, it first
parses the file at that item, and stores the result in the hash, returning
the root node in the file. This is to cache files so that they do not
get reparsed multiple times.
... | [
"A",
"cache",
"for",
"all",
"of",
"the",
"root",
"nodes",
".",
"This",
"is",
"a",
"regular",
"hash",
";",
"however",
"upon",
"attempt",
"to",
"access",
"an",
"item",
"that",
"isn",
"t",
"already",
"in",
"the",
"hash",
"it",
"first",
"parses",
"the",
... | c63f91dbb356aa0958351ad9bcbdab0c57e7f649 | https://github.com/medcat/brandish/blob/c63f91dbb356aa0958351ad9bcbdab0c57e7f649/lib/brandish/configure.rb#L163-L168 |
8,580 | medcat/brandish | lib/brandish/configure.rb | Brandish.Configure.parse_from | def parse_from(path, short = path.relative_path_from(root))
contents = path.read
digest = Digest::SHA2.digest(contents)
cache.fetch(digest) do
scanner = Scanner.new(contents, short, options)
parser = Parser.new(scanner.call)
parser.call.tap { |r| cache[digest] = r }
end
... | ruby | def parse_from(path, short = path.relative_path_from(root))
contents = path.read
digest = Digest::SHA2.digest(contents)
cache.fetch(digest) do
scanner = Scanner.new(contents, short, options)
parser = Parser.new(scanner.call)
parser.call.tap { |r| cache[digest] = r }
end
... | [
"def",
"parse_from",
"(",
"path",
",",
"short",
"=",
"path",
".",
"relative_path_from",
"(",
"root",
")",
")",
"contents",
"=",
"path",
".",
"read",
"digest",
"=",
"Digest",
"::",
"SHA2",
".",
"digest",
"(",
"contents",
")",
"cache",
".",
"fetch",
"(",... | Parses a file. This bypasses the filename cache.
@param path [::Pathname] The path to the actual file. This should
respond to `#read`. If this isn't a pathname, the short should be
provided.
@param short [::String] The short name of the file. This is used for
location information.
@return [Parser::Root... | [
"Parses",
"a",
"file",
".",
"This",
"bypasses",
"the",
"filename",
"cache",
"."
] | c63f91dbb356aa0958351ad9bcbdab0c57e7f649 | https://github.com/medcat/brandish/blob/c63f91dbb356aa0958351ad9bcbdab0c57e7f649/lib/brandish/configure.rb#L178-L187 |
8,581 | d11wtq/rdo | lib/rdo/statement.rb | RDO.Statement.execute | def execute(*bind_values)
t = Time.now
@executor.execute(*bind_values).tap do |rs|
rs.info[:execution_time] ||= Time.now - t
if logger.debug?
logger.debug(
"(%.6f) %s %s" % [
rs.execution_time,
command,
("<Bind: #{bind_values.in... | ruby | def execute(*bind_values)
t = Time.now
@executor.execute(*bind_values).tap do |rs|
rs.info[:execution_time] ||= Time.now - t
if logger.debug?
logger.debug(
"(%.6f) %s %s" % [
rs.execution_time,
command,
("<Bind: #{bind_values.in... | [
"def",
"execute",
"(",
"*",
"bind_values",
")",
"t",
"=",
"Time",
".",
"now",
"@executor",
".",
"execute",
"(",
"bind_values",
")",
".",
"tap",
"do",
"|",
"rs",
"|",
"rs",
".",
"info",
"[",
":execution_time",
"]",
"||=",
"Time",
".",
"now",
"-",
"t... | Initialize a new Statement wrapping the given StatementExecutor.
@param [Object] executor
any object that responds to #execute, #connection and #command
Execute the command using the given bind values.
@param [Object...] args
bind parameters to use in place of '?' | [
"Initialize",
"a",
"new",
"Statement",
"wrapping",
"the",
"given",
"StatementExecutor",
"."
] | 91fe0c70cbce9947b879141c0f1001b8c4eeef19 | https://github.com/d11wtq/rdo/blob/91fe0c70cbce9947b879141c0f1001b8c4eeef19/lib/rdo/statement.rb#L33-L50 |
8,582 | ktonon/code_node | spec/fixtures/activerecord/src/active_record/attribute_methods.rb | ActiveRecord.AttributeMethods.attributes | def attributes
attrs = {}
attribute_names.each { |name| attrs[name] = read_attribute(name) }
attrs
end | ruby | def attributes
attrs = {}
attribute_names.each { |name| attrs[name] = read_attribute(name) }
attrs
end | [
"def",
"attributes",
"attrs",
"=",
"{",
"}",
"attribute_names",
".",
"each",
"{",
"|",
"name",
"|",
"attrs",
"[",
"name",
"]",
"=",
"read_attribute",
"(",
"name",
")",
"}",
"attrs",
"end"
] | Returns a hash of all the attributes with their names as keys and the values of the attributes as values. | [
"Returns",
"a",
"hash",
"of",
"all",
"the",
"attributes",
"with",
"their",
"names",
"as",
"keys",
"and",
"the",
"values",
"of",
"the",
"attributes",
"as",
"values",
"."
] | 48d5d1a7442d9cade602be4fb782a1b56c7677f5 | https://github.com/ktonon/code_node/blob/48d5d1a7442d9cade602be4fb782a1b56c7677f5/spec/fixtures/activerecord/src/active_record/attribute_methods.rb#L183-L187 |
8,583 | kachick/declare | lib/declare/assertions.rb | Declare.Assertions.EQL? | def EQL?(sample)
@it.eql?(sample) && sample.eql?(@it) && (@it.hash == sample.hash) &&
({@it => true}.has_key? sample)
end | ruby | def EQL?(sample)
@it.eql?(sample) && sample.eql?(@it) && (@it.hash == sample.hash) &&
({@it => true}.has_key? sample)
end | [
"def",
"EQL?",
"(",
"sample",
")",
"@it",
".",
"eql?",
"(",
"sample",
")",
"&&",
"sample",
".",
"eql?",
"(",
"@it",
")",
"&&",
"(",
"@it",
".",
"hash",
"==",
"sample",
".",
"hash",
")",
"&&",
"(",
"{",
"@it",
"=>",
"true",
"}",
".",
"has_key?",... | true if can use for hash-key | [
"true",
"if",
"can",
"use",
"for",
"hash",
"-",
"key"
] | ea871fd652a2b6664f0c3f49ed9e33b0bbaec2e3 | https://github.com/kachick/declare/blob/ea871fd652a2b6664f0c3f49ed9e33b0bbaec2e3/lib/declare/assertions.rb#L54-L57 |
8,584 | kachick/declare | lib/declare/assertions.rb | Declare.Assertions.CATCH | def CATCH(exception_klass, &block)
block.call
rescue ::Exception
if $!.instance_of? exception_klass
pass
else
failure("Faced a exception, that instance of #{exception_klass}.",
"Faced a exception, that instance of #{$!.class}.", 2)
end
else
failure("... | ruby | def CATCH(exception_klass, &block)
block.call
rescue ::Exception
if $!.instance_of? exception_klass
pass
else
failure("Faced a exception, that instance of #{exception_klass}.",
"Faced a exception, that instance of #{$!.class}.", 2)
end
else
failure("... | [
"def",
"CATCH",
"(",
"exception_klass",
",",
"&",
"block",
")",
"block",
".",
"call",
"rescue",
"::",
"Exception",
"if",
"$!",
".",
"instance_of?",
"exception_klass",
"pass",
"else",
"failure",
"(",
"\"Faced a exception, that instance of #{exception_klass}.\"",
",",
... | pass if occured the error is just a own instance
@param [Class] exception_klass | [
"pass",
"if",
"occured",
"the",
"error",
"is",
"just",
"a",
"own",
"instance"
] | ea871fd652a2b6664f0c3f49ed9e33b0bbaec2e3 | https://github.com/kachick/declare/blob/ea871fd652a2b6664f0c3f49ed9e33b0bbaec2e3/lib/declare/assertions.rb#L238-L252 |
8,585 | vojto/active_harmony | lib/active_harmony/queue_item.rb | ActiveHarmony.QueueItem.process_push | def process_push
factory = "::#{object_type}".constantize
local_object = factory.find(object_local_id)
syncer = factory.synchronizer
syncer.push_object(local_object)
self.state = 'done'
self.save
end | ruby | def process_push
factory = "::#{object_type}".constantize
local_object = factory.find(object_local_id)
syncer = factory.synchronizer
syncer.push_object(local_object)
self.state = 'done'
self.save
end | [
"def",
"process_push",
"factory",
"=",
"\"::#{object_type}\"",
".",
"constantize",
"local_object",
"=",
"factory",
".",
"find",
"(",
"object_local_id",
")",
"syncer",
"=",
"factory",
".",
"synchronizer",
"syncer",
".",
"push_object",
"(",
"local_object",
")",
"sel... | Processes queued item of type push | [
"Processes",
"queued",
"item",
"of",
"type",
"push"
] | 03e5c67ea7a1f986c729001c4fec944bf116640f | https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/queue_item.rb#L27-L35 |
8,586 | vojto/active_harmony | lib/active_harmony/queue_item.rb | ActiveHarmony.QueueItem.process_pull | def process_pull
factory = "::#{object_type}".constantize
syncer = factory.synchronizer
syncer.pull_object(self.object_remote_id)
self.state = 'done'
self.save
end | ruby | def process_pull
factory = "::#{object_type}".constantize
syncer = factory.synchronizer
syncer.pull_object(self.object_remote_id)
self.state = 'done'
self.save
end | [
"def",
"process_pull",
"factory",
"=",
"\"::#{object_type}\"",
".",
"constantize",
"syncer",
"=",
"factory",
".",
"synchronizer",
"syncer",
".",
"pull_object",
"(",
"self",
".",
"object_remote_id",
")",
"self",
".",
"state",
"=",
"'done'",
"self",
".",
"save",
... | Processes queued item of type pull | [
"Processes",
"queued",
"item",
"of",
"type",
"pull"
] | 03e5c67ea7a1f986c729001c4fec944bf116640f | https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/queue_item.rb#L39-L46 |
8,587 | elgalu/strongly_typed | lib/strongly_typed/attributes.rb | StronglyTyped.Attributes.attribute | def attribute(name, type=Object)
name = name.to_sym #normalize
raise NameError, "attribute `#{name}` already created" if members.include?(name)
raise TypeError, "second argument, type, must be a Class but got `#{type.inspect}` insted" unless type.is_a?(Class)
raise TypeError, "directly converti... | ruby | def attribute(name, type=Object)
name = name.to_sym #normalize
raise NameError, "attribute `#{name}` already created" if members.include?(name)
raise TypeError, "second argument, type, must be a Class but got `#{type.inspect}` insted" unless type.is_a?(Class)
raise TypeError, "directly converti... | [
"def",
"attribute",
"(",
"name",
",",
"type",
"=",
"Object",
")",
"name",
"=",
"name",
".",
"to_sym",
"#normalize",
"raise",
"NameError",
",",
"\"attribute `#{name}` already created\"",
"if",
"members",
".",
"include?",
"(",
"name",
")",
"raise",
"TypeError",
... | Create attribute accesors for the included class
Also validations and coercions for the type specified
@param [Symbol] name the accessor name
@param [Class] type the class type to use for validations and coercions
@example
class Person
include StronglyTyped::Model
attribute :id, Integer
attri... | [
"Create",
"attribute",
"accesors",
"for",
"the",
"included",
"class",
"Also",
"validations",
"and",
"coercions",
"for",
"the",
"type",
"specified"
] | b779ec9fe7bde28608a8a7022b28ef322fcdcebd | https://github.com/elgalu/strongly_typed/blob/b779ec9fe7bde28608a8a7022b28ef322fcdcebd/lib/strongly_typed/attributes.rb#L22-L30 |
8,588 | elgalu/strongly_typed | lib/strongly_typed/attributes.rb | StronglyTyped.Attributes.new_attribute | def new_attribute(name, type)
attributes[name] = type
define_attr_reader(name)
define_attr_writer(name, type)
name
end | ruby | def new_attribute(name, type)
attributes[name] = type
define_attr_reader(name)
define_attr_writer(name, type)
name
end | [
"def",
"new_attribute",
"(",
"name",
",",
"type",
")",
"attributes",
"[",
"name",
"]",
"=",
"type",
"define_attr_reader",
"(",
"name",
")",
"define_attr_writer",
"(",
"name",
",",
"type",
")",
"name",
"end"
] | Add new attribute for the tiny object modeled
@param [Symbol] name the attribute name
@param [Class] type the class type
@private | [
"Add",
"new",
"attribute",
"for",
"the",
"tiny",
"object",
"modeled"
] | b779ec9fe7bde28608a8a7022b28ef322fcdcebd | https://github.com/elgalu/strongly_typed/blob/b779ec9fe7bde28608a8a7022b28ef322fcdcebd/lib/strongly_typed/attributes.rb#L54-L59 |
8,589 | elgalu/strongly_typed | lib/strongly_typed/attributes.rb | StronglyTyped.Attributes.define_attr_writer | def define_attr_writer(name, type)
define_method("#{name}=") do |value|
unless value.kind_of?(type)
value = coerce(value, to: type)
unless value.kind_of?(type)
raise TypeError, "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead"
... | ruby | def define_attr_writer(name, type)
define_method("#{name}=") do |value|
unless value.kind_of?(type)
value = coerce(value, to: type)
unless value.kind_of?(type)
raise TypeError, "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead"
... | [
"def",
"define_attr_writer",
"(",
"name",
",",
"type",
")",
"define_method",
"(",
"\"#{name}=\"",
")",
"do",
"|",
"value",
"|",
"unless",
"value",
".",
"kind_of?",
"(",
"type",
")",
"value",
"=",
"coerce",
"(",
"value",
",",
"to",
":",
"type",
")",
"un... | Define attr_writer method for the new attribute
with the added feature of validations and coercions.
@param [Symbol] name the attribute name
@param [Class] type the class type
@raise [TypeError] if unable to coerce the value
@private | [
"Define",
"attr_writer",
"method",
"for",
"the",
"new",
"attribute",
"with",
"the",
"added",
"feature",
"of",
"validations",
"and",
"coercions",
"."
] | b779ec9fe7bde28608a8a7022b28ef322fcdcebd | https://github.com/elgalu/strongly_typed/blob/b779ec9fe7bde28608a8a7022b28ef322fcdcebd/lib/strongly_typed/attributes.rb#L81-L91 |
8,590 | bradfeehan/derelict | lib/derelict/virtual_machine.rb | Derelict.VirtualMachine.validate! | def validate!
logger.debug "Starting validation for #{description}"
raise NotFound.new name, connection unless exists?
logger.info "Successfully validated #{description}"
self
end | ruby | def validate!
logger.debug "Starting validation for #{description}"
raise NotFound.new name, connection unless exists?
logger.info "Successfully validated #{description}"
self
end | [
"def",
"validate!",
"logger",
".",
"debug",
"\"Starting validation for #{description}\"",
"raise",
"NotFound",
".",
"new",
"name",
",",
"connection",
"unless",
"exists?",
"logger",
".",
"info",
"\"Successfully validated #{description}\"",
"self",
"end"
] | Initializes a new VirtualMachine for a connection and name
* connection: The +Derelict::Connection+ to use to manipulate
the VirtualMachine instance
* name: The name of the virtual machine, used when
communicating with the connection)
Validates the data used for this conn... | [
"Initializes",
"a",
"new",
"VirtualMachine",
"for",
"a",
"connection",
"and",
"name"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/virtual_machine.rb#L44-L49 |
8,591 | bradfeehan/derelict | lib/derelict/virtual_machine.rb | Derelict.VirtualMachine.execute! | def execute!(command, options)
# Build up the arguments to pass to connection.execute!
arguments = [command, name, *arguments_for(command)]
arguments << "--color" if options[:color]
if options[:provider]
arguments << "--provider"
arguments << options[:provider]
... | ruby | def execute!(command, options)
# Build up the arguments to pass to connection.execute!
arguments = [command, name, *arguments_for(command)]
arguments << "--color" if options[:color]
if options[:provider]
arguments << "--provider"
arguments << options[:provider]
... | [
"def",
"execute!",
"(",
"command",
",",
"options",
")",
"# Build up the arguments to pass to connection.execute!",
"arguments",
"=",
"[",
"command",
",",
"name",
",",
"arguments_for",
"(",
"command",
")",
"]",
"arguments",
"<<",
"\"--color\"",
"if",
"options",
"[",
... | Executes a command on the connection for this VM
* command: The command to execute (as a symbol)
* options: A Hash of options, with the following optional keys:
* log: Logs the output of the command if true
(defaults to false)
* log_mode: Controls how commands are logged (on... | [
"Executes",
"a",
"command",
"on",
"the",
"connection",
"for",
"this",
"VM"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/virtual_machine.rb#L142-L161 |
8,592 | hawx/duvet | lib/duvet/cov.rb | Duvet.Cov.total_coverage | def total_coverage
return 0.0 if lines.size.zero?
ran_lines.size.to_f / lines.size.to_f
end | ruby | def total_coverage
return 0.0 if lines.size.zero?
ran_lines.size.to_f / lines.size.to_f
end | [
"def",
"total_coverage",
"return",
"0.0",
"if",
"lines",
".",
"size",
".",
"zero?",
"ran_lines",
".",
"size",
".",
"to_f",
"/",
"lines",
".",
"size",
".",
"to_f",
"end"
] | Gives a real number between 0 and 1 indicating how many lines have been
executed.
@return [Float] lines executed as a fraction | [
"Gives",
"a",
"real",
"number",
"between",
"0",
"and",
"1",
"indicating",
"how",
"many",
"lines",
"have",
"been",
"executed",
"."
] | f1fdcb68742e0fd67e52afe3730b78d3b3a31cfd | https://github.com/hawx/duvet/blob/f1fdcb68742e0fd67e52afe3730b78d3b3a31cfd/lib/duvet/cov.rb#L35-L38 |
8,593 | hawx/duvet | lib/duvet/cov.rb | Duvet.Cov.code_coverage | def code_coverage
return 0.0 if code_lines.size.zero?
ran_lines.size.to_f / code_lines.size.to_f
end | ruby | def code_coverage
return 0.0 if code_lines.size.zero?
ran_lines.size.to_f / code_lines.size.to_f
end | [
"def",
"code_coverage",
"return",
"0.0",
"if",
"code_lines",
".",
"size",
".",
"zero?",
"ran_lines",
".",
"size",
".",
"to_f",
"/",
"code_lines",
".",
"size",
".",
"to_f",
"end"
] | Gives a real number between 0 and 1 indicating how many lines of code have
been executed. It ignores all lines that can not be executed such as
comments.
@return [Float] lines of code executed as a fraction | [
"Gives",
"a",
"real",
"number",
"between",
"0",
"and",
"1",
"indicating",
"how",
"many",
"lines",
"of",
"code",
"have",
"been",
"executed",
".",
"It",
"ignores",
"all",
"lines",
"that",
"can",
"not",
"be",
"executed",
"such",
"as",
"comments",
"."
] | f1fdcb68742e0fd67e52afe3730b78d3b3a31cfd | https://github.com/hawx/duvet/blob/f1fdcb68742e0fd67e52afe3730b78d3b3a31cfd/lib/duvet/cov.rb#L45-L48 |
8,594 | pboling/stackable_flash | lib/stackable_flash/stack_layer.rb | StackableFlash.StackLayer.[]= | def []=(key, value)
if StackableFlash.stacking
super(key,
StackableFlash::FlashStack.new.replace(
value.kind_of?(Array) ?
value :
# Preserves nil values in the result... I suppose that's OK, users can compact if needed :)
Array.new(1, value)
... | ruby | def []=(key, value)
if StackableFlash.stacking
super(key,
StackableFlash::FlashStack.new.replace(
value.kind_of?(Array) ?
value :
# Preserves nil values in the result... I suppose that's OK, users can compact if needed :)
Array.new(1, value)
... | [
"def",
"[]=",
"(",
"key",
",",
"value",
")",
"if",
"StackableFlash",
".",
"stacking",
"super",
"(",
"key",
",",
"StackableFlash",
"::",
"FlashStack",
".",
"new",
".",
"replace",
"(",
"value",
".",
"kind_of?",
"(",
"Array",
")",
"?",
"value",
":",
"# Pr... | Make an array at the key, while providing a seamless upgrade to existing flashes
Initial set to Array
Principle of least surprise
flash[:notice] = ['message1','message2']
flash[:notice] # => ['message1','message2']
Initial set to String
Principle of least surprise
flash[:notice] = 'original'
flash[:notice] ... | [
"Make",
"an",
"array",
"at",
"the",
"key",
"while",
"providing",
"a",
"seamless",
"upgrade",
"to",
"existing",
"flashes"
] | 9d52a7768c2261a88044bb26fec6defda8e100e7 | https://github.com/pboling/stackable_flash/blob/9d52a7768c2261a88044bb26fec6defda8e100e7/lib/stackable_flash/stack_layer.rb#L45-L59 |
8,595 | rudionrails/little_log_friend | lib/little_log_friend.rb | ActiveSupport.BufferedLogger.add | def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
message = formatter.call(formatter.number_to_severity(severity), Time.now.utc, progname, message)
message = "#{message}\n" unless message[-1] == ?\n
... | ruby | def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
message = formatter.call(formatter.number_to_severity(severity), Time.now.utc, progname, message)
message = "#{message}\n" unless message[-1] == ?\n
... | [
"def",
"add",
"(",
"severity",
",",
"message",
"=",
"nil",
",",
"progname",
"=",
"nil",
",",
"&",
"block",
")",
"return",
"if",
"@level",
">",
"severity",
"message",
"=",
"(",
"message",
"||",
"(",
"block",
"&&",
"block",
".",
"call",
")",
"||",
"p... | We need to overload the add method. Basibally it is the same as the
original one, but we add our own log format to it. | [
"We",
"need",
"to",
"overload",
"the",
"add",
"method",
".",
"Basibally",
"it",
"is",
"the",
"same",
"as",
"the",
"original",
"one",
"but",
"we",
"add",
"our",
"own",
"log",
"format",
"to",
"it",
"."
] | eed4ecadbf4aeff0e7cd7cfb619e6a7695c6bfbd | https://github.com/rudionrails/little_log_friend/blob/eed4ecadbf4aeff0e7cd7cfb619e6a7695c6bfbd/lib/little_log_friend.rb#L49-L57 |
8,596 | colbell/bitsa | lib/bitsa/gmail_contacts_loader.rb | Bitsa.GmailContactsLoader.load_chunk | def load_chunk(client, idx, cache, orig_last_modified)
# last_modified = nil
url = generate_loader_url(idx, orig_last_modified)
feed = client.get(url).to_xml
feed.elements.each('entry') do |entry|
process_entry(cache, entry)
# last_modified = entry.elements['updated'].text
... | ruby | def load_chunk(client, idx, cache, orig_last_modified)
# last_modified = nil
url = generate_loader_url(idx, orig_last_modified)
feed = client.get(url).to_xml
feed.elements.each('entry') do |entry|
process_entry(cache, entry)
# last_modified = entry.elements['updated'].text
... | [
"def",
"load_chunk",
"(",
"client",
",",
"idx",
",",
"cache",
",",
"orig_last_modified",
")",
"# last_modified = nil",
"url",
"=",
"generate_loader_url",
"(",
"idx",
",",
"orig_last_modified",
")",
"feed",
"=",
"client",
".",
"get",
"(",
"url",
")",
".",
"to... | Load the next chuck of data from GMail into the cache.
@param [GData::Client::Contacts] client Connection to GMail.
@param [Integer] idx Index of next piece of data to read from
<tt>client</tt>.
@param [Bitsa::ContacstCache] cache Cache to be updated from GMail.
@param [Datetime] orig_last_mo... | [
"Load",
"the",
"next",
"chuck",
"of",
"data",
"from",
"GMail",
"into",
"the",
"cache",
"."
] | 8b73c4988bde1bf8e64d9cb999164c3e5988dba5 | https://github.com/colbell/bitsa/blob/8b73c4988bde1bf8e64d9cb999164c3e5988dba5/lib/bitsa/gmail_contacts_loader.rb#L72-L82 |
8,597 | colbell/bitsa | lib/bitsa/gmail_contacts_loader.rb | Bitsa.GmailContactsLoader.process_entry | def process_entry(cache, entry)
gmail_id = entry.elements['id'].text
if entry.elements['gd:deleted']
cache.delete(gmail_id)
else
addrs = []
entry.each_element('gd:email') { |a| addrs << a.attributes['address'] }
cache.update(gmail_id, entry.elements['title'].text || '',... | ruby | def process_entry(cache, entry)
gmail_id = entry.elements['id'].text
if entry.elements['gd:deleted']
cache.delete(gmail_id)
else
addrs = []
entry.each_element('gd:email') { |a| addrs << a.attributes['address'] }
cache.update(gmail_id, entry.elements['title'].text || '',... | [
"def",
"process_entry",
"(",
"cache",
",",
"entry",
")",
"gmail_id",
"=",
"entry",
".",
"elements",
"[",
"'id'",
"]",
".",
"text",
"if",
"entry",
".",
"elements",
"[",
"'gd:deleted'",
"]",
"cache",
".",
"delete",
"(",
"gmail_id",
")",
"else",
"addrs",
... | Process a Gmail contact, updating the cache appropriately.
@param [Bitsa::ContacstCache] cache Cache to be updated from GMail.
@param [REXML::Element] entry GMail data for a contact. | [
"Process",
"a",
"Gmail",
"contact",
"updating",
"the",
"cache",
"appropriately",
"."
] | 8b73c4988bde1bf8e64d9cb999164c3e5988dba5 | https://github.com/colbell/bitsa/blob/8b73c4988bde1bf8e64d9cb999164c3e5988dba5/lib/bitsa/gmail_contacts_loader.rb#L88-L97 |
8,598 | colbell/bitsa | lib/bitsa/gmail_contacts_loader.rb | Bitsa.GmailContactsLoader.generate_loader_url | def generate_loader_url(idx, cache_last_modified)
# FIXME: Escape variables
url = "https://www.google.com/m8/feeds/contacts/#{@user}/thin"
url += '?orderby=lastmodified'
url += '&showdeleted=true'
url += "&max-results=#{@fetch_size}"
url += "&start-index=#{idx}"
if cache_last_m... | ruby | def generate_loader_url(idx, cache_last_modified)
# FIXME: Escape variables
url = "https://www.google.com/m8/feeds/contacts/#{@user}/thin"
url += '?orderby=lastmodified'
url += '&showdeleted=true'
url += "&max-results=#{@fetch_size}"
url += "&start-index=#{idx}"
if cache_last_m... | [
"def",
"generate_loader_url",
"(",
"idx",
",",
"cache_last_modified",
")",
"# FIXME: Escape variables",
"url",
"=",
"\"https://www.google.com/m8/feeds/contacts/#{@user}/thin\"",
"url",
"+=",
"'?orderby=lastmodified'",
"url",
"+=",
"'&showdeleted=true'",
"url",
"+=",
"\"&max-res... | Generate the URL to retrieve the next chunk of data from GMail.
@param [Integer] idx Index of next piece of data to read from
<tt>client</tt>.
@param [Datetime] cache_last_modified modification time of last contact
read from GMail | [
"Generate",
"the",
"URL",
"to",
"retrieve",
"the",
"next",
"chunk",
"of",
"data",
"from",
"GMail",
"."
] | 8b73c4988bde1bf8e64d9cb999164c3e5988dba5 | https://github.com/colbell/bitsa/blob/8b73c4988bde1bf8e64d9cb999164c3e5988dba5/lib/bitsa/gmail_contacts_loader.rb#L105-L116 |
8,599 | hannesg/multi_git | lib/multi_git/walkable.rb | MultiGit.Walkable.walk | def walk( mode = :pre, &block )
raise ArgumentError, "Unknown walk mode #{mode.inspect}. Use either :pre, :post or :leaves" unless MODES.include? mode
return to_enum(:walk, mode) unless block
case(mode)
when :pre then walk_pre(&block)
when :post then walk_post(&block)
when :leaves... | ruby | def walk( mode = :pre, &block )
raise ArgumentError, "Unknown walk mode #{mode.inspect}. Use either :pre, :post or :leaves" unless MODES.include? mode
return to_enum(:walk, mode) unless block
case(mode)
when :pre then walk_pre(&block)
when :post then walk_post(&block)
when :leaves... | [
"def",
"walk",
"(",
"mode",
"=",
":pre",
",",
"&",
"block",
")",
"raise",
"ArgumentError",
",",
"\"Unknown walk mode #{mode.inspect}. Use either :pre, :post or :leaves\"",
"unless",
"MODES",
".",
"include?",
"mode",
"return",
"to_enum",
"(",
":walk",
",",
"mode",
")... | works like each, but recursive
@param mode [:pre, :post, :leaves] | [
"works",
"like",
"each",
"but",
"recursive"
] | cb82e66be7d27c3b630610ce3f1385b30811f139 | https://github.com/hannesg/multi_git/blob/cb82e66be7d27c3b630610ce3f1385b30811f139/lib/multi_git/walkable.rb#L12-L20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.