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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
10,100
|
ecssiah/project-euler-cli
|
lib/project_euler_cli/concerns/scraper.rb
|
ProjectEulerCli.Scraper.load_page
|
def load_page(page)
return if Page.visited.include?(page)
html = open("https://projecteuler.net/archives;page=#{page}")
fragment = Nokogiri::HTML(html)
problem_links = fragment.css('#problems_table td a')
i = (page - 1) * Page::LENGTH + 1
problem_links.each do |link|
Problem[i].title = link.text
i += 1
end
Page.visited << page
end
|
ruby
|
def load_page(page)
return if Page.visited.include?(page)
html = open("https://projecteuler.net/archives;page=#{page}")
fragment = Nokogiri::HTML(html)
problem_links = fragment.css('#problems_table td a')
i = (page - 1) * Page::LENGTH + 1
problem_links.each do |link|
Problem[i].title = link.text
i += 1
end
Page.visited << page
end
|
[
"def",
"load_page",
"(",
"page",
")",
"return",
"if",
"Page",
".",
"visited",
".",
"include?",
"(",
"page",
")",
"html",
"=",
"open",
"(",
"\"https://projecteuler.net/archives;page=#{page}\"",
")",
"fragment",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
"problem_links",
"=",
"fragment",
".",
"css",
"(",
"'#problems_table td a'",
")",
"i",
"=",
"(",
"page",
"-",
"1",
")",
"*",
"Page",
"::",
"LENGTH",
"+",
"1",
"problem_links",
".",
"each",
"do",
"|",
"link",
"|",
"Problem",
"[",
"i",
"]",
".",
"title",
"=",
"link",
".",
"text",
"i",
"+=",
"1",
"end",
"Page",
".",
"visited",
"<<",
"page",
"end"
] |
Loads the problem numbers and titles for an individual page of the archive.
|
[
"Loads",
"the",
"problem",
"numbers",
"and",
"titles",
"for",
"an",
"individual",
"page",
"of",
"the",
"archive",
"."
] |
ae6fb1fb516bd9bcf193e3e1f1c82894198fe997
|
https://github.com/ecssiah/project-euler-cli/blob/ae6fb1fb516bd9bcf193e3e1f1c82894198fe997/lib/project_euler_cli/concerns/scraper.rb#L49-L64
|
10,101
|
ecssiah/project-euler-cli
|
lib/project_euler_cli/concerns/scraper.rb
|
ProjectEulerCli.Scraper.load_problem_details
|
def load_problem_details(id)
return unless Problem[id].published.nil?
html = open("https://projecteuler.net/problem=#{id}")
fragment = Nokogiri::HTML(html)
problem_info = fragment.css('div#problem_info span span')
details = problem_info.text.split(';')
Problem[id].published = details[0].strip
Problem[id].solved_by = details[1].strip
# recent problems do not have a difficult rating
Problem[id].difficulty = details[2].strip if id <= Problem.total - 10
end
|
ruby
|
def load_problem_details(id)
return unless Problem[id].published.nil?
html = open("https://projecteuler.net/problem=#{id}")
fragment = Nokogiri::HTML(html)
problem_info = fragment.css('div#problem_info span span')
details = problem_info.text.split(';')
Problem[id].published = details[0].strip
Problem[id].solved_by = details[1].strip
# recent problems do not have a difficult rating
Problem[id].difficulty = details[2].strip if id <= Problem.total - 10
end
|
[
"def",
"load_problem_details",
"(",
"id",
")",
"return",
"unless",
"Problem",
"[",
"id",
"]",
".",
"published",
".",
"nil?",
"html",
"=",
"open",
"(",
"\"https://projecteuler.net/problem=#{id}\"",
")",
"fragment",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
"problem_info",
"=",
"fragment",
".",
"css",
"(",
"'div#problem_info span span'",
")",
"details",
"=",
"problem_info",
".",
"text",
".",
"split",
"(",
"';'",
")",
"Problem",
"[",
"id",
"]",
".",
"published",
"=",
"details",
"[",
"0",
"]",
".",
"strip",
"Problem",
"[",
"id",
"]",
".",
"solved_by",
"=",
"details",
"[",
"1",
"]",
".",
"strip",
"# recent problems do not have a difficult rating",
"Problem",
"[",
"id",
"]",
".",
"difficulty",
"=",
"details",
"[",
"2",
"]",
".",
"strip",
"if",
"id",
"<=",
"Problem",
".",
"total",
"-",
"10",
"end"
] |
Loads the details of an individual problem.
|
[
"Loads",
"the",
"details",
"of",
"an",
"individual",
"problem",
"."
] |
ae6fb1fb516bd9bcf193e3e1f1c82894198fe997
|
https://github.com/ecssiah/project-euler-cli/blob/ae6fb1fb516bd9bcf193e3e1f1c82894198fe997/lib/project_euler_cli/concerns/scraper.rb#L67-L81
|
10,102
|
pwnall/authpwn_rails
|
lib/authpwn_rails/session_mailer.rb
|
Authpwn.SessionMailer.email_verification_email
|
def email_verification_email(token, root_url)
@token = token
@protocol, @host = *root_url.split('://', 2)
@host.slice!(-1) if @host[-1] == ?/
hostname = @host.split(':', 2).first # Strip out any port.
mail to: @token.email,
subject: email_verification_subject(token, hostname, @protocol),
from: email_verification_from(token, hostname, @protocol)
end
|
ruby
|
def email_verification_email(token, root_url)
@token = token
@protocol, @host = *root_url.split('://', 2)
@host.slice!(-1) if @host[-1] == ?/
hostname = @host.split(':', 2).first # Strip out any port.
mail to: @token.email,
subject: email_verification_subject(token, hostname, @protocol),
from: email_verification_from(token, hostname, @protocol)
end
|
[
"def",
"email_verification_email",
"(",
"token",
",",
"root_url",
")",
"@token",
"=",
"token",
"@protocol",
",",
"@host",
"=",
"root_url",
".",
"split",
"(",
"'://'",
",",
"2",
")",
"@host",
".",
"slice!",
"(",
"-",
"1",
")",
"if",
"@host",
"[",
"-",
"1",
"]",
"==",
"?/",
"hostname",
"=",
"@host",
".",
"split",
"(",
"':'",
",",
"2",
")",
".",
"first",
"# Strip out any port.",
"mail",
"to",
":",
"@token",
".",
"email",
",",
"subject",
":",
"email_verification_subject",
"(",
"token",
",",
"hostname",
",",
"@protocol",
")",
",",
"from",
":",
"email_verification_from",
"(",
"token",
",",
"hostname",
",",
"@protocol",
")",
"end"
] |
Creates an e-mail containing a verification token for the e-mail address.
@param [String] token the e-mail confirmation token
@param [String] the application's root URL (e.g. "https://localhost:3000/")
|
[
"Creates",
"an",
"e",
"-",
"mail",
"containing",
"a",
"verification",
"token",
"for",
"the",
"e",
"-",
"mail",
"address",
"."
] |
de3bd612a00025e8dc8296a73abe3acba948db17
|
https://github.com/pwnall/authpwn_rails/blob/de3bd612a00025e8dc8296a73abe3acba948db17/lib/authpwn_rails/session_mailer.rb#L12-L21
|
10,103
|
pwnall/authpwn_rails
|
lib/authpwn_rails/session_mailer.rb
|
Authpwn.SessionMailer.reset_password_email
|
def reset_password_email(email, token, root_url)
@email, @token, @host, @protocol = email, token
@token = token
@protocol, @host = *root_url.split('://', 2)
@host.slice!(-1) if @host[-1] == ?/
hostname = @host.split(':', 2).first # Strip out any port.
mail to: email, from: reset_password_from(token, hostname, @protocol),
subject: reset_password_subject(token, hostname, @protocol)
end
|
ruby
|
def reset_password_email(email, token, root_url)
@email, @token, @host, @protocol = email, token
@token = token
@protocol, @host = *root_url.split('://', 2)
@host.slice!(-1) if @host[-1] == ?/
hostname = @host.split(':', 2).first # Strip out any port.
mail to: email, from: reset_password_from(token, hostname, @protocol),
subject: reset_password_subject(token, hostname, @protocol)
end
|
[
"def",
"reset_password_email",
"(",
"email",
",",
"token",
",",
"root_url",
")",
"@email",
",",
"@token",
",",
"@host",
",",
"@protocol",
"=",
"email",
",",
"token",
"@token",
"=",
"token",
"@protocol",
",",
"@host",
"=",
"root_url",
".",
"split",
"(",
"'://'",
",",
"2",
")",
"@host",
".",
"slice!",
"(",
"-",
"1",
")",
"if",
"@host",
"[",
"-",
"1",
"]",
"==",
"?/",
"hostname",
"=",
"@host",
".",
"split",
"(",
"':'",
",",
"2",
")",
".",
"first",
"# Strip out any port.",
"mail",
"to",
":",
"email",
",",
"from",
":",
"reset_password_from",
"(",
"token",
",",
"hostname",
",",
"@protocol",
")",
",",
"subject",
":",
"reset_password_subject",
"(",
"token",
",",
"hostname",
",",
"@protocol",
")",
"end"
] |
Creates an e-mail containing a password reset token.
@param [String] email the email to send the token to
@param [String] token the password reset token
@param [String] root_url the application's root URL
(e.g. "https://localhost:3000/")
|
[
"Creates",
"an",
"e",
"-",
"mail",
"containing",
"a",
"password",
"reset",
"token",
"."
] |
de3bd612a00025e8dc8296a73abe3acba948db17
|
https://github.com/pwnall/authpwn_rails/blob/de3bd612a00025e8dc8296a73abe3acba948db17/lib/authpwn_rails/session_mailer.rb#L43-L52
|
10,104
|
djlebersilvestre/descendants-loader
|
lib/descendants_loader.rb
|
DescendantsLoader.ClassMethods.load_self_descendants
|
def load_self_descendants
file = ClassFinder.where_is(self)
path = File.expand_path(File.dirname(file))
Dir["#{path}/**/*.rb"].each { |f| load f }
end
|
ruby
|
def load_self_descendants
file = ClassFinder.where_is(self)
path = File.expand_path(File.dirname(file))
Dir["#{path}/**/*.rb"].each { |f| load f }
end
|
[
"def",
"load_self_descendants",
"file",
"=",
"ClassFinder",
".",
"where_is",
"(",
"self",
")",
"path",
"=",
"File",
".",
"expand_path",
"(",
"File",
".",
"dirname",
"(",
"file",
")",
")",
"Dir",
"[",
"\"#{path}/**/*.rb\"",
"]",
".",
"each",
"{",
"|",
"f",
"|",
"load",
"f",
"}",
"end"
] |
Find and load all ruby files under the same directory structure
of the declared class which is including DescendantsLoader module.
This is the trick to put the classes into ObjectSpace and have the
desired behavior of Object.descendants and Object.subclasses.
|
[
"Find",
"and",
"load",
"all",
"ruby",
"files",
"under",
"the",
"same",
"directory",
"structure",
"of",
"the",
"declared",
"class",
"which",
"is",
"including",
"DescendantsLoader",
"module",
"."
] |
5b1fe23b1de3e6d62d20d46f79a80c132d0b165f
|
https://github.com/djlebersilvestre/descendants-loader/blob/5b1fe23b1de3e6d62d20d46f79a80c132d0b165f/lib/descendants_loader.rb#L64-L68
|
10,105
|
ratherblue/renegade
|
lib/renegade/commit_message.rb
|
Renegade.CommitMessage.check_commit_message_length
|
def check_commit_message_length(message)
check_label = 'Commit message length'
if message.length >= @min_length && message.length <= @max_length
Status.report(check_label, true)
else
@errors.push "Commit messages should be between #{@min_length} "\
"and #{@max_length} characters."
Status.report(check_label, false)
end
end
|
ruby
|
def check_commit_message_length(message)
check_label = 'Commit message length'
if message.length >= @min_length && message.length <= @max_length
Status.report(check_label, true)
else
@errors.push "Commit messages should be between #{@min_length} "\
"and #{@max_length} characters."
Status.report(check_label, false)
end
end
|
[
"def",
"check_commit_message_length",
"(",
"message",
")",
"check_label",
"=",
"'Commit message length'",
"if",
"message",
".",
"length",
">=",
"@min_length",
"&&",
"message",
".",
"length",
"<=",
"@max_length",
"Status",
".",
"report",
"(",
"check_label",
",",
"true",
")",
"else",
"@errors",
".",
"push",
"\"Commit messages should be between #{@min_length} \"",
"\"and #{@max_length} characters.\"",
"Status",
".",
"report",
"(",
"check_label",
",",
"false",
")",
"end",
"end"
] |
Check message length
|
[
"Check",
"message",
"length"
] |
b058750979c4510835368fb0dba552e228331a8c
|
https://github.com/ratherblue/renegade/blob/b058750979c4510835368fb0dba552e228331a8c/lib/renegade/commit_message.rb#L25-L35
|
10,106
|
jeremyvdw/disqussion
|
lib/disqussion/client/users.rb
|
Disqussion.Users.follow
|
def follow(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
target = args.first
merge_target_into_options!(target, options)
response = post('users/follow', options)
end
|
ruby
|
def follow(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
target = args.first
merge_target_into_options!(target, options)
response = post('users/follow', options)
end
|
[
"def",
"follow",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"pop",
":",
"{",
"}",
"target",
"=",
"args",
".",
"first",
"merge_target_into_options!",
"(",
"target",
",",
"options",
")",
"response",
"=",
"post",
"(",
"'users/follow'",
",",
"options",
")",
"end"
] |
Follow a user
@accessibility: public key, secret key
@methods: POST
@format: json, jsonp
@authenticated: true
@limited: false
@param target [Integer, String] A Disqus user ID or screen name.
@return [Hashie::Rash] Details on the requested user.
@example Return extended information for 'the88'
Disqussion::Client.follow("the88")
Disqussion::Client.follow(1234) # Same as above
@see: http://disqus.com/api/3.0/users/details.json
|
[
"Follow",
"a",
"user"
] |
5ad1b0325b7630daf41eb59fc8acbcb785cbc387
|
https://github.com/jeremyvdw/disqussion/blob/5ad1b0325b7630daf41eb59fc8acbcb785cbc387/lib/disqussion/client/users.rb#L51-L56
|
10,107
|
jeremyruppel/codependency
|
lib/codependency/parser.rb
|
Codependency.Parser.parse
|
def parse( file )
pattern = PATTERNS[ File.extname( file ) ]
IO.readlines( file ).take_while do |line|
line =~ pattern
end.map { |line| line[ pattern, 1 ] }
end
|
ruby
|
def parse( file )
pattern = PATTERNS[ File.extname( file ) ]
IO.readlines( file ).take_while do |line|
line =~ pattern
end.map { |line| line[ pattern, 1 ] }
end
|
[
"def",
"parse",
"(",
"file",
")",
"pattern",
"=",
"PATTERNS",
"[",
"File",
".",
"extname",
"(",
"file",
")",
"]",
"IO",
".",
"readlines",
"(",
"file",
")",
".",
"take_while",
"do",
"|",
"line",
"|",
"line",
"=~",
"pattern",
"end",
".",
"map",
"{",
"|",
"line",
"|",
"line",
"[",
"pattern",
",",
"1",
"]",
"}",
"end"
] |
Determines a file's dependencies based on the file's extension.
|
[
"Determines",
"a",
"file",
"s",
"dependencies",
"based",
"on",
"the",
"file",
"s",
"extension",
"."
] |
635eddcc0149211e71f89bcaddaa6603aacf942f
|
https://github.com/jeremyruppel/codependency/blob/635eddcc0149211e71f89bcaddaa6603aacf942f/lib/codependency/parser.rb#L12-L18
|
10,108
|
octoai/gem-octocore-cassandra
|
lib/octocore-cassandra/counter.rb
|
Octo.Counter.increment_for
|
def increment_for(obj)
# decide the time of event asap
ts = Time.now.ceil.to_i
if obj.class.ancestors.include?Cequel::Record
args = obj.key_attributes.collect { |k,v| v.to_s }
cache_key = generate_key(ts, obj.class.name, *args)
val = Cequel::Record.redis.get(cache_key)
if val.nil?
val = 1
else
val = val.to_i + 1
end
ttl = (time_window + 1) * 60
# Update a sharded counter
Cequel::Record.redis.setex(cache_key, ttl, val)
# Optionally, update the index
index_key = generate_index_key(ts, obj.class.name, *args)
index_present = Cequel::Record.redis.get(index_key).try(:to_i)
if index_present != 1
Cequel::Record.redis.setex(index_key, ttl, 1)
end
end
end
|
ruby
|
def increment_for(obj)
# decide the time of event asap
ts = Time.now.ceil.to_i
if obj.class.ancestors.include?Cequel::Record
args = obj.key_attributes.collect { |k,v| v.to_s }
cache_key = generate_key(ts, obj.class.name, *args)
val = Cequel::Record.redis.get(cache_key)
if val.nil?
val = 1
else
val = val.to_i + 1
end
ttl = (time_window + 1) * 60
# Update a sharded counter
Cequel::Record.redis.setex(cache_key, ttl, val)
# Optionally, update the index
index_key = generate_index_key(ts, obj.class.name, *args)
index_present = Cequel::Record.redis.get(index_key).try(:to_i)
if index_present != 1
Cequel::Record.redis.setex(index_key, ttl, 1)
end
end
end
|
[
"def",
"increment_for",
"(",
"obj",
")",
"# decide the time of event asap",
"ts",
"=",
"Time",
".",
"now",
".",
"ceil",
".",
"to_i",
"if",
"obj",
".",
"class",
".",
"ancestors",
".",
"include?",
"Cequel",
"::",
"Record",
"args",
"=",
"obj",
".",
"key_attributes",
".",
"collect",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"to_s",
"}",
"cache_key",
"=",
"generate_key",
"(",
"ts",
",",
"obj",
".",
"class",
".",
"name",
",",
"args",
")",
"val",
"=",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"get",
"(",
"cache_key",
")",
"if",
"val",
".",
"nil?",
"val",
"=",
"1",
"else",
"val",
"=",
"val",
".",
"to_i",
"+",
"1",
"end",
"ttl",
"=",
"(",
"time_window",
"+",
"1",
")",
"*",
"60",
"# Update a sharded counter",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"setex",
"(",
"cache_key",
",",
"ttl",
",",
"val",
")",
"# Optionally, update the index",
"index_key",
"=",
"generate_index_key",
"(",
"ts",
",",
"obj",
".",
"class",
".",
"name",
",",
"args",
")",
"index_present",
"=",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"get",
"(",
"index_key",
")",
".",
"try",
"(",
":to_i",
")",
"if",
"index_present",
"!=",
"1",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"setex",
"(",
"index_key",
",",
"ttl",
",",
"1",
")",
"end",
"end",
"end"
] |
Increments the counter for a model.
@param [Object] obj The model instance for whom counter would be
incremented
|
[
"Increments",
"the",
"counter",
"for",
"a",
"model",
"."
] |
c0977dce5ba0eb174ff810f161aba151069935df
|
https://github.com/octoai/gem-octocore-cassandra/blob/c0977dce5ba0eb174ff810f161aba151069935df/lib/octocore-cassandra/counter.rb#L53-L81
|
10,109
|
octoai/gem-octocore-cassandra
|
lib/octocore-cassandra/counter.rb
|
Octo.Counter.aggregate
|
def aggregate(ts = Time.now.floor)
ts = ts.to_i
aggr = {}
# Find all counters from the index
index_key = generate_index_key(ts, '*')
counters = Cequel::Record.redis.keys(index_key)
counters.each do |cnt|
_tmp = cnt.split(SEPARATOR)
_ts = _tmp[2].to_i
aggr[_ts] = {} unless aggr.has_key?(_ts)
clazz = _tmp[3]
_clazz = clazz.constantize
_attrs = _tmp[4.._tmp.length]
args = {}
_clazz.key_column_names.each_with_index do |k, i|
args[k] = _attrs[i]
end
obj = _clazz.public_send(:get_cached, args)
# construct the keys for all counters matching this patter
_attrs << '*'
counters_search_key = generate_key_prefix(_ts, clazz, _attrs)
counter_keys = Cequel::Record.redis.keys(counters_search_key)
counter_keys.each do |c_key|
val = Cequel::Record.redis.get(c_key)
if val
aggr[_ts][obj] = aggr[_ts].fetch(obj, 0) + val.to_i
else
aggr[_ts][obj] = aggr[_ts].fetch(obj, 0) + 1
end
end
end
aggr
end
|
ruby
|
def aggregate(ts = Time.now.floor)
ts = ts.to_i
aggr = {}
# Find all counters from the index
index_key = generate_index_key(ts, '*')
counters = Cequel::Record.redis.keys(index_key)
counters.each do |cnt|
_tmp = cnt.split(SEPARATOR)
_ts = _tmp[2].to_i
aggr[_ts] = {} unless aggr.has_key?(_ts)
clazz = _tmp[3]
_clazz = clazz.constantize
_attrs = _tmp[4.._tmp.length]
args = {}
_clazz.key_column_names.each_with_index do |k, i|
args[k] = _attrs[i]
end
obj = _clazz.public_send(:get_cached, args)
# construct the keys for all counters matching this patter
_attrs << '*'
counters_search_key = generate_key_prefix(_ts, clazz, _attrs)
counter_keys = Cequel::Record.redis.keys(counters_search_key)
counter_keys.each do |c_key|
val = Cequel::Record.redis.get(c_key)
if val
aggr[_ts][obj] = aggr[_ts].fetch(obj, 0) + val.to_i
else
aggr[_ts][obj] = aggr[_ts].fetch(obj, 0) + 1
end
end
end
aggr
end
|
[
"def",
"aggregate",
"(",
"ts",
"=",
"Time",
".",
"now",
".",
"floor",
")",
"ts",
"=",
"ts",
".",
"to_i",
"aggr",
"=",
"{",
"}",
"# Find all counters from the index",
"index_key",
"=",
"generate_index_key",
"(",
"ts",
",",
"'*'",
")",
"counters",
"=",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"keys",
"(",
"index_key",
")",
"counters",
".",
"each",
"do",
"|",
"cnt",
"|",
"_tmp",
"=",
"cnt",
".",
"split",
"(",
"SEPARATOR",
")",
"_ts",
"=",
"_tmp",
"[",
"2",
"]",
".",
"to_i",
"aggr",
"[",
"_ts",
"]",
"=",
"{",
"}",
"unless",
"aggr",
".",
"has_key?",
"(",
"_ts",
")",
"clazz",
"=",
"_tmp",
"[",
"3",
"]",
"_clazz",
"=",
"clazz",
".",
"constantize",
"_attrs",
"=",
"_tmp",
"[",
"4",
"..",
"_tmp",
".",
"length",
"]",
"args",
"=",
"{",
"}",
"_clazz",
".",
"key_column_names",
".",
"each_with_index",
"do",
"|",
"k",
",",
"i",
"|",
"args",
"[",
"k",
"]",
"=",
"_attrs",
"[",
"i",
"]",
"end",
"obj",
"=",
"_clazz",
".",
"public_send",
"(",
":get_cached",
",",
"args",
")",
"# construct the keys for all counters matching this patter",
"_attrs",
"<<",
"'*'",
"counters_search_key",
"=",
"generate_key_prefix",
"(",
"_ts",
",",
"clazz",
",",
"_attrs",
")",
"counter_keys",
"=",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"keys",
"(",
"counters_search_key",
")",
"counter_keys",
".",
"each",
"do",
"|",
"c_key",
"|",
"val",
"=",
"Cequel",
"::",
"Record",
".",
"redis",
".",
"get",
"(",
"c_key",
")",
"if",
"val",
"aggr",
"[",
"_ts",
"]",
"[",
"obj",
"]",
"=",
"aggr",
"[",
"_ts",
"]",
".",
"fetch",
"(",
"obj",
",",
"0",
")",
"+",
"val",
".",
"to_i",
"else",
"aggr",
"[",
"_ts",
"]",
"[",
"obj",
"]",
"=",
"aggr",
"[",
"_ts",
"]",
".",
"fetch",
"(",
"obj",
",",
"0",
")",
"+",
"1",
"end",
"end",
"end",
"aggr",
"end"
] |
Aggregates all the counters available. Aggregation of only time specific
events can be done by passing the `ts` parameter.
@param [Time] ts The time at which aggregation has to be done.
@return [Hash{Fixnum => Hash{ Obj => Fixnum }}] The counts of each object
|
[
"Aggregates",
"all",
"the",
"counters",
"available",
".",
"Aggregation",
"of",
"only",
"time",
"specific",
"events",
"can",
"be",
"done",
"by",
"passing",
"the",
"ts",
"parameter",
"."
] |
c0977dce5ba0eb174ff810f161aba151069935df
|
https://github.com/octoai/gem-octocore-cassandra/blob/c0977dce5ba0eb174ff810f161aba151069935df/lib/octocore-cassandra/counter.rb#L164-L202
|
10,110
|
SpeciesFileGroup/taxonifi
|
lib/taxonifi/model/name.rb
|
Taxonifi.Model::Name.rank=
|
def rank=(value)
r = value.to_s.downcase.strip
if !RANKS.include?(r)
raise NameError, "#{r} is not a valid rank."
end
@rank = r
end
|
ruby
|
def rank=(value)
r = value.to_s.downcase.strip
if !RANKS.include?(r)
raise NameError, "#{r} is not a valid rank."
end
@rank = r
end
|
[
"def",
"rank",
"=",
"(",
"value",
")",
"r",
"=",
"value",
".",
"to_s",
".",
"downcase",
".",
"strip",
"if",
"!",
"RANKS",
".",
"include?",
"(",
"r",
")",
"raise",
"NameError",
",",
"\"#{r} is not a valid rank.\"",
"end",
"@rank",
"=",
"r",
"end"
] |
Set the rank.
|
[
"Set",
"the",
"rank",
"."
] |
100dc94e7ffd378f6a81381c13768e35b2b65bf2
|
https://github.com/SpeciesFileGroup/taxonifi/blob/100dc94e7ffd378f6a81381c13768e35b2b65bf2/lib/taxonifi/model/name.rb#L77-L83
|
10,111
|
SpeciesFileGroup/taxonifi
|
lib/taxonifi/model/name.rb
|
Taxonifi.Model::IcznName.name=
|
def name=(name)
case @rank
when 'superfamily'
raise NameError, "ICZN superfamily name does not end in 'oidae'." if name[-5,5] != 'oidae'
when 'family'
raise NameError, "ICZN family name does not end in 'idae'." if name[-4,4] != 'idae'
when 'subfamily'
raise NameError, "ICZN subfamily name does not end in 'inae'." if name[-4,4] != 'inae'
when 'tribe'
raise NameError, "ICZN tribe name does not end in 'ini'." if name[-3,3] != 'ini'
when 'subtribe'
raise NameError, "ICZN subtribe name does not end in 'ina'." if name[-3,3] != 'ina'
end
@name = name
end
|
ruby
|
def name=(name)
case @rank
when 'superfamily'
raise NameError, "ICZN superfamily name does not end in 'oidae'." if name[-5,5] != 'oidae'
when 'family'
raise NameError, "ICZN family name does not end in 'idae'." if name[-4,4] != 'idae'
when 'subfamily'
raise NameError, "ICZN subfamily name does not end in 'inae'." if name[-4,4] != 'inae'
when 'tribe'
raise NameError, "ICZN tribe name does not end in 'ini'." if name[-3,3] != 'ini'
when 'subtribe'
raise NameError, "ICZN subtribe name does not end in 'ina'." if name[-3,3] != 'ina'
end
@name = name
end
|
[
"def",
"name",
"=",
"(",
"name",
")",
"case",
"@rank",
"when",
"'superfamily'",
"raise",
"NameError",
",",
"\"ICZN superfamily name does not end in 'oidae'.\"",
"if",
"name",
"[",
"-",
"5",
",",
"5",
"]",
"!=",
"'oidae'",
"when",
"'family'",
"raise",
"NameError",
",",
"\"ICZN family name does not end in 'idae'.\"",
"if",
"name",
"[",
"-",
"4",
",",
"4",
"]",
"!=",
"'idae'",
"when",
"'subfamily'",
"raise",
"NameError",
",",
"\"ICZN subfamily name does not end in 'inae'.\"",
"if",
"name",
"[",
"-",
"4",
",",
"4",
"]",
"!=",
"'inae'",
"when",
"'tribe'",
"raise",
"NameError",
",",
"\"ICZN tribe name does not end in 'ini'.\"",
"if",
"name",
"[",
"-",
"3",
",",
"3",
"]",
"!=",
"'ini'",
"when",
"'subtribe'",
"raise",
"NameError",
",",
"\"ICZN subtribe name does not end in 'ina'.\"",
"if",
"name",
"[",
"-",
"3",
",",
"3",
"]",
"!=",
"'ina'",
"end",
"@name",
"=",
"name",
"end"
] |
Set the name, checks for family group restrictions.
|
[
"Set",
"the",
"name",
"checks",
"for",
"family",
"group",
"restrictions",
"."
] |
100dc94e7ffd378f6a81381c13768e35b2b65bf2
|
https://github.com/SpeciesFileGroup/taxonifi/blob/100dc94e7ffd378f6a81381c13768e35b2b65bf2/lib/taxonifi/model/name.rb#L331-L345
|
10,112
|
ktonon/code_node
|
spec/fixtures/activerecord/src/active_record/transactions.rb
|
ActiveRecord.Transactions.rollback_active_record_state!
|
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
IdentityMap.remove(self) if IdentityMap.enabled?
restore_transaction_record_state
raise
ensure
clear_transaction_record_state
end
|
ruby
|
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
IdentityMap.remove(self) if IdentityMap.enabled?
restore_transaction_record_state
raise
ensure
clear_transaction_record_state
end
|
[
"def",
"rollback_active_record_state!",
"remember_transaction_record_state",
"yield",
"rescue",
"Exception",
"IdentityMap",
".",
"remove",
"(",
"self",
")",
"if",
"IdentityMap",
".",
"enabled?",
"restore_transaction_record_state",
"raise",
"ensure",
"clear_transaction_record_state",
"end"
] |
Reset id and @new_record if the transaction rolls back.
|
[
"Reset",
"id",
"and"
] |
48d5d1a7442d9cade602be4fb782a1b56c7677f5
|
https://github.com/ktonon/code_node/blob/48d5d1a7442d9cade602be4fb782a1b56c7677f5/spec/fixtures/activerecord/src/active_record/transactions.rb#L268-L277
|
10,113
|
ktonon/code_node
|
spec/fixtures/activerecord/src/active_record/transactions.rb
|
ActiveRecord.Transactions.rolledback!
|
def rolledback!(force_restore_state = false) #:nodoc:
run_callbacks :rollback
ensure
IdentityMap.remove(self) if IdentityMap.enabled?
restore_transaction_record_state(force_restore_state)
end
|
ruby
|
def rolledback!(force_restore_state = false) #:nodoc:
run_callbacks :rollback
ensure
IdentityMap.remove(self) if IdentityMap.enabled?
restore_transaction_record_state(force_restore_state)
end
|
[
"def",
"rolledback!",
"(",
"force_restore_state",
"=",
"false",
")",
"#:nodoc:",
"run_callbacks",
":rollback",
"ensure",
"IdentityMap",
".",
"remove",
"(",
"self",
")",
"if",
"IdentityMap",
".",
"enabled?",
"restore_transaction_record_state",
"(",
"force_restore_state",
")",
"end"
] |
Call the after rollback callbacks. The restore_state argument indicates if the record
state should be rolled back to the beginning or just to the last savepoint.
|
[
"Call",
"the",
"after",
"rollback",
"callbacks",
".",
"The",
"restore_state",
"argument",
"indicates",
"if",
"the",
"record",
"state",
"should",
"be",
"rolled",
"back",
"to",
"the",
"beginning",
"or",
"just",
"to",
"the",
"last",
"savepoint",
"."
] |
48d5d1a7442d9cade602be4fb782a1b56c7677f5
|
https://github.com/ktonon/code_node/blob/48d5d1a7442d9cade602be4fb782a1b56c7677f5/spec/fixtures/activerecord/src/active_record/transactions.rb#L288-L293
|
10,114
|
irvingwashington/gem_footprint_analyzer
|
lib/gem_footprint_analyzer/child_process.rb
|
GemFootprintAnalyzer.ChildProcess.start_child
|
def start_child
@child_thread ||= Thread.new do # rubocop:disable Naming/MemoizedInstanceVariableName
Open3.popen3(child_env_vars, *ruby_command, context_file) do |_, stdout, stderr|
@pid = stdout.gets.strip.to_i
while (line = stderr.gets)
print "!! #{line}"
end
end
end
end
|
ruby
|
def start_child
@child_thread ||= Thread.new do # rubocop:disable Naming/MemoizedInstanceVariableName
Open3.popen3(child_env_vars, *ruby_command, context_file) do |_, stdout, stderr|
@pid = stdout.gets.strip.to_i
while (line = stderr.gets)
print "!! #{line}"
end
end
end
end
|
[
"def",
"start_child",
"@child_thread",
"||=",
"Thread",
".",
"new",
"do",
"# rubocop:disable Naming/MemoizedInstanceVariableName",
"Open3",
".",
"popen3",
"(",
"child_env_vars",
",",
"ruby_command",
",",
"context_file",
")",
"do",
"|",
"_",
",",
"stdout",
",",
"stderr",
"|",
"@pid",
"=",
"stdout",
".",
"gets",
".",
"strip",
".",
"to_i",
"while",
"(",
"line",
"=",
"stderr",
".",
"gets",
")",
"print",
"\"!! #{line}\"",
"end",
"end",
"end",
"end"
] |
Sets necessary ivars
Starts a child process in a child-watching-thread
Reads it's PID from the new process' STDOUT and sets it as an instance variable
|
[
"Sets",
"necessary",
"ivars",
"Starts",
"a",
"child",
"process",
"in",
"a",
"child",
"-",
"watching",
"-",
"thread",
"Reads",
"it",
"s",
"PID",
"from",
"the",
"new",
"process",
"STDOUT",
"and",
"sets",
"it",
"as",
"an",
"instance",
"variable"
] |
19a8892f6baaeb16b1b166144c4f73852396220c
|
https://github.com/irvingwashington/gem_footprint_analyzer/blob/19a8892f6baaeb16b1b166144c4f73852396220c/lib/gem_footprint_analyzer/child_process.rb#L21-L31
|
10,115
|
davidan1981/rails-identity
|
app/controllers/rails_identity/users_controller.rb
|
RailsIdentity.UsersController.create
|
def create
logger.debug("Create new user")
@user = User.new(user_params)
if @user.save
# Save succeeded. Render the response based on the created user.
render json: @user,
except: [:verification_token, :reset_token, :password_digest],
status: 201
# Then, issue the verification token and send the email for
# verification.
@user.issue_token(:verification_token)
@user.save
user_mailer.email_verification(@user).deliver_later
else
render_errors 400, @user.errors.full_messages
end
end
|
ruby
|
def create
logger.debug("Create new user")
@user = User.new(user_params)
if @user.save
# Save succeeded. Render the response based on the created user.
render json: @user,
except: [:verification_token, :reset_token, :password_digest],
status: 201
# Then, issue the verification token and send the email for
# verification.
@user.issue_token(:verification_token)
@user.save
user_mailer.email_verification(@user).deliver_later
else
render_errors 400, @user.errors.full_messages
end
end
|
[
"def",
"create",
"logger",
".",
"debug",
"(",
"\"Create new user\"",
")",
"@user",
"=",
"User",
".",
"new",
"(",
"user_params",
")",
"if",
"@user",
".",
"save",
"# Save succeeded. Render the response based on the created user.",
"render",
"json",
":",
"@user",
",",
"except",
":",
"[",
":verification_token",
",",
":reset_token",
",",
":password_digest",
"]",
",",
"status",
":",
"201",
"# Then, issue the verification token and send the email for",
"# verification.",
"@user",
".",
"issue_token",
"(",
":verification_token",
")",
"@user",
".",
"save",
"user_mailer",
".",
"email_verification",
"(",
"@user",
")",
".",
"deliver_later",
"else",
"render_errors",
"400",
",",
"@user",
".",
"errors",
".",
"full_messages",
"end",
"end"
] |
Creates a new user. This action does not require any auth although it
is optional.
|
[
"Creates",
"a",
"new",
"user",
".",
"This",
"action",
"does",
"not",
"require",
"any",
"auth",
"although",
"it",
"is",
"optional",
"."
] |
12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0
|
https://github.com/davidan1981/rails-identity/blob/12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0/app/controllers/rails_identity/users_controller.rb#L31-L49
|
10,116
|
davidan1981/rails-identity
|
app/controllers/rails_identity/users_controller.rb
|
RailsIdentity.UsersController.update_user
|
def update_user(update_user_params)
if @user.update_attributes(update_user_params)
render json: @user, except: [:password_digest]
else
render_errors 400, @user.errors.full_messages
end
end
|
ruby
|
def update_user(update_user_params)
if @user.update_attributes(update_user_params)
render json: @user, except: [:password_digest]
else
render_errors 400, @user.errors.full_messages
end
end
|
[
"def",
"update_user",
"(",
"update_user_params",
")",
"if",
"@user",
".",
"update_attributes",
"(",
"update_user_params",
")",
"render",
"json",
":",
"@user",
",",
"except",
":",
"[",
":password_digest",
"]",
"else",
"render_errors",
"400",
",",
"@user",
".",
"errors",
".",
"full_messages",
"end",
"end"
] |
This method normally updates the user using permitted params.
|
[
"This",
"method",
"normally",
"updates",
"the",
"user",
"using",
"permitted",
"params",
"."
] |
12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0
|
https://github.com/davidan1981/rails-identity/blob/12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0/app/controllers/rails_identity/users_controller.rb#L139-L145
|
10,117
|
davidan1981/rails-identity
|
app/controllers/rails_identity/users_controller.rb
|
RailsIdentity.UsersController.update_token
|
def update_token(kind)
@user.issue_token(kind)
@user.save
if kind == :reset_token
user_mailer.password_reset(@user).deliver_later
else
user_mailer.email_verification(@user).deliver_later
end
render body: '', status: 204
end
|
ruby
|
def update_token(kind)
@user.issue_token(kind)
@user.save
if kind == :reset_token
user_mailer.password_reset(@user).deliver_later
else
user_mailer.email_verification(@user).deliver_later
end
render body: '', status: 204
end
|
[
"def",
"update_token",
"(",
"kind",
")",
"@user",
".",
"issue_token",
"(",
"kind",
")",
"@user",
".",
"save",
"if",
"kind",
"==",
":reset_token",
"user_mailer",
".",
"password_reset",
"(",
"@user",
")",
".",
"deliver_later",
"else",
"user_mailer",
".",
"email_verification",
"(",
"@user",
")",
".",
"deliver_later",
"end",
"render",
"body",
":",
"''",
",",
"status",
":",
"204",
"end"
] |
This method updates user with a new reset token. Only used for this
operation.
|
[
"This",
"method",
"updates",
"user",
"with",
"a",
"new",
"reset",
"token",
".",
"Only",
"used",
"for",
"this",
"operation",
"."
] |
12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0
|
https://github.com/davidan1981/rails-identity/blob/12b0d6fd85bd9019d3be7f4fd79fbca39f824ca0/app/controllers/rails_identity/users_controller.rb#L151-L160
|
10,118
|
PeterCamilleri/format_output
|
lib/format_output/builders/bullet_builder.rb
|
FormatOutput.BulletPointBuilder.add
|
def add(bullet, *items)
items.each do |item|
@bullet_data << [bullet.to_s, item]
bullet = ""
end
end
|
ruby
|
def add(bullet, *items)
items.each do |item|
@bullet_data << [bullet.to_s, item]
bullet = ""
end
end
|
[
"def",
"add",
"(",
"bullet",
",",
"*",
"items",
")",
"items",
".",
"each",
"do",
"|",
"item",
"|",
"@bullet_data",
"<<",
"[",
"bullet",
".",
"to_s",
",",
"item",
"]",
"bullet",
"=",
"\"\"",
"end",
"end"
] |
Prepare a blank slate.
Add items to these bullet points.
|
[
"Prepare",
"a",
"blank",
"slate",
".",
"Add",
"items",
"to",
"these",
"bullet",
"points",
"."
] |
95dac24bd21f618a74bb665a44235491d725e1b7
|
https://github.com/PeterCamilleri/format_output/blob/95dac24bd21f618a74bb665a44235491d725e1b7/lib/format_output/builders/bullet_builder.rb#L18-L23
|
10,119
|
PeterCamilleri/format_output
|
lib/format_output/builders/bullet_builder.rb
|
FormatOutput.BulletPointBuilder.render
|
def render
@key_length, results = get_key_length, []
@bullet_data.each do |key, item|
results.concat(render_bullet(key, item))
end
@bullet_data = []
results
end
|
ruby
|
def render
@key_length, results = get_key_length, []
@bullet_data.each do |key, item|
results.concat(render_bullet(key, item))
end
@bullet_data = []
results
end
|
[
"def",
"render",
"@key_length",
",",
"results",
"=",
"get_key_length",
",",
"[",
"]",
"@bullet_data",
".",
"each",
"do",
"|",
"key",
",",
"item",
"|",
"results",
".",
"concat",
"(",
"render_bullet",
"(",
"key",
",",
"item",
")",
")",
"end",
"@bullet_data",
"=",
"[",
"]",
"results",
"end"
] |
Render the bullet points as an array of strings.
|
[
"Render",
"the",
"bullet",
"points",
"as",
"an",
"array",
"of",
"strings",
"."
] |
95dac24bd21f618a74bb665a44235491d725e1b7
|
https://github.com/PeterCamilleri/format_output/blob/95dac24bd21f618a74bb665a44235491d725e1b7/lib/format_output/builders/bullet_builder.rb#L26-L35
|
10,120
|
thriventures/storage_room_gem
|
lib/storage_room/model.rb
|
StorageRoom.Model.create
|
def create
return false unless new_record?
run_callbacks :save do
run_callbacks :create do
httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
handle_save_response(httparty)
end
end
end
|
ruby
|
def create
return false unless new_record?
run_callbacks :save do
run_callbacks :create do
httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
handle_save_response(httparty)
end
end
end
|
[
"def",
"create",
"return",
"false",
"unless",
"new_record?",
"run_callbacks",
":save",
"do",
"run_callbacks",
":create",
"do",
"httparty",
"=",
"self",
".",
"class",
".",
"post",
"(",
"self",
".",
"class",
".",
"index_path",
",",
"request_options",
".",
"merge",
"(",
":body",
"=>",
"to_json",
")",
")",
"handle_save_response",
"(",
"httparty",
")",
"end",
"end",
"end"
] |
Create a new model on the server
|
[
"Create",
"a",
"new",
"model",
"on",
"the",
"server"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/model.rb#L65-L73
|
10,121
|
thriventures/storage_room_gem
|
lib/storage_room/model.rb
|
StorageRoom.Model.update
|
def update
return false if new_record?
run_callbacks :save do
run_callbacks :update do
httparty = self.class.put(self[:@url], request_options.merge(:body => to_json))
handle_save_response(httparty)
end
end
end
|
ruby
|
def update
return false if new_record?
run_callbacks :save do
run_callbacks :update do
httparty = self.class.put(self[:@url], request_options.merge(:body => to_json))
handle_save_response(httparty)
end
end
end
|
[
"def",
"update",
"return",
"false",
"if",
"new_record?",
"run_callbacks",
":save",
"do",
"run_callbacks",
":update",
"do",
"httparty",
"=",
"self",
".",
"class",
".",
"put",
"(",
"self",
"[",
":@url",
"]",
",",
"request_options",
".",
"merge",
"(",
":body",
"=>",
"to_json",
")",
")",
"handle_save_response",
"(",
"httparty",
")",
"end",
"end",
"end"
] |
Update an existing model on the server
|
[
"Update",
"an",
"existing",
"model",
"on",
"the",
"server"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/model.rb#L76-L84
|
10,122
|
thriventures/storage_room_gem
|
lib/storage_room/model.rb
|
StorageRoom.Model.destroy
|
def destroy
return false if new_record?
run_callbacks :destroy do
httparty = self.class.delete(self[:@url], request_options)
self.class.handle_critical_response_errors(httparty)
end
true
end
|
ruby
|
def destroy
return false if new_record?
run_callbacks :destroy do
httparty = self.class.delete(self[:@url], request_options)
self.class.handle_critical_response_errors(httparty)
end
true
end
|
[
"def",
"destroy",
"return",
"false",
"if",
"new_record?",
"run_callbacks",
":destroy",
"do",
"httparty",
"=",
"self",
".",
"class",
".",
"delete",
"(",
"self",
"[",
":@url",
"]",
",",
"request_options",
")",
"self",
".",
"class",
".",
"handle_critical_response_errors",
"(",
"httparty",
")",
"end",
"true",
"end"
] |
Delete an existing model on the server
|
[
"Delete",
"an",
"existing",
"model",
"on",
"the",
"server"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/model.rb#L87-L96
|
10,123
|
thriventures/storage_room_gem
|
lib/storage_room/model.rb
|
StorageRoom.Model.to_hash
|
def to_hash(args = {}) # :nodoc:
args ||= {}
if args[:nested]
{'url' => self[:@url] || self[:url]}
else
hash = super
hash.merge!('@version' => self['@version']) unless new_record?
{self.class.json_name => hash}
end
end
|
ruby
|
def to_hash(args = {}) # :nodoc:
args ||= {}
if args[:nested]
{'url' => self[:@url] || self[:url]}
else
hash = super
hash.merge!('@version' => self['@version']) unless new_record?
{self.class.json_name => hash}
end
end
|
[
"def",
"to_hash",
"(",
"args",
"=",
"{",
"}",
")",
"# :nodoc:",
"args",
"||=",
"{",
"}",
"if",
"args",
"[",
":nested",
"]",
"{",
"'url'",
"=>",
"self",
"[",
":@url",
"]",
"||",
"self",
"[",
":url",
"]",
"}",
"else",
"hash",
"=",
"super",
"hash",
".",
"merge!",
"(",
"'@version'",
"=>",
"self",
"[",
"'@version'",
"]",
")",
"unless",
"new_record?",
"{",
"self",
".",
"class",
".",
"json_name",
"=>",
"hash",
"}",
"end",
"end"
] |
ActiveSupport caused problems when using as_json, so using to_hash
|
[
"ActiveSupport",
"caused",
"problems",
"when",
"using",
"as_json",
"so",
"using",
"to_hash"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/model.rb#L104-L114
|
10,124
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.retrieve
|
def retrieve(url, method = :get, headers = {}, data = nil)
puts "[ActiveHarmony] Retrieving data:"
puts "[ActiveHarmony] URL: #{url}"
puts "[ActiveHarmony] Method: #{method}"
puts "[ActiveHarmony] Headers: #{headers.inspect}"
puts "[ActiveHarmony] Data: #{data.inspect}" if data
if defined?(Rails) && !Rails.env.test?
data = retrieve_with_typhoeus(url, method, headers, data)
else
data = retrieve_with_http(url, method, headers, data)
end
data
end
|
ruby
|
def retrieve(url, method = :get, headers = {}, data = nil)
puts "[ActiveHarmony] Retrieving data:"
puts "[ActiveHarmony] URL: #{url}"
puts "[ActiveHarmony] Method: #{method}"
puts "[ActiveHarmony] Headers: #{headers.inspect}"
puts "[ActiveHarmony] Data: #{data.inspect}" if data
if defined?(Rails) && !Rails.env.test?
data = retrieve_with_typhoeus(url, method, headers, data)
else
data = retrieve_with_http(url, method, headers, data)
end
data
end
|
[
"def",
"retrieve",
"(",
"url",
",",
"method",
"=",
":get",
",",
"headers",
"=",
"{",
"}",
",",
"data",
"=",
"nil",
")",
"puts",
"\"[ActiveHarmony] Retrieving data:\"",
"puts",
"\"[ActiveHarmony] URL: #{url}\"",
"puts",
"\"[ActiveHarmony] Method: #{method}\"",
"puts",
"\"[ActiveHarmony] Headers: #{headers.inspect}\"",
"puts",
"\"[ActiveHarmony] Data: #{data.inspect}\"",
"if",
"data",
"if",
"defined?",
"(",
"Rails",
")",
"&&",
"!",
"Rails",
".",
"env",
".",
"test?",
"data",
"=",
"retrieve_with_typhoeus",
"(",
"url",
",",
"method",
",",
"headers",
",",
"data",
")",
"else",
"data",
"=",
"retrieve_with_http",
"(",
"url",
",",
"method",
",",
"headers",
",",
"data",
")",
"end",
"data",
"end"
] |
Retrieving data from networks
Retrieves data from URL
@param [String] URL
@return [String] Retrieved data from the URL
|
[
"Retrieving",
"data",
"from",
"networks"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L87-L99
|
10,125
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.list
|
def list(object_type)
url = generate_rest_url(:list, object_type)
result = retrieve(url.path)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :list)
end
|
ruby
|
def list(object_type)
url = generate_rest_url(:list, object_type)
result = retrieve(url.path)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :list)
end
|
[
"def",
"list",
"(",
"object_type",
")",
"url",
"=",
"generate_rest_url",
"(",
":list",
",",
"object_type",
")",
"result",
"=",
"retrieve",
"(",
"url",
".",
"path",
")",
"parsed_result",
"=",
"parse_xml",
"(",
"result",
")",
"find_object_in_result",
"(",
"parsed_result",
",",
"object_type",
",",
":list",
")",
"end"
] |
Working with REST services
List collection of remote objects
@param [Symbol] Object type
@return [Array<Hash>] Array of objects
|
[
"Working",
"with",
"REST",
"services"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L166-L171
|
10,126
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.show
|
def show(object_type, id)
url = generate_rest_url(:show, object_type, id)
result = retrieve(url.path)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :show)
end
|
ruby
|
def show(object_type, id)
url = generate_rest_url(:show, object_type, id)
result = retrieve(url.path)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :show)
end
|
[
"def",
"show",
"(",
"object_type",
",",
"id",
")",
"url",
"=",
"generate_rest_url",
"(",
":show",
",",
"object_type",
",",
"id",
")",
"result",
"=",
"retrieve",
"(",
"url",
".",
"path",
")",
"parsed_result",
"=",
"parse_xml",
"(",
"result",
")",
"find_object_in_result",
"(",
"parsed_result",
",",
"object_type",
",",
":show",
")",
"end"
] |
Shows remote object
@param [Symbol] Object type
@param [String] Object ID
@return [Hash] Object
|
[
"Shows",
"remote",
"object"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L178-L183
|
10,127
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.update
|
def update(object_type, id, data)
url = generate_rest_url(:update, object_type, id)
object_name = object_name_for(object_type, :update)
xml_data = data.to_xml(:root => object_name, :skip_instruct => true, :dasherize => false)
result = retrieve(url.path, url.method, {'Content-type' => 'application/xml'}, xml_data)
find_object_in_result(result, object_type, :update)
end
|
ruby
|
def update(object_type, id, data)
url = generate_rest_url(:update, object_type, id)
object_name = object_name_for(object_type, :update)
xml_data = data.to_xml(:root => object_name, :skip_instruct => true, :dasherize => false)
result = retrieve(url.path, url.method, {'Content-type' => 'application/xml'}, xml_data)
find_object_in_result(result, object_type, :update)
end
|
[
"def",
"update",
"(",
"object_type",
",",
"id",
",",
"data",
")",
"url",
"=",
"generate_rest_url",
"(",
":update",
",",
"object_type",
",",
"id",
")",
"object_name",
"=",
"object_name_for",
"(",
"object_type",
",",
":update",
")",
"xml_data",
"=",
"data",
".",
"to_xml",
"(",
":root",
"=>",
"object_name",
",",
":skip_instruct",
"=>",
"true",
",",
":dasherize",
"=>",
"false",
")",
"result",
"=",
"retrieve",
"(",
"url",
".",
"path",
",",
"url",
".",
"method",
",",
"{",
"'Content-type'",
"=>",
"'application/xml'",
"}",
",",
"xml_data",
")",
"find_object_in_result",
"(",
"result",
",",
"object_type",
",",
":update",
")",
"end"
] |
Updates remote object
@param [Symbol] Object type
@param [String] Object ID
@param [Hash] Data to be sent
|
[
"Updates",
"remote",
"object"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L190-L196
|
10,128
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.create
|
def create(object_type, data)
url = generate_rest_url(:create, object_type)
object_name = object_name_for(object_type, :create)
xml_data = data.to_xml(:root => object_name, :skip_instruct => true, :dasherize => false)
result = retrieve(url.path, url.method, {'Content-type' => 'application/xml'}, xml_data)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :create)
end
|
ruby
|
def create(object_type, data)
url = generate_rest_url(:create, object_type)
object_name = object_name_for(object_type, :create)
xml_data = data.to_xml(:root => object_name, :skip_instruct => true, :dasherize => false)
result = retrieve(url.path, url.method, {'Content-type' => 'application/xml'}, xml_data)
parsed_result = parse_xml(result)
find_object_in_result(parsed_result, object_type, :create)
end
|
[
"def",
"create",
"(",
"object_type",
",",
"data",
")",
"url",
"=",
"generate_rest_url",
"(",
":create",
",",
"object_type",
")",
"object_name",
"=",
"object_name_for",
"(",
"object_type",
",",
":create",
")",
"xml_data",
"=",
"data",
".",
"to_xml",
"(",
":root",
"=>",
"object_name",
",",
":skip_instruct",
"=>",
"true",
",",
":dasherize",
"=>",
"false",
")",
"result",
"=",
"retrieve",
"(",
"url",
".",
"path",
",",
"url",
".",
"method",
",",
"{",
"'Content-type'",
"=>",
"'application/xml'",
"}",
",",
"xml_data",
")",
"parsed_result",
"=",
"parse_xml",
"(",
"result",
")",
"find_object_in_result",
"(",
"parsed_result",
",",
"object_type",
",",
":create",
")",
"end"
] |
Creates a new remote object
@param [Symbol] Object type
@param [Hash] Data to be sent
|
[
"Creates",
"a",
"new",
"remote",
"object"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L202-L209
|
10,129
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.custom_url_for
|
def custom_url_for(object_type, action)
path = @paths.find do |path|
path[:object_type] == object_type &&
path[:action] == action
end
if path
ServiceUrl.new(generate_url(path[:path]), path[:method])
end
end
|
ruby
|
def custom_url_for(object_type, action)
path = @paths.find do |path|
path[:object_type] == object_type &&
path[:action] == action
end
if path
ServiceUrl.new(generate_url(path[:path]), path[:method])
end
end
|
[
"def",
"custom_url_for",
"(",
"object_type",
",",
"action",
")",
"path",
"=",
"@paths",
".",
"find",
"do",
"|",
"path",
"|",
"path",
"[",
":object_type",
"]",
"==",
"object_type",
"&&",
"path",
"[",
":action",
"]",
"==",
"action",
"end",
"if",
"path",
"ServiceUrl",
".",
"new",
"(",
"generate_url",
"(",
"path",
"[",
":path",
"]",
")",
",",
"path",
"[",
":method",
"]",
")",
"end",
"end"
] |
Returns custom path
@param [Symbol] Object type
@param [Symbol] Action
@return [Service::ServiceUrl] Custom path
|
[
"Returns",
"custom",
"path"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L251-L259
|
10,130
|
vojto/active_harmony
|
lib/active_harmony/service.rb
|
ActiveHarmony.Service.object_name_for
|
def object_name_for(object_type, action)
object_name = @object_names.find do |object_name|
object_name[:object_type] == object_type
object_name[:action] == action
end
object_name = object_name ? object_name[:new_object_name] : nil
unless object_name
object_name = object_type.to_s.gsub('-', '_')
end
object_name
end
|
ruby
|
def object_name_for(object_type, action)
object_name = @object_names.find do |object_name|
object_name[:object_type] == object_type
object_name[:action] == action
end
object_name = object_name ? object_name[:new_object_name] : nil
unless object_name
object_name = object_type.to_s.gsub('-', '_')
end
object_name
end
|
[
"def",
"object_name_for",
"(",
"object_type",
",",
"action",
")",
"object_name",
"=",
"@object_names",
".",
"find",
"do",
"|",
"object_name",
"|",
"object_name",
"[",
":object_type",
"]",
"==",
"object_type",
"object_name",
"[",
":action",
"]",
"==",
"action",
"end",
"object_name",
"=",
"object_name",
"?",
"object_name",
"[",
":new_object_name",
"]",
":",
"nil",
"unless",
"object_name",
"object_name",
"=",
"object_type",
".",
"to_s",
".",
"gsub",
"(",
"'-'",
",",
"'_'",
")",
"end",
"object_name",
"end"
] |
Returns custom object name for action
@param [Symbol] Object type
@param [Symbol] Action
|
[
"Returns",
"custom",
"object",
"name",
"for",
"action"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/service.rb#L281-L291
|
10,131
|
Illianthe/lolbase
|
lib/lolbase/connection.rb
|
LoLBase.Connection.get
|
def get(path, options = {})
if options[:query].nil?
options.merge!({ query: { api_key: @key } })
else
options[:query].merge!({ api_key: @key })
end
response = self.class.get path, options
raise LoLBaseError, response.message if response.code != 200
response.body
end
|
ruby
|
def get(path, options = {})
if options[:query].nil?
options.merge!({ query: { api_key: @key } })
else
options[:query].merge!({ api_key: @key })
end
response = self.class.get path, options
raise LoLBaseError, response.message if response.code != 200
response.body
end
|
[
"def",
"get",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"if",
"options",
"[",
":query",
"]",
".",
"nil?",
"options",
".",
"merge!",
"(",
"{",
"query",
":",
"{",
"api_key",
":",
"@key",
"}",
"}",
")",
"else",
"options",
"[",
":query",
"]",
".",
"merge!",
"(",
"{",
"api_key",
":",
"@key",
"}",
")",
"end",
"response",
"=",
"self",
".",
"class",
".",
"get",
"path",
",",
"options",
"raise",
"LoLBaseError",
",",
"response",
".",
"message",
"if",
"response",
".",
"code",
"!=",
"200",
"response",
".",
"body",
"end"
] |
Override HTTParty's get method to append the API key and to process errors returned from request
|
[
"Override",
"HTTParty",
"s",
"get",
"method",
"to",
"append",
"the",
"API",
"key",
"and",
"to",
"process",
"errors",
"returned",
"from",
"request"
] |
b622315bb3e9e44a0e33da2d34a89e524fd8863e
|
https://github.com/Illianthe/lolbase/blob/b622315bb3e9e44a0e33da2d34a89e524fd8863e/lib/lolbase/connection.rb#L13-L23
|
10,132
|
baroquebobcat/sinatra-twitter-oauth
|
lib/sinatra-twitter-oauth/helpers.rb
|
Sinatra::TwitterOAuth.Helpers.login_required
|
def login_required
setup_client
@user = ::TwitterOAuth::User.new(@client, session[:user]) if session[:user]
@rate_limit_status = @client.rate_limit_status
redirect '/login' unless user
end
|
ruby
|
def login_required
setup_client
@user = ::TwitterOAuth::User.new(@client, session[:user]) if session[:user]
@rate_limit_status = @client.rate_limit_status
redirect '/login' unless user
end
|
[
"def",
"login_required",
"setup_client",
"@user",
"=",
"::",
"TwitterOAuth",
"::",
"User",
".",
"new",
"(",
"@client",
",",
"session",
"[",
":user",
"]",
")",
"if",
"session",
"[",
":user",
"]",
"@rate_limit_status",
"=",
"@client",
".",
"rate_limit_status",
"redirect",
"'/login'",
"unless",
"user",
"end"
] |
Redirects to login unless there is an authenticated user
|
[
"Redirects",
"to",
"login",
"unless",
"there",
"is",
"an",
"authenticated",
"user"
] |
8e11cc2a223a45b7c09152a492c48387f86cca2f
|
https://github.com/baroquebobcat/sinatra-twitter-oauth/blob/8e11cc2a223a45b7c09152a492c48387f86cca2f/lib/sinatra-twitter-oauth/helpers.rb#L12-L20
|
10,133
|
baroquebobcat/sinatra-twitter-oauth
|
lib/sinatra-twitter-oauth/helpers.rb
|
Sinatra::TwitterOAuth.Helpers.redirect_to_twitter_auth_url
|
def redirect_to_twitter_auth_url
request_token = get_request_token
session[:request_token] = request_token.token
session[:request_token_secret]= request_token.secret
redirect request_token.authorize_url.gsub('authorize','authenticate')
end
|
ruby
|
def redirect_to_twitter_auth_url
request_token = get_request_token
session[:request_token] = request_token.token
session[:request_token_secret]= request_token.secret
redirect request_token.authorize_url.gsub('authorize','authenticate')
end
|
[
"def",
"redirect_to_twitter_auth_url",
"request_token",
"=",
"get_request_token",
"session",
"[",
":request_token",
"]",
"=",
"request_token",
".",
"token",
"session",
"[",
":request_token_secret",
"]",
"=",
"request_token",
".",
"secret",
"redirect",
"request_token",
".",
"authorize_url",
".",
"gsub",
"(",
"'authorize'",
",",
"'authenticate'",
")",
"end"
] |
gets the request token and redirects to twitter's OAuth endpoint
|
[
"gets",
"the",
"request",
"token",
"and",
"redirects",
"to",
"twitter",
"s",
"OAuth",
"endpoint"
] |
8e11cc2a223a45b7c09152a492c48387f86cca2f
|
https://github.com/baroquebobcat/sinatra-twitter-oauth/blob/8e11cc2a223a45b7c09152a492c48387f86cca2f/lib/sinatra-twitter-oauth/helpers.rb#L57-L64
|
10,134
|
gnomex/ruby-si-units
|
lib/si_units/unit.rb
|
SIUnits.Unit.convert_to
|
def convert_to(other)
return self if other.nil?
case other
when Unit
return self if other == self
target = other
when String
target = SIUnits::Unit.new(other.to_f)
else
raise ArgumentError, "Unknown target units"
end
end
|
ruby
|
def convert_to(other)
return self if other.nil?
case other
when Unit
return self if other == self
target = other
when String
target = SIUnits::Unit.new(other.to_f)
else
raise ArgumentError, "Unknown target units"
end
end
|
[
"def",
"convert_to",
"(",
"other",
")",
"return",
"self",
"if",
"other",
".",
"nil?",
"case",
"other",
"when",
"Unit",
"return",
"self",
"if",
"other",
"==",
"self",
"target",
"=",
"other",
"when",
"String",
"target",
"=",
"SIUnits",
"::",
"Unit",
".",
"new",
"(",
"other",
".",
"to_f",
")",
"else",
"raise",
"ArgumentError",
",",
"\"Unknown target units\"",
"end",
"end"
] |
Comparable units
=> Compare with scale of kinds
convert to a specified unit string or to the same unit as another Unit
|
[
"Comparable",
"units",
"=",
">",
"Compare",
"with",
"scale",
"of",
"kinds",
"convert",
"to",
"a",
"specified",
"unit",
"string",
"or",
"to",
"the",
"same",
"unit",
"as",
"another",
"Unit"
] |
4a0a9f8c53c8d70372b4e0b82b8618a7e4a65245
|
https://github.com/gnomex/ruby-si-units/blob/4a0a9f8c53c8d70372b4e0b82b8618a7e4a65245/lib/si_units/unit.rb#L95-L107
|
10,135
|
SteveOscar/fotofetch
|
lib/fotofetch.rb
|
Fotofetch.Fetch.add_sources
|
def add_sources(urls)
urls.each_with_object( {}.compare_by_identity ) do |link, pairs|
pairs[root_url(link)] = link
end
end
|
ruby
|
def add_sources(urls)
urls.each_with_object( {}.compare_by_identity ) do |link, pairs|
pairs[root_url(link)] = link
end
end
|
[
"def",
"add_sources",
"(",
"urls",
")",
"urls",
".",
"each_with_object",
"(",
"{",
"}",
".",
"compare_by_identity",
")",
"do",
"|",
"link",
",",
"pairs",
"|",
"pairs",
"[",
"root_url",
"(",
"link",
")",
"]",
"=",
"link",
"end",
"end"
] |
Adds root urls as hash keys
|
[
"Adds",
"root",
"urls",
"as",
"hash",
"keys"
] |
e6f7981bd69b61895b39c2a9874bca19488a8c08
|
https://github.com/SteveOscar/fotofetch/blob/e6f7981bd69b61895b39c2a9874bca19488a8c08/lib/fotofetch.rb#L89-L93
|
10,136
|
SteveOscar/fotofetch
|
lib/fotofetch.rb
|
Fotofetch.Fetch.save_images
|
def save_images(urls, file_path)
urls.each_with_index do |url, i|
open("#{@topic.gsub(' ', '-')}_#{i}.jpg", 'wb') do |file|
file << open(url).read
end
end
end
|
ruby
|
def save_images(urls, file_path)
urls.each_with_index do |url, i|
open("#{@topic.gsub(' ', '-')}_#{i}.jpg", 'wb') do |file|
file << open(url).read
end
end
end
|
[
"def",
"save_images",
"(",
"urls",
",",
"file_path",
")",
"urls",
".",
"each_with_index",
"do",
"|",
"url",
",",
"i",
"|",
"open",
"(",
"\"#{@topic.gsub(' ', '-')}_#{i}.jpg\"",
",",
"'wb'",
")",
"do",
"|",
"file",
"|",
"file",
"<<",
"open",
"(",
"url",
")",
".",
"read",
"end",
"end",
"end"
] |
takes an array of links
|
[
"takes",
"an",
"array",
"of",
"links"
] |
e6f7981bd69b61895b39c2a9874bca19488a8c08
|
https://github.com/SteveOscar/fotofetch/blob/e6f7981bd69b61895b39c2a9874bca19488a8c08/lib/fotofetch.rb#L96-L102
|
10,137
|
jeanlazarou/calco
|
lib/calco/sheet.rb
|
Calco.Sheet.row
|
def row row_number
if row_number == 0
cells = []
if @has_titles
@column_titles.each do |title|
cells << title ? title : ''
end
end
cells
else
@engine.generate(row_number, @columns, @cell_styles, @column_styles, @column_types)
end
end
|
ruby
|
def row row_number
if row_number == 0
cells = []
if @has_titles
@column_titles.each do |title|
cells << title ? title : ''
end
end
cells
else
@engine.generate(row_number, @columns, @cell_styles, @column_styles, @column_types)
end
end
|
[
"def",
"row",
"row_number",
"if",
"row_number",
"==",
"0",
"cells",
"=",
"[",
"]",
"if",
"@has_titles",
"@column_titles",
".",
"each",
"do",
"|",
"title",
"|",
"cells",
"<<",
"title",
"?",
"title",
":",
"''",
"end",
"end",
"cells",
"else",
"@engine",
".",
"generate",
"(",
"row_number",
",",
"@columns",
",",
"@cell_styles",
",",
"@column_styles",
",",
"@column_types",
")",
"end",
"end"
] |
Returns an array of String objects generates by the engine
attached to this Sheet's Spreadsheet.
|
[
"Returns",
"an",
"array",
"of",
"String",
"objects",
"generates",
"by",
"the",
"engine",
"attached",
"to",
"this",
"Sheet",
"s",
"Spreadsheet",
"."
] |
e70516e6b6eedd29b5e2924a7780157f2c1fff3b
|
https://github.com/jeanlazarou/calco/blob/e70516e6b6eedd29b5e2924a7780157f2c1fff3b/lib/calco/sheet.rb#L234-L256
|
10,138
|
jeanlazarou/calco
|
lib/calco/sheet.rb
|
Calco.Sheet.each_cell_definition
|
def each_cell_definition &block
if block.arity == 1
@columns.each do |column|
yield column
end
else
@columns.each_with_index do |column, i|
yield column, i
end
end
end
|
ruby
|
def each_cell_definition &block
if block.arity == 1
@columns.each do |column|
yield column
end
else
@columns.each_with_index do |column, i|
yield column, i
end
end
end
|
[
"def",
"each_cell_definition",
"&",
"block",
"if",
"block",
".",
"arity",
"==",
"1",
"@columns",
".",
"each",
"do",
"|",
"column",
"|",
"yield",
"column",
"end",
"else",
"@columns",
".",
"each_with_index",
"do",
"|",
"column",
",",
"i",
"|",
"yield",
"column",
",",
"i",
"end",
"end",
"end"
] |
Calls the passed block for every Element, the cell definition,
attached to columns for this Sheet.
Depending an the block's arity, passes the Element or the Element
and the index to the given block.
Examples:
each_cell_definition {|column_def| ... }
each_cell_definition {|column_def, index| ... }
|
[
"Calls",
"the",
"passed",
"block",
"for",
"every",
"Element",
"the",
"cell",
"definition",
"attached",
"to",
"columns",
"for",
"this",
"Sheet",
"."
] |
e70516e6b6eedd29b5e2924a7780157f2c1fff3b
|
https://github.com/jeanlazarou/calco/blob/e70516e6b6eedd29b5e2924a7780157f2c1fff3b/lib/calco/sheet.rb#L272-L288
|
10,139
|
nilsding/Empyrean
|
lib/empyrean/templaterenderer.rb
|
Empyrean.TemplateRenderer.render
|
def render
mentions = mentions_erb
hashtags = hashtags_erb
smileys = smileys_erb
clients = clients_erb
counters = {
tweets: @parsed[:tweet_count],
retweets: @parsed[:retweet_count],
retweets_percentage: (@parsed[:retweet_count] * 100 / @parsed[:tweet_count].to_f).round(2),
selftweets: @parsed[:selftweet_count],
selftweets_percentage: (@parsed[:selftweet_count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
times_of_day = times_erb
erb = ERB.new @template
erb.result binding
end
|
ruby
|
def render
mentions = mentions_erb
hashtags = hashtags_erb
smileys = smileys_erb
clients = clients_erb
counters = {
tweets: @parsed[:tweet_count],
retweets: @parsed[:retweet_count],
retweets_percentage: (@parsed[:retweet_count] * 100 / @parsed[:tweet_count].to_f).round(2),
selftweets: @parsed[:selftweet_count],
selftweets_percentage: (@parsed[:selftweet_count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
times_of_day = times_erb
erb = ERB.new @template
erb.result binding
end
|
[
"def",
"render",
"mentions",
"=",
"mentions_erb",
"hashtags",
"=",
"hashtags_erb",
"smileys",
"=",
"smileys_erb",
"clients",
"=",
"clients_erb",
"counters",
"=",
"{",
"tweets",
":",
"@parsed",
"[",
":tweet_count",
"]",
",",
"retweets",
":",
"@parsed",
"[",
":retweet_count",
"]",
",",
"retweets_percentage",
":",
"(",
"@parsed",
"[",
":retweet_count",
"]",
"*",
"100",
"/",
"@parsed",
"[",
":tweet_count",
"]",
".",
"to_f",
")",
".",
"round",
"(",
"2",
")",
",",
"selftweets",
":",
"@parsed",
"[",
":selftweet_count",
"]",
",",
"selftweets_percentage",
":",
"(",
"@parsed",
"[",
":selftweet_count",
"]",
"*",
"100",
"/",
"@parsed",
"[",
":tweet_count",
"]",
".",
"to_f",
")",
".",
"round",
"(",
"2",
")",
"}",
"times_of_day",
"=",
"times_erb",
"erb",
"=",
"ERB",
".",
"new",
"@template",
"erb",
".",
"result",
"binding",
"end"
] |
Initializes a new TemplateRenderer.
template: The template to use (i.e. not the file name)
parsed_tweets: The dict that gets returned by TweetParser::merge_parsed
Renders @template.
|
[
"Initializes",
"a",
"new",
"TemplateRenderer",
"."
] |
e652fb8966dfcd32968789af75e8d5a4f63134ec
|
https://github.com/nilsding/Empyrean/blob/e652fb8966dfcd32968789af75e8d5a4f63134ec/lib/empyrean/templaterenderer.rb#L38-L53
|
10,140
|
nilsding/Empyrean
|
lib/empyrean/templaterenderer.rb
|
Empyrean.TemplateRenderer.mentions_erb
|
def mentions_erb
retdict = {
enabled: @config[:mentions][:enabled],
top: [],
nottop: []
}
if @config[:mentions][:enabled]
top = @parsed[:mentions].slice(0, @config[:mentions][:top]) # top X mentions
top.each do |mention|
retdict[:top] << mention[1]
end
nottop = @parsed[:mentions].slice(@config[:mentions][:top], @config[:mentions][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |mention|
mention[1].delete(:example)
retdict[:nottop] << mention[1]
end
end
end
retdict
end
|
ruby
|
def mentions_erb
retdict = {
enabled: @config[:mentions][:enabled],
top: [],
nottop: []
}
if @config[:mentions][:enabled]
top = @parsed[:mentions].slice(0, @config[:mentions][:top]) # top X mentions
top.each do |mention|
retdict[:top] << mention[1]
end
nottop = @parsed[:mentions].slice(@config[:mentions][:top], @config[:mentions][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |mention|
mention[1].delete(:example)
retdict[:nottop] << mention[1]
end
end
end
retdict
end
|
[
"def",
"mentions_erb",
"retdict",
"=",
"{",
"enabled",
":",
"@config",
"[",
":mentions",
"]",
"[",
":enabled",
"]",
",",
"top",
":",
"[",
"]",
",",
"nottop",
":",
"[",
"]",
"}",
"if",
"@config",
"[",
":mentions",
"]",
"[",
":enabled",
"]",
"top",
"=",
"@parsed",
"[",
":mentions",
"]",
".",
"slice",
"(",
"0",
",",
"@config",
"[",
":mentions",
"]",
"[",
":top",
"]",
")",
"# top X mentions",
"top",
".",
"each",
"do",
"|",
"mention",
"|",
"retdict",
"[",
":top",
"]",
"<<",
"mention",
"[",
"1",
"]",
"end",
"nottop",
"=",
"@parsed",
"[",
":mentions",
"]",
".",
"slice",
"(",
"@config",
"[",
":mentions",
"]",
"[",
":top",
"]",
",",
"@config",
"[",
":mentions",
"]",
"[",
":notop",
"]",
")",
"# not in the top X",
"unless",
"nottop",
".",
"nil?",
"nottop",
".",
"each",
"do",
"|",
"mention",
"|",
"mention",
"[",
"1",
"]",
".",
"delete",
"(",
":example",
")",
"retdict",
"[",
":nottop",
"]",
"<<",
"mention",
"[",
"1",
"]",
"end",
"end",
"end",
"retdict",
"end"
] |
Returns an array with the mentions which can be easily used within ERB.
|
[
"Returns",
"an",
"array",
"with",
"the",
"mentions",
"which",
"can",
"be",
"easily",
"used",
"within",
"ERB",
"."
] |
e652fb8966dfcd32968789af75e8d5a4f63134ec
|
https://github.com/nilsding/Empyrean/blob/e652fb8966dfcd32968789af75e8d5a4f63134ec/lib/empyrean/templaterenderer.rb#L58-L81
|
10,141
|
nilsding/Empyrean
|
lib/empyrean/templaterenderer.rb
|
Empyrean.TemplateRenderer.hashtags_erb
|
def hashtags_erb
retdict = {
enabled: @config[:hashtags][:enabled],
top: [],
nottop: []
}
if @config[:hashtags][:enabled]
top = @parsed[:hashtags].slice(0, @config[:hashtags][:top]) # top X hashtags
top.each do |hashtag|
retdict[:top] << hashtag[1]
end
nottop = @parsed[:hashtags].slice(@config[:hashtags][:top], @config[:hashtags][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |hashtag|
hashtag[1].delete(:example)
retdict[:nottop] << hashtag[1]
end
end
end
retdict
end
|
ruby
|
def hashtags_erb
retdict = {
enabled: @config[:hashtags][:enabled],
top: [],
nottop: []
}
if @config[:hashtags][:enabled]
top = @parsed[:hashtags].slice(0, @config[:hashtags][:top]) # top X hashtags
top.each do |hashtag|
retdict[:top] << hashtag[1]
end
nottop = @parsed[:hashtags].slice(@config[:hashtags][:top], @config[:hashtags][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |hashtag|
hashtag[1].delete(:example)
retdict[:nottop] << hashtag[1]
end
end
end
retdict
end
|
[
"def",
"hashtags_erb",
"retdict",
"=",
"{",
"enabled",
":",
"@config",
"[",
":hashtags",
"]",
"[",
":enabled",
"]",
",",
"top",
":",
"[",
"]",
",",
"nottop",
":",
"[",
"]",
"}",
"if",
"@config",
"[",
":hashtags",
"]",
"[",
":enabled",
"]",
"top",
"=",
"@parsed",
"[",
":hashtags",
"]",
".",
"slice",
"(",
"0",
",",
"@config",
"[",
":hashtags",
"]",
"[",
":top",
"]",
")",
"# top X hashtags",
"top",
".",
"each",
"do",
"|",
"hashtag",
"|",
"retdict",
"[",
":top",
"]",
"<<",
"hashtag",
"[",
"1",
"]",
"end",
"nottop",
"=",
"@parsed",
"[",
":hashtags",
"]",
".",
"slice",
"(",
"@config",
"[",
":hashtags",
"]",
"[",
":top",
"]",
",",
"@config",
"[",
":hashtags",
"]",
"[",
":notop",
"]",
")",
"# not in the top X",
"unless",
"nottop",
".",
"nil?",
"nottop",
".",
"each",
"do",
"|",
"hashtag",
"|",
"hashtag",
"[",
"1",
"]",
".",
"delete",
"(",
":example",
")",
"retdict",
"[",
":nottop",
"]",
"<<",
"hashtag",
"[",
"1",
"]",
"end",
"end",
"end",
"retdict",
"end"
] |
Returns an array with the hashtags which can be easily used within ERB.
|
[
"Returns",
"an",
"array",
"with",
"the",
"hashtags",
"which",
"can",
"be",
"easily",
"used",
"within",
"ERB",
"."
] |
e652fb8966dfcd32968789af75e8d5a4f63134ec
|
https://github.com/nilsding/Empyrean/blob/e652fb8966dfcd32968789af75e8d5a4f63134ec/lib/empyrean/templaterenderer.rb#L85-L108
|
10,142
|
nilsding/Empyrean
|
lib/empyrean/templaterenderer.rb
|
Empyrean.TemplateRenderer.smileys_erb
|
def smileys_erb
retdict = {
enabled: @config[:smileys][:enabled],
top: [],
nottop: []
}
if @config[:smileys][:enabled]
top = @parsed[:smileys].slice(0, @config[:smileys][:top]) # top X smileys
top.each do |smiley|
retdict[:top] << smiley[1]
end
nottop = @parsed[:smileys].slice(@config[:smileys][:top], @config[:smileys][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |smiley|
smiley[1].delete(:example)
retdict[:nottop] << smiley[1]
end
end
end
retdict
end
|
ruby
|
def smileys_erb
retdict = {
enabled: @config[:smileys][:enabled],
top: [],
nottop: []
}
if @config[:smileys][:enabled]
top = @parsed[:smileys].slice(0, @config[:smileys][:top]) # top X smileys
top.each do |smiley|
retdict[:top] << smiley[1]
end
nottop = @parsed[:smileys].slice(@config[:smileys][:top], @config[:smileys][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |smiley|
smiley[1].delete(:example)
retdict[:nottop] << smiley[1]
end
end
end
retdict
end
|
[
"def",
"smileys_erb",
"retdict",
"=",
"{",
"enabled",
":",
"@config",
"[",
":smileys",
"]",
"[",
":enabled",
"]",
",",
"top",
":",
"[",
"]",
",",
"nottop",
":",
"[",
"]",
"}",
"if",
"@config",
"[",
":smileys",
"]",
"[",
":enabled",
"]",
"top",
"=",
"@parsed",
"[",
":smileys",
"]",
".",
"slice",
"(",
"0",
",",
"@config",
"[",
":smileys",
"]",
"[",
":top",
"]",
")",
"# top X smileys",
"top",
".",
"each",
"do",
"|",
"smiley",
"|",
"retdict",
"[",
":top",
"]",
"<<",
"smiley",
"[",
"1",
"]",
"end",
"nottop",
"=",
"@parsed",
"[",
":smileys",
"]",
".",
"slice",
"(",
"@config",
"[",
":smileys",
"]",
"[",
":top",
"]",
",",
"@config",
"[",
":smileys",
"]",
"[",
":notop",
"]",
")",
"# not in the top X",
"unless",
"nottop",
".",
"nil?",
"nottop",
".",
"each",
"do",
"|",
"smiley",
"|",
"smiley",
"[",
"1",
"]",
".",
"delete",
"(",
":example",
")",
"retdict",
"[",
":nottop",
"]",
"<<",
"smiley",
"[",
"1",
"]",
"end",
"end",
"end",
"retdict",
"end"
] |
Returns an array with the smileys which can be easily used within ERB.
|
[
"Returns",
"an",
"array",
"with",
"the",
"smileys",
"which",
"can",
"be",
"easily",
"used",
"within",
"ERB",
"."
] |
e652fb8966dfcd32968789af75e8d5a4f63134ec
|
https://github.com/nilsding/Empyrean/blob/e652fb8966dfcd32968789af75e8d5a4f63134ec/lib/empyrean/templaterenderer.rb#L112-L135
|
10,143
|
nilsding/Empyrean
|
lib/empyrean/templaterenderer.rb
|
Empyrean.TemplateRenderer.clients_erb
|
def clients_erb
retdict = {
enabled: @config[:clients][:enabled],
top: [],
nottop: []
}
if @config[:clients][:enabled]
top = @parsed[:clients].slice(0, @config[:clients][:top]) # top X clients
top.each do |client|
retdict[:top] << {
name: client[1][:name],
url: client[1][:url],
count: client[1][:count],
percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
end
nottop = @parsed[:clients].slice(@config[:clients][:top], @config[:clients][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |client|
client[1].delete(:example)
retdict[:nottop] << {
name: client[1][:name],
url: client[1][:url],
count: client[1][:count],
percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
end
end
end
retdict
end
|
ruby
|
def clients_erb
retdict = {
enabled: @config[:clients][:enabled],
top: [],
nottop: []
}
if @config[:clients][:enabled]
top = @parsed[:clients].slice(0, @config[:clients][:top]) # top X clients
top.each do |client|
retdict[:top] << {
name: client[1][:name],
url: client[1][:url],
count: client[1][:count],
percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
end
nottop = @parsed[:clients].slice(@config[:clients][:top], @config[:clients][:notop]) # not in the top X
unless nottop.nil?
nottop.each do |client|
client[1].delete(:example)
retdict[:nottop] << {
name: client[1][:name],
url: client[1][:url],
count: client[1][:count],
percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2)
}
end
end
end
retdict
end
|
[
"def",
"clients_erb",
"retdict",
"=",
"{",
"enabled",
":",
"@config",
"[",
":clients",
"]",
"[",
":enabled",
"]",
",",
"top",
":",
"[",
"]",
",",
"nottop",
":",
"[",
"]",
"}",
"if",
"@config",
"[",
":clients",
"]",
"[",
":enabled",
"]",
"top",
"=",
"@parsed",
"[",
":clients",
"]",
".",
"slice",
"(",
"0",
",",
"@config",
"[",
":clients",
"]",
"[",
":top",
"]",
")",
"# top X clients",
"top",
".",
"each",
"do",
"|",
"client",
"|",
"retdict",
"[",
":top",
"]",
"<<",
"{",
"name",
":",
"client",
"[",
"1",
"]",
"[",
":name",
"]",
",",
"url",
":",
"client",
"[",
"1",
"]",
"[",
":url",
"]",
",",
"count",
":",
"client",
"[",
"1",
"]",
"[",
":count",
"]",
",",
"percentage",
":",
"(",
"client",
"[",
"1",
"]",
"[",
":count",
"]",
"*",
"100",
"/",
"@parsed",
"[",
":tweet_count",
"]",
".",
"to_f",
")",
".",
"round",
"(",
"2",
")",
"}",
"end",
"nottop",
"=",
"@parsed",
"[",
":clients",
"]",
".",
"slice",
"(",
"@config",
"[",
":clients",
"]",
"[",
":top",
"]",
",",
"@config",
"[",
":clients",
"]",
"[",
":notop",
"]",
")",
"# not in the top X",
"unless",
"nottop",
".",
"nil?",
"nottop",
".",
"each",
"do",
"|",
"client",
"|",
"client",
"[",
"1",
"]",
".",
"delete",
"(",
":example",
")",
"retdict",
"[",
":nottop",
"]",
"<<",
"{",
"name",
":",
"client",
"[",
"1",
"]",
"[",
":name",
"]",
",",
"url",
":",
"client",
"[",
"1",
"]",
"[",
":url",
"]",
",",
"count",
":",
"client",
"[",
"1",
"]",
"[",
":count",
"]",
",",
"percentage",
":",
"(",
"client",
"[",
"1",
"]",
"[",
":count",
"]",
"*",
"100",
"/",
"@parsed",
"[",
":tweet_count",
"]",
".",
"to_f",
")",
".",
"round",
"(",
"2",
")",
"}",
"end",
"end",
"end",
"retdict",
"end"
] |
Returns an array with the clients which can be easily used within ERB.
|
[
"Returns",
"an",
"array",
"with",
"the",
"clients",
"which",
"can",
"be",
"easily",
"used",
"within",
"ERB",
"."
] |
e652fb8966dfcd32968789af75e8d5a4f63134ec
|
https://github.com/nilsding/Empyrean/blob/e652fb8966dfcd32968789af75e8d5a4f63134ec/lib/empyrean/templaterenderer.rb#L139-L172
|
10,144
|
maxjacobson/todo_lint
|
lib/todo_lint/file_finder.rb
|
TodoLint.FileFinder.list
|
def list(*extensions)
all_files.keep_if do |filename|
extensions.include?(Pathname.new(filename).extname)
end
all_files.reject! { |file| excluded_file?(file) }
all_files
end
|
ruby
|
def list(*extensions)
all_files.keep_if do |filename|
extensions.include?(Pathname.new(filename).extname)
end
all_files.reject! { |file| excluded_file?(file) }
all_files
end
|
[
"def",
"list",
"(",
"*",
"extensions",
")",
"all_files",
".",
"keep_if",
"do",
"|",
"filename",
"|",
"extensions",
".",
"include?",
"(",
"Pathname",
".",
"new",
"(",
"filename",
")",
".",
"extname",
")",
"end",
"all_files",
".",
"reject!",
"{",
"|",
"file",
"|",
"excluded_file?",
"(",
"file",
")",
"}",
"all_files",
"end"
] |
Instantiate a FileFinder with the path to a folder
@example
FileFinder.new("/Users/max/src/layabout")
@api public
Absolute paths to all the files with the provided extensions
@example
FileFinder.new("/Users/max/src/layabout").list(".rb", ".coffee")
@api public
@return [Array<String>]
|
[
"Instantiate",
"a",
"FileFinder",
"with",
"the",
"path",
"to",
"a",
"folder"
] |
0d1061383ea205ef4c74edc64568e308ac1af990
|
https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/file_finder.rb#L22-L28
|
10,145
|
maxjacobson/todo_lint
|
lib/todo_lint/file_finder.rb
|
TodoLint.FileFinder.excluded_file?
|
def excluded_file?(file)
full_path = File.expand_path(file)
options.fetch(:excluded_files) { [] }.any? do |file_to_exclude|
File.fnmatch(file_to_exclude, full_path)
end
end
|
ruby
|
def excluded_file?(file)
full_path = File.expand_path(file)
options.fetch(:excluded_files) { [] }.any? do |file_to_exclude|
File.fnmatch(file_to_exclude, full_path)
end
end
|
[
"def",
"excluded_file?",
"(",
"file",
")",
"full_path",
"=",
"File",
".",
"expand_path",
"(",
"file",
")",
"options",
".",
"fetch",
"(",
":excluded_files",
")",
"{",
"[",
"]",
"}",
".",
"any?",
"do",
"|",
"file_to_exclude",
"|",
"File",
".",
"fnmatch",
"(",
"file_to_exclude",
",",
"full_path",
")",
"end",
"end"
] |
Check if this file has been excluded
@api private
@return [Boolean]
|
[
"Check",
"if",
"this",
"file",
"has",
"been",
"excluded"
] |
0d1061383ea205ef4c74edc64568e308ac1af990
|
https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/file_finder.rb#L51-L56
|
10,146
|
nathansobo/prequel
|
lib/prequel/errors.rb
|
Prequel.Errors.full_messages
|
def full_messages
inject([]) do |m, kv|
att, errors = *kv
errors.each {|e| m << "#{e}"}
m
end
end
|
ruby
|
def full_messages
inject([]) do |m, kv|
att, errors = *kv
errors.each {|e| m << "#{e}"}
m
end
end
|
[
"def",
"full_messages",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"m",
",",
"kv",
"|",
"att",
",",
"errors",
"=",
"kv",
"errors",
".",
"each",
"{",
"|",
"e",
"|",
"m",
"<<",
"\"#{e}\"",
"}",
"m",
"end",
"end"
] |
Returns an array of fully-formatted error messages.
errors.full_messages
# => ['name is not valid',
# 'hometown is not at least 2 letters']
|
[
"Returns",
"an",
"array",
"of",
"fully",
"-",
"formatted",
"error",
"messages",
"."
] |
5133dceb7af0b34caf38f4804c2951c043d89937
|
https://github.com/nathansobo/prequel/blob/5133dceb7af0b34caf38f4804c2951c043d89937/lib/prequel/errors.rb#L37-L43
|
10,147
|
johnwunder/stix_schema_spy
|
lib/stix_schema_spy/models/schema.rb
|
StixSchemaSpy.Schema.find_prefix
|
def find_prefix(doc)
return config['prefix'] if config && config['prefix']
# Loop through the attributes until we see one with the same value
ns_prefix_attribute = doc.namespaces.find do |prefix, ns|
ns.to_s == namespace.to_s && prefix != 'xmlns'
end
# If the attribute was found, return it, otherwise return nil
ns_prefix_attribute ? ns_prefix_attribute[0].split(':').last : "Unknown"
end
|
ruby
|
def find_prefix(doc)
return config['prefix'] if config && config['prefix']
# Loop through the attributes until we see one with the same value
ns_prefix_attribute = doc.namespaces.find do |prefix, ns|
ns.to_s == namespace.to_s && prefix != 'xmlns'
end
# If the attribute was found, return it, otherwise return nil
ns_prefix_attribute ? ns_prefix_attribute[0].split(':').last : "Unknown"
end
|
[
"def",
"find_prefix",
"(",
"doc",
")",
"return",
"config",
"[",
"'prefix'",
"]",
"if",
"config",
"&&",
"config",
"[",
"'prefix'",
"]",
"# Loop through the attributes until we see one with the same value",
"ns_prefix_attribute",
"=",
"doc",
".",
"namespaces",
".",
"find",
"do",
"|",
"prefix",
",",
"ns",
"|",
"ns",
".",
"to_s",
"==",
"namespace",
".",
"to_s",
"&&",
"prefix",
"!=",
"'xmlns'",
"end",
"# If the attribute was found, return it, otherwise return nil",
"ns_prefix_attribute",
"?",
"ns_prefix_attribute",
"[",
"0",
"]",
".",
"split",
"(",
"':'",
")",
".",
"last",
":",
"\"Unknown\"",
"end"
] |
Find the namespace prefix by searching through the namespaces for the TNS
|
[
"Find",
"the",
"namespace",
"prefix",
"by",
"searching",
"through",
"the",
"namespaces",
"for",
"the",
"TNS"
] |
2d551c6854d749eb330340e69f73baee1c4b52d3
|
https://github.com/johnwunder/stix_schema_spy/blob/2d551c6854d749eb330340e69f73baee1c4b52d3/lib/stix_schema_spy/models/schema.rb#L97-L107
|
10,148
|
hannesg/multi_git
|
lib/multi_git/config.rb
|
MultiGit.Config.each
|
def each
return to_enum unless block_given?
each_explicit_key do |*key|
next if default?(*key)
yield key, get(*key)
end
end
|
ruby
|
def each
return to_enum unless block_given?
each_explicit_key do |*key|
next if default?(*key)
yield key, get(*key)
end
end
|
[
"def",
"each",
"return",
"to_enum",
"unless",
"block_given?",
"each_explicit_key",
"do",
"|",
"*",
"key",
"|",
"next",
"if",
"default?",
"(",
"key",
")",
"yield",
"key",
",",
"get",
"(",
"key",
")",
"end",
"end"
] |
Expensive. Use only for debug
|
[
"Expensive",
".",
"Use",
"only",
"for",
"debug"
] |
cb82e66be7d27c3b630610ce3f1385b30811f139
|
https://github.com/hannesg/multi_git/blob/cb82e66be7d27c3b630610ce3f1385b30811f139/lib/multi_git/config.rb#L139-L145
|
10,149
|
maca/eventual
|
lib/eventual/syntax_nodes.rb
|
Eventual.Node.include?
|
def include? date
result = false
walk { |elements|
break result = true if elements.include? date
}
return result if !result || date.class == Date || times.nil?
times.include? date
end
|
ruby
|
def include? date
result = false
walk { |elements|
break result = true if elements.include? date
}
return result if !result || date.class == Date || times.nil?
times.include? date
end
|
[
"def",
"include?",
"date",
"result",
"=",
"false",
"walk",
"{",
"|",
"elements",
"|",
"break",
"result",
"=",
"true",
"if",
"elements",
".",
"include?",
"date",
"}",
"return",
"result",
"if",
"!",
"result",
"||",
"date",
".",
"class",
"==",
"Date",
"||",
"times",
".",
"nil?",
"times",
".",
"include?",
"date",
"end"
] |
Returns true if the Date or DateTime passed is included in the parsed Dates or DateTimes
|
[
"Returns",
"true",
"if",
"the",
"Date",
"or",
"DateTime",
"passed",
"is",
"included",
"in",
"the",
"parsed",
"Dates",
"or",
"DateTimes"
] |
8933def8f4440dae69df47fb90b80796c32ebc9d
|
https://github.com/maca/eventual/blob/8933def8f4440dae69df47fb90b80796c32ebc9d/lib/eventual/syntax_nodes.rb#L82-L91
|
10,150
|
vast/rokko
|
lib/rokko/task.rb
|
Rokko.Task.define
|
def define
desc "Generate rokko documentation"
task @name do
# Find README file for `index.html` and delete it from `sources`
if @options[:generate_index]
readme_source = @sources.detect { |f| File.basename(f) =~ /README(\.(md|text|markdown|mdown|mkd|mkdn)$)?/i }
readme = readme_source ? File.read(@sources.delete(readme_source)) : ''
end
# Run each file through Rokko and write output
@sources.each do |filename|
rokko = Rokko.new(filename, @sources, @options)
out_dest = File.join(@dest, filename.sub(Regexp.new("#{File.extname(filename)}$"), ".html"))
puts "rokko: #{filename} -> #{out_dest}"
FileUtils.mkdir_p File.dirname(out_dest)
File.open(out_dest, 'wb') { |fd| fd.write(rokko.to_html) }
end
# Generate index.html if needed
if @options[:generate_index]
require 'rokko/index_layout'
out_dest = File.join(@dest, 'index.html')
puts "rokko: #{out_dest}"
File.open(out_dest, 'wb') { |fd| fd.write(IndexLayout.new(@sources, readme, @options).render) }
end
# Run specified file through rokko and use it as index
if @options[:index] && source_index = @sources.find{|s| s == @options[:index]}
rokko = Rokko.new(source_index, @sources, @options.merge(preserve_urls: true))
out_dest = File.join(@dest, 'index.html')
puts "rokko: #{source_index} -> index.html"
File.open(out_dest, 'wb') { |fd| fd.write(rokko.to_html) }
end
end
end
|
ruby
|
def define
desc "Generate rokko documentation"
task @name do
# Find README file for `index.html` and delete it from `sources`
if @options[:generate_index]
readme_source = @sources.detect { |f| File.basename(f) =~ /README(\.(md|text|markdown|mdown|mkd|mkdn)$)?/i }
readme = readme_source ? File.read(@sources.delete(readme_source)) : ''
end
# Run each file through Rokko and write output
@sources.each do |filename|
rokko = Rokko.new(filename, @sources, @options)
out_dest = File.join(@dest, filename.sub(Regexp.new("#{File.extname(filename)}$"), ".html"))
puts "rokko: #{filename} -> #{out_dest}"
FileUtils.mkdir_p File.dirname(out_dest)
File.open(out_dest, 'wb') { |fd| fd.write(rokko.to_html) }
end
# Generate index.html if needed
if @options[:generate_index]
require 'rokko/index_layout'
out_dest = File.join(@dest, 'index.html')
puts "rokko: #{out_dest}"
File.open(out_dest, 'wb') { |fd| fd.write(IndexLayout.new(@sources, readme, @options).render) }
end
# Run specified file through rokko and use it as index
if @options[:index] && source_index = @sources.find{|s| s == @options[:index]}
rokko = Rokko.new(source_index, @sources, @options.merge(preserve_urls: true))
out_dest = File.join(@dest, 'index.html')
puts "rokko: #{source_index} -> index.html"
File.open(out_dest, 'wb') { |fd| fd.write(rokko.to_html) }
end
end
end
|
[
"def",
"define",
"desc",
"\"Generate rokko documentation\"",
"task",
"@name",
"do",
"# Find README file for `index.html` and delete it from `sources`",
"if",
"@options",
"[",
":generate_index",
"]",
"readme_source",
"=",
"@sources",
".",
"detect",
"{",
"|",
"f",
"|",
"File",
".",
"basename",
"(",
"f",
")",
"=~",
"/",
"\\.",
"/i",
"}",
"readme",
"=",
"readme_source",
"?",
"File",
".",
"read",
"(",
"@sources",
".",
"delete",
"(",
"readme_source",
")",
")",
":",
"''",
"end",
"# Run each file through Rokko and write output",
"@sources",
".",
"each",
"do",
"|",
"filename",
"|",
"rokko",
"=",
"Rokko",
".",
"new",
"(",
"filename",
",",
"@sources",
",",
"@options",
")",
"out_dest",
"=",
"File",
".",
"join",
"(",
"@dest",
",",
"filename",
".",
"sub",
"(",
"Regexp",
".",
"new",
"(",
"\"#{File.extname(filename)}$\"",
")",
",",
"\".html\"",
")",
")",
"puts",
"\"rokko: #{filename} -> #{out_dest}\"",
"FileUtils",
".",
"mkdir_p",
"File",
".",
"dirname",
"(",
"out_dest",
")",
"File",
".",
"open",
"(",
"out_dest",
",",
"'wb'",
")",
"{",
"|",
"fd",
"|",
"fd",
".",
"write",
"(",
"rokko",
".",
"to_html",
")",
"}",
"end",
"# Generate index.html if needed",
"if",
"@options",
"[",
":generate_index",
"]",
"require",
"'rokko/index_layout'",
"out_dest",
"=",
"File",
".",
"join",
"(",
"@dest",
",",
"'index.html'",
")",
"puts",
"\"rokko: #{out_dest}\"",
"File",
".",
"open",
"(",
"out_dest",
",",
"'wb'",
")",
"{",
"|",
"fd",
"|",
"fd",
".",
"write",
"(",
"IndexLayout",
".",
"new",
"(",
"@sources",
",",
"readme",
",",
"@options",
")",
".",
"render",
")",
"}",
"end",
"# Run specified file through rokko and use it as index",
"if",
"@options",
"[",
":index",
"]",
"&&",
"source_index",
"=",
"@sources",
".",
"find",
"{",
"|",
"s",
"|",
"s",
"==",
"@options",
"[",
":index",
"]",
"}",
"rokko",
"=",
"Rokko",
".",
"new",
"(",
"source_index",
",",
"@sources",
",",
"@options",
".",
"merge",
"(",
"preserve_urls",
":",
"true",
")",
")",
"out_dest",
"=",
"File",
".",
"join",
"(",
"@dest",
",",
"'index.html'",
")",
"puts",
"\"rokko: #{source_index} -> index.html\"",
"File",
".",
"open",
"(",
"out_dest",
",",
"'wb'",
")",
"{",
"|",
"fd",
"|",
"fd",
".",
"write",
"(",
"rokko",
".",
"to_html",
")",
"}",
"end",
"end",
"end"
] |
Actually setup the task
|
[
"Actually",
"setup",
"the",
"task"
] |
37f451db3d0bd92151809fcaba5a88bb597bbcc0
|
https://github.com/vast/rokko/blob/37f451db3d0bd92151809fcaba5a88bb597bbcc0/lib/rokko/task.rb#L42-L77
|
10,151
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.new
|
def new(item, total)
data = read_file
data[item] = {'total' => total.to_i, 'min' => options[:minimum].to_i, 'url' => options[:url] || read_config['url'], 'checked' => Time.now}
write_file(data)
end
|
ruby
|
def new(item, total)
data = read_file
data[item] = {'total' => total.to_i, 'min' => options[:minimum].to_i, 'url' => options[:url] || read_config['url'], 'checked' => Time.now}
write_file(data)
end
|
[
"def",
"new",
"(",
"item",
",",
"total",
")",
"data",
"=",
"read_file",
"data",
"[",
"item",
"]",
"=",
"{",
"'total'",
"=>",
"total",
".",
"to_i",
",",
"'min'",
"=>",
"options",
"[",
":minimum",
"]",
".",
"to_i",
",",
"'url'",
"=>",
"options",
"[",
":url",
"]",
"||",
"read_config",
"[",
"'url'",
"]",
",",
"'checked'",
"=>",
"Time",
".",
"now",
"}",
"write_file",
"(",
"data",
")",
"end"
] |
Creates a new item in the inventory
@param item [String] The item to add to the inventory
@param total [String] How many of the new item on hand
@return [Hash] Returns a hash of the updated inventory and writes YAML to .stocker.yaml
|
[
"Creates",
"a",
"new",
"item",
"in",
"the",
"inventory"
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L23-L27
|
10,152
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.delete
|
def delete(item)
data = read_file
match_name(item)
data.delete(@@item)
write_file(data)
end
|
ruby
|
def delete(item)
data = read_file
match_name(item)
data.delete(@@item)
write_file(data)
end
|
[
"def",
"delete",
"(",
"item",
")",
"data",
"=",
"read_file",
"match_name",
"(",
"item",
")",
"data",
".",
"delete",
"(",
"@@item",
")",
"write_file",
"(",
"data",
")",
"end"
] |
Deletes an item from the inventory.
Stocker will attempt a "fuzzy match" of the item name.
@param item [String] The item to delete from the inventory
@return [Hash] Returns a hash of the updated inventory and writes YAML to .stocker.yaml
|
[
"Deletes",
"an",
"item",
"from",
"the",
"inventory",
".",
"Stocker",
"will",
"attempt",
"a",
"fuzzy",
"match",
"of",
"the",
"item",
"name",
"."
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L34-L39
|
10,153
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.check
|
def check
links = []
read_file.each do |key, value|
value["checked"] = Time.now
if value["total"] < value["min"]
puts "You're running low on #{key}!"
links << key
end
end
links.uniq!
links.each { |link| buy(link)}
end
|
ruby
|
def check
links = []
read_file.each do |key, value|
value["checked"] = Time.now
if value["total"] < value["min"]
puts "You're running low on #{key}!"
links << key
end
end
links.uniq!
links.each { |link| buy(link)}
end
|
[
"def",
"check",
"links",
"=",
"[",
"]",
"read_file",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"value",
"[",
"\"checked\"",
"]",
"=",
"Time",
".",
"now",
"if",
"value",
"[",
"\"total\"",
"]",
"<",
"value",
"[",
"\"min\"",
"]",
"puts",
"\"You're running low on #{key}!\"",
"links",
"<<",
"key",
"end",
"end",
"links",
".",
"uniq!",
"links",
".",
"each",
"{",
"|",
"link",
"|",
"buy",
"(",
"link",
")",
"}",
"end"
] |
Checks the total number of items on hand against their acceptable minimum values and opens the URLs of any items running low in stock.
@return Opens a link in default web browser if URL is set for low stock item
|
[
"Checks",
"the",
"total",
"number",
"of",
"items",
"on",
"hand",
"against",
"their",
"acceptable",
"minimum",
"values",
"and",
"opens",
"the",
"URLs",
"of",
"any",
"items",
"running",
"low",
"in",
"stock",
"."
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L44-L55
|
10,154
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.total
|
def total(item, total)
data = read_file
match_name(item)
data[@@item]["total"] = total.to_i
time(item)
write_file(data)
end
|
ruby
|
def total(item, total)
data = read_file
match_name(item)
data[@@item]["total"] = total.to_i
time(item)
write_file(data)
end
|
[
"def",
"total",
"(",
"item",
",",
"total",
")",
"data",
"=",
"read_file",
"match_name",
"(",
"item",
")",
"data",
"[",
"@@item",
"]",
"[",
"\"total\"",
"]",
"=",
"total",
".",
"to_i",
"time",
"(",
"item",
")",
"write_file",
"(",
"data",
")",
"end"
] |
Set total of existing item in Stocker's inventory
@param item [String] item to update
@param total [String] total on hand
|
[
"Set",
"total",
"of",
"existing",
"item",
"in",
"Stocker",
"s",
"inventory"
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L61-L67
|
10,155
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.url
|
def url(item, url)
data = read_file
match_name(item)
data[@@item]["url"] = url
time(item)
write_file(data)
end
|
ruby
|
def url(item, url)
data = read_file
match_name(item)
data[@@item]["url"] = url
time(item)
write_file(data)
end
|
[
"def",
"url",
"(",
"item",
",",
"url",
")",
"data",
"=",
"read_file",
"match_name",
"(",
"item",
")",
"data",
"[",
"@@item",
"]",
"[",
"\"url\"",
"]",
"=",
"url",
"time",
"(",
"item",
")",
"write_file",
"(",
"data",
")",
"end"
] |
Set URL of existing item in Stocker's inventory
@param item [String] item to update
@param url [String] URL of item
|
[
"Set",
"URL",
"of",
"existing",
"item",
"in",
"Stocker",
"s",
"inventory"
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L73-L79
|
10,156
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.min
|
def min(item, min)
data = read_file
match_name(item)
data[@@item]["min"] = min.to_i
write_file(data)
end
|
ruby
|
def min(item, min)
data = read_file
match_name(item)
data[@@item]["min"] = min.to_i
write_file(data)
end
|
[
"def",
"min",
"(",
"item",
",",
"min",
")",
"data",
"=",
"read_file",
"match_name",
"(",
"item",
")",
"data",
"[",
"@@item",
"]",
"[",
"\"min\"",
"]",
"=",
"min",
".",
"to_i",
"write_file",
"(",
"data",
")",
"end"
] |
Set minimum acceptable amount of existing inventory item
@param item [String] item to update
@param min [String] acceptable minimum amount of item to always have on hand
|
[
"Set",
"minimum",
"acceptable",
"amount",
"of",
"existing",
"inventory",
"item"
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L93-L98
|
10,157
|
brandonpittman/stocker
|
lib/stocker.rb
|
Stocker.Generator.list
|
def list
begin
@header = [["", ""]]
# @header = [[set_color("Item", :white), set_color("Total", :white)], [set_color("=================", :white), set_color("=====", :white)]]
@green = []
@yellow = []
@yellow2 = []
@green2 = []
@red = []
@red2 = []
read_file.each do |key, value|
if value['total'] > value['min']
@green += [[key.titlecase,value['total'], value['total']-value['min']]]
elsif value['total'] == value['min']
@yellow += [[key.titlecase,value['total'], value['total']-value['min']]]
else
@red += [[key.titlecase,value['total'], value['total']-value['min']]]
end
end
@green.sort_by! { |a,b,c| c }
@yellow.sort_by! { |a,b,c| c }
@red.sort_by! { |a,b,c| c }
@green.reverse!
@yellow.reverse!
@red.reverse!
@green.each { |a,b| @green2 += [[set_color(a, :green), set_color(b, :green)]] }
@yellow.each { |a,b| @yellow2 += [[set_color(a, :yellow), set_color(b, :yellow)]] }
@red.each { |a,b| @red2 += [[set_color(a, :red), set_color(b, :red)]] }
print_table(@header + @green2 + @yellow2 + @red2,{indent: 2})
rescue Exception => e
puts "Inventory empty"
end
end
|
ruby
|
def list
begin
@header = [["", ""]]
# @header = [[set_color("Item", :white), set_color("Total", :white)], [set_color("=================", :white), set_color("=====", :white)]]
@green = []
@yellow = []
@yellow2 = []
@green2 = []
@red = []
@red2 = []
read_file.each do |key, value|
if value['total'] > value['min']
@green += [[key.titlecase,value['total'], value['total']-value['min']]]
elsif value['total'] == value['min']
@yellow += [[key.titlecase,value['total'], value['total']-value['min']]]
else
@red += [[key.titlecase,value['total'], value['total']-value['min']]]
end
end
@green.sort_by! { |a,b,c| c }
@yellow.sort_by! { |a,b,c| c }
@red.sort_by! { |a,b,c| c }
@green.reverse!
@yellow.reverse!
@red.reverse!
@green.each { |a,b| @green2 += [[set_color(a, :green), set_color(b, :green)]] }
@yellow.each { |a,b| @yellow2 += [[set_color(a, :yellow), set_color(b, :yellow)]] }
@red.each { |a,b| @red2 += [[set_color(a, :red), set_color(b, :red)]] }
print_table(@header + @green2 + @yellow2 + @red2,{indent: 2})
rescue Exception => e
puts "Inventory empty"
end
end
|
[
"def",
"list",
"begin",
"@header",
"=",
"[",
"[",
"\"\"",
",",
"\"\"",
"]",
"]",
"# @header = [[set_color(\"Item\", :white), set_color(\"Total\", :white)], [set_color(\"=================\", :white), set_color(\"=====\", :white)]]",
"@green",
"=",
"[",
"]",
"@yellow",
"=",
"[",
"]",
"@yellow2",
"=",
"[",
"]",
"@green2",
"=",
"[",
"]",
"@red",
"=",
"[",
"]",
"@red2",
"=",
"[",
"]",
"read_file",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"value",
"[",
"'total'",
"]",
">",
"value",
"[",
"'min'",
"]",
"@green",
"+=",
"[",
"[",
"key",
".",
"titlecase",
",",
"value",
"[",
"'total'",
"]",
",",
"value",
"[",
"'total'",
"]",
"-",
"value",
"[",
"'min'",
"]",
"]",
"]",
"elsif",
"value",
"[",
"'total'",
"]",
"==",
"value",
"[",
"'min'",
"]",
"@yellow",
"+=",
"[",
"[",
"key",
".",
"titlecase",
",",
"value",
"[",
"'total'",
"]",
",",
"value",
"[",
"'total'",
"]",
"-",
"value",
"[",
"'min'",
"]",
"]",
"]",
"else",
"@red",
"+=",
"[",
"[",
"key",
".",
"titlecase",
",",
"value",
"[",
"'total'",
"]",
",",
"value",
"[",
"'total'",
"]",
"-",
"value",
"[",
"'min'",
"]",
"]",
"]",
"end",
"end",
"@green",
".",
"sort_by!",
"{",
"|",
"a",
",",
"b",
",",
"c",
"|",
"c",
"}",
"@yellow",
".",
"sort_by!",
"{",
"|",
"a",
",",
"b",
",",
"c",
"|",
"c",
"}",
"@red",
".",
"sort_by!",
"{",
"|",
"a",
",",
"b",
",",
"c",
"|",
"c",
"}",
"@green",
".",
"reverse!",
"@yellow",
".",
"reverse!",
"@red",
".",
"reverse!",
"@green",
".",
"each",
"{",
"|",
"a",
",",
"b",
"|",
"@green2",
"+=",
"[",
"[",
"set_color",
"(",
"a",
",",
":green",
")",
",",
"set_color",
"(",
"b",
",",
":green",
")",
"]",
"]",
"}",
"@yellow",
".",
"each",
"{",
"|",
"a",
",",
"b",
"|",
"@yellow2",
"+=",
"[",
"[",
"set_color",
"(",
"a",
",",
":yellow",
")",
",",
"set_color",
"(",
"b",
",",
":yellow",
")",
"]",
"]",
"}",
"@red",
".",
"each",
"{",
"|",
"a",
",",
"b",
"|",
"@red2",
"+=",
"[",
"[",
"set_color",
"(",
"a",
",",
":red",
")",
",",
"set_color",
"(",
"b",
",",
":red",
")",
"]",
"]",
"}",
"print_table",
"(",
"@header",
"+",
"@green2",
"+",
"@yellow2",
"+",
"@red2",
",",
"{",
"indent",
":",
"2",
"}",
")",
"rescue",
"Exception",
"=>",
"e",
"puts",
"\"Inventory empty\"",
"end",
"end"
] |
Print a list of all inventory items. Green items are well stocked. Yellow items are at minimum acceptable total. Red items are below minimum acceptable total.
|
[
"Print",
"a",
"list",
"of",
"all",
"inventory",
"items",
".",
"Green",
"items",
"are",
"well",
"stocked",
".",
"Yellow",
"items",
"are",
"at",
"minimum",
"acceptable",
"total",
".",
"Red",
"items",
"are",
"below",
"minimum",
"acceptable",
"total",
"."
] |
f2251eb3dc10dda8068a5edc1822f7704e51bade
|
https://github.com/brandonpittman/stocker/blob/f2251eb3dc10dda8068a5edc1822f7704e51bade/lib/stocker.rb#L132-L164
|
10,158
|
mattmccray/gumdrop
|
lib/gumdrop/data.rb
|
Gumdrop.DataManager.parse_file
|
def parse_file(path, target_ext=nil)
return nil if path.nil?
return nil if File.directory? path
_load_from_file path, target_ext
# if File.directory? path
# _load_from_directory path
# else
# _load_from_file path, target_ext
# end
end
|
ruby
|
def parse_file(path, target_ext=nil)
return nil if path.nil?
return nil if File.directory? path
_load_from_file path, target_ext
# if File.directory? path
# _load_from_directory path
# else
# _load_from_file path, target_ext
# end
end
|
[
"def",
"parse_file",
"(",
"path",
",",
"target_ext",
"=",
"nil",
")",
"return",
"nil",
"if",
"path",
".",
"nil?",
"return",
"nil",
"if",
"File",
".",
"directory?",
"path",
"_load_from_file",
"path",
",",
"target_ext",
"# if File.directory? path",
"# _load_from_directory path",
"# else",
"# _load_from_file path, target_ext",
"# end",
"end"
] |
Not used internally, but useful for external usage
|
[
"Not",
"used",
"internally",
"but",
"useful",
"for",
"external",
"usage"
] |
7c0998675dbc65e6c7fa0cd580ea0fc3167394fd
|
https://github.com/mattmccray/gumdrop/blob/7c0998675dbc65e6c7fa0cd580ea0fc3167394fd/lib/gumdrop/data.rb#L59-L68
|
10,159
|
michaelmior/mipper
|
lib/mipper/model.rb
|
MIPPeR.Model.build_pointer_array
|
def build_pointer_array(array, type)
buffer = FFI::MemoryPointer.new type, array.length
buffer.send("write_array_of_#{type}".to_sym, array)
buffer
end
|
ruby
|
def build_pointer_array(array, type)
buffer = FFI::MemoryPointer.new type, array.length
buffer.send("write_array_of_#{type}".to_sym, array)
buffer
end
|
[
"def",
"build_pointer_array",
"(",
"array",
",",
"type",
")",
"buffer",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"new",
"type",
",",
"array",
".",
"length",
"buffer",
".",
"send",
"(",
"\"write_array_of_#{type}\"",
".",
"to_sym",
",",
"array",
")",
"buffer",
"end"
] |
Shortcut to build a C array from a Ruby array
|
[
"Shortcut",
"to",
"build",
"a",
"C",
"array",
"from",
"a",
"Ruby",
"array"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/model.rb#L82-L87
|
10,160
|
adamsanderson/has_default_association
|
lib/has_default_association.rb
|
HasDefaultAssociation.ClassMethods.has_default_association
|
def has_default_association *names, &default_proc
opts = names.extract_options!
opts.assert_valid_keys(:eager)
names.each do |name|
create_default_association(name, default_proc)
add_default_association_callback(name) if opts[:eager]
end
end
|
ruby
|
def has_default_association *names, &default_proc
opts = names.extract_options!
opts.assert_valid_keys(:eager)
names.each do |name|
create_default_association(name, default_proc)
add_default_association_callback(name) if opts[:eager]
end
end
|
[
"def",
"has_default_association",
"*",
"names",
",",
"&",
"default_proc",
"opts",
"=",
"names",
".",
"extract_options!",
"opts",
".",
"assert_valid_keys",
"(",
":eager",
")",
"names",
".",
"each",
"do",
"|",
"name",
"|",
"create_default_association",
"(",
"name",
",",
"default_proc",
")",
"add_default_association_callback",
"(",
"name",
")",
"if",
"opts",
"[",
":eager",
"]",
"end",
"end"
] |
Declare default associations for ActiveRecord models.
# Build a new association on demand
belongs_to :address
has_default_association :address
# Build a custom assocation on demand
belongs_to :address
has_default_association :address do |model|
Address.new(:name => model.full_name)
end
=Options
+eager+ will instantiate a default assocation when a
model is initialized.
|
[
"Declare",
"default",
"associations",
"for",
"ActiveRecord",
"models",
"."
] |
68d33e9d1fd470d164eb8ec9cdb312cbd32fd7b3
|
https://github.com/adamsanderson/has_default_association/blob/68d33e9d1fd470d164eb8ec9cdb312cbd32fd7b3/lib/has_default_association.rb#L26-L34
|
10,161
|
georgyangelov/vcs-toolkit
|
lib/vcs_toolkit/repository.rb
|
VCSToolkit.Repository.status
|
def status(commit, ignore: [])
tree = get_object(commit.tree) unless commit.nil?
Utils::Status.compare_tree_and_store tree,
staging_area,
object_store,
ignore: ignore
end
|
ruby
|
def status(commit, ignore: [])
tree = get_object(commit.tree) unless commit.nil?
Utils::Status.compare_tree_and_store tree,
staging_area,
object_store,
ignore: ignore
end
|
[
"def",
"status",
"(",
"commit",
",",
"ignore",
":",
"[",
"]",
")",
"tree",
"=",
"get_object",
"(",
"commit",
".",
"tree",
")",
"unless",
"commit",
".",
"nil?",
"Utils",
"::",
"Status",
".",
"compare_tree_and_store",
"tree",
",",
"staging_area",
",",
"object_store",
",",
"ignore",
":",
"ignore",
"end"
] |
Return new, changed and deleted files
compared to a specific commit and the staging area.
The return value is a hash with :created, :changed and :deleted keys.
|
[
"Return",
"new",
"changed",
"and",
"deleted",
"files",
"compared",
"to",
"a",
"specific",
"commit",
"and",
"the",
"staging",
"area",
"."
] |
9d73735da090a5e0f612aee04f423306fa512f38
|
https://github.com/georgyangelov/vcs-toolkit/blob/9d73735da090a5e0f612aee04f423306fa512f38/lib/vcs_toolkit/repository.rb#L89-L96
|
10,162
|
georgyangelov/vcs-toolkit
|
lib/vcs_toolkit/repository.rb
|
VCSToolkit.Repository.commit_status
|
def commit_status(base_commit, new_commit, ignore: [])
base_tree = get_object(base_commit.tree) unless base_commit.nil?
new_tree = get_object(new_commit.tree) unless new_commit.nil?
Utils::Status.compare_trees base_tree,
new_tree,
object_store,
ignore: ignore
end
|
ruby
|
def commit_status(base_commit, new_commit, ignore: [])
base_tree = get_object(base_commit.tree) unless base_commit.nil?
new_tree = get_object(new_commit.tree) unless new_commit.nil?
Utils::Status.compare_trees base_tree,
new_tree,
object_store,
ignore: ignore
end
|
[
"def",
"commit_status",
"(",
"base_commit",
",",
"new_commit",
",",
"ignore",
":",
"[",
"]",
")",
"base_tree",
"=",
"get_object",
"(",
"base_commit",
".",
"tree",
")",
"unless",
"base_commit",
".",
"nil?",
"new_tree",
"=",
"get_object",
"(",
"new_commit",
".",
"tree",
")",
"unless",
"new_commit",
".",
"nil?",
"Utils",
"::",
"Status",
".",
"compare_trees",
"base_tree",
",",
"new_tree",
",",
"object_store",
",",
"ignore",
":",
"ignore",
"end"
] |
Return new, changed and deleted files
by comparing two commits.
The return value is a hash with :created, :changed and :deleted keys.
|
[
"Return",
"new",
"changed",
"and",
"deleted",
"files",
"by",
"comparing",
"two",
"commits",
"."
] |
9d73735da090a5e0f612aee04f423306fa512f38
|
https://github.com/georgyangelov/vcs-toolkit/blob/9d73735da090a5e0f612aee04f423306fa512f38/lib/vcs_toolkit/repository.rb#L104-L112
|
10,163
|
georgyangelov/vcs-toolkit
|
lib/vcs_toolkit/repository.rb
|
VCSToolkit.Repository.merge
|
def merge(commit_one, commit_two)
common_ancestor = commit_one.common_ancestor(commit_two, object_store)
commit_one_files = Hash[get_object(commit_one.tree).all_files(object_store).to_a]
commit_two_files = Hash[get_object(commit_two.tree).all_files(object_store).to_a]
if common_ancestor.nil?
ancestor_files = {}
else
ancestor_files = Hash[get_object(common_ancestor.tree).all_files(object_store).to_a]
end
all_files = commit_one_files.keys | commit_two_files.keys | ancestor_files.keys
merged = []
conflicted = []
all_files.each do |file|
ancestor = ancestor_files.key?(file) ? get_object(ancestor_files[file]).content.lines : []
file_one = commit_one_files.key?(file) ? get_object(commit_one_files[file]).content.lines : []
file_two = commit_two_files.key?(file) ? get_object(commit_two_files[file]).content.lines : []
diff = VCSToolkit::Merge.three_way ancestor, file_one, file_two
if diff.has_conflicts?
conflicted << file
elsif diff.has_changes?
merged << file
end
content = diff.new_content("<<<<< #{commit_one.id}\n", ">>>>> #{commit_two.id}\n", "=====\n")
if content.empty?
staging_area.delete_file file if staging_area.file? file
else
staging_area.store file, content.join('')
end
end
{merged: merged, conflicted: conflicted}
end
|
ruby
|
def merge(commit_one, commit_two)
common_ancestor = commit_one.common_ancestor(commit_two, object_store)
commit_one_files = Hash[get_object(commit_one.tree).all_files(object_store).to_a]
commit_two_files = Hash[get_object(commit_two.tree).all_files(object_store).to_a]
if common_ancestor.nil?
ancestor_files = {}
else
ancestor_files = Hash[get_object(common_ancestor.tree).all_files(object_store).to_a]
end
all_files = commit_one_files.keys | commit_two_files.keys | ancestor_files.keys
merged = []
conflicted = []
all_files.each do |file|
ancestor = ancestor_files.key?(file) ? get_object(ancestor_files[file]).content.lines : []
file_one = commit_one_files.key?(file) ? get_object(commit_one_files[file]).content.lines : []
file_two = commit_two_files.key?(file) ? get_object(commit_two_files[file]).content.lines : []
diff = VCSToolkit::Merge.three_way ancestor, file_one, file_two
if diff.has_conflicts?
conflicted << file
elsif diff.has_changes?
merged << file
end
content = diff.new_content("<<<<< #{commit_one.id}\n", ">>>>> #{commit_two.id}\n", "=====\n")
if content.empty?
staging_area.delete_file file if staging_area.file? file
else
staging_area.store file, content.join('')
end
end
{merged: merged, conflicted: conflicted}
end
|
[
"def",
"merge",
"(",
"commit_one",
",",
"commit_two",
")",
"common_ancestor",
"=",
"commit_one",
".",
"common_ancestor",
"(",
"commit_two",
",",
"object_store",
")",
"commit_one_files",
"=",
"Hash",
"[",
"get_object",
"(",
"commit_one",
".",
"tree",
")",
".",
"all_files",
"(",
"object_store",
")",
".",
"to_a",
"]",
"commit_two_files",
"=",
"Hash",
"[",
"get_object",
"(",
"commit_two",
".",
"tree",
")",
".",
"all_files",
"(",
"object_store",
")",
".",
"to_a",
"]",
"if",
"common_ancestor",
".",
"nil?",
"ancestor_files",
"=",
"{",
"}",
"else",
"ancestor_files",
"=",
"Hash",
"[",
"get_object",
"(",
"common_ancestor",
".",
"tree",
")",
".",
"all_files",
"(",
"object_store",
")",
".",
"to_a",
"]",
"end",
"all_files",
"=",
"commit_one_files",
".",
"keys",
"|",
"commit_two_files",
".",
"keys",
"|",
"ancestor_files",
".",
"keys",
"merged",
"=",
"[",
"]",
"conflicted",
"=",
"[",
"]",
"all_files",
".",
"each",
"do",
"|",
"file",
"|",
"ancestor",
"=",
"ancestor_files",
".",
"key?",
"(",
"file",
")",
"?",
"get_object",
"(",
"ancestor_files",
"[",
"file",
"]",
")",
".",
"content",
".",
"lines",
":",
"[",
"]",
"file_one",
"=",
"commit_one_files",
".",
"key?",
"(",
"file",
")",
"?",
"get_object",
"(",
"commit_one_files",
"[",
"file",
"]",
")",
".",
"content",
".",
"lines",
":",
"[",
"]",
"file_two",
"=",
"commit_two_files",
".",
"key?",
"(",
"file",
")",
"?",
"get_object",
"(",
"commit_two_files",
"[",
"file",
"]",
")",
".",
"content",
".",
"lines",
":",
"[",
"]",
"diff",
"=",
"VCSToolkit",
"::",
"Merge",
".",
"three_way",
"ancestor",
",",
"file_one",
",",
"file_two",
"if",
"diff",
".",
"has_conflicts?",
"conflicted",
"<<",
"file",
"elsif",
"diff",
".",
"has_changes?",
"merged",
"<<",
"file",
"end",
"content",
"=",
"diff",
".",
"new_content",
"(",
"\"<<<<< #{commit_one.id}\\n\"",
",",
"\">>>>> #{commit_two.id}\\n\"",
",",
"\"=====\\n\"",
")",
"if",
"content",
".",
"empty?",
"staging_area",
".",
"delete_file",
"file",
"if",
"staging_area",
".",
"file?",
"file",
"else",
"staging_area",
".",
"store",
"file",
",",
"content",
".",
"join",
"(",
"''",
")",
"end",
"end",
"{",
"merged",
":",
"merged",
",",
"conflicted",
":",
"conflicted",
"}",
"end"
] |
Merge two commits and save the changes to the staging area.
|
[
"Merge",
"two",
"commits",
"and",
"save",
"the",
"changes",
"to",
"the",
"staging",
"area",
"."
] |
9d73735da090a5e0f612aee04f423306fa512f38
|
https://github.com/georgyangelov/vcs-toolkit/blob/9d73735da090a5e0f612aee04f423306fa512f38/lib/vcs_toolkit/repository.rb#L129-L168
|
10,164
|
georgyangelov/vcs-toolkit
|
lib/vcs_toolkit/repository.rb
|
VCSToolkit.Repository.file_difference
|
def file_difference(file_path, commit)
if staging_area.file? file_path
file_lines = staging_area.fetch(file_path).lines
file_lines.last << "\n" unless file_lines.last.nil? or file_lines.last.end_with? "\n"
else
file_lines = []
end
tree = get_object commit.tree
blob_name_and_id = tree.all_files(object_store).find { |file, _| file_path == file }
if blob_name_and_id.nil?
blob_lines = []
else
blob = get_object blob_name_and_id.last
blob_lines = blob.content.lines
blob_lines.last << "\n" unless blob_lines.last.nil? or blob_lines.last.end_with? "\n"
end
Diff.from_sequences blob_lines, file_lines
end
|
ruby
|
def file_difference(file_path, commit)
if staging_area.file? file_path
file_lines = staging_area.fetch(file_path).lines
file_lines.last << "\n" unless file_lines.last.nil? or file_lines.last.end_with? "\n"
else
file_lines = []
end
tree = get_object commit.tree
blob_name_and_id = tree.all_files(object_store).find { |file, _| file_path == file }
if blob_name_and_id.nil?
blob_lines = []
else
blob = get_object blob_name_and_id.last
blob_lines = blob.content.lines
blob_lines.last << "\n" unless blob_lines.last.nil? or blob_lines.last.end_with? "\n"
end
Diff.from_sequences blob_lines, file_lines
end
|
[
"def",
"file_difference",
"(",
"file_path",
",",
"commit",
")",
"if",
"staging_area",
".",
"file?",
"file_path",
"file_lines",
"=",
"staging_area",
".",
"fetch",
"(",
"file_path",
")",
".",
"lines",
"file_lines",
".",
"last",
"<<",
"\"\\n\"",
"unless",
"file_lines",
".",
"last",
".",
"nil?",
"or",
"file_lines",
".",
"last",
".",
"end_with?",
"\"\\n\"",
"else",
"file_lines",
"=",
"[",
"]",
"end",
"tree",
"=",
"get_object",
"commit",
".",
"tree",
"blob_name_and_id",
"=",
"tree",
".",
"all_files",
"(",
"object_store",
")",
".",
"find",
"{",
"|",
"file",
",",
"_",
"|",
"file_path",
"==",
"file",
"}",
"if",
"blob_name_and_id",
".",
"nil?",
"blob_lines",
"=",
"[",
"]",
"else",
"blob",
"=",
"get_object",
"blob_name_and_id",
".",
"last",
"blob_lines",
"=",
"blob",
".",
"content",
".",
"lines",
"blob_lines",
".",
"last",
"<<",
"\"\\n\"",
"unless",
"blob_lines",
".",
"last",
".",
"nil?",
"or",
"blob_lines",
".",
"last",
".",
"end_with?",
"\"\\n\"",
"end",
"Diff",
".",
"from_sequences",
"blob_lines",
",",
"file_lines",
"end"
] |
Return a list of changes between a file in the staging area
and a specific commit.
This method is just a tiny wrapper around VCSToolkit::Diff.from_sequences
which loads the two files and splits them by lines beforehand.
It also ensures that both files have \n at the end (otherwise the last
two lines of the diff may be merged).
|
[
"Return",
"a",
"list",
"of",
"changes",
"between",
"a",
"file",
"in",
"the",
"staging",
"area",
"and",
"a",
"specific",
"commit",
"."
] |
9d73735da090a5e0f612aee04f423306fa512f38
|
https://github.com/georgyangelov/vcs-toolkit/blob/9d73735da090a5e0f612aee04f423306fa512f38/lib/vcs_toolkit/repository.rb#L179-L200
|
10,165
|
jgrowl/omniauth-oauthio
|
lib/oauthio/client.rb
|
Oauthio.Client.me_url
|
def me_url(provider, params=nil)
connection.build_url(options[:me_url].sub(/:provider/, provider), params).
to_s
end
|
ruby
|
def me_url(provider, params=nil)
connection.build_url(options[:me_url].sub(/:provider/, provider), params).
to_s
end
|
[
"def",
"me_url",
"(",
"provider",
",",
"params",
"=",
"nil",
")",
"connection",
".",
"build_url",
"(",
"options",
"[",
":me_url",
"]",
".",
"sub",
"(",
"/",
"/",
",",
"provider",
")",
",",
"params",
")",
".",
"to_s",
"end"
] |
Instantiate a new OAuth 2.0 client using the
Client ID and Client Secret registered to your
application.
@param [String] client_id the client_id value
@param [String] client_secret the client_secret value
@param [Hash] opts the options to create the client with
@option opts [String] :site the OAuth2 provider site host
@option opts [String] :authorize_url ('/oauth/authorize') absolute or relative URL path to the Authorization endpoint
@option opts [String] :token_url ('/oauth/token') absolute or relative URL path to the Token endpoint
@option opts [Symbol] :token_method (:post) HTTP method to use to request token (:get or :post)
@option opts [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
@option opts [FixNum] :max_redirects (5) maximum number of redirects to follow
@option opts [Boolean] :raise_errors (true) whether or not to raise an OAuth2::Error
on responses with 400+ status codes
@yield [builder] The Faraday connection builder
|
[
"Instantiate",
"a",
"new",
"OAuth",
"2",
".",
"0",
"client",
"using",
"the",
"Client",
"ID",
"and",
"Client",
"Secret",
"registered",
"to",
"your",
"application",
"."
] |
3e6a338dccac764dce8b12673156924233dcc605
|
https://github.com/jgrowl/omniauth-oauthio/blob/3e6a338dccac764dce8b12673156924233dcc605/lib/oauthio/client.rb#L39-L42
|
10,166
|
redding/much-plugin
|
lib/much-plugin.rb
|
MuchPlugin.ClassMethods.included
|
def included(plugin_receiver)
return if plugin_receiver.include?(self.much_plugin_included_detector)
plugin_receiver.send(:include, self.much_plugin_included_detector)
self.much_plugin_included_hooks.each do |hook|
plugin_receiver.class_eval(&hook)
end
end
|
ruby
|
def included(plugin_receiver)
return if plugin_receiver.include?(self.much_plugin_included_detector)
plugin_receiver.send(:include, self.much_plugin_included_detector)
self.much_plugin_included_hooks.each do |hook|
plugin_receiver.class_eval(&hook)
end
end
|
[
"def",
"included",
"(",
"plugin_receiver",
")",
"return",
"if",
"plugin_receiver",
".",
"include?",
"(",
"self",
".",
"much_plugin_included_detector",
")",
"plugin_receiver",
".",
"send",
"(",
":include",
",",
"self",
".",
"much_plugin_included_detector",
")",
"self",
".",
"much_plugin_included_hooks",
".",
"each",
"do",
"|",
"hook",
"|",
"plugin_receiver",
".",
"class_eval",
"(",
"hook",
")",
"end",
"end"
] |
install an included hook that first checks if this plugin's receiver mixin
has already been included. If it has not been, include the receiver mixin
and run all of the `plugin_included` hooks
|
[
"install",
"an",
"included",
"hook",
"that",
"first",
"checks",
"if",
"this",
"plugin",
"s",
"receiver",
"mixin",
"has",
"already",
"been",
"included",
".",
"If",
"it",
"has",
"not",
"been",
"include",
"the",
"receiver",
"mixin",
"and",
"run",
"all",
"of",
"the",
"plugin_included",
"hooks"
] |
5df6dfbc2c66b53faa899359f4a528eda124bb86
|
https://github.com/redding/much-plugin/blob/5df6dfbc2c66b53faa899359f4a528eda124bb86/lib/much-plugin.rb#L14-L21
|
10,167
|
amberbit/amberbit-config
|
lib/amberbit-config/hash_struct.rb
|
AmberbitConfig.HashStruct.to_hash
|
def to_hash
_copy = {}
@table.each { |key, value| _copy[key] = value.is_a?(HashStruct) ? value.to_hash : value }
_copy
end
|
ruby
|
def to_hash
_copy = {}
@table.each { |key, value| _copy[key] = value.is_a?(HashStruct) ? value.to_hash : value }
_copy
end
|
[
"def",
"to_hash",
"_copy",
"=",
"{",
"}",
"@table",
".",
"each",
"{",
"|",
"key",
",",
"value",
"|",
"_copy",
"[",
"key",
"]",
"=",
"value",
".",
"is_a?",
"(",
"HashStruct",
")",
"?",
"value",
".",
"to_hash",
":",
"value",
"}",
"_copy",
"end"
] |
Generates a nested Hash object which is a copy of existing configuration
|
[
"Generates",
"a",
"nested",
"Hash",
"object",
"which",
"is",
"a",
"copy",
"of",
"existing",
"configuration"
] |
cc392005c740d987ad44502d0eb6f9269a55bd4a
|
https://github.com/amberbit/amberbit-config/blob/cc392005c740d987ad44502d0eb6f9269a55bd4a/lib/amberbit-config/hash_struct.rb#L18-L22
|
10,168
|
amberbit/amberbit-config
|
lib/amberbit-config/hash_struct.rb
|
AmberbitConfig.HashStruct.check_hash_for_conflicts
|
def check_hash_for_conflicts(hash)
raise HashArgumentError, 'It must be a hash' unless hash.is_a?(Hash)
unless (conflicts = self.public_methods & hash.keys.map(&:to_sym)).empty?
raise HashArgumentError, "Rename keys in order to avoid conflicts with internal calls: #{conflicts.join(', ')}"
end
end
|
ruby
|
def check_hash_for_conflicts(hash)
raise HashArgumentError, 'It must be a hash' unless hash.is_a?(Hash)
unless (conflicts = self.public_methods & hash.keys.map(&:to_sym)).empty?
raise HashArgumentError, "Rename keys in order to avoid conflicts with internal calls: #{conflicts.join(', ')}"
end
end
|
[
"def",
"check_hash_for_conflicts",
"(",
"hash",
")",
"raise",
"HashArgumentError",
",",
"'It must be a hash'",
"unless",
"hash",
".",
"is_a?",
"(",
"Hash",
")",
"unless",
"(",
"conflicts",
"=",
"self",
".",
"public_methods",
"&",
"hash",
".",
"keys",
".",
"map",
"(",
":to_sym",
")",
")",
".",
"empty?",
"raise",
"HashArgumentError",
",",
"\"Rename keys in order to avoid conflicts with internal calls: #{conflicts.join(', ')}\"",
"end",
"end"
] |
Checks if provided option is a hash and if the keys are not in confict with OpenStruct public methods.
|
[
"Checks",
"if",
"provided",
"option",
"is",
"a",
"hash",
"and",
"if",
"the",
"keys",
"are",
"not",
"in",
"confict",
"with",
"OpenStruct",
"public",
"methods",
"."
] |
cc392005c740d987ad44502d0eb6f9269a55bd4a
|
https://github.com/amberbit/amberbit-config/blob/cc392005c740d987ad44502d0eb6f9269a55bd4a/lib/amberbit-config/hash_struct.rb#L51-L57
|
10,169
|
andrewpthorp/unchained
|
lib/unchained/request.rb
|
Unchained.Request.get_resource
|
def get_resource(url, resource_class, params={})
resource_class.from_hash(get(url, params), client: self)
end
|
ruby
|
def get_resource(url, resource_class, params={})
resource_class.from_hash(get(url, params), client: self)
end
|
[
"def",
"get_resource",
"(",
"url",
",",
"resource_class",
",",
"params",
"=",
"{",
"}",
")",
"resource_class",
".",
"from_hash",
"(",
"get",
"(",
"url",
",",
"params",
")",
",",
"client",
":",
"self",
")",
"end"
] |
If an API endpoint returns a single resource, not an Array of resources,
we want to use this.
Returns an instance of `resource_class`.
|
[
"If",
"an",
"API",
"endpoint",
"returns",
"a",
"single",
"resource",
"not",
"an",
"Array",
"of",
"resources",
"we",
"want",
"to",
"use",
"this",
"."
] |
54db3bfdb41f141de95df9bb620cbd86de675d07
|
https://github.com/andrewpthorp/unchained/blob/54db3bfdb41f141de95df9bb620cbd86de675d07/lib/unchained/request.rb#L28-L30
|
10,170
|
andrewpthorp/unchained
|
lib/unchained/request.rb
|
Unchained.Request.get_resources
|
def get_resources(url, resource_class, params={})
get(url, params).map do |result|
resource_class.from_hash(result, client: self)
end
end
|
ruby
|
def get_resources(url, resource_class, params={})
get(url, params).map do |result|
resource_class.from_hash(result, client: self)
end
end
|
[
"def",
"get_resources",
"(",
"url",
",",
"resource_class",
",",
"params",
"=",
"{",
"}",
")",
"get",
"(",
"url",
",",
"params",
")",
".",
"map",
"do",
"|",
"result",
"|",
"resource_class",
".",
"from_hash",
"(",
"result",
",",
"client",
":",
"self",
")",
"end",
"end"
] |
If an API endpoint returns an Array of resources, we want to use this.
Returns an array of `resource_classes`.
|
[
"If",
"an",
"API",
"endpoint",
"returns",
"an",
"Array",
"of",
"resources",
"we",
"want",
"to",
"use",
"this",
"."
] |
54db3bfdb41f141de95df9bb620cbd86de675d07
|
https://github.com/andrewpthorp/unchained/blob/54db3bfdb41f141de95df9bb620cbd86de675d07/lib/unchained/request.rb#L35-L39
|
10,171
|
bcantin/auditing
|
lib/auditing/audit_relationship.rb
|
Auditing.AuditRelationship.audit_relationship_enabled
|
def audit_relationship_enabled(opts={})
include InstanceMethods
# class_inheritable_accessor :audit_enabled_models
# class_inheritable_accessor :field_names
class_attribute :audit_enabled_models
class_attribute :field_names
self.audit_enabled_models = gather_models(opts)
self.field_names = gather_assoc_fields_for_auditing(opts[:fields])
after_create :audit_relationship_create
before_update :audit_relationship_update
before_destroy :audit_relationship_destroy
end
|
ruby
|
def audit_relationship_enabled(opts={})
include InstanceMethods
# class_inheritable_accessor :audit_enabled_models
# class_inheritable_accessor :field_names
class_attribute :audit_enabled_models
class_attribute :field_names
self.audit_enabled_models = gather_models(opts)
self.field_names = gather_assoc_fields_for_auditing(opts[:fields])
after_create :audit_relationship_create
before_update :audit_relationship_update
before_destroy :audit_relationship_destroy
end
|
[
"def",
"audit_relationship_enabled",
"(",
"opts",
"=",
"{",
"}",
")",
"include",
"InstanceMethods",
"# class_inheritable_accessor :audit_enabled_models",
"# class_inheritable_accessor :field_names",
"class_attribute",
":audit_enabled_models",
"class_attribute",
":field_names",
"self",
".",
"audit_enabled_models",
"=",
"gather_models",
"(",
"opts",
")",
"self",
".",
"field_names",
"=",
"gather_assoc_fields_for_auditing",
"(",
"opts",
"[",
":fields",
"]",
")",
"after_create",
":audit_relationship_create",
"before_update",
":audit_relationship_update",
"before_destroy",
":audit_relationship_destroy",
"end"
] |
AuditRelationship creates audits for a has_many relationship.
@examples
class Company < ActiveRecord::Base
has_many :phone_numbers
audit_enabled
end
class PhoneNumber < ActiveRecord::Base
belongs_to :company
audit_relationship_enabled
end
valid options include:
:only => [(array of models)]
an array of models to only send an audit to
:except => [(array of models)]
an array of models to not send an audit to
:fields => [(array of field names)]
an array of field names. Each field name will be one audit item
|
[
"AuditRelationship",
"creates",
"audits",
"for",
"a",
"has_many",
"relationship",
"."
] |
495b9e2d465c8263e7709623a003bb933ff540b7
|
https://github.com/bcantin/auditing/blob/495b9e2d465c8263e7709623a003bb933ff540b7/lib/auditing/audit_relationship.rb#L23-L38
|
10,172
|
blambeau/myrrha
|
lib/myrrha/coercions.rb
|
Myrrha.Coercions.delegate
|
def delegate(method, &convproc)
convproc ||= lambda{|v,t| v.send(method) }
upon(lambda{|v,t| v.respond_to?(method) }, convproc)
end
|
ruby
|
def delegate(method, &convproc)
convproc ||= lambda{|v,t| v.send(method) }
upon(lambda{|v,t| v.respond_to?(method) }, convproc)
end
|
[
"def",
"delegate",
"(",
"method",
",",
"&",
"convproc",
")",
"convproc",
"||=",
"lambda",
"{",
"|",
"v",
",",
"t",
"|",
"v",
".",
"send",
"(",
"method",
")",
"}",
"upon",
"(",
"lambda",
"{",
"|",
"v",
",",
"t",
"|",
"v",
".",
"respond_to?",
"(",
"method",
")",
"}",
",",
"convproc",
")",
"end"
] |
Adds an upon rule that works by delegation if the value responds to `method`.
Example:
Myrrha.coercions do |r|
r.delegate(:to_foo)
# is a shortcut for
r.upon(lambda{|v,_| v.respond_to?(:to_foo)}){|v,_| v.to_foo}
end
|
[
"Adds",
"an",
"upon",
"rule",
"that",
"works",
"by",
"delegation",
"if",
"the",
"value",
"responds",
"to",
"method",
"."
] |
302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe
|
https://github.com/blambeau/myrrha/blob/302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe/lib/myrrha/coercions.rb#L100-L103
|
10,173
|
blambeau/myrrha
|
lib/myrrha/coercions.rb
|
Myrrha.Coercions.coercion
|
def coercion(source, target = main_target_domain, converter = nil, &convproc)
@rules.send(@appender, [source, target, converter || convproc])
self
end
|
ruby
|
def coercion(source, target = main_target_domain, converter = nil, &convproc)
@rules.send(@appender, [source, target, converter || convproc])
self
end
|
[
"def",
"coercion",
"(",
"source",
",",
"target",
"=",
"main_target_domain",
",",
"converter",
"=",
"nil",
",",
"&",
"convproc",
")",
"@rules",
".",
"send",
"(",
"@appender",
",",
"[",
"source",
",",
"target",
",",
"converter",
"||",
"convproc",
"]",
")",
"self",
"end"
] |
Adds a coercion rule from a source to a target domain.
The conversion can be provided through `converter` or via a block
directly. See main documentation about recognized converters.
Example:
Myrrha.coercions do |r|
# With an explicit proc
r.coercion String, Integer, lambda{|v,t|
Integer(v)
}
# With an implicit proc
r.coercion(String, Float) do |v,t|
Float(v)
end
end
@param source [Domain] a source domain (mimicing Domain)
@param target [Domain] a target domain (mimicing Domain)
@param converter [Converter] an optional converter (mimic Converter)
@param convproc [Proc] used when converter is not specified
@return self
|
[
"Adds",
"a",
"coercion",
"rule",
"from",
"a",
"source",
"to",
"a",
"target",
"domain",
"."
] |
302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe
|
https://github.com/blambeau/myrrha/blob/302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe/lib/myrrha/coercions.rb#L132-L135
|
10,174
|
blambeau/myrrha
|
lib/myrrha/coercions.rb
|
Myrrha.Coercions.coerce
|
def coerce(value, target_domain = main_target_domain)
return value if belongs_to?(value, target_domain)
error = nil
each_rule do |from,to,converter|
next unless from.nil? or belongs_to?(value, from, target_domain)
begin
catch(:nextrule) do
if to.nil? or subdomain?(to, target_domain)
got = convert(value, target_domain, converter)
return got
elsif subdomain?(target_domain, to)
got = convert(value, target_domain, converter)
return got if belongs_to?(got, target_domain)
end
end
rescue => ex
error = ex unless error
end
end
error_handler.call(value, target_domain, error)
end
|
ruby
|
def coerce(value, target_domain = main_target_domain)
return value if belongs_to?(value, target_domain)
error = nil
each_rule do |from,to,converter|
next unless from.nil? or belongs_to?(value, from, target_domain)
begin
catch(:nextrule) do
if to.nil? or subdomain?(to, target_domain)
got = convert(value, target_domain, converter)
return got
elsif subdomain?(target_domain, to)
got = convert(value, target_domain, converter)
return got if belongs_to?(got, target_domain)
end
end
rescue => ex
error = ex unless error
end
end
error_handler.call(value, target_domain, error)
end
|
[
"def",
"coerce",
"(",
"value",
",",
"target_domain",
"=",
"main_target_domain",
")",
"return",
"value",
"if",
"belongs_to?",
"(",
"value",
",",
"target_domain",
")",
"error",
"=",
"nil",
"each_rule",
"do",
"|",
"from",
",",
"to",
",",
"converter",
"|",
"next",
"unless",
"from",
".",
"nil?",
"or",
"belongs_to?",
"(",
"value",
",",
"from",
",",
"target_domain",
")",
"begin",
"catch",
"(",
":nextrule",
")",
"do",
"if",
"to",
".",
"nil?",
"or",
"subdomain?",
"(",
"to",
",",
"target_domain",
")",
"got",
"=",
"convert",
"(",
"value",
",",
"target_domain",
",",
"converter",
")",
"return",
"got",
"elsif",
"subdomain?",
"(",
"target_domain",
",",
"to",
")",
"got",
"=",
"convert",
"(",
"value",
",",
"target_domain",
",",
"converter",
")",
"return",
"got",
"if",
"belongs_to?",
"(",
"got",
",",
"target_domain",
")",
"end",
"end",
"rescue",
"=>",
"ex",
"error",
"=",
"ex",
"unless",
"error",
"end",
"end",
"error_handler",
".",
"call",
"(",
"value",
",",
"target_domain",
",",
"error",
")",
"end"
] |
Coerces `value` to an element of `target_domain`
This method tries each coercion rule, then each fallback in turn. Rules
for which source and target domain match are executed until one succeeds.
A Myrrha::Error is raised if no rule matches or executes successfuly.
@param [Object] value any ruby value
@param [Domain] target_domain a target domain to convert to (mimic Domain)
@return self
|
[
"Coerces",
"value",
"to",
"an",
"element",
"of",
"target_domain"
] |
302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe
|
https://github.com/blambeau/myrrha/blob/302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe/lib/myrrha/coercions.rb#L170-L190
|
10,175
|
blambeau/myrrha
|
lib/myrrha/coercions.rb
|
Myrrha.Coercions.belongs_to?
|
def belongs_to?(value, domain, target_domain = domain)
if domain.is_a?(Proc) and domain.arity==2
domain.call(value, target_domain)
else
domain.respond_to?(:===) && (domain === value)
end
end
|
ruby
|
def belongs_to?(value, domain, target_domain = domain)
if domain.is_a?(Proc) and domain.arity==2
domain.call(value, target_domain)
else
domain.respond_to?(:===) && (domain === value)
end
end
|
[
"def",
"belongs_to?",
"(",
"value",
",",
"domain",
",",
"target_domain",
"=",
"domain",
")",
"if",
"domain",
".",
"is_a?",
"(",
"Proc",
")",
"and",
"domain",
".",
"arity",
"==",
"2",
"domain",
".",
"call",
"(",
"value",
",",
"target_domain",
")",
"else",
"domain",
".",
"respond_to?",
"(",
":===",
")",
"&&",
"(",
"domain",
"===",
"value",
")",
"end",
"end"
] |
Returns true if `value` can be considered as a valid element of the
domain `domain`, false otherwise.
@param [Object] value any ruby value
@param [Domain] domain a domain (mimic Domain)
@return [Boolean] true if `value` belongs to `domain`, false otherwise
|
[
"Returns",
"true",
"if",
"value",
"can",
"be",
"considered",
"as",
"a",
"valid",
"element",
"of",
"the",
"domain",
"domain",
"false",
"otherwise",
"."
] |
302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe
|
https://github.com/blambeau/myrrha/blob/302f90d1bd6039410cbfbf87e90ff3f4e6abe9fe/lib/myrrha/coercions.rb#L215-L221
|
10,176
|
kynetx/Kynetx-Application-Manager-API
|
lib/kynetx_am_api/application.rb
|
KynetxAmApi.Application.endpoint
|
def endpoint(type, opts={})
options = {
:extname => @name,
:extdesc => "",
:extauthor => @user.name,
:force_build => 'N',
:contents => "compiled",
:format => 'json',
:env => 'prod'
}
# Set type specific options
case type.to_s
when 'bookmarklet'
options[:runtime] = "init.kobj.net/js/shared/kobj-static.js"
when 'info_card'
options[:image_url] = image_url('icard')
options[:datasets] = ""
when 'ie'
options[:appguid] = @guid
end
options.merge!(opts)
puts "ENDPOINT PARAMS: (#{type}): #{options.inspect}" if $DEBUG
return @api.post_app_generate(@application_id, type.to_s, options)
end
|
ruby
|
def endpoint(type, opts={})
options = {
:extname => @name,
:extdesc => "",
:extauthor => @user.name,
:force_build => 'N',
:contents => "compiled",
:format => 'json',
:env => 'prod'
}
# Set type specific options
case type.to_s
when 'bookmarklet'
options[:runtime] = "init.kobj.net/js/shared/kobj-static.js"
when 'info_card'
options[:image_url] = image_url('icard')
options[:datasets] = ""
when 'ie'
options[:appguid] = @guid
end
options.merge!(opts)
puts "ENDPOINT PARAMS: (#{type}): #{options.inspect}" if $DEBUG
return @api.post_app_generate(@application_id, type.to_s, options)
end
|
[
"def",
"endpoint",
"(",
"type",
",",
"opts",
"=",
"{",
"}",
")",
"options",
"=",
"{",
":extname",
"=>",
"@name",
",",
":extdesc",
"=>",
"\"\"",
",",
":extauthor",
"=>",
"@user",
".",
"name",
",",
":force_build",
"=>",
"'N'",
",",
":contents",
"=>",
"\"compiled\"",
",",
":format",
"=>",
"'json'",
",",
":env",
"=>",
"'prod'",
"}",
"# Set type specific options",
"case",
"type",
".",
"to_s",
"when",
"'bookmarklet'",
"options",
"[",
":runtime",
"]",
"=",
"\"init.kobj.net/js/shared/kobj-static.js\"",
"when",
"'info_card'",
"options",
"[",
":image_url",
"]",
"=",
"image_url",
"(",
"'icard'",
")",
"options",
"[",
":datasets",
"]",
"=",
"\"\"",
"when",
"'ie'",
"options",
"[",
":appguid",
"]",
"=",
"@guid",
"end",
"options",
".",
"merge!",
"(",
"opts",
")",
"puts",
"\"ENDPOINT PARAMS: (#{type}): #{options.inspect}\"",
"if",
"$DEBUG",
"return",
"@api",
".",
"post_app_generate",
"(",
"@application_id",
",",
"type",
".",
"to_s",
",",
"options",
")",
"end"
] |
Returns an endpoint
type is a String or Symbol of one of the following:
:chrome
:ie
:firefox
:info_card
:bookmarklet
:sitetags
opts is a Hash of options that has the following keys:
(see Kynetx App Management API documentation on "generate" for more information)
- :extname (endpoint name - defaults to app name.)
- :extauthor (endpoint author - defaults to user generating the endpoint.)
- :extdesc (endpoint description - defaults to empty.)
- :force_build ('Y' or 'N' force a regeneration of the endpoint - defaults to 'N'.)
- :contents ( 'compiled' or 'src' specifies whether you want the endpoint or the source code of the endpoint - defaults to 'compiled'.)
- :format ('url' or 'json' specifies how the endpoint is returned - default is 'json' which returns a Base64 encoded data string.)
- :datasets (used for infocards - defaults to empty)
- :env ('dev' or 'prod' specifies whether to run the development or production version of the app - defaults to 'prod'.)
- :image_url (a fully qualified url to the image that will be used for the infocard. It must be a 240x160 jpg - defaults to a cropped version of the app image in appBuilder.)
- :runtime (specific runtime to be used. This only works with bookmarklets - defaults to init.kobj.net/js/shared/kobj-static.js )
Returns a hash formatted as follows:
{:data => "endpoint as specified in the :format option",
:file_name => "filename.*",
:content_type => 'content type',
:errors => []
}
|
[
"Returns",
"an",
"endpoint"
] |
fe96ad8aca56fef99734416cc3a7d29ee6f24d57
|
https://github.com/kynetx/Kynetx-Application-Manager-API/blob/fe96ad8aca56fef99734416cc3a7d29ee6f24d57/lib/kynetx_am_api/application.rb#L217-L243
|
10,177
|
mark-d-holmberg/handcart
|
app/models/handcart/concerns/handcarts.rb
|
Handcart::Concerns::Handcarts.ClassMethods.handcart_show_path
|
def handcart_show_path(handcart)
if Handcart.handcart_show_path.present?
# Load it straight from the config
"/#{Handcart.handcart_show_path}/#{handcart.to_param}"
else
if Rails.application.routes.url_helpers.respond_to?("#{Handcart.handcart_class.model_name.singular}_path".to_sym)
# Is there one already defined
Rails.application.routes.url_helpers.send("#{Handcart.handcart_class.model_name.singular}_path", handcart.to_param)
else
# Shot in the dark
"/#{Handcart.handcart_class.model_name.route_key}/#{handcart.to_param}"
end
end
end
|
ruby
|
def handcart_show_path(handcart)
if Handcart.handcart_show_path.present?
# Load it straight from the config
"/#{Handcart.handcart_show_path}/#{handcart.to_param}"
else
if Rails.application.routes.url_helpers.respond_to?("#{Handcart.handcart_class.model_name.singular}_path".to_sym)
# Is there one already defined
Rails.application.routes.url_helpers.send("#{Handcart.handcart_class.model_name.singular}_path", handcart.to_param)
else
# Shot in the dark
"/#{Handcart.handcart_class.model_name.route_key}/#{handcart.to_param}"
end
end
end
|
[
"def",
"handcart_show_path",
"(",
"handcart",
")",
"if",
"Handcart",
".",
"handcart_show_path",
".",
"present?",
"# Load it straight from the config",
"\"/#{Handcart.handcart_show_path}/#{handcart.to_param}\"",
"else",
"if",
"Rails",
".",
"application",
".",
"routes",
".",
"url_helpers",
".",
"respond_to?",
"(",
"\"#{Handcart.handcart_class.model_name.singular}_path\"",
".",
"to_sym",
")",
"# Is there one already defined",
"Rails",
".",
"application",
".",
"routes",
".",
"url_helpers",
".",
"send",
"(",
"\"#{Handcart.handcart_class.model_name.singular}_path\"",
",",
"handcart",
".",
"to_param",
")",
"else",
"# Shot in the dark",
"\"/#{Handcart.handcart_class.model_name.route_key}/#{handcart.to_param}\"",
"end",
"end",
"end"
] |
Try to formulate a path to view the handcart show page
|
[
"Try",
"to",
"formulate",
"a",
"path",
"to",
"view",
"the",
"handcart",
"show",
"page"
] |
9f9c7484db007066357c71c9c50f3342aab59c11
|
https://github.com/mark-d-holmberg/handcart/blob/9f9c7484db007066357c71c9c50f3342aab59c11/app/models/handcart/concerns/handcarts.rb#L14-L27
|
10,178
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/post_fields_controller.rb
|
LatoBlog.Back::PostFieldsController.destroy_relay_field
|
def destroy_relay_field
# find post field
child_field = LatoBlog::PostField.find_by(id: params[:id])
@post_field = child_field.post_field
unless @post_field
@error = true
respond_to { |r| r.js }
end
# find post field child and destroy it
unless child_field.destroy
@error = true
respond_to { |r| r.js }
end
# send response to client
@error = false
respond_to { |r| r.js }
end
|
ruby
|
def destroy_relay_field
# find post field
child_field = LatoBlog::PostField.find_by(id: params[:id])
@post_field = child_field.post_field
unless @post_field
@error = true
respond_to { |r| r.js }
end
# find post field child and destroy it
unless child_field.destroy
@error = true
respond_to { |r| r.js }
end
# send response to client
@error = false
respond_to { |r| r.js }
end
|
[
"def",
"destroy_relay_field",
"# find post field",
"child_field",
"=",
"LatoBlog",
"::",
"PostField",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"@post_field",
"=",
"child_field",
".",
"post_field",
"unless",
"@post_field",
"@error",
"=",
"true",
"respond_to",
"{",
"|",
"r",
"|",
"r",
".",
"js",
"}",
"end",
"# find post field child and destroy it",
"unless",
"child_field",
".",
"destroy",
"@error",
"=",
"true",
"respond_to",
"{",
"|",
"r",
"|",
"r",
".",
"js",
"}",
"end",
"# send response to client",
"@error",
"=",
"false",
"respond_to",
"{",
"|",
"r",
"|",
"r",
".",
"js",
"}",
"end"
] |
This function destroy a post for the field.
|
[
"This",
"function",
"destroy",
"a",
"post",
"for",
"the",
"field",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/post_fields_controller.rb#L67-L83
|
10,179
|
dannysmith/guard-shopifytheme
|
lib/guard/shopifytheme.rb
|
Guard.Shopifytheme.start
|
def start
if File.exist? 'config.yml'
Notifier.notify "Watching for changes to Shopify Theme"
else
data = <<-EOF
---
:api_key: YOUR_API_KEY
:password: YOUR_PASSWORD
:store: YOURSHOP.myshopify.com
:theme_id: 'YOUR_THEME_ID'
:ignore_files:
- README.md
- CHANGELOG.md
EOF
File.open('./config.yml', "w") { |file| file.write data }
Notifier.notify "Created config.yml. Remember to add your Shopify details to it."
end
end
|
ruby
|
def start
if File.exist? 'config.yml'
Notifier.notify "Watching for changes to Shopify Theme"
else
data = <<-EOF
---
:api_key: YOUR_API_KEY
:password: YOUR_PASSWORD
:store: YOURSHOP.myshopify.com
:theme_id: 'YOUR_THEME_ID'
:ignore_files:
- README.md
- CHANGELOG.md
EOF
File.open('./config.yml', "w") { |file| file.write data }
Notifier.notify "Created config.yml. Remember to add your Shopify details to it."
end
end
|
[
"def",
"start",
"if",
"File",
".",
"exist?",
"'config.yml'",
"Notifier",
".",
"notify",
"\"Watching for changes to Shopify Theme\"",
"else",
"data",
"=",
"<<-EOF",
"EOF",
"File",
".",
"open",
"(",
"'./config.yml'",
",",
"\"w\"",
")",
"{",
"|",
"file",
"|",
"file",
".",
"write",
"data",
"}",
"Notifier",
".",
"notify",
"\"Created config.yml. Remember to add your Shopify details to it.\"",
"end",
"end"
] |
VERSION = "0.0.1"
Called once when Guard starts. Please override initialize method to init stuff.
@raise [:task_has_failed] when start has failed
@return [Object] the task result
|
[
"VERSION",
"=",
"0",
".",
"0",
".",
"1",
"Called",
"once",
"when",
"Guard",
"starts",
".",
"Please",
"override",
"initialize",
"method",
"to",
"init",
"stuff",
"."
] |
bb30fdb228f8f370ab9a6aa5b819a1347c2c1249
|
https://github.com/dannysmith/guard-shopifytheme/blob/bb30fdb228f8f370ab9a6aa5b819a1347c2c1249/lib/guard/shopifytheme.rb#L20-L37
|
10,180
|
fenton-project/fenton_shell
|
lib/fenton_shell/project.rb
|
FentonShell.Project.create
|
def create(global_options, options)
status, body = project_create(global_options, options)
if status == 201
save_message(create_success_message(body))
true
else
parse_message(body)
false
end
end
|
ruby
|
def create(global_options, options)
status, body = project_create(global_options, options)
if status == 201
save_message(create_success_message(body))
true
else
parse_message(body)
false
end
end
|
[
"def",
"create",
"(",
"global_options",
",",
"options",
")",
"status",
",",
"body",
"=",
"project_create",
"(",
"global_options",
",",
"options",
")",
"if",
"status",
"==",
"201",
"save_message",
"(",
"create_success_message",
"(",
"body",
")",
")",
"true",
"else",
"parse_message",
"(",
"body",
")",
"false",
"end",
"end"
] |
Creates a new project on fenton server by sending a post
request with json from the command line to create the project
@param global_options [Hash] global command line options
@param options [Hash] json fields to send to fenton server
@return [String] success or failure message
|
[
"Creates",
"a",
"new",
"project",
"on",
"fenton",
"server",
"by",
"sending",
"a",
"post",
"request",
"with",
"json",
"from",
"the",
"command",
"line",
"to",
"create",
"the",
"project"
] |
6e1d76186fa7ee7a3be141afad9361e3a3e0ec91
|
https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/project.rb#L15-L25
|
10,181
|
fenton-project/fenton_shell
|
lib/fenton_shell/project.rb
|
FentonShell.Project.project_json
|
def project_json(options)
{
project: {
name: options[:name],
description: options[:description],
passphrase: options[:passphrase],
key: options[:key],
organization: options[:organization]
}
}.to_json
end
|
ruby
|
def project_json(options)
{
project: {
name: options[:name],
description: options[:description],
passphrase: options[:passphrase],
key: options[:key],
organization: options[:organization]
}
}.to_json
end
|
[
"def",
"project_json",
"(",
"options",
")",
"{",
"project",
":",
"{",
"name",
":",
"options",
"[",
":name",
"]",
",",
"description",
":",
"options",
"[",
":description",
"]",
",",
"passphrase",
":",
"options",
"[",
":passphrase",
"]",
",",
"key",
":",
"options",
"[",
":key",
"]",
",",
"organization",
":",
"options",
"[",
":organization",
"]",
"}",
"}",
".",
"to_json",
"end"
] |
Formulates the project json for the post request
@param options [Hash] fields from fenton command line
@return [String] json created from the options hash
|
[
"Formulates",
"the",
"project",
"json",
"for",
"the",
"post",
"request"
] |
6e1d76186fa7ee7a3be141afad9361e3a3e0ec91
|
https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/project.rb#L62-L72
|
10,182
|
thriventures/storage_room_gem
|
lib/storage_room/resource.rb
|
StorageRoom.Resource.reload
|
def reload(url = nil, parameters = {})
httparty = self.class.get(url || self[:@url], StorageRoom.request_options.merge(parameters))
hash = httparty.parsed_response.first[1]
reset!
set_from_response_data(hash)
true
end
|
ruby
|
def reload(url = nil, parameters = {})
httparty = self.class.get(url || self[:@url], StorageRoom.request_options.merge(parameters))
hash = httparty.parsed_response.first[1]
reset!
set_from_response_data(hash)
true
end
|
[
"def",
"reload",
"(",
"url",
"=",
"nil",
",",
"parameters",
"=",
"{",
"}",
")",
"httparty",
"=",
"self",
".",
"class",
".",
"get",
"(",
"url",
"||",
"self",
"[",
":@url",
"]",
",",
"StorageRoom",
".",
"request_options",
".",
"merge",
"(",
"parameters",
")",
")",
"hash",
"=",
"httparty",
".",
"parsed_response",
".",
"first",
"[",
"1",
"]",
"reset!",
"set_from_response_data",
"(",
"hash",
")",
"true",
"end"
] |
Reload an object from the API. Optionally pass an URL.
|
[
"Reload",
"an",
"object",
"from",
"the",
"API",
".",
"Optionally",
"pass",
"an",
"URL",
"."
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/resource.rb#L31-L37
|
10,183
|
d11wtq/rdo
|
lib/rdo/connection.rb
|
RDO.Connection.debug
|
def debug
raise ArgumentError,
"RDO::Connection#debug requires a block" unless block_given?
reset, logger.level = logger.level, Logger::DEBUG
yield
ensure
logger.level = reset
end
|
ruby
|
def debug
raise ArgumentError,
"RDO::Connection#debug requires a block" unless block_given?
reset, logger.level = logger.level, Logger::DEBUG
yield
ensure
logger.level = reset
end
|
[
"def",
"debug",
"raise",
"ArgumentError",
",",
"\"RDO::Connection#debug requires a block\"",
"unless",
"block_given?",
"reset",
",",
"logger",
".",
"level",
"=",
"logger",
".",
"level",
",",
"Logger",
"::",
"DEBUG",
"yield",
"ensure",
"logger",
".",
"level",
"=",
"reset",
"end"
] |
Use debug log level in the context of a block.
|
[
"Use",
"debug",
"log",
"level",
"in",
"the",
"context",
"of",
"a",
"block",
"."
] |
91fe0c70cbce9947b879141c0f1001b8c4eeef19
|
https://github.com/d11wtq/rdo/blob/91fe0c70cbce9947b879141c0f1001b8c4eeef19/lib/rdo/connection.rb#L131-L139
|
10,184
|
d11wtq/rdo
|
lib/rdo/connection.rb
|
RDO.Connection.normalize_options
|
def normalize_options(options)
case options
when Hash
Hash[options.map{|k,v| [k.respond_to?(:to_sym) ? k.to_sym : k, v]}].tap do |opts|
opts[:driver] = opts[:driver].to_s if opts[:driver]
end
when String, URI
parse_connection_uri(options)
else
raise RDO::Exception,
"Unsupported connection argument format: #{options.class.name}"
end
end
|
ruby
|
def normalize_options(options)
case options
when Hash
Hash[options.map{|k,v| [k.respond_to?(:to_sym) ? k.to_sym : k, v]}].tap do |opts|
opts[:driver] = opts[:driver].to_s if opts[:driver]
end
when String, URI
parse_connection_uri(options)
else
raise RDO::Exception,
"Unsupported connection argument format: #{options.class.name}"
end
end
|
[
"def",
"normalize_options",
"(",
"options",
")",
"case",
"options",
"when",
"Hash",
"Hash",
"[",
"options",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"k",
".",
"respond_to?",
"(",
":to_sym",
")",
"?",
"k",
".",
"to_sym",
":",
"k",
",",
"v",
"]",
"}",
"]",
".",
"tap",
"do",
"|",
"opts",
"|",
"opts",
"[",
":driver",
"]",
"=",
"opts",
"[",
":driver",
"]",
".",
"to_s",
"if",
"opts",
"[",
":driver",
"]",
"end",
"when",
"String",
",",
"URI",
"parse_connection_uri",
"(",
"options",
")",
"else",
"raise",
"RDO",
"::",
"Exception",
",",
"\"Unsupported connection argument format: #{options.class.name}\"",
"end",
"end"
] |
Normalizes the given options String or Hash into a Symbol-keyed Hash.
@param [Object] options
either a String, a URI or a Hash
@return [Hash]
a Symbol-keyed Hash
|
[
"Normalizes",
"the",
"given",
"options",
"String",
"or",
"Hash",
"into",
"a",
"Symbol",
"-",
"keyed",
"Hash",
"."
] |
91fe0c70cbce9947b879141c0f1001b8c4eeef19
|
https://github.com/d11wtq/rdo/blob/91fe0c70cbce9947b879141c0f1001b8c4eeef19/lib/rdo/connection.rb#L150-L162
|
10,185
|
vinsol/Unified-Payments
|
lib/generators/unified_payment/install_generator.rb
|
UnifiedPayment.InstallGenerator.create_migrations
|
def create_migrations
Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
name = File.basename(filepath)
template "migrations/#{name}", "db/migrate/#{name}"
sleep 1
end
end
|
ruby
|
def create_migrations
Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
name = File.basename(filepath)
template "migrations/#{name}", "db/migrate/#{name}"
sleep 1
end
end
|
[
"def",
"create_migrations",
"Dir",
"[",
"\"#{self.class.source_root}/migrations/*.rb\"",
"]",
".",
"sort",
".",
"each",
"do",
"|",
"filepath",
"|",
"name",
"=",
"File",
".",
"basename",
"(",
"filepath",
")",
"template",
"\"migrations/#{name}\"",
",",
"\"db/migrate/#{name}\"",
"sleep",
"1",
"end",
"end"
] |
Generator Code. Remember this is just suped-up Thor so methods are executed in order
|
[
"Generator",
"Code",
".",
"Remember",
"this",
"is",
"just",
"suped",
"-",
"up",
"Thor",
"so",
"methods",
"are",
"executed",
"in",
"order"
] |
2cd3f984ce45a2add0a7754aa48d18a2fbf87205
|
https://github.com/vinsol/Unified-Payments/blob/2cd3f984ce45a2add0a7754aa48d18a2fbf87205/lib/generators/unified_payment/install_generator.rb#L18-L24
|
10,186
|
Nanosim-LIG/ffi-bitmask
|
lib/ffi/bitmask.rb
|
FFI.Bitmask.to_native
|
def to_native(query, ctx)
return 0 if query.nil?
flat_query = [query].flatten
flat_query.inject(0) do |val, o|
case o
when Symbol
v = @kv_map[o]
raise ArgumentError, "invalid bitmask value, #{o.inspect}" unless v
val |= v
when Integer
val |= o
when ->(obj) { obj.respond_to?(:to_int) }
val |= o.to_int
else
raise ArgumentError, "invalid bitmask value, #{o.inspect}"
end
end
end
|
ruby
|
def to_native(query, ctx)
return 0 if query.nil?
flat_query = [query].flatten
flat_query.inject(0) do |val, o|
case o
when Symbol
v = @kv_map[o]
raise ArgumentError, "invalid bitmask value, #{o.inspect}" unless v
val |= v
when Integer
val |= o
when ->(obj) { obj.respond_to?(:to_int) }
val |= o.to_int
else
raise ArgumentError, "invalid bitmask value, #{o.inspect}"
end
end
end
|
[
"def",
"to_native",
"(",
"query",
",",
"ctx",
")",
"return",
"0",
"if",
"query",
".",
"nil?",
"flat_query",
"=",
"[",
"query",
"]",
".",
"flatten",
"flat_query",
".",
"inject",
"(",
"0",
")",
"do",
"|",
"val",
",",
"o",
"|",
"case",
"o",
"when",
"Symbol",
"v",
"=",
"@kv_map",
"[",
"o",
"]",
"raise",
"ArgumentError",
",",
"\"invalid bitmask value, #{o.inspect}\"",
"unless",
"v",
"val",
"|=",
"v",
"when",
"Integer",
"val",
"|=",
"o",
"when",
"->",
"(",
"obj",
")",
"{",
"obj",
".",
"respond_to?",
"(",
":to_int",
")",
"}",
"val",
"|=",
"o",
".",
"to_int",
"else",
"raise",
"ArgumentError",
",",
"\"invalid bitmask value, #{o.inspect}\"",
"end",
"end",
"end"
] |
Get the native value of a bitmask
@overload to_native(query, ctx)
@param [Symbol, Integer, #to_int] query
@param ctx unused
@return [Integer] value of a bitmask
@overload to_native(query, ctx)
@param [Array<Symbol, Integer, #to_int>] query
@param ctx unused
@return [Integer] value of a bitmask
|
[
"Get",
"the",
"native",
"value",
"of",
"a",
"bitmask"
] |
ee891f00d28223494e45574c7b6663fc0f67f5ef
|
https://github.com/Nanosim-LIG/ffi-bitmask/blob/ee891f00d28223494e45574c7b6663fc0f67f5ef/lib/ffi/bitmask.rb#L151-L168
|
10,187
|
PeterCamilleri/format_output
|
lib/format_output/builders/column_builder.rb
|
FormatOutput.ColumnBuilder.render
|
def render
results, column_widths = [], get_column_widths
rows.times { |row_index| results << render_row(row_index, column_widths)}
@page_data.clear
results
end
|
ruby
|
def render
results, column_widths = [], get_column_widths
rows.times { |row_index| results << render_row(row_index, column_widths)}
@page_data.clear
results
end
|
[
"def",
"render",
"results",
",",
"column_widths",
"=",
"[",
"]",
",",
"get_column_widths",
"rows",
".",
"times",
"{",
"|",
"row_index",
"|",
"results",
"<<",
"render_row",
"(",
"row_index",
",",
"column_widths",
")",
"}",
"@page_data",
".",
"clear",
"results",
"end"
] |
Render the page as an array of strings.
|
[
"Render",
"the",
"page",
"as",
"an",
"array",
"of",
"strings",
"."
] |
95dac24bd21f618a74bb665a44235491d725e1b7
|
https://github.com/PeterCamilleri/format_output/blob/95dac24bd21f618a74bb665a44235491d725e1b7/lib/format_output/builders/column_builder.rb#L32-L39
|
10,188
|
PeterCamilleri/format_output
|
lib/format_output/builders/column_builder.rb
|
FormatOutput.ColumnBuilder.add_a_row
|
def add_a_row
new_rows = rows + 1
pool, @page_data = @page_data.flatten, []
until pool.empty?
@page_data << pool.shift(new_rows)
end
end
|
ruby
|
def add_a_row
new_rows = rows + 1
pool, @page_data = @page_data.flatten, []
until pool.empty?
@page_data << pool.shift(new_rows)
end
end
|
[
"def",
"add_a_row",
"new_rows",
"=",
"rows",
"+",
"1",
"pool",
",",
"@page_data",
"=",
"@page_data",
".",
"flatten",
",",
"[",
"]",
"until",
"pool",
".",
"empty?",
"@page_data",
"<<",
"pool",
".",
"shift",
"(",
"new_rows",
")",
"end",
"end"
] |
Add a row to the page, moving items as needed.
|
[
"Add",
"a",
"row",
"to",
"the",
"page",
"moving",
"items",
"as",
"needed",
"."
] |
95dac24bd21f618a74bb665a44235491d725e1b7
|
https://github.com/PeterCamilleri/format_output/blob/95dac24bd21f618a74bb665a44235491d725e1b7/lib/format_output/builders/column_builder.rb#L64-L71
|
10,189
|
NUBIC/aker
|
lib/aker/cas/rack_proxy_callback.rb
|
Aker::Cas.RackProxyCallback.call
|
def call(env)
return receive(env) if env["PATH_INFO"] == RECEIVE_PATH
return retrieve(env) if env["PATH_INFO"] == RETRIEVE_PATH
@app.call(env)
end
|
ruby
|
def call(env)
return receive(env) if env["PATH_INFO"] == RECEIVE_PATH
return retrieve(env) if env["PATH_INFO"] == RETRIEVE_PATH
@app.call(env)
end
|
[
"def",
"call",
"(",
"env",
")",
"return",
"receive",
"(",
"env",
")",
"if",
"env",
"[",
"\"PATH_INFO\"",
"]",
"==",
"RECEIVE_PATH",
"return",
"retrieve",
"(",
"env",
")",
"if",
"env",
"[",
"\"PATH_INFO\"",
"]",
"==",
"RETRIEVE_PATH",
"@app",
".",
"call",
"(",
"env",
")",
"end"
] |
Create a new instance of the middleware.
@param [#call] app the next rack application in the chain.
@param [Hash] options
@option options [String] :store the file where the middleware
will store the received PGTs until they are retrieved.
Handles a single request in the manner specified in the class
overview.
@param [Hash] env the rack environment for the request.
@return [Array] an appropriate rack response.
|
[
"Create",
"a",
"new",
"instance",
"of",
"the",
"middleware",
"."
] |
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
|
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/cas/rack_proxy_callback.rb#L66-L70
|
10,190
|
NUBIC/aker
|
lib/aker/cas/rack_proxy_callback.rb
|
Aker::Cas.RackProxyCallback.store_iou
|
def store_iou(pgt_iou, pgt)
pstore = open_pstore
pstore.transaction do
pstore[pgt_iou] = pgt
end
end
|
ruby
|
def store_iou(pgt_iou, pgt)
pstore = open_pstore
pstore.transaction do
pstore[pgt_iou] = pgt
end
end
|
[
"def",
"store_iou",
"(",
"pgt_iou",
",",
"pgt",
")",
"pstore",
"=",
"open_pstore",
"pstore",
".",
"transaction",
"do",
"pstore",
"[",
"pgt_iou",
"]",
"=",
"pgt",
"end",
"end"
] |
Associates the given PGTIOU and PGT.
@param [String] pgt_iou
@param [String] pgt
@return [void]
|
[
"Associates",
"the",
"given",
"PGTIOU",
"and",
"PGT",
"."
] |
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
|
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/cas/rack_proxy_callback.rb#L96-L102
|
10,191
|
NUBIC/aker
|
lib/aker/cas/rack_proxy_callback.rb
|
Aker::Cas.RackProxyCallback.resolve_iou
|
def resolve_iou(pgt_iou)
pstore = open_pstore
pgt = nil
pstore.transaction do
pgt = pstore[pgt_iou]
pstore.delete(pgt_iou) if pgt
end
pgt
end
|
ruby
|
def resolve_iou(pgt_iou)
pstore = open_pstore
pgt = nil
pstore.transaction do
pgt = pstore[pgt_iou]
pstore.delete(pgt_iou) if pgt
end
pgt
end
|
[
"def",
"resolve_iou",
"(",
"pgt_iou",
")",
"pstore",
"=",
"open_pstore",
"pgt",
"=",
"nil",
"pstore",
".",
"transaction",
"do",
"pgt",
"=",
"pstore",
"[",
"pgt_iou",
"]",
"pstore",
".",
"delete",
"(",
"pgt_iou",
")",
"if",
"pgt",
"end",
"pgt",
"end"
] |
Finds the PGT for the given PGTIOU. If there isn't one, it
returns nil. If there is one, it deletes it from the store
before returning it.
@param [String] pgt_iou
@return [String,nil]
|
[
"Finds",
"the",
"PGT",
"for",
"the",
"given",
"PGTIOU",
".",
"If",
"there",
"isn",
"t",
"one",
"it",
"returns",
"nil",
".",
"If",
"there",
"is",
"one",
"it",
"deletes",
"it",
"from",
"the",
"store",
"before",
"returning",
"it",
"."
] |
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
|
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/cas/rack_proxy_callback.rb#L111-L121
|
10,192
|
mhluska/quadrigacx
|
lib/quadrigacx/client/private.rb
|
QuadrigaCX.Private.withdraw
|
def withdraw(coin, params = {})
raise ConfigurationError.new('No coin type specified') unless coin
raise ConfigurationError.new('Invalid coin type specified') unless Coin.valid?(coin)
request(:post, "/#{coin}_withdrawal", params)
end
|
ruby
|
def withdraw(coin, params = {})
raise ConfigurationError.new('No coin type specified') unless coin
raise ConfigurationError.new('Invalid coin type specified') unless Coin.valid?(coin)
request(:post, "/#{coin}_withdrawal", params)
end
|
[
"def",
"withdraw",
"(",
"coin",
",",
"params",
"=",
"{",
"}",
")",
"raise",
"ConfigurationError",
".",
"new",
"(",
"'No coin type specified'",
")",
"unless",
"coin",
"raise",
"ConfigurationError",
".",
"new",
"(",
"'Invalid coin type specified'",
")",
"unless",
"Coin",
".",
"valid?",
"(",
"coin",
")",
"request",
"(",
":post",
",",
"\"/#{coin}_withdrawal\"",
",",
"params",
")",
"end"
] |
Withdrawal of the specified coin type.
coin - The coin type
amount - The amount to withdraw.
address - The coin type's address we will send the amount to.
|
[
"Withdrawal",
"of",
"the",
"specified",
"coin",
"type",
"."
] |
4d83ce3aa21dbe8a80a24efdb1ae40514f014136
|
https://github.com/mhluska/quadrigacx/blob/4d83ce3aa21dbe8a80a24efdb1ae40514f014136/lib/quadrigacx/client/private.rb#L71-L75
|
10,193
|
mhluska/quadrigacx
|
lib/quadrigacx/client/private.rb
|
QuadrigaCX.Private.user_transactions
|
def user_transactions(params = {})
request(:post, '/user_transactions', params).each { |t| t.id = t.id.to_s }
end
|
ruby
|
def user_transactions(params = {})
request(:post, '/user_transactions', params).each { |t| t.id = t.id.to_s }
end
|
[
"def",
"user_transactions",
"(",
"params",
"=",
"{",
"}",
")",
"request",
"(",
":post",
",",
"'/user_transactions'",
",",
"params",
")",
".",
"each",
"{",
"|",
"t",
"|",
"t",
".",
"id",
"=",
"t",
".",
"id",
".",
"to_s",
"}",
"end"
] |
Return a list of user transactions.
offset - optional, skip that many transactions before beginning to return results. Default: 0.
limit - optional, limit result to that many transactions. Default: 50.
sort - optional, sorting by date and time (asc - ascending; desc - descending). Default: desc.
book - optional, if not specified, will default to btc_cad.
|
[
"Return",
"a",
"list",
"of",
"user",
"transactions",
"."
] |
4d83ce3aa21dbe8a80a24efdb1ae40514f014136
|
https://github.com/mhluska/quadrigacx/blob/4d83ce3aa21dbe8a80a24efdb1ae40514f014136/lib/quadrigacx/client/private.rb#L92-L94
|
10,194
|
chetan/bixby-bench
|
lib/bixby/bench.rb
|
Bixby.Bench.label_width
|
def label_width
if !@label_width then
@label_width = @samples.find_all{ |s| Sample === s }.
max{ |a, b| a.label.length <=> b.label.length }.
label.length + 1
@label_width = 40 if @label_width < 40
end
return @label_width
end
|
ruby
|
def label_width
if !@label_width then
@label_width = @samples.find_all{ |s| Sample === s }.
max{ |a, b| a.label.length <=> b.label.length }.
label.length + 1
@label_width = 40 if @label_width < 40
end
return @label_width
end
|
[
"def",
"label_width",
"if",
"!",
"@label_width",
"then",
"@label_width",
"=",
"@samples",
".",
"find_all",
"{",
"|",
"s",
"|",
"Sample",
"===",
"s",
"}",
".",
"max",
"{",
"|",
"a",
",",
"b",
"|",
"a",
".",
"label",
".",
"length",
"<=>",
"b",
".",
"label",
".",
"length",
"}",
".",
"label",
".",
"length",
"+",
"1",
"@label_width",
"=",
"40",
"if",
"@label_width",
"<",
"40",
"end",
"return",
"@label_width",
"end"
] |
Calculate the label padding, taking all labels into account
|
[
"Calculate",
"the",
"label",
"padding",
"taking",
"all",
"labels",
"into",
"account"
] |
488754f5ae88b4e3345b45590b63d77159891b57
|
https://github.com/chetan/bixby-bench/blob/488754f5ae88b4e3345b45590b63d77159891b57/lib/bixby/bench.rb#L71-L81
|
10,195
|
sinisterchipmunk/genspec
|
lib/genspec/matchers.rb
|
GenSpec.Matchers.delete
|
def delete(filename)
within_source_root do
FileUtils.mkdir_p File.dirname(filename)
FileUtils.touch filename
end
generate { expect(File).not_to exist(filename) }
end
|
ruby
|
def delete(filename)
within_source_root do
FileUtils.mkdir_p File.dirname(filename)
FileUtils.touch filename
end
generate { expect(File).not_to exist(filename) }
end
|
[
"def",
"delete",
"(",
"filename",
")",
"within_source_root",
"do",
"FileUtils",
".",
"mkdir_p",
"File",
".",
"dirname",
"(",
"filename",
")",
"FileUtils",
".",
"touch",
"filename",
"end",
"generate",
"{",
"expect",
"(",
"File",
")",
".",
"not_to",
"exist",
"(",
"filename",
")",
"}",
"end"
] |
Makes sure that the generator deletes the named file. This is done by first ensuring that the
file exists in the first place, and then ensuring that it does not exist after the generator
completes its run.
Example:
expect(subject).to delete("path/to/file")
|
[
"Makes",
"sure",
"that",
"the",
"generator",
"deletes",
"the",
"named",
"file",
".",
"This",
"is",
"done",
"by",
"first",
"ensuring",
"that",
"the",
"file",
"exists",
"in",
"the",
"first",
"place",
"and",
"then",
"ensuring",
"that",
"it",
"does",
"not",
"exist",
"after",
"the",
"generator",
"completes",
"its",
"run",
"."
] |
88dcef6bc09d29fe9a26c2782cb643ed6b888549
|
https://github.com/sinisterchipmunk/genspec/blob/88dcef6bc09d29fe9a26c2782cb643ed6b888549/lib/genspec/matchers.rb#L32-L39
|
10,196
|
alexanderbez/sounddrop
|
lib/sounddrop/client.rb
|
SoundDrop.Client.get_client
|
def get_client
init_opts = {
client_id: @CLIENT_ID,
client_secret: @CLIENT_SECRET
}
if username? and password?
init_opts[:username] = @USERNAME
init_opts[:password] = @PASSWORD
end
Soundcloud.new(init_opts)
end
|
ruby
|
def get_client
init_opts = {
client_id: @CLIENT_ID,
client_secret: @CLIENT_SECRET
}
if username? and password?
init_opts[:username] = @USERNAME
init_opts[:password] = @PASSWORD
end
Soundcloud.new(init_opts)
end
|
[
"def",
"get_client",
"init_opts",
"=",
"{",
"client_id",
":",
"@CLIENT_ID",
",",
"client_secret",
":",
"@CLIENT_SECRET",
"}",
"if",
"username?",
"and",
"password?",
"init_opts",
"[",
":username",
"]",
"=",
"@USERNAME",
"init_opts",
"[",
":password",
"]",
"=",
"@PASSWORD",
"end",
"Soundcloud",
".",
"new",
"(",
"init_opts",
")",
"end"
] |
Defines a Soundcloud client object
|
[
"Defines",
"a",
"Soundcloud",
"client",
"object"
] |
563903234cb8a86d2fd8c19f2991437a5dc71d7e
|
https://github.com/alexanderbez/sounddrop/blob/563903234cb8a86d2fd8c19f2991437a5dc71d7e/lib/sounddrop/client.rb#L34-L46
|
10,197
|
alexanderbez/sounddrop
|
lib/sounddrop/client.rb
|
SoundDrop.Client.get_drop
|
def get_drop(url)
sc_track = client.get('/resolve', url: url)
SoundDrop::Drop.new(client: client, track: sc_track)
end
|
ruby
|
def get_drop(url)
sc_track = client.get('/resolve', url: url)
SoundDrop::Drop.new(client: client, track: sc_track)
end
|
[
"def",
"get_drop",
"(",
"url",
")",
"sc_track",
"=",
"client",
".",
"get",
"(",
"'/resolve'",
",",
"url",
":",
"url",
")",
"SoundDrop",
"::",
"Drop",
".",
"new",
"(",
"client",
":",
"client",
",",
"track",
":",
"sc_track",
")",
"end"
] |
Returns a Drop object that contains useful track information.
|
[
"Returns",
"a",
"Drop",
"object",
"that",
"contains",
"useful",
"track",
"information",
"."
] |
563903234cb8a86d2fd8c19f2991437a5dc71d7e
|
https://github.com/alexanderbez/sounddrop/blob/563903234cb8a86d2fd8c19f2991437a5dc71d7e/lib/sounddrop/client.rb#L49-L52
|
10,198
|
marcusbaguley/exception_dog
|
lib/exception_dog/handler.rb
|
ExceptionDog.Handler.format_backtrace
|
def format_backtrace(backtrace)
backtrace ||= []
backtrace[0..BACKTRACE_LINES].collect do |line|
"#{line.gsub(/\n|\`|\'/, '')}".split(//).last(MAX_LINE_LENGTH).join
end
end
|
ruby
|
def format_backtrace(backtrace)
backtrace ||= []
backtrace[0..BACKTRACE_LINES].collect do |line|
"#{line.gsub(/\n|\`|\'/, '')}".split(//).last(MAX_LINE_LENGTH).join
end
end
|
[
"def",
"format_backtrace",
"(",
"backtrace",
")",
"backtrace",
"||=",
"[",
"]",
"backtrace",
"[",
"0",
"..",
"BACKTRACE_LINES",
"]",
".",
"collect",
"do",
"|",
"line",
"|",
"\"#{line.gsub(/\\n|\\`|\\'/, '')}\"",
".",
"split",
"(",
"/",
"/",
")",
".",
"last",
"(",
"MAX_LINE_LENGTH",
")",
".",
"join",
"end",
"end"
] |
remove backticks, single quotes, \n and ensure each line is reasonably small
|
[
"remove",
"backticks",
"single",
"quotes",
"\\",
"n",
"and",
"ensure",
"each",
"line",
"is",
"reasonably",
"small"
] |
33b3a61e842b8d9d1b9c0ce897bf195b90f78e02
|
https://github.com/marcusbaguley/exception_dog/blob/33b3a61e842b8d9d1b9c0ce897bf195b90f78e02/lib/exception_dog/handler.rb#L52-L57
|
10,199
|
chetan/bixby-common
|
lib/bixby-common/command_spec.rb
|
Bixby.CommandSpec.validate
|
def validate(expected_digest)
if not bundle_exists? then
raise BundleNotFound.new("repo = #{@repo}; bundle = #{@bundle}")
end
if not command_exists? then
raise CommandNotFound.new("repo = #{@repo}; bundle = #{@bundle}; command = #{@command}")
end
if self.digest != expected_digest then
raise BundleNotFound, "digest does not match ('#{self.digest}' != '#{expected_digest}')", caller
end
return true
end
|
ruby
|
def validate(expected_digest)
if not bundle_exists? then
raise BundleNotFound.new("repo = #{@repo}; bundle = #{@bundle}")
end
if not command_exists? then
raise CommandNotFound.new("repo = #{@repo}; bundle = #{@bundle}; command = #{@command}")
end
if self.digest != expected_digest then
raise BundleNotFound, "digest does not match ('#{self.digest}' != '#{expected_digest}')", caller
end
return true
end
|
[
"def",
"validate",
"(",
"expected_digest",
")",
"if",
"not",
"bundle_exists?",
"then",
"raise",
"BundleNotFound",
".",
"new",
"(",
"\"repo = #{@repo}; bundle = #{@bundle}\"",
")",
"end",
"if",
"not",
"command_exists?",
"then",
"raise",
"CommandNotFound",
".",
"new",
"(",
"\"repo = #{@repo}; bundle = #{@bundle}; command = #{@command}\"",
")",
"end",
"if",
"self",
".",
"digest",
"!=",
"expected_digest",
"then",
"raise",
"BundleNotFound",
",",
"\"digest does not match ('#{self.digest}' != '#{expected_digest}')\"",
",",
"caller",
"end",
"return",
"true",
"end"
] |
Create new CommandSpec
@param [Hash] params Hash of attributes to initialize with
Validate the existence of this Command on the local system
and compare digest to local version
@param [String] expected_digest
@return [Boolean] returns true if available, else raises error
@raise [BundleNotFound] If bundle doesn't exist or digest does not match
@raise [CommandNotFound] If command doesn't exist
|
[
"Create",
"new",
"CommandSpec"
] |
3fb8829987b115fc53ec820d97a20b4a8c49b4a2
|
https://github.com/chetan/bixby-common/blob/3fb8829987b115fc53ec820d97a20b4a8c49b4a2/lib/bixby-common/command_spec.rb#L34-L46
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.