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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,100 | nathanstitt/erb_latex | lib/erb_latex/template.rb | ErbLatex.Template.compile_latex | def compile_latex
begin
context = @context.new( @partials_path || @view.dirname, @data )
content = ErbLatex::File.evaluate(@view, context.getBinding)
if layout
ErbLatex::File.evaluate(layout_file, context.getBinding{ content })
else
content
end
rescue LocalJumpError=>e
raise LatexError.new( "ERB compile raised #{e.class} on #{@view}", e.backtrace )
end
end | ruby | def compile_latex
begin
context = @context.new( @partials_path || @view.dirname, @data )
content = ErbLatex::File.evaluate(@view, context.getBinding)
if layout
ErbLatex::File.evaluate(layout_file, context.getBinding{ content })
else
content
end
rescue LocalJumpError=>e
raise LatexError.new( "ERB compile raised #{e.class} on #{@view}", e.backtrace )
end
end | [
"def",
"compile_latex",
"begin",
"context",
"=",
"@context",
".",
"new",
"(",
"@partials_path",
"||",
"@view",
".",
"dirname",
",",
"@data",
")",
"content",
"=",
"ErbLatex",
"::",
"File",
".",
"evaluate",
"(",
"@view",
",",
"context",
".",
"getBinding",
")",
"if",
"layout",
"ErbLatex",
"::",
"File",
".",
"evaluate",
"(",
"layout_file",
",",
"context",
".",
"getBinding",
"{",
"content",
"}",
")",
"else",
"content",
"end",
"rescue",
"LocalJumpError",
"=>",
"e",
"raise",
"LatexError",
".",
"new",
"(",
"\"ERB compile raised #{e.class} on #{@view}\"",
",",
"e",
".",
"backtrace",
")",
"end",
"end"
] | Runs the ERB pre-process on the latex file
@return [String] latex with ERB substitutions performed
@raise [LatexError] if the xelatex process does not complete successfully | [
"Runs",
"the",
"ERB",
"pre",
"-",
"process",
"on",
"the",
"latex",
"file"
] | ea74677264b48b72913d5eae9eaac60f4151de8c | https://github.com/nathanstitt/erb_latex/blob/ea74677264b48b72913d5eae9eaac60f4151de8c/lib/erb_latex/template.rb#L117-L129 |
5,101 | nathanstitt/erb_latex | lib/erb_latex/template.rb | ErbLatex.Template.execute_xelatex | def execute_xelatex( latex, dir )
success = false
@log = ''
if @packages_path
ENV['TEXINPUTS'] = "#{@packages_path}:"
end
Open3.popen2e( ErbLatex.config.xelatex_path,
"--no-shell-escape", "-shell-restricted",
"-jobname=output", "-output-directory=#{dir}",
) do |stdin, output, wait_thr|
stdin.write latex
stdin.close
@log = output.read.strip
success = ( 0 == wait_thr.value )
end
success
end | ruby | def execute_xelatex( latex, dir )
success = false
@log = ''
if @packages_path
ENV['TEXINPUTS'] = "#{@packages_path}:"
end
Open3.popen2e( ErbLatex.config.xelatex_path,
"--no-shell-escape", "-shell-restricted",
"-jobname=output", "-output-directory=#{dir}",
) do |stdin, output, wait_thr|
stdin.write latex
stdin.close
@log = output.read.strip
success = ( 0 == wait_thr.value )
end
success
end | [
"def",
"execute_xelatex",
"(",
"latex",
",",
"dir",
")",
"success",
"=",
"false",
"@log",
"=",
"''",
"if",
"@packages_path",
"ENV",
"[",
"'TEXINPUTS'",
"]",
"=",
"\"#{@packages_path}:\"",
"end",
"Open3",
".",
"popen2e",
"(",
"ErbLatex",
".",
"config",
".",
"xelatex_path",
",",
"\"--no-shell-escape\"",
",",
"\"-shell-restricted\"",
",",
"\"-jobname=output\"",
",",
"\"-output-directory=#{dir}\"",
",",
")",
"do",
"|",
"stdin",
",",
"output",
",",
"wait_thr",
"|",
"stdin",
".",
"write",
"latex",
"stdin",
".",
"close",
"@log",
"=",
"output",
".",
"read",
".",
"strip",
"success",
"=",
"(",
"0",
"==",
"wait_thr",
".",
"value",
")",
"end",
"success",
"end"
] | Execute xelatex on the file.
@param latex [String] contents of the template after running ERB on it
@param dir [String] path to the temporary working directory | [
"Execute",
"xelatex",
"on",
"the",
"file",
"."
] | ea74677264b48b72913d5eae9eaac60f4151de8c | https://github.com/nathanstitt/erb_latex/blob/ea74677264b48b72913d5eae9eaac60f4151de8c/lib/erb_latex/template.rb#L141-L158 |
5,102 | wvanbergen/sql_tree | lib/sql_tree/node/update_query.rb | SQLTree::Node.UpdateQuery.to_sql | def to_sql(options = {})
sql = "UPDATE #{table.to_sql(options)} SET "
sql << updates.map { |u| u.to_sql(options) }.join(', ')
sql << " WHERE " << where.to_sql(options) if self.where
sql
end | ruby | def to_sql(options = {})
sql = "UPDATE #{table.to_sql(options)} SET "
sql << updates.map { |u| u.to_sql(options) }.join(', ')
sql << " WHERE " << where.to_sql(options) if self.where
sql
end | [
"def",
"to_sql",
"(",
"options",
"=",
"{",
"}",
")",
"sql",
"=",
"\"UPDATE #{table.to_sql(options)} SET \"",
"sql",
"<<",
"updates",
".",
"map",
"{",
"|",
"u",
"|",
"u",
".",
"to_sql",
"(",
"options",
")",
"}",
".",
"join",
"(",
"', '",
")",
"sql",
"<<",
"\" WHERE \"",
"<<",
"where",
".",
"to_sql",
"(",
"options",
")",
"if",
"self",
".",
"where",
"sql",
"end"
] | Generates the SQL UPDATE query.
@return [String] The SQL update query | [
"Generates",
"the",
"SQL",
"UPDATE",
"query",
"."
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/lib/sql_tree/node/update_query.rb#L25-L30 |
5,103 | tpope/ldaptic | lib/ldaptic/entry.rb | Ldaptic.Entry.attributes | def attributes
(@original_attributes||{}).merge(@attributes).keys.inject({}) do |hash, key|
hash[key] = read_attribute(key)
hash
end
end | ruby | def attributes
(@original_attributes||{}).merge(@attributes).keys.inject({}) do |hash, key|
hash[key] = read_attribute(key)
hash
end
end | [
"def",
"attributes",
"(",
"@original_attributes",
"||",
"{",
"}",
")",
".",
"merge",
"(",
"@attributes",
")",
".",
"keys",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"hash",
",",
"key",
"|",
"hash",
"[",
"key",
"]",
"=",
"read_attribute",
"(",
"key",
")",
"hash",
"end",
"end"
] | Returns a hash of attributes. | [
"Returns",
"a",
"hash",
"of",
"attributes",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/entry.rb#L284-L289 |
5,104 | tpope/ldaptic | lib/ldaptic/entry.rb | Ldaptic.Entry.modify_attribute | def modify_attribute(action, key, *values)
key = Ldaptic.encode(key)
values.flatten!.map! {|v| Ldaptic.encode(v)}
@original_attributes[key] ||= []
virgin = @original_attributes[key].dup
original = Ldaptic::AttributeSet.new(self, key, @original_attributes[key])
original.__send__(action, values)
begin
namespace.modify(dn, [[action, key, values]])
rescue
@original_attributes[key] = virgin
raise $!
end
if @attributes[key]
read_attribute(key).__send__(action, values)
end
self
end | ruby | def modify_attribute(action, key, *values)
key = Ldaptic.encode(key)
values.flatten!.map! {|v| Ldaptic.encode(v)}
@original_attributes[key] ||= []
virgin = @original_attributes[key].dup
original = Ldaptic::AttributeSet.new(self, key, @original_attributes[key])
original.__send__(action, values)
begin
namespace.modify(dn, [[action, key, values]])
rescue
@original_attributes[key] = virgin
raise $!
end
if @attributes[key]
read_attribute(key).__send__(action, values)
end
self
end | [
"def",
"modify_attribute",
"(",
"action",
",",
"key",
",",
"*",
"values",
")",
"key",
"=",
"Ldaptic",
".",
"encode",
"(",
"key",
")",
"values",
".",
"flatten!",
".",
"map!",
"{",
"|",
"v",
"|",
"Ldaptic",
".",
"encode",
"(",
"v",
")",
"}",
"@original_attributes",
"[",
"key",
"]",
"||=",
"[",
"]",
"virgin",
"=",
"@original_attributes",
"[",
"key",
"]",
".",
"dup",
"original",
"=",
"Ldaptic",
"::",
"AttributeSet",
".",
"new",
"(",
"self",
",",
"key",
",",
"@original_attributes",
"[",
"key",
"]",
")",
"original",
".",
"__send__",
"(",
"action",
",",
"values",
")",
"begin",
"namespace",
".",
"modify",
"(",
"dn",
",",
"[",
"[",
"action",
",",
"key",
",",
"values",
"]",
"]",
")",
"rescue",
"@original_attributes",
"[",
"key",
"]",
"=",
"virgin",
"raise",
"$!",
"end",
"if",
"@attributes",
"[",
"key",
"]",
"read_attribute",
"(",
"key",
")",
".",
"__send__",
"(",
"action",
",",
"values",
")",
"end",
"self",
"end"
] | Note the values are not typecast and thus must be strings. | [
"Note",
"the",
"values",
"are",
"not",
"typecast",
"and",
"thus",
"must",
"be",
"strings",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/entry.rb#L316-L333 |
5,105 | tpope/ldaptic | lib/ldaptic/entry.rb | Ldaptic.Entry.method_missing | def method_missing(method, *args, &block)
attribute = Ldaptic.encode(method)
if attribute[-1] == ?=
attribute.chop!
if may_must(attribute)
return write_attribute(attribute, *args, &block)
end
elsif attribute[-1] == ??
attribute.chop!
if may_must(attribute)
if args.empty?
return !read_attribute(attribute).empty?
else
return args.flatten.any? {|arg| compare(attribute, arg)}
end
end
elsif attribute =~ /\A(.*)-before-type-cast\z/ && may_must($1)
return read_attribute($1, *args, &block)
elsif may_must(attribute)
return read_attribute(attribute, *args, &block).one
end
super(method, *args, &block)
end | ruby | def method_missing(method, *args, &block)
attribute = Ldaptic.encode(method)
if attribute[-1] == ?=
attribute.chop!
if may_must(attribute)
return write_attribute(attribute, *args, &block)
end
elsif attribute[-1] == ??
attribute.chop!
if may_must(attribute)
if args.empty?
return !read_attribute(attribute).empty?
else
return args.flatten.any? {|arg| compare(attribute, arg)}
end
end
elsif attribute =~ /\A(.*)-before-type-cast\z/ && may_must($1)
return read_attribute($1, *args, &block)
elsif may_must(attribute)
return read_attribute(attribute, *args, &block).one
end
super(method, *args, &block)
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"attribute",
"=",
"Ldaptic",
".",
"encode",
"(",
"method",
")",
"if",
"attribute",
"[",
"-",
"1",
"]",
"==",
"?=",
"attribute",
".",
"chop!",
"if",
"may_must",
"(",
"attribute",
")",
"return",
"write_attribute",
"(",
"attribute",
",",
"args",
",",
"block",
")",
"end",
"elsif",
"attribute",
"[",
"-",
"1",
"]",
"==",
"??",
"attribute",
".",
"chop!",
"if",
"may_must",
"(",
"attribute",
")",
"if",
"args",
".",
"empty?",
"return",
"!",
"read_attribute",
"(",
"attribute",
")",
".",
"empty?",
"else",
"return",
"args",
".",
"flatten",
".",
"any?",
"{",
"|",
"arg",
"|",
"compare",
"(",
"attribute",
",",
"arg",
")",
"}",
"end",
"end",
"elsif",
"attribute",
"=~",
"/",
"\\A",
"\\z",
"/",
"&&",
"may_must",
"(",
"$1",
")",
"return",
"read_attribute",
"(",
"$1",
",",
"args",
",",
"block",
")",
"elsif",
"may_must",
"(",
"attribute",
")",
"return",
"read_attribute",
"(",
"attribute",
",",
"args",
",",
"block",
")",
".",
"one",
"end",
"super",
"(",
"method",
",",
"args",
",",
"block",
")",
"end"
] | Delegates to +read_attribute+ or +write_attribute+. Pops an element out
of its set if the attribute is marked SINGLE-VALUE. | [
"Delegates",
"to",
"+",
"read_attribute",
"+",
"or",
"+",
"write_attribute",
"+",
".",
"Pops",
"an",
"element",
"out",
"of",
"its",
"set",
"if",
"the",
"attribute",
"is",
"marked",
"SINGLE",
"-",
"VALUE",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/entry.rb#L413-L435 |
5,106 | tpope/ldaptic | lib/ldaptic/entry.rb | Ldaptic.Entry.reload | def reload
new = search(:scope => :base, :limit => true)
@original_attributes = new.instance_variable_get(:@original_attributes)
@attributes = new.instance_variable_get(:@attributes)
@dn = Ldaptic::DN(new.dn, self)
@children = {}
self
end | ruby | def reload
new = search(:scope => :base, :limit => true)
@original_attributes = new.instance_variable_get(:@original_attributes)
@attributes = new.instance_variable_get(:@attributes)
@dn = Ldaptic::DN(new.dn, self)
@children = {}
self
end | [
"def",
"reload",
"new",
"=",
"search",
"(",
":scope",
"=>",
":base",
",",
":limit",
"=>",
"true",
")",
"@original_attributes",
"=",
"new",
".",
"instance_variable_get",
"(",
":@original_attributes",
")",
"@attributes",
"=",
"new",
".",
"instance_variable_get",
"(",
":@attributes",
")",
"@dn",
"=",
"Ldaptic",
"::",
"DN",
"(",
"new",
".",
"dn",
",",
"self",
")",
"@children",
"=",
"{",
"}",
"self",
"end"
] | Refetches the attributes from the server. | [
"Refetches",
"the",
"attributes",
"from",
"the",
"server",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/entry.rb#L550-L557 |
5,107 | MattRyder/tableau | lib/tableau/timetableparser.rb | Tableau.TimetableParser.sort_classes | def sort_classes(timetable, classes)
classes.each do |c|
if !(cmodule = timetable.module_for_code(c.code))
cmodule = Tableau::Module.new(c.code)
timetable.push_module(cmodule)
end
cmodule.add_class(c)
end
end | ruby | def sort_classes(timetable, classes)
classes.each do |c|
if !(cmodule = timetable.module_for_code(c.code))
cmodule = Tableau::Module.new(c.code)
timetable.push_module(cmodule)
end
cmodule.add_class(c)
end
end | [
"def",
"sort_classes",
"(",
"timetable",
",",
"classes",
")",
"classes",
".",
"each",
"do",
"|",
"c",
"|",
"if",
"!",
"(",
"cmodule",
"=",
"timetable",
".",
"module_for_code",
"(",
"c",
".",
"code",
")",
")",
"cmodule",
"=",
"Tableau",
"::",
"Module",
".",
"new",
"(",
"c",
".",
"code",
")",
"timetable",
".",
"push_module",
"(",
"cmodule",
")",
"end",
"cmodule",
".",
"add_class",
"(",
"c",
")",
"end",
"end"
] | Sort all the parsed classes into modules | [
"Sort",
"all",
"the",
"parsed",
"classes",
"into",
"modules"
] | a313fa88bf165ca66cb564c14abd3e526d6c1494 | https://github.com/MattRyder/tableau/blob/a313fa88bf165ca66cb564c14abd3e526d6c1494/lib/tableau/timetableparser.rb#L42-L51 |
5,108 | siuying/itunes-auto-ingestion | lib/itunes_ingestion/fetcher.rb | ITunesIngestion.Fetcher.fetch | def fetch(options={})
params = {
:USERNAME => @username, :PASSWORD => @password, :VNDNUMBER => @vadnumber
}
params[:TYPEOFREPORT] = options[:type_of_report] || REPORT_TYPE_SALES
params[:DATETYPE] = options[:date_type] || DATE_TYPE_DAILY
params[:REPORTTYPE] = options[:report_type] || REPORT_SUMMARY
params[:REPORTDATE] = options[:report_date] || (Time.now-60*60*24).strftime("%Y%m%d")
response = RestClient.post BASE_URL, params
if response.headers[:"errormsg"]
raise ITunesConnectError.new response.headers[:"errormsg"]
elsif response.headers[:"filename"]
Zlib::GzipReader.new(StringIO.new(response.body)).read
else
raise "no data returned from itunes: #{response.body}"
end
end | ruby | def fetch(options={})
params = {
:USERNAME => @username, :PASSWORD => @password, :VNDNUMBER => @vadnumber
}
params[:TYPEOFREPORT] = options[:type_of_report] || REPORT_TYPE_SALES
params[:DATETYPE] = options[:date_type] || DATE_TYPE_DAILY
params[:REPORTTYPE] = options[:report_type] || REPORT_SUMMARY
params[:REPORTDATE] = options[:report_date] || (Time.now-60*60*24).strftime("%Y%m%d")
response = RestClient.post BASE_URL, params
if response.headers[:"errormsg"]
raise ITunesConnectError.new response.headers[:"errormsg"]
elsif response.headers[:"filename"]
Zlib::GzipReader.new(StringIO.new(response.body)).read
else
raise "no data returned from itunes: #{response.body}"
end
end | [
"def",
"fetch",
"(",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"{",
":USERNAME",
"=>",
"@username",
",",
":PASSWORD",
"=>",
"@password",
",",
":VNDNUMBER",
"=>",
"@vadnumber",
"}",
"params",
"[",
":TYPEOFREPORT",
"]",
"=",
"options",
"[",
":type_of_report",
"]",
"||",
"REPORT_TYPE_SALES",
"params",
"[",
":DATETYPE",
"]",
"=",
"options",
"[",
":date_type",
"]",
"||",
"DATE_TYPE_DAILY",
"params",
"[",
":REPORTTYPE",
"]",
"=",
"options",
"[",
":report_type",
"]",
"||",
"REPORT_SUMMARY",
"params",
"[",
":REPORTDATE",
"]",
"=",
"options",
"[",
":report_date",
"]",
"||",
"(",
"Time",
".",
"now",
"-",
"60",
"*",
"60",
"*",
"24",
")",
".",
"strftime",
"(",
"\"%Y%m%d\"",
")",
"response",
"=",
"RestClient",
".",
"post",
"BASE_URL",
",",
"params",
"if",
"response",
".",
"headers",
"[",
":\"",
"\"",
"]",
"raise",
"ITunesConnectError",
".",
"new",
"response",
".",
"headers",
"[",
":\"",
"\"",
"]",
"elsif",
"response",
".",
"headers",
"[",
":\"",
"\"",
"]",
"Zlib",
"::",
"GzipReader",
".",
"new",
"(",
"StringIO",
".",
"new",
"(",
"response",
".",
"body",
")",
")",
".",
"read",
"else",
"raise",
"\"no data returned from itunes: #{response.body}\"",
"end",
"end"
] | Create new instance of Fetcher
username - username
password - password
vadnumber - vadnumber
Fetch and unzip report from itunes connect
options - Hash of options:
- :type_of_report can only be REPORT_TYPE_SALES at the moment
- :date_type either DATE_TYPE_DAILY or DATE_TYPE_WEEKLY, default DATE_TYPE_DAILY
- :report_type either REPORT_OPT_IN or REPORT_SUMMARY, default REPORT_SUMMARY
- :report_date date in YYYYMMDD
Returns text file downloaded and unzipped from iTunes | [
"Create",
"new",
"instance",
"of",
"Fetcher"
] | 2bfd5cb4a12b68a352a0b0191f831845c65b84e2 | https://github.com/siuying/itunes-auto-ingestion/blob/2bfd5cb4a12b68a352a0b0191f831845c65b84e2/lib/itunes_ingestion/fetcher.rb#L35-L52 |
5,109 | nathanstitt/erb_latex | lib/erb_latex/context.rb | ErbLatex.Context.partial | def partial( template, data={} )
context = self.class.new( @directory, data )
ErbLatex::File.evaluate(Pathname.new(template), context.getBinding, @directory)
end | ruby | def partial( template, data={} )
context = self.class.new( @directory, data )
ErbLatex::File.evaluate(Pathname.new(template), context.getBinding, @directory)
end | [
"def",
"partial",
"(",
"template",
",",
"data",
"=",
"{",
"}",
")",
"context",
"=",
"self",
".",
"class",
".",
"new",
"(",
"@directory",
",",
"data",
")",
"ErbLatex",
"::",
"File",
".",
"evaluate",
"(",
"Pathname",
".",
"new",
"(",
"template",
")",
",",
"context",
".",
"getBinding",
",",
"@directory",
")",
"end"
] | create new Context
@param directory [String] directory to use as a base for finding partials
@param data [Hash]
include another latex file into the current template | [
"create",
"new",
"Context"
] | ea74677264b48b72913d5eae9eaac60f4151de8c | https://github.com/nathanstitt/erb_latex/blob/ea74677264b48b72913d5eae9eaac60f4151de8c/lib/erb_latex/context.rb#L32-L35 |
5,110 | Kuniri/kuniri | lib/kuniri/language/container_data/structured_and_oo/class_data.rb | Languages.ClassData.add_attribute | def add_attribute(pAttribute)
pAttribute.each do |attributeElement|
next unless attributeElement.is_a?(Languages::AttributeData)
@attributes.push(attributeElement)
end
end | ruby | def add_attribute(pAttribute)
pAttribute.each do |attributeElement|
next unless attributeElement.is_a?(Languages::AttributeData)
@attributes.push(attributeElement)
end
end | [
"def",
"add_attribute",
"(",
"pAttribute",
")",
"pAttribute",
".",
"each",
"do",
"|",
"attributeElement",
"|",
"next",
"unless",
"attributeElement",
".",
"is_a?",
"(",
"Languages",
"::",
"AttributeData",
")",
"@attributes",
".",
"push",
"(",
"attributeElement",
")",
"end",
"end"
] | Add attribute to class data, notice the possibility of call this
method more than one time.
@param pAttribute Attribute to be added inside class. This attribute
is a list of AttributeData. | [
"Add",
"attribute",
"to",
"class",
"data",
"notice",
"the",
"possibility",
"of",
"call",
"this",
"method",
"more",
"than",
"one",
"time",
"."
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/language/container_data/structured_and_oo/class_data.rb#L37-L42 |
5,111 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.bundles_set | def bundles_set(bundle_or_name, tags = [])
params = prepare_bundles_set_params(bundle_or_name, tags)
response = request(API_PATH_BUNDLES_SET, params)
parse_and_eval_execution_response(response.body)
end | ruby | def bundles_set(bundle_or_name, tags = [])
params = prepare_bundles_set_params(bundle_or_name, tags)
response = request(API_PATH_BUNDLES_SET, params)
parse_and_eval_execution_response(response.body)
end | [
"def",
"bundles_set",
"(",
"bundle_or_name",
",",
"tags",
"=",
"[",
"]",
")",
"params",
"=",
"prepare_bundles_set_params",
"(",
"bundle_or_name",
",",
"tags",
")",
"response",
"=",
"request",
"(",
"API_PATH_BUNDLES_SET",
",",
"params",
")",
"parse_and_eval_execution_response",
"(",
"response",
".",
"body",
")",
"end"
] | Assignes a set of tags to a single bundle,
wipes away previous settings for bundle.
# create from a bundle
d.bundles_set(WWW::Delicious::Bundle.new('MyBundle'), %w(foo bar))
# create from a string
d.bundles_set('MyBundle', %w(foo bar))
Raises:: WWW::Delicious::Error
Raises:: WWW::Delicious::HTTPError
Raises:: WWW::Delicious::ResponseError | [
"Assignes",
"a",
"set",
"of",
"tags",
"to",
"a",
"single",
"bundle",
"wipes",
"away",
"previous",
"settings",
"for",
"bundle",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L296-L300 |
5,112 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.tags_rename | def tags_rename(from_name_or_tag, to_name_or_tag)
params = prepare_tags_rename_params(from_name_or_tag, to_name_or_tag)
response = request(API_PATH_TAGS_RENAME, params)
parse_and_eval_execution_response(response.body)
end | ruby | def tags_rename(from_name_or_tag, to_name_or_tag)
params = prepare_tags_rename_params(from_name_or_tag, to_name_or_tag)
response = request(API_PATH_TAGS_RENAME, params)
parse_and_eval_execution_response(response.body)
end | [
"def",
"tags_rename",
"(",
"from_name_or_tag",
",",
"to_name_or_tag",
")",
"params",
"=",
"prepare_tags_rename_params",
"(",
"from_name_or_tag",
",",
"to_name_or_tag",
")",
"response",
"=",
"request",
"(",
"API_PATH_TAGS_RENAME",
",",
"params",
")",
"parse_and_eval_execution_response",
"(",
"response",
".",
"body",
")",
"end"
] | Renames an existing tag with a new tag name.
# rename from a tag
d.bundles_set(WWW::Delicious::Tag.new('old'), WWW::Delicious::Tag.new('new'))
# rename from a string
d.bundles_set('old', 'new')
Raises:: WWW::Delicious::Error
Raises:: WWW::Delicious::HTTPError
Raises:: WWW::Delicious::ResponseError | [
"Renames",
"an",
"existing",
"tag",
"with",
"a",
"new",
"tag",
"name",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L358-L362 |
5,113 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.posts_recent | def posts_recent(options = {})
params = prepare_posts_params(options.clone, [:count, :tag])
response = request(API_PATH_POSTS_RECENT, params)
parse_post_collection(response.body)
end | ruby | def posts_recent(options = {})
params = prepare_posts_params(options.clone, [:count, :tag])
response = request(API_PATH_POSTS_RECENT, params)
parse_post_collection(response.body)
end | [
"def",
"posts_recent",
"(",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"prepare_posts_params",
"(",
"options",
".",
"clone",
",",
"[",
":count",
",",
":tag",
"]",
")",
"response",
"=",
"request",
"(",
"API_PATH_POSTS_RECENT",
",",
"params",
")",
"parse_post_collection",
"(",
"response",
".",
"body",
")",
"end"
] | Returns a list of the most recent posts, filtered by argument.
# get the most recent posts
d.posts_recent()
# get the 10 most recent posts
d.posts_recent(:count => 10)
=== Options
<tt>:tag</tt>:: a tag to filter by. It can be either a <tt>WWW::Delicious::Tag</tt> or a +String+.
<tt>:count</tt>:: number of items to retrieve. (default: 15, maximum: 100). | [
"Returns",
"a",
"list",
"of",
"the",
"most",
"recent",
"posts",
"filtered",
"by",
"argument",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L412-L416 |
5,114 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.posts_all | def posts_all(options = {})
params = prepare_posts_params(options.clone, [:tag])
response = request(API_PATH_POSTS_ALL, params)
parse_post_collection(response.body)
end | ruby | def posts_all(options = {})
params = prepare_posts_params(options.clone, [:tag])
response = request(API_PATH_POSTS_ALL, params)
parse_post_collection(response.body)
end | [
"def",
"posts_all",
"(",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"prepare_posts_params",
"(",
"options",
".",
"clone",
",",
"[",
":tag",
"]",
")",
"response",
"=",
"request",
"(",
"API_PATH_POSTS_ALL",
",",
"params",
")",
"parse_post_collection",
"(",
"response",
".",
"body",
")",
"end"
] | Returns a list of all posts, filtered by argument.
# get all (this is a very expensive query)
d.posts_all
# get all posts matching ruby
d.posts_all(:tag => WWW::Delicious::Tag.new('ruby'))
=== Options
<tt>:tag</tt>:: a tag to filter by. It can be either a <tt>WWW::Delicious::Tag</tt> or a +String+. | [
"Returns",
"a",
"list",
"of",
"all",
"posts",
"filtered",
"by",
"argument",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L431-L435 |
5,115 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.posts_dates | def posts_dates(options = {})
params = prepare_posts_params(options.clone, [:tag])
response = request(API_PATH_POSTS_DATES, params)
parse_posts_dates_response(response.body)
end | ruby | def posts_dates(options = {})
params = prepare_posts_params(options.clone, [:tag])
response = request(API_PATH_POSTS_DATES, params)
parse_posts_dates_response(response.body)
end | [
"def",
"posts_dates",
"(",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"prepare_posts_params",
"(",
"options",
".",
"clone",
",",
"[",
":tag",
"]",
")",
"response",
"=",
"request",
"(",
"API_PATH_POSTS_DATES",
",",
"params",
")",
"parse_posts_dates_response",
"(",
"response",
".",
"body",
")",
"end"
] | Returns a list of dates with the number of posts at each date.
# get number of posts per date
d.posts_dates
# => { '2008-05-05' => 12, '2008-05-06' => 3, ... }
# get number posts per date tagged as ruby
d.posts_dates(:tag => WWW::Delicious::Tag.new('ruby'))
# => { '2008-05-05' => 10, '2008-05-06' => 3, ... }
=== Options
<tt>:tag</tt>:: a tag to filter by. It can be either a <tt>WWW::Delicious::Tag</tt> or a +String+. | [
"Returns",
"a",
"list",
"of",
"dates",
"with",
"the",
"number",
"of",
"posts",
"at",
"each",
"date",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L452-L456 |
5,116 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.posts_delete | def posts_delete(url)
params = prepare_posts_params({ :url => url }, [:url])
response = request(API_PATH_POSTS_DELETE, params)
parse_and_eval_execution_response(response.body)
end | ruby | def posts_delete(url)
params = prepare_posts_params({ :url => url }, [:url])
response = request(API_PATH_POSTS_DELETE, params)
parse_and_eval_execution_response(response.body)
end | [
"def",
"posts_delete",
"(",
"url",
")",
"params",
"=",
"prepare_posts_params",
"(",
"{",
":url",
"=>",
"url",
"}",
",",
"[",
":url",
"]",
")",
"response",
"=",
"request",
"(",
"API_PATH_POSTS_DELETE",
",",
"params",
")",
"parse_and_eval_execution_response",
"(",
"response",
".",
"body",
")",
"end"
] | Deletes the post matching given +url+ from del.icio.us.
+url+ can be either an URI instance or a string representation of a valid URL.
This method doesn't care whether a post with given +url+ exists.
If not, the execution will silently return without rising any error.
# delete a post from URI
d.post_delete(URI.parse('http://www.foobar.com/'))
# delete a post from a string
d.post_delete('http://www.foobar.com/') | [
"Deletes",
"the",
"post",
"matching",
"given",
"+",
"url",
"+",
"from",
"del",
".",
"icio",
".",
"us",
".",
"+",
"url",
"+",
"can",
"be",
"either",
"an",
"URI",
"instance",
"or",
"a",
"string",
"representation",
"of",
"a",
"valid",
"URL",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L491-L495 |
5,117 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.init_http_client | def init_http_client(options)
http = Net::HTTP.new(@base_uri.host, 443)
http.use_ssl = true if @base_uri.scheme == "https"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # FIXME: not 100% supported
self.http_client = http
end | ruby | def init_http_client(options)
http = Net::HTTP.new(@base_uri.host, 443)
http.use_ssl = true if @base_uri.scheme == "https"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # FIXME: not 100% supported
self.http_client = http
end | [
"def",
"init_http_client",
"(",
"options",
")",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"@base_uri",
".",
"host",
",",
"443",
")",
"http",
".",
"use_ssl",
"=",
"true",
"if",
"@base_uri",
".",
"scheme",
"==",
"\"https\"",
"http",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"# FIXME: not 100% supported",
"self",
".",
"http_client",
"=",
"http",
"end"
] | Initializes the HTTP client.
It automatically enable +use_ssl+ flag according to +@base_uri+ scheme. | [
"Initializes",
"the",
"HTTP",
"client",
".",
"It",
"automatically",
"enable",
"+",
"use_ssl",
"+",
"flag",
"according",
"to",
"+"
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L502-L507 |
5,118 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.http_build_query | def http_build_query(params = {})
params.collect do |k,v|
"#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" unless v.nil?
end.compact.join('&')
end | ruby | def http_build_query(params = {})
params.collect do |k,v|
"#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" unless v.nil?
end.compact.join('&')
end | [
"def",
"http_build_query",
"(",
"params",
"=",
"{",
"}",
")",
"params",
".",
"collect",
"do",
"|",
"k",
",",
"v",
"|",
"\"#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}\"",
"unless",
"v",
".",
"nil?",
"end",
".",
"compact",
".",
"join",
"(",
"'&'",
")",
"end"
] | Composes an HTTP query string from an hash of +options+.
The result is URI encoded.
http_build_query(:foo => 'baa', :bar => 'boo')
# => foo=baa&bar=boo | [
"Composes",
"an",
"HTTP",
"query",
"string",
"from",
"an",
"hash",
"of",
"+",
"options",
"+",
".",
"The",
"result",
"is",
"URI",
"encoded",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L540-L544 |
5,119 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.request | def request(path, params = {})
raise Error, 'Invalid HTTP Client' unless http_client
wait_before_new_request
uri = @base_uri.merge(path)
uri.query = http_build_query(params) unless params.empty?
begin
@last_request = Time.now # see #wait_before_new_request
@last_request_uri = uri # useful for debug
response = make_request(uri)
rescue => e # catch EOFError, SocketError and more
raise HTTPError, e.message
end
case response
when Net::HTTPSuccess
response
when Net::HTTPUnauthorized # 401
raise HTTPError, 'Invalid username or password'
when Net::HTTPServiceUnavailable # 503
raise HTTPError, 'You have been throttled.' +
'Please ensure you are waiting at least one second before each request.'
else
raise HTTPError, "HTTP #{response.code}: #{response.message}"
end
end | ruby | def request(path, params = {})
raise Error, 'Invalid HTTP Client' unless http_client
wait_before_new_request
uri = @base_uri.merge(path)
uri.query = http_build_query(params) unless params.empty?
begin
@last_request = Time.now # see #wait_before_new_request
@last_request_uri = uri # useful for debug
response = make_request(uri)
rescue => e # catch EOFError, SocketError and more
raise HTTPError, e.message
end
case response
when Net::HTTPSuccess
response
when Net::HTTPUnauthorized # 401
raise HTTPError, 'Invalid username or password'
when Net::HTTPServiceUnavailable # 503
raise HTTPError, 'You have been throttled.' +
'Please ensure you are waiting at least one second before each request.'
else
raise HTTPError, "HTTP #{response.code}: #{response.message}"
end
end | [
"def",
"request",
"(",
"path",
",",
"params",
"=",
"{",
"}",
")",
"raise",
"Error",
",",
"'Invalid HTTP Client'",
"unless",
"http_client",
"wait_before_new_request",
"uri",
"=",
"@base_uri",
".",
"merge",
"(",
"path",
")",
"uri",
".",
"query",
"=",
"http_build_query",
"(",
"params",
")",
"unless",
"params",
".",
"empty?",
"begin",
"@last_request",
"=",
"Time",
".",
"now",
"# see #wait_before_new_request",
"@last_request_uri",
"=",
"uri",
"# useful for debug",
"response",
"=",
"make_request",
"(",
"uri",
")",
"rescue",
"=>",
"e",
"# catch EOFError, SocketError and more",
"raise",
"HTTPError",
",",
"e",
".",
"message",
"end",
"case",
"response",
"when",
"Net",
"::",
"HTTPSuccess",
"response",
"when",
"Net",
"::",
"HTTPUnauthorized",
"# 401",
"raise",
"HTTPError",
",",
"'Invalid username or password'",
"when",
"Net",
"::",
"HTTPServiceUnavailable",
"# 503",
"raise",
"HTTPError",
",",
"'You have been throttled.'",
"+",
"'Please ensure you are waiting at least one second before each request.'",
"else",
"raise",
"HTTPError",
",",
"\"HTTP #{response.code}: #{response.message}\"",
"end",
"end"
] | Sends an HTTP GET request to +path+ and appends given +params+.
This method is 100% compliant with Delicious API reference.
It waits at least 1 second between each HTTP request and
provides an identifiable user agent by default,
or the custom user agent set by +user_agent+ option
when this instance has been created.
request('/v1/api/path', :foo => 1, :bar => 2)
# => sends a GET request to /v1/api/path?foo=1&bar=2 | [
"Sends",
"an",
"HTTP",
"GET",
"request",
"to",
"+",
"path",
"+",
"and",
"appends",
"given",
"+",
"params",
"+",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L558-L584 |
5,120 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.make_request | def make_request(uri)
http_client.start do |http|
req = Net::HTTP::Get.new(uri.request_uri, @headers)
req.basic_auth(@username, @password)
http.request(req)
end
end | ruby | def make_request(uri)
http_client.start do |http|
req = Net::HTTP::Get.new(uri.request_uri, @headers)
req.basic_auth(@username, @password)
http.request(req)
end
end | [
"def",
"make_request",
"(",
"uri",
")",
"http_client",
".",
"start",
"do",
"|",
"http",
"|",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"uri",
".",
"request_uri",
",",
"@headers",
")",
"req",
".",
"basic_auth",
"(",
"@username",
",",
"@password",
")",
"http",
".",
"request",
"(",
"req",
")",
"end",
"end"
] | Makes the real HTTP request to given +uri+ and returns the +response+.
This method exists basically to simplify unit testing with mocha. | [
"Makes",
"the",
"real",
"HTTP",
"request",
"to",
"given",
"+",
"uri",
"+",
"and",
"returns",
"the",
"+",
"response",
"+",
".",
"This",
"method",
"exists",
"basically",
"to",
"simplify",
"unit",
"testing",
"with",
"mocha",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L588-L594 |
5,121 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.parse_update_response | def parse_update_response(body)
dom = parse_and_validate_response(body, :root_name => 'update')
dom.root.if_attribute_value(:time) { |v| Time.parse(v) }
end | ruby | def parse_update_response(body)
dom = parse_and_validate_response(body, :root_name => 'update')
dom.root.if_attribute_value(:time) { |v| Time.parse(v) }
end | [
"def",
"parse_update_response",
"(",
"body",
")",
"dom",
"=",
"parse_and_validate_response",
"(",
"body",
",",
":root_name",
"=>",
"'update'",
")",
"dom",
".",
"root",
".",
"if_attribute_value",
"(",
":time",
")",
"{",
"|",
"v",
"|",
"Time",
".",
"parse",
"(",
"v",
")",
"}",
"end"
] | Parses the response of an Update request
and returns the update Timestamp. | [
"Parses",
"the",
"response",
"of",
"an",
"Update",
"request",
"and",
"returns",
"the",
"update",
"Timestamp",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L652-L655 |
5,122 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.prepare_tags_rename_params | def prepare_tags_rename_params(from_name_or_tag, to_name_or_tag)
from, to = [from_name_or_tag, to_name_or_tag].collect do |v|
prepare_param_tag(v)
end
{ :old => from, :new => to }
end | ruby | def prepare_tags_rename_params(from_name_or_tag, to_name_or_tag)
from, to = [from_name_or_tag, to_name_or_tag].collect do |v|
prepare_param_tag(v)
end
{ :old => from, :new => to }
end | [
"def",
"prepare_tags_rename_params",
"(",
"from_name_or_tag",
",",
"to_name_or_tag",
")",
"from",
",",
"to",
"=",
"[",
"from_name_or_tag",
",",
"to_name_or_tag",
"]",
".",
"collect",
"do",
"|",
"v",
"|",
"prepare_param_tag",
"(",
"v",
")",
"end",
"{",
":old",
"=>",
"from",
",",
":new",
"=>",
"to",
"}",
"end"
] | Prepares the params for a `tags_rename` call
and returns a Hash with the params ready for the HTTP request.
Raises:: WWW::Delicious::Error | [
"Prepares",
"the",
"params",
"for",
"a",
"tags_rename",
"call",
"and",
"returns",
"a",
"Hash",
"with",
"the",
"params",
"ready",
"for",
"the",
"HTTP",
"request",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L723-L728 |
5,123 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.prepare_param_post | def prepare_param_post(post_or_values, &block)
post = case post_or_values
when WWW::Delicious::Post
post_or_values
when Hash
Post.new(post_or_values)
else
raise ArgumentError, 'Expected `args` to be `WWW::Delicious::Post` or `Hash`'
end
yield(post) if block_given?
# TODO: validate post with post.validate!
raise ArgumentError, 'Both `url` and `title` are required' unless post.api_valid?
post
end | ruby | def prepare_param_post(post_or_values, &block)
post = case post_or_values
when WWW::Delicious::Post
post_or_values
when Hash
Post.new(post_or_values)
else
raise ArgumentError, 'Expected `args` to be `WWW::Delicious::Post` or `Hash`'
end
yield(post) if block_given?
# TODO: validate post with post.validate!
raise ArgumentError, 'Both `url` and `title` are required' unless post.api_valid?
post
end | [
"def",
"prepare_param_post",
"(",
"post_or_values",
",",
"&",
"block",
")",
"post",
"=",
"case",
"post_or_values",
"when",
"WWW",
"::",
"Delicious",
"::",
"Post",
"post_or_values",
"when",
"Hash",
"Post",
".",
"new",
"(",
"post_or_values",
")",
"else",
"raise",
"ArgumentError",
",",
"'Expected `args` to be `WWW::Delicious::Post` or `Hash`'",
"end",
"yield",
"(",
"post",
")",
"if",
"block_given?",
"# TODO: validate post with post.validate!",
"raise",
"ArgumentError",
",",
"'Both `url` and `title` are required'",
"unless",
"post",
".",
"api_valid?",
"post",
"end"
] | Prepares the +post+ param for an API request.
Creates and returns a <tt>WWW::Delicious::Post</tt> instance from <tt>post_or_values</tt>.
<tt>post_or_values</tt> can be either an Hash with post attributes
or a <tt>WWW::Delicious::Post</tt> instance. | [
"Prepares",
"the",
"+",
"post",
"+",
"param",
"for",
"an",
"API",
"request",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L764-L778 |
5,124 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.prepare_param_bundle | def prepare_param_bundle(name_or_bundle, tags = [], &block) # :yields: bundle
bundle = case name_or_bundle
when WWW::Delicious::Bundle
name_or_bundle
else
Bundle.new(:name => name_or_bundle, :tags => tags)
end
yield(bundle) if block_given?
# TODO: validate bundle with bundle.validate!
bundle
end | ruby | def prepare_param_bundle(name_or_bundle, tags = [], &block) # :yields: bundle
bundle = case name_or_bundle
when WWW::Delicious::Bundle
name_or_bundle
else
Bundle.new(:name => name_or_bundle, :tags => tags)
end
yield(bundle) if block_given?
# TODO: validate bundle with bundle.validate!
bundle
end | [
"def",
"prepare_param_bundle",
"(",
"name_or_bundle",
",",
"tags",
"=",
"[",
"]",
",",
"&",
"block",
")",
"# :yields: bundle",
"bundle",
"=",
"case",
"name_or_bundle",
"when",
"WWW",
"::",
"Delicious",
"::",
"Bundle",
"name_or_bundle",
"else",
"Bundle",
".",
"new",
"(",
":name",
"=>",
"name_or_bundle",
",",
":tags",
"=>",
"tags",
")",
"end",
"yield",
"(",
"bundle",
")",
"if",
"block_given?",
"# TODO: validate bundle with bundle.validate!",
"bundle",
"end"
] | Prepares the +bundle+ param for an API request.
Creates and returns a <tt>WWW::Delicious::Bundle</tt> instance from <tt>name_or_bundle</tt>.
<tt>name_or_bundle</tt> can be either a string holding bundle name
or a <tt>WWW::Delicious::Bundle</tt> instance. | [
"Prepares",
"the",
"+",
"bundle",
"+",
"param",
"for",
"an",
"API",
"request",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L787-L798 |
5,125 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.prepare_param_tag | def prepare_param_tag(name_or_tag, &block) # :yields: tag
tag = case name_or_tag
when WWW::Delicious::Tag
name_or_tag
else
Tag.new(:name => name_or_tag.to_s)
end
yield(tag) if block_given?
# TODO: validate tag with tag.validate!
raise "Invalid `tag` value supplied" unless tag.api_valid?
tag
end | ruby | def prepare_param_tag(name_or_tag, &block) # :yields: tag
tag = case name_or_tag
when WWW::Delicious::Tag
name_or_tag
else
Tag.new(:name => name_or_tag.to_s)
end
yield(tag) if block_given?
# TODO: validate tag with tag.validate!
raise "Invalid `tag` value supplied" unless tag.api_valid?
tag
end | [
"def",
"prepare_param_tag",
"(",
"name_or_tag",
",",
"&",
"block",
")",
"# :yields: tag",
"tag",
"=",
"case",
"name_or_tag",
"when",
"WWW",
"::",
"Delicious",
"::",
"Tag",
"name_or_tag",
"else",
"Tag",
".",
"new",
"(",
":name",
"=>",
"name_or_tag",
".",
"to_s",
")",
"end",
"yield",
"(",
"tag",
")",
"if",
"block_given?",
"# TODO: validate tag with tag.validate!",
"raise",
"\"Invalid `tag` value supplied\"",
"unless",
"tag",
".",
"api_valid?",
"tag",
"end"
] | Prepares the +tag+ param for an API request.
Creates and returns a <tt>WWW::Delicious::Tag</tt> instance from <tt>name_or_tag</tt>.
<tt>name_or_tag</tt> can be either a string holding tag name
or a <tt>WWW::Delicious::Tag</tt> instance. | [
"Prepares",
"the",
"+",
"tag",
"+",
"param",
"for",
"an",
"API",
"request",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L807-L819 |
5,126 | weppos/www-delicious | lib/www/delicious.rb | WWW.Delicious.compare_params | def compare_params(params, valid_params)
raise ArgumentError, "Expected `params` to be a kind of `Hash`" unless params.kind_of?(Hash)
raise ArgumentError, "Expected `valid_params` to be a kind of `Array`" unless valid_params.kind_of?(Array)
# compute options difference
difference = params.keys - valid_params
raise Error, "Invalid params: `#{difference.join('`, `')}`" unless difference.empty?
end | ruby | def compare_params(params, valid_params)
raise ArgumentError, "Expected `params` to be a kind of `Hash`" unless params.kind_of?(Hash)
raise ArgumentError, "Expected `valid_params` to be a kind of `Array`" unless valid_params.kind_of?(Array)
# compute options difference
difference = params.keys - valid_params
raise Error, "Invalid params: `#{difference.join('`, `')}`" unless difference.empty?
end | [
"def",
"compare_params",
"(",
"params",
",",
"valid_params",
")",
"raise",
"ArgumentError",
",",
"\"Expected `params` to be a kind of `Hash`\"",
"unless",
"params",
".",
"kind_of?",
"(",
"Hash",
")",
"raise",
"ArgumentError",
",",
"\"Expected `valid_params` to be a kind of `Array`\"",
"unless",
"valid_params",
".",
"kind_of?",
"(",
"Array",
")",
"# compute options difference",
"difference",
"=",
"params",
".",
"keys",
"-",
"valid_params",
"raise",
"Error",
",",
"\"Invalid params: `#{difference.join('`, `')}`\"",
"unless",
"difference",
".",
"empty?",
"end"
] | Checks whether user given +params+ are valid against a defined collection of +valid_params+.
=== Examples
params = {:foo => 1, :bar => 2}
compare_params(params, [:foo, :bar])
# => valid
compare_params(params, [:foo, :bar, :baz])
# => raises
compare_params(params, [:foo])
# => raises
Raises:: WWW::Delicious::Error | [
"Checks",
"whether",
"user",
"given",
"+",
"params",
"+",
"are",
"valid",
"against",
"a",
"defined",
"collection",
"of",
"+",
"valid_params",
"+",
"."
] | 68006915fdca50af7868e12b0fa93f62b01e0f9f | https://github.com/weppos/www-delicious/blob/68006915fdca50af7868e12b0fa93f62b01e0f9f/lib/www/delicious.rb#L839-L846 |
5,127 | pengwynn/groupon | lib/groupon/client.rb | Groupon.Client.deals | def deals(query={})
division = query.delete(:division)
query.merge! :client_id => @api_key
path = division ? "/#{division}" : ""
path += "/deals.json"
self.class.get(path, :query => query).deals
end | ruby | def deals(query={})
division = query.delete(:division)
query.merge! :client_id => @api_key
path = division ? "/#{division}" : ""
path += "/deals.json"
self.class.get(path, :query => query).deals
end | [
"def",
"deals",
"(",
"query",
"=",
"{",
"}",
")",
"division",
"=",
"query",
".",
"delete",
"(",
":division",
")",
"query",
".",
"merge!",
":client_id",
"=>",
"@api_key",
"path",
"=",
"division",
"?",
"\"/#{division}\"",
":",
"\"\"",
"path",
"+=",
"\"/deals.json\"",
"self",
".",
"class",
".",
"get",
"(",
"path",
",",
":query",
"=>",
"query",
")",
".",
"deals",
"end"
] | Returns a list of deals.
The API returns an ordered list of deals currently running for a given Division.
Priority is based on position within the response (top deals are higher in priority).
@see http://sites.google.com/site/grouponapi/divisions-api Groupon API docs
@option options [String] :lat (Latitudinal coordinates based on IP of API request) Latitude of geolocation to find deals
@option options [String] :lng (Longtitudinal coordinates based on IP of API request) Longitude of geolocation to find deals
@return [Array<Hashie::Mash>] an array of deals | [
"Returns",
"a",
"list",
"of",
"deals",
"."
] | 6f778cc71bf51a559c40038822d90cc7cacca0b7 | https://github.com/pengwynn/groupon/blob/6f778cc71bf51a559c40038822d90cc7cacca0b7/lib/groupon/client.rb#L40-L46 |
5,128 | groupon/sycl | lib/sycl.rb | Sycl.Array.[]= | def []=(*args) # :nodoc:
raise ArgumentError => 'wrong number of arguments' unless args.size > 1
unless args[-1].is_a?(Sycl::Hash) || args[-1].is_a?(Sycl::Array)
args[-1] = Sycl::from_object(args[-1])
end
super
end | ruby | def []=(*args) # :nodoc:
raise ArgumentError => 'wrong number of arguments' unless args.size > 1
unless args[-1].is_a?(Sycl::Hash) || args[-1].is_a?(Sycl::Array)
args[-1] = Sycl::from_object(args[-1])
end
super
end | [
"def",
"[]=",
"(",
"*",
"args",
")",
"# :nodoc:",
"raise",
"ArgumentError",
"=>",
"'wrong number of arguments'",
"unless",
"args",
".",
"size",
">",
"1",
"unless",
"args",
"[",
"-",
"1",
"]",
".",
"is_a?",
"(",
"Sycl",
"::",
"Hash",
")",
"||",
"args",
"[",
"-",
"1",
"]",
".",
"is_a?",
"(",
"Sycl",
"::",
"Array",
")",
"args",
"[",
"-",
"1",
"]",
"=",
"Sycl",
"::",
"from_object",
"(",
"args",
"[",
"-",
"1",
"]",
")",
"end",
"super",
"end"
] | Make sure that if we write to this array, we promote any inputs
to their Sycl equivalents. This lets dot notation, styled YAML,
and other Sycl goodies continue. | [
"Make",
"sure",
"that",
"if",
"we",
"write",
"to",
"this",
"array",
"we",
"promote",
"any",
"inputs",
"to",
"their",
"Sycl",
"equivalents",
".",
"This",
"lets",
"dot",
"notation",
"styled",
"YAML",
"and",
"other",
"Sycl",
"goodies",
"continue",
"."
] | 1efa291503b212d69355c2fbf6c1f2588e15068d | https://github.com/groupon/sycl/blob/1efa291503b212d69355c2fbf6c1f2588e15068d/lib/sycl.rb#L179-L185 |
5,129 | groupon/sycl | lib/sycl.rb | Sycl.Hash.[]= | def []=(k, v) # :nodoc:
unless v.is_a?(Sycl::Hash) || v.is_a?(Sycl::Array)
v = Sycl::from_object(v)
end
super
end | ruby | def []=(k, v) # :nodoc:
unless v.is_a?(Sycl::Hash) || v.is_a?(Sycl::Array)
v = Sycl::from_object(v)
end
super
end | [
"def",
"[]=",
"(",
"k",
",",
"v",
")",
"# :nodoc:",
"unless",
"v",
".",
"is_a?",
"(",
"Sycl",
"::",
"Hash",
")",
"||",
"v",
".",
"is_a?",
"(",
"Sycl",
"::",
"Array",
")",
"v",
"=",
"Sycl",
"::",
"from_object",
"(",
"v",
")",
"end",
"super",
"end"
] | Make sure that if we write to this hash, we promote any inputs
to their Sycl equivalents. This lets dot notation, styled YAML,
and other Sycl goodies continue. | [
"Make",
"sure",
"that",
"if",
"we",
"write",
"to",
"this",
"hash",
"we",
"promote",
"any",
"inputs",
"to",
"their",
"Sycl",
"equivalents",
".",
"This",
"lets",
"dot",
"notation",
"styled",
"YAML",
"and",
"other",
"Sycl",
"goodies",
"continue",
"."
] | 1efa291503b212d69355c2fbf6c1f2588e15068d | https://github.com/groupon/sycl/blob/1efa291503b212d69355c2fbf6c1f2588e15068d/lib/sycl.rb#L467-L472 |
5,130 | vigetlabs/stat_board | lib/stat_board/graph_helper.rb | StatBoard.GraphHelper.first_day_of | def first_day_of(klass_name)
klass = klass_name.to_s.constantize
klass.order("created_at ASC").first.try(:created_at) || Time.now
end | ruby | def first_day_of(klass_name)
klass = klass_name.to_s.constantize
klass.order("created_at ASC").first.try(:created_at) || Time.now
end | [
"def",
"first_day_of",
"(",
"klass_name",
")",
"klass",
"=",
"klass_name",
".",
"to_s",
".",
"constantize",
"klass",
".",
"order",
"(",
"\"created_at ASC\"",
")",
".",
"first",
".",
"try",
"(",
":created_at",
")",
"||",
"Time",
".",
"now",
"end"
] | returns the earliest `created_at` of a given class
returns `Time.now` if none is available | [
"returns",
"the",
"earliest",
"created_at",
"of",
"a",
"given",
"class",
"returns",
"Time",
".",
"now",
"if",
"none",
"is",
"available"
] | c3486280cc86d48de88f8ddb1a506a855650f7fe | https://github.com/vigetlabs/stat_board/blob/c3486280cc86d48de88f8ddb1a506a855650f7fe/lib/stat_board/graph_helper.rb#L53-L56 |
5,131 | darbylabs/magma | lib/magma/utils.rb | Magma.Utils.read_file_or_stdin | def read_file_or_stdin(filename = nil)
filename.nil? ? !STDIN.tty? && STDIN.read : File.read(filename)
end | ruby | def read_file_or_stdin(filename = nil)
filename.nil? ? !STDIN.tty? && STDIN.read : File.read(filename)
end | [
"def",
"read_file_or_stdin",
"(",
"filename",
"=",
"nil",
")",
"filename",
".",
"nil?",
"?",
"!",
"STDIN",
".",
"tty?",
"&&",
"STDIN",
".",
"read",
":",
"File",
".",
"read",
"(",
"filename",
")",
"end"
] | Reads a file or from STDIN if piped | [
"Reads",
"a",
"file",
"or",
"from",
"STDIN",
"if",
"piped"
] | 62da478396fb479786f109128b6f65dd85b7c04c | https://github.com/darbylabs/magma/blob/62da478396fb479786f109128b6f65dd85b7c04c/lib/magma/utils.rb#L6-L8 |
5,132 | darbylabs/magma | lib/magma/utils.rb | Magma.Utils.run | def run(*args, &block)
return Open3.popen3(*args, &block) if block_given?
Open3.popen3(*args)
end | ruby | def run(*args, &block)
return Open3.popen3(*args, &block) if block_given?
Open3.popen3(*args)
end | [
"def",
"run",
"(",
"*",
"args",
",",
"&",
"block",
")",
"return",
"Open3",
".",
"popen3",
"(",
"args",
",",
"block",
")",
"if",
"block_given?",
"Open3",
".",
"popen3",
"(",
"args",
")",
"end"
] | Delegates to Open3 | [
"Delegates",
"to",
"Open3"
] | 62da478396fb479786f109128b6f65dd85b7c04c | https://github.com/darbylabs/magma/blob/62da478396fb479786f109128b6f65dd85b7c04c/lib/magma/utils.rb#L34-L37 |
5,133 | darbylabs/magma | lib/magma/utils.rb | Magma.Utils.symbolize_keys | def symbolize_keys(hash)
hash.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v }
end | ruby | def symbolize_keys(hash)
hash.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v }
end | [
"def",
"symbolize_keys",
"(",
"hash",
")",
"hash",
".",
"each_with_object",
"(",
"{",
"}",
")",
"{",
"|",
"(",
"k",
",",
"v",
")",
",",
"memo",
"|",
"memo",
"[",
"k",
".",
"to_sym",
"]",
"=",
"v",
"}",
"end"
] | Symbolizes a hash's keys | [
"Symbolizes",
"a",
"hash",
"s",
"keys"
] | 62da478396fb479786f109128b6f65dd85b7c04c | https://github.com/darbylabs/magma/blob/62da478396fb479786f109128b6f65dd85b7c04c/lib/magma/utils.rb#L40-L42 |
5,134 | rschultheis/tcfg | lib/tcfg/tcfg_helper.rb | TCFG.Helper.tcfg_get | def tcfg_get(key)
t_tcfg = tcfg
unless t_tcfg.key? key
raise NoSuchConfigurationKeyError, "No configuration defined for '#{key}'"
end
t_tcfg[key]
end | ruby | def tcfg_get(key)
t_tcfg = tcfg
unless t_tcfg.key? key
raise NoSuchConfigurationKeyError, "No configuration defined for '#{key}'"
end
t_tcfg[key]
end | [
"def",
"tcfg_get",
"(",
"key",
")",
"t_tcfg",
"=",
"tcfg",
"unless",
"t_tcfg",
".",
"key?",
"key",
"raise",
"NoSuchConfigurationKeyError",
",",
"\"No configuration defined for '#{key}'\"",
"end",
"t_tcfg",
"[",
"key",
"]",
"end"
] | return a single piece of configuration by key
@param key [String] the configuration to return
@return [String, Integer, FixNum, Array, Hash] the value of the configuration from the resolved configuration | [
"return",
"a",
"single",
"piece",
"of",
"configuration",
"by",
"key"
] | 7016ee3a70404d468e20efc39b7ee8d37f288b19 | https://github.com/rschultheis/tcfg/blob/7016ee3a70404d468e20efc39b7ee8d37f288b19/lib/tcfg/tcfg_helper.rb#L121-L127 |
5,135 | Kuniri/kuniri | lib/kuniri/language/language_factory.rb | Languages.LanguageFactory.get_language | def get_language(pType)
pType.downcase!
return Languages::RubySyntax.new if pType == 'ruby'
# if pType == "python"
# raise Error::LanguageError
# end
# if pType == "vhdl"
# raise Error::LanguageError
# end
# if pType == "c"
# raise Error::LanguageError
# end
# if pType == "cplusplus"
# raise Error::LanguageError
# end
# if pType == "java"
# raise Error::LanguageError
# end
# if pType == "assemblyarm"
# raise Error::LanguageError
# end
# if pType == "php"
# raise Error::LanguageError
raise Error::LanguageError
end | ruby | def get_language(pType)
pType.downcase!
return Languages::RubySyntax.new if pType == 'ruby'
# if pType == "python"
# raise Error::LanguageError
# end
# if pType == "vhdl"
# raise Error::LanguageError
# end
# if pType == "c"
# raise Error::LanguageError
# end
# if pType == "cplusplus"
# raise Error::LanguageError
# end
# if pType == "java"
# raise Error::LanguageError
# end
# if pType == "assemblyarm"
# raise Error::LanguageError
# end
# if pType == "php"
# raise Error::LanguageError
raise Error::LanguageError
end | [
"def",
"get_language",
"(",
"pType",
")",
"pType",
".",
"downcase!",
"return",
"Languages",
"::",
"RubySyntax",
".",
"new",
"if",
"pType",
"==",
"'ruby'",
"# if pType == \"python\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"vhdl\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"c\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"cplusplus\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"java\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"assemblyarm\"",
"# raise Error::LanguageError",
"# end",
"# if pType == \"php\"",
"# raise Error::LanguageError",
"raise",
"Error",
"::",
"LanguageError",
"end"
] | Handling the class creation.
@param pType [String] Type of object
@return Return an object of language. | [
"Handling",
"the",
"class",
"creation",
"."
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/language/language_factory.rb#L19-L44 |
5,136 | bdurand/json_record | lib/json_record/embedded_document_array.rb | JsonRecord.EmbeddedDocumentArray.concat | def concat (objects)
objects = objects.collect do |obj|
obj = @klass.new(obj) if obj.is_a?(Hash)
raise ArgumentError.new("#{obj.inspect} is not a #{@klass}") unless obj.is_a?(@klass)
obj.parent = @parent
obj
end
super(objects)
end | ruby | def concat (objects)
objects = objects.collect do |obj|
obj = @klass.new(obj) if obj.is_a?(Hash)
raise ArgumentError.new("#{obj.inspect} is not a #{@klass}") unless obj.is_a?(@klass)
obj.parent = @parent
obj
end
super(objects)
end | [
"def",
"concat",
"(",
"objects",
")",
"objects",
"=",
"objects",
".",
"collect",
"do",
"|",
"obj",
"|",
"obj",
"=",
"@klass",
".",
"new",
"(",
"obj",
")",
"if",
"obj",
".",
"is_a?",
"(",
"Hash",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"#{obj.inspect} is not a #{@klass}\"",
")",
"unless",
"obj",
".",
"is_a?",
"(",
"@klass",
")",
"obj",
".",
"parent",
"=",
"@parent",
"obj",
"end",
"super",
"(",
"objects",
")",
"end"
] | Concatenate an array of objects to the array. The objects must either be an EmbeddedDocument of the
correct class, or a Hash. | [
"Concatenate",
"an",
"array",
"of",
"objects",
"to",
"the",
"array",
".",
"The",
"objects",
"must",
"either",
"be",
"an",
"EmbeddedDocument",
"of",
"the",
"correct",
"class",
"or",
"a",
"Hash",
"."
] | 463f4719d9618f6d2406c0aab6028e0156f7c775 | https://github.com/bdurand/json_record/blob/463f4719d9618f6d2406c0aab6028e0156f7c775/lib/json_record/embedded_document_array.rb#L34-L42 |
5,137 | bdurand/json_record | lib/json_record/embedded_document_array.rb | JsonRecord.EmbeddedDocumentArray.build | def build (obj)
obj = @klass.new(obj) if obj.is_a?(Hash)
raise ArgumentError.new("#{obj.inspect} is not a #{@klass}") unless obj.is_a?(@klass)
obj.parent = @parent
self << obj
obj
end | ruby | def build (obj)
obj = @klass.new(obj) if obj.is_a?(Hash)
raise ArgumentError.new("#{obj.inspect} is not a #{@klass}") unless obj.is_a?(@klass)
obj.parent = @parent
self << obj
obj
end | [
"def",
"build",
"(",
"obj",
")",
"obj",
"=",
"@klass",
".",
"new",
"(",
"obj",
")",
"if",
"obj",
".",
"is_a?",
"(",
"Hash",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"#{obj.inspect} is not a #{@klass}\"",
")",
"unless",
"obj",
".",
"is_a?",
"(",
"@klass",
")",
"obj",
".",
"parent",
"=",
"@parent",
"self",
"<<",
"obj",
"obj",
"end"
] | Similar add an EmbeddedDocument to the array and return the object. If the object passed
in is a Hash, it will be used to make a new EmbeddedDocument. | [
"Similar",
"add",
"an",
"EmbeddedDocument",
"to",
"the",
"array",
"and",
"return",
"the",
"object",
".",
"If",
"the",
"object",
"passed",
"in",
"is",
"a",
"Hash",
"it",
"will",
"be",
"used",
"to",
"make",
"a",
"new",
"EmbeddedDocument",
"."
] | 463f4719d9618f6d2406c0aab6028e0156f7c775 | https://github.com/bdurand/json_record/blob/463f4719d9618f6d2406c0aab6028e0156f7c775/lib/json_record/embedded_document_array.rb#L46-L52 |
5,138 | ronyv89/skydrive | lib/skydrive/client.rb | Skydrive.Client.put | def put url, body=nil, options={}
response = filtered_response(self.class.put(url, { :body => body, :query => options, headers: { 'content-type' => ''} }))
end | ruby | def put url, body=nil, options={}
response = filtered_response(self.class.put(url, { :body => body, :query => options, headers: { 'content-type' => ''} }))
end | [
"def",
"put",
"url",
",",
"body",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
"response",
"=",
"filtered_response",
"(",
"self",
".",
"class",
".",
"put",
"(",
"url",
",",
"{",
":body",
"=>",
"body",
",",
":query",
"=>",
"options",
",",
"headers",
":",
"{",
"'content-type'",
"=>",
"''",
"}",
"}",
")",
")",
"end"
] | Do a put request
@param [String] url the url to put
@param [Hash] options Additonal options to be passed | [
"Do",
"a",
"put",
"request"
] | 6cf7b692f64c6f00a81bc7ca6fffca3020244072 | https://github.com/ronyv89/skydrive/blob/6cf7b692f64c6f00a81bc7ca6fffca3020244072/lib/skydrive/client.rb#L44-L46 |
5,139 | ronyv89/skydrive | lib/skydrive/client.rb | Skydrive.Client.filtered_response | def filtered_response response
raise Skydrive::Error.new({"code" => "no_response_received", "message" => "Request didn't make through or response not received"}) unless response
if response.success?
filtered_response = response.parsed_response
if response.response.code =~ /(201|200)/
raise Skydrive::Error.new(filtered_response["error"]) if filtered_response["error"]
if filtered_response["data"]
return Skydrive::Collection.new(self, filtered_response["data"])
elsif filtered_response["id"] && (filtered_response["id"].match /^comment\..+/)
return Skydrive::Comment.new(self, filtered_response)
elsif filtered_response["id"] && (filtered_response["id"].match /^file\..+/)
return Skydrive::File.new(self, filtered_response)
elsif filtered_response["type"]
return "Skydrive::#{filtered_response["type"].capitalize}".constantize.new(self, filtered_response)
else
return filtered_response
end
else
return true
end
else
raise Skydrive::Error.new("code" => "http_error_#{response.response.code}", "message" => response.response.message)
end
end | ruby | def filtered_response response
raise Skydrive::Error.new({"code" => "no_response_received", "message" => "Request didn't make through or response not received"}) unless response
if response.success?
filtered_response = response.parsed_response
if response.response.code =~ /(201|200)/
raise Skydrive::Error.new(filtered_response["error"]) if filtered_response["error"]
if filtered_response["data"]
return Skydrive::Collection.new(self, filtered_response["data"])
elsif filtered_response["id"] && (filtered_response["id"].match /^comment\..+/)
return Skydrive::Comment.new(self, filtered_response)
elsif filtered_response["id"] && (filtered_response["id"].match /^file\..+/)
return Skydrive::File.new(self, filtered_response)
elsif filtered_response["type"]
return "Skydrive::#{filtered_response["type"].capitalize}".constantize.new(self, filtered_response)
else
return filtered_response
end
else
return true
end
else
raise Skydrive::Error.new("code" => "http_error_#{response.response.code}", "message" => response.response.message)
end
end | [
"def",
"filtered_response",
"response",
"raise",
"Skydrive",
"::",
"Error",
".",
"new",
"(",
"{",
"\"code\"",
"=>",
"\"no_response_received\"",
",",
"\"message\"",
"=>",
"\"Request didn't make through or response not received\"",
"}",
")",
"unless",
"response",
"if",
"response",
".",
"success?",
"filtered_response",
"=",
"response",
".",
"parsed_response",
"if",
"response",
".",
"response",
".",
"code",
"=~",
"/",
"/",
"raise",
"Skydrive",
"::",
"Error",
".",
"new",
"(",
"filtered_response",
"[",
"\"error\"",
"]",
")",
"if",
"filtered_response",
"[",
"\"error\"",
"]",
"if",
"filtered_response",
"[",
"\"data\"",
"]",
"return",
"Skydrive",
"::",
"Collection",
".",
"new",
"(",
"self",
",",
"filtered_response",
"[",
"\"data\"",
"]",
")",
"elsif",
"filtered_response",
"[",
"\"id\"",
"]",
"&&",
"(",
"filtered_response",
"[",
"\"id\"",
"]",
".",
"match",
"/",
"\\.",
"/",
")",
"return",
"Skydrive",
"::",
"Comment",
".",
"new",
"(",
"self",
",",
"filtered_response",
")",
"elsif",
"filtered_response",
"[",
"\"id\"",
"]",
"&&",
"(",
"filtered_response",
"[",
"\"id\"",
"]",
".",
"match",
"/",
"\\.",
"/",
")",
"return",
"Skydrive",
"::",
"File",
".",
"new",
"(",
"self",
",",
"filtered_response",
")",
"elsif",
"filtered_response",
"[",
"\"type\"",
"]",
"return",
"\"Skydrive::#{filtered_response[\"type\"].capitalize}\"",
".",
"constantize",
".",
"new",
"(",
"self",
",",
"filtered_response",
")",
"else",
"return",
"filtered_response",
"end",
"else",
"return",
"true",
"end",
"else",
"raise",
"Skydrive",
"::",
"Error",
".",
"new",
"(",
"\"code\"",
"=>",
"\"http_error_#{response.response.code}\"",
",",
"\"message\"",
"=>",
"response",
".",
"response",
".",
"message",
")",
"end",
"end"
] | Filter the response after checking for any errors | [
"Filter",
"the",
"response",
"after",
"checking",
"for",
"any",
"errors"
] | 6cf7b692f64c6f00a81bc7ca6fffca3020244072 | https://github.com/ronyv89/skydrive/blob/6cf7b692f64c6f00a81bc7ca6fffca3020244072/lib/skydrive/client.rb#L73-L96 |
5,140 | Kuniri/kuniri | lib/kuniri/parser/output_factory.rb | Parser.OutputFactory.get_output | def get_output(pType)
pType.downcase!
return XMLOutputFormat.new if pType == 'xml'
raise Error::ParserError if pType == 'yml'
end | ruby | def get_output(pType)
pType.downcase!
return XMLOutputFormat.new if pType == 'xml'
raise Error::ParserError if pType == 'yml'
end | [
"def",
"get_output",
"(",
"pType",
")",
"pType",
".",
"downcase!",
"return",
"XMLOutputFormat",
".",
"new",
"if",
"pType",
"==",
"'xml'",
"raise",
"Error",
"::",
"ParserError",
"if",
"pType",
"==",
"'yml'",
"end"
] | Handling the output tyoe.
@param pType [String] Type of object
@return Return an object of output. | [
"Handling",
"the",
"output",
"tyoe",
"."
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/parser/output_factory.rb#L17-L22 |
5,141 | oggy/redis_master_slave | lib/redis_master_slave/client.rb | RedisMasterSlave.Client.method_missing | def method_missing(name, *args, &block) # :nodoc:
if writable_master.respond_to?(name)
Client.send(:send_to_master, name)
send(name, *args, &block)
else
super
end
end | ruby | def method_missing(name, *args, &block) # :nodoc:
if writable_master.respond_to?(name)
Client.send(:send_to_master, name)
send(name, *args, &block)
else
super
end
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
",",
"&",
"block",
")",
"# :nodoc:",
"if",
"writable_master",
".",
"respond_to?",
"(",
"name",
")",
"Client",
".",
"send",
"(",
":send_to_master",
",",
"name",
")",
"send",
"(",
"name",
",",
"args",
",",
"block",
")",
"else",
"super",
"end",
"end"
] | Send everything else to master. | [
"Send",
"everything",
"else",
"to",
"master",
"."
] | 29a0aeb62e5f4466e40be58d99de9420b54f3758 | https://github.com/oggy/redis_master_slave/blob/29a0aeb62e5f4466e40be58d99de9420b54f3758/lib/redis_master_slave/client.rb#L121-L128 |
5,142 | payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb | PaynetEasy::PaynetEasyApi::Callback.CallbackPrototype.process_callback | def process_callback(payment_transaction, callback_response)
begin
validate_callback payment_transaction, callback_response
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end
update_payment_transaction payment_transaction, callback_response
if callback_response.error?
raise callback_response.error
end
callback_response
end | ruby | def process_callback(payment_transaction, callback_response)
begin
validate_callback payment_transaction, callback_response
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end
update_payment_transaction payment_transaction, callback_response
if callback_response.error?
raise callback_response.error
end
callback_response
end | [
"def",
"process_callback",
"(",
"payment_transaction",
",",
"callback_response",
")",
"begin",
"validate_callback",
"payment_transaction",
",",
"callback_response",
"rescue",
"Exception",
"=>",
"error",
"payment_transaction",
".",
"add_error",
"error",
"payment_transaction",
".",
"status",
"=",
"PaymentTransaction",
"::",
"STATUS_ERROR",
"raise",
"error",
"end",
"update_payment_transaction",
"payment_transaction",
",",
"callback_response",
"if",
"callback_response",
".",
"error?",
"raise",
"callback_response",
".",
"error",
"end",
"callback_response",
"end"
] | Process API gateway Response and update Payment transaction
@param payment_transaction [PaymentTransaction] Payment transaction for update
@param callback_response [CallbackResponse] PaynetEasy callback
@return [CallbackResponse] PaynetEasy callback | [
"Process",
"API",
"gateway",
"Response",
"and",
"update",
"Payment",
"transaction"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb#L56-L73 |
5,143 | payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb | PaynetEasy::PaynetEasyApi::Callback.CallbackPrototype.validate_signature | def validate_signature(payment_transaction, callback_response)
expected_control_code = Digest::SHA1.hexdigest(
callback_response.status +
callback_response.payment_paynet_id.to_s +
callback_response.payment_client_id.to_s +
payment_transaction.query_config.signing_key
)
if expected_control_code != callback_response.control_code
raise ValidationError, "Actual control code '#{callback_response.control_code}' does " +
"not equal expected '#{expected_control_code}'"
end
end | ruby | def validate_signature(payment_transaction, callback_response)
expected_control_code = Digest::SHA1.hexdigest(
callback_response.status +
callback_response.payment_paynet_id.to_s +
callback_response.payment_client_id.to_s +
payment_transaction.query_config.signing_key
)
if expected_control_code != callback_response.control_code
raise ValidationError, "Actual control code '#{callback_response.control_code}' does " +
"not equal expected '#{expected_control_code}'"
end
end | [
"def",
"validate_signature",
"(",
"payment_transaction",
",",
"callback_response",
")",
"expected_control_code",
"=",
"Digest",
"::",
"SHA1",
".",
"hexdigest",
"(",
"callback_response",
".",
"status",
"+",
"callback_response",
".",
"payment_paynet_id",
".",
"to_s",
"+",
"callback_response",
".",
"payment_client_id",
".",
"to_s",
"+",
"payment_transaction",
".",
"query_config",
".",
"signing_key",
")",
"if",
"expected_control_code",
"!=",
"callback_response",
".",
"control_code",
"raise",
"ValidationError",
",",
"\"Actual control code '#{callback_response.control_code}' does \"",
"+",
"\"not equal expected '#{expected_control_code}'\"",
"end",
"end"
] | Validate callback response control code
@param payment_transaction [PaymentTransaction] Payment transaction for control code checking
@param callback_response [CallbackResponse] Callback for control code checking | [
"Validate",
"callback",
"response",
"control",
"code"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb#L134-L146 |
5,144 | payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb | PaynetEasy::PaynetEasyApi::Callback.CallbackPrototype.update_payment_transaction | def update_payment_transaction(payment_transaction, callback_response)
payment_transaction.status = callback_response.status
payment_transaction.payment.paynet_id = callback_response.payment_paynet_id
if callback_response.error? || callback_response.declined?
payment_transaction.add_error callback_response.error
end
end | ruby | def update_payment_transaction(payment_transaction, callback_response)
payment_transaction.status = callback_response.status
payment_transaction.payment.paynet_id = callback_response.payment_paynet_id
if callback_response.error? || callback_response.declined?
payment_transaction.add_error callback_response.error
end
end | [
"def",
"update_payment_transaction",
"(",
"payment_transaction",
",",
"callback_response",
")",
"payment_transaction",
".",
"status",
"=",
"callback_response",
".",
"status",
"payment_transaction",
".",
"payment",
".",
"paynet_id",
"=",
"callback_response",
".",
"payment_paynet_id",
"if",
"callback_response",
".",
"error?",
"||",
"callback_response",
".",
"declined?",
"payment_transaction",
".",
"add_error",
"callback_response",
".",
"error",
"end",
"end"
] | Updates Payment transaction by Callback data
@param payment_transaction [PaymentTransaction] Payment transaction for updating
@param callback_response [CallbackResponse] Callback for payment transaction updating | [
"Updates",
"Payment",
"transaction",
"by",
"Callback",
"data"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb#L152-L159 |
5,145 | petebrowne/massimo | lib/massimo/ui.rb | Massimo.UI.report_errors | def report_errors
begin
yield
true
rescue Exception => error
say 'massimo had a problem', :red
indent do
say error.message, :magenta
say error.backtrace.first, :magenta
end
growl "#{error.message}\n#{error.backtrace.first}", 'massimo problem'
false
end
end | ruby | def report_errors
begin
yield
true
rescue Exception => error
say 'massimo had a problem', :red
indent do
say error.message, :magenta
say error.backtrace.first, :magenta
end
growl "#{error.message}\n#{error.backtrace.first}", 'massimo problem'
false
end
end | [
"def",
"report_errors",
"begin",
"yield",
"true",
"rescue",
"Exception",
"=>",
"error",
"say",
"'massimo had a problem'",
",",
":red",
"indent",
"do",
"say",
"error",
".",
"message",
",",
":magenta",
"say",
"error",
".",
"backtrace",
".",
"first",
",",
":magenta",
"end",
"growl",
"\"#{error.message}\\n#{error.backtrace.first}\"",
",",
"'massimo problem'",
"false",
"end",
"end"
] | Run the given block and cleanly report any errors | [
"Run",
"the",
"given",
"block",
"and",
"cleanly",
"report",
"any",
"errors"
] | c450edc531ad358f011da0a47e5d0bc9a038d911 | https://github.com/petebrowne/massimo/blob/c450edc531ad358f011da0a47e5d0bc9a038d911/lib/massimo/ui.rb#L35-L48 |
5,146 | mamantoha/freshdesk_api_client_rb | lib/freshdesk_api/client.rb | FreshdeskAPI.Client.method_missing | def method_missing(method, *args)
method = method.to_s
method_class = method_as_class(method)
options = args.last.is_a?(Hash) ? args.pop : {}
FreshdeskAPI::Collection.new(self, method_class, options)
end | ruby | def method_missing(method, *args)
method = method.to_s
method_class = method_as_class(method)
options = args.last.is_a?(Hash) ? args.pop : {}
FreshdeskAPI::Collection.new(self, method_class, options)
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
")",
"method",
"=",
"method",
".",
"to_s",
"method_class",
"=",
"method_as_class",
"(",
"method",
")",
"options",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"pop",
":",
"{",
"}",
"FreshdeskAPI",
"::",
"Collection",
".",
"new",
"(",
"self",
",",
"method_class",
",",
"options",
")",
"end"
] | Handles resources such as 'tickets'.
@return [Collection] Collection instance for resource | [
"Handles",
"resources",
"such",
"as",
"tickets",
"."
] | 74367fe0dd31bd269197b3f419412ef600031e62 | https://github.com/mamantoha/freshdesk_api_client_rb/blob/74367fe0dd31bd269197b3f419412ef600031e62/lib/freshdesk_api/client.rb#L28-L34 |
5,147 | Kuniri/kuniri | lib/kuniri/core/kuniri.rb | Kuniri.Kuniri.run_analysis | def run_analysis
@filesPathProject = get_project_file(@configurationInfo[:source])
unless @filesPathProject
message = "Problem on source path: #{@configurationInfo[:source]}"
Util::LoggerKuniri.error(message)
return -1
end
@parser = Parser::Parser.new(@filesPathProject,
@configurationInfo[:language])
Util::LoggerKuniri.info('Start parse...')
begin
@parser.start_parser
rescue Error::ConfigurationFileError => e
puts e.message
end
end | ruby | def run_analysis
@filesPathProject = get_project_file(@configurationInfo[:source])
unless @filesPathProject
message = "Problem on source path: #{@configurationInfo[:source]}"
Util::LoggerKuniri.error(message)
return -1
end
@parser = Parser::Parser.new(@filesPathProject,
@configurationInfo[:language])
Util::LoggerKuniri.info('Start parse...')
begin
@parser.start_parser
rescue Error::ConfigurationFileError => e
puts e.message
end
end | [
"def",
"run_analysis",
"@filesPathProject",
"=",
"get_project_file",
"(",
"@configurationInfo",
"[",
":source",
"]",
")",
"unless",
"@filesPathProject",
"message",
"=",
"\"Problem on source path: #{@configurationInfo[:source]}\"",
"Util",
"::",
"LoggerKuniri",
".",
"error",
"(",
"message",
")",
"return",
"-",
"1",
"end",
"@parser",
"=",
"Parser",
"::",
"Parser",
".",
"new",
"(",
"@filesPathProject",
",",
"@configurationInfo",
"[",
":language",
"]",
")",
"Util",
"::",
"LoggerKuniri",
".",
"info",
"(",
"'Start parse...'",
")",
"begin",
"@parser",
".",
"start_parser",
"rescue",
"Error",
"::",
"ConfigurationFileError",
"=>",
"e",
"puts",
"e",
".",
"message",
"end",
"end"
] | Start Kuniri tasks based on configuration file. After read
configuration file, find all files in source directory. | [
"Start",
"Kuniri",
"tasks",
"based",
"on",
"configuration",
"file",
".",
"After",
"read",
"configuration",
"file",
"find",
"all",
"files",
"in",
"source",
"directory",
"."
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/core/kuniri.rb#L52-L67 |
5,148 | donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/publish.rb | GithubPivotalFlow.Publish.run! | def run!
story = @configuration.story
fail("Could not find story associated with branch") unless story
Git.clean_working_tree?
Git.push(story.branch_name, set_upstream: true)
unless story.release?
print "Creating pull-request on Github... "
pull_request_params = story.params_for_pull_request.merge(project: @configuration.project)
@configuration.github_client.create_pullrequest(pull_request_params)
puts 'OK'
end
return 0
end | ruby | def run!
story = @configuration.story
fail("Could not find story associated with branch") unless story
Git.clean_working_tree?
Git.push(story.branch_name, set_upstream: true)
unless story.release?
print "Creating pull-request on Github... "
pull_request_params = story.params_for_pull_request.merge(project: @configuration.project)
@configuration.github_client.create_pullrequest(pull_request_params)
puts 'OK'
end
return 0
end | [
"def",
"run!",
"story",
"=",
"@configuration",
".",
"story",
"fail",
"(",
"\"Could not find story associated with branch\"",
")",
"unless",
"story",
"Git",
".",
"clean_working_tree?",
"Git",
".",
"push",
"(",
"story",
".",
"branch_name",
",",
"set_upstream",
":",
"true",
")",
"unless",
"story",
".",
"release?",
"print",
"\"Creating pull-request on Github... \"",
"pull_request_params",
"=",
"story",
".",
"params_for_pull_request",
".",
"merge",
"(",
"project",
":",
"@configuration",
".",
"project",
")",
"@configuration",
".",
"github_client",
".",
"create_pullrequest",
"(",
"pull_request_params",
")",
"puts",
"'OK'",
"end",
"return",
"0",
"end"
] | Publishes the branch and opens the pull request | [
"Publishes",
"the",
"branch",
"and",
"opens",
"the",
"pull",
"request"
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/publish.rb#L6-L18 |
5,149 | payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/create_card_ref_query.rb | PaynetEasy::PaynetEasyApi::Query.CreateCardRefQuery.check_payment_transaction_status | def check_payment_transaction_status(payment_transaction)
unless payment_transaction.finished?
raise ValidationError, 'Only finished payment transaction can be used for create-card-ref-id'
end
unless payment_transaction.payment.paid?
raise ValidationError, "Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first"
end
end | ruby | def check_payment_transaction_status(payment_transaction)
unless payment_transaction.finished?
raise ValidationError, 'Only finished payment transaction can be used for create-card-ref-id'
end
unless payment_transaction.payment.paid?
raise ValidationError, "Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first"
end
end | [
"def",
"check_payment_transaction_status",
"(",
"payment_transaction",
")",
"unless",
"payment_transaction",
".",
"finished?",
"raise",
"ValidationError",
",",
"'Only finished payment transaction can be used for create-card-ref-id'",
"end",
"unless",
"payment_transaction",
".",
"payment",
".",
"paid?",
"raise",
"ValidationError",
",",
"\"Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first\"",
"end",
"end"
] | Check, if payment transaction is finished and payment is not new.
@param payment_transaction [PaymentTransaction] Payment transaction for validation | [
"Check",
"if",
"payment",
"transaction",
"is",
"finished",
"and",
"payment",
"is",
"not",
"new",
"."
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/create_card_ref_query.rb#L68-L76 |
5,150 | dceballos/roomer | lib/roomer/utils.rb | Roomer.Utils.current_tenant= | def current_tenant=(val)
key = :"roomer_current_tenant"
unless Thread.current[key].try(:url_identifier) == val.try(:url_identifier)
Thread.current[key] = val
ensure_tenant_model_reset
end
Thread.current[key]
end | ruby | def current_tenant=(val)
key = :"roomer_current_tenant"
unless Thread.current[key].try(:url_identifier) == val.try(:url_identifier)
Thread.current[key] = val
ensure_tenant_model_reset
end
Thread.current[key]
end | [
"def",
"current_tenant",
"=",
"(",
"val",
")",
"key",
"=",
":\"",
"\"",
"unless",
"Thread",
".",
"current",
"[",
"key",
"]",
".",
"try",
"(",
":url_identifier",
")",
"==",
"val",
".",
"try",
"(",
":url_identifier",
")",
"Thread",
".",
"current",
"[",
"key",
"]",
"=",
"val",
"ensure_tenant_model_reset",
"end",
"Thread",
".",
"current",
"[",
"key",
"]",
"end"
] | Sets current tenant from ApplicationController into a Thread
local variable. Works only with thread-safe Rails as long as
it gets set on every request
@return [Symbol] the current tenant key in the thread | [
"Sets",
"current",
"tenant",
"from",
"ApplicationController",
"into",
"a",
"Thread",
"local",
"variable",
".",
"Works",
"only",
"with",
"thread",
"-",
"safe",
"Rails",
"as",
"long",
"as",
"it",
"gets",
"set",
"on",
"every",
"request"
] | 923908cc5f239578c322f0851720fb69a68353b7 | https://github.com/dceballos/roomer/blob/923908cc5f239578c322f0851720fb69a68353b7/lib/roomer/utils.rb#L41-L48 |
5,151 | dceballos/roomer | lib/roomer/utils.rb | Roomer.Utils.with_tenant | def with_tenant(tenant,&blk)
orig = self.current_tenant
begin
self.current_tenant = tenant
return blk.call(tenant)
ensure
self.current_tenant = orig
end
end | ruby | def with_tenant(tenant,&blk)
orig = self.current_tenant
begin
self.current_tenant = tenant
return blk.call(tenant)
ensure
self.current_tenant = orig
end
end | [
"def",
"with_tenant",
"(",
"tenant",
",",
"&",
"blk",
")",
"orig",
"=",
"self",
".",
"current_tenant",
"begin",
"self",
".",
"current_tenant",
"=",
"tenant",
"return",
"blk",
".",
"call",
"(",
"tenant",
")",
"ensure",
"self",
".",
"current_tenant",
"=",
"orig",
"end",
"end"
] | Replace current_tenant with @tenant
during the execution of @blk | [
"Replace",
"current_tenant",
"with"
] | 923908cc5f239578c322f0851720fb69a68353b7 | https://github.com/dceballos/roomer/blob/923908cc5f239578c322f0851720fb69a68353b7/lib/roomer/utils.rb#L66-L74 |
5,152 | bdurand/json_record | lib/json_record/field_definition.rb | JsonRecord.FieldDefinition.convert | def convert (val)
return nil if val.blank? and val != false
if @type == String
return val.to_s
elsif @type == Integer
return Kernel.Integer(val) rescue val
elsif @type == Float
return Kernel.Float(val) rescue val
elsif @type == Boolean
v = BOOLEAN_MAPPING[val]
v = val.to_s.downcase == 'true' if v.nil? # Check all mixed case spellings for true
return v
elsif @type == Date
if val.is_a?(Date)
return val
elsif val.is_a?(Time)
return val.to_date
else
return Date.parse(val.to_s) rescue val
end
elsif @type == Time
if val.is_a?(Time)
return Time.at((val.to_i / 60) * 60).utc
else
return Time.parse(val).utc rescue val
end
elsif @type == DateTime
if val.is_a?(DateTime)
return val.utc
else
return DateTime.parse(val).utc rescue val
end
elsif @type == Array
val = [val] unless val.is_a?(Array)
raise ArgumentError.new("#{name} must be an Array") unless val.is_a?(Array)
return val
elsif @type == Hash
raise ArgumentError.new("#{name} must be a Hash") unless val.is_a?(Hash)
return val
elsif @type == BigDecimal
return BigDecimal.new(val.to_s)
else
if val.is_a?(@type)
val
elsif val.is_a?(Hash) and (@type < EmbeddedDocument)
return @type.new(val)
else
raise ArgumentError.new("#{name} must be a #{@type}")
end
end
end | ruby | def convert (val)
return nil if val.blank? and val != false
if @type == String
return val.to_s
elsif @type == Integer
return Kernel.Integer(val) rescue val
elsif @type == Float
return Kernel.Float(val) rescue val
elsif @type == Boolean
v = BOOLEAN_MAPPING[val]
v = val.to_s.downcase == 'true' if v.nil? # Check all mixed case spellings for true
return v
elsif @type == Date
if val.is_a?(Date)
return val
elsif val.is_a?(Time)
return val.to_date
else
return Date.parse(val.to_s) rescue val
end
elsif @type == Time
if val.is_a?(Time)
return Time.at((val.to_i / 60) * 60).utc
else
return Time.parse(val).utc rescue val
end
elsif @type == DateTime
if val.is_a?(DateTime)
return val.utc
else
return DateTime.parse(val).utc rescue val
end
elsif @type == Array
val = [val] unless val.is_a?(Array)
raise ArgumentError.new("#{name} must be an Array") unless val.is_a?(Array)
return val
elsif @type == Hash
raise ArgumentError.new("#{name} must be a Hash") unless val.is_a?(Hash)
return val
elsif @type == BigDecimal
return BigDecimal.new(val.to_s)
else
if val.is_a?(@type)
val
elsif val.is_a?(Hash) and (@type < EmbeddedDocument)
return @type.new(val)
else
raise ArgumentError.new("#{name} must be a #{@type}")
end
end
end | [
"def",
"convert",
"(",
"val",
")",
"return",
"nil",
"if",
"val",
".",
"blank?",
"and",
"val",
"!=",
"false",
"if",
"@type",
"==",
"String",
"return",
"val",
".",
"to_s",
"elsif",
"@type",
"==",
"Integer",
"return",
"Kernel",
".",
"Integer",
"(",
"val",
")",
"rescue",
"val",
"elsif",
"@type",
"==",
"Float",
"return",
"Kernel",
".",
"Float",
"(",
"val",
")",
"rescue",
"val",
"elsif",
"@type",
"==",
"Boolean",
"v",
"=",
"BOOLEAN_MAPPING",
"[",
"val",
"]",
"v",
"=",
"val",
".",
"to_s",
".",
"downcase",
"==",
"'true'",
"if",
"v",
".",
"nil?",
"# Check all mixed case spellings for true",
"return",
"v",
"elsif",
"@type",
"==",
"Date",
"if",
"val",
".",
"is_a?",
"(",
"Date",
")",
"return",
"val",
"elsif",
"val",
".",
"is_a?",
"(",
"Time",
")",
"return",
"val",
".",
"to_date",
"else",
"return",
"Date",
".",
"parse",
"(",
"val",
".",
"to_s",
")",
"rescue",
"val",
"end",
"elsif",
"@type",
"==",
"Time",
"if",
"val",
".",
"is_a?",
"(",
"Time",
")",
"return",
"Time",
".",
"at",
"(",
"(",
"val",
".",
"to_i",
"/",
"60",
")",
"*",
"60",
")",
".",
"utc",
"else",
"return",
"Time",
".",
"parse",
"(",
"val",
")",
".",
"utc",
"rescue",
"val",
"end",
"elsif",
"@type",
"==",
"DateTime",
"if",
"val",
".",
"is_a?",
"(",
"DateTime",
")",
"return",
"val",
".",
"utc",
"else",
"return",
"DateTime",
".",
"parse",
"(",
"val",
")",
".",
"utc",
"rescue",
"val",
"end",
"elsif",
"@type",
"==",
"Array",
"val",
"=",
"[",
"val",
"]",
"unless",
"val",
".",
"is_a?",
"(",
"Array",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"#{name} must be an Array\"",
")",
"unless",
"val",
".",
"is_a?",
"(",
"Array",
")",
"return",
"val",
"elsif",
"@type",
"==",
"Hash",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"#{name} must be a Hash\"",
")",
"unless",
"val",
".",
"is_a?",
"(",
"Hash",
")",
"return",
"val",
"elsif",
"@type",
"==",
"BigDecimal",
"return",
"BigDecimal",
".",
"new",
"(",
"val",
".",
"to_s",
")",
"else",
"if",
"val",
".",
"is_a?",
"(",
"@type",
")",
"val",
"elsif",
"val",
".",
"is_a?",
"(",
"Hash",
")",
"and",
"(",
"@type",
"<",
"EmbeddedDocument",
")",
"return",
"@type",
".",
"new",
"(",
"val",
")",
"else",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"#{name} must be a #{@type}\"",
")",
"end",
"end",
"end"
] | Convert a value to the proper class for storing it in the field. If the value can't be converted,
the original value will be returned. Blank values are always translated to nil. Hashes will be converted
to EmbeddedDocument objects if the field type extends from EmbeddedDocument. | [
"Convert",
"a",
"value",
"to",
"the",
"proper",
"class",
"for",
"storing",
"it",
"in",
"the",
"field",
".",
"If",
"the",
"value",
"can",
"t",
"be",
"converted",
"the",
"original",
"value",
"will",
"be",
"returned",
".",
"Blank",
"values",
"are",
"always",
"translated",
"to",
"nil",
".",
"Hashes",
"will",
"be",
"converted",
"to",
"EmbeddedDocument",
"objects",
"if",
"the",
"field",
"type",
"extends",
"from",
"EmbeddedDocument",
"."
] | 463f4719d9618f6d2406c0aab6028e0156f7c775 | https://github.com/bdurand/json_record/blob/463f4719d9618f6d2406c0aab6028e0156f7c775/lib/json_record/field_definition.rb#L42-L92 |
5,153 | dapi/gritter_notices | lib/gritter_notices/active_record.rb | GritterNotices::ActiveRecord.InstanceMethods.method_missing | def method_missing(method_name, *args, &block)
if level = ValidMethods[method_name.to_s] or level = ValidMethods["gritter_#{method_name}"]
options = args.extract_options!
options[:level] = level
args << options
gritter_notice *args
else
super(method_name, *args, &block)
end
end | ruby | def method_missing(method_name, *args, &block)
if level = ValidMethods[method_name.to_s] or level = ValidMethods["gritter_#{method_name}"]
options = args.extract_options!
options[:level] = level
args << options
gritter_notice *args
else
super(method_name, *args, &block)
end
end | [
"def",
"method_missing",
"(",
"method_name",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"level",
"=",
"ValidMethods",
"[",
"method_name",
".",
"to_s",
"]",
"or",
"level",
"=",
"ValidMethods",
"[",
"\"gritter_#{method_name}\"",
"]",
"options",
"=",
"args",
".",
"extract_options!",
"options",
"[",
":level",
"]",
"=",
"level",
"args",
"<<",
"options",
"gritter_notice",
"args",
"else",
"super",
"(",
"method_name",
",",
"args",
",",
"block",
")",
"end",
"end"
] | notice_success
notice_error
notice_warning
notice_progress
notice_notice - default. An alias for `notice` | [
"notice_success",
"notice_error",
"notice_warning",
"notice_progress",
"notice_notice",
"-",
"default",
".",
"An",
"alias",
"for",
"notice"
] | 739b49ac96ba733e5276677a04bd8c5e4a73716d | https://github.com/dapi/gritter_notices/blob/739b49ac96ba733e5276677a04bd8c5e4a73716d/lib/gritter_notices/active_record.rb#L41-L50 |
5,154 | mikerodrigues/onkyo_eiscp_ruby | lib/eiscp/message.rb | EISCP.Message.get_human_readable_attrs | def get_human_readable_attrs
@zone = Dictionary.zone_from_command(@command)
@command_name = Dictionary.command_to_name(@command)
@command_description = Dictionary.description_from_command(@command)
@value_name = Dictionary.command_value_to_value_name(@command, @value)
@value_description = Dictionary.description_from_command_value(@command, @value)
end | ruby | def get_human_readable_attrs
@zone = Dictionary.zone_from_command(@command)
@command_name = Dictionary.command_to_name(@command)
@command_description = Dictionary.description_from_command(@command)
@value_name = Dictionary.command_value_to_value_name(@command, @value)
@value_description = Dictionary.description_from_command_value(@command, @value)
end | [
"def",
"get_human_readable_attrs",
"@zone",
"=",
"Dictionary",
".",
"zone_from_command",
"(",
"@command",
")",
"@command_name",
"=",
"Dictionary",
".",
"command_to_name",
"(",
"@command",
")",
"@command_description",
"=",
"Dictionary",
".",
"description_from_command",
"(",
"@command",
")",
"@value_name",
"=",
"Dictionary",
".",
"command_value_to_value_name",
"(",
"@command",
",",
"@value",
")",
"@value_description",
"=",
"Dictionary",
".",
"description_from_command_value",
"(",
"@command",
",",
"@value",
")",
"end"
] | Retrieves human readable attributes from the yaml file via Dictionary | [
"Retrieves",
"human",
"readable",
"attributes",
"from",
"the",
"yaml",
"file",
"via",
"Dictionary"
] | c51f8b22c74decd88b1d1a91e170885c4ec2a0b0 | https://github.com/mikerodrigues/onkyo_eiscp_ruby/blob/c51f8b22c74decd88b1d1a91e170885c4ec2a0b0/lib/eiscp/message.rb#L115-L121 |
5,155 | razor-x/config_curator | lib/config_curator/package_lookup.rb | ConfigCurator.PackageLookup.installed? | def installed?(package)
fail LookupFailed, 'No supported package tool found.' if tool.nil?
cmd = tools[tool]
fail LookupFailed, "Package tool '#{cmd}' not found." if command?(cmd).nil?
send tool, package
end | ruby | def installed?(package)
fail LookupFailed, 'No supported package tool found.' if tool.nil?
cmd = tools[tool]
fail LookupFailed, "Package tool '#{cmd}' not found." if command?(cmd).nil?
send tool, package
end | [
"def",
"installed?",
"(",
"package",
")",
"fail",
"LookupFailed",
",",
"'No supported package tool found.'",
"if",
"tool",
".",
"nil?",
"cmd",
"=",
"tools",
"[",
"tool",
"]",
"fail",
"LookupFailed",
",",
"\"Package tool '#{cmd}' not found.\"",
"if",
"command?",
"(",
"cmd",
")",
".",
"nil?",
"send",
"tool",
",",
"package",
"end"
] | Checks if package is installed.
@param package [String] package name to check
@return [Boolean] if package is installed | [
"Checks",
"if",
"package",
"is",
"installed",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/package_lookup.rb#L55-L62 |
5,156 | razor-x/config_curator | lib/config_curator/package_lookup.rb | ConfigCurator.PackageLookup.dpkg | def dpkg(package)
cmd = command? 'dpkg'
Open3.popen3 cmd, '-s', package do |_, _, _, wait_thr|
wait_thr.value.to_i == 0
end
end | ruby | def dpkg(package)
cmd = command? 'dpkg'
Open3.popen3 cmd, '-s', package do |_, _, _, wait_thr|
wait_thr.value.to_i == 0
end
end | [
"def",
"dpkg",
"(",
"package",
")",
"cmd",
"=",
"command?",
"'dpkg'",
"Open3",
".",
"popen3",
"cmd",
",",
"'-s'",
",",
"package",
"do",
"|",
"_",
",",
"_",
",",
"_",
",",
"wait_thr",
"|",
"wait_thr",
".",
"value",
".",
"to_i",
"==",
"0",
"end",
"end"
] | Tool specific package lookup methods below. | [
"Tool",
"specific",
"package",
"lookup",
"methods",
"below",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/package_lookup.rb#L70-L75 |
5,157 | Fetcher/mongo-fixture | lib/mongo-fixture.rb | Mongo.Fixture.check | def check
return @checked if @checked # If already checked, it's alright
raise MissingFixtureError, "No fixture has been loaded, nothing to check" unless @data
raise MissingConnectionError, "No connection has been provided, impossible to check" unless @connection
@data.each_key do |collection|
raise CollectionsNotEmptyError, "The collection '#{collection}' is not empty, all collections should be empty prior to testing" if @connection[collection].count != 0
end
return @checked = true
end | ruby | def check
return @checked if @checked # If already checked, it's alright
raise MissingFixtureError, "No fixture has been loaded, nothing to check" unless @data
raise MissingConnectionError, "No connection has been provided, impossible to check" unless @connection
@data.each_key do |collection|
raise CollectionsNotEmptyError, "The collection '#{collection}' is not empty, all collections should be empty prior to testing" if @connection[collection].count != 0
end
return @checked = true
end | [
"def",
"check",
"return",
"@checked",
"if",
"@checked",
"# If already checked, it's alright",
"raise",
"MissingFixtureError",
",",
"\"No fixture has been loaded, nothing to check\"",
"unless",
"@data",
"raise",
"MissingConnectionError",
",",
"\"No connection has been provided, impossible to check\"",
"unless",
"@connection",
"@data",
".",
"each_key",
"do",
"|",
"collection",
"|",
"raise",
"CollectionsNotEmptyError",
",",
"\"The collection '#{collection}' is not empty, all collections should be empty prior to testing\"",
"if",
"@connection",
"[",
"collection",
"]",
".",
"count",
"!=",
"0",
"end",
"return",
"@checked",
"=",
"true",
"end"
] | Assures that the collections are empty before proceeding | [
"Assures",
"that",
"the",
"collections",
"are",
"empty",
"before",
"proceeding"
] | b03175529d7ffce060cfcbeea29fe17288d7b778 | https://github.com/Fetcher/mongo-fixture/blob/b03175529d7ffce060cfcbeea29fe17288d7b778/lib/mongo-fixture.rb#L103-L113 |
5,158 | Fetcher/mongo-fixture | lib/mongo-fixture.rb | Mongo.Fixture.rollback | def rollback
begin
check
@data.each_key do |collection|
@connection[collection].drop
end
rescue CollectionsNotEmptyError => e
raise RollbackIllegalError, "The collections weren't empty to begin with, rollback aborted."
end
end | ruby | def rollback
begin
check
@data.each_key do |collection|
@connection[collection].drop
end
rescue CollectionsNotEmptyError => e
raise RollbackIllegalError, "The collections weren't empty to begin with, rollback aborted."
end
end | [
"def",
"rollback",
"begin",
"check",
"@data",
".",
"each_key",
"do",
"|",
"collection",
"|",
"@connection",
"[",
"collection",
"]",
".",
"drop",
"end",
"rescue",
"CollectionsNotEmptyError",
"=>",
"e",
"raise",
"RollbackIllegalError",
",",
"\"The collections weren't empty to begin with, rollback aborted.\"",
"end",
"end"
] | Empties the collections, only if they were empty to begin with | [
"Empties",
"the",
"collections",
"only",
"if",
"they",
"were",
"empty",
"to",
"begin",
"with"
] | b03175529d7ffce060cfcbeea29fe17288d7b778 | https://github.com/Fetcher/mongo-fixture/blob/b03175529d7ffce060cfcbeea29fe17288d7b778/lib/mongo-fixture.rb#L138-L148 |
5,159 | r7kamura/altria | lib/altria/scheduler.rb | Altria.Scheduler.scheduled? | def scheduled?
[:min, :hour, :day, :month, :wday].all? do |key|
send(key).nil? || send(key) == now.send(key)
end
end | ruby | def scheduled?
[:min, :hour, :day, :month, :wday].all? do |key|
send(key).nil? || send(key) == now.send(key)
end
end | [
"def",
"scheduled?",
"[",
":min",
",",
":hour",
",",
":day",
",",
":month",
",",
":wday",
"]",
".",
"all?",
"do",
"|",
"key",
"|",
"send",
"(",
"key",
")",
".",
"nil?",
"||",
"send",
"(",
"key",
")",
"==",
"now",
".",
"send",
"(",
"key",
")",
"end",
"end"
] | Takes a schedule as a String. | [
"Takes",
"a",
"schedule",
"as",
"a",
"String",
"."
] | d7743298b1cef2a839be6f6a3ce2a697dda44fda | https://github.com/r7kamura/altria/blob/d7743298b1cef2a839be6f6a3ce2a697dda44fda/lib/altria/scheduler.rb#L11-L15 |
5,160 | RipTheJacker/auto_excerpt | lib/auto_excerpt/parser.rb | AutoExcerpt.Parser.close_tags | def close_tags(text)
# Don't bother closing tags if html is stripped since there are no tags.
if @settings[:strip_html] && @settings[:allowed_tags].empty?
tagstoclose = nil
else
tagstoclose = ""
tags = []
opentags = text.scan(OPENING_TAG).transpose[0] || []
opentags.reverse!
closedtags = text.scan(CLOSING_TAG).transpose[0] || []
opentags.each do |ot|
if closedtags.include?(ot)
closedtags.delete_at(closedtags.index(ot))
else
tags << ot
end
end
tags.each do |tag|
tagstoclose << "</#{tag.strip.downcase}>" unless NO_CLOSE.include?(tag)
end
end
@excerpt = [text, @settings[:ending], tagstoclose].join
end | ruby | def close_tags(text)
# Don't bother closing tags if html is stripped since there are no tags.
if @settings[:strip_html] && @settings[:allowed_tags].empty?
tagstoclose = nil
else
tagstoclose = ""
tags = []
opentags = text.scan(OPENING_TAG).transpose[0] || []
opentags.reverse!
closedtags = text.scan(CLOSING_TAG).transpose[0] || []
opentags.each do |ot|
if closedtags.include?(ot)
closedtags.delete_at(closedtags.index(ot))
else
tags << ot
end
end
tags.each do |tag|
tagstoclose << "</#{tag.strip.downcase}>" unless NO_CLOSE.include?(tag)
end
end
@excerpt = [text, @settings[:ending], tagstoclose].join
end | [
"def",
"close_tags",
"(",
"text",
")",
"# Don't bother closing tags if html is stripped since there are no tags.",
"if",
"@settings",
"[",
":strip_html",
"]",
"&&",
"@settings",
"[",
":allowed_tags",
"]",
".",
"empty?",
"tagstoclose",
"=",
"nil",
"else",
"tagstoclose",
"=",
"\"\"",
"tags",
"=",
"[",
"]",
"opentags",
"=",
"text",
".",
"scan",
"(",
"OPENING_TAG",
")",
".",
"transpose",
"[",
"0",
"]",
"||",
"[",
"]",
"opentags",
".",
"reverse!",
"closedtags",
"=",
"text",
".",
"scan",
"(",
"CLOSING_TAG",
")",
".",
"transpose",
"[",
"0",
"]",
"||",
"[",
"]",
"opentags",
".",
"each",
"do",
"|",
"ot",
"|",
"if",
"closedtags",
".",
"include?",
"(",
"ot",
")",
"closedtags",
".",
"delete_at",
"(",
"closedtags",
".",
"index",
"(",
"ot",
")",
")",
"else",
"tags",
"<<",
"ot",
"end",
"end",
"tags",
".",
"each",
"do",
"|",
"tag",
"|",
"tagstoclose",
"<<",
"\"</#{tag.strip.downcase}>\"",
"unless",
"NO_CLOSE",
".",
"include?",
"(",
"tag",
")",
"end",
"end",
"@excerpt",
"=",
"[",
"text",
",",
"@settings",
"[",
":ending",
"]",
",",
"tagstoclose",
"]",
".",
"join",
"end"
] | close html tags | [
"close",
"html",
"tags"
] | 17514e21d5ee275e14d1596db387730d7ebb2b14 | https://github.com/RipTheJacker/auto_excerpt/blob/17514e21d5ee275e14d1596db387730d7ebb2b14/lib/auto_excerpt/parser.rb#L79-L104 |
5,161 | RipTheJacker/auto_excerpt | lib/auto_excerpt/parser.rb | AutoExcerpt.Parser.paragraphs | def paragraphs
return non_excerpted_text if @pghcount < @settings[:paragraphs]
text = @body.split("</p>").slice(@settings[:skip_paragraphs], @settings[:paragraphs])
@settings[:ending] = nil
text = text.join("</p>")
close_tags(text)
end | ruby | def paragraphs
return non_excerpted_text if @pghcount < @settings[:paragraphs]
text = @body.split("</p>").slice(@settings[:skip_paragraphs], @settings[:paragraphs])
@settings[:ending] = nil
text = text.join("</p>")
close_tags(text)
end | [
"def",
"paragraphs",
"return",
"non_excerpted_text",
"if",
"@pghcount",
"<",
"@settings",
"[",
":paragraphs",
"]",
"text",
"=",
"@body",
".",
"split",
"(",
"\"</p>\"",
")",
".",
"slice",
"(",
"@settings",
"[",
":skip_paragraphs",
"]",
",",
"@settings",
"[",
":paragraphs",
"]",
")",
"@settings",
"[",
":ending",
"]",
"=",
"nil",
"text",
"=",
"text",
".",
"join",
"(",
"\"</p>\"",
")",
"close_tags",
"(",
"text",
")",
"end"
] | limit by paragraphs | [
"limit",
"by",
"paragraphs"
] | 17514e21d5ee275e14d1596db387730d7ebb2b14 | https://github.com/RipTheJacker/auto_excerpt/blob/17514e21d5ee275e14d1596db387730d7ebb2b14/lib/auto_excerpt/parser.rb#L150-L156 |
5,162 | RipTheJacker/auto_excerpt | lib/auto_excerpt/parser.rb | AutoExcerpt.Parser.strip_html | def strip_html(html)
return @stripped_html if @stripped_html
allowed = @settings[:allowed_tags]
reg = if allowed.any?
Regexp.new(
%(<(?!(\\s|\\/)*(#{
allowed.map {|tag| Regexp.escape( tag )}.join( "|" )
})( |>|\\/|'|"|<|\\s*\\z))[^>]*(>+|\\s*\\z)),
Regexp::IGNORECASE | Regexp::MULTILINE, 'u'
)
else
/<[^>]*(>+|\s*\z)/m
end
@stripped_html = html.gsub(reg,'')
end | ruby | def strip_html(html)
return @stripped_html if @stripped_html
allowed = @settings[:allowed_tags]
reg = if allowed.any?
Regexp.new(
%(<(?!(\\s|\\/)*(#{
allowed.map {|tag| Regexp.escape( tag )}.join( "|" )
})( |>|\\/|'|"|<|\\s*\\z))[^>]*(>+|\\s*\\z)),
Regexp::IGNORECASE | Regexp::MULTILINE, 'u'
)
else
/<[^>]*(>+|\s*\z)/m
end
@stripped_html = html.gsub(reg,'')
end | [
"def",
"strip_html",
"(",
"html",
")",
"return",
"@stripped_html",
"if",
"@stripped_html",
"allowed",
"=",
"@settings",
"[",
":allowed_tags",
"]",
"reg",
"=",
"if",
"allowed",
".",
"any?",
"Regexp",
".",
"new",
"(",
"%(<(?!(\\\\s|\\\\/)*(#{\n allowed.map {|tag| Regexp.escape( tag )}.join( \"|\" )\n })( |>|\\\\/|'|\"|<|\\\\s*\\\\z))[^>]*(>+|\\\\s*\\\\z))",
",",
"Regexp",
"::",
"IGNORECASE",
"|",
"Regexp",
"::",
"MULTILINE",
",",
"'u'",
")",
"else",
"/",
"\\s",
"\\z",
"/m",
"end",
"@stripped_html",
"=",
"html",
".",
"gsub",
"(",
"reg",
",",
"''",
")",
"end"
] | Removes HTML tags from a string. Allows you to specify some tags to be kept.
@see http://codesnippets.joyent.com/posts/show/1354#comment-293 | [
"Removes",
"HTML",
"tags",
"from",
"a",
"string",
".",
"Allows",
"you",
"to",
"specify",
"some",
"tags",
"to",
"be",
"kept",
"."
] | 17514e21d5ee275e14d1596db387730d7ebb2b14 | https://github.com/RipTheJacker/auto_excerpt/blob/17514e21d5ee275e14d1596db387730d7ebb2b14/lib/auto_excerpt/parser.rb#L165-L179 |
5,163 | kunishi/algebra-ruby2 | lib/algebra/gaussian-elimination.rb | Algebra.SquareMatrix.determinant_by_elimination_old | def determinant_by_elimination_old
m = dup
inv, k = m.left_eliminate!
s = ground.unity
(0...size).each do |i|
s *= m[i, i]
end
s / k
end | ruby | def determinant_by_elimination_old
m = dup
inv, k = m.left_eliminate!
s = ground.unity
(0...size).each do |i|
s *= m[i, i]
end
s / k
end | [
"def",
"determinant_by_elimination_old",
"m",
"=",
"dup",
"inv",
",",
"k",
"=",
"m",
".",
"left_eliminate!",
"s",
"=",
"ground",
".",
"unity",
"(",
"0",
"...",
"size",
")",
".",
"each",
"do",
"|",
"i",
"|",
"s",
"*=",
"m",
"[",
"i",
",",
"i",
"]",
"end",
"s",
"/",
"k",
"end"
] | def inverse_euclidian; left_inverse_euclidian; end | [
"def",
"inverse_euclidian",
";",
"left_inverse_euclidian",
";",
"end"
] | 8976fbaac14933d3206324c845b879bf67fa0cf7 | https://github.com/kunishi/algebra-ruby2/blob/8976fbaac14933d3206324c845b879bf67fa0cf7/lib/algebra/gaussian-elimination.rb#L239-L247 |
5,164 | kunishi/algebra-ruby2 | lib/algebra/gaussian-elimination.rb | Algebra.SquareMatrix.determinant_by_elimination | def determinant_by_elimination
m = dup
det = ground.unity
each_j do |d|
if i = (d...size).find{|i| !m[i, d].zero?}
if i != d
m.sswap_r!(d, i)
det = -det
end
c = m[d, d]
det *= c
(d+1...size).each do |i0|
r = m.row!(i0)
q = ground.unity * m[i0, d] / c #this lets the entries be in ground
(d+1...size).each do |j0|
r[j0] -= q * m[d, j0]
end
end
else
return ground.zero
end
end
det
end | ruby | def determinant_by_elimination
m = dup
det = ground.unity
each_j do |d|
if i = (d...size).find{|i| !m[i, d].zero?}
if i != d
m.sswap_r!(d, i)
det = -det
end
c = m[d, d]
det *= c
(d+1...size).each do |i0|
r = m.row!(i0)
q = ground.unity * m[i0, d] / c #this lets the entries be in ground
(d+1...size).each do |j0|
r[j0] -= q * m[d, j0]
end
end
else
return ground.zero
end
end
det
end | [
"def",
"determinant_by_elimination",
"m",
"=",
"dup",
"det",
"=",
"ground",
".",
"unity",
"each_j",
"do",
"|",
"d",
"|",
"if",
"i",
"=",
"(",
"d",
"...",
"size",
")",
".",
"find",
"{",
"|",
"i",
"|",
"!",
"m",
"[",
"i",
",",
"d",
"]",
".",
"zero?",
"}",
"if",
"i",
"!=",
"d",
"m",
".",
"sswap_r!",
"(",
"d",
",",
"i",
")",
"det",
"=",
"-",
"det",
"end",
"c",
"=",
"m",
"[",
"d",
",",
"d",
"]",
"det",
"*=",
"c",
"(",
"d",
"+",
"1",
"...",
"size",
")",
".",
"each",
"do",
"|",
"i0",
"|",
"r",
"=",
"m",
".",
"row!",
"(",
"i0",
")",
"q",
"=",
"ground",
".",
"unity",
"*",
"m",
"[",
"i0",
",",
"d",
"]",
"/",
"c",
"#this lets the entries be in ground",
"(",
"d",
"+",
"1",
"...",
"size",
")",
".",
"each",
"do",
"|",
"j0",
"|",
"r",
"[",
"j0",
"]",
"-=",
"q",
"*",
"m",
"[",
"d",
",",
"j0",
"]",
"end",
"end",
"else",
"return",
"ground",
".",
"zero",
"end",
"end",
"det",
"end"
] | ground ring must be a field | [
"ground",
"ring",
"must",
"be",
"a",
"field"
] | 8976fbaac14933d3206324c845b879bf67fa0cf7 | https://github.com/kunishi/algebra-ruby2/blob/8976fbaac14933d3206324c845b879bf67fa0cf7/lib/algebra/gaussian-elimination.rb#L260-L283 |
5,165 | jellybob/text_tractor | lib/text_tractor/projects.rb | TextTractor.Project.update_blurb | def update_blurb(state, locale, key, value, overwrite = false)
id = key
key = "projects:#{api_key}:#{state}_blurbs:#{key}"
current_value = redis.sismember("projects:#{api_key}:#{state}_blurb_keys", id) ? JSON.parse(redis.get(key)) : {}
phrase = Phrase.new(self, current_value)
# A new value is only written if no previous translation was present, or overwriting is enabled.
if overwrite || phrase[locale].text.nil?
phrase[locale] = value
redis.sadd "projects:#{api_key}:#{state}_blurb_keys", id
redis.sadd "projects:#{api_key}:locales", locale
redis.set key, phrase.to_hash.to_json
redis.set "projects:#{api_key}:#{state}_blurbs_etag", Projects.random_key
end
end | ruby | def update_blurb(state, locale, key, value, overwrite = false)
id = key
key = "projects:#{api_key}:#{state}_blurbs:#{key}"
current_value = redis.sismember("projects:#{api_key}:#{state}_blurb_keys", id) ? JSON.parse(redis.get(key)) : {}
phrase = Phrase.new(self, current_value)
# A new value is only written if no previous translation was present, or overwriting is enabled.
if overwrite || phrase[locale].text.nil?
phrase[locale] = value
redis.sadd "projects:#{api_key}:#{state}_blurb_keys", id
redis.sadd "projects:#{api_key}:locales", locale
redis.set key, phrase.to_hash.to_json
redis.set "projects:#{api_key}:#{state}_blurbs_etag", Projects.random_key
end
end | [
"def",
"update_blurb",
"(",
"state",
",",
"locale",
",",
"key",
",",
"value",
",",
"overwrite",
"=",
"false",
")",
"id",
"=",
"key",
"key",
"=",
"\"projects:#{api_key}:#{state}_blurbs:#{key}\"",
"current_value",
"=",
"redis",
".",
"sismember",
"(",
"\"projects:#{api_key}:#{state}_blurb_keys\"",
",",
"id",
")",
"?",
"JSON",
".",
"parse",
"(",
"redis",
".",
"get",
"(",
"key",
")",
")",
":",
"{",
"}",
"phrase",
"=",
"Phrase",
".",
"new",
"(",
"self",
",",
"current_value",
")",
"# A new value is only written if no previous translation was present, or overwriting is enabled.",
"if",
"overwrite",
"||",
"phrase",
"[",
"locale",
"]",
".",
"text",
".",
"nil?",
"phrase",
"[",
"locale",
"]",
"=",
"value",
"redis",
".",
"sadd",
"\"projects:#{api_key}:#{state}_blurb_keys\"",
",",
"id",
"redis",
".",
"sadd",
"\"projects:#{api_key}:locales\"",
",",
"locale",
"redis",
".",
"set",
"key",
",",
"phrase",
".",
"to_hash",
".",
"to_json",
"redis",
".",
"set",
"\"projects:#{api_key}:#{state}_blurbs_etag\"",
",",
"Projects",
".",
"random_key",
"end",
"end"
] | Set the overwrite option to true to force overwriting existing translations. | [
"Set",
"the",
"overwrite",
"option",
"to",
"true",
"to",
"force",
"overwriting",
"existing",
"translations",
"."
] | 8ffde8f505655c40614c523ff6b8d18b274d093c | https://github.com/jellybob/text_tractor/blob/8ffde8f505655c40614c523ff6b8d18b274d093c/lib/text_tractor/projects.rb#L39-L55 |
5,166 | ArchimediaZerogroup/KonoUtils | lib/kono_utils/base_search.rb | KonoUtils.BaseSearch.get_query_params | def get_query_params
out = {}
search_attributes.each do |val|
out[val.field]=self.send(val.field) unless self.send(val.field).blank?
end
out
end | ruby | def get_query_params
out = {}
search_attributes.each do |val|
out[val.field]=self.send(val.field) unless self.send(val.field).blank?
end
out
end | [
"def",
"get_query_params",
"out",
"=",
"{",
"}",
"search_attributes",
".",
"each",
"do",
"|",
"val",
"|",
"out",
"[",
"val",
".",
"field",
"]",
"=",
"self",
".",
"send",
"(",
"val",
".",
"field",
")",
"unless",
"self",
".",
"send",
"(",
"val",
".",
"field",
")",
".",
"blank?",
"end",
"out",
"end"
] | Restituisce un hash con tutti i parametri da implementare sulla ricerca | [
"Restituisce",
"un",
"hash",
"con",
"tutti",
"i",
"parametri",
"da",
"implementare",
"sulla",
"ricerca"
] | a255a30b65e4e0f01cd6236d991da4fd13c64fc6 | https://github.com/ArchimediaZerogroup/KonoUtils/blob/a255a30b65e4e0f01cd6236d991da4fd13c64fc6/lib/kono_utils/base_search.rb#L147-L154 |
5,167 | ArchimediaZerogroup/KonoUtils | lib/kono_utils/base_search.rb | KonoUtils.BaseSearch.update_attributes | def update_attributes(datas)
search_attributes.each do |val|
self.send("#{val.field}=", val.cast_value(datas[val.field]))
end
end | ruby | def update_attributes(datas)
search_attributes.each do |val|
self.send("#{val.field}=", val.cast_value(datas[val.field]))
end
end | [
"def",
"update_attributes",
"(",
"datas",
")",
"search_attributes",
".",
"each",
"do",
"|",
"val",
"|",
"self",
".",
"send",
"(",
"\"#{val.field}=\"",
",",
"val",
".",
"cast_value",
"(",
"datas",
"[",
"val",
".",
"field",
"]",
")",
")",
"end",
"end"
] | Si occupa di aggiornare i valori interni di ricerca | [
"Si",
"occupa",
"di",
"aggiornare",
"i",
"valori",
"interni",
"di",
"ricerca"
] | a255a30b65e4e0f01cd6236d991da4fd13c64fc6 | https://github.com/ArchimediaZerogroup/KonoUtils/blob/a255a30b65e4e0f01cd6236d991da4fd13c64fc6/lib/kono_utils/base_search.rb#L158-L162 |
5,168 | leshill/mongodoc | lib/mongoid/criteria.rb | Mongoid.Criteria.fuse | def fuse(criteria_conditions = {})
criteria_conditions.inject(self) do |criteria, (key, value)|
criteria.send(key, value)
end
end | ruby | def fuse(criteria_conditions = {})
criteria_conditions.inject(self) do |criteria, (key, value)|
criteria.send(key, value)
end
end | [
"def",
"fuse",
"(",
"criteria_conditions",
"=",
"{",
"}",
")",
"criteria_conditions",
".",
"inject",
"(",
"self",
")",
"do",
"|",
"criteria",
",",
"(",
"key",
",",
"value",
")",
"|",
"criteria",
".",
"send",
"(",
"key",
",",
"value",
")",
"end",
"end"
] | Merges the supplied argument hash into a single criteria
Options:
criteria_conditions: Hash of criteria keys, and parameter values
Example:
<tt>criteria.fuse(:where => { :field => "value"}, :limit => 20)</tt>
Returns <tt>self</tt> | [
"Merges",
"the",
"supplied",
"argument",
"hash",
"into",
"a",
"single",
"criteria"
] | fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4 | https://github.com/leshill/mongodoc/blob/fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4/lib/mongoid/criteria.rb#L112-L116 |
5,169 | leshill/mongodoc | lib/mongoid/criteria.rb | Mongoid.Criteria.merge | def merge(other)
@selector.update(other.selector)
@options.update(other.options)
@documents = other.documents
end | ruby | def merge(other)
@selector.update(other.selector)
@options.update(other.options)
@documents = other.documents
end | [
"def",
"merge",
"(",
"other",
")",
"@selector",
".",
"update",
"(",
"other",
".",
"selector",
")",
"@options",
".",
"update",
"(",
"other",
".",
"options",
")",
"@documents",
"=",
"other",
".",
"documents",
"end"
] | Create the new +Criteria+ object. This will initialize the selector
and options hashes, as well as the type of criteria.
Options:
type: One of :all, :first:, or :last
klass: The class to execute on.
Merges another object into this +Criteria+. The other object may be a
+Criteria+ or a +Hash+. This is used to combine multiple scopes together,
where a chained scope situation may be desired.
Options:
other: The +Criteria+ or +Hash+ to merge with.
Example:
<tt>criteria.merge({ :conditions => { :title => "Sir" } })</tt> | [
"Create",
"the",
"new",
"+",
"Criteria",
"+",
"object",
".",
"This",
"will",
"initialize",
"the",
"selector",
"and",
"options",
"hashes",
"as",
"well",
"as",
"the",
"type",
"of",
"criteria",
"."
] | fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4 | https://github.com/leshill/mongodoc/blob/fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4/lib/mongoid/criteria.rb#L140-L144 |
5,170 | leshill/mongodoc | lib/mongoid/criteria.rb | Mongoid.Criteria.filter_options | def filter_options
page_num = @options.delete(:page)
per_page_num = @options.delete(:per_page)
if (page_num || per_page_num)
@options[:limit] = limits = (per_page_num || 20).to_i
@options[:skip] = (page_num || 1).to_i * limits - limits
end
end | ruby | def filter_options
page_num = @options.delete(:page)
per_page_num = @options.delete(:per_page)
if (page_num || per_page_num)
@options[:limit] = limits = (per_page_num || 20).to_i
@options[:skip] = (page_num || 1).to_i * limits - limits
end
end | [
"def",
"filter_options",
"page_num",
"=",
"@options",
".",
"delete",
"(",
":page",
")",
"per_page_num",
"=",
"@options",
".",
"delete",
"(",
":per_page",
")",
"if",
"(",
"page_num",
"||",
"per_page_num",
")",
"@options",
"[",
":limit",
"]",
"=",
"limits",
"=",
"(",
"per_page_num",
"||",
"20",
")",
".",
"to_i",
"@options",
"[",
":skip",
"]",
"=",
"(",
"page_num",
"||",
"1",
")",
".",
"to_i",
"*",
"limits",
"-",
"limits",
"end",
"end"
] | Filters the unused options out of the options +Hash+. Currently this
takes into account the "page" and "per_page" options that would be passed
in if using will_paginate.
Example:
Given a criteria with a selector of { :page => 1, :per_page => 40 }
<tt>criteria.filter_options</tt> # selector: { :skip => 0, :limit => 40 } | [
"Filters",
"the",
"unused",
"options",
"out",
"of",
"the",
"options",
"+",
"Hash",
"+",
".",
"Currently",
"this",
"takes",
"into",
"account",
"the",
"page",
"and",
"per_page",
"options",
"that",
"would",
"be",
"passed",
"in",
"if",
"using",
"will_paginate",
"."
] | fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4 | https://github.com/leshill/mongodoc/blob/fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4/lib/mongoid/criteria.rb#L214-L221 |
5,171 | leshill/mongodoc | lib/mongoid/criteria.rb | Mongoid.Criteria.update_selector | def update_selector(attributes, operator)
attributes.each { |key, value| @selector[key] = { operator => value } }; self
end | ruby | def update_selector(attributes, operator)
attributes.each { |key, value| @selector[key] = { operator => value } }; self
end | [
"def",
"update_selector",
"(",
"attributes",
",",
"operator",
")",
"attributes",
".",
"each",
"{",
"|",
"key",
",",
"value",
"|",
"@selector",
"[",
"key",
"]",
"=",
"{",
"operator",
"=>",
"value",
"}",
"}",
";",
"self",
"end"
] | Update the selector setting the operator on the value for each key in the
supplied attributes +Hash+.
Example:
<tt>criteria.update_selector({ :field => "value" }, "$in")</tt> | [
"Update",
"the",
"selector",
"setting",
"the",
"operator",
"on",
"the",
"value",
"for",
"each",
"key",
"in",
"the",
"supplied",
"attributes",
"+",
"Hash",
"+",
"."
] | fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4 | https://github.com/leshill/mongodoc/blob/fb2a4ec456d4c4ae1eb92e117dc73f55951fc3b4/lib/mongoid/criteria.rb#L235-L237 |
5,172 | kjvarga/arid_cache | lib/arid_cache/framework.rb | AridCache.Framework.active_record? | def active_record?(*args)
version, comparator = args.pop, (args.pop || :==)
result =
if version.nil?
defined?(::ActiveRecord)
elsif defined?(::ActiveRecord)
ar_version = ::ActiveRecord::VERSION::STRING.to_f
ar_version = ar_version.floor if version.is_a?(Integer)
ar_version.send(comparator, version.to_f)
else
false
end
!!result
end | ruby | def active_record?(*args)
version, comparator = args.pop, (args.pop || :==)
result =
if version.nil?
defined?(::ActiveRecord)
elsif defined?(::ActiveRecord)
ar_version = ::ActiveRecord::VERSION::STRING.to_f
ar_version = ar_version.floor if version.is_a?(Integer)
ar_version.send(comparator, version.to_f)
else
false
end
!!result
end | [
"def",
"active_record?",
"(",
"*",
"args",
")",
"version",
",",
"comparator",
"=",
"args",
".",
"pop",
",",
"(",
"args",
".",
"pop",
"||",
":==",
")",
"result",
"=",
"if",
"version",
".",
"nil?",
"defined?",
"(",
"::",
"ActiveRecord",
")",
"elsif",
"defined?",
"(",
"::",
"ActiveRecord",
")",
"ar_version",
"=",
"::",
"ActiveRecord",
"::",
"VERSION",
"::",
"STRING",
".",
"to_f",
"ar_version",
"=",
"ar_version",
".",
"floor",
"if",
"version",
".",
"is_a?",
"(",
"Integer",
")",
"ar_version",
".",
"send",
"(",
"comparator",
",",
"version",
".",
"to_f",
")",
"else",
"false",
"end",
"!",
"!",
"result",
"end"
] | Return a boolean indicating whether the version of ActiveRecord matches
the constraints in the args.
== Arguments
Optional comparator function as a symbol followed by a version number
as an integer or float.
If the version is an integer only the major version is compared.
if the version is a float the major.minor version is compared.
If called with no arguments returns a boolean indicating whether ActiveRecord
is defined.
== Example
active_record?(3) => true if ActiveRecord major version is 3
active_record?(3.0) => true if ActiveRecord major.minor version is 3.0
active_record?(:>=, 3) => true if ActiveRecord major version is >= 3
active_record?(:>=, 3.1) => true if ActiveRecord major.minor version is >= 3.1 | [
"Return",
"a",
"boolean",
"indicating",
"whether",
"the",
"version",
"of",
"ActiveRecord",
"matches",
"the",
"constraints",
"in",
"the",
"args",
"."
] | 8a1e21b970aae37a3206a4ee08efa6f1002fc9e0 | https://github.com/kjvarga/arid_cache/blob/8a1e21b970aae37a3206a4ee08efa6f1002fc9e0/lib/arid_cache/framework.rb#L23-L36 |
5,173 | securityroots/vulndbhq | lib/vulndbhq/client.rb | VulnDBHQ.Client.private_page | def private_page(id, options={})
response = get("/api/private_pages/#{id}", options)
VulnDBHQ::PrivatePage.from_response(response)
end | ruby | def private_page(id, options={})
response = get("/api/private_pages/#{id}", options)
VulnDBHQ::PrivatePage.from_response(response)
end | [
"def",
"private_page",
"(",
"id",
",",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"get",
"(",
"\"/api/private_pages/#{id}\"",
",",
"options",
")",
"VulnDBHQ",
"::",
"PrivatePage",
".",
"from_response",
"(",
"response",
")",
"end"
] | Initializes a new Client object
@param options [Hash]
@return [VulnDBHQ::Client]
************************************************************* PrivatePage
Returns a private page
@see http://support.securityroots.com/vulndbhq_api_v2.html#model-private-page
@authentication_required Yes
@raise [VulnDBHQ::Error::Unauthorized] Error raised when supplied user credentials are not valid.
@return [VulnDBHQ::PrivatePage] The requested messages.
@param id [Integer] A VulnDB HQ private page ID.
@param options [Hash] A customizable set of options.
@example Return the private page with the id 87
VulnDBHQ.private_page(87) | [
"Initializes",
"a",
"new",
"Client",
"object"
] | 14db8db3877498d16fce166017bd50301b71fb63 | https://github.com/securityroots/vulndbhq/blob/14db8db3877498d16fce166017bd50301b71fb63/lib/vulndbhq/client.rb#L46-L49 |
5,174 | snusnu/substation | lib/substation/environment.rb | Substation.Environment.inherit | def inherit(app_env = self.app_env, actions = Dispatcher.new_registry, &block)
self.class.new(app_env, actions, merged_chain_dsl(&block))
end | ruby | def inherit(app_env = self.app_env, actions = Dispatcher.new_registry, &block)
self.class.new(app_env, actions, merged_chain_dsl(&block))
end | [
"def",
"inherit",
"(",
"app_env",
"=",
"self",
".",
"app_env",
",",
"actions",
"=",
"Dispatcher",
".",
"new_registry",
",",
"&",
"block",
")",
"self",
".",
"class",
".",
"new",
"(",
"app_env",
",",
"actions",
",",
"merged_chain_dsl",
"(",
"block",
")",
")",
"end"
] | Initialize a new instance
@param [Chain::DSL] chain_dsl
the chain dsl tailored for the environment
@return [undefined]
@api private
Inherit a new instance from self, merging the {Chain::DSL}
@param [Dispatcher::Registry] actions
the mutable action registry
@param [Proc] block
a block to instance_eval inside a {DSL} instance
@return [Environment]
@api private | [
"Initialize",
"a",
"new",
"instance"
] | fabf062a3640f5e82dae68597f0709b63f6b9027 | https://github.com/snusnu/substation/blob/fabf062a3640f5e82dae68597f0709b63f6b9027/lib/substation/environment.rb#L91-L93 |
5,175 | snusnu/substation | lib/substation/environment.rb | Substation.Environment.register | def register(name, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &block)
actions[name] = chain(name, other, exception_chain, &block)
self
end | ruby | def register(name, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &block)
actions[name] = chain(name, other, exception_chain, &block)
self
end | [
"def",
"register",
"(",
"name",
",",
"other",
"=",
"Chain",
"::",
"EMPTY",
",",
"exception_chain",
"=",
"Chain",
"::",
"EMPTY",
",",
"&",
"block",
")",
"actions",
"[",
"name",
"]",
"=",
"chain",
"(",
"name",
",",
"other",
",",
"exception_chain",
",",
"block",
")",
"self",
"end"
] | Register a new chain under the given +name+
@param [#to_sym] name
the new chain's name
@param [Chain] other
the chain to build on top of
@param [Chain] exception_chain
the chain to invoke in case of uncaught exceptions in handlers
@return [Chain]
the registered chain
@api private | [
"Register",
"a",
"new",
"chain",
"under",
"the",
"given",
"+",
"name",
"+"
] | fabf062a3640f5e82dae68597f0709b63f6b9027 | https://github.com/snusnu/substation/blob/fabf062a3640f5e82dae68597f0709b63f6b9027/lib/substation/environment.rb#L131-L134 |
5,176 | dwradcliffe/groupme | lib/groupme/messages.rb | GroupMe.Messages.create_message | def create_message(group_id, text, attachments = [])
data = {
:message => {
:source_guid => SecureRandom.uuid,
:text => text
}
}
data[:message][:attachments] = attachments if attachments.any?
post("/groups/#{group_id}/messages", data).message
end | ruby | def create_message(group_id, text, attachments = [])
data = {
:message => {
:source_guid => SecureRandom.uuid,
:text => text
}
}
data[:message][:attachments] = attachments if attachments.any?
post("/groups/#{group_id}/messages", data).message
end | [
"def",
"create_message",
"(",
"group_id",
",",
"text",
",",
"attachments",
"=",
"[",
"]",
")",
"data",
"=",
"{",
":message",
"=>",
"{",
":source_guid",
"=>",
"SecureRandom",
".",
"uuid",
",",
":text",
"=>",
"text",
"}",
"}",
"data",
"[",
":message",
"]",
"[",
":attachments",
"]",
"=",
"attachments",
"if",
"attachments",
".",
"any?",
"post",
"(",
"\"/groups/#{group_id}/messages\"",
",",
"data",
")",
".",
"message",
"end"
] | Create a message for a group
@return [Hashie::Mash] Hash representing the message
@see https://dev.groupme.com/docs/v3#messages_create
@param group_id [String, Integer] Id of the group
@param text [String] Text of the message
@param attachments [Array<Hash>] Array of attachments | [
"Create",
"a",
"message",
"for",
"a",
"group"
] | a306dbcf38cc4d9ed219e010783799b2ccb4f9a2 | https://github.com/dwradcliffe/groupme/blob/a306dbcf38cc4d9ed219e010783799b2ccb4f9a2/lib/groupme/messages.rb#L12-L21 |
5,177 | dwradcliffe/groupme | lib/groupme/messages.rb | GroupMe.Messages.messages | def messages(group_id, options = {}, fetch_all = false)
if fetch_all
get_all_messages(group_id)
else
get_messages(group_id, options)
end
end | ruby | def messages(group_id, options = {}, fetch_all = false)
if fetch_all
get_all_messages(group_id)
else
get_messages(group_id, options)
end
end | [
"def",
"messages",
"(",
"group_id",
",",
"options",
"=",
"{",
"}",
",",
"fetch_all",
"=",
"false",
")",
"if",
"fetch_all",
"get_all_messages",
"(",
"group_id",
")",
"else",
"get_messages",
"(",
"group_id",
",",
"options",
")",
"end",
"end"
] | List messages for a group
@return [Array<Hashie::Mash>] Array of hashes representing the messages
@see https://dev.groupme.com/docs/v3#messages_index
@param group_id [String, Integer] Id of the group
@param options [Hash] options hash that will be passed to the groupme call
@param fetch_all [Boolean] if true, fetches all messages for the group | [
"List",
"messages",
"for",
"a",
"group"
] | a306dbcf38cc4d9ed219e010783799b2ccb4f9a2 | https://github.com/dwradcliffe/groupme/blob/a306dbcf38cc4d9ed219e010783799b2ccb4f9a2/lib/groupme/messages.rb#L30-L36 |
5,178 | razor-x/config_curator | lib/config_curator/units/symlink.rb | ConfigCurator.Symlink.install_symlink | def install_symlink
FileUtils.mkdir_p File.dirname(destination_path)
FileUtils.symlink source_path, destination_path, force: true
end | ruby | def install_symlink
FileUtils.mkdir_p File.dirname(destination_path)
FileUtils.symlink source_path, destination_path, force: true
end | [
"def",
"install_symlink",
"FileUtils",
".",
"mkdir_p",
"File",
".",
"dirname",
"(",
"destination_path",
")",
"FileUtils",
".",
"symlink",
"source_path",
",",
"destination_path",
",",
"force",
":",
"true",
"end"
] | Recursively creates the necessary directories and make the symlink. | [
"Recursively",
"creates",
"the",
"necessary",
"directories",
"and",
"make",
"the",
"symlink",
"."
] | b0c0742ba0c36acf66de3eafd23a7d17b210036b | https://github.com/razor-x/config_curator/blob/b0c0742ba0c36acf66de3eafd23a7d17b210036b/lib/config_curator/units/symlink.rb#L39-L42 |
5,179 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__get_partials_for_module | def core__get_partials_for_module(module_name)
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_partials = []
if module_configs[:partials]
module_configs[:partials].each do |key, value|
module_partials.push(core__generate_partial(key, value, module_name))
end
end
# return module items
module_partials
end | ruby | def core__get_partials_for_module(module_name)
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_partials = []
if module_configs[:partials]
module_configs[:partials].each do |key, value|
module_partials.push(core__generate_partial(key, value, module_name))
end
end
# return module items
module_partials
end | [
"def",
"core__get_partials_for_module",
"(",
"module_name",
")",
"module_configs",
"=",
"core__get_module_configs",
"(",
"module_name",
")",
"return",
"[",
"]",
"unless",
"module_configs",
"# load module items",
"module_partials",
"=",
"[",
"]",
"if",
"module_configs",
"[",
":partials",
"]",
"module_configs",
"[",
":partials",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"module_partials",
".",
"push",
"(",
"core__generate_partial",
"(",
"key",
",",
"value",
",",
"module_name",
")",
")",
"end",
"end",
"# return module items",
"module_partials",
"end"
] | This function return the list of partials for a specific module. | [
"This",
"function",
"return",
"the",
"list",
"of",
"partials",
"for",
"a",
"specific",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L35-L47 |
5,180 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__generate_partial | def core__generate_partial(key, values, module_name)
partial = {}
partial[:key] = key
partial[:path] = values[:path] ? values[:path] : ''
partial[:position] = values[:position] ? values[:position] : 999
partial
end | ruby | def core__generate_partial(key, values, module_name)
partial = {}
partial[:key] = key
partial[:path] = values[:path] ? values[:path] : ''
partial[:position] = values[:position] ? values[:position] : 999
partial
end | [
"def",
"core__generate_partial",
"(",
"key",
",",
"values",
",",
"module_name",
")",
"partial",
"=",
"{",
"}",
"partial",
"[",
":key",
"]",
"=",
"key",
"partial",
"[",
":path",
"]",
"=",
"values",
"[",
":path",
"]",
"?",
"values",
"[",
":path",
"]",
":",
"''",
"partial",
"[",
":position",
"]",
"=",
"values",
"[",
":position",
"]",
"?",
"values",
"[",
":position",
"]",
":",
"999",
"partial",
"end"
] | This function create a correct partial object for the header. | [
"This",
"function",
"create",
"a",
"correct",
"partial",
"object",
"for",
"the",
"header",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L50-L56 |
5,181 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__get_widgets_for_module | def core__get_widgets_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_widgets = []
if module_configs[:widgets]
module_configs[:widgets].each do |key, value|
module_widgets.push(core__generate_widget(key, value, module_name))
end
end
# return module items
return module_widgets
end | ruby | def core__get_widgets_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_widgets = []
if module_configs[:widgets]
module_configs[:widgets].each do |key, value|
module_widgets.push(core__generate_widget(key, value, module_name))
end
end
# return module items
return module_widgets
end | [
"def",
"core__get_widgets_for_module",
"module_name",
"module_configs",
"=",
"core__get_module_configs",
"(",
"module_name",
")",
"return",
"[",
"]",
"unless",
"module_configs",
"# load module items",
"module_widgets",
"=",
"[",
"]",
"if",
"module_configs",
"[",
":widgets",
"]",
"module_configs",
"[",
":widgets",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"module_widgets",
".",
"push",
"(",
"core__generate_widget",
"(",
"key",
",",
"value",
",",
"module_name",
")",
")",
"end",
"end",
"# return module items",
"return",
"module_widgets",
"end"
] | This function return the list of widgets for a specific module. | [
"This",
"function",
"return",
"the",
"list",
"of",
"widgets",
"for",
"a",
"specific",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L75-L87 |
5,182 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__generate_widget | def core__generate_widget key, values, module_name
widget = {}
widget[:key] = key
widget[:icon] = values[:icon] ? values[:icon] : 'check-circle'
widget[:path] = values[:path] ? values[:path] : ''
widget[:position] = values[:position] ? values[:position] : 999
widget[:title] = values[:title] ? values[:title] : ''
return widget
end | ruby | def core__generate_widget key, values, module_name
widget = {}
widget[:key] = key
widget[:icon] = values[:icon] ? values[:icon] : 'check-circle'
widget[:path] = values[:path] ? values[:path] : ''
widget[:position] = values[:position] ? values[:position] : 999
widget[:title] = values[:title] ? values[:title] : ''
return widget
end | [
"def",
"core__generate_widget",
"key",
",",
"values",
",",
"module_name",
"widget",
"=",
"{",
"}",
"widget",
"[",
":key",
"]",
"=",
"key",
"widget",
"[",
":icon",
"]",
"=",
"values",
"[",
":icon",
"]",
"?",
"values",
"[",
":icon",
"]",
":",
"'check-circle'",
"widget",
"[",
":path",
"]",
"=",
"values",
"[",
":path",
"]",
"?",
"values",
"[",
":path",
"]",
":",
"''",
"widget",
"[",
":position",
"]",
"=",
"values",
"[",
":position",
"]",
"?",
"values",
"[",
":position",
"]",
":",
"999",
"widget",
"[",
":title",
"]",
"=",
"values",
"[",
":title",
"]",
"?",
"values",
"[",
":title",
"]",
":",
"''",
"return",
"widget",
"end"
] | This function create a correct widget object for the header. | [
"This",
"function",
"create",
"a",
"correct",
"widget",
"object",
"for",
"the",
"header",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L90-L98 |
5,183 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__get_menu_for_module | def core__get_menu_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_menu = []
if module_configs[:menu]
module_configs[:menu].each do |key, value|
module_menu.push(core__generate_menu_item(key, value, module_name))
end
end
# return module items
return module_menu
end | ruby | def core__get_menu_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module items
module_menu = []
if module_configs[:menu]
module_configs[:menu].each do |key, value|
module_menu.push(core__generate_menu_item(key, value, module_name))
end
end
# return module items
return module_menu
end | [
"def",
"core__get_menu_for_module",
"module_name",
"module_configs",
"=",
"core__get_module_configs",
"(",
"module_name",
")",
"return",
"[",
"]",
"unless",
"module_configs",
"# load module items",
"module_menu",
"=",
"[",
"]",
"if",
"module_configs",
"[",
":menu",
"]",
"module_configs",
"[",
":menu",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"module_menu",
".",
"push",
"(",
"core__generate_menu_item",
"(",
"key",
",",
"value",
",",
"module_name",
")",
")",
"end",
"end",
"# return module items",
"return",
"module_menu",
"end"
] | This function returns the list of the items for the menu for a specific module. | [
"This",
"function",
"returns",
"the",
"list",
"of",
"the",
"items",
"for",
"the",
"menu",
"for",
"a",
"specific",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L117-L129 |
5,184 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__generate_menu_item | def core__generate_menu_item key, values, module_name
menu_item = {}
menu_item[:key] = key
menu_item[:title] = values[:title] ? core__get_menu_title_translation(values[:title], module_name) : 'Undefined'
menu_item[:icon] = values[:icon] ? values[:icon] : 'check-circle'
menu_item[:url] = values[:url] ? values[:url] : ''
menu_item[:position] = values[:position] ? values[:position] : 999
menu_item[:permission_min] = values[:permission_min] ? values[:permission_min] : 0
menu_item[:permission_max] = values[:permission_max] ? values[:permission_max] : 999
menu_item[:sub_items] = []
if values[:sub_items]
values[:sub_items].each do |key, value|
menu_item[:sub_items].push(core__generate_menu_sub_item(key, value, module_name))
end
end
return menu_item
end | ruby | def core__generate_menu_item key, values, module_name
menu_item = {}
menu_item[:key] = key
menu_item[:title] = values[:title] ? core__get_menu_title_translation(values[:title], module_name) : 'Undefined'
menu_item[:icon] = values[:icon] ? values[:icon] : 'check-circle'
menu_item[:url] = values[:url] ? values[:url] : ''
menu_item[:position] = values[:position] ? values[:position] : 999
menu_item[:permission_min] = values[:permission_min] ? values[:permission_min] : 0
menu_item[:permission_max] = values[:permission_max] ? values[:permission_max] : 999
menu_item[:sub_items] = []
if values[:sub_items]
values[:sub_items].each do |key, value|
menu_item[:sub_items].push(core__generate_menu_sub_item(key, value, module_name))
end
end
return menu_item
end | [
"def",
"core__generate_menu_item",
"key",
",",
"values",
",",
"module_name",
"menu_item",
"=",
"{",
"}",
"menu_item",
"[",
":key",
"]",
"=",
"key",
"menu_item",
"[",
":title",
"]",
"=",
"values",
"[",
":title",
"]",
"?",
"core__get_menu_title_translation",
"(",
"values",
"[",
":title",
"]",
",",
"module_name",
")",
":",
"'Undefined'",
"menu_item",
"[",
":icon",
"]",
"=",
"values",
"[",
":icon",
"]",
"?",
"values",
"[",
":icon",
"]",
":",
"'check-circle'",
"menu_item",
"[",
":url",
"]",
"=",
"values",
"[",
":url",
"]",
"?",
"values",
"[",
":url",
"]",
":",
"''",
"menu_item",
"[",
":position",
"]",
"=",
"values",
"[",
":position",
"]",
"?",
"values",
"[",
":position",
"]",
":",
"999",
"menu_item",
"[",
":permission_min",
"]",
"=",
"values",
"[",
":permission_min",
"]",
"?",
"values",
"[",
":permission_min",
"]",
":",
"0",
"menu_item",
"[",
":permission_max",
"]",
"=",
"values",
"[",
":permission_max",
"]",
"?",
"values",
"[",
":permission_max",
"]",
":",
"999",
"menu_item",
"[",
":sub_items",
"]",
"=",
"[",
"]",
"if",
"values",
"[",
":sub_items",
"]",
"values",
"[",
":sub_items",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"menu_item",
"[",
":sub_items",
"]",
".",
"push",
"(",
"core__generate_menu_sub_item",
"(",
"key",
",",
"value",
",",
"module_name",
")",
")",
"end",
"end",
"return",
"menu_item",
"end"
] | This function create a correct menu item object for the menu. | [
"This",
"function",
"create",
"a",
"correct",
"menu",
"item",
"object",
"for",
"the",
"menu",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L132-L150 |
5,185 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__generate_menu_sub_item | def core__generate_menu_sub_item key, values, module_name
menu_sub_item = {}
menu_sub_item[:key] = key
menu_sub_item[:title] = values[:title] ? core__get_menu_title_translation(values[:title], module_name) : 'Undefined'
menu_sub_item[:url] = values[:url] ? values[:url] : ''
menu_sub_item[:permission_min] = values[:permission_min] ? values[:permission_min] : 0
menu_sub_item[:permission_max] = values[:permission_max] ? values[:permission_max] : 999
return menu_sub_item
end | ruby | def core__generate_menu_sub_item key, values, module_name
menu_sub_item = {}
menu_sub_item[:key] = key
menu_sub_item[:title] = values[:title] ? core__get_menu_title_translation(values[:title], module_name) : 'Undefined'
menu_sub_item[:url] = values[:url] ? values[:url] : ''
menu_sub_item[:permission_min] = values[:permission_min] ? values[:permission_min] : 0
menu_sub_item[:permission_max] = values[:permission_max] ? values[:permission_max] : 999
return menu_sub_item
end | [
"def",
"core__generate_menu_sub_item",
"key",
",",
"values",
",",
"module_name",
"menu_sub_item",
"=",
"{",
"}",
"menu_sub_item",
"[",
":key",
"]",
"=",
"key",
"menu_sub_item",
"[",
":title",
"]",
"=",
"values",
"[",
":title",
"]",
"?",
"core__get_menu_title_translation",
"(",
"values",
"[",
":title",
"]",
",",
"module_name",
")",
":",
"'Undefined'",
"menu_sub_item",
"[",
":url",
"]",
"=",
"values",
"[",
":url",
"]",
"?",
"values",
"[",
":url",
"]",
":",
"''",
"menu_sub_item",
"[",
":permission_min",
"]",
"=",
"values",
"[",
":permission_min",
"]",
"?",
"values",
"[",
":permission_min",
"]",
":",
"0",
"menu_sub_item",
"[",
":permission_max",
"]",
"=",
"values",
"[",
":permission_max",
"]",
"?",
"values",
"[",
":permission_max",
"]",
":",
"999",
"return",
"menu_sub_item",
"end"
] | This function create a correct menu sub itam object for the menu. | [
"This",
"function",
"create",
"a",
"correct",
"menu",
"sub",
"itam",
"object",
"for",
"the",
"menu",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L153-L161 |
5,186 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__get_menu_title_translation | def core__get_menu_title_translation title, module_name
return title if (!title.start_with?('translate'))
title_key = core__get_string_inside_strings(title, '[', ']')
module_languages = core__get_module_languages(module_name)
return title if !module_languages || !module_languages[:menu] || !module_languages[:menu][title_key]
return module_languages[:menu][title_key]
end | ruby | def core__get_menu_title_translation title, module_name
return title if (!title.start_with?('translate'))
title_key = core__get_string_inside_strings(title, '[', ']')
module_languages = core__get_module_languages(module_name)
return title if !module_languages || !module_languages[:menu] || !module_languages[:menu][title_key]
return module_languages[:menu][title_key]
end | [
"def",
"core__get_menu_title_translation",
"title",
",",
"module_name",
"return",
"title",
"if",
"(",
"!",
"title",
".",
"start_with?",
"(",
"'translate'",
")",
")",
"title_key",
"=",
"core__get_string_inside_strings",
"(",
"title",
",",
"'['",
",",
"']'",
")",
"module_languages",
"=",
"core__get_module_languages",
"(",
"module_name",
")",
"return",
"title",
"if",
"!",
"module_languages",
"||",
"!",
"module_languages",
"[",
":menu",
"]",
"||",
"!",
"module_languages",
"[",
":menu",
"]",
"[",
"title_key",
"]",
"return",
"module_languages",
"[",
":menu",
"]",
"[",
"title_key",
"]",
"end"
] | This function check the title name and, if it need a translaction, it return the value. | [
"This",
"function",
"check",
"the",
"title",
"name",
"and",
"if",
"it",
"need",
"a",
"translaction",
"it",
"return",
"the",
"value",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L164-L172 |
5,187 | ideonetwork/lato-core | lib/lato_core/interfaces/layout.rb | LatoCore.Interface::Layout.core__get_assets_for_module | def core__get_assets_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module assets
module_assets = []
if module_configs[:assets]
module_configs[:assets].each do |key, value|
module_assets.push(value)
end
end
# return module assets
return module_assets
end | ruby | def core__get_assets_for_module module_name
module_configs = core__get_module_configs(module_name)
return [] unless module_configs
# load module assets
module_assets = []
if module_configs[:assets]
module_configs[:assets].each do |key, value|
module_assets.push(value)
end
end
# return module assets
return module_assets
end | [
"def",
"core__get_assets_for_module",
"module_name",
"module_configs",
"=",
"core__get_module_configs",
"(",
"module_name",
")",
"return",
"[",
"]",
"unless",
"module_configs",
"# load module assets",
"module_assets",
"=",
"[",
"]",
"if",
"module_configs",
"[",
":assets",
"]",
"module_configs",
"[",
":assets",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"module_assets",
".",
"push",
"(",
"value",
")",
"end",
"end",
"# return module assets",
"return",
"module_assets",
"end"
] | This function return the lists of assets for a specific module. | [
"This",
"function",
"return",
"the",
"lists",
"of",
"assets",
"for",
"a",
"specific",
"module",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/lib/lato_core/interfaces/layout.rb#L190-L202 |
5,188 | murayama/azure_media_service_ruby | lib/azure_media_service/service.rb | AzureMediaService.Service.create_access_policy | def create_access_policy(name:'Policy', duration_minutes:300, permission:2)
warn("DEPRECATION WARNING: Service#create_access_policy is deprecated. Use AzureMediaService::AccessPolicy.create() instead.")
post_body = {
"Name" => name,
"DurationInMinutes" => duration_minutes,
"Permissions" => permission
}
res = @request.post("AccessPolicies", post_body)
AccessPolicy.new(res["d"])
end | ruby | def create_access_policy(name:'Policy', duration_minutes:300, permission:2)
warn("DEPRECATION WARNING: Service#create_access_policy is deprecated. Use AzureMediaService::AccessPolicy.create() instead.")
post_body = {
"Name" => name,
"DurationInMinutes" => duration_minutes,
"Permissions" => permission
}
res = @request.post("AccessPolicies", post_body)
AccessPolicy.new(res["d"])
end | [
"def",
"create_access_policy",
"(",
"name",
":",
"'Policy'",
",",
"duration_minutes",
":",
"300",
",",
"permission",
":",
"2",
")",
"warn",
"(",
"\"DEPRECATION WARNING: Service#create_access_policy is deprecated. Use AzureMediaService::AccessPolicy.create() instead.\"",
")",
"post_body",
"=",
"{",
"\"Name\"",
"=>",
"name",
",",
"\"DurationInMinutes\"",
"=>",
"duration_minutes",
",",
"\"Permissions\"",
"=>",
"permission",
"}",
"res",
"=",
"@request",
".",
"post",
"(",
"\"AccessPolicies\"",
",",
"post_body",
")",
"AccessPolicy",
".",
"new",
"(",
"res",
"[",
"\"d\"",
"]",
")",
"end"
] | access policy create | [
"access",
"policy",
"create"
] | e6f84daefab685a2dd4fa1de759d115a0800a967 | https://github.com/murayama/azure_media_service_ruby/blob/e6f84daefab685a2dd4fa1de759d115a0800a967/lib/azure_media_service/service.rb#L25-L34 |
5,189 | Sharparam/chatrix | lib/chatrix/room.rb | Chatrix.Room.process_join | def process_join(data)
@state.update data['state'] if data.key? 'state'
@timeline.update data['timeline'] if data.key? 'timeline'
end | ruby | def process_join(data)
@state.update data['state'] if data.key? 'state'
@timeline.update data['timeline'] if data.key? 'timeline'
end | [
"def",
"process_join",
"(",
"data",
")",
"@state",
".",
"update",
"data",
"[",
"'state'",
"]",
"if",
"data",
".",
"key?",
"'state'",
"@timeline",
".",
"update",
"data",
"[",
"'timeline'",
"]",
"if",
"data",
".",
"key?",
"'timeline'",
"end"
] | Initializes a new Room instance.
@param id [String] The room ID.
@param users [Users] The User manager.
@param matrix [Matrix] The Matrix API instance.
Process join events for this room.
@param data [Hash] Event data containing state and timeline events. | [
"Initializes",
"a",
"new",
"Room",
"instance",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/room.rb#L62-L65 |
5,190 | Sharparam/chatrix | lib/chatrix/room.rb | Chatrix.Room.process_leave | def process_leave(data)
@state.update data['state'] if data.key? 'state'
@timeline.update data['timeline'] if data.key? 'timeline'
end | ruby | def process_leave(data)
@state.update data['state'] if data.key? 'state'
@timeline.update data['timeline'] if data.key? 'timeline'
end | [
"def",
"process_leave",
"(",
"data",
")",
"@state",
".",
"update",
"data",
"[",
"'state'",
"]",
"if",
"data",
".",
"key?",
"'state'",
"@timeline",
".",
"update",
"data",
"[",
"'timeline'",
"]",
"if",
"data",
".",
"key?",
"'timeline'",
"end"
] | Process leave events for this room.
@param data [Hash] Event data containing state and timeline events up
until the point of leaving the room. | [
"Process",
"leave",
"events",
"for",
"this",
"room",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/room.rb#L76-L79 |
5,191 | Sharparam/chatrix | lib/chatrix/room.rb | Chatrix.Room.process_invite_event | def process_invite_event(event)
return unless event['type'] == 'm.room.member'
return unless event['content']['membership'] == 'invite'
@users.process_invite self, event
sender = @users[event['sender']]
invitee = @users[event['state_key']]
# Return early if the user is already in the room
return if @state.member? invitee
broadcast(:invited, sender, invitee)
end | ruby | def process_invite_event(event)
return unless event['type'] == 'm.room.member'
return unless event['content']['membership'] == 'invite'
@users.process_invite self, event
sender = @users[event['sender']]
invitee = @users[event['state_key']]
# Return early if the user is already in the room
return if @state.member? invitee
broadcast(:invited, sender, invitee)
end | [
"def",
"process_invite_event",
"(",
"event",
")",
"return",
"unless",
"event",
"[",
"'type'",
"]",
"==",
"'m.room.member'",
"return",
"unless",
"event",
"[",
"'content'",
"]",
"[",
"'membership'",
"]",
"==",
"'invite'",
"@users",
".",
"process_invite",
"self",
",",
"event",
"sender",
"=",
"@users",
"[",
"event",
"[",
"'sender'",
"]",
"]",
"invitee",
"=",
"@users",
"[",
"event",
"[",
"'state_key'",
"]",
"]",
"# Return early if the user is already in the room",
"return",
"if",
"@state",
".",
"member?",
"invitee",
"broadcast",
"(",
":invited",
",",
"sender",
",",
"invitee",
")",
"end"
] | Process an invite event for this room.
@param event [Hash] Event data. | [
"Process",
"an",
"invite",
"event",
"for",
"this",
"room",
"."
] | 6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34 | https://github.com/Sharparam/chatrix/blob/6f2e9cf3a614ba7e8a9960f7d9b97092c0ce1e34/lib/chatrix/room.rb#L93-L102 |
5,192 | andrba/hungryform | lib/hungryform/resolver.rb | HungryForm.Resolver.get_value | def get_value(name, element = nil)
return name.call(element) if name.respond_to? :call
# We don't want to mess up elements names
name = name.to_s.dup
# Apply placeholders to the name.
# A sample name string can look like this: page1_group[GROUP_NUMBER]_field
# where [GROUP_NUMBER] is a placeholder. When an element is present
# we get its placeholders and replace substrings in the name argument
element.placeholders.each { |k, v| name[k] &&= v } if element
elements[name].try(:value) || params[name] || name
end | ruby | def get_value(name, element = nil)
return name.call(element) if name.respond_to? :call
# We don't want to mess up elements names
name = name.to_s.dup
# Apply placeholders to the name.
# A sample name string can look like this: page1_group[GROUP_NUMBER]_field
# where [GROUP_NUMBER] is a placeholder. When an element is present
# we get its placeholders and replace substrings in the name argument
element.placeholders.each { |k, v| name[k] &&= v } if element
elements[name].try(:value) || params[name] || name
end | [
"def",
"get_value",
"(",
"name",
",",
"element",
"=",
"nil",
")",
"return",
"name",
".",
"call",
"(",
"element",
")",
"if",
"name",
".",
"respond_to?",
":call",
"# We don't want to mess up elements names",
"name",
"=",
"name",
".",
"to_s",
".",
"dup",
"# Apply placeholders to the name.",
"# A sample name string can look like this: page1_group[GROUP_NUMBER]_field",
"# where [GROUP_NUMBER] is a placeholder. When an element is present",
"# we get its placeholders and replace substrings in the name argument",
"element",
".",
"placeholders",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"name",
"[",
"k",
"]",
"&&=",
"v",
"}",
"if",
"element",
"elements",
"[",
"name",
"]",
".",
"try",
"(",
":value",
")",
"||",
"params",
"[",
"name",
"]",
"||",
"name",
"end"
] | Gets element value by element's name.
If name is lambda - returns lambda's result
If name is present in the resolvers' elements hash - returns element's value
If name is present in the resolvers' params hash - returns params value
Otherwise returns the argument without changes | [
"Gets",
"element",
"value",
"by",
"element",
"s",
"name",
".",
"If",
"name",
"is",
"lambda",
"-",
"returns",
"lambda",
"s",
"result",
"If",
"name",
"is",
"present",
"in",
"the",
"resolvers",
"elements",
"hash",
"-",
"returns",
"element",
"s",
"value",
"If",
"name",
"is",
"present",
"in",
"the",
"resolvers",
"params",
"hash",
"-",
"returns",
"params",
"value",
"Otherwise",
"returns",
"the",
"argument",
"without",
"changes"
] | d9d9dad9d8409323910372372c3c7672bd8bf478 | https://github.com/andrba/hungryform/blob/d9d9dad9d8409323910372372c3c7672bd8bf478/lib/hungryform/resolver.rb#L18-L31 |
5,193 | andrba/hungryform | lib/hungryform/resolver.rb | HungryForm.Resolver.resolve_dependency | def resolve_dependency(dependency)
dependency.each do |operator, arguments|
operator = operator.to_sym
case operator
when :and, :or
return resolve_multi_dependency(operator, arguments)
when :not
return !resolve_dependency(arguments)
end
arguments = [arguments] unless arguments.is_a?(Array)
values = arguments[0..1].map { |name| get_value(name) }
return false if values.any?(&:nil?)
case operator
when :eq
return values[0].to_s == values[1].to_s
when :lt
return values[0].to_f < values[1].to_f
when :gt
return values[0].to_f > values[1].to_f
when :set
return !values[0].empty?
end
end
end | ruby | def resolve_dependency(dependency)
dependency.each do |operator, arguments|
operator = operator.to_sym
case operator
when :and, :or
return resolve_multi_dependency(operator, arguments)
when :not
return !resolve_dependency(arguments)
end
arguments = [arguments] unless arguments.is_a?(Array)
values = arguments[0..1].map { |name| get_value(name) }
return false if values.any?(&:nil?)
case operator
when :eq
return values[0].to_s == values[1].to_s
when :lt
return values[0].to_f < values[1].to_f
when :gt
return values[0].to_f > values[1].to_f
when :set
return !values[0].empty?
end
end
end | [
"def",
"resolve_dependency",
"(",
"dependency",
")",
"dependency",
".",
"each",
"do",
"|",
"operator",
",",
"arguments",
"|",
"operator",
"=",
"operator",
".",
"to_sym",
"case",
"operator",
"when",
":and",
",",
":or",
"return",
"resolve_multi_dependency",
"(",
"operator",
",",
"arguments",
")",
"when",
":not",
"return",
"!",
"resolve_dependency",
"(",
"arguments",
")",
"end",
"arguments",
"=",
"[",
"arguments",
"]",
"unless",
"arguments",
".",
"is_a?",
"(",
"Array",
")",
"values",
"=",
"arguments",
"[",
"0",
"..",
"1",
"]",
".",
"map",
"{",
"|",
"name",
"|",
"get_value",
"(",
"name",
")",
"}",
"return",
"false",
"if",
"values",
".",
"any?",
"(",
":nil?",
")",
"case",
"operator",
"when",
":eq",
"return",
"values",
"[",
"0",
"]",
".",
"to_s",
"==",
"values",
"[",
"1",
"]",
".",
"to_s",
"when",
":lt",
"return",
"values",
"[",
"0",
"]",
".",
"to_f",
"<",
"values",
"[",
"1",
"]",
".",
"to_f",
"when",
":gt",
"return",
"values",
"[",
"0",
"]",
".",
"to_f",
">",
"values",
"[",
"1",
"]",
".",
"to_f",
"when",
":set",
"return",
"!",
"values",
"[",
"0",
"]",
".",
"empty?",
"end",
"end",
"end"
] | Gets dependency rules hash and returns true or false depending on
the result of a recursive processing of the rules | [
"Gets",
"dependency",
"rules",
"hash",
"and",
"returns",
"true",
"or",
"false",
"depending",
"on",
"the",
"result",
"of",
"a",
"recursive",
"processing",
"of",
"the",
"rules"
] | d9d9dad9d8409323910372372c3c7672bd8bf478 | https://github.com/andrba/hungryform/blob/d9d9dad9d8409323910372372c3c7672bd8bf478/lib/hungryform/resolver.rb#L35-L62 |
5,194 | andrba/hungryform | lib/hungryform/resolver.rb | HungryForm.Resolver.resolve_multi_dependency | def resolve_multi_dependency(type, arguments)
if arguments.size == 0
fail HungryFormException, "No arguments for #{type.upcase} comparison: #{arguments}"
end
result = type == :and
arguments.each do |argument|
return !result unless resolve_dependency(argument)
end
result
end | ruby | def resolve_multi_dependency(type, arguments)
if arguments.size == 0
fail HungryFormException, "No arguments for #{type.upcase} comparison: #{arguments}"
end
result = type == :and
arguments.each do |argument|
return !result unless resolve_dependency(argument)
end
result
end | [
"def",
"resolve_multi_dependency",
"(",
"type",
",",
"arguments",
")",
"if",
"arguments",
".",
"size",
"==",
"0",
"fail",
"HungryFormException",
",",
"\"No arguments for #{type.upcase} comparison: #{arguments}\"",
"end",
"result",
"=",
"type",
"==",
":and",
"arguments",
".",
"each",
"do",
"|",
"argument",
"|",
"return",
"!",
"result",
"unless",
"resolve_dependency",
"(",
"argument",
")",
"end",
"result",
"end"
] | Method resolves AND or OR conditions.
Walks through the arguments and resolves their dependencies. | [
"Method",
"resolves",
"AND",
"or",
"OR",
"conditions",
".",
"Walks",
"through",
"the",
"arguments",
"and",
"resolves",
"their",
"dependencies",
"."
] | d9d9dad9d8409323910372372c3c7672bd8bf478 | https://github.com/andrba/hungryform/blob/d9d9dad9d8409323910372372c3c7672bd8bf478/lib/hungryform/resolver.rb#L68-L80 |
5,195 | dolzenko/reflexive | lib/reflexive/methods.rb | Reflexive.Methods.append_ancestor_entry | def append_ancestor_entry(ancestors, ancestor, class_methods, instance_methods = nil)
if class_methods || instance_methods
ancestor_entry = {}
ancestor_entry[:class] = class_methods if class_methods
ancestor_entry[:instance] = instance_methods if instance_methods
ancestors << {ancestor => ancestor_entry}
end
end | ruby | def append_ancestor_entry(ancestors, ancestor, class_methods, instance_methods = nil)
if class_methods || instance_methods
ancestor_entry = {}
ancestor_entry[:class] = class_methods if class_methods
ancestor_entry[:instance] = instance_methods if instance_methods
ancestors << {ancestor => ancestor_entry}
end
end | [
"def",
"append_ancestor_entry",
"(",
"ancestors",
",",
"ancestor",
",",
"class_methods",
",",
"instance_methods",
"=",
"nil",
")",
"if",
"class_methods",
"||",
"instance_methods",
"ancestor_entry",
"=",
"{",
"}",
"ancestor_entry",
"[",
":class",
"]",
"=",
"class_methods",
"if",
"class_methods",
"ancestor_entry",
"[",
":instance",
"]",
"=",
"instance_methods",
"if",
"instance_methods",
"ancestors",
"<<",
"{",
"ancestor",
"=>",
"ancestor_entry",
"}",
"end",
"end"
] | ancestor is included only when contributes some methods | [
"ancestor",
"is",
"included",
"only",
"when",
"contributes",
"some",
"methods"
] | 04a58ba2f45c15e2815b7ca04a78a5b6b89a52b9 | https://github.com/dolzenko/reflexive/blob/04a58ba2f45c15e2815b7ca04a78a5b6b89a52b9/lib/reflexive/methods.rb#L111-L118 |
5,196 | ideonetwork/lato-core | app/cells/lato_core/inputs/select/cell.rb | LatoCore.Inputs::Select::Cell.get_option_value_selected | def get_option_value_selected(option_value)
if @args[:multiple]
values = @args[:value].is_a?(Array) ? @args[:value] : @args[:value].split(',')
return values.include?(option_value) ? "selected='selected'" : ''
end
@args[:value] == option_value ? "selected='selected'" : ''
end | ruby | def get_option_value_selected(option_value)
if @args[:multiple]
values = @args[:value].is_a?(Array) ? @args[:value] : @args[:value].split(',')
return values.include?(option_value) ? "selected='selected'" : ''
end
@args[:value] == option_value ? "selected='selected'" : ''
end | [
"def",
"get_option_value_selected",
"(",
"option_value",
")",
"if",
"@args",
"[",
":multiple",
"]",
"values",
"=",
"@args",
"[",
":value",
"]",
".",
"is_a?",
"(",
"Array",
")",
"?",
"@args",
"[",
":value",
"]",
":",
"@args",
"[",
":value",
"]",
".",
"split",
"(",
"','",
")",
"return",
"values",
".",
"include?",
"(",
"option_value",
")",
"?",
"\"selected='selected'\"",
":",
"''",
"end",
"@args",
"[",
":value",
"]",
"==",
"option_value",
"?",
"\"selected='selected'\"",
":",
"''",
"end"
] | This function return a string used on the HTML option to
set a an option value selected or not. | [
"This",
"function",
"return",
"a",
"string",
"used",
"on",
"the",
"HTML",
"option",
"to",
"set",
"a",
"an",
"option",
"value",
"selected",
"or",
"not",
"."
] | c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c | https://github.com/ideonetwork/lato-core/blob/c01fa585725c8e9992f25d8a7bd4ba2d0bfca08c/app/cells/lato_core/inputs/select/cell.rb#L39-L46 |
5,197 | blahah/biopsy | lib/biopsy/target.rb | Biopsy.Target.load_by_name | def load_by_name name
path = self.locate_definition name
raise TargetLoadError.new("Target definition file does not exist for #{name}") if path.nil?
config = YAML::load_file(path)
raise TargetLoadError.new("Target definition file #{path} is not valid YAML") if config.nil?
config = config.deep_symbolize
self.store_config config
self.check_constructor name
self.load_constructor
end | ruby | def load_by_name name
path = self.locate_definition name
raise TargetLoadError.new("Target definition file does not exist for #{name}") if path.nil?
config = YAML::load_file(path)
raise TargetLoadError.new("Target definition file #{path} is not valid YAML") if config.nil?
config = config.deep_symbolize
self.store_config config
self.check_constructor name
self.load_constructor
end | [
"def",
"load_by_name",
"name",
"path",
"=",
"self",
".",
"locate_definition",
"name",
"raise",
"TargetLoadError",
".",
"new",
"(",
"\"Target definition file does not exist for #{name}\"",
")",
"if",
"path",
".",
"nil?",
"config",
"=",
"YAML",
"::",
"load_file",
"(",
"path",
")",
"raise",
"TargetLoadError",
".",
"new",
"(",
"\"Target definition file #{path} is not valid YAML\"",
")",
"if",
"config",
".",
"nil?",
"config",
"=",
"config",
".",
"deep_symbolize",
"self",
".",
"store_config",
"config",
"self",
".",
"check_constructor",
"name",
"self",
".",
"load_constructor",
"end"
] | load target with +name+. | [
"load",
"target",
"with",
"+",
"name",
"+",
"."
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/target.rb#L23-L32 |
5,198 | blahah/biopsy | lib/biopsy/target.rb | Biopsy.Target.locate_file | def locate_file name
Settings.instance.target_dir.each do |dir|
Dir.chdir File.expand_path(dir) do
return File.expand_path(name) if File.exists? name
end
end
raise TargetLoadError.new("Couldn't find file #{name}")
nil
end | ruby | def locate_file name
Settings.instance.target_dir.each do |dir|
Dir.chdir File.expand_path(dir) do
return File.expand_path(name) if File.exists? name
end
end
raise TargetLoadError.new("Couldn't find file #{name}")
nil
end | [
"def",
"locate_file",
"name",
"Settings",
".",
"instance",
".",
"target_dir",
".",
"each",
"do",
"|",
"dir",
"|",
"Dir",
".",
"chdir",
"File",
".",
"expand_path",
"(",
"dir",
")",
"do",
"return",
"File",
".",
"expand_path",
"(",
"name",
")",
"if",
"File",
".",
"exists?",
"name",
"end",
"end",
"raise",
"TargetLoadError",
".",
"new",
"(",
"\"Couldn't find file #{name}\"",
")",
"nil",
"end"
] | Locate a file with name in one of the target_dirs | [
"Locate",
"a",
"file",
"with",
"name",
"in",
"one",
"of",
"the",
"target_dirs"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/target.rb#L64-L72 |
5,199 | blahah/biopsy | lib/biopsy/target.rb | Biopsy.Target.count_parameter_permutations | def count_parameter_permutations
@parameters.each_pair.map{ |k, v| v }.reduce(1) { |n, arr| n * arr.size }
end | ruby | def count_parameter_permutations
@parameters.each_pair.map{ |k, v| v }.reduce(1) { |n, arr| n * arr.size }
end | [
"def",
"count_parameter_permutations",
"@parameters",
".",
"each_pair",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"v",
"}",
".",
"reduce",
"(",
"1",
")",
"{",
"|",
"n",
",",
"arr",
"|",
"n",
"*",
"arr",
".",
"size",
"}",
"end"
] | return the total number of possible permutations of | [
"return",
"the",
"total",
"number",
"of",
"possible",
"permutations",
"of"
] | e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2 | https://github.com/blahah/biopsy/blob/e46f3d1c75de4da2ec47a377f7e4f0e16a8e03d2/lib/biopsy/target.rb#L141-L143 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.