id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
8,400
|
nerab/pwl
|
lib/pwl/locker.rb
|
Pwl.Locker.change_password!
|
def change_password!(new_master_password)
self.class.password_policy.validate!(new_master_password)
@backend.transaction{
# Decrypt each key and value with the old master password and encrypt them with the new master password
copy = {}
@backend[:user].each{|k,v|
# No need to (de)serialize - the value comes in as JSON and goes out as JSON
new_key = Encryptor.encrypt(decrypt(k), :key => new_master_password)
new_val = Encryptor.encrypt(decrypt(v), :key => new_master_password)
copy[new_key] = new_val
}
# re-write user branch with newly encrypted keys and values
@backend[:user] = copy
# from now on, use the new master password as long as the object lives
@master_password = new_master_password
timestamp!(:last_modified)
@backend[:system][:salt] = encrypt(Random.rand.to_s)
}
end
|
ruby
|
def change_password!(new_master_password)
self.class.password_policy.validate!(new_master_password)
@backend.transaction{
# Decrypt each key and value with the old master password and encrypt them with the new master password
copy = {}
@backend[:user].each{|k,v|
# No need to (de)serialize - the value comes in as JSON and goes out as JSON
new_key = Encryptor.encrypt(decrypt(k), :key => new_master_password)
new_val = Encryptor.encrypt(decrypt(v), :key => new_master_password)
copy[new_key] = new_val
}
# re-write user branch with newly encrypted keys and values
@backend[:user] = copy
# from now on, use the new master password as long as the object lives
@master_password = new_master_password
timestamp!(:last_modified)
@backend[:system][:salt] = encrypt(Random.rand.to_s)
}
end
|
[
"def",
"change_password!",
"(",
"new_master_password",
")",
"self",
".",
"class",
".",
"password_policy",
".",
"validate!",
"(",
"new_master_password",
")",
"@backend",
".",
"transaction",
"{",
"# Decrypt each key and value with the old master password and encrypt them with the new master password",
"copy",
"=",
"{",
"}",
"@backend",
"[",
":user",
"]",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"# No need to (de)serialize - the value comes in as JSON and goes out as JSON",
"new_key",
"=",
"Encryptor",
".",
"encrypt",
"(",
"decrypt",
"(",
"k",
")",
",",
":key",
"=>",
"new_master_password",
")",
"new_val",
"=",
"Encryptor",
".",
"encrypt",
"(",
"decrypt",
"(",
"v",
")",
",",
":key",
"=>",
"new_master_password",
")",
"copy",
"[",
"new_key",
"]",
"=",
"new_val",
"}",
"# re-write user branch with newly encrypted keys and values",
"@backend",
"[",
":user",
"]",
"=",
"copy",
"# from now on, use the new master password as long as the object lives",
"@master_password",
"=",
"new_master_password",
"timestamp!",
"(",
":last_modified",
")",
"@backend",
"[",
":system",
"]",
"[",
":salt",
"]",
"=",
"encrypt",
"(",
"Random",
".",
"rand",
".",
"to_s",
")",
"}",
"end"
] |
Change the master password to +new_master_password+. Note that we don't take a password confirmation here.
This is up to a UI layer.
|
[
"Change",
"the",
"master",
"password",
"to",
"+",
"new_master_password",
"+",
".",
"Note",
"that",
"we",
"don",
"t",
"take",
"a",
"password",
"confirmation",
"here",
".",
"This",
"is",
"up",
"to",
"a",
"UI",
"layer",
"."
] |
ef22d0f43be90c63d0a30564122c31c49148f89c
|
https://github.com/nerab/pwl/blob/ef22d0f43be90c63d0a30564122c31c49148f89c/lib/pwl/locker.rb#L202-L224
|
8,401
|
vojto/active_harmony
|
lib/active_harmony/synchronizer.rb
|
ActiveHarmony.Synchronizer.pull_object
|
def pull_object(id)
local_object = @factory.with_remote_id(id)
if local_object
# FIXME What if there's no local object and we still want to set some
# contexts?
@service.set_contexts(local_object.contexts)
else
local_object = @factory.new
end
local_object.before_pull(self) if local_object.respond_to?(:before_pull)
object_hash = @service.show(object_name, id)
@service.clear_contexts
local_object._remote_id = object_hash.delete('id')
fields = configuration.synchronizable_for_pull
fields.each do |key|
value = object_hash[key.to_s]
local_object.send("#{key}=", value)
end
local_object.after_pull(self) if local_object.respond_to?(:after_pull)
local_object.save
end
|
ruby
|
def pull_object(id)
local_object = @factory.with_remote_id(id)
if local_object
# FIXME What if there's no local object and we still want to set some
# contexts?
@service.set_contexts(local_object.contexts)
else
local_object = @factory.new
end
local_object.before_pull(self) if local_object.respond_to?(:before_pull)
object_hash = @service.show(object_name, id)
@service.clear_contexts
local_object._remote_id = object_hash.delete('id')
fields = configuration.synchronizable_for_pull
fields.each do |key|
value = object_hash[key.to_s]
local_object.send("#{key}=", value)
end
local_object.after_pull(self) if local_object.respond_to?(:after_pull)
local_object.save
end
|
[
"def",
"pull_object",
"(",
"id",
")",
"local_object",
"=",
"@factory",
".",
"with_remote_id",
"(",
"id",
")",
"if",
"local_object",
"# FIXME What if there's no local object and we still want to set some",
"# contexts?",
"@service",
".",
"set_contexts",
"(",
"local_object",
".",
"contexts",
")",
"else",
"local_object",
"=",
"@factory",
".",
"new",
"end",
"local_object",
".",
"before_pull",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":before_pull",
")",
"object_hash",
"=",
"@service",
".",
"show",
"(",
"object_name",
",",
"id",
")",
"@service",
".",
"clear_contexts",
"local_object",
".",
"_remote_id",
"=",
"object_hash",
".",
"delete",
"(",
"'id'",
")",
"fields",
"=",
"configuration",
".",
"synchronizable_for_pull",
"fields",
".",
"each",
"do",
"|",
"key",
"|",
"value",
"=",
"object_hash",
"[",
"key",
".",
"to_s",
"]",
"local_object",
".",
"send",
"(",
"\"#{key}=\"",
",",
"value",
")",
"end",
"local_object",
".",
"after_pull",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":after_pull",
")",
"local_object",
".",
"save",
"end"
] |
Pulls object from remote service
@param [Integer] Remote ID of object.
@return [Boolean] Result of pulling
|
[
"Pulls",
"object",
"from",
"remote",
"service"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/synchronizer.rb#L41-L61
|
8,402
|
vojto/active_harmony
|
lib/active_harmony/synchronizer.rb
|
ActiveHarmony.Synchronizer.push_object
|
def push_object(local_object)
object_name = @factory.object_name.to_sym
local_object.before_push(self) if local_object.respond_to?(:before_push)
changes = {}
fields = configuration.synchronizable_for_push
fields.each do |atr|
value = local_object.send(atr)
changes[atr.to_s] = value
end
@service.set_contexts(local_object.contexts)
if local_object._remote_id
@service.update(object_name, local_object._remote_id, changes)
else
result = @service.create(object_name, changes)
if result
local_object._remote_id = result['id']
fields = configuration.synchronizable_for_pull
fields.each do |atr|
local_object.write_attribute(atr, result[atr.to_s])
end
local_object.save
end
end
local_object.after_push(self) if local_object.respond_to?(:after_push)
@service.clear_contexts
end
|
ruby
|
def push_object(local_object)
object_name = @factory.object_name.to_sym
local_object.before_push(self) if local_object.respond_to?(:before_push)
changes = {}
fields = configuration.synchronizable_for_push
fields.each do |atr|
value = local_object.send(atr)
changes[atr.to_s] = value
end
@service.set_contexts(local_object.contexts)
if local_object._remote_id
@service.update(object_name, local_object._remote_id, changes)
else
result = @service.create(object_name, changes)
if result
local_object._remote_id = result['id']
fields = configuration.synchronizable_for_pull
fields.each do |atr|
local_object.write_attribute(atr, result[atr.to_s])
end
local_object.save
end
end
local_object.after_push(self) if local_object.respond_to?(:after_push)
@service.clear_contexts
end
|
[
"def",
"push_object",
"(",
"local_object",
")",
"object_name",
"=",
"@factory",
".",
"object_name",
".",
"to_sym",
"local_object",
".",
"before_push",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":before_push",
")",
"changes",
"=",
"{",
"}",
"fields",
"=",
"configuration",
".",
"synchronizable_for_push",
"fields",
".",
"each",
"do",
"|",
"atr",
"|",
"value",
"=",
"local_object",
".",
"send",
"(",
"atr",
")",
"changes",
"[",
"atr",
".",
"to_s",
"]",
"=",
"value",
"end",
"@service",
".",
"set_contexts",
"(",
"local_object",
".",
"contexts",
")",
"if",
"local_object",
".",
"_remote_id",
"@service",
".",
"update",
"(",
"object_name",
",",
"local_object",
".",
"_remote_id",
",",
"changes",
")",
"else",
"result",
"=",
"@service",
".",
"create",
"(",
"object_name",
",",
"changes",
")",
"if",
"result",
"local_object",
".",
"_remote_id",
"=",
"result",
"[",
"'id'",
"]",
"fields",
"=",
"configuration",
".",
"synchronizable_for_pull",
"fields",
".",
"each",
"do",
"|",
"atr",
"|",
"local_object",
".",
"write_attribute",
"(",
"atr",
",",
"result",
"[",
"atr",
".",
"to_s",
"]",
")",
"end",
"local_object",
".",
"save",
"end",
"end",
"local_object",
".",
"after_push",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":after_push",
")",
"@service",
".",
"clear_contexts",
"end"
] |
Pushes local object to remote services.
Er, I mean, its attributes.
Like not object itself. Just attributes.
@param [Object] Local object
|
[
"Pushes",
"local",
"object",
"to",
"remote",
"services",
".",
"Er",
"I",
"mean",
"its",
"attributes",
".",
"Like",
"not",
"object",
"itself",
".",
"Just",
"attributes",
"."
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/synchronizer.rb#L68-L98
|
8,403
|
vojto/active_harmony
|
lib/active_harmony/synchronizer.rb
|
ActiveHarmony.Synchronizer.pull_collection
|
def pull_collection
@service.set_contexts(@contexts)
collection = @service.list(object_name)
@service.clear_contexts
collection.each_with_index do |remote_object_hash, index|
remote_id = remote_object_hash.delete("id")
local_object = @factory.with_remote_id(remote_id)
unless local_object
local_object = @factory.new
local_object.update_remote_id(remote_id)
end
local_object.before_pull(self) if local_object.respond_to?(:before_pull)
local_object._collection_order = index
fields = configuration.synchronizable_for_pull
fields.each do |field|
value = remote_object_hash[field.to_s]
local_object.send("#{field}=", value)
end
local_object.after_pull(self) if local_object.respond_to?(:after_pull)
local_object.save
end
collection.count
end
|
ruby
|
def pull_collection
@service.set_contexts(@contexts)
collection = @service.list(object_name)
@service.clear_contexts
collection.each_with_index do |remote_object_hash, index|
remote_id = remote_object_hash.delete("id")
local_object = @factory.with_remote_id(remote_id)
unless local_object
local_object = @factory.new
local_object.update_remote_id(remote_id)
end
local_object.before_pull(self) if local_object.respond_to?(:before_pull)
local_object._collection_order = index
fields = configuration.synchronizable_for_pull
fields.each do |field|
value = remote_object_hash[field.to_s]
local_object.send("#{field}=", value)
end
local_object.after_pull(self) if local_object.respond_to?(:after_pull)
local_object.save
end
collection.count
end
|
[
"def",
"pull_collection",
"@service",
".",
"set_contexts",
"(",
"@contexts",
")",
"collection",
"=",
"@service",
".",
"list",
"(",
"object_name",
")",
"@service",
".",
"clear_contexts",
"collection",
".",
"each_with_index",
"do",
"|",
"remote_object_hash",
",",
"index",
"|",
"remote_id",
"=",
"remote_object_hash",
".",
"delete",
"(",
"\"id\"",
")",
"local_object",
"=",
"@factory",
".",
"with_remote_id",
"(",
"remote_id",
")",
"unless",
"local_object",
"local_object",
"=",
"@factory",
".",
"new",
"local_object",
".",
"update_remote_id",
"(",
"remote_id",
")",
"end",
"local_object",
".",
"before_pull",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":before_pull",
")",
"local_object",
".",
"_collection_order",
"=",
"index",
"fields",
"=",
"configuration",
".",
"synchronizable_for_pull",
"fields",
".",
"each",
"do",
"|",
"field",
"|",
"value",
"=",
"remote_object_hash",
"[",
"field",
".",
"to_s",
"]",
"local_object",
".",
"send",
"(",
"\"#{field}=\"",
",",
"value",
")",
"end",
"local_object",
".",
"after_pull",
"(",
"self",
")",
"if",
"local_object",
".",
"respond_to?",
"(",
":after_pull",
")",
"local_object",
".",
"save",
"end",
"collection",
".",
"count",
"end"
] |
Pulls whole remote collection. If it cannot find
matching local object, it will create one.
This method is slow, useful for initial import, not
for regular updates. For regular updates, only
changed remote objects should be updates using pull_object
@see pull_object
|
[
"Pulls",
"whole",
"remote",
"collection",
".",
"If",
"it",
"cannot",
"find",
"matching",
"local",
"object",
"it",
"will",
"create",
"one",
".",
"This",
"method",
"is",
"slow",
"useful",
"for",
"initial",
"import",
"not",
"for",
"regular",
"updates",
".",
"For",
"regular",
"updates",
"only",
"changed",
"remote",
"objects",
"should",
"be",
"updates",
"using",
"pull_object"
] |
03e5c67ea7a1f986c729001c4fec944bf116640f
|
https://github.com/vojto/active_harmony/blob/03e5c67ea7a1f986c729001c4fec944bf116640f/lib/active_harmony/synchronizer.rb#L107-L129
|
8,404
|
26fe/sem4r
|
lib/sem4r/ad_group/ad_group.rb
|
Sem4r.AdGroup.xml
|
def xml(t)
t.campaignId campaign.id
t.name name
t.status "ENABLED"
@bids.to_xml(t) if @bids
end
|
ruby
|
def xml(t)
t.campaignId campaign.id
t.name name
t.status "ENABLED"
@bids.to_xml(t) if @bids
end
|
[
"def",
"xml",
"(",
"t",
")",
"t",
".",
"campaignId",
"campaign",
".",
"id",
"t",
".",
"name",
"name",
"t",
".",
"status",
"\"ENABLED\"",
"@bids",
".",
"to_xml",
"(",
"t",
")",
"if",
"@bids",
"end"
] |
Build xml into Builder
@param [Builder::XmlMarkup]
|
[
"Build",
"xml",
"into",
"Builder"
] |
2326404f98b9c2833549fcfda078d39c9954a0fa
|
https://github.com/26fe/sem4r/blob/2326404f98b9c2833549fcfda078d39c9954a0fa/lib/sem4r/ad_group/ad_group.rb#L72-L77
|
8,405
|
26fe/sem4r
|
lib/sem4r/ad_group/ad_group.rb
|
Sem4r.AdGroup.keyword
|
def keyword(text = nil, match = nil, &block)
biddable_criterion = BiddableAdGroupCriterion.new(self)
criterion = CriterionKeyword.new(self, text, match, &block)
biddable_criterion.criterion = criterion
@criterions ||= []
@criterions.push( biddable_criterion )
biddable_criterion
end
|
ruby
|
def keyword(text = nil, match = nil, &block)
biddable_criterion = BiddableAdGroupCriterion.new(self)
criterion = CriterionKeyword.new(self, text, match, &block)
biddable_criterion.criterion = criterion
@criterions ||= []
@criterions.push( biddable_criterion )
biddable_criterion
end
|
[
"def",
"keyword",
"(",
"text",
"=",
"nil",
",",
"match",
"=",
"nil",
",",
"&",
"block",
")",
"biddable_criterion",
"=",
"BiddableAdGroupCriterion",
".",
"new",
"(",
"self",
")",
"criterion",
"=",
"CriterionKeyword",
".",
"new",
"(",
"self",
",",
"text",
",",
"match",
",",
"block",
")",
"biddable_criterion",
".",
"criterion",
"=",
"criterion",
"@criterions",
"||=",
"[",
"]",
"@criterions",
".",
"push",
"(",
"biddable_criterion",
")",
"biddable_criterion",
"end"
] |
instantiate an BiddableAdGroupCriterion but it is called 'keyword' for convenience
http://code.google.com/apis/adwords/v2009/docs/reference/AdGroupCriterionService.BiddableAdGroupCriterion.html
|
[
"instantiate",
"an",
"BiddableAdGroupCriterion",
"but",
"it",
"is",
"called",
"keyword",
"for",
"convenience"
] |
2326404f98b9c2833549fcfda078d39c9954a0fa
|
https://github.com/26fe/sem4r/blob/2326404f98b9c2833549fcfda078d39c9954a0fa/lib/sem4r/ad_group/ad_group.rb#L246-L253
|
8,406
|
26fe/sem4r
|
lib/sem4r/ad_group/ad_group.rb
|
Sem4r.AdGroup.ad_param
|
def ad_param(criterion, index = nil, text = nil, &block)
ad_param = AdParam.new(self, criterion, index, text, &block)
ad_param.save unless inside_initialize? or criterion.inside_initialize?
@ad_params ||= []
@ad_params.push( ad_param )
ad_param
end
|
ruby
|
def ad_param(criterion, index = nil, text = nil, &block)
ad_param = AdParam.new(self, criterion, index, text, &block)
ad_param.save unless inside_initialize? or criterion.inside_initialize?
@ad_params ||= []
@ad_params.push( ad_param )
ad_param
end
|
[
"def",
"ad_param",
"(",
"criterion",
",",
"index",
"=",
"nil",
",",
"text",
"=",
"nil",
",",
"&",
"block",
")",
"ad_param",
"=",
"AdParam",
".",
"new",
"(",
"self",
",",
"criterion",
",",
"index",
",",
"text",
",",
"block",
")",
"ad_param",
".",
"save",
"unless",
"inside_initialize?",
"or",
"criterion",
".",
"inside_initialize?",
"@ad_params",
"||=",
"[",
"]",
"@ad_params",
".",
"push",
"(",
"ad_param",
")",
"ad_param",
"end"
] |
ad param management
|
[
"ad",
"param",
"management"
] |
2326404f98b9c2833549fcfda078d39c9954a0fa
|
https://github.com/26fe/sem4r/blob/2326404f98b9c2833549fcfda078d39c9954a0fa/lib/sem4r/ad_group/ad_group.rb#L317-L323
|
8,407
|
boof/xbel
|
lib/nokogiri/decorators/xbel/folder.rb
|
Nokogiri::Decorators::XBEL.Folder.add_bookmark
|
def add_bookmark(title, href, attributes = {}, &block)
attributes = attributes.merge :title => title, :href => href
add_child build(:bookmark, attributes, &block)
end
|
ruby
|
def add_bookmark(title, href, attributes = {}, &block)
attributes = attributes.merge :title => title, :href => href
add_child build(:bookmark, attributes, &block)
end
|
[
"def",
"add_bookmark",
"(",
"title",
",",
"href",
",",
"attributes",
"=",
"{",
"}",
",",
"&",
"block",
")",
"attributes",
"=",
"attributes",
".",
"merge",
":title",
"=>",
"title",
",",
":href",
"=>",
"href",
"add_child",
"build",
"(",
":bookmark",
",",
"attributes",
",",
"block",
")",
"end"
] |
Builds a bookmark with given attributes and add it.
|
[
"Builds",
"a",
"bookmark",
"with",
"given",
"attributes",
"and",
"add",
"it",
"."
] |
a1997a0ff61e99f390cc4f05ef9ec4757557048e
|
https://github.com/boof/xbel/blob/a1997a0ff61e99f390cc4f05ef9ec4757557048e/lib/nokogiri/decorators/xbel/folder.rb#L46-L49
|
8,408
|
boof/xbel
|
lib/nokogiri/decorators/xbel/folder.rb
|
Nokogiri::Decorators::XBEL.Folder.add_folder
|
def add_folder(title, attributes = {}, &block)
attributes = attributes.merge :title => title
add_child build(:folder, attributes, &block)
end
|
ruby
|
def add_folder(title, attributes = {}, &block)
attributes = attributes.merge :title => title
add_child build(:folder, attributes, &block)
end
|
[
"def",
"add_folder",
"(",
"title",
",",
"attributes",
"=",
"{",
"}",
",",
"&",
"block",
")",
"attributes",
"=",
"attributes",
".",
"merge",
":title",
"=>",
"title",
"add_child",
"build",
"(",
":folder",
",",
"attributes",
",",
"block",
")",
"end"
] |
Builds a folder with given attributes and add it.
|
[
"Builds",
"a",
"folder",
"with",
"given",
"attributes",
"and",
"add",
"it",
"."
] |
a1997a0ff61e99f390cc4f05ef9ec4757557048e
|
https://github.com/boof/xbel/blob/a1997a0ff61e99f390cc4f05ef9ec4757557048e/lib/nokogiri/decorators/xbel/folder.rb#L51-L54
|
8,409
|
boof/xbel
|
lib/nokogiri/decorators/xbel/folder.rb
|
Nokogiri::Decorators::XBEL.Folder.add_alias
|
def add_alias(ref)
node = Nokogiri::XML::Node.new 'alias', document
node.ref = (Entry === ref) ? ref.id : ref.to_s
add_child node
end
|
ruby
|
def add_alias(ref)
node = Nokogiri::XML::Node.new 'alias', document
node.ref = (Entry === ref) ? ref.id : ref.to_s
add_child node
end
|
[
"def",
"add_alias",
"(",
"ref",
")",
"node",
"=",
"Nokogiri",
"::",
"XML",
"::",
"Node",
".",
"new",
"'alias'",
",",
"document",
"node",
".",
"ref",
"=",
"(",
"Entry",
"===",
"ref",
")",
"?",
"ref",
".",
"id",
":",
"ref",
".",
"to_s",
"add_child",
"node",
"end"
] |
Builds an alias with given attributes and add it.
|
[
"Builds",
"an",
"alias",
"with",
"given",
"attributes",
"and",
"add",
"it",
"."
] |
a1997a0ff61e99f390cc4f05ef9ec4757557048e
|
https://github.com/boof/xbel/blob/a1997a0ff61e99f390cc4f05ef9ec4757557048e/lib/nokogiri/decorators/xbel/folder.rb#L56-L61
|
8,410
|
StormhelmSoftworks/specfacthor
|
lib/specfac.rb
|
Specfac.CLI.generate
|
def generate(*args)
init_vars(options)
controller = args.shift
actions = args
if controller
sanitize(controller, actions, options)
else
puts "Please provide a controller name."
exit
end
end
|
ruby
|
def generate(*args)
init_vars(options)
controller = args.shift
actions = args
if controller
sanitize(controller, actions, options)
else
puts "Please provide a controller name."
exit
end
end
|
[
"def",
"generate",
"(",
"*",
"args",
")",
"init_vars",
"(",
"options",
")",
"controller",
"=",
"args",
".",
"shift",
"actions",
"=",
"args",
"if",
"controller",
"sanitize",
"(",
"controller",
",",
"actions",
",",
"options",
")",
"else",
"puts",
"\"Please provide a controller name.\"",
"exit",
"end",
"end"
] |
end to end tests
|
[
"end",
"to",
"end",
"tests"
] |
8fb36d7e44b12183dc18954bc9f80c04b46b7f6d
|
https://github.com/StormhelmSoftworks/specfacthor/blob/8fb36d7e44b12183dc18954bc9f80c04b46b7f6d/lib/specfac.rb#L86-L98
|
8,411
|
kristianmandrup/rails3_artifactor
|
lib/rails3_artifactor/base/crud/create.rb
|
Rails3::Assist::Artifact::CRUD.Create.new_artifact_content
|
def new_artifact_content name, options = {}, &block
type = get_type(options)
content = extract_content type, options, &block
%Q{class #{marker(name, type)}
#{content}
end}
end
|
ruby
|
def new_artifact_content name, options = {}, &block
type = get_type(options)
content = extract_content type, options, &block
%Q{class #{marker(name, type)}
#{content}
end}
end
|
[
"def",
"new_artifact_content",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
"type",
"=",
"get_type",
"(",
"options",
")",
"content",
"=",
"extract_content",
"type",
",",
"options",
",",
"block",
"%Q{class #{marker(name, type)}\n #{content}\nend}",
"end"
] |
def new_artifact_content name, type, content=nil, &block
|
[
"def",
"new_artifact_content",
"name",
"type",
"content",
"=",
"nil",
"&block"
] |
79500e011e022042ab9f9115c6df91b6d63f3b3d
|
https://github.com/kristianmandrup/rails3_artifactor/blob/79500e011e022042ab9f9115c6df91b6d63f3b3d/lib/rails3_artifactor/base/crud/create.rb#L39-L45
|
8,412
|
Figure53/qlab-ruby
|
lib/qlab-ruby/reply.rb
|
QLab.Reply.json
|
def json
@json ||= begin
JSON.parse(osc_message.to_a.first)
rescue => ex
puts ex.message
{}
end
end
|
ruby
|
def json
@json ||= begin
JSON.parse(osc_message.to_a.first)
rescue => ex
puts ex.message
{}
end
end
|
[
"def",
"json",
"@json",
"||=",
"begin",
"JSON",
".",
"parse",
"(",
"osc_message",
".",
"to_a",
".",
"first",
")",
"rescue",
"=>",
"ex",
"puts",
"ex",
".",
"message",
"{",
"}",
"end",
"end"
] |
Actually perform the message unpacking
|
[
"Actually",
"perform",
"the",
"message",
"unpacking"
] |
169494940f478b897066db4c15f130769aa43243
|
https://github.com/Figure53/qlab-ruby/blob/169494940f478b897066db4c15f130769aa43243/lib/qlab-ruby/reply.rb#L41-L48
|
8,413
|
michaelmior/mipper
|
lib/mipper/glpk/model.rb
|
MIPPeR.GLPKModel.glpk_type
|
def glpk_type(type)
case type
when :integer
GLPK::GLP_IV
when :binary
GLPK::GLP_BV
when :continuous
GLPK::GLP_CV
else
fail type
end
end
|
ruby
|
def glpk_type(type)
case type
when :integer
GLPK::GLP_IV
when :binary
GLPK::GLP_BV
when :continuous
GLPK::GLP_CV
else
fail type
end
end
|
[
"def",
"glpk_type",
"(",
"type",
")",
"case",
"type",
"when",
":integer",
"GLPK",
"::",
"GLP_IV",
"when",
":binary",
"GLPK",
"::",
"GLP_BV",
"when",
":continuous",
"GLPK",
"::",
"GLP_CV",
"else",
"fail",
"type",
"end",
"end"
] |
Get the constant GLPK uses to represent our variable types
|
[
"Get",
"the",
"constant",
"GLPK",
"uses",
"to",
"represent",
"our",
"variable",
"types"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/glpk/model.rb#L184-L195
|
8,414
|
jeremyvdw/disqussion
|
lib/disqussion/client/applications.rb
|
Disqussion.Applications.listUsage
|
def listUsage(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
get('applications/listUsage', options)
end
|
ruby
|
def listUsage(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
get('applications/listUsage', options)
end
|
[
"def",
"listUsage",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"pop",
":",
"{",
"}",
"get",
"(",
"'applications/listUsage'",
",",
"options",
")",
"end"
] |
Returns the API usage per day for this application.
@accessibility: public key, secret key
@methods: GET
@format: json, jsonp
@authenticated: true
@limited: false
@return [Hashie::Rash] API usage per day for this application.
@param application [Integer] Defaults to null
@param days [Integer] Defaults to 30, Maximum length of 30
@example Returns the API usage per day for this application.
Disqussion::Client.applications.listUsage
@see http://disqus.com/api/3.0/applications/listUsage.json
|
[
"Returns",
"the",
"API",
"usage",
"per",
"day",
"for",
"this",
"application",
"."
] |
5ad1b0325b7630daf41eb59fc8acbcb785cbc387
|
https://github.com/jeremyvdw/disqussion/blob/5ad1b0325b7630daf41eb59fc8acbcb785cbc387/lib/disqussion/client/applications.rb#L15-L18
|
8,415
|
cajun/smile
|
lib/smile/smug.rb
|
Smile.Smug.auth
|
def auth( email, pass )
json = secure_web_method_call( {
:method => 'smugmug.login.withPassword',
:EmailAddress => email,
:Password => pass
}
)
self.session.id = json["login"]["session"]["id"]
json
end
|
ruby
|
def auth( email, pass )
json = secure_web_method_call( {
:method => 'smugmug.login.withPassword',
:EmailAddress => email,
:Password => pass
}
)
self.session.id = json["login"]["session"]["id"]
json
end
|
[
"def",
"auth",
"(",
"email",
",",
"pass",
")",
"json",
"=",
"secure_web_method_call",
"(",
"{",
":method",
"=>",
"'smugmug.login.withPassword'",
",",
":EmailAddress",
"=>",
"email",
",",
":Password",
"=>",
"pass",
"}",
")",
"self",
".",
"session",
".",
"id",
"=",
"json",
"[",
"\"login\"",
"]",
"[",
"\"session\"",
"]",
"[",
"\"id\"",
"]",
"json",
"end"
] |
Login to SmugMug using a specific user account.
@param [String] email The username ( Nickname ) for the SmugMug account
@param [String] password The password for the SmugMug account
@return [Smile::SmugMug.new] An Smug object that has been authenticated
|
[
"Login",
"to",
"SmugMug",
"using",
"a",
"specific",
"user",
"account",
"."
] |
5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6
|
https://github.com/cajun/smile/blob/5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6/lib/smile/smug.rb#L16-L26
|
8,416
|
hackersrc/hs-cli
|
lib/hs/models/course.rb
|
HS.Course.find_chapter
|
def find_chapter(slug)
chapters.find { |c| c.slug.to_s == slug.to_s }
end
|
ruby
|
def find_chapter(slug)
chapters.find { |c| c.slug.to_s == slug.to_s }
end
|
[
"def",
"find_chapter",
"(",
"slug",
")",
"chapters",
".",
"find",
"{",
"|",
"c",
"|",
"c",
".",
"slug",
".",
"to_s",
"==",
"slug",
".",
"to_s",
"}",
"end"
] |
Tries to find chapter in this course by chapter slug.
|
[
"Tries",
"to",
"find",
"chapter",
"in",
"this",
"course",
"by",
"chapter",
"slug",
"."
] |
018367cab5e8d324f2097e79faaf71819390eccc
|
https://github.com/hackersrc/hs-cli/blob/018367cab5e8d324f2097e79faaf71819390eccc/lib/hs/models/course.rb#L32-L34
|
8,417
|
ikayzo/SDL.rb
|
lib/sdl4r/parser.rb
|
SDL4R.Parser.parse
|
def parse
tags = []
while tokens = @tokenizer.read_line_tokens()
if tokens.last.type == :START_BLOCK
# tag with a block
tag = construct_tag(tokens[0...-1])
add_children(tag)
tags << tag
elsif tokens.first.type == :END_BLOCK
# we found an block end token that should have been consumed by
# add_children() normally
parse_error(
"No opening block ({) for close block (}).",
tokens.first.line,
tokens.first.position)
else
# tag without block
tags << construct_tag(tokens)
end
end
@tokenizer.close()
return tags
end
|
ruby
|
def parse
tags = []
while tokens = @tokenizer.read_line_tokens()
if tokens.last.type == :START_BLOCK
# tag with a block
tag = construct_tag(tokens[0...-1])
add_children(tag)
tags << tag
elsif tokens.first.type == :END_BLOCK
# we found an block end token that should have been consumed by
# add_children() normally
parse_error(
"No opening block ({) for close block (}).",
tokens.first.line,
tokens.first.position)
else
# tag without block
tags << construct_tag(tokens)
end
end
@tokenizer.close()
return tags
end
|
[
"def",
"parse",
"tags",
"=",
"[",
"]",
"while",
"tokens",
"=",
"@tokenizer",
".",
"read_line_tokens",
"(",
")",
"if",
"tokens",
".",
"last",
".",
"type",
"==",
":START_BLOCK",
"# tag with a block\r",
"tag",
"=",
"construct_tag",
"(",
"tokens",
"[",
"0",
"...",
"-",
"1",
"]",
")",
"add_children",
"(",
"tag",
")",
"tags",
"<<",
"tag",
"elsif",
"tokens",
".",
"first",
".",
"type",
"==",
":END_BLOCK",
"# we found an block end token that should have been consumed by\r",
"# add_children() normally\r",
"parse_error",
"(",
"\"No opening block ({) for close block (}).\"",
",",
"tokens",
".",
"first",
".",
"line",
",",
"tokens",
".",
"first",
".",
"position",
")",
"else",
"# tag without block\r",
"tags",
"<<",
"construct_tag",
"(",
"tokens",
")",
"end",
"end",
"@tokenizer",
".",
"close",
"(",
")",
"return",
"tags",
"end"
] |
Creates an SDL parser on the specified +IO+.
IO.open("path/to/sdl_file") { |io|
parser = SDL4R::Parser.new(io)
tags = parser.parse()
}
Parses the underlying +IO+ and returns an +Array+ of +Tag+.
==Errors
[IOError] If a problem is encountered with the IO
[SdlParseError] If the document is malformed
|
[
"Creates",
"an",
"SDL",
"parser",
"on",
"the",
"specified",
"+",
"IO",
"+",
"."
] |
1663b9f5aa95d8d6269f060e343c2d2fd9309259
|
https://github.com/ikayzo/SDL.rb/blob/1663b9f5aa95d8d6269f060e343c2d2fd9309259/lib/sdl4r/parser.rb#L70-L96
|
8,418
|
ikayzo/SDL.rb
|
lib/sdl4r/parser.rb
|
SDL4R.Parser.add_children
|
def add_children(parent)
while tokens = @tokenizer.read_line_tokens()
if tokens.first.type == :END_BLOCK
return
elsif tokens.last.type == :START_BLOCK
# found a child with a block
tag = construct_tag(tokens[0...-1]);
add_children(tag)
parent.add_child(tag)
else
parent.add_child(construct_tag(tokens))
end
end
parse_error("No close block (}).", @tokenizer.line_no, UNKNOWN_POSITION)
end
|
ruby
|
def add_children(parent)
while tokens = @tokenizer.read_line_tokens()
if tokens.first.type == :END_BLOCK
return
elsif tokens.last.type == :START_BLOCK
# found a child with a block
tag = construct_tag(tokens[0...-1]);
add_children(tag)
parent.add_child(tag)
else
parent.add_child(construct_tag(tokens))
end
end
parse_error("No close block (}).", @tokenizer.line_no, UNKNOWN_POSITION)
end
|
[
"def",
"add_children",
"(",
"parent",
")",
"while",
"tokens",
"=",
"@tokenizer",
".",
"read_line_tokens",
"(",
")",
"if",
"tokens",
".",
"first",
".",
"type",
"==",
":END_BLOCK",
"return",
"elsif",
"tokens",
".",
"last",
".",
"type",
"==",
":START_BLOCK",
"# found a child with a block\r",
"tag",
"=",
"construct_tag",
"(",
"tokens",
"[",
"0",
"...",
"-",
"1",
"]",
")",
";",
"add_children",
"(",
"tag",
")",
"parent",
".",
"add_child",
"(",
"tag",
")",
"else",
"parent",
".",
"add_child",
"(",
"construct_tag",
"(",
"tokens",
")",
")",
"end",
"end",
"parse_error",
"(",
"\"No close block (}).\"",
",",
"@tokenizer",
".",
"line_no",
",",
"UNKNOWN_POSITION",
")",
"end"
] |
Parses the children tags of +parent+ until an end of block is found.
|
[
"Parses",
"the",
"children",
"tags",
"of",
"+",
"parent",
"+",
"until",
"an",
"end",
"of",
"block",
"is",
"found",
"."
] |
1663b9f5aa95d8d6269f060e343c2d2fd9309259
|
https://github.com/ikayzo/SDL.rb/blob/1663b9f5aa95d8d6269f060e343c2d2fd9309259/lib/sdl4r/parser.rb#L112-L129
|
8,419
|
ikayzo/SDL.rb
|
lib/sdl4r/parser.rb
|
SDL4R.Parser.combine
|
def combine(date, time_span_with_zone)
time_zone_offset = time_span_with_zone.time_zone_offset
time_zone_offset = TimeSpanWithZone.default_time_zone_offset if time_zone_offset.nil?
new_date_time(
date.year,
date.month,
date.day,
time_span_with_zone.hour,
time_span_with_zone.min,
time_span_with_zone.sec,
time_zone_offset)
end
|
ruby
|
def combine(date, time_span_with_zone)
time_zone_offset = time_span_with_zone.time_zone_offset
time_zone_offset = TimeSpanWithZone.default_time_zone_offset if time_zone_offset.nil?
new_date_time(
date.year,
date.month,
date.day,
time_span_with_zone.hour,
time_span_with_zone.min,
time_span_with_zone.sec,
time_zone_offset)
end
|
[
"def",
"combine",
"(",
"date",
",",
"time_span_with_zone",
")",
"time_zone_offset",
"=",
"time_span_with_zone",
".",
"time_zone_offset",
"time_zone_offset",
"=",
"TimeSpanWithZone",
".",
"default_time_zone_offset",
"if",
"time_zone_offset",
".",
"nil?",
"new_date_time",
"(",
"date",
".",
"year",
",",
"date",
".",
"month",
",",
"date",
".",
"day",
",",
"time_span_with_zone",
".",
"hour",
",",
"time_span_with_zone",
".",
"min",
",",
"time_span_with_zone",
".",
"sec",
",",
"time_zone_offset",
")",
"end"
] |
Combines a simple Date with a TimeSpanWithZone to create a DateTime
|
[
"Combines",
"a",
"simple",
"Date",
"with",
"a",
"TimeSpanWithZone",
"to",
"create",
"a",
"DateTime"
] |
1663b9f5aa95d8d6269f060e343c2d2fd9309259
|
https://github.com/ikayzo/SDL.rb/blob/1663b9f5aa95d8d6269f060e343c2d2fd9309259/lib/sdl4r/parser.rb#L417-L429
|
8,420
|
ikayzo/SDL.rb
|
lib/sdl4r/parser.rb
|
SDL4R.Parser.expecting_but_got
|
def expecting_but_got(expecting, got, line, position)
@tokenizer.expecting_but_got(expecting, got, line, position)
end
|
ruby
|
def expecting_but_got(expecting, got, line, position)
@tokenizer.expecting_but_got(expecting, got, line, position)
end
|
[
"def",
"expecting_but_got",
"(",
"expecting",
",",
"got",
",",
"line",
",",
"position",
")",
"@tokenizer",
".",
"expecting_but_got",
"(",
"expecting",
",",
"got",
",",
"line",
",",
"position",
")",
"end"
] |
Close the reader and throw a SdlParseError using the format
Was expecting X but got Y.
|
[
"Close",
"the",
"reader",
"and",
"throw",
"a",
"SdlParseError",
"using",
"the",
"format",
"Was",
"expecting",
"X",
"but",
"got",
"Y",
"."
] |
1663b9f5aa95d8d6269f060e343c2d2fd9309259
|
https://github.com/ikayzo/SDL.rb/blob/1663b9f5aa95d8d6269f060e343c2d2fd9309259/lib/sdl4r/parser.rb#L648-L650
|
8,421
|
rikas/tracinho
|
lib/tracinho/complement_builder.rb
|
Tracinho.ComplementBuilder.build
|
def build
text = @word.hyphenated? ? remove_dash(@word.to_s) : add_dash(@word.to_s)
Word.new(text)
end
|
ruby
|
def build
text = @word.hyphenated? ? remove_dash(@word.to_s) : add_dash(@word.to_s)
Word.new(text)
end
|
[
"def",
"build",
"text",
"=",
"@word",
".",
"hyphenated?",
"?",
"remove_dash",
"(",
"@word",
".",
"to_s",
")",
":",
"add_dash",
"(",
"@word",
".",
"to_s",
")",
"Word",
".",
"new",
"(",
"text",
")",
"end"
] |
Builds the complementary word.
ComplementBuilder.new(Word.new('fizeste')).build
# => #<Tracinho::Word:0x007f8a9b0ba928 @text="fize-te">
ComplementBuilder.new(Word.new('passa-mos')).build
# => #<Tracinho::Word:0x007f8a9b10f270 @text="passamos">
|
[
"Builds",
"the",
"complementary",
"word",
"."
] |
2d0abfec5da8fd24ba4dc72480401cd5adbf5fac
|
https://github.com/rikas/tracinho/blob/2d0abfec5da8fd24ba4dc72480401cd5adbf5fac/lib/tracinho/complement_builder.rb#L17-L21
|
8,422
|
elgalu/strongly_typed
|
lib/strongly_typed/model.rb
|
StronglyTyped.Model.initialize_from_hash
|
def initialize_from_hash(hsh)
hsh.first.each_pair do |k, v|
if self.class.members.include?(k.to_sym)
self.public_send("#{k}=", v)
else
raise NameError, "Trying to assign non-existing member #{k}=#{v}"
end
end
end
|
ruby
|
def initialize_from_hash(hsh)
hsh.first.each_pair do |k, v|
if self.class.members.include?(k.to_sym)
self.public_send("#{k}=", v)
else
raise NameError, "Trying to assign non-existing member #{k}=#{v}"
end
end
end
|
[
"def",
"initialize_from_hash",
"(",
"hsh",
")",
"hsh",
".",
"first",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"if",
"self",
".",
"class",
".",
"members",
".",
"include?",
"(",
"k",
".",
"to_sym",
")",
"self",
".",
"public_send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"else",
"raise",
"NameError",
",",
"\"Trying to assign non-existing member #{k}=#{v}\"",
"end",
"end",
"end"
] |
Entity constructor from a Hash
@param [Hash] hsh hash of values
@example
class Person
include StronglyTyped::Model
attribute :id, Integer
attribute :slug, String
end
Person.new(id: 1, slug: 'elgalu')
#=> #<Person:0x00c98 @id=1, @slug="elgalu">
leo.id #=> 1
leo.slug #=> "elgalu"
@raise [NameError] if tries to assign a non-existing member
@private
|
[
"Entity",
"constructor",
"from",
"a",
"Hash"
] |
b779ec9fe7bde28608a8a7022b28ef322fcdcebd
|
https://github.com/elgalu/strongly_typed/blob/b779ec9fe7bde28608a8a7022b28ef322fcdcebd/lib/strongly_typed/model.rb#L59-L67
|
8,423
|
elgalu/strongly_typed
|
lib/strongly_typed/model.rb
|
StronglyTyped.Model.initialize_from_ordered_args
|
def initialize_from_ordered_args(values)
raise ArgumentError, "wrong number of arguments(#{values.size} for #{self.class.members.size})" if values.size > self.class.members.size
values.each_with_index do |v, i|
# instance_variable_set("@#{self.class.members[i]}", v)
self.public_send("#{self.class.members[i]}=", v)
end
end
|
ruby
|
def initialize_from_ordered_args(values)
raise ArgumentError, "wrong number of arguments(#{values.size} for #{self.class.members.size})" if values.size > self.class.members.size
values.each_with_index do |v, i|
# instance_variable_set("@#{self.class.members[i]}", v)
self.public_send("#{self.class.members[i]}=", v)
end
end
|
[
"def",
"initialize_from_ordered_args",
"(",
"values",
")",
"raise",
"ArgumentError",
",",
"\"wrong number of arguments(#{values.size} for #{self.class.members.size})\"",
"if",
"values",
".",
"size",
">",
"self",
".",
"class",
".",
"members",
".",
"size",
"values",
".",
"each_with_index",
"do",
"|",
"v",
",",
"i",
"|",
"# instance_variable_set(\"@#{self.class.members[i]}\", v)",
"self",
".",
"public_send",
"(",
"\"#{self.class.members[i]}=\"",
",",
"v",
")",
"end",
"end"
] |
Entity constructor from ordered params
@param [Array] values ordered values
@example
class Person
include StronglyTyped::Model
attribute :id, Integer
attribute :slug, String
end
Person.new(1, 'elgalu')
#=> #<Person:0x00c99 @id=1, @slug="elgalu">
leo.id #=> 1
leo.slug #=> "elgalu"
@raise [ArgumentError] if the arity doesn't match
@private
|
[
"Entity",
"constructor",
"from",
"ordered",
"params"
] |
b779ec9fe7bde28608a8a7022b28ef322fcdcebd
|
https://github.com/elgalu/strongly_typed/blob/b779ec9fe7bde28608a8a7022b28ef322fcdcebd/lib/strongly_typed/model.rb#L89-L96
|
8,424
|
AndreasWurm/pingback
|
lib/pingback/server.rb
|
Pingback.Server.call
|
def call(env)
@request = Rack::Request.new(env)
xml_response = @xmlrpc_handler.process(request_body)
[200, {'Content-Type' => 'text/xml'}, [xml_response]]
end
|
ruby
|
def call(env)
@request = Rack::Request.new(env)
xml_response = @xmlrpc_handler.process(request_body)
[200, {'Content-Type' => 'text/xml'}, [xml_response]]
end
|
[
"def",
"call",
"(",
"env",
")",
"@request",
"=",
"Rack",
"::",
"Request",
".",
"new",
"(",
"env",
")",
"xml_response",
"=",
"@xmlrpc_handler",
".",
"process",
"(",
"request_body",
")",
"[",
"200",
",",
"{",
"'Content-Type'",
"=>",
"'text/xml'",
"}",
",",
"[",
"xml_response",
"]",
"]",
"end"
] |
A new instance of Server.
@param [Proc, #call] request_handler proc which implements the pingback registration and takes the source_uri and the target_uri
as params. Use the exceptions defined in Pingback to indicate errors.
|
[
"A",
"new",
"instance",
"of",
"Server",
"."
] |
44028aa94420b5cb5454ee56d459f0e4ff31194f
|
https://github.com/AndreasWurm/pingback/blob/44028aa94420b5cb5454ee56d459f0e4ff31194f/lib/pingback/server.rb#L20-L24
|
8,425
|
pengwynn/buzzsprout
|
lib/buzzsprout/episode.rb
|
Buzzsprout.Episode.duration=
|
def duration=(value)
new_duration = value.to_s.split(":").reverse
s, m = new_duration
self[:duration] = (s.to_i + (m.to_i*60))
end
|
ruby
|
def duration=(value)
new_duration = value.to_s.split(":").reverse
s, m = new_duration
self[:duration] = (s.to_i + (m.to_i*60))
end
|
[
"def",
"duration",
"=",
"(",
"value",
")",
"new_duration",
"=",
"value",
".",
"to_s",
".",
"split",
"(",
"\":\"",
")",
".",
"reverse",
"s",
",",
"m",
"=",
"new_duration",
"self",
"[",
":duration",
"]",
"=",
"(",
"s",
".",
"to_i",
"+",
"(",
"m",
".",
"to_i",
"60",
")",
")",
"end"
] |
Set the duration
@param [String] duration as time
|
[
"Set",
"the",
"duration"
] |
6a4bf696efc086ef6d009293ece21e001fc133cd
|
https://github.com/pengwynn/buzzsprout/blob/6a4bf696efc086ef6d009293ece21e001fc133cd/lib/buzzsprout/episode.rb#L40-L44
|
8,426
|
philosophie/stairs
|
lib/stairs/step.rb
|
Stairs.Step.provide
|
def provide(prompt, options = {})
options.reverse_merge! required: true, default: nil
required = options[:required] && !options[:default]
prompt = "#{defaulted_prompt(prompt, options[:default])}: "
if Stairs.configuration.use_defaults && options[:default]
options[:default]
else
Stairs::Util::CLI.collect(prompt.blue, required: required) ||
options[:default]
end
end
|
ruby
|
def provide(prompt, options = {})
options.reverse_merge! required: true, default: nil
required = options[:required] && !options[:default]
prompt = "#{defaulted_prompt(prompt, options[:default])}: "
if Stairs.configuration.use_defaults && options[:default]
options[:default]
else
Stairs::Util::CLI.collect(prompt.blue, required: required) ||
options[:default]
end
end
|
[
"def",
"provide",
"(",
"prompt",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"reverse_merge!",
"required",
":",
"true",
",",
"default",
":",
"nil",
"required",
"=",
"options",
"[",
":required",
"]",
"&&",
"!",
"options",
"[",
":default",
"]",
"prompt",
"=",
"\"#{defaulted_prompt(prompt, options[:default])}: \"",
"if",
"Stairs",
".",
"configuration",
".",
"use_defaults",
"&&",
"options",
"[",
":default",
"]",
"options",
"[",
":default",
"]",
"else",
"Stairs",
"::",
"Util",
"::",
"CLI",
".",
"collect",
"(",
"prompt",
".",
"blue",
",",
"required",
":",
"required",
")",
"||",
"options",
"[",
":default",
"]",
"end",
"end"
] |
Prompt user to provide input
|
[
"Prompt",
"user",
"to",
"provide",
"input"
] |
535f69a783bd5ff418d786af8c91789925c4388b
|
https://github.com/philosophie/stairs/blob/535f69a783bd5ff418d786af8c91789925c4388b/lib/stairs/step.rb#L39-L50
|
8,427
|
philosophie/stairs
|
lib/stairs/step.rb
|
Stairs.Step.env
|
def env(name, value)
ENV[name] = value
if value
Stairs.configuration.env_adapter.set name, value
else
Stairs.configuration.env_adapter.unset name
end
end
|
ruby
|
def env(name, value)
ENV[name] = value
if value
Stairs.configuration.env_adapter.set name, value
else
Stairs.configuration.env_adapter.unset name
end
end
|
[
"def",
"env",
"(",
"name",
",",
"value",
")",
"ENV",
"[",
"name",
"]",
"=",
"value",
"if",
"value",
"Stairs",
".",
"configuration",
".",
"env_adapter",
".",
"set",
"name",
",",
"value",
"else",
"Stairs",
".",
"configuration",
".",
"env_adapter",
".",
"unset",
"name",
"end",
"end"
] |
Set or update env var
|
[
"Set",
"or",
"update",
"env",
"var"
] |
535f69a783bd5ff418d786af8c91789925c4388b
|
https://github.com/philosophie/stairs/blob/535f69a783bd5ff418d786af8c91789925c4388b/lib/stairs/step.rb#L64-L72
|
8,428
|
26fe/dircat
|
lib/dircat/cat_on_yaml/cat_on_yaml.rb
|
DirCat.CatOnYaml.from_dir
|
def from_dir(dirname)
unless File.directory?(dirname)
raise "'#{dirname}' is not a directory or doesn't exists"
end
@dirname = File.expand_path dirname
@ctime = DateTime.now
_load_from_dir
self
end
|
ruby
|
def from_dir(dirname)
unless File.directory?(dirname)
raise "'#{dirname}' is not a directory or doesn't exists"
end
@dirname = File.expand_path dirname
@ctime = DateTime.now
_load_from_dir
self
end
|
[
"def",
"from_dir",
"(",
"dirname",
")",
"unless",
"File",
".",
"directory?",
"(",
"dirname",
")",
"raise",
"\"'#{dirname}' is not a directory or doesn't exists\"",
"end",
"@dirname",
"=",
"File",
".",
"expand_path",
"dirname",
"@ctime",
"=",
"DateTime",
".",
"now",
"_load_from_dir",
"self",
"end"
] |
Build a catalog from a directory
|
[
"Build",
"a",
"catalog",
"from",
"a",
"directory"
] |
b36bc07562f6be4a7092b33b9153f807033ad670
|
https://github.com/26fe/dircat/blob/b36bc07562f6be4a7092b33b9153f807033ad670/lib/dircat/cat_on_yaml/cat_on_yaml.rb#L59-L67
|
8,429
|
26fe/dircat
|
lib/dircat/cat_on_yaml/cat_on_yaml.rb
|
DirCat.CatOnYaml.from_file
|
def from_file(filename)
unless File.exist?(filename)
raise DirCatException.new, "'#{filename}' not exists"
end
dircat_ser = File.open(filename) { |f| YAML::load(f) }
@dirname = dircat_ser.dirname
@ctime = dircat_ser.ctime
dircat_ser.entries.each do |entry_ser|
add_entry(Entry.from_ser(entry_ser))
end
self
end
|
ruby
|
def from_file(filename)
unless File.exist?(filename)
raise DirCatException.new, "'#{filename}' not exists"
end
dircat_ser = File.open(filename) { |f| YAML::load(f) }
@dirname = dircat_ser.dirname
@ctime = dircat_ser.ctime
dircat_ser.entries.each do |entry_ser|
add_entry(Entry.from_ser(entry_ser))
end
self
end
|
[
"def",
"from_file",
"(",
"filename",
")",
"unless",
"File",
".",
"exist?",
"(",
"filename",
")",
"raise",
"DirCatException",
".",
"new",
",",
"\"'#{filename}' not exists\"",
"end",
"dircat_ser",
"=",
"File",
".",
"open",
"(",
"filename",
")",
"{",
"|",
"f",
"|",
"YAML",
"::",
"load",
"(",
"f",
")",
"}",
"@dirname",
"=",
"dircat_ser",
".",
"dirname",
"@ctime",
"=",
"dircat_ser",
".",
"ctime",
"dircat_ser",
".",
"entries",
".",
"each",
"do",
"|",
"entry_ser",
"|",
"add_entry",
"(",
"Entry",
".",
"from_ser",
"(",
"entry_ser",
")",
")",
"end",
"self",
"end"
] |
Load catalog from a file
|
[
"Load",
"catalog",
"from",
"a",
"file"
] |
b36bc07562f6be4a7092b33b9153f807033ad670
|
https://github.com/26fe/dircat/blob/b36bc07562f6be4a7092b33b9153f807033ad670/lib/dircat/cat_on_yaml/cat_on_yaml.rb#L70-L81
|
8,430
|
26fe/dircat
|
lib/dircat/cat_on_yaml/cat_on_yaml.rb
|
DirCat.CatOnYaml.save_to
|
def save_to(file)
if file.kind_of?(String)
begin
File.open(file, "w") do |f|
f.puts to_ser.to_yaml
end
rescue Errno::ENOENT
raise DirCatException.new, "DirCat: cannot write into '#{file}'", caller
end
else
file.puts to_ser.to_yaml
end
end
|
ruby
|
def save_to(file)
if file.kind_of?(String)
begin
File.open(file, "w") do |f|
f.puts to_ser.to_yaml
end
rescue Errno::ENOENT
raise DirCatException.new, "DirCat: cannot write into '#{file}'", caller
end
else
file.puts to_ser.to_yaml
end
end
|
[
"def",
"save_to",
"(",
"file",
")",
"if",
"file",
".",
"kind_of?",
"(",
"String",
")",
"begin",
"File",
".",
"open",
"(",
"file",
",",
"\"w\"",
")",
"do",
"|",
"f",
"|",
"f",
".",
"puts",
"to_ser",
".",
"to_yaml",
"end",
"rescue",
"Errno",
"::",
"ENOENT",
"raise",
"DirCatException",
".",
"new",
",",
"\"DirCat: cannot write into '#{file}'\"",
",",
"caller",
"end",
"else",
"file",
".",
"puts",
"to_ser",
".",
"to_yaml",
"end",
"end"
] |
Save serialized catalog to file
@param [String,File] file
|
[
"Save",
"serialized",
"catalog",
"to",
"file"
] |
b36bc07562f6be4a7092b33b9153f807033ad670
|
https://github.com/26fe/dircat/blob/b36bc07562f6be4a7092b33b9153f807033ad670/lib/dircat/cat_on_yaml/cat_on_yaml.rb#L139-L151
|
8,431
|
26fe/dircat
|
lib/dircat/cat_on_yaml/cat_on_yaml.rb
|
DirCat.CatOnYaml.report
|
def report
dups = duplicates
s = "Base dir: #{@dirname}\n"
s += "Nr. file: #{size}"
if dups.size > 0
s+= " (duplicates #{dups.size})"
end
s += "\nBytes: #{bytes.with_separator}"
s
end
|
ruby
|
def report
dups = duplicates
s = "Base dir: #{@dirname}\n"
s += "Nr. file: #{size}"
if dups.size > 0
s+= " (duplicates #{dups.size})"
end
s += "\nBytes: #{bytes.with_separator}"
s
end
|
[
"def",
"report",
"dups",
"=",
"duplicates",
"s",
"=",
"\"Base dir: #{@dirname}\\n\"",
"s",
"+=",
"\"Nr. file: #{size}\"",
"if",
"dups",
".",
"size",
">",
"0",
"s",
"+=",
"\" (duplicates #{dups.size})\"",
"end",
"s",
"+=",
"\"\\nBytes: #{bytes.with_separator}\"",
"s",
"end"
] |
simple report with essential information about this catalog
@return [String] report
|
[
"simple",
"report",
"with",
"essential",
"information",
"about",
"this",
"catalog"
] |
b36bc07562f6be4a7092b33b9153f807033ad670
|
https://github.com/26fe/dircat/blob/b36bc07562f6be4a7092b33b9153f807033ad670/lib/dircat/cat_on_yaml/cat_on_yaml.rb#L177-L186
|
8,432
|
26fe/dircat
|
lib/dircat/cat_on_yaml/cat_on_yaml.rb
|
DirCat.CatOnYaml.script_dup
|
def script_dup
r = "require 'fileutils'\n"
duplicates.each do |entries|
flg_first = true
r += "\n"
entries.each do |entry|
src = File.join(@dirname, entry.path, entry.name)
if flg_first
flg_first = false
r += "# FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
else
r += "FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
end
end
end
r
end
|
ruby
|
def script_dup
r = "require 'fileutils'\n"
duplicates.each do |entries|
flg_first = true
r += "\n"
entries.each do |entry|
src = File.join(@dirname, entry.path, entry.name)
if flg_first
flg_first = false
r += "# FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
else
r += "FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
end
end
end
r
end
|
[
"def",
"script_dup",
"r",
"=",
"\"require 'fileutils'\\n\"",
"duplicates",
".",
"each",
"do",
"|",
"entries",
"|",
"flg_first",
"=",
"true",
"r",
"+=",
"\"\\n\"",
"entries",
".",
"each",
"do",
"|",
"entry",
"|",
"src",
"=",
"File",
".",
"join",
"(",
"@dirname",
",",
"entry",
".",
"path",
",",
"entry",
".",
"name",
")",
"if",
"flg_first",
"flg_first",
"=",
"false",
"r",
"+=",
"\"# FileUtils.mv( \\\"#{src}\\\", \\\"#{Dir.tmpdir}\\\" )\\n\"",
"else",
"r",
"+=",
"\"FileUtils.mv( \\\"#{src}\\\", \\\"#{Dir.tmpdir}\\\" )\\n\"",
"end",
"end",
"end",
"r",
"end"
] |
return ruby script to eliminate duplicated
@return [String] ruby script
|
[
"return",
"ruby",
"script",
"to",
"eliminate",
"duplicated"
] |
b36bc07562f6be4a7092b33b9153f807033ad670
|
https://github.com/26fe/dircat/blob/b36bc07562f6be4a7092b33b9153f807033ad670/lib/dircat/cat_on_yaml/cat_on_yaml.rb#L265-L281
|
8,433
|
jimjh/reaction
|
lib/reaction/registry/registry.rb
|
Reaction.Registry.add
|
def add(channel, client)
@lock.synchronize do
_remove(client) if @clients.include? client and @clients[client] != channel
debug { "Adding #{client} to #{channel}." }
@clients[client] = channel
@channels[channel] = @channels[channel] ? @channels[channel] + 1 : 1
end
end
|
ruby
|
def add(channel, client)
@lock.synchronize do
_remove(client) if @clients.include? client and @clients[client] != channel
debug { "Adding #{client} to #{channel}." }
@clients[client] = channel
@channels[channel] = @channels[channel] ? @channels[channel] + 1 : 1
end
end
|
[
"def",
"add",
"(",
"channel",
",",
"client",
")",
"@lock",
".",
"synchronize",
"do",
"_remove",
"(",
"client",
")",
"if",
"@clients",
".",
"include?",
"client",
"and",
"@clients",
"[",
"client",
"]",
"!=",
"channel",
"debug",
"{",
"\"Adding #{client} to #{channel}.\"",
"}",
"@clients",
"[",
"client",
"]",
"=",
"channel",
"@channels",
"[",
"channel",
"]",
"=",
"@channels",
"[",
"channel",
"]",
"?",
"@channels",
"[",
"channel",
"]",
"+",
"1",
":",
"1",
"end",
"end"
] |
Creates a new registry.
Registers a new client for that channel. Migrates client to new channel
if client already exists.
@param [String] channel ID
@param [String] client ID
|
[
"Creates",
"a",
"new",
"registry",
".",
"Registers",
"a",
"new",
"client",
"for",
"that",
"channel",
".",
"Migrates",
"client",
"to",
"new",
"channel",
"if",
"client",
"already",
"exists",
"."
] |
8aff9633dbd177ea536b79f59115a2825b5adf0a
|
https://github.com/jimjh/reaction/blob/8aff9633dbd177ea536b79f59115a2825b5adf0a/lib/reaction/registry/registry.rb#L27-L34
|
8,434
|
jimjh/reaction
|
lib/reaction/registry/registry.rb
|
Reaction.Registry._remove
|
def _remove(client)
return unless @clients.include? client
channel = @clients.delete(client)
debug { "Removing #{client} from #{channel}." }
@channels[channel] -= 1
@channels.delete(channel) if @channels[channel].zero?
end
|
ruby
|
def _remove(client)
return unless @clients.include? client
channel = @clients.delete(client)
debug { "Removing #{client} from #{channel}." }
@channels[channel] -= 1
@channels.delete(channel) if @channels[channel].zero?
end
|
[
"def",
"_remove",
"(",
"client",
")",
"return",
"unless",
"@clients",
".",
"include?",
"client",
"channel",
"=",
"@clients",
".",
"delete",
"(",
"client",
")",
"debug",
"{",
"\"Removing #{client} from #{channel}.\"",
"}",
"@channels",
"[",
"channel",
"]",
"-=",
"1",
"@channels",
".",
"delete",
"(",
"channel",
")",
"if",
"@channels",
"[",
"channel",
"]",
".",
"zero?",
"end"
] |
Removes client from +@clients+, and decrements channel's client count. If
channel has no clients, it is removed.
@param [String] client ID
|
[
"Removes",
"client",
"from",
"+"
] |
8aff9633dbd177ea536b79f59115a2825b5adf0a
|
https://github.com/jimjh/reaction/blob/8aff9633dbd177ea536b79f59115a2825b5adf0a/lib/reaction/registry/registry.rb#L55-L61
|
8,435
|
NathanTCz/idlc-sdk-core
|
lib/idlc-sdk-core/helpers.rb
|
Idlc.Helpers.system_command
|
def system_command(*command_args)
cmd = Mixlib::ShellOut.new(*command_args)
cmd.run_command
cmd
end
|
ruby
|
def system_command(*command_args)
cmd = Mixlib::ShellOut.new(*command_args)
cmd.run_command
cmd
end
|
[
"def",
"system_command",
"(",
"*",
"command_args",
")",
"cmd",
"=",
"Mixlib",
"::",
"ShellOut",
".",
"new",
"(",
"command_args",
")",
"cmd",
".",
"run_command",
"cmd",
"end"
] |
Runs given commands using mixlib-shellout
|
[
"Runs",
"given",
"commands",
"using",
"mixlib",
"-",
"shellout"
] |
a9cf07f65a1b206b7f776183d29923aa345f582e
|
https://github.com/NathanTCz/idlc-sdk-core/blob/a9cf07f65a1b206b7f776183d29923aa345f582e/lib/idlc-sdk-core/helpers.rb#L8-L12
|
8,436
|
leather-s/renote_dac
|
app/workers/renote_dac/service_queue_worker.rb
|
RenoteDac.ServiceQueueWorker.work
|
def work(message)
# invoke service object to save message to database
message = JSON.parse(message)
RenoteDac::Mailer.enqueue(
message['postmark_data']['template'],
message['postmark_data']['address'],
message['postmark_data']['params'],
message['postmark_data']['attachments']
)
# let queue know message was received
ack!
end
|
ruby
|
def work(message)
# invoke service object to save message to database
message = JSON.parse(message)
RenoteDac::Mailer.enqueue(
message['postmark_data']['template'],
message['postmark_data']['address'],
message['postmark_data']['params'],
message['postmark_data']['attachments']
)
# let queue know message was received
ack!
end
|
[
"def",
"work",
"(",
"message",
")",
"# invoke service object to save message to database",
"message",
"=",
"JSON",
".",
"parse",
"(",
"message",
")",
"RenoteDac",
"::",
"Mailer",
".",
"enqueue",
"(",
"message",
"[",
"'postmark_data'",
"]",
"[",
"'template'",
"]",
",",
"message",
"[",
"'postmark_data'",
"]",
"[",
"'address'",
"]",
",",
"message",
"[",
"'postmark_data'",
"]",
"[",
"'params'",
"]",
",",
"message",
"[",
"'postmark_data'",
"]",
"[",
"'attachments'",
"]",
")",
"# let queue know message was received",
"ack!",
"end"
] |
work method receives message payload in raw format
in our case it is JSON encoded string
which we can pass to RecentPosts service without
changes
|
[
"work",
"method",
"receives",
"message",
"payload",
"in",
"raw",
"format",
"in",
"our",
"case",
"it",
"is",
"JSON",
"encoded",
"string",
"which",
"we",
"can",
"pass",
"to",
"RecentPosts",
"service",
"without",
"changes"
] |
2836ab504891d94e5b18758b0910dae9a2cda8f9
|
https://github.com/leather-s/renote_dac/blob/2836ab504891d94e5b18758b0910dae9a2cda8f9/app/workers/renote_dac/service_queue_worker.rb#L16-L27
|
8,437
|
joakimk/dboard
|
lib/collector.rb
|
Dboard.Collector.update_source
|
def update_source(source, instance)
begin
data = instance.fetch
publish_data(source, data)
ensure
@after_update_callback.call
end
rescue Exception => ex
puts "Failed to update #{source}: #{ex.message}"
puts ex.backtrace
@error_callback.call(ex)
end
|
ruby
|
def update_source(source, instance)
begin
data = instance.fetch
publish_data(source, data)
ensure
@after_update_callback.call
end
rescue Exception => ex
puts "Failed to update #{source}: #{ex.message}"
puts ex.backtrace
@error_callback.call(ex)
end
|
[
"def",
"update_source",
"(",
"source",
",",
"instance",
")",
"begin",
"data",
"=",
"instance",
".",
"fetch",
"publish_data",
"(",
"source",
",",
"data",
")",
"ensure",
"@after_update_callback",
".",
"call",
"end",
"rescue",
"Exception",
"=>",
"ex",
"puts",
"\"Failed to update #{source}: #{ex.message}\"",
"puts",
"ex",
".",
"backtrace",
"@error_callback",
".",
"call",
"(",
"ex",
")",
"end"
] |
Public because the old tests depend on it
|
[
"Public",
"because",
"the",
"old",
"tests",
"depend",
"on",
"it"
] |
49a05d1ee679cf1ba8b2b543ac5836651d4cfd38
|
https://github.com/joakimk/dboard/blob/49a05d1ee679cf1ba8b2b543ac5836651d4cfd38/lib/collector.rb#L58-L69
|
8,438
|
thriventures/storage_room_gem
|
lib/storage_room/proxy.rb
|
StorageRoom.Proxy.method_missing
|
def method_missing(method_name, *args, &block)
if @object.loaded? || METHODS_WITHOUT_RELOAD.include?(method_name)
# no need to reload
else
StorageRoom.log("Reloading #{@object['url']} due to #{method_name}")
@object.reload(@object['url'], @parameters)
end
@object.send(method_name, *args, &block)
end
|
ruby
|
def method_missing(method_name, *args, &block)
if @object.loaded? || METHODS_WITHOUT_RELOAD.include?(method_name)
# no need to reload
else
StorageRoom.log("Reloading #{@object['url']} due to #{method_name}")
@object.reload(@object['url'], @parameters)
end
@object.send(method_name, *args, &block)
end
|
[
"def",
"method_missing",
"(",
"method_name",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"@object",
".",
"loaded?",
"||",
"METHODS_WITHOUT_RELOAD",
".",
"include?",
"(",
"method_name",
")",
"# no need to reload",
"else",
"StorageRoom",
".",
"log",
"(",
"\"Reloading #{@object['url']} due to #{method_name}\"",
")",
"@object",
".",
"reload",
"(",
"@object",
"[",
"'url'",
"]",
",",
"@parameters",
")",
"end",
"@object",
".",
"send",
"(",
"method_name",
",",
"args",
",",
"block",
")",
"end"
] |
Forward all method calls to the proxied object, reload if necessary
|
[
"Forward",
"all",
"method",
"calls",
"to",
"the",
"proxied",
"object",
"reload",
"if",
"necessary"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/proxy.rb#L37-L46
|
8,439
|
alphagov/govuk_navigation_helpers
|
lib/govuk_navigation_helpers/grouped_related_links.rb
|
GovukNavigationHelpers.GroupedRelatedLinks.tagged_to_same_mainstream_browse_page
|
def tagged_to_same_mainstream_browse_page
return [] unless content_item.parent
@tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
related_item.mainstream_browse_pages.map(&:content_id).include?(content_item.parent.content_id)
end
end
|
ruby
|
def tagged_to_same_mainstream_browse_page
return [] unless content_item.parent
@tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
related_item.mainstream_browse_pages.map(&:content_id).include?(content_item.parent.content_id)
end
end
|
[
"def",
"tagged_to_same_mainstream_browse_page",
"return",
"[",
"]",
"unless",
"content_item",
".",
"parent",
"@tagged_to_same_mainstream_browse_page",
"||=",
"content_item",
".",
"related_links",
".",
"select",
"do",
"|",
"related_item",
"|",
"related_item",
".",
"mainstream_browse_pages",
".",
"map",
"(",
":content_id",
")",
".",
"include?",
"(",
"content_item",
".",
"parent",
".",
"content_id",
")",
"end",
"end"
] |
This will return related items that are tagged to the same mainstream
browse page as the main content item.
|
[
"This",
"will",
"return",
"related",
"items",
"that",
"are",
"tagged",
"to",
"the",
"same",
"mainstream",
"browse",
"page",
"as",
"the",
"main",
"content",
"item",
"."
] |
5eddcaec5412473fa4e22ef8b8d2cbe406825886
|
https://github.com/alphagov/govuk_navigation_helpers/blob/5eddcaec5412473fa4e22ef8b8d2cbe406825886/lib/govuk_navigation_helpers/grouped_related_links.rb#L16-L22
|
8,440
|
alphagov/govuk_navigation_helpers
|
lib/govuk_navigation_helpers/grouped_related_links.rb
|
GovukNavigationHelpers.GroupedRelatedLinks.parents_tagged_to_same_mainstream_browse_page
|
def parents_tagged_to_same_mainstream_browse_page
return [] unless content_item.parent && content_item.parent.parent
common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id)
@parents_tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
next if common_parent_content_ids.include?(related_item.content_id)
related_item.mainstream_browse_pages.map(&:parent).map(&:content_id).include?(content_item.parent.parent.content_id)
end
end
|
ruby
|
def parents_tagged_to_same_mainstream_browse_page
return [] unless content_item.parent && content_item.parent.parent
common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id)
@parents_tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
next if common_parent_content_ids.include?(related_item.content_id)
related_item.mainstream_browse_pages.map(&:parent).map(&:content_id).include?(content_item.parent.parent.content_id)
end
end
|
[
"def",
"parents_tagged_to_same_mainstream_browse_page",
"return",
"[",
"]",
"unless",
"content_item",
".",
"parent",
"&&",
"content_item",
".",
"parent",
".",
"parent",
"common_parent_content_ids",
"=",
"tagged_to_same_mainstream_browse_page",
".",
"map",
"(",
":content_id",
")",
"@parents_tagged_to_same_mainstream_browse_page",
"||=",
"content_item",
".",
"related_links",
".",
"select",
"do",
"|",
"related_item",
"|",
"next",
"if",
"common_parent_content_ids",
".",
"include?",
"(",
"related_item",
".",
"content_id",
")",
"related_item",
".",
"mainstream_browse_pages",
".",
"map",
"(",
":parent",
")",
".",
"map",
"(",
":content_id",
")",
".",
"include?",
"(",
"content_item",
".",
"parent",
".",
"parent",
".",
"content_id",
")",
"end",
"end"
] |
This will return related items whose parents are tagged to the same mainstream
browse page as the main content item's parent.
|
[
"This",
"will",
"return",
"related",
"items",
"whose",
"parents",
"are",
"tagged",
"to",
"the",
"same",
"mainstream",
"browse",
"page",
"as",
"the",
"main",
"content",
"item",
"s",
"parent",
"."
] |
5eddcaec5412473fa4e22ef8b8d2cbe406825886
|
https://github.com/alphagov/govuk_navigation_helpers/blob/5eddcaec5412473fa4e22ef8b8d2cbe406825886/lib/govuk_navigation_helpers/grouped_related_links.rb#L26-L35
|
8,441
|
alphagov/govuk_navigation_helpers
|
lib/govuk_navigation_helpers/grouped_related_links.rb
|
GovukNavigationHelpers.GroupedRelatedLinks.tagged_to_different_mainstream_browse_pages
|
def tagged_to_different_mainstream_browse_pages
all_content_ids = (tagged_to_same_mainstream_browse_page + parents_tagged_to_same_mainstream_browse_page).map(&:content_id)
@tagged_to_different_mainstream_browse_pages ||= content_item.related_links.reject do |related_item|
all_content_ids.include?(related_item.content_id)
end
end
|
ruby
|
def tagged_to_different_mainstream_browse_pages
all_content_ids = (tagged_to_same_mainstream_browse_page + parents_tagged_to_same_mainstream_browse_page).map(&:content_id)
@tagged_to_different_mainstream_browse_pages ||= content_item.related_links.reject do |related_item|
all_content_ids.include?(related_item.content_id)
end
end
|
[
"def",
"tagged_to_different_mainstream_browse_pages",
"all_content_ids",
"=",
"(",
"tagged_to_same_mainstream_browse_page",
"+",
"parents_tagged_to_same_mainstream_browse_page",
")",
".",
"map",
"(",
":content_id",
")",
"@tagged_to_different_mainstream_browse_pages",
"||=",
"content_item",
".",
"related_links",
".",
"reject",
"do",
"|",
"related_item",
"|",
"all_content_ids",
".",
"include?",
"(",
"related_item",
".",
"content_id",
")",
"end",
"end"
] |
This will return related links that are tagged to mainstream browse
pages unrelated to the main content item.
|
[
"This",
"will",
"return",
"related",
"links",
"that",
"are",
"tagged",
"to",
"mainstream",
"browse",
"pages",
"unrelated",
"to",
"the",
"main",
"content",
"item",
"."
] |
5eddcaec5412473fa4e22ef8b8d2cbe406825886
|
https://github.com/alphagov/govuk_navigation_helpers/blob/5eddcaec5412473fa4e22ef8b8d2cbe406825886/lib/govuk_navigation_helpers/grouped_related_links.rb#L39-L45
|
8,442
|
alexblackie/yokunai
|
lib/yokunai/template.rb
|
Yokunai.Template.render
|
def render(template, context = {})
return nil unless exist?(template)
path = File.join(@template_path, template + ".erb")
layout_context = context.merge(partial: ERB.new(File.read(path)).result(Yokunai::RenderContext.new(context).get_binding))
ERB.new(@raw_layout).result(Yokunai::RenderContext.new(layout_context).get_binding)
end
|
ruby
|
def render(template, context = {})
return nil unless exist?(template)
path = File.join(@template_path, template + ".erb")
layout_context = context.merge(partial: ERB.new(File.read(path)).result(Yokunai::RenderContext.new(context).get_binding))
ERB.new(@raw_layout).result(Yokunai::RenderContext.new(layout_context).get_binding)
end
|
[
"def",
"render",
"(",
"template",
",",
"context",
"=",
"{",
"}",
")",
"return",
"nil",
"unless",
"exist?",
"(",
"template",
")",
"path",
"=",
"File",
".",
"join",
"(",
"@template_path",
",",
"template",
"+",
"\".erb\"",
")",
"layout_context",
"=",
"context",
".",
"merge",
"(",
"partial",
":",
"ERB",
".",
"new",
"(",
"File",
".",
"read",
"(",
"path",
")",
")",
".",
"result",
"(",
"Yokunai",
"::",
"RenderContext",
".",
"new",
"(",
"context",
")",
".",
"get_binding",
")",
")",
"ERB",
".",
"new",
"(",
"@raw_layout",
")",
".",
"result",
"(",
"Yokunai",
"::",
"RenderContext",
".",
"new",
"(",
"layout_context",
")",
".",
"get_binding",
")",
"end"
] |
Render an ERB template with the given name, and cache the result for
subsequent calls.
@param template [String] the name of a template
@param context [Hash] key/value pairs of variables to bind the template
@return [String] the ERB render result
|
[
"Render",
"an",
"ERB",
"template",
"with",
"the",
"given",
"name",
"and",
"cache",
"the",
"result",
"for",
"subsequent",
"calls",
"."
] |
a3266c8e3980cc174b143030c96467c2c956c0f8
|
https://github.com/alexblackie/yokunai/blob/a3266c8e3980cc174b143030c96467c2c956c0f8/lib/yokunai/template.rb#L19-L26
|
8,443
|
dmerrick/nagios_alerter
|
lib/nagios/alerter.rb
|
Nagios.Alerter.connection_params
|
def connection_params(host, port)
params = {}
if !host.nil?
params[:host] = host
elsif !Nagios::Connection.instance.host.nil?
params[:host] = Nagios::Connection.instance.host
else
raise ArgumentError, "You must provide a Nagios host or use Nagios::Connection"
end
if !port.nil?
params[:port] = port
elsif !Nagios::Connection.instance.port.nil?
params[:port] = Nagios::Connection.instance.port
else
raise ArgumentError, "You must provide a Nagios port or use Nagios::Connection"
end
return params
end
|
ruby
|
def connection_params(host, port)
params = {}
if !host.nil?
params[:host] = host
elsif !Nagios::Connection.instance.host.nil?
params[:host] = Nagios::Connection.instance.host
else
raise ArgumentError, "You must provide a Nagios host or use Nagios::Connection"
end
if !port.nil?
params[:port] = port
elsif !Nagios::Connection.instance.port.nil?
params[:port] = Nagios::Connection.instance.port
else
raise ArgumentError, "You must provide a Nagios port or use Nagios::Connection"
end
return params
end
|
[
"def",
"connection_params",
"(",
"host",
",",
"port",
")",
"params",
"=",
"{",
"}",
"if",
"!",
"host",
".",
"nil?",
"params",
"[",
":host",
"]",
"=",
"host",
"elsif",
"!",
"Nagios",
"::",
"Connection",
".",
"instance",
".",
"host",
".",
"nil?",
"params",
"[",
":host",
"]",
"=",
"Nagios",
"::",
"Connection",
".",
"instance",
".",
"host",
"else",
"raise",
"ArgumentError",
",",
"\"You must provide a Nagios host or use Nagios::Connection\"",
"end",
"if",
"!",
"port",
".",
"nil?",
"params",
"[",
":port",
"]",
"=",
"port",
"elsif",
"!",
"Nagios",
"::",
"Connection",
".",
"instance",
".",
"port",
".",
"nil?",
"params",
"[",
":port",
"]",
"=",
"Nagios",
"::",
"Connection",
".",
"instance",
".",
"port",
"else",
"raise",
"ArgumentError",
",",
"\"You must provide a Nagios port or use Nagios::Connection\"",
"end",
"return",
"params",
"end"
] |
check that we have the Nagios server details
|
[
"check",
"that",
"we",
"have",
"the",
"Nagios",
"server",
"details"
] |
c38f9d8dee7bc082d399bb4987382fbf8cd67d7d
|
https://github.com/dmerrick/nagios_alerter/blob/c38f9d8dee7bc082d399bb4987382fbf8cd67d7d/lib/nagios/alerter.rb#L66-L87
|
8,444
|
mguymon/buildr-resolver
|
lib/buildr/packaging/repository_array.rb
|
Buildr.RepositoryArray.concat
|
def concat(urls)
if !urls.nil?
converted = urls.map { |url| convert_remote_url( url ) }
super(converted)
else
super(nil)
end
end
|
ruby
|
def concat(urls)
if !urls.nil?
converted = urls.map { |url| convert_remote_url( url ) }
super(converted)
else
super(nil)
end
end
|
[
"def",
"concat",
"(",
"urls",
")",
"if",
"!",
"urls",
".",
"nil?",
"converted",
"=",
"urls",
".",
"map",
"{",
"|",
"url",
"|",
"convert_remote_url",
"(",
"url",
")",
"}",
"super",
"(",
"converted",
")",
"else",
"super",
"(",
"nil",
")",
"end",
"end"
] |
Appends the elements in other_array to self, as standardized URL Hashes
|
[
"Appends",
"the",
"elements",
"in",
"other_array",
"to",
"self",
"as",
"standardized",
"URL",
"Hashes"
] |
dbe612cffeb7e5e8b88862f54cf773f196dd6722
|
https://github.com/mguymon/buildr-resolver/blob/dbe612cffeb7e5e8b88862f54cf773f196dd6722/lib/buildr/packaging/repository_array.rb#L45-L52
|
8,445
|
mguymon/buildr-resolver
|
lib/buildr/packaging/repository_array.rb
|
Buildr.RepositoryArray.replace
|
def replace( other_array )
if !other_array.nil?
converted = other_array.map { |url| convert_remote_url( url ) }
super( converted )
else
super( nil )
end
end
|
ruby
|
def replace( other_array )
if !other_array.nil?
converted = other_array.map { |url| convert_remote_url( url ) }
super( converted )
else
super( nil )
end
end
|
[
"def",
"replace",
"(",
"other_array",
")",
"if",
"!",
"other_array",
".",
"nil?",
"converted",
"=",
"other_array",
".",
"map",
"{",
"|",
"url",
"|",
"convert_remote_url",
"(",
"url",
")",
"}",
"super",
"(",
"converted",
")",
"else",
"super",
"(",
"nil",
")",
"end",
"end"
] |
Replaces the contents of self with the contents of other_array, truncating or expanding if necessary. The contents of other_array
is converted standardized URL Hashes.
|
[
"Replaces",
"the",
"contents",
"of",
"self",
"with",
"the",
"contents",
"of",
"other_array",
"truncating",
"or",
"expanding",
"if",
"necessary",
".",
"The",
"contents",
"of",
"other_array",
"is",
"converted",
"standardized",
"URL",
"Hashes",
"."
] |
dbe612cffeb7e5e8b88862f54cf773f196dd6722
|
https://github.com/mguymon/buildr-resolver/blob/dbe612cffeb7e5e8b88862f54cf773f196dd6722/lib/buildr/packaging/repository_array.rb#L99-L106
|
8,446
|
jonahoffline/link_shrink
|
lib/link_shrink/request.rb
|
LinkShrink.Request.request
|
def request(new_url, shrinker)
shrinker.url = new_url
Typhoeus::Request.new(
shrinker.api_url,
method: shrinker.http_method,
body: shrinker.body_parameters(shrinker.url),
headers: { 'Content-Type' => shrinker.content_type }
).run
end
|
ruby
|
def request(new_url, shrinker)
shrinker.url = new_url
Typhoeus::Request.new(
shrinker.api_url,
method: shrinker.http_method,
body: shrinker.body_parameters(shrinker.url),
headers: { 'Content-Type' => shrinker.content_type }
).run
end
|
[
"def",
"request",
"(",
"new_url",
",",
"shrinker",
")",
"shrinker",
".",
"url",
"=",
"new_url",
"Typhoeus",
"::",
"Request",
".",
"new",
"(",
"shrinker",
".",
"api_url",
",",
"method",
":",
"shrinker",
".",
"http_method",
",",
"body",
":",
"shrinker",
".",
"body_parameters",
"(",
"shrinker",
".",
"url",
")",
",",
"headers",
":",
"{",
"'Content-Type'",
"=>",
"shrinker",
".",
"content_type",
"}",
")",
".",
"run",
"end"
] |
Calls URL API
@see LinkShrink::Shrinkers::Base#api_url
@see LinkShrink::Shrinkers::Base#body_parameters
|
[
"Calls",
"URL",
"API"
] |
8ed842b4f004265e4e91693df72a4d8c49de3ea8
|
https://github.com/jonahoffline/link_shrink/blob/8ed842b4f004265e4e91693df72a4d8c49de3ea8/lib/link_shrink/request.rb#L47-L55
|
8,447
|
yaauie/implements
|
lib/implements/interface.rb
|
Implements.Interface.implementation
|
def implementation(*selectors)
selectors << :auto if selectors.empty?
Implementation::Registry::Finder.new(@implementations, selectors)
end
|
ruby
|
def implementation(*selectors)
selectors << :auto if selectors.empty?
Implementation::Registry::Finder.new(@implementations, selectors)
end
|
[
"def",
"implementation",
"(",
"*",
"selectors",
")",
"selectors",
"<<",
":auto",
"if",
"selectors",
".",
"empty?",
"Implementation",
"::",
"Registry",
"::",
"Finder",
".",
"new",
"(",
"@implementations",
",",
"selectors",
")",
"end"
] |
Used to find a suitable implementation
@api public
@param [*selectors] zero or more selectors to use for finding an
implementation of this interface. If none is given, :auto is assumed.
@return [Implementation::Registry::Finder]
|
[
"Used",
"to",
"find",
"a",
"suitable",
"implementation"
] |
27c698d283dbf71d04721b4cf4929d53b4a99cb7
|
https://github.com/yaauie/implements/blob/27c698d283dbf71d04721b4cf4929d53b4a99cb7/lib/implements/interface.rb#L11-L14
|
8,448
|
malmostad/siteseeker_normalizer
|
lib/siteseeker_normalizer/parse.rb
|
SiteseekerNormalizer.Parse.clean_up
|
def clean_up
@doc.css(".ess-separator").remove
@doc.css("@title").remove
@doc.css("@onclick").remove
@doc.css("@tabindex").remove
@doc.css(".ess-label-hits").remove
@doc.css(".ess-clear").remove
end
|
ruby
|
def clean_up
@doc.css(".ess-separator").remove
@doc.css("@title").remove
@doc.css("@onclick").remove
@doc.css("@tabindex").remove
@doc.css(".ess-label-hits").remove
@doc.css(".ess-clear").remove
end
|
[
"def",
"clean_up",
"@doc",
".",
"css",
"(",
"\".ess-separator\"",
")",
".",
"remove",
"@doc",
".",
"css",
"(",
"\"@title\"",
")",
".",
"remove",
"@doc",
".",
"css",
"(",
"\"@onclick\"",
")",
".",
"remove",
"@doc",
".",
"css",
"(",
"\"@tabindex\"",
")",
".",
"remove",
"@doc",
".",
"css",
"(",
"\".ess-label-hits\"",
")",
".",
"remove",
"@doc",
".",
"css",
"(",
"\".ess-clear\"",
")",
".",
"remove",
"end"
] |
Cleanup some crap
|
[
"Cleanup",
"some",
"crap"
] |
c5ed3a1edec7fb6c19e3ae87fc5960dd0ee9ef3d
|
https://github.com/malmostad/siteseeker_normalizer/blob/c5ed3a1edec7fb6c19e3ae87fc5960dd0ee9ef3d/lib/siteseeker_normalizer/parse.rb#L80-L87
|
8,449
|
mediasp/confuse
|
lib/confuse/key_splitter.rb
|
Confuse.KeySplitter.possible_namespaces
|
def possible_namespaces
namespaces = []
key = @key.to_s
while (index = key.rindex('_'))
key = key[0, index]
namespaces << key.to_sym
end
namespaces
end
|
ruby
|
def possible_namespaces
namespaces = []
key = @key.to_s
while (index = key.rindex('_'))
key = key[0, index]
namespaces << key.to_sym
end
namespaces
end
|
[
"def",
"possible_namespaces",
"namespaces",
"=",
"[",
"]",
"key",
"=",
"@key",
".",
"to_s",
"while",
"(",
"index",
"=",
"key",
".",
"rindex",
"(",
"'_'",
")",
")",
"key",
"=",
"key",
"[",
"0",
",",
"index",
"]",
"namespaces",
"<<",
"key",
".",
"to_sym",
"end",
"namespaces",
"end"
] |
Returns an array of possible namespaces based on splitting the key at
every underscore.
|
[
"Returns",
"an",
"array",
"of",
"possible",
"namespaces",
"based",
"on",
"splitting",
"the",
"key",
"at",
"every",
"underscore",
"."
] |
7e0e976d9461cd794b222305a24fa44946d6a9d3
|
https://github.com/mediasp/confuse/blob/7e0e976d9461cd794b222305a24fa44946d6a9d3/lib/confuse/key_splitter.rb#L20-L28
|
8,450
|
mediasp/confuse
|
lib/confuse/key_splitter.rb
|
Confuse.KeySplitter.rest_of_key
|
def rest_of_key(namespace)
return nil if @key == namespace
key = @key.to_s
index = key.index(namespace.to_s) && (namespace.to_s.length + 1)
key[index, key.length].to_sym if index
end
|
ruby
|
def rest_of_key(namespace)
return nil if @key == namespace
key = @key.to_s
index = key.index(namespace.to_s) && (namespace.to_s.length + 1)
key[index, key.length].to_sym if index
end
|
[
"def",
"rest_of_key",
"(",
"namespace",
")",
"return",
"nil",
"if",
"@key",
"==",
"namespace",
"key",
"=",
"@key",
".",
"to_s",
"index",
"=",
"key",
".",
"index",
"(",
"namespace",
".",
"to_s",
")",
"&&",
"(",
"namespace",
".",
"to_s",
".",
"length",
"+",
"1",
")",
"key",
"[",
"index",
",",
"key",
".",
"length",
"]",
".",
"to_sym",
"if",
"index",
"end"
] |
Returns the rest of the key for a given namespace
|
[
"Returns",
"the",
"rest",
"of",
"the",
"key",
"for",
"a",
"given",
"namespace"
] |
7e0e976d9461cd794b222305a24fa44946d6a9d3
|
https://github.com/mediasp/confuse/blob/7e0e976d9461cd794b222305a24fa44946d6a9d3/lib/confuse/key_splitter.rb#L31-L38
|
8,451
|
medcat/mixture
|
lib/mixture/attribute.rb
|
Mixture.Attribute.update
|
def update(value)
@list.callbacks[:update].inject(value) { |a, e| e.call(self, a) }
end
|
ruby
|
def update(value)
@list.callbacks[:update].inject(value) { |a, e| e.call(self, a) }
end
|
[
"def",
"update",
"(",
"value",
")",
"@list",
".",
"callbacks",
"[",
":update",
"]",
".",
"inject",
"(",
"value",
")",
"{",
"|",
"a",
",",
"e",
"|",
"e",
".",
"call",
"(",
"self",
",",
"a",
")",
"}",
"end"
] |
Initialize the attribute.
@param name [Symbol] The name of the attribute.
@param list [AttributeList] The attribute list this attribute is
a part of.
@param options [Hash] The optiosn for the attribute.
Update the attribute with the given value. It runs the value
through the callbacks, and returns a new value given by the
callbacks.
@param value [Object] The new value.
@return [Object] The new new value.
|
[
"Initialize",
"the",
"attribute",
"."
] |
8c59a57e07d495f678a0adefba7bcfc088195614
|
https://github.com/medcat/mixture/blob/8c59a57e07d495f678a0adefba7bcfc088195614/lib/mixture/attribute.rb#L36-L38
|
8,452
|
postmodern/ripl-shell_commands
|
lib/ripl/shell_commands.rb
|
Ripl.ShellCommands.loop_eval
|
def loop_eval(input)
if (@buffer.nil? && input =~ PATTERN)
command = input[1..-1]
name, arguments = ShellCommands.parse(command)
unless BLACKLIST.include?(name)
if BUILTIN.include?(name)
arguments ||= []
return ShellCommands.send(name,*arguments)
elsif EXECUTABLES[name]
return ShellCommands.exec(name,*arguments)
end
end
end
super(input)
end
|
ruby
|
def loop_eval(input)
if (@buffer.nil? && input =~ PATTERN)
command = input[1..-1]
name, arguments = ShellCommands.parse(command)
unless BLACKLIST.include?(name)
if BUILTIN.include?(name)
arguments ||= []
return ShellCommands.send(name,*arguments)
elsif EXECUTABLES[name]
return ShellCommands.exec(name,*arguments)
end
end
end
super(input)
end
|
[
"def",
"loop_eval",
"(",
"input",
")",
"if",
"(",
"@buffer",
".",
"nil?",
"&&",
"input",
"=~",
"PATTERN",
")",
"command",
"=",
"input",
"[",
"1",
"..",
"-",
"1",
"]",
"name",
",",
"arguments",
"=",
"ShellCommands",
".",
"parse",
"(",
"command",
")",
"unless",
"BLACKLIST",
".",
"include?",
"(",
"name",
")",
"if",
"BUILTIN",
".",
"include?",
"(",
"name",
")",
"arguments",
"||=",
"[",
"]",
"return",
"ShellCommands",
".",
"send",
"(",
"name",
",",
"arguments",
")",
"elsif",
"EXECUTABLES",
"[",
"name",
"]",
"return",
"ShellCommands",
".",
"exec",
"(",
"name",
",",
"arguments",
")",
"end",
"end",
"end",
"super",
"(",
"input",
")",
"end"
] |
Dynamically execute shell commands, instead of Ruby.
@param [String] input
The input from the console.
|
[
"Dynamically",
"execute",
"shell",
"commands",
"instead",
"of",
"Ruby",
"."
] |
56bdca61921229af02f4699fa67fb84a78252099
|
https://github.com/postmodern/ripl-shell_commands/blob/56bdca61921229af02f4699fa67fb84a78252099/lib/ripl/shell_commands.rb#L40-L57
|
8,453
|
iv-mexx/git-releaselog
|
lib/git-releaselog/changelog.rb
|
Releaselog.Changelog.section
|
def section(section_changes, header, entry_style, header_style = nil)
return "" unless section_changes.size > 0
str = ""
unless header.empty?
if header_style
str << header_style.call(header)
else
str << header
end
end
section_changes.each_with_index do |e, i|
str << entry_style.call(e, i)
end
str
end
|
ruby
|
def section(section_changes, header, entry_style, header_style = nil)
return "" unless section_changes.size > 0
str = ""
unless header.empty?
if header_style
str << header_style.call(header)
else
str << header
end
end
section_changes.each_with_index do |e, i|
str << entry_style.call(e, i)
end
str
end
|
[
"def",
"section",
"(",
"section_changes",
",",
"header",
",",
"entry_style",
",",
"header_style",
"=",
"nil",
")",
"return",
"\"\"",
"unless",
"section_changes",
".",
"size",
">",
"0",
"str",
"=",
"\"\"",
"unless",
"header",
".",
"empty?",
"if",
"header_style",
"str",
"<<",
"header_style",
".",
"call",
"(",
"header",
")",
"else",
"str",
"<<",
"header",
"end",
"end",
"section_changes",
".",
"each_with_index",
"do",
"|",
"e",
",",
"i",
"|",
"str",
"<<",
"entry_style",
".",
"call",
"(",
"e",
",",
"i",
")",
"end",
"str",
"end"
] |
Format a specific section.
section_changes ... changes in the format of { section_1: [changes...], section_2: [changes...]}
header ... header of the section
entry_style ... is called for styling each item of a section
header_style ... optional, since styled header can be passed directly; is called for styling the header of the section
|
[
"Format",
"a",
"specific",
"section",
"."
] |
393d5d9b12f9dd808ccb2d13ab0ada12d72d2849
|
https://github.com/iv-mexx/git-releaselog/blob/393d5d9b12f9dd808ccb2d13ab0ada12d72d2849/lib/git-releaselog/changelog.rb#L70-L86
|
8,454
|
iv-mexx/git-releaselog
|
lib/git-releaselog/changelog.rb
|
Releaselog.Changelog.to_slack
|
def to_slack
str = ""
str << tag_info { |t| t }
str << commit_info { |ci| ci.empty? ? "" : "(_#{ci}_)\n" }
str << sections(
changes,
-> (header) { "*#{header.capitalize}*\n" },
-> (field, _index) { "\t- #{field}\n" }
)
str
end
|
ruby
|
def to_slack
str = ""
str << tag_info { |t| t }
str << commit_info { |ci| ci.empty? ? "" : "(_#{ci}_)\n" }
str << sections(
changes,
-> (header) { "*#{header.capitalize}*\n" },
-> (field, _index) { "\t- #{field}\n" }
)
str
end
|
[
"def",
"to_slack",
"str",
"=",
"\"\"",
"str",
"<<",
"tag_info",
"{",
"|",
"t",
"|",
"t",
"}",
"str",
"<<",
"commit_info",
"{",
"|",
"ci",
"|",
"ci",
".",
"empty?",
"?",
"\"\"",
":",
"\"(_#{ci}_)\\n\"",
"}",
"str",
"<<",
"sections",
"(",
"changes",
",",
"->",
"(",
"header",
")",
"{",
"\"*#{header.capitalize}*\\n\"",
"}",
",",
"->",
"(",
"field",
",",
"_index",
")",
"{",
"\"\\t- #{field}\\n\"",
"}",
")",
"str",
"end"
] |
Render the Changelog with Slack Formatting
|
[
"Render",
"the",
"Changelog",
"with",
"Slack",
"Formatting"
] |
393d5d9b12f9dd808ccb2d13ab0ada12d72d2849
|
https://github.com/iv-mexx/git-releaselog/blob/393d5d9b12f9dd808ccb2d13ab0ada12d72d2849/lib/git-releaselog/changelog.rb#L89-L101
|
8,455
|
chetan/bixby-common
|
lib/bixby-common/util/thread_pool.rb
|
Bixby.ThreadPool.grow
|
def grow
@lock.synchronize do
prune
logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
if @size == 0 || (@size < @max_size && num_jobs > 0 && num_jobs > num_idle) then
space = @max_size-@size
jobs = num_jobs-num_idle
needed = space < jobs ? space : jobs
needed = 1 if needed <= 0
expand(needed)
else
logger.debug "NOT growing the pool!"
end
end
nil
end
|
ruby
|
def grow
@lock.synchronize do
prune
logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
if @size == 0 || (@size < @max_size && num_jobs > 0 && num_jobs > num_idle) then
space = @max_size-@size
jobs = num_jobs-num_idle
needed = space < jobs ? space : jobs
needed = 1 if needed <= 0
expand(needed)
else
logger.debug "NOT growing the pool!"
end
end
nil
end
|
[
"def",
"grow",
"@lock",
".",
"synchronize",
"do",
"prune",
"logger",
".",
"debug",
"{",
"\"jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}\"",
"}",
"if",
"@size",
"==",
"0",
"||",
"(",
"@size",
"<",
"@max_size",
"&&",
"num_jobs",
">",
"0",
"&&",
"num_jobs",
">",
"num_idle",
")",
"then",
"space",
"=",
"@max_size",
"-",
"@size",
"jobs",
"=",
"num_jobs",
"-",
"num_idle",
"needed",
"=",
"space",
"<",
"jobs",
"?",
"space",
":",
"jobs",
"needed",
"=",
"1",
"if",
"needed",
"<=",
"0",
"expand",
"(",
"needed",
")",
"else",
"logger",
".",
"debug",
"\"NOT growing the pool!\"",
"end",
"end",
"nil",
"end"
] |
Grow the pool by one if we have more jobs than idle workers
|
[
"Grow",
"the",
"pool",
"by",
"one",
"if",
"we",
"have",
"more",
"jobs",
"than",
"idle",
"workers"
] |
3fb8829987b115fc53ec820d97a20b4a8c49b4a2
|
https://github.com/chetan/bixby-common/blob/3fb8829987b115fc53ec820d97a20b4a8c49b4a2/lib/bixby-common/util/thread_pool.rb#L181-L197
|
8,456
|
zpatten/ztk
|
lib/ztk/config.rb
|
ZTK.Config.method_missing
|
def method_missing(method_symbol, *method_args)
if method_args.length > 0
_set(method_symbol, method_args.first)
end
_get(method_symbol)
end
|
ruby
|
def method_missing(method_symbol, *method_args)
if method_args.length > 0
_set(method_symbol, method_args.first)
end
_get(method_symbol)
end
|
[
"def",
"method_missing",
"(",
"method_symbol",
",",
"*",
"method_args",
")",
"if",
"method_args",
".",
"length",
">",
"0",
"_set",
"(",
"method_symbol",
",",
"method_args",
".",
"first",
")",
"end",
"_get",
"(",
"method_symbol",
")",
"end"
] |
Handles method calls for our configuration keys.
|
[
"Handles",
"method",
"calls",
"for",
"our",
"configuration",
"keys",
"."
] |
9b0f35bef36f38428e1a57b36f25a806c240b3fb
|
https://github.com/zpatten/ztk/blob/9b0f35bef36f38428e1a57b36f25a806c240b3fb/lib/ztk/config.rb#L127-L133
|
8,457
|
SpeciesFileGroup/taxonifi
|
lib/taxonifi/export/format/base.rb
|
Taxonifi::Export.Base.write_file
|
def write_file(filename = 'foo', string = nil)
raise ExportError, 'Nothing to export for #{filename}.' if string.nil? || string == ""
f = File.new( File.expand_path(File.join(export_path, filename)), 'w+')
f.puts string
f.close
end
|
ruby
|
def write_file(filename = 'foo', string = nil)
raise ExportError, 'Nothing to export for #{filename}.' if string.nil? || string == ""
f = File.new( File.expand_path(File.join(export_path, filename)), 'w+')
f.puts string
f.close
end
|
[
"def",
"write_file",
"(",
"filename",
"=",
"'foo'",
",",
"string",
"=",
"nil",
")",
"raise",
"ExportError",
",",
"'Nothing to export for #{filename}.'",
"if",
"string",
".",
"nil?",
"||",
"string",
"==",
"\"\"",
"f",
"=",
"File",
".",
"new",
"(",
"File",
".",
"expand_path",
"(",
"File",
".",
"join",
"(",
"export_path",
",",
"filename",
")",
")",
",",
"'w+'",
")",
"f",
".",
"puts",
"string",
"f",
".",
"close",
"end"
] |
Write the string to a file in the export path.
|
[
"Write",
"the",
"string",
"to",
"a",
"file",
"in",
"the",
"export",
"path",
"."
] |
100dc94e7ffd378f6a81381c13768e35b2b65bf2
|
https://github.com/SpeciesFileGroup/taxonifi/blob/100dc94e7ffd378f6a81381c13768e35b2b65bf2/lib/taxonifi/export/format/base.rb#L99-L104
|
8,458
|
ebfjunior/juno-report
|
lib/juno-report/pdf.rb
|
JunoReport.Pdf.new_page
|
def new_page
@pdf.start_new_page
set_pos_y
print_section :page unless @sections[:page].nil?
set_pos_y (@sections[:body][:settings][:posY] || 0)
@current_groups.each do |field, value|
print_section field.to_sym, @record, true
end
draw_columns
end
|
ruby
|
def new_page
@pdf.start_new_page
set_pos_y
print_section :page unless @sections[:page].nil?
set_pos_y (@sections[:body][:settings][:posY] || 0)
@current_groups.each do |field, value|
print_section field.to_sym, @record, true
end
draw_columns
end
|
[
"def",
"new_page",
"@pdf",
".",
"start_new_page",
"set_pos_y",
"print_section",
":page",
"unless",
"@sections",
"[",
":page",
"]",
".",
"nil?",
"set_pos_y",
"(",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":posY",
"]",
"||",
"0",
")",
"@current_groups",
".",
"each",
"do",
"|",
"field",
",",
"value",
"|",
"print_section",
"field",
".",
"to_sym",
",",
"@record",
",",
"true",
"end",
"draw_columns",
"end"
] |
Creates a new page, restarting the vertical position of the pointer.
Print the whole header for the current groups and the columns of the report.
|
[
"Creates",
"a",
"new",
"page",
"restarting",
"the",
"vertical",
"position",
"of",
"the",
"pointer",
".",
"Print",
"the",
"whole",
"header",
"for",
"the",
"current",
"groups",
"and",
"the",
"columns",
"of",
"the",
"report",
"."
] |
139f2a1733e0d7a68160b338cc1a4645f05d5953
|
https://github.com/ebfjunior/juno-report/blob/139f2a1733e0d7a68160b338cc1a4645f05d5953/lib/juno-report/pdf.rb#L72-L81
|
8,459
|
ebfjunior/juno-report
|
lib/juno-report/pdf.rb
|
JunoReport.Pdf.symbolize!
|
def symbolize! hash
hash.symbolize_keys!
hash.values.select{|v| v.is_a? Hash}.each{|h| symbolize!(h)}
end
|
ruby
|
def symbolize! hash
hash.symbolize_keys!
hash.values.select{|v| v.is_a? Hash}.each{|h| symbolize!(h)}
end
|
[
"def",
"symbolize!",
"hash",
"hash",
".",
"symbolize_keys!",
"hash",
".",
"values",
".",
"select",
"{",
"|",
"v",
"|",
"v",
".",
"is_a?",
"Hash",
"}",
".",
"each",
"{",
"|",
"h",
"|",
"symbolize!",
"(",
"h",
")",
"}",
"end"
] |
Convert to symbol all hash keys, recursively.
|
[
"Convert",
"to",
"symbol",
"all",
"hash",
"keys",
"recursively",
"."
] |
139f2a1733e0d7a68160b338cc1a4645f05d5953
|
https://github.com/ebfjunior/juno-report/blob/139f2a1733e0d7a68160b338cc1a4645f05d5953/lib/juno-report/pdf.rb#L149-L152
|
8,460
|
ebfjunior/juno-report
|
lib/juno-report/pdf.rb
|
JunoReport.Pdf.get_sections
|
def get_sections
symbolize! @rules
raise "[body] section on YAML file is needed to generate the report." if @rules[:body].nil?
@sections = {:page => @rules[:page], :body => @rules[:body], :defaults => @rules[:defaults], :groups => {}}
@sections[:body][:settings][:groups].each { |group| @sections[:groups][group.to_sym] = @rules[group.to_sym] } if has_groups?
end
|
ruby
|
def get_sections
symbolize! @rules
raise "[body] section on YAML file is needed to generate the report." if @rules[:body].nil?
@sections = {:page => @rules[:page], :body => @rules[:body], :defaults => @rules[:defaults], :groups => {}}
@sections[:body][:settings][:groups].each { |group| @sections[:groups][group.to_sym] = @rules[group.to_sym] } if has_groups?
end
|
[
"def",
"get_sections",
"symbolize!",
"@rules",
"raise",
"\"[body] section on YAML file is needed to generate the report.\"",
"if",
"@rules",
"[",
":body",
"]",
".",
"nil?",
"@sections",
"=",
"{",
":page",
"=>",
"@rules",
"[",
":page",
"]",
",",
":body",
"=>",
"@rules",
"[",
":body",
"]",
",",
":defaults",
"=>",
"@rules",
"[",
":defaults",
"]",
",",
":groups",
"=>",
"{",
"}",
"}",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":groups",
"]",
".",
"each",
"{",
"|",
"group",
"|",
"@sections",
"[",
":groups",
"]",
"[",
"group",
".",
"to_sym",
"]",
"=",
"@rules",
"[",
"group",
".",
"to_sym",
"]",
"}",
"if",
"has_groups?",
"end"
] |
Convert the structure of the rules to facilitate the generating proccess.
|
[
"Convert",
"the",
"structure",
"of",
"the",
"rules",
"to",
"facilitate",
"the",
"generating",
"proccess",
"."
] |
139f2a1733e0d7a68160b338cc1a4645f05d5953
|
https://github.com/ebfjunior/juno-report/blob/139f2a1733e0d7a68160b338cc1a4645f05d5953/lib/juno-report/pdf.rb#L155-L160
|
8,461
|
ebfjunior/juno-report
|
lib/juno-report/pdf.rb
|
JunoReport.Pdf.initialize_footer_values
|
def initialize_footer_values
@sections[:body][:settings][:groups].each do |group|
current_footer = {}
@sections[:groups][group.to_sym][:footer].each { |field, settings| current_footer[field] = nil } unless @sections[:groups][group.to_sym][:footer].nil?
@footers[group.to_sym] = current_footer unless current_footer.empty?
end if has_groups?
raise "The report must have at least a footer on body section" if @sections[:body][:footer].nil?
current_footer = {}
@sections[:body][:footer].each { |field, settings| current_footer[field] = nil }
@footers[:body] = current_footer unless current_footer.empty?
end
|
ruby
|
def initialize_footer_values
@sections[:body][:settings][:groups].each do |group|
current_footer = {}
@sections[:groups][group.to_sym][:footer].each { |field, settings| current_footer[field] = nil } unless @sections[:groups][group.to_sym][:footer].nil?
@footers[group.to_sym] = current_footer unless current_footer.empty?
end if has_groups?
raise "The report must have at least a footer on body section" if @sections[:body][:footer].nil?
current_footer = {}
@sections[:body][:footer].each { |field, settings| current_footer[field] = nil }
@footers[:body] = current_footer unless current_footer.empty?
end
|
[
"def",
"initialize_footer_values",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":groups",
"]",
".",
"each",
"do",
"|",
"group",
"|",
"current_footer",
"=",
"{",
"}",
"@sections",
"[",
":groups",
"]",
"[",
"group",
".",
"to_sym",
"]",
"[",
":footer",
"]",
".",
"each",
"{",
"|",
"field",
",",
"settings",
"|",
"current_footer",
"[",
"field",
"]",
"=",
"nil",
"}",
"unless",
"@sections",
"[",
":groups",
"]",
"[",
"group",
".",
"to_sym",
"]",
"[",
":footer",
"]",
".",
"nil?",
"@footers",
"[",
"group",
".",
"to_sym",
"]",
"=",
"current_footer",
"unless",
"current_footer",
".",
"empty?",
"end",
"if",
"has_groups?",
"raise",
"\"The report must have at least a footer on body section\"",
"if",
"@sections",
"[",
":body",
"]",
"[",
":footer",
"]",
".",
"nil?",
"current_footer",
"=",
"{",
"}",
"@sections",
"[",
":body",
"]",
"[",
":footer",
"]",
".",
"each",
"{",
"|",
"field",
",",
"settings",
"|",
"current_footer",
"[",
"field",
"]",
"=",
"nil",
"}",
"@footers",
"[",
":body",
"]",
"=",
"current_footer",
"unless",
"current_footer",
".",
"empty?",
"end"
] |
Create a structure to calculate the footer values for all groups. Appends the footer body to total values too.
|
[
"Create",
"a",
"structure",
"to",
"calculate",
"the",
"footer",
"values",
"for",
"all",
"groups",
".",
"Appends",
"the",
"footer",
"body",
"to",
"total",
"values",
"too",
"."
] |
139f2a1733e0d7a68160b338cc1a4645f05d5953
|
https://github.com/ebfjunior/juno-report/blob/139f2a1733e0d7a68160b338cc1a4645f05d5953/lib/juno-report/pdf.rb#L197-L207
|
8,462
|
ebfjunior/juno-report
|
lib/juno-report/pdf.rb
|
JunoReport.Pdf.draw_footer
|
def draw_footer footers_to_print, source
footers_to_print.reverse_each do |group|
draw_line(@posY + @sections[:body][:settings][:height]/2)
source[group][:footer].each do |field, settings|
settings = [settings[0], @posY, (@defaults.merge (settings[1] || { }).symbolize_keys!)]
settings[2][:style] = settings[2][:style].to_sym
set_options settings[2]
draw_text @footers[group][field], settings
end
draw_line(@posY - @sections[:body][:settings][:height]/4)
set_pos_y @sections[:body][:settings][:height]
reset_footer group
end
end
|
ruby
|
def draw_footer footers_to_print, source
footers_to_print.reverse_each do |group|
draw_line(@posY + @sections[:body][:settings][:height]/2)
source[group][:footer].each do |field, settings|
settings = [settings[0], @posY, (@defaults.merge (settings[1] || { }).symbolize_keys!)]
settings[2][:style] = settings[2][:style].to_sym
set_options settings[2]
draw_text @footers[group][field], settings
end
draw_line(@posY - @sections[:body][:settings][:height]/4)
set_pos_y @sections[:body][:settings][:height]
reset_footer group
end
end
|
[
"def",
"draw_footer",
"footers_to_print",
",",
"source",
"footers_to_print",
".",
"reverse_each",
"do",
"|",
"group",
"|",
"draw_line",
"(",
"@posY",
"+",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":height",
"]",
"/",
"2",
")",
"source",
"[",
"group",
"]",
"[",
":footer",
"]",
".",
"each",
"do",
"|",
"field",
",",
"settings",
"|",
"settings",
"=",
"[",
"settings",
"[",
"0",
"]",
",",
"@posY",
",",
"(",
"@defaults",
".",
"merge",
"(",
"settings",
"[",
"1",
"]",
"||",
"{",
"}",
")",
".",
"symbolize_keys!",
")",
"]",
"settings",
"[",
"2",
"]",
"[",
":style",
"]",
"=",
"settings",
"[",
"2",
"]",
"[",
":style",
"]",
".",
"to_sym",
"set_options",
"settings",
"[",
"2",
"]",
"draw_text",
"@footers",
"[",
"group",
"]",
"[",
"field",
"]",
",",
"settings",
"end",
"draw_line",
"(",
"@posY",
"-",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":height",
"]",
"/",
"4",
")",
"set_pos_y",
"@sections",
"[",
":body",
"]",
"[",
":settings",
"]",
"[",
":height",
"]",
"reset_footer",
"group",
"end",
"end"
] |
Print the footers according to the groups and source specified
|
[
"Print",
"the",
"footers",
"according",
"to",
"the",
"groups",
"and",
"source",
"specified"
] |
139f2a1733e0d7a68160b338cc1a4645f05d5953
|
https://github.com/ebfjunior/juno-report/blob/139f2a1733e0d7a68160b338cc1a4645f05d5953/lib/juno-report/pdf.rb#L239-L253
|
8,463
|
jeremyz/edoors-ruby
|
lib/edoors/spin.rb
|
Edoors.Spin.release_p
|
def release_p p
# hope there is no circular loop
while p2=p.merged_shift
release_p p2
end
p.reset!
( @pool[p.class] ||= [] ) << p
end
|
ruby
|
def release_p p
# hope there is no circular loop
while p2=p.merged_shift
release_p p2
end
p.reset!
( @pool[p.class] ||= [] ) << p
end
|
[
"def",
"release_p",
"p",
"# hope there is no circular loop",
"while",
"p2",
"=",
"p",
".",
"merged_shift",
"release_p",
"p2",
"end",
"p",
".",
"reset!",
"(",
"@pool",
"[",
"p",
".",
"class",
"]",
"||=",
"[",
"]",
")",
"<<",
"p",
"end"
] |
releases the given Particle
@parama [Particle] p the Particle to be released
@note the Particle is stored into Hash @pool to be reused as soon as needed
@see Particle#reset! the Particle is reseted before beeing stored
|
[
"releases",
"the",
"given",
"Particle"
] |
4f065f63125907b3a4f72fbab8722c58ccab41c1
|
https://github.com/jeremyz/edoors-ruby/blob/4f065f63125907b3a4f72fbab8722c58ccab41c1/lib/edoors/spin.rb#L150-L157
|
8,464
|
jeremyz/edoors-ruby
|
lib/edoors/spin.rb
|
Edoors.Spin.require_p
|
def require_p p_kls
l = @pool[p_kls]
return p_kls.new if l.nil?
p = l.pop
return p_kls.new if p.nil?
p
end
|
ruby
|
def require_p p_kls
l = @pool[p_kls]
return p_kls.new if l.nil?
p = l.pop
return p_kls.new if p.nil?
p
end
|
[
"def",
"require_p",
"p_kls",
"l",
"=",
"@pool",
"[",
"p_kls",
"]",
"return",
"p_kls",
".",
"new",
"if",
"l",
".",
"nil?",
"p",
"=",
"l",
".",
"pop",
"return",
"p_kls",
".",
"new",
"if",
"p",
".",
"nil?",
"p",
"end"
] |
requires a Particle of the given Class
@param [Class] p_kls the desired Class of Particle
@note if there is no Particle of the given Class, one is created
|
[
"requires",
"a",
"Particle",
"of",
"the",
"given",
"Class"
] |
4f065f63125907b3a4f72fbab8722c58ccab41c1
|
https://github.com/jeremyz/edoors-ruby/blob/4f065f63125907b3a4f72fbab8722c58ccab41c1/lib/edoors/spin.rb#L165-L171
|
8,465
|
jeremyz/edoors-ruby
|
lib/edoors/spin.rb
|
Edoors.Spin.process_sys_p
|
def process_sys_p p
if p.action==Edoors::SYS_ACT_HIBERNATE
stop!
hibernate! p[FIELD_HIBERNATE_PATH]
else
super p
end
end
|
ruby
|
def process_sys_p p
if p.action==Edoors::SYS_ACT_HIBERNATE
stop!
hibernate! p[FIELD_HIBERNATE_PATH]
else
super p
end
end
|
[
"def",
"process_sys_p",
"p",
"if",
"p",
".",
"action",
"==",
"Edoors",
"::",
"SYS_ACT_HIBERNATE",
"stop!",
"hibernate!",
"p",
"[",
"FIELD_HIBERNATE_PATH",
"]",
"else",
"super",
"p",
"end",
"end"
] |
process the given particle
@param [Particle] p the Particle to be processed
|
[
"process",
"the",
"given",
"particle"
] |
4f065f63125907b3a4f72fbab8722c58ccab41c1
|
https://github.com/jeremyz/edoors-ruby/blob/4f065f63125907b3a4f72fbab8722c58ccab41c1/lib/edoors/spin.rb#L193-L200
|
8,466
|
jeremyz/edoors-ruby
|
lib/edoors/spin.rb
|
Edoors.Spin.spin!
|
def spin!
start!
@run = true
@hibernation = false
while @run and (@sys_fifo.length>0 or @app_fifo.length>0)
while @run and @sys_fifo.length>0
p = @sys_fifo.shift
p.dst.process_sys_p p
end
while @run and @app_fifo.length>0
p = @app_fifo.shift
p.dst.process_p p
break
end
end
stop!
end
|
ruby
|
def spin!
start!
@run = true
@hibernation = false
while @run and (@sys_fifo.length>0 or @app_fifo.length>0)
while @run and @sys_fifo.length>0
p = @sys_fifo.shift
p.dst.process_sys_p p
end
while @run and @app_fifo.length>0
p = @app_fifo.shift
p.dst.process_p p
break
end
end
stop!
end
|
[
"def",
"spin!",
"start!",
"@run",
"=",
"true",
"@hibernation",
"=",
"false",
"while",
"@run",
"and",
"(",
"@sys_fifo",
".",
"length",
">",
"0",
"or",
"@app_fifo",
".",
"length",
">",
"0",
")",
"while",
"@run",
"and",
"@sys_fifo",
".",
"length",
">",
"0",
"p",
"=",
"@sys_fifo",
".",
"shift",
"p",
".",
"dst",
".",
"process_sys_p",
"p",
"end",
"while",
"@run",
"and",
"@app_fifo",
".",
"length",
">",
"0",
"p",
"=",
"@app_fifo",
".",
"shift",
"p",
".",
"dst",
".",
"process_p",
"p",
"break",
"end",
"end",
"stop!",
"end"
] |
starts the system mainloop
first Iota#start! is called on each children unless the system is resuming from hibernation
then while there is Particle in the fifo, first process all system Particle then 1 application Particle
after all Iota#stop! is called on each children, unless the system is going into hibernation
|
[
"starts",
"the",
"system",
"mainloop"
] |
4f065f63125907b3a4f72fbab8722c58ccab41c1
|
https://github.com/jeremyz/edoors-ruby/blob/4f065f63125907b3a4f72fbab8722c58ccab41c1/lib/edoors/spin.rb#L208-L224
|
8,467
|
jeremyz/edoors-ruby
|
lib/edoors/spin.rb
|
Edoors.Spin.hibernate!
|
def hibernate! path=nil
@hibernation = true
File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end
end
|
ruby
|
def hibernate! path=nil
@hibernation = true
File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end
end
|
[
"def",
"hibernate!",
"path",
"=",
"nil",
"@hibernation",
"=",
"true",
"File",
".",
"open",
"(",
"path",
"||",
"@hibernate_path",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
"<<",
"JSON",
".",
"pretty_generate",
"(",
"self",
")",
"end",
"end"
] |
sends the system into hibernation
@param [String] path the path to the hibernation file
the system is serialized into JSON data and flushed to disk
|
[
"sends",
"the",
"system",
"into",
"hibernation"
] |
4f065f63125907b3a4f72fbab8722c58ccab41c1
|
https://github.com/jeremyz/edoors-ruby/blob/4f065f63125907b3a4f72fbab8722c58ccab41c1/lib/edoors/spin.rb#L238-L241
|
8,468
|
loveablelobster/DwCR
|
lib/dwca_content_analyzer/column.rb
|
DwCAContentAnalyzer.Column.collapse
|
def collapse(types)
return types.first if types.size == 1
return nil if types.empty?
return String if string?(types)
return Float if float?(types)
String
end
|
ruby
|
def collapse(types)
return types.first if types.size == 1
return nil if types.empty?
return String if string?(types)
return Float if float?(types)
String
end
|
[
"def",
"collapse",
"(",
"types",
")",
"return",
"types",
".",
"first",
"if",
"types",
".",
"size",
"==",
"1",
"return",
"nil",
"if",
"types",
".",
"empty?",
"return",
"String",
"if",
"string?",
"(",
"types",
")",
"return",
"Float",
"if",
"float?",
"(",
"types",
")",
"String",
"end"
] |
collapses all types encountered in a file's column into a single type
|
[
"collapses",
"all",
"types",
"encountered",
"in",
"a",
"file",
"s",
"column",
"into",
"a",
"single",
"type"
] |
093e112337bfb664630a0f164c9d9d7552b1e54c
|
https://github.com/loveablelobster/DwCR/blob/093e112337bfb664630a0f164c9d9d7552b1e54c/lib/dwca_content_analyzer/column.rb#L29-L35
|
8,469
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.remote_a
|
def remote_a
return unless @page_a_tags
remote_a = []
@page_a_tags.uniq.each do |link|
uri = URI(link[0].to_ascii)
if uri && @site_domain
remote_a << link[0] unless uri.host == @site_domain
end
end
remote_a
end
|
ruby
|
def remote_a
return unless @page_a_tags
remote_a = []
@page_a_tags.uniq.each do |link|
uri = URI(link[0].to_ascii)
if uri && @site_domain
remote_a << link[0] unless uri.host == @site_domain
end
end
remote_a
end
|
[
"def",
"remote_a",
"return",
"unless",
"@page_a_tags",
"remote_a",
"=",
"[",
"]",
"@page_a_tags",
".",
"uniq",
".",
"each",
"do",
"|",
"link",
"|",
"uri",
"=",
"URI",
"(",
"link",
"[",
"0",
"]",
".",
"to_ascii",
")",
"if",
"uri",
"&&",
"@site_domain",
"remote_a",
"<<",
"link",
"[",
"0",
"]",
"unless",
"uri",
".",
"host",
"==",
"@site_domain",
"end",
"end",
"remote_a",
"end"
] |
get all remote link on page
|
[
"get",
"all",
"remote",
"link",
"on",
"page"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L37-L47
|
8,470
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.fill_data_field!
|
def fill_data_field!
@all_titles = titles
@meta_data = collect_metadates
@title_h1_h2 = all_titles_h1_h2
@page_text_size = text_size
@page_a_tags = all_a_tags
@meta_desc_content = all_meta_description_content
@h2_text = h2
@hlu = bad_url
@title_good = title_good?
@title_and_h1_good = title_and_h1_good?
@meta_description_good = metadescription_good?
@meta_keywords = keywords_good?
@code_less = code_less?
@meta_title_duplicates = metadates_good?
@have_h2 = h2?
end
|
ruby
|
def fill_data_field!
@all_titles = titles
@meta_data = collect_metadates
@title_h1_h2 = all_titles_h1_h2
@page_text_size = text_size
@page_a_tags = all_a_tags
@meta_desc_content = all_meta_description_content
@h2_text = h2
@hlu = bad_url
@title_good = title_good?
@title_and_h1_good = title_and_h1_good?
@meta_description_good = metadescription_good?
@meta_keywords = keywords_good?
@code_less = code_less?
@meta_title_duplicates = metadates_good?
@have_h2 = h2?
end
|
[
"def",
"fill_data_field!",
"@all_titles",
"=",
"titles",
"@meta_data",
"=",
"collect_metadates",
"@title_h1_h2",
"=",
"all_titles_h1_h2",
"@page_text_size",
"=",
"text_size",
"@page_a_tags",
"=",
"all_a_tags",
"@meta_desc_content",
"=",
"all_meta_description_content",
"@h2_text",
"=",
"h2",
"@hlu",
"=",
"bad_url",
"@title_good",
"=",
"title_good?",
"@title_and_h1_good",
"=",
"title_and_h1_good?",
"@meta_description_good",
"=",
"metadescription_good?",
"@meta_keywords",
"=",
"keywords_good?",
"@code_less",
"=",
"code_less?",
"@meta_title_duplicates",
"=",
"metadates_good?",
"@have_h2",
"=",
"h2?",
"end"
] |
fill Page instant with data for report
|
[
"fill",
"Page",
"instant",
"with",
"data",
"for",
"report"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L52-L68
|
8,471
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.get_page
|
def get_page(url)
timeout(30) do
page = open(url)
@site_domain = page.base_uri.host
@page_path = page.base_uri.request_uri
@page = Nokogiri::HTML(page)
end
rescue Timeout::Error, EOFError, OpenURI::HTTPError, Errno::ENOENT, TypeError
return nil
end
|
ruby
|
def get_page(url)
timeout(30) do
page = open(url)
@site_domain = page.base_uri.host
@page_path = page.base_uri.request_uri
@page = Nokogiri::HTML(page)
end
rescue Timeout::Error, EOFError, OpenURI::HTTPError, Errno::ENOENT, TypeError
return nil
end
|
[
"def",
"get_page",
"(",
"url",
")",
"timeout",
"(",
"30",
")",
"do",
"page",
"=",
"open",
"(",
"url",
")",
"@site_domain",
"=",
"page",
".",
"base_uri",
".",
"host",
"@page_path",
"=",
"page",
".",
"base_uri",
".",
"request_uri",
"@page",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"page",
")",
"end",
"rescue",
"Timeout",
"::",
"Error",
",",
"EOFError",
",",
"OpenURI",
"::",
"HTTPError",
",",
"Errno",
"::",
"ENOENT",
",",
"TypeError",
"return",
"nil",
"end"
] |
get page with open-uri, then parse it with Nokogiri. Get site domain and path from URI
|
[
"get",
"page",
"with",
"open",
"-",
"uri",
"then",
"parse",
"it",
"with",
"Nokogiri",
".",
"Get",
"site",
"domain",
"and",
"path",
"from",
"URI"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L70-L79
|
8,472
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.title_and_h1_good?
|
def title_and_h1_good?
return unless @page
arr = []
@page.css('h1').each { |node| arr << node.text }
@page.css('title').size == 1 && arr.uniq.size == arr.size
end
|
ruby
|
def title_and_h1_good?
return unless @page
arr = []
@page.css('h1').each { |node| arr << node.text }
@page.css('title').size == 1 && arr.uniq.size == arr.size
end
|
[
"def",
"title_and_h1_good?",
"return",
"unless",
"@page",
"arr",
"=",
"[",
"]",
"@page",
".",
"css",
"(",
"'h1'",
")",
".",
"each",
"{",
"|",
"node",
"|",
"arr",
"<<",
"node",
".",
"text",
"}",
"@page",
".",
"css",
"(",
"'title'",
")",
".",
"size",
"==",
"1",
"&&",
"arr",
".",
"uniq",
".",
"size",
"==",
"arr",
".",
"size",
"end"
] |
true if title and h1 have no duplicates
|
[
"true",
"if",
"title",
"and",
"h1",
"have",
"no",
"duplicates"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L85-L90
|
8,473
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.metadescription_good?
|
def metadescription_good?
return unless @page
tags = @page.css("meta[name='description']")
return false if tags.size == 0
tags.each do |t|
unless t['value'].nil?
return false if t['content'].size == 0 || t['content'].size > 200
end
end
true
end
|
ruby
|
def metadescription_good?
return unless @page
tags = @page.css("meta[name='description']")
return false if tags.size == 0
tags.each do |t|
unless t['value'].nil?
return false if t['content'].size == 0 || t['content'].size > 200
end
end
true
end
|
[
"def",
"metadescription_good?",
"return",
"unless",
"@page",
"tags",
"=",
"@page",
".",
"css",
"(",
"\"meta[name='description']\"",
")",
"return",
"false",
"if",
"tags",
".",
"size",
"==",
"0",
"tags",
".",
"each",
"do",
"|",
"t",
"|",
"unless",
"t",
"[",
"'value'",
"]",
".",
"nil?",
"return",
"false",
"if",
"t",
"[",
"'content'",
"]",
".",
"size",
"==",
"0",
"||",
"t",
"[",
"'content'",
"]",
".",
"size",
">",
"200",
"end",
"end",
"true",
"end"
] |
true if metadescription less then 200 symbols
|
[
"true",
"if",
"metadescription",
"less",
"then",
"200",
"symbols"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L92-L102
|
8,474
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.code_less?
|
def code_less?
return unless @page
sum = 0
page_text = @page.text.size
@page.css('script').each do |tag|
sum += tag.text.size
end
sum < page_text / 2
end
|
ruby
|
def code_less?
return unless @page
sum = 0
page_text = @page.text.size
@page.css('script').each do |tag|
sum += tag.text.size
end
sum < page_text / 2
end
|
[
"def",
"code_less?",
"return",
"unless",
"@page",
"sum",
"=",
"0",
"page_text",
"=",
"@page",
".",
"text",
".",
"size",
"@page",
".",
"css",
"(",
"'script'",
")",
".",
"each",
"do",
"|",
"tag",
"|",
"sum",
"+=",
"tag",
".",
"text",
".",
"size",
"end",
"sum",
"<",
"page_text",
"/",
"2",
"end"
] |
true if code of page less then text on it
|
[
"true",
"if",
"code",
"of",
"page",
"less",
"then",
"text",
"on",
"it"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L116-L124
|
8,475
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.metadates_good?
|
def metadates_good?
return unless @page
return false if @all_titles.size > 1 || @meta_data.empty?
node_names = []
@meta_data.each { |node| node_names << node['name'] }
node_names.compact!
node_names.uniq.size == node_names.size unless node_names.nil? || node_names.size < 1
end
|
ruby
|
def metadates_good?
return unless @page
return false if @all_titles.size > 1 || @meta_data.empty?
node_names = []
@meta_data.each { |node| node_names << node['name'] }
node_names.compact!
node_names.uniq.size == node_names.size unless node_names.nil? || node_names.size < 1
end
|
[
"def",
"metadates_good?",
"return",
"unless",
"@page",
"return",
"false",
"if",
"@all_titles",
".",
"size",
">",
"1",
"||",
"@meta_data",
".",
"empty?",
"node_names",
"=",
"[",
"]",
"@meta_data",
".",
"each",
"{",
"|",
"node",
"|",
"node_names",
"<<",
"node",
"[",
"'name'",
"]",
"}",
"node_names",
".",
"compact!",
"node_names",
".",
"uniq",
".",
"size",
"==",
"node_names",
".",
"size",
"unless",
"node_names",
".",
"nil?",
"||",
"node_names",
".",
"size",
"<",
"1",
"end"
] |
check meta and title tags duplicates
|
[
"check",
"meta",
"and",
"title",
"tags",
"duplicates"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L132-L139
|
8,476
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.all_titles_h1_h2
|
def all_titles_h1_h2
return unless @page
out = []
out << @page.css('title').text << { @page_url => @page.css('h1').text }
out << { @page_url => @page.css('h2').text }
out
end
|
ruby
|
def all_titles_h1_h2
return unless @page
out = []
out << @page.css('title').text << { @page_url => @page.css('h1').text }
out << { @page_url => @page.css('h2').text }
out
end
|
[
"def",
"all_titles_h1_h2",
"return",
"unless",
"@page",
"out",
"=",
"[",
"]",
"out",
"<<",
"@page",
".",
"css",
"(",
"'title'",
")",
".",
"text",
"<<",
"{",
"@page_url",
"=>",
"@page",
".",
"css",
"(",
"'h1'",
")",
".",
"text",
"}",
"out",
"<<",
"{",
"@page_url",
"=>",
"@page",
".",
"css",
"(",
"'h2'",
")",
".",
"text",
"}",
"out",
"end"
] |
return hash with all titles, h1 and h2
|
[
"return",
"hash",
"with",
"all",
"titles",
"h1",
"and",
"h2"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L141-L147
|
8,477
|
Mordorreal/SiteAnalyzer
|
lib/site_analyzer/page.rb
|
SiteAnalyzer.Page.all_a_tags
|
def all_a_tags
return unless @page
tags = []
@page.css('a').each do |node|
tags << [node['href'], node['target'], node['rel']]
end
tags.compact
end
|
ruby
|
def all_a_tags
return unless @page
tags = []
@page.css('a').each do |node|
tags << [node['href'], node['target'], node['rel']]
end
tags.compact
end
|
[
"def",
"all_a_tags",
"return",
"unless",
"@page",
"tags",
"=",
"[",
"]",
"@page",
".",
"css",
"(",
"'a'",
")",
".",
"each",
"do",
"|",
"node",
"|",
"tags",
"<<",
"[",
"node",
"[",
"'href'",
"]",
",",
"node",
"[",
"'target'",
"]",
",",
"node",
"[",
"'rel'",
"]",
"]",
"end",
"tags",
".",
"compact",
"end"
] |
get all a tags
|
[
"get",
"all",
"a",
"tags"
] |
7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb
|
https://github.com/Mordorreal/SiteAnalyzer/blob/7b17f7c1651c2fe85dbc2088c28cf1ec94ffdefb/lib/site_analyzer/page.rb#L157-L164
|
8,478
|
cajun/smile
|
lib/smile/common.rb
|
Smile.Common.default_params
|
def default_params
@params ||= { :api_key => session.api_key }
@params.merge!( :session_id => session.id ) if( session.id )
@params = Smile::ParamConverter.clean_hash_keys( @params )
end
|
ruby
|
def default_params
@params ||= { :api_key => session.api_key }
@params.merge!( :session_id => session.id ) if( session.id )
@params = Smile::ParamConverter.clean_hash_keys( @params )
end
|
[
"def",
"default_params",
"@params",
"||=",
"{",
":api_key",
"=>",
"session",
".",
"api_key",
"}",
"@params",
".",
"merge!",
"(",
":session_id",
"=>",
"session",
".",
"id",
")",
"if",
"(",
"session",
".",
"id",
")",
"@params",
"=",
"Smile",
"::",
"ParamConverter",
".",
"clean_hash_keys",
"(",
"@params",
")",
"end"
] |
This will be included in every request once you have logged in
|
[
"This",
"will",
"be",
"included",
"in",
"every",
"request",
"once",
"you",
"have",
"logged",
"in"
] |
5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6
|
https://github.com/cajun/smile/blob/5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6/lib/smile/common.rb#L14-L18
|
8,479
|
cajun/smile
|
lib/smile/common.rb
|
Smile.Common.base_web_method_call
|
def base_web_method_call( web_options, options ={}, url )
options = Smile::ParamConverter.clean_hash_keys( options )
web_options = Smile::ParamConverter.clean_hash_keys( web_options )
params = default_params.merge( web_options )
params.merge!( options ) if( options )
logger.info( params.inspect )
json = RestClient.post( url, params ).body
upper_hash_to_lower_hash( Smile::Json.parse( json ) )
end
|
ruby
|
def base_web_method_call( web_options, options ={}, url )
options = Smile::ParamConverter.clean_hash_keys( options )
web_options = Smile::ParamConverter.clean_hash_keys( web_options )
params = default_params.merge( web_options )
params.merge!( options ) if( options )
logger.info( params.inspect )
json = RestClient.post( url, params ).body
upper_hash_to_lower_hash( Smile::Json.parse( json ) )
end
|
[
"def",
"base_web_method_call",
"(",
"web_options",
",",
"options",
"=",
"{",
"}",
",",
"url",
")",
"options",
"=",
"Smile",
"::",
"ParamConverter",
".",
"clean_hash_keys",
"(",
"options",
")",
"web_options",
"=",
"Smile",
"::",
"ParamConverter",
".",
"clean_hash_keys",
"(",
"web_options",
")",
"params",
"=",
"default_params",
".",
"merge",
"(",
"web_options",
")",
"params",
".",
"merge!",
"(",
"options",
")",
"if",
"(",
"options",
")",
"logger",
".",
"info",
"(",
"params",
".",
"inspect",
")",
"json",
"=",
"RestClient",
".",
"post",
"(",
"url",
",",
"params",
")",
".",
"body",
"upper_hash_to_lower_hash",
"(",
"Smile",
"::",
"Json",
".",
"parse",
"(",
"json",
")",
")",
"end"
] |
Call either the secure or the base web url
|
[
"Call",
"either",
"the",
"secure",
"or",
"the",
"base",
"web",
"url"
] |
5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6
|
https://github.com/cajun/smile/blob/5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6/lib/smile/common.rb#L35-L46
|
8,480
|
cajun/smile
|
lib/smile/common.rb
|
Smile.Common.upper_hash_to_lower_hash
|
def upper_hash_to_lower_hash( upper )
case upper
when Hash
upper.inject({}) do |lower,array|
key, value = array
lower[key.downcase] = upper_hash_to_lower_hash( value )
lower
end
else
upper
end
end
|
ruby
|
def upper_hash_to_lower_hash( upper )
case upper
when Hash
upper.inject({}) do |lower,array|
key, value = array
lower[key.downcase] = upper_hash_to_lower_hash( value )
lower
end
else
upper
end
end
|
[
"def",
"upper_hash_to_lower_hash",
"(",
"upper",
")",
"case",
"upper",
"when",
"Hash",
"upper",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"lower",
",",
"array",
"|",
"key",
",",
"value",
"=",
"array",
"lower",
"[",
"key",
".",
"downcase",
"]",
"=",
"upper_hash_to_lower_hash",
"(",
"value",
")",
"lower",
"end",
"else",
"upper",
"end",
"end"
] |
This converts a hash that has mixed case
into all lower case
|
[
"This",
"converts",
"a",
"hash",
"that",
"has",
"mixed",
"case",
"into",
"all",
"lower",
"case"
] |
5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6
|
https://github.com/cajun/smile/blob/5a9ffe3d9f46cddf0562d8fe68d892dd785c0bd6/lib/smile/common.rb#L50-L61
|
8,481
|
galetahub/cancan_namespace
|
lib/cancan_namespace/rule.rb
|
CanCanNamespace.Rule.relevant?
|
def relevant?(action, subject, context = nil)
subject = subject.values.first if subject.class == Hash
@match_all || (matches_action?(action) && matches_subject?(subject) && matches_context(context))
end
|
ruby
|
def relevant?(action, subject, context = nil)
subject = subject.values.first if subject.class == Hash
@match_all || (matches_action?(action) && matches_subject?(subject) && matches_context(context))
end
|
[
"def",
"relevant?",
"(",
"action",
",",
"subject",
",",
"context",
"=",
"nil",
")",
"subject",
"=",
"subject",
".",
"values",
".",
"first",
"if",
"subject",
".",
"class",
"==",
"Hash",
"@match_all",
"||",
"(",
"matches_action?",
"(",
"action",
")",
"&&",
"matches_subject?",
"(",
"subject",
")",
"&&",
"matches_context",
"(",
"context",
")",
")",
"end"
] |
Matches both the subject and action, not necessarily the conditions
|
[
"Matches",
"both",
"the",
"subject",
"and",
"action",
"not",
"necessarily",
"the",
"conditions"
] |
87b5ef90e620d7b692414e3cc8ed1c822dfafe8b
|
https://github.com/galetahub/cancan_namespace/blob/87b5ef90e620d7b692414e3cc8ed1c822dfafe8b/lib/cancan_namespace/rule.rb#L26-L29
|
8,482
|
vadviktor/jenkins_junit_builder
|
lib/jenkins_junit_builder/suite.rb
|
JenkinsJunitBuilder.Suite.build_report
|
def build_report
# build cases
builder = Nokogiri::XML::Builder.new do |xml|
xml.testsuites {
testsuite = xml.testsuite {
@cases.each do |tc|
testcase = xml.testcase {
if tc.result_has_message?
result_type = xml.send(tc.result)
result_type[:message] = tc.message if tc.message.present?
end
if tc.system_out.size > 0
xml.send('system-out') { xml.text tc.system_out.to_s }
end
if tc.system_err.size > 0
xml.send('system-err') { xml.text tc.system_err.to_s }
end
}
testcase[:name] = tc.name if tc.name.present?
testcase[:time] = tc.time if tc.time.present?
testcase[:classname] = package if package.present?
if tc.classname.present?
if testcase[:classname].present?
testcase[:classname] = "#{testcase[:classname]}.#{tc.classname}"
else
testcase[:classname] = tc.classname
end
end
end
}
testsuite[:name] = name if name.present?
testsuite[:package] = package if package.present?
}
end
builder.parent.root.to_xml
end
|
ruby
|
def build_report
# build cases
builder = Nokogiri::XML::Builder.new do |xml|
xml.testsuites {
testsuite = xml.testsuite {
@cases.each do |tc|
testcase = xml.testcase {
if tc.result_has_message?
result_type = xml.send(tc.result)
result_type[:message] = tc.message if tc.message.present?
end
if tc.system_out.size > 0
xml.send('system-out') { xml.text tc.system_out.to_s }
end
if tc.system_err.size > 0
xml.send('system-err') { xml.text tc.system_err.to_s }
end
}
testcase[:name] = tc.name if tc.name.present?
testcase[:time] = tc.time if tc.time.present?
testcase[:classname] = package if package.present?
if tc.classname.present?
if testcase[:classname].present?
testcase[:classname] = "#{testcase[:classname]}.#{tc.classname}"
else
testcase[:classname] = tc.classname
end
end
end
}
testsuite[:name] = name if name.present?
testsuite[:package] = package if package.present?
}
end
builder.parent.root.to_xml
end
|
[
"def",
"build_report",
"# build cases",
"builder",
"=",
"Nokogiri",
"::",
"XML",
"::",
"Builder",
".",
"new",
"do",
"|",
"xml",
"|",
"xml",
".",
"testsuites",
"{",
"testsuite",
"=",
"xml",
".",
"testsuite",
"{",
"@cases",
".",
"each",
"do",
"|",
"tc",
"|",
"testcase",
"=",
"xml",
".",
"testcase",
"{",
"if",
"tc",
".",
"result_has_message?",
"result_type",
"=",
"xml",
".",
"send",
"(",
"tc",
".",
"result",
")",
"result_type",
"[",
":message",
"]",
"=",
"tc",
".",
"message",
"if",
"tc",
".",
"message",
".",
"present?",
"end",
"if",
"tc",
".",
"system_out",
".",
"size",
">",
"0",
"xml",
".",
"send",
"(",
"'system-out'",
")",
"{",
"xml",
".",
"text",
"tc",
".",
"system_out",
".",
"to_s",
"}",
"end",
"if",
"tc",
".",
"system_err",
".",
"size",
">",
"0",
"xml",
".",
"send",
"(",
"'system-err'",
")",
"{",
"xml",
".",
"text",
"tc",
".",
"system_err",
".",
"to_s",
"}",
"end",
"}",
"testcase",
"[",
":name",
"]",
"=",
"tc",
".",
"name",
"if",
"tc",
".",
"name",
".",
"present?",
"testcase",
"[",
":time",
"]",
"=",
"tc",
".",
"time",
"if",
"tc",
".",
"time",
".",
"present?",
"testcase",
"[",
":classname",
"]",
"=",
"package",
"if",
"package",
".",
"present?",
"if",
"tc",
".",
"classname",
".",
"present?",
"if",
"testcase",
"[",
":classname",
"]",
".",
"present?",
"testcase",
"[",
":classname",
"]",
"=",
"\"#{testcase[:classname]}.#{tc.classname}\"",
"else",
"testcase",
"[",
":classname",
"]",
"=",
"tc",
".",
"classname",
"end",
"end",
"end",
"}",
"testsuite",
"[",
":name",
"]",
"=",
"name",
"if",
"name",
".",
"present?",
"testsuite",
"[",
":package",
"]",
"=",
"package",
"if",
"package",
".",
"present?",
"}",
"end",
"builder",
".",
"parent",
".",
"root",
".",
"to_xml",
"end"
] |
In short, this is the XML string that makes the report.
@return [String] XML report
|
[
"In",
"short",
"this",
"is",
"the",
"XML",
"string",
"that",
"makes",
"the",
"report",
"."
] |
92dae28e2d135bc06f912c92572827850b95a2f0
|
https://github.com/vadviktor/jenkins_junit_builder/blob/92dae28e2d135bc06f912c92572827850b95a2f0/lib/jenkins_junit_builder/suite.rb#L23-L65
|
8,483
|
vadviktor/jenkins_junit_builder
|
lib/jenkins_junit_builder/suite.rb
|
JenkinsJunitBuilder.Suite.write_report_file
|
def write_report_file
raise FileNotFoundException.new 'There is no report file path specified' if report_path.blank?
report = build_report
if append_report.present? && File.exist?(report_path)
f = File.open(report_path)
existing_xml = Nokogiri::XML(f)
f.close
report = existing_xml.root << Nokogiri::XML(report).at('testsuite')
# formatting
report = format_xml report.to_xml
end
File.write report_path, report
report
end
|
ruby
|
def write_report_file
raise FileNotFoundException.new 'There is no report file path specified' if report_path.blank?
report = build_report
if append_report.present? && File.exist?(report_path)
f = File.open(report_path)
existing_xml = Nokogiri::XML(f)
f.close
report = existing_xml.root << Nokogiri::XML(report).at('testsuite')
# formatting
report = format_xml report.to_xml
end
File.write report_path, report
report
end
|
[
"def",
"write_report_file",
"raise",
"FileNotFoundException",
".",
"new",
"'There is no report file path specified'",
"if",
"report_path",
".",
"blank?",
"report",
"=",
"build_report",
"if",
"append_report",
".",
"present?",
"&&",
"File",
".",
"exist?",
"(",
"report_path",
")",
"f",
"=",
"File",
".",
"open",
"(",
"report_path",
")",
"existing_xml",
"=",
"Nokogiri",
"::",
"XML",
"(",
"f",
")",
"f",
".",
"close",
"report",
"=",
"existing_xml",
".",
"root",
"<<",
"Nokogiri",
"::",
"XML",
"(",
"report",
")",
".",
"at",
"(",
"'testsuite'",
")",
"# formatting",
"report",
"=",
"format_xml",
"report",
".",
"to_xml",
"end",
"File",
".",
"write",
"report_path",
",",
"report",
"report",
"end"
] |
Writes the report to the specified file
also returns the new XML report content
@return [String] final XML report content
|
[
"Writes",
"the",
"report",
"to",
"the",
"specified",
"file",
"also",
"returns",
"the",
"new",
"XML",
"report",
"content"
] |
92dae28e2d135bc06f912c92572827850b95a2f0
|
https://github.com/vadviktor/jenkins_junit_builder/blob/92dae28e2d135bc06f912c92572827850b95a2f0/lib/jenkins_junit_builder/suite.rb#L71-L89
|
8,484
|
checkdin/checkdin-ruby
|
lib/checkdin/client.rb
|
Checkdin.Client.return_error_or_body
|
def return_error_or_body(response)
if response.status / 100 == 2
response.body
else
raise Checkdin::APIError.new(response.status, response.body)
end
end
|
ruby
|
def return_error_or_body(response)
if response.status / 100 == 2
response.body
else
raise Checkdin::APIError.new(response.status, response.body)
end
end
|
[
"def",
"return_error_or_body",
"(",
"response",
")",
"if",
"response",
".",
"status",
"/",
"100",
"==",
"2",
"response",
".",
"body",
"else",
"raise",
"Checkdin",
"::",
"APIError",
".",
"new",
"(",
"response",
".",
"status",
",",
"response",
".",
"body",
")",
"end",
"end"
] |
Helper method to return errors or desired response data as appropriate.
Added just for convenience to avoid having to traverse farther down the response just to get to returned data.
|
[
"Helper",
"method",
"to",
"return",
"errors",
"or",
"desired",
"response",
"data",
"as",
"appropriate",
"."
] |
c3c4b38b0f8c710e1f805100dcf3a70649215b48
|
https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/client.rb#L69-L75
|
8,485
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.set_variable_bounds
|
def set_variable_bounds(var_index, lb, ub, force = false)
# This is a bit of a hack so that we don't try to set
# the variable bounds before they get added to the model
return unless force
Cbc.Cbc_setColLower @ptr, var_index, lb
Cbc.Cbc_setColUpper @ptr, var_index, ub
end
|
ruby
|
def set_variable_bounds(var_index, lb, ub, force = false)
# This is a bit of a hack so that we don't try to set
# the variable bounds before they get added to the model
return unless force
Cbc.Cbc_setColLower @ptr, var_index, lb
Cbc.Cbc_setColUpper @ptr, var_index, ub
end
|
[
"def",
"set_variable_bounds",
"(",
"var_index",
",",
"lb",
",",
"ub",
",",
"force",
"=",
"false",
")",
"# This is a bit of a hack so that we don't try to set",
"# the variable bounds before they get added to the model",
"return",
"unless",
"force",
"Cbc",
".",
"Cbc_setColLower",
"@ptr",
",",
"var_index",
",",
"lb",
"Cbc",
".",
"Cbc_setColUpper",
"@ptr",
",",
"var_index",
",",
"ub",
"end"
] |
Set the bounds of a variable in the model
|
[
"Set",
"the",
"bounds",
"of",
"a",
"variable",
"in",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L67-L74
|
8,486
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.new_model
|
def new_model
ptr = FFI::AutoPointer.new Cbc.Cbc_newModel,
Cbc.method(:Cbc_deleteModel)
# Older versions of COIN-OR do not support setting the log level via
# the C interface in which case setParameter will not be defined
Cbc.Cbc_setParameter ptr, 'logLevel', '0' \
if Cbc.respond_to?(:Cbc_setParameter)
ptr
end
|
ruby
|
def new_model
ptr = FFI::AutoPointer.new Cbc.Cbc_newModel,
Cbc.method(:Cbc_deleteModel)
# Older versions of COIN-OR do not support setting the log level via
# the C interface in which case setParameter will not be defined
Cbc.Cbc_setParameter ptr, 'logLevel', '0' \
if Cbc.respond_to?(:Cbc_setParameter)
ptr
end
|
[
"def",
"new_model",
"ptr",
"=",
"FFI",
"::",
"AutoPointer",
".",
"new",
"Cbc",
".",
"Cbc_newModel",
",",
"Cbc",
".",
"method",
"(",
":Cbc_deleteModel",
")",
"# Older versions of COIN-OR do not support setting the log level via",
"# the C interface in which case setParameter will not be defined",
"Cbc",
".",
"Cbc_setParameter",
"ptr",
",",
"'logLevel'",
",",
"'0'",
"if",
"Cbc",
".",
"respond_to?",
"(",
":Cbc_setParameter",
")",
"ptr",
"end"
] |
Construct a new model object
|
[
"Construct",
"a",
"new",
"model",
"object"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L106-L116
|
8,487
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.build_constraint_matrix
|
def build_constraint_matrix(constrs)
store_constraint_indexes constrs
# Construct a matrix of non-zero values in CSC format
start = []
index = []
value = []
col_start = 0
@variables.each do |var|
# Mark the start of this column
start << col_start
var.constraints.each do |constr|
col_start += 1
index << constr.index
value << constr.expression.terms[var]
end
end
start << col_start
[start, index, value]
end
|
ruby
|
def build_constraint_matrix(constrs)
store_constraint_indexes constrs
# Construct a matrix of non-zero values in CSC format
start = []
index = []
value = []
col_start = 0
@variables.each do |var|
# Mark the start of this column
start << col_start
var.constraints.each do |constr|
col_start += 1
index << constr.index
value << constr.expression.terms[var]
end
end
start << col_start
[start, index, value]
end
|
[
"def",
"build_constraint_matrix",
"(",
"constrs",
")",
"store_constraint_indexes",
"constrs",
"# Construct a matrix of non-zero values in CSC format",
"start",
"=",
"[",
"]",
"index",
"=",
"[",
"]",
"value",
"=",
"[",
"]",
"col_start",
"=",
"0",
"@variables",
".",
"each",
"do",
"|",
"var",
"|",
"# Mark the start of this column",
"start",
"<<",
"col_start",
"var",
".",
"constraints",
".",
"each",
"do",
"|",
"constr",
"|",
"col_start",
"+=",
"1",
"index",
"<<",
"constr",
".",
"index",
"value",
"<<",
"constr",
".",
"expression",
".",
"terms",
"[",
"var",
"]",
"end",
"end",
"start",
"<<",
"col_start",
"[",
"start",
",",
"index",
",",
"value",
"]",
"end"
] |
Build a constraint matrix for the currently existing variables
|
[
"Build",
"a",
"constraint",
"matrix",
"for",
"the",
"currently",
"existing",
"variables"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L128-L149
|
8,488
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.store_model
|
def store_model(constrs, vars)
# Store all constraints
constrs.each do |constr|
store_constraint constr
@constraints << constr
end
# We store variables now since they didn't exist earlier
vars.each_with_index do |var, i|
var.index = i
var.model = self
store_variable var
end
end
|
ruby
|
def store_model(constrs, vars)
# Store all constraints
constrs.each do |constr|
store_constraint constr
@constraints << constr
end
# We store variables now since they didn't exist earlier
vars.each_with_index do |var, i|
var.index = i
var.model = self
store_variable var
end
end
|
[
"def",
"store_model",
"(",
"constrs",
",",
"vars",
")",
"# Store all constraints",
"constrs",
".",
"each",
"do",
"|",
"constr",
"|",
"store_constraint",
"constr",
"@constraints",
"<<",
"constr",
"end",
"# We store variables now since they didn't exist earlier",
"vars",
".",
"each_with_index",
"do",
"|",
"var",
",",
"i",
"|",
"var",
".",
"index",
"=",
"i",
"var",
".",
"model",
"=",
"self",
"store_variable",
"var",
"end",
"end"
] |
Store all data for the model
|
[
"Store",
"all",
"data",
"for",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L152-L165
|
8,489
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.store_constraint_bounds
|
def store_constraint_bounds(index, sense, rhs)
case sense
when :==
lb = ub = rhs
when :>=
lb = rhs
ub = Float::INFINITY
when :<=
lb = -Float::INFINITY
ub = rhs
end
Cbc.Cbc_setRowLower @ptr, index, lb
Cbc.Cbc_setRowUpper @ptr, index, ub
end
|
ruby
|
def store_constraint_bounds(index, sense, rhs)
case sense
when :==
lb = ub = rhs
when :>=
lb = rhs
ub = Float::INFINITY
when :<=
lb = -Float::INFINITY
ub = rhs
end
Cbc.Cbc_setRowLower @ptr, index, lb
Cbc.Cbc_setRowUpper @ptr, index, ub
end
|
[
"def",
"store_constraint_bounds",
"(",
"index",
",",
"sense",
",",
"rhs",
")",
"case",
"sense",
"when",
":==",
"lb",
"=",
"ub",
"=",
"rhs",
"when",
":>=",
"lb",
"=",
"rhs",
"ub",
"=",
"Float",
"::",
"INFINITY",
"when",
":<=",
"lb",
"=",
"-",
"Float",
"::",
"INFINITY",
"ub",
"=",
"rhs",
"end",
"Cbc",
".",
"Cbc_setRowLower",
"@ptr",
",",
"index",
",",
"lb",
"Cbc",
".",
"Cbc_setRowUpper",
"@ptr",
",",
"index",
",",
"ub",
"end"
] |
Store the bounds for a given constraint
|
[
"Store",
"the",
"bounds",
"for",
"a",
"given",
"constraint"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L212-L226
|
8,490
|
michaelmior/mipper
|
lib/mipper/cbc/model.rb
|
MIPPeR.CbcModel.store_variable
|
def store_variable(var)
# Force the correct bounds since we can't explicitly specify binary
if var.type == :binary
var.instance_variable_set(:@lower_bound, 0)
var.instance_variable_set(:@upper_bound, 1)
end
set_variable_bounds var.index, var.lower_bound, var.upper_bound, true
Cbc.Cbc_setObjCoeff @ptr, var.index, var.coefficient
Cbc.Cbc_setColName(@ptr, var.index, var.name) unless var.name.nil?
set_variable_type var.index, var.type
end
|
ruby
|
def store_variable(var)
# Force the correct bounds since we can't explicitly specify binary
if var.type == :binary
var.instance_variable_set(:@lower_bound, 0)
var.instance_variable_set(:@upper_bound, 1)
end
set_variable_bounds var.index, var.lower_bound, var.upper_bound, true
Cbc.Cbc_setObjCoeff @ptr, var.index, var.coefficient
Cbc.Cbc_setColName(@ptr, var.index, var.name) unless var.name.nil?
set_variable_type var.index, var.type
end
|
[
"def",
"store_variable",
"(",
"var",
")",
"# Force the correct bounds since we can't explicitly specify binary",
"if",
"var",
".",
"type",
"==",
":binary",
"var",
".",
"instance_variable_set",
"(",
":@lower_bound",
",",
"0",
")",
"var",
".",
"instance_variable_set",
"(",
":@upper_bound",
",",
"1",
")",
"end",
"set_variable_bounds",
"var",
".",
"index",
",",
"var",
".",
"lower_bound",
",",
"var",
".",
"upper_bound",
",",
"true",
"Cbc",
".",
"Cbc_setObjCoeff",
"@ptr",
",",
"var",
".",
"index",
",",
"var",
".",
"coefficient",
"Cbc",
".",
"Cbc_setColName",
"(",
"@ptr",
",",
"var",
".",
"index",
",",
"var",
".",
"name",
")",
"unless",
"var",
".",
"name",
".",
"nil?",
"set_variable_type",
"var",
".",
"index",
",",
"var",
".",
"type",
"end"
] |
Set the properties of a variable in the model
|
[
"Set",
"the",
"properties",
"of",
"a",
"variable",
"in",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/cbc/model.rb#L229-L240
|
8,491
|
robotex82/ecm_calendar_helper
|
app/helpers/ecm/calendar_helper.rb
|
Ecm.CalendarHelper.month_calendar
|
def month_calendar(date = Time.zone.now.to_date, elements = [], options = {})
options.reverse_merge! :date_method => :start_at, :display_method => :to_s, :link_elements => true, :start_day => :sunday, start_date_method: nil, end_date_method: nil
display_method = options.delete(:display_method)
link_elements = options.delete(:link_elements)
start_date_method = options.delete(:start_date_method)
end_date_method = options.delete(:end_date_method)
# calculate beginning and end of month
beginning_of_month = date.beginning_of_month.to_date
end_of_month = date.end_of_month.to_date
# Get localized day names
localized_day_names = I18n.t('date.abbr_day_names').dup
# Shift day names to suite start day
english_day_names = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
# Raise an exception if the passed start day is not an english day name
raise ":start_day option for month_calendar must be in: #{english_day_names.join(', ')}, but you passed: #{options[:start_day].to_s} (class: #{options[:start_day].class.to_s})" unless english_day_names.include?(options[:start_day])
# Get the offset of start day
offset = english_day_names.index(options[:start_day])
last_day_of_week = Time.zone.now.end_of_week.wday
# Change calendar heading if offset is not 0 (offset 0 means sunday is the first day of the week)
offset.times do
localized_day_names.push(localized_day_names.shift)
end
days_by_week = {}
first_day = beginning_of_month.beginning_of_week
last_day = end_of_month.end_of_week
days = (first_day..last_day).each_with_object({}).with_index do |(day, memo), index|
memo[day.to_date] = elements.find_all do |e|
if start_date_method.present? && end_date_method.present?
day.to_date.between?(e.send(start_date_method), e.send(end_date_method))
else
e.send(options[:date_method]).to_date == day.to_date
end
end || {}
end
days_by_week = days.each_with_object({}) { |(k, v), m| (m[k.cweek] ||= {})[k] = v }
render partial: 'ecm/calendar_helper/month_calendar', locals: { localized_day_names: localized_day_names, days_by_week: days_by_week, display_method: display_method, link_elements: link_elements }
end
|
ruby
|
def month_calendar(date = Time.zone.now.to_date, elements = [], options = {})
options.reverse_merge! :date_method => :start_at, :display_method => :to_s, :link_elements => true, :start_day => :sunday, start_date_method: nil, end_date_method: nil
display_method = options.delete(:display_method)
link_elements = options.delete(:link_elements)
start_date_method = options.delete(:start_date_method)
end_date_method = options.delete(:end_date_method)
# calculate beginning and end of month
beginning_of_month = date.beginning_of_month.to_date
end_of_month = date.end_of_month.to_date
# Get localized day names
localized_day_names = I18n.t('date.abbr_day_names').dup
# Shift day names to suite start day
english_day_names = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
# Raise an exception if the passed start day is not an english day name
raise ":start_day option for month_calendar must be in: #{english_day_names.join(', ')}, but you passed: #{options[:start_day].to_s} (class: #{options[:start_day].class.to_s})" unless english_day_names.include?(options[:start_day])
# Get the offset of start day
offset = english_day_names.index(options[:start_day])
last_day_of_week = Time.zone.now.end_of_week.wday
# Change calendar heading if offset is not 0 (offset 0 means sunday is the first day of the week)
offset.times do
localized_day_names.push(localized_day_names.shift)
end
days_by_week = {}
first_day = beginning_of_month.beginning_of_week
last_day = end_of_month.end_of_week
days = (first_day..last_day).each_with_object({}).with_index do |(day, memo), index|
memo[day.to_date] = elements.find_all do |e|
if start_date_method.present? && end_date_method.present?
day.to_date.between?(e.send(start_date_method), e.send(end_date_method))
else
e.send(options[:date_method]).to_date == day.to_date
end
end || {}
end
days_by_week = days.each_with_object({}) { |(k, v), m| (m[k.cweek] ||= {})[k] = v }
render partial: 'ecm/calendar_helper/month_calendar', locals: { localized_day_names: localized_day_names, days_by_week: days_by_week, display_method: display_method, link_elements: link_elements }
end
|
[
"def",
"month_calendar",
"(",
"date",
"=",
"Time",
".",
"zone",
".",
"now",
".",
"to_date",
",",
"elements",
"=",
"[",
"]",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"reverse_merge!",
":date_method",
"=>",
":start_at",
",",
":display_method",
"=>",
":to_s",
",",
":link_elements",
"=>",
"true",
",",
":start_day",
"=>",
":sunday",
",",
"start_date_method",
":",
"nil",
",",
"end_date_method",
":",
"nil",
"display_method",
"=",
"options",
".",
"delete",
"(",
":display_method",
")",
"link_elements",
"=",
"options",
".",
"delete",
"(",
":link_elements",
")",
"start_date_method",
"=",
"options",
".",
"delete",
"(",
":start_date_method",
")",
"end_date_method",
"=",
"options",
".",
"delete",
"(",
":end_date_method",
")",
"# calculate beginning and end of month",
"beginning_of_month",
"=",
"date",
".",
"beginning_of_month",
".",
"to_date",
"end_of_month",
"=",
"date",
".",
"end_of_month",
".",
"to_date",
"# Get localized day names",
"localized_day_names",
"=",
"I18n",
".",
"t",
"(",
"'date.abbr_day_names'",
")",
".",
"dup",
"# Shift day names to suite start day",
"english_day_names",
"=",
"[",
":sunday",
",",
":monday",
",",
":tuesday",
",",
":wednesday",
",",
":thursday",
",",
":friday",
",",
":saturday",
"]",
"# Raise an exception if the passed start day is not an english day name",
"raise",
"\":start_day option for month_calendar must be in: #{english_day_names.join(', ')}, but you passed: #{options[:start_day].to_s} (class: #{options[:start_day].class.to_s})\"",
"unless",
"english_day_names",
".",
"include?",
"(",
"options",
"[",
":start_day",
"]",
")",
"# Get the offset of start day",
"offset",
"=",
"english_day_names",
".",
"index",
"(",
"options",
"[",
":start_day",
"]",
")",
"last_day_of_week",
"=",
"Time",
".",
"zone",
".",
"now",
".",
"end_of_week",
".",
"wday",
"# Change calendar heading if offset is not 0 (offset 0 means sunday is the first day of the week)",
"offset",
".",
"times",
"do",
"localized_day_names",
".",
"push",
"(",
"localized_day_names",
".",
"shift",
")",
"end",
"days_by_week",
"=",
"{",
"}",
"first_day",
"=",
"beginning_of_month",
".",
"beginning_of_week",
"last_day",
"=",
"end_of_month",
".",
"end_of_week",
"days",
"=",
"(",
"first_day",
"..",
"last_day",
")",
".",
"each_with_object",
"(",
"{",
"}",
")",
".",
"with_index",
"do",
"|",
"(",
"day",
",",
"memo",
")",
",",
"index",
"|",
"memo",
"[",
"day",
".",
"to_date",
"]",
"=",
"elements",
".",
"find_all",
"do",
"|",
"e",
"|",
"if",
"start_date_method",
".",
"present?",
"&&",
"end_date_method",
".",
"present?",
"day",
".",
"to_date",
".",
"between?",
"(",
"e",
".",
"send",
"(",
"start_date_method",
")",
",",
"e",
".",
"send",
"(",
"end_date_method",
")",
")",
"else",
"e",
".",
"send",
"(",
"options",
"[",
":date_method",
"]",
")",
".",
"to_date",
"==",
"day",
".",
"to_date",
"end",
"end",
"||",
"{",
"}",
"end",
"days_by_week",
"=",
"days",
".",
"each_with_object",
"(",
"{",
"}",
")",
"{",
"|",
"(",
"k",
",",
"v",
")",
",",
"m",
"|",
"(",
"m",
"[",
"k",
".",
"cweek",
"]",
"||=",
"{",
"}",
")",
"[",
"k",
"]",
"=",
"v",
"}",
"render",
"partial",
":",
"'ecm/calendar_helper/month_calendar'",
",",
"locals",
":",
"{",
"localized_day_names",
":",
"localized_day_names",
",",
"days_by_week",
":",
"days_by_week",
",",
"display_method",
":",
"display_method",
",",
"link_elements",
":",
"link_elements",
"}",
"end"
] |
renders a calendar table
Example with elements that span more than 1 day:
= month_calendar @date, @reservations, start_date_method: :start_at, end_date_method: :end_at
Example of using a lamda as display method:
= month_calendar(display_method: ->(context, resource) { context.link_to(resource.booker.human, resource.booker) })
|
[
"renders",
"a",
"calendar",
"table"
] |
2bf66f370d0de1162705aa3c1f77559ad9386cb0
|
https://github.com/robotex82/ecm_calendar_helper/blob/2bf66f370d0de1162705aa3c1f77559ad9386cb0/app/helpers/ecm/calendar_helper.rb#L13-L62
|
8,492
|
dominikh/weechat-ruby
|
lib/weechat/buffer.rb
|
Weechat.Buffer.command
|
def command(*parts)
parts[0][0,0] = '/' unless parts[0][0..0] == '/'
line = parts.join(" ")
Weechat.exec(line, self)
line
end
|
ruby
|
def command(*parts)
parts[0][0,0] = '/' unless parts[0][0..0] == '/'
line = parts.join(" ")
Weechat.exec(line, self)
line
end
|
[
"def",
"command",
"(",
"*",
"parts",
")",
"parts",
"[",
"0",
"]",
"[",
"0",
",",
"0",
"]",
"=",
"'/'",
"unless",
"parts",
"[",
"0",
"]",
"[",
"0",
"..",
"0",
"]",
"==",
"'/'",
"line",
"=",
"parts",
".",
"join",
"(",
"\" \"",
")",
"Weechat",
".",
"exec",
"(",
"line",
",",
"self",
")",
"line",
"end"
] |
Send a command to the current buffer.
Note: If the given command does not start with a slash, one will be added.
@param [Array<String>] *parts All parts of the command to send
@return [String] The whole command as sent to the buffer
@example
my_buffer.command("/whois", "dominikh")
|
[
"Send",
"a",
"command",
"to",
"the",
"current",
"buffer",
"."
] |
b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb
|
https://github.com/dominikh/weechat-ruby/blob/b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb/lib/weechat/buffer.rb#L377-L382
|
8,493
|
dominikh/weechat-ruby
|
lib/weechat/buffer.rb
|
Weechat.Buffer.send
|
def send(*text)
text[0][0,0] = '/' if text[0][0..0] == '/'
line = text.join(" ")
Weechat.exec(line)
line
end
|
ruby
|
def send(*text)
text[0][0,0] = '/' if text[0][0..0] == '/'
line = text.join(" ")
Weechat.exec(line)
line
end
|
[
"def",
"send",
"(",
"*",
"text",
")",
"text",
"[",
"0",
"]",
"[",
"0",
",",
"0",
"]",
"=",
"'/'",
"if",
"text",
"[",
"0",
"]",
"[",
"0",
"..",
"0",
"]",
"==",
"'/'",
"line",
"=",
"text",
".",
"join",
"(",
"\" \"",
")",
"Weechat",
".",
"exec",
"(",
"line",
")",
"line",
"end"
] |
Send a text to the buffer. If the buffer represents a channel, the text
will be send as a message to the channel.
Note: this method will automatically escape a leading slash, if present.
@param [Array<String>] *text All parts of the text to send
@return [String] The whole string as sent to the buffer
|
[
"Send",
"a",
"text",
"to",
"the",
"buffer",
".",
"If",
"the",
"buffer",
"represents",
"a",
"channel",
"the",
"text",
"will",
"be",
"send",
"as",
"a",
"message",
"to",
"the",
"channel",
"."
] |
b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb
|
https://github.com/dominikh/weechat-ruby/blob/b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb/lib/weechat/buffer.rb#L394-L399
|
8,494
|
dominikh/weechat-ruby
|
lib/weechat/buffer.rb
|
Weechat.Buffer.lines
|
def lines(strip_colors = false)
lines = []
Weechat::Infolist.parse("buffer_lines", @ptr).each do |line|
line = Weechat::Line.from_hash(line)
if strip_colors
line.prefix.strip_colors!
line.message.strip_colors!
end
lines << line
end
lines
end
|
ruby
|
def lines(strip_colors = false)
lines = []
Weechat::Infolist.parse("buffer_lines", @ptr).each do |line|
line = Weechat::Line.from_hash(line)
if strip_colors
line.prefix.strip_colors!
line.message.strip_colors!
end
lines << line
end
lines
end
|
[
"def",
"lines",
"(",
"strip_colors",
"=",
"false",
")",
"lines",
"=",
"[",
"]",
"Weechat",
"::",
"Infolist",
".",
"parse",
"(",
"\"buffer_lines\"",
",",
"@ptr",
")",
".",
"each",
"do",
"|",
"line",
"|",
"line",
"=",
"Weechat",
"::",
"Line",
".",
"from_hash",
"(",
"line",
")",
"if",
"strip_colors",
"line",
".",
"prefix",
".",
"strip_colors!",
"line",
".",
"message",
".",
"strip_colors!",
"end",
"lines",
"<<",
"line",
"end",
"lines",
"end"
] |
Returns an array with all lines of the buffer.
@param [Boolean] strip_colors Whether to strip out all color codes
@return [Array<Line>] The lines
@see #text
|
[
"Returns",
"an",
"array",
"with",
"all",
"lines",
"of",
"the",
"buffer",
"."
] |
b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb
|
https://github.com/dominikh/weechat-ruby/blob/b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb/lib/weechat/buffer.rb#L470-L482
|
8,495
|
dominikh/weechat-ruby
|
lib/weechat/buffer.rb
|
Weechat.Buffer.bind_keys
|
def bind_keys(*args)
keys = args[0..-2]
command = args[-1]
keychain = keys.join("-")
if command.is_a? Command
command = command.command
end
set("key_bind_#{keychain}", command)
@keybinds[keys] = command
keychain
end
|
ruby
|
def bind_keys(*args)
keys = args[0..-2]
command = args[-1]
keychain = keys.join("-")
if command.is_a? Command
command = command.command
end
set("key_bind_#{keychain}", command)
@keybinds[keys] = command
keychain
end
|
[
"def",
"bind_keys",
"(",
"*",
"args",
")",
"keys",
"=",
"args",
"[",
"0",
"..",
"-",
"2",
"]",
"command",
"=",
"args",
"[",
"-",
"1",
"]",
"keychain",
"=",
"keys",
".",
"join",
"(",
"\"-\"",
")",
"if",
"command",
".",
"is_a?",
"Command",
"command",
"=",
"command",
".",
"command",
"end",
"set",
"(",
"\"key_bind_#{keychain}\"",
",",
"command",
")",
"@keybinds",
"[",
"keys",
"]",
"=",
"command",
"keychain",
"end"
] |
Bind keys to a command.
@param [Array<String>] keys An array of keys which will be used to build a keychain
@param [String, Command] command The command to execute when the keys are being pressed
@return [String] The keychain
@see #unbind_keys
|
[
"Bind",
"keys",
"to",
"a",
"command",
"."
] |
b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb
|
https://github.com/dominikh/weechat-ruby/blob/b3bbe37e5c0cc0a41e9107a23b7cfbb39c0e59eb/lib/weechat/buffer.rb#L510-L521
|
8,496
|
agrobbin/google-api
|
lib/google-api/api.rb
|
GoogleAPI.API.request
|
def request(method, url = nil, options = {})
options[:headers] = {'Content-Type' => 'application/json'}.merge(options[:headers] || {})
options[:body] = options[:body].to_json if options[:body].is_a?(Hash)
# Adopt Google's API erorr handling recommendation here:
# https://developers.google.com/drive/handle-errors#implementing_exponential_backoff
#
# In essence, we try 5 times to perform the request. With each subsequent request,
# we wait 2^n seconds plus a random number of milliseconds (no greater than 1 second)
# until either we receive a successful response, or we run out of attempts.
# If the Retry-After header is in the error response, we use whichever happens to be
# greater, our calculated wait time, or the value in the Retry-After header.
#
# If development_mode is set to true, we only run the request once. This speeds up
# development for those using this gem.
attempt = 0
max_attempts = GoogleAPI.development_mode ? 1 : 5
while attempt < max_attempts
response = access_token.send(method.to_sym, url, options)
seconds_to_wait = [((2 ** attempt) + rand), response.headers['Retry-After'].to_i].max
attempt += 1
break if response.status < 400 || attempt == max_attempts
GoogleAPI.logger.error "Request attempt ##{attempt} to #{url} failed for. Trying again in #{seconds_to_wait} seconds..."
sleep seconds_to_wait
end
response.parsed || response
end
|
ruby
|
def request(method, url = nil, options = {})
options[:headers] = {'Content-Type' => 'application/json'}.merge(options[:headers] || {})
options[:body] = options[:body].to_json if options[:body].is_a?(Hash)
# Adopt Google's API erorr handling recommendation here:
# https://developers.google.com/drive/handle-errors#implementing_exponential_backoff
#
# In essence, we try 5 times to perform the request. With each subsequent request,
# we wait 2^n seconds plus a random number of milliseconds (no greater than 1 second)
# until either we receive a successful response, or we run out of attempts.
# If the Retry-After header is in the error response, we use whichever happens to be
# greater, our calculated wait time, or the value in the Retry-After header.
#
# If development_mode is set to true, we only run the request once. This speeds up
# development for those using this gem.
attempt = 0
max_attempts = GoogleAPI.development_mode ? 1 : 5
while attempt < max_attempts
response = access_token.send(method.to_sym, url, options)
seconds_to_wait = [((2 ** attempt) + rand), response.headers['Retry-After'].to_i].max
attempt += 1
break if response.status < 400 || attempt == max_attempts
GoogleAPI.logger.error "Request attempt ##{attempt} to #{url} failed for. Trying again in #{seconds_to_wait} seconds..."
sleep seconds_to_wait
end
response.parsed || response
end
|
[
"def",
"request",
"(",
"method",
",",
"url",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":headers",
"]",
"=",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
".",
"merge",
"(",
"options",
"[",
":headers",
"]",
"||",
"{",
"}",
")",
"options",
"[",
":body",
"]",
"=",
"options",
"[",
":body",
"]",
".",
"to_json",
"if",
"options",
"[",
":body",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"# Adopt Google's API erorr handling recommendation here:",
"# https://developers.google.com/drive/handle-errors#implementing_exponential_backoff",
"#",
"# In essence, we try 5 times to perform the request. With each subsequent request,",
"# we wait 2^n seconds plus a random number of milliseconds (no greater than 1 second)",
"# until either we receive a successful response, or we run out of attempts.",
"# If the Retry-After header is in the error response, we use whichever happens to be",
"# greater, our calculated wait time, or the value in the Retry-After header.",
"#",
"# If development_mode is set to true, we only run the request once. This speeds up",
"# development for those using this gem.",
"attempt",
"=",
"0",
"max_attempts",
"=",
"GoogleAPI",
".",
"development_mode",
"?",
"1",
":",
"5",
"while",
"attempt",
"<",
"max_attempts",
"response",
"=",
"access_token",
".",
"send",
"(",
"method",
".",
"to_sym",
",",
"url",
",",
"options",
")",
"seconds_to_wait",
"=",
"[",
"(",
"(",
"2",
"**",
"attempt",
")",
"+",
"rand",
")",
",",
"response",
".",
"headers",
"[",
"'Retry-After'",
"]",
".",
"to_i",
"]",
".",
"max",
"attempt",
"+=",
"1",
"break",
"if",
"response",
".",
"status",
"<",
"400",
"||",
"attempt",
"==",
"max_attempts",
"GoogleAPI",
".",
"logger",
".",
"error",
"\"Request attempt ##{attempt} to #{url} failed for. Trying again in #{seconds_to_wait} seconds...\"",
"sleep",
"seconds_to_wait",
"end",
"response",
".",
"parsed",
"||",
"response",
"end"
] |
A really important part of this class. The headers are injected here,
and the body is transformed into a JSON'd string when necessary.
We do exponential back-off for error responses, and return a parsed
response body if present, the full Response object if not.
|
[
"A",
"really",
"important",
"part",
"of",
"this",
"class",
".",
"The",
"headers",
"are",
"injected",
"here",
"and",
"the",
"body",
"is",
"transformed",
"into",
"a",
"JSON",
"d",
"string",
"when",
"necessary",
".",
"We",
"do",
"exponential",
"back",
"-",
"off",
"for",
"error",
"responses",
"and",
"return",
"a",
"parsed",
"response",
"body",
"if",
"present",
"the",
"full",
"Response",
"object",
"if",
"not",
"."
] |
8d9577a476b018c964c803ea0485ed3d221540be
|
https://github.com/agrobbin/google-api/blob/8d9577a476b018c964c803ea0485ed3d221540be/lib/google-api/api.rb#L49-L76
|
8,497
|
agrobbin/google-api
|
lib/google-api/api.rb
|
GoogleAPI.API.upload
|
def upload(api_method, url, options = {})
mime_type = ::MIME::Types.type_for(options[:media]).first.to_s
file = File.read(options.delete(:media))
options[:body][:mimeType] = mime_type
options[:headers] = (options[:headers] || {}).merge({'X-Upload-Content-Type' => mime_type})
response = request(api_method, url, options)
options[:body] = file
options[:headers].delete('X-Upload-Content-Type')
options[:headers].merge!({'Content-Type' => mime_type, 'Content-Length' => file.bytesize.to_s})
request(:put, response.headers['Location'], options)
end
|
ruby
|
def upload(api_method, url, options = {})
mime_type = ::MIME::Types.type_for(options[:media]).first.to_s
file = File.read(options.delete(:media))
options[:body][:mimeType] = mime_type
options[:headers] = (options[:headers] || {}).merge({'X-Upload-Content-Type' => mime_type})
response = request(api_method, url, options)
options[:body] = file
options[:headers].delete('X-Upload-Content-Type')
options[:headers].merge!({'Content-Type' => mime_type, 'Content-Length' => file.bytesize.to_s})
request(:put, response.headers['Location'], options)
end
|
[
"def",
"upload",
"(",
"api_method",
",",
"url",
",",
"options",
"=",
"{",
"}",
")",
"mime_type",
"=",
"::",
"MIME",
"::",
"Types",
".",
"type_for",
"(",
"options",
"[",
":media",
"]",
")",
".",
"first",
".",
"to_s",
"file",
"=",
"File",
".",
"read",
"(",
"options",
".",
"delete",
"(",
":media",
")",
")",
"options",
"[",
":body",
"]",
"[",
":mimeType",
"]",
"=",
"mime_type",
"options",
"[",
":headers",
"]",
"=",
"(",
"options",
"[",
":headers",
"]",
"||",
"{",
"}",
")",
".",
"merge",
"(",
"{",
"'X-Upload-Content-Type'",
"=>",
"mime_type",
"}",
")",
"response",
"=",
"request",
"(",
"api_method",
",",
"url",
",",
"options",
")",
"options",
"[",
":body",
"]",
"=",
"file",
"options",
"[",
":headers",
"]",
".",
"delete",
"(",
"'X-Upload-Content-Type'",
")",
"options",
"[",
":headers",
"]",
".",
"merge!",
"(",
"{",
"'Content-Type'",
"=>",
"mime_type",
",",
"'Content-Length'",
"=>",
"file",
".",
"bytesize",
".",
"to_s",
"}",
")",
"request",
"(",
":put",
",",
"response",
".",
"headers",
"[",
"'Location'",
"]",
",",
"options",
")",
"end"
] |
Build a resumable upload request that then makes POST and PUT requests with the correct
headers for each request.
The initial POST request initiates the upload process, passing the metadata for the file.
The response from the API includes a Location header telling us where to actually send the
media we want uploaded. The subsequent PUT request sends the media itself to the API.
|
[
"Build",
"a",
"resumable",
"upload",
"request",
"that",
"then",
"makes",
"POST",
"and",
"PUT",
"requests",
"with",
"the",
"correct",
"headers",
"for",
"each",
"request",
"."
] |
8d9577a476b018c964c803ea0485ed3d221540be
|
https://github.com/agrobbin/google-api/blob/8d9577a476b018c964c803ea0485ed3d221540be/lib/google-api/api.rb#L84-L98
|
8,498
|
agrobbin/google-api
|
lib/google-api/api.rb
|
GoogleAPI.API.build_url
|
def build_url(api_method, options = {})
if api_method['mediaUpload'] && options[:media]
# we need to do [1..-1] to remove the prepended slash
url = GoogleAPI.discovered_apis[api]['rootUrl'] + api_method['mediaUpload']['protocols']['resumable']['path'][1..-1]
else
url = GoogleAPI.discovered_apis[api]['baseUrl'] + api_method['path']
query_params = []
api_method['parameters'].each_with_index do |(param, settings), index|
param = param.to_sym
case settings['location']
when 'path'
raise ArgumentError, ":#{param} was not passed" if settings['required'] && !options[param]
url.sub!("{#{param}}", options.delete(param).to_s)
when 'query'
query_params << "#{param}=#{options.delete(param)}" if options[param]
end
end if api_method['parameters']
url += "?#{query_params.join('&')}" if query_params.length > 0
end
[url, options]
end
|
ruby
|
def build_url(api_method, options = {})
if api_method['mediaUpload'] && options[:media]
# we need to do [1..-1] to remove the prepended slash
url = GoogleAPI.discovered_apis[api]['rootUrl'] + api_method['mediaUpload']['protocols']['resumable']['path'][1..-1]
else
url = GoogleAPI.discovered_apis[api]['baseUrl'] + api_method['path']
query_params = []
api_method['parameters'].each_with_index do |(param, settings), index|
param = param.to_sym
case settings['location']
when 'path'
raise ArgumentError, ":#{param} was not passed" if settings['required'] && !options[param]
url.sub!("{#{param}}", options.delete(param).to_s)
when 'query'
query_params << "#{param}=#{options.delete(param)}" if options[param]
end
end if api_method['parameters']
url += "?#{query_params.join('&')}" if query_params.length > 0
end
[url, options]
end
|
[
"def",
"build_url",
"(",
"api_method",
",",
"options",
"=",
"{",
"}",
")",
"if",
"api_method",
"[",
"'mediaUpload'",
"]",
"&&",
"options",
"[",
":media",
"]",
"# we need to do [1..-1] to remove the prepended slash",
"url",
"=",
"GoogleAPI",
".",
"discovered_apis",
"[",
"api",
"]",
"[",
"'rootUrl'",
"]",
"+",
"api_method",
"[",
"'mediaUpload'",
"]",
"[",
"'protocols'",
"]",
"[",
"'resumable'",
"]",
"[",
"'path'",
"]",
"[",
"1",
"..",
"-",
"1",
"]",
"else",
"url",
"=",
"GoogleAPI",
".",
"discovered_apis",
"[",
"api",
"]",
"[",
"'baseUrl'",
"]",
"+",
"api_method",
"[",
"'path'",
"]",
"query_params",
"=",
"[",
"]",
"api_method",
"[",
"'parameters'",
"]",
".",
"each_with_index",
"do",
"|",
"(",
"param",
",",
"settings",
")",
",",
"index",
"|",
"param",
"=",
"param",
".",
"to_sym",
"case",
"settings",
"[",
"'location'",
"]",
"when",
"'path'",
"raise",
"ArgumentError",
",",
"\":#{param} was not passed\"",
"if",
"settings",
"[",
"'required'",
"]",
"&&",
"!",
"options",
"[",
"param",
"]",
"url",
".",
"sub!",
"(",
"\"{#{param}}\"",
",",
"options",
".",
"delete",
"(",
"param",
")",
".",
"to_s",
")",
"when",
"'query'",
"query_params",
"<<",
"\"#{param}=#{options.delete(param)}\"",
"if",
"options",
"[",
"param",
"]",
"end",
"end",
"if",
"api_method",
"[",
"'parameters'",
"]",
"url",
"+=",
"\"?#{query_params.join('&')}\"",
"if",
"query_params",
".",
"length",
">",
"0",
"end",
"[",
"url",
",",
"options",
"]",
"end"
] |
Put together the full URL we will send a request to.
First we join the API's base URL with the current method's path, forming the main URL.
If the method is mediaUpload-enabled (like uploading a file to Google Drive), then we want
to take the path from the resumable upload protocol.
If not, then, we are going to iterate through each of the parameters for the current method.
When the parameter's location is within the path, we first check that we have had that
option passed, and if so, substitute it in the correct place.
When the parameter's location is a query, we add it to our query parameters hash, provided it is present.
Before returning the URL and remaining options, we have to build the query parameters hash
into a string and append it to the end of the URL.
|
[
"Put",
"together",
"the",
"full",
"URL",
"we",
"will",
"send",
"a",
"request",
"to",
".",
"First",
"we",
"join",
"the",
"API",
"s",
"base",
"URL",
"with",
"the",
"current",
"method",
"s",
"path",
"forming",
"the",
"main",
"URL",
"."
] |
8d9577a476b018c964c803ea0485ed3d221540be
|
https://github.com/agrobbin/google-api/blob/8d9577a476b018c964c803ea0485ed3d221540be/lib/google-api/api.rb#L112-L133
|
8,499
|
Sitata/i18n_language_select
|
lib/i18n_language_select/instance_tag.rb
|
I18nLanguageSelect.InstanceTag.language_code_select
|
def language_code_select(priority_languages, options, html_options)
selected = object.send(@method_name) if object.respond_to?(@method_name)
languages = ""
if options.present? and options[:include_blank]
option = options[:include_blank] == true ? "" : options[:include_blank]
languages += "<option>#{option}</option>\n"
end
if priority_languages
languages += options_for_select(priority_languages, selected)
languages += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
end
languages = languages + options_for_select(language_translations, selected)
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
content_tag(:select, languages.html_safe, html_options)
end
|
ruby
|
def language_code_select(priority_languages, options, html_options)
selected = object.send(@method_name) if object.respond_to?(@method_name)
languages = ""
if options.present? and options[:include_blank]
option = options[:include_blank] == true ? "" : options[:include_blank]
languages += "<option>#{option}</option>\n"
end
if priority_languages
languages += options_for_select(priority_languages, selected)
languages += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
end
languages = languages + options_for_select(language_translations, selected)
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
content_tag(:select, languages.html_safe, html_options)
end
|
[
"def",
"language_code_select",
"(",
"priority_languages",
",",
"options",
",",
"html_options",
")",
"selected",
"=",
"object",
".",
"send",
"(",
"@method_name",
")",
"if",
"object",
".",
"respond_to?",
"(",
"@method_name",
")",
"languages",
"=",
"\"\"",
"if",
"options",
".",
"present?",
"and",
"options",
"[",
":include_blank",
"]",
"option",
"=",
"options",
"[",
":include_blank",
"]",
"==",
"true",
"?",
"\"\"",
":",
"options",
"[",
":include_blank",
"]",
"languages",
"+=",
"\"<option>#{option}</option>\\n\"",
"end",
"if",
"priority_languages",
"languages",
"+=",
"options_for_select",
"(",
"priority_languages",
",",
"selected",
")",
"languages",
"+=",
"\"<option value=\\\"\\\" disabled=\\\"disabled\\\">-------------</option>\\n\"",
"end",
"languages",
"=",
"languages",
"+",
"options_for_select",
"(",
"language_translations",
",",
"selected",
")",
"html_options",
"=",
"html_options",
".",
"stringify_keys",
"add_default_name_and_id",
"(",
"html_options",
")",
"content_tag",
"(",
":select",
",",
"languages",
".",
"html_safe",
",",
"html_options",
")",
"end"
] |
Adapted from Rails language_select. Just uses language codes instead of full names.
|
[
"Adapted",
"from",
"Rails",
"language_select",
".",
"Just",
"uses",
"language",
"codes",
"instead",
"of",
"full",
"names",
"."
] |
4e41d4e43c013af54c765fa8e2a189e0be94fbe5
|
https://github.com/Sitata/i18n_language_select/blob/4e41d4e43c013af54c765fa8e2a189e0be94fbe5/lib/i18n_language_select/instance_tag.rb#L13-L34
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.