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
|
---|---|---|---|---|---|---|---|---|---|---|---|
21,300 |
rahmal/rconfig
|
lib/rconfig/load_paths.rb
|
RConfig.LoadPaths.add_load_path
|
def add_load_path(path)
if path = parse_load_paths(path).first # only accept first one.
self.load_paths << path
self.load_paths.uniq!
return reload(true) # Load Paths have changed so force a reload
end
false
end
|
ruby
|
def add_load_path(path)
if path = parse_load_paths(path).first # only accept first one.
self.load_paths << path
self.load_paths.uniq!
return reload(true) # Load Paths have changed so force a reload
end
false
end
|
[
"def",
"add_load_path",
"(",
"path",
")",
"if",
"path",
"=",
"parse_load_paths",
"(",
"path",
")",
".",
"first",
"# only accept first one.",
"self",
".",
"load_paths",
"<<",
"path",
"self",
".",
"load_paths",
".",
"uniq!",
"return",
"reload",
"(",
"true",
")",
"# Load Paths have changed so force a reload",
"end",
"false",
"end"
] |
Adds the specified path to the list of directories to search for
configuration files.
It only allows one path to be entered at a time.
|
[
"Adds",
"the",
"specified",
"path",
"to",
"the",
"list",
"of",
"directories",
"to",
"search",
"for",
"configuration",
"files",
".",
"It",
"only",
"allows",
"one",
"path",
"to",
"be",
"entered",
"at",
"a",
"time",
"."
] |
528c2fca29fcba4eb495ae443fa04269278d226b
|
https://github.com/rahmal/rconfig/blob/528c2fca29fcba4eb495ae443fa04269278d226b/lib/rconfig/load_paths.rb#L21-L28
|
21,301 |
rahmal/rconfig
|
lib/rconfig/reload.rb
|
RConfig.Reload.enable_reload=
|
def enable_reload=(reload)
raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(reload)
self.enable_reload = reload
end
|
ruby
|
def enable_reload=(reload)
raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(reload)
self.enable_reload = reload
end
|
[
"def",
"enable_reload",
"=",
"(",
"reload",
")",
"raise",
"ArgumentError",
",",
"'Argument must be true or false.'",
"unless",
"[",
"true",
",",
"false",
"]",
".",
"include?",
"(",
"reload",
")",
"self",
".",
"enable_reload",
"=",
"reload",
"end"
] |
Sets the flag indicating whether or not reload should be executed.
|
[
"Sets",
"the",
"flag",
"indicating",
"whether",
"or",
"not",
"reload",
"should",
"be",
"executed",
"."
] |
528c2fca29fcba4eb495ae443fa04269278d226b
|
https://github.com/rahmal/rconfig/blob/528c2fca29fcba4eb495ae443fa04269278d226b/lib/rconfig/reload.rb#L16-L19
|
21,302 |
rahmal/rconfig
|
lib/rconfig/reload.rb
|
RConfig.Reload.reload_interval=
|
def reload_interval=(interval)
raise ArgumentError, 'Argument must be Integer.' unless interval.kind_of?(Integer)
self.enable_reload = false if interval == 0 # Sett
self.reload_interval = interval
end
|
ruby
|
def reload_interval=(interval)
raise ArgumentError, 'Argument must be Integer.' unless interval.kind_of?(Integer)
self.enable_reload = false if interval == 0 # Sett
self.reload_interval = interval
end
|
[
"def",
"reload_interval",
"=",
"(",
"interval",
")",
"raise",
"ArgumentError",
",",
"'Argument must be Integer.'",
"unless",
"interval",
".",
"kind_of?",
"(",
"Integer",
")",
"self",
".",
"enable_reload",
"=",
"false",
"if",
"interval",
"==",
"0",
"# Sett",
"self",
".",
"reload_interval",
"=",
"interval",
"end"
] |
Sets the number of seconds between reloading of config files
and automatic reload checks. Defaults to 5 minutes. Setting
|
[
"Sets",
"the",
"number",
"of",
"seconds",
"between",
"reloading",
"of",
"config",
"files",
"and",
"automatic",
"reload",
"checks",
".",
"Defaults",
"to",
"5",
"minutes",
".",
"Setting"
] |
528c2fca29fcba4eb495ae443fa04269278d226b
|
https://github.com/rahmal/rconfig/blob/528c2fca29fcba4eb495ae443fa04269278d226b/lib/rconfig/reload.rb#L25-L29
|
21,303 |
rahmal/rconfig
|
lib/rconfig/reload.rb
|
RConfig.Reload.reload
|
def reload(force=false)
raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(force)
if force || reload?
flush_cache
return true
end
false
end
|
ruby
|
def reload(force=false)
raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(force)
if force || reload?
flush_cache
return true
end
false
end
|
[
"def",
"reload",
"(",
"force",
"=",
"false",
")",
"raise",
"ArgumentError",
",",
"'Argument must be true or false.'",
"unless",
"[",
"true",
",",
"false",
"]",
".",
"include?",
"(",
"force",
")",
"if",
"force",
"||",
"reload?",
"flush_cache",
"return",
"true",
"end",
"false",
"end"
] |
Flushes cached config data, so that it can be reloaded from disk.
It is recommended that this should be used with caution, and any
need to reload in a production setting should minimized or
completely avoided if possible.
|
[
"Flushes",
"cached",
"config",
"data",
"so",
"that",
"it",
"can",
"be",
"reloaded",
"from",
"disk",
".",
"It",
"is",
"recommended",
"that",
"this",
"should",
"be",
"used",
"with",
"caution",
"and",
"any",
"need",
"to",
"reload",
"in",
"a",
"production",
"setting",
"should",
"minimized",
"or",
"completely",
"avoided",
"if",
"possible",
"."
] |
528c2fca29fcba4eb495ae443fa04269278d226b
|
https://github.com/rahmal/rconfig/blob/528c2fca29fcba4eb495ae443fa04269278d226b/lib/rconfig/reload.rb#L36-L43
|
21,304 |
metanorma/isodoc
|
lib/isodoc/function/utils.rb
|
IsoDoc::Function.Utils.noko
|
def noko(&block)
doc = ::Nokogiri::XML.parse(NOKOHEAD)
fragment = doc.fragment("")
::Nokogiri::XML::Builder.with fragment, &block
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
l.gsub(/\s*\n/, "")
end
end
|
ruby
|
def noko(&block)
doc = ::Nokogiri::XML.parse(NOKOHEAD)
fragment = doc.fragment("")
::Nokogiri::XML::Builder.with fragment, &block
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
l.gsub(/\s*\n/, "")
end
end
|
[
"def",
"noko",
"(",
"&",
"block",
")",
"doc",
"=",
"::",
"Nokogiri",
"::",
"XML",
".",
"parse",
"(",
"NOKOHEAD",
")",
"fragment",
"=",
"doc",
".",
"fragment",
"(",
"\"\"",
")",
"::",
"Nokogiri",
"::",
"XML",
"::",
"Builder",
".",
"with",
"fragment",
",",
"block",
"fragment",
".",
"to_xml",
"(",
"encoding",
":",
"\"US-ASCII\"",
")",
".",
"lines",
".",
"map",
"do",
"|",
"l",
"|",
"l",
".",
"gsub",
"(",
"/",
"\\s",
"\\n",
"/",
",",
"\"\"",
")",
"end",
"end"
] |
block for processing XML document fragments as XHTML,
to allow for HTMLentities
|
[
"block",
"for",
"processing",
"XML",
"document",
"fragments",
"as",
"XHTML",
"to",
"allow",
"for",
"HTMLentities"
] |
b8b51a28f9aecb7ce3ec1028317e94d0d623036a
|
https://github.com/metanorma/isodoc/blob/b8b51a28f9aecb7ce3ec1028317e94d0d623036a/lib/isodoc/function/utils.rb#L27-L34
|
21,305 |
metanorma/isodoc
|
lib/isodoc/function/xref_gen.rb
|
IsoDoc::Function.XrefGen.anchor_names
|
def anchor_names(docxml)
initial_anchor_names(docxml)
back_anchor_names(docxml)
# preempt clause notes with all other types of note
note_anchor_names(docxml.xpath(ns("//table | //example | //formula | "\
"//figure")))
note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
end
|
ruby
|
def anchor_names(docxml)
initial_anchor_names(docxml)
back_anchor_names(docxml)
# preempt clause notes with all other types of note
note_anchor_names(docxml.xpath(ns("//table | //example | //formula | "\
"//figure")))
note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
end
|
[
"def",
"anchor_names",
"(",
"docxml",
")",
"initial_anchor_names",
"(",
"docxml",
")",
"back_anchor_names",
"(",
"docxml",
")",
"# preempt clause notes with all other types of note",
"note_anchor_names",
"(",
"docxml",
".",
"xpath",
"(",
"ns",
"(",
"\"//table | //example | //formula | \"",
"\"//figure\"",
")",
")",
")",
"note_anchor_names",
"(",
"docxml",
".",
"xpath",
"(",
"ns",
"(",
"SECTIONS_XPATH",
")",
")",
")",
"example_anchor_names",
"(",
"docxml",
".",
"xpath",
"(",
"ns",
"(",
"SECTIONS_XPATH",
")",
")",
")",
"list_anchor_names",
"(",
"docxml",
".",
"xpath",
"(",
"ns",
"(",
"SECTIONS_XPATH",
")",
")",
")",
"end"
] |
extract names for all anchors, xref and label
|
[
"extract",
"names",
"for",
"all",
"anchors",
"xref",
"and",
"label"
] |
b8b51a28f9aecb7ce3ec1028317e94d0d623036a
|
https://github.com/metanorma/isodoc/blob/b8b51a28f9aecb7ce3ec1028317e94d0d623036a/lib/isodoc/function/xref_gen.rb#L125-L134
|
21,306 |
metanorma/isodoc
|
lib/isodoc/function/cleanup.rb
|
IsoDoc::Function.Cleanup.figure_cleanup
|
def figure_cleanup(docxml)
docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
key = figure_get_or_make_dl(f)
f.xpath(".//aside").each do |aside|
figure_aside_process(f, aside, key)
end
end
docxml
end
|
ruby
|
def figure_cleanup(docxml)
docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
key = figure_get_or_make_dl(f)
f.xpath(".//aside").each do |aside|
figure_aside_process(f, aside, key)
end
end
docxml
end
|
[
"def",
"figure_cleanup",
"(",
"docxml",
")",
"docxml",
".",
"xpath",
"(",
"FIGURE_WITH_FOOTNOTES",
")",
".",
"each",
"do",
"|",
"f",
"|",
"key",
"=",
"figure_get_or_make_dl",
"(",
"f",
")",
"f",
".",
"xpath",
"(",
"\".//aside\"",
")",
".",
"each",
"do",
"|",
"aside",
"|",
"figure_aside_process",
"(",
"f",
",",
"aside",
",",
"key",
")",
"end",
"end",
"docxml",
"end"
] |
move footnotes into key, and get rid of footnote reference
since it is in diagram
|
[
"move",
"footnotes",
"into",
"key",
"and",
"get",
"rid",
"of",
"footnote",
"reference",
"since",
"it",
"is",
"in",
"diagram"
] |
b8b51a28f9aecb7ce3ec1028317e94d0d623036a
|
https://github.com/metanorma/isodoc/blob/b8b51a28f9aecb7ce3ec1028317e94d0d623036a/lib/isodoc/function/cleanup.rb#L58-L66
|
21,307 |
metanorma/isodoc
|
lib/isodoc/function/xref_sect_gen.rb
|
IsoDoc::Function.XrefSectGen.preface_names
|
def preface_names(clause)
return if clause.nil?
@anchors[clause["id"]] =
{ label: nil, level: 1, xref: preface_clause_name(clause), type: "clause" }
clause.xpath(ns("./clause | ./terms | ./term | ./definitions | ./references")).each_with_index do |c, i|
preface_names1(c, c.at(ns("./title"))&.text, "#{preface_clause_name(clause)}, #{i+1}", 2)
end
end
|
ruby
|
def preface_names(clause)
return if clause.nil?
@anchors[clause["id"]] =
{ label: nil, level: 1, xref: preface_clause_name(clause), type: "clause" }
clause.xpath(ns("./clause | ./terms | ./term | ./definitions | ./references")).each_with_index do |c, i|
preface_names1(c, c.at(ns("./title"))&.text, "#{preface_clause_name(clause)}, #{i+1}", 2)
end
end
|
[
"def",
"preface_names",
"(",
"clause",
")",
"return",
"if",
"clause",
".",
"nil?",
"@anchors",
"[",
"clause",
"[",
"\"id\"",
"]",
"]",
"=",
"{",
"label",
":",
"nil",
",",
"level",
":",
"1",
",",
"xref",
":",
"preface_clause_name",
"(",
"clause",
")",
",",
"type",
":",
"\"clause\"",
"}",
"clause",
".",
"xpath",
"(",
"ns",
"(",
"\"./clause | ./terms | ./term | ./definitions | ./references\"",
")",
")",
".",
"each_with_index",
"do",
"|",
"c",
",",
"i",
"|",
"preface_names1",
"(",
"c",
",",
"c",
".",
"at",
"(",
"ns",
"(",
"\"./title\"",
")",
")",
"&.",
"text",
",",
"\"#{preface_clause_name(clause)}, #{i+1}\"",
",",
"2",
")",
"end",
"end"
] |
in StanDoc, prefaces have no numbering; they are referenced only by title
|
[
"in",
"StanDoc",
"prefaces",
"have",
"no",
"numbering",
";",
"they",
"are",
"referenced",
"only",
"by",
"title"
] |
b8b51a28f9aecb7ce3ec1028317e94d0d623036a
|
https://github.com/metanorma/isodoc/blob/b8b51a28f9aecb7ce3ec1028317e94d0d623036a/lib/isodoc/function/xref_sect_gen.rb#L40-L47
|
21,308 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.destroy_sandbox
|
def destroy_sandbox
if File.directory?(Strainer.sandbox_path)
Strainer.ui.debug " Destroying sandbox at '#{Strainer.sandbox_path}'"
FileUtils.rm_rf(Strainer.sandbox_path)
else
Strainer.ui.debug " Sandbox does not exist... skipping"
end
end
|
ruby
|
def destroy_sandbox
if File.directory?(Strainer.sandbox_path)
Strainer.ui.debug " Destroying sandbox at '#{Strainer.sandbox_path}'"
FileUtils.rm_rf(Strainer.sandbox_path)
else
Strainer.ui.debug " Sandbox does not exist... skipping"
end
end
|
[
"def",
"destroy_sandbox",
"if",
"File",
".",
"directory?",
"(",
"Strainer",
".",
"sandbox_path",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\" Destroying sandbox at '#{Strainer.sandbox_path}'\"",
"FileUtils",
".",
"rm_rf",
"(",
"Strainer",
".",
"sandbox_path",
")",
"else",
"Strainer",
".",
"ui",
".",
"debug",
"\" Sandbox does not exist... skipping\"",
"end",
"end"
] |
Destroy the current sandbox, if it exists
|
[
"Destroy",
"the",
"current",
"sandbox",
"if",
"it",
"exists"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L70-L77
|
21,309 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.create_sandbox
|
def create_sandbox
unless File.directory?(Strainer.sandbox_path)
Strainer.ui.debug " Creating sandbox at '#{Strainer.sandbox_path}'"
FileUtils.mkdir_p(Strainer.sandbox_path)
end
copy_globals
place_knife_rb
copy_cookbooks
end
|
ruby
|
def create_sandbox
unless File.directory?(Strainer.sandbox_path)
Strainer.ui.debug " Creating sandbox at '#{Strainer.sandbox_path}'"
FileUtils.mkdir_p(Strainer.sandbox_path)
end
copy_globals
place_knife_rb
copy_cookbooks
end
|
[
"def",
"create_sandbox",
"unless",
"File",
".",
"directory?",
"(",
"Strainer",
".",
"sandbox_path",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\" Creating sandbox at '#{Strainer.sandbox_path}'\"",
"FileUtils",
".",
"mkdir_p",
"(",
"Strainer",
".",
"sandbox_path",
")",
"end",
"copy_globals",
"place_knife_rb",
"copy_cookbooks",
"end"
] |
Create the sandbox unless it already exits
|
[
"Create",
"the",
"sandbox",
"unless",
"it",
"already",
"exits"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L80-L89
|
21,310 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.load_cookbooks
|
def load_cookbooks(cookbook_names)
Strainer.ui.debug "Sandbox#load_cookbooks(#{cookbook_names.inspect})"
cookbook_names.collect{ |cookbook_name| load_cookbook(cookbook_name) }
end
|
ruby
|
def load_cookbooks(cookbook_names)
Strainer.ui.debug "Sandbox#load_cookbooks(#{cookbook_names.inspect})"
cookbook_names.collect{ |cookbook_name| load_cookbook(cookbook_name) }
end
|
[
"def",
"load_cookbooks",
"(",
"cookbook_names",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\"Sandbox#load_cookbooks(#{cookbook_names.inspect})\"",
"cookbook_names",
".",
"collect",
"{",
"|",
"cookbook_name",
"|",
"load_cookbook",
"(",
"cookbook_name",
")",
"}",
"end"
] |
Load a cookbook from the given array of cookbook names
@param [Array<String>] cookbook_names
the list of cookbooks to search for
@return [Array<Berkshelf::CachedCookbook>]
the array of cached cookbooks
|
[
"Load",
"a",
"cookbook",
"from",
"the",
"given",
"array",
"of",
"cookbook",
"names"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L145-L148
|
21,311 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.load_cookbook
|
def load_cookbook(cookbook_name)
Strainer.ui.debug "Sandbox#load_cookbook('#{cookbook_name.inspect}')"
cookbook_path = cookbooks_paths.find { |path| path.join(cookbook_name).exist? }
cookbook = if cookbook_path
path = cookbook_path.join(cookbook_name)
Strainer.ui.debug " found cookbook at '#{path}'"
begin
Berkshelf::CachedCookbook.from_path(path)
rescue Berkshelf::CookbookNotFound
raise Strainer::Error::CookbookNotFound, "'#{path}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?"
end
else
Strainer.ui.debug " did not find '#{cookbook_name}' in any of the sources - resorting to the default cookbook_store..."
Berkshelf.cookbook_store.cookbooks(cookbook_name).last
end
cookbook || raise(Strainer::Error::CookbookNotFound, "Could not find '#{cookbook_name}' in any of the sources.")
end
|
ruby
|
def load_cookbook(cookbook_name)
Strainer.ui.debug "Sandbox#load_cookbook('#{cookbook_name.inspect}')"
cookbook_path = cookbooks_paths.find { |path| path.join(cookbook_name).exist? }
cookbook = if cookbook_path
path = cookbook_path.join(cookbook_name)
Strainer.ui.debug " found cookbook at '#{path}'"
begin
Berkshelf::CachedCookbook.from_path(path)
rescue Berkshelf::CookbookNotFound
raise Strainer::Error::CookbookNotFound, "'#{path}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?"
end
else
Strainer.ui.debug " did not find '#{cookbook_name}' in any of the sources - resorting to the default cookbook_store..."
Berkshelf.cookbook_store.cookbooks(cookbook_name).last
end
cookbook || raise(Strainer::Error::CookbookNotFound, "Could not find '#{cookbook_name}' in any of the sources.")
end
|
[
"def",
"load_cookbook",
"(",
"cookbook_name",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\"Sandbox#load_cookbook('#{cookbook_name.inspect}')\"",
"cookbook_path",
"=",
"cookbooks_paths",
".",
"find",
"{",
"|",
"path",
"|",
"path",
".",
"join",
"(",
"cookbook_name",
")",
".",
"exist?",
"}",
"cookbook",
"=",
"if",
"cookbook_path",
"path",
"=",
"cookbook_path",
".",
"join",
"(",
"cookbook_name",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\" found cookbook at '#{path}'\"",
"begin",
"Berkshelf",
"::",
"CachedCookbook",
".",
"from_path",
"(",
"path",
")",
"rescue",
"Berkshelf",
"::",
"CookbookNotFound",
"raise",
"Strainer",
"::",
"Error",
"::",
"CookbookNotFound",
",",
"\"'#{path}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?\"",
"end",
"else",
"Strainer",
".",
"ui",
".",
"debug",
"\" did not find '#{cookbook_name}' in any of the sources - resorting to the default cookbook_store...\"",
"Berkshelf",
".",
"cookbook_store",
".",
"cookbooks",
"(",
"cookbook_name",
")",
".",
"last",
"end",
"cookbook",
"||",
"raise",
"(",
"Strainer",
"::",
"Error",
"::",
"CookbookNotFound",
",",
"\"Could not find '#{cookbook_name}' in any of the sources.\"",
")",
"end"
] |
Load an individual cookbook by its name
@param [String] cookbook_name
the name of the cookbook to load
@return [Berkshelf::CachedCookbook]
the cached cookbook
@raise [Strainer::Error::CookbookNotFound]
when the cookbook was not found in any of the sources
|
[
"Load",
"an",
"individual",
"cookbook",
"by",
"its",
"name"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L158-L177
|
21,312 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.load_self
|
def load_self
Strainer.ui.debug "Sandbox#load_self"
begin
Berkshelf::CachedCookbook.from_path(File.expand_path('.'))
rescue Berkshelf::CookbookNotFound
raise Strainer::Error::CookbookNotFound, "'#{File.expand_path('.')}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?"
end
end
|
ruby
|
def load_self
Strainer.ui.debug "Sandbox#load_self"
begin
Berkshelf::CachedCookbook.from_path(File.expand_path('.'))
rescue Berkshelf::CookbookNotFound
raise Strainer::Error::CookbookNotFound, "'#{File.expand_path('.')}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?"
end
end
|
[
"def",
"load_self",
"Strainer",
".",
"ui",
".",
"debug",
"\"Sandbox#load_self\"",
"begin",
"Berkshelf",
"::",
"CachedCookbook",
".",
"from_path",
"(",
"File",
".",
"expand_path",
"(",
"'.'",
")",
")",
"rescue",
"Berkshelf",
"::",
"CookbookNotFound",
"raise",
"Strainer",
"::",
"Error",
"::",
"CookbookNotFound",
",",
"\"'#{File.expand_path('.')}' existed, but I could not extract a cookbook. Is there a 'metadata.rb'?\"",
"end",
"end"
] |
Load the current root entirely as a cookbook. This is useful when testing within
a cookbook, instead of a chef repo
|
[
"Load",
"the",
"current",
"root",
"entirely",
"as",
"a",
"cookbook",
".",
"This",
"is",
"useful",
"when",
"testing",
"within",
"a",
"cookbook",
"instead",
"of",
"a",
"chef",
"repo"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L181-L189
|
21,313 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.cookbooks_and_dependencies
|
def cookbooks_and_dependencies
loaded_dependencies = Hash.new(false)
dependencies = @cookbooks.dup
dependencies.each do |cookbook|
loaded_dependencies[cookbook.cookbook_name] = true
cookbook.metadata.dependencies.keys.each do |dependency_name|
unless loaded_dependencies[dependency_name]
dependencies << load_cookbook(dependency_name)
loaded_dependencies[dependency_name] = true
end
end
end
end
|
ruby
|
def cookbooks_and_dependencies
loaded_dependencies = Hash.new(false)
dependencies = @cookbooks.dup
dependencies.each do |cookbook|
loaded_dependencies[cookbook.cookbook_name] = true
cookbook.metadata.dependencies.keys.each do |dependency_name|
unless loaded_dependencies[dependency_name]
dependencies << load_cookbook(dependency_name)
loaded_dependencies[dependency_name] = true
end
end
end
end
|
[
"def",
"cookbooks_and_dependencies",
"loaded_dependencies",
"=",
"Hash",
".",
"new",
"(",
"false",
")",
"dependencies",
"=",
"@cookbooks",
".",
"dup",
"dependencies",
".",
"each",
"do",
"|",
"cookbook",
"|",
"loaded_dependencies",
"[",
"cookbook",
".",
"cookbook_name",
"]",
"=",
"true",
"cookbook",
".",
"metadata",
".",
"dependencies",
".",
"keys",
".",
"each",
"do",
"|",
"dependency_name",
"|",
"unless",
"loaded_dependencies",
"[",
"dependency_name",
"]",
"dependencies",
"<<",
"load_cookbook",
"(",
"dependency_name",
")",
"loaded_dependencies",
"[",
"dependency_name",
"]",
"=",
"true",
"end",
"end",
"end",
"end"
] |
Collect all cookbooks and the dependencies specified in their metadata.rb
for copying
@return [Array<Berkshelf::CachedCookbook>]
a list of cached cookbooks
|
[
"Collect",
"all",
"cookbooks",
"and",
"the",
"dependencies",
"specified",
"in",
"their",
"metadata",
".",
"rb",
"for",
"copying"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L216-L230
|
21,314 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.chef_repo?
|
def chef_repo?
@_chef_repo ||= begin
chef_folders = %w(.chef certificates config cookbooks data_bags environments roles)
(root_folders & chef_folders).size > 2
end
end
|
ruby
|
def chef_repo?
@_chef_repo ||= begin
chef_folders = %w(.chef certificates config cookbooks data_bags environments roles)
(root_folders & chef_folders).size > 2
end
end
|
[
"def",
"chef_repo?",
"@_chef_repo",
"||=",
"begin",
"chef_folders",
"=",
"%w(",
".chef",
"certificates",
"config",
"cookbooks",
"data_bags",
"environments",
"roles",
")",
"(",
"root_folders",
"&",
"chef_folders",
")",
".",
"size",
">",
"2",
"end",
"end"
] |
Determines if the current project is a chef repo
@return [Boolean]
true if the current project is a chef repo, false otherwise
|
[
"Determines",
"if",
"the",
"current",
"project",
"is",
"a",
"chef",
"repo"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L244-L249
|
21,315 |
customink/strainer
|
lib/strainer/sandbox.rb
|
Strainer.Sandbox.root_folders
|
def root_folders
@root_folders ||= Dir.glob("#{Dir.pwd}/*", File::FNM_DOTMATCH).collect do |f|
File.basename(f) if File.directory?(f)
end.reject { |dir| %w(. ..).include?(dir) }.compact!
end
|
ruby
|
def root_folders
@root_folders ||= Dir.glob("#{Dir.pwd}/*", File::FNM_DOTMATCH).collect do |f|
File.basename(f) if File.directory?(f)
end.reject { |dir| %w(. ..).include?(dir) }.compact!
end
|
[
"def",
"root_folders",
"@root_folders",
"||=",
"Dir",
".",
"glob",
"(",
"\"#{Dir.pwd}/*\"",
",",
"File",
"::",
"FNM_DOTMATCH",
")",
".",
"collect",
"do",
"|",
"f",
"|",
"File",
".",
"basename",
"(",
"f",
")",
"if",
"File",
".",
"directory?",
"(",
"f",
")",
"end",
".",
"reject",
"{",
"|",
"dir",
"|",
"%w(",
".",
"..",
")",
".",
"include?",
"(",
"dir",
")",
"}",
".",
"compact!",
"end"
] |
Return a list of all directory folders at the root of the repo.
This is useful for detecting if it's a chef repo or cookbook
repo.
@return [Array]
the list of root-level directories
|
[
"Return",
"a",
"list",
"of",
"all",
"directory",
"folders",
"at",
"the",
"root",
"of",
"the",
"repo",
".",
"This",
"is",
"useful",
"for",
"detecting",
"if",
"it",
"s",
"a",
"chef",
"repo",
"or",
"cookbook",
"repo",
"."
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/sandbox.rb#L257-L261
|
21,316 |
customink/strainer
|
lib/strainer/runner.rb
|
Strainer.Runner.run!
|
def run!
@cookbooks.each do |name, c|
cookbook = c[:cookbook]
strainerfile = c[:strainerfile]
Strainer.ui.debug "Starting Runner for #{cookbook.cookbook_name} (#{cookbook.version})"
Strainer.ui.header("# Straining '#{cookbook.cookbook_name} (v#{cookbook.version})'")
strainerfile.commands.each do |command|
success = command.run!
@report[cookbook.cookbook_name] ||= {}
@report[cookbook.cookbook_name][command.label] = success
Strainer.ui.debug "Strainer::Runner#report: #{@report.inspect}"
if options[:fail_fast] && !success
Strainer.ui.debug "Run was not successful and --fail-fast was specified"
Strainer.ui.fatal "Exited early because '--fail-fast' was specified. Some tests may have been skipped!"
return false
end
end
end
# Move the logfile back over
if File.exist?(Strainer.sandbox_path.join('strainer.out'))
FileUtils.mv(Strainer.logfile_path, Strainer.sandbox_path.join('strainer.out'))
end
success = @report.values.collect(&:values).flatten.all?
msg = success ? "Strainer marked build OK" : "Strainer marked build as failure"
Strainer.ui.say msg
return success
end
|
ruby
|
def run!
@cookbooks.each do |name, c|
cookbook = c[:cookbook]
strainerfile = c[:strainerfile]
Strainer.ui.debug "Starting Runner for #{cookbook.cookbook_name} (#{cookbook.version})"
Strainer.ui.header("# Straining '#{cookbook.cookbook_name} (v#{cookbook.version})'")
strainerfile.commands.each do |command|
success = command.run!
@report[cookbook.cookbook_name] ||= {}
@report[cookbook.cookbook_name][command.label] = success
Strainer.ui.debug "Strainer::Runner#report: #{@report.inspect}"
if options[:fail_fast] && !success
Strainer.ui.debug "Run was not successful and --fail-fast was specified"
Strainer.ui.fatal "Exited early because '--fail-fast' was specified. Some tests may have been skipped!"
return false
end
end
end
# Move the logfile back over
if File.exist?(Strainer.sandbox_path.join('strainer.out'))
FileUtils.mv(Strainer.logfile_path, Strainer.sandbox_path.join('strainer.out'))
end
success = @report.values.collect(&:values).flatten.all?
msg = success ? "Strainer marked build OK" : "Strainer marked build as failure"
Strainer.ui.say msg
return success
end
|
[
"def",
"run!",
"@cookbooks",
".",
"each",
"do",
"|",
"name",
",",
"c",
"|",
"cookbook",
"=",
"c",
"[",
":cookbook",
"]",
"strainerfile",
"=",
"c",
"[",
":strainerfile",
"]",
"Strainer",
".",
"ui",
".",
"debug",
"\"Starting Runner for #{cookbook.cookbook_name} (#{cookbook.version})\"",
"Strainer",
".",
"ui",
".",
"header",
"(",
"\"# Straining '#{cookbook.cookbook_name} (v#{cookbook.version})'\"",
")",
"strainerfile",
".",
"commands",
".",
"each",
"do",
"|",
"command",
"|",
"success",
"=",
"command",
".",
"run!",
"@report",
"[",
"cookbook",
".",
"cookbook_name",
"]",
"||=",
"{",
"}",
"@report",
"[",
"cookbook",
".",
"cookbook_name",
"]",
"[",
"command",
".",
"label",
"]",
"=",
"success",
"Strainer",
".",
"ui",
".",
"debug",
"\"Strainer::Runner#report: #{@report.inspect}\"",
"if",
"options",
"[",
":fail_fast",
"]",
"&&",
"!",
"success",
"Strainer",
".",
"ui",
".",
"debug",
"\"Run was not successful and --fail-fast was specified\"",
"Strainer",
".",
"ui",
".",
"fatal",
"\"Exited early because '--fail-fast' was specified. Some tests may have been skipped!\"",
"return",
"false",
"end",
"end",
"end",
"# Move the logfile back over",
"if",
"File",
".",
"exist?",
"(",
"Strainer",
".",
"sandbox_path",
".",
"join",
"(",
"'strainer.out'",
")",
")",
"FileUtils",
".",
"mv",
"(",
"Strainer",
".",
"logfile_path",
",",
"Strainer",
".",
"sandbox_path",
".",
"join",
"(",
"'strainer.out'",
")",
")",
"end",
"success",
"=",
"@report",
".",
"values",
".",
"collect",
"(",
":values",
")",
".",
"flatten",
".",
"all?",
"msg",
"=",
"success",
"?",
"\"Strainer marked build OK\"",
":",
"\"Strainer marked build as failure\"",
"Strainer",
".",
"ui",
".",
"say",
"msg",
"return",
"success",
"end"
] |
Creates a Strainer runner
@param [Array<String>] cookbook_names
an array of cookbook_names to test and load into the sandbox
@param [Hash] options
a list of options to pass along
Runs the Strainer runner
|
[
"Creates",
"a",
"Strainer",
"runner"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/runner.rb#L44-L78
|
21,317 |
customink/strainer
|
lib/strainer/strainerfile.rb
|
Strainer.Strainerfile.commands
|
def commands
@commands ||= if @options[:except]
@all_commands.reject{ |command| @options[:except].include?(command.label) }
elsif @options[:only]
@all_commands.select{ |command| @options[:only].include?(command.label) }
else
@all_commands
end
end
|
ruby
|
def commands
@commands ||= if @options[:except]
@all_commands.reject{ |command| @options[:except].include?(command.label) }
elsif @options[:only]
@all_commands.select{ |command| @options[:only].include?(command.label) }
else
@all_commands
end
end
|
[
"def",
"commands",
"@commands",
"||=",
"if",
"@options",
"[",
":except",
"]",
"@all_commands",
".",
"reject",
"{",
"|",
"command",
"|",
"@options",
"[",
":except",
"]",
".",
"include?",
"(",
"command",
".",
"label",
")",
"}",
"elsif",
"@options",
"[",
":only",
"]",
"@all_commands",
".",
"select",
"{",
"|",
"command",
"|",
"@options",
"[",
":only",
"]",
".",
"include?",
"(",
"command",
".",
"label",
")",
"}",
"else",
"@all_commands",
"end",
"end"
] |
Instantiate an instance of this class from a cookbook
@param [Berkshelf::CachedCookbook] cookbook
the cached cookbook to search for a Strainerfile
@param [Hash] options
a list of options to pass along
@return [Strainerfile]
an instance of this class
Get the list of commands to run, filtered by the `@options` hash for either
`:ignore` or `:only`
@return [Array<Strainer::Command>]
the list of commands to execute
|
[
"Instantiate",
"an",
"instance",
"of",
"this",
"class",
"from",
"a",
"cookbook"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/strainerfile.rb#L62-L70
|
21,318 |
customink/strainer
|
lib/strainer/strainerfile.rb
|
Strainer.Strainerfile.load!
|
def load!
return if @all_commands
contents = File.read @strainerfile
contents.strip!
contents.gsub! '$COOKBOOK', @cookbook.cookbook_name
contents.gsub! '$SANDBOX', Strainer.sandbox_path.to_s
# Drop empty lines and comments
lines = contents.split("\n")
lines.reject!{ |line| line.strip.empty? || line.strip.start_with?('#') }
lines.compact!
lines ||= []
# Parse the line and split it into the label and command parts
#
# @example Example Line
# foodcritic -f any phantomjs
@all_commands = lines.collect{ |line| Command.new(line, @cookbook, @options) }
end
|
ruby
|
def load!
return if @all_commands
contents = File.read @strainerfile
contents.strip!
contents.gsub! '$COOKBOOK', @cookbook.cookbook_name
contents.gsub! '$SANDBOX', Strainer.sandbox_path.to_s
# Drop empty lines and comments
lines = contents.split("\n")
lines.reject!{ |line| line.strip.empty? || line.strip.start_with?('#') }
lines.compact!
lines ||= []
# Parse the line and split it into the label and command parts
#
# @example Example Line
# foodcritic -f any phantomjs
@all_commands = lines.collect{ |line| Command.new(line, @cookbook, @options) }
end
|
[
"def",
"load!",
"return",
"if",
"@all_commands",
"contents",
"=",
"File",
".",
"read",
"@strainerfile",
"contents",
".",
"strip!",
"contents",
".",
"gsub!",
"'$COOKBOOK'",
",",
"@cookbook",
".",
"cookbook_name",
"contents",
".",
"gsub!",
"'$SANDBOX'",
",",
"Strainer",
".",
"sandbox_path",
".",
"to_s",
"# Drop empty lines and comments",
"lines",
"=",
"contents",
".",
"split",
"(",
"\"\\n\"",
")",
"lines",
".",
"reject!",
"{",
"|",
"line",
"|",
"line",
".",
"strip",
".",
"empty?",
"||",
"line",
".",
"strip",
".",
"start_with?",
"(",
"'#'",
")",
"}",
"lines",
".",
"compact!",
"lines",
"||=",
"[",
"]",
"# Parse the line and split it into the label and command parts",
"#",
"# @example Example Line",
"# foodcritic -f any phantomjs",
"@all_commands",
"=",
"lines",
".",
"collect",
"{",
"|",
"line",
"|",
"Command",
".",
"new",
"(",
"line",
",",
"@cookbook",
",",
"@options",
")",
"}",
"end"
] |
Parse the given Strainerfile
|
[
"Parse",
"the",
"given",
"Strainerfile"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/strainerfile.rb#L80-L98
|
21,319 |
customink/strainer
|
lib/strainer/command.rb
|
Strainer.Command.speak
|
def speak(message, options = {})
message.to_s.strip.split("\n").each do |line|
next if line.strip.empty?
line.gsub! Strainer.sandbox_path.to_s, @cookbook.original_path.dirname.to_s
Strainer.ui.say label_with_padding + line, options
end
end
|
ruby
|
def speak(message, options = {})
message.to_s.strip.split("\n").each do |line|
next if line.strip.empty?
line.gsub! Strainer.sandbox_path.to_s, @cookbook.original_path.dirname.to_s
Strainer.ui.say label_with_padding + line, options
end
end
|
[
"def",
"speak",
"(",
"message",
",",
"options",
"=",
"{",
"}",
")",
"message",
".",
"to_s",
".",
"strip",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"each",
"do",
"|",
"line",
"|",
"next",
"if",
"line",
".",
"strip",
".",
"empty?",
"line",
".",
"gsub!",
"Strainer",
".",
"sandbox_path",
".",
"to_s",
",",
"@cookbook",
".",
"original_path",
".",
"dirname",
".",
"to_s",
"Strainer",
".",
"ui",
".",
"say",
"label_with_padding",
"+",
"line",
",",
"options",
"end",
"end"
] |
Have this command output text, prefixing with its output with the
command name
@param [String] message
the message to speak
@param [Hash] options
a list of options to pass along
|
[
"Have",
"this",
"command",
"output",
"text",
"prefixing",
"with",
"its",
"output",
"with",
"the",
"command",
"name"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/command.rb#L99-L106
|
21,320 |
customink/strainer
|
lib/strainer/command.rb
|
Strainer.Command.inside_sandbox
|
def inside_sandbox(&block)
Strainer.ui.debug "Changing working directory to '#{Strainer.sandbox_path}'"
original_pwd = ENV['PWD']
ENV['PWD'] = Strainer.sandbox_path.to_s
success = Dir.chdir(Strainer.sandbox_path, &block)
ENV['PWD'] = original_pwd
Strainer.ui.debug "Restored working directory to '#{original_pwd}'"
success
end
|
ruby
|
def inside_sandbox(&block)
Strainer.ui.debug "Changing working directory to '#{Strainer.sandbox_path}'"
original_pwd = ENV['PWD']
ENV['PWD'] = Strainer.sandbox_path.to_s
success = Dir.chdir(Strainer.sandbox_path, &block)
ENV['PWD'] = original_pwd
Strainer.ui.debug "Restored working directory to '#{original_pwd}'"
success
end
|
[
"def",
"inside_sandbox",
"(",
"&",
"block",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\"Changing working directory to '#{Strainer.sandbox_path}'\"",
"original_pwd",
"=",
"ENV",
"[",
"'PWD'",
"]",
"ENV",
"[",
"'PWD'",
"]",
"=",
"Strainer",
".",
"sandbox_path",
".",
"to_s",
"success",
"=",
"Dir",
".",
"chdir",
"(",
"Strainer",
".",
"sandbox_path",
",",
"block",
")",
"ENV",
"[",
"'PWD'",
"]",
"=",
"original_pwd",
"Strainer",
".",
"ui",
".",
"debug",
"\"Restored working directory to '#{original_pwd}'\"",
"success",
"end"
] |
Execute a block inside the sandbox directory defined in 'Strainer.sandbox_path'.
This will first change the 'PWD' env variable to the sandbox path, and then
pass the given block into 'Dir.chdir'. 'PWD' is restored to the original value
when the block is finished.
@yield The block to execute inside the sandbox
@return [Boolean]
`true` if the command exited successfully, `false` otherwise
|
[
"Execute",
"a",
"block",
"inside",
"the",
"sandbox",
"directory",
"defined",
"in",
"Strainer",
".",
"sandbox_path",
".",
"This",
"will",
"first",
"change",
"the",
"PWD",
"env",
"variable",
"to",
"the",
"sandbox",
"path",
"and",
"then",
"pass",
"the",
"given",
"block",
"into",
"Dir",
".",
"chdir",
".",
"PWD",
"is",
"restored",
"to",
"the",
"original",
"value",
"when",
"the",
"block",
"is",
"finished",
"."
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/command.rb#L145-L155
|
21,321 |
customink/strainer
|
lib/strainer/command.rb
|
Strainer.Command.inside_cookbook
|
def inside_cookbook(&block)
cookbook_path = File.join(Strainer.sandbox_path.to_s, @cookbook.cookbook_name)
Strainer.ui.debug "Changing working directory to '#{cookbook_path}'"
original_pwd = ENV['PWD']
ENV['PWD'] = cookbook_path
success = Dir.chdir(cookbook_path, &block)
ENV['PWD'] = original_pwd
Strainer.ui.debug "Restoring working directory to '#{original_pwd}'"
success
end
|
ruby
|
def inside_cookbook(&block)
cookbook_path = File.join(Strainer.sandbox_path.to_s, @cookbook.cookbook_name)
Strainer.ui.debug "Changing working directory to '#{cookbook_path}'"
original_pwd = ENV['PWD']
ENV['PWD'] = cookbook_path
success = Dir.chdir(cookbook_path, &block)
ENV['PWD'] = original_pwd
Strainer.ui.debug "Restoring working directory to '#{original_pwd}'"
success
end
|
[
"def",
"inside_cookbook",
"(",
"&",
"block",
")",
"cookbook_path",
"=",
"File",
".",
"join",
"(",
"Strainer",
".",
"sandbox_path",
".",
"to_s",
",",
"@cookbook",
".",
"cookbook_name",
")",
"Strainer",
".",
"ui",
".",
"debug",
"\"Changing working directory to '#{cookbook_path}'\"",
"original_pwd",
"=",
"ENV",
"[",
"'PWD'",
"]",
"ENV",
"[",
"'PWD'",
"]",
"=",
"cookbook_path",
"success",
"=",
"Dir",
".",
"chdir",
"(",
"cookbook_path",
",",
"block",
")",
"ENV",
"[",
"'PWD'",
"]",
"=",
"original_pwd",
"Strainer",
".",
"ui",
".",
"debug",
"\"Restoring working directory to '#{original_pwd}'\"",
"success",
"end"
] |
Execute a block inside the sandboxed cookbook directory.
@yield The block to execute inside the cookbook sandbox
@return [Boolean]
`true` if the command exited successfully, `false` otherwise
|
[
"Execute",
"a",
"block",
"inside",
"the",
"sandboxed",
"cookbook",
"directory",
"."
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/command.rb#L162-L173
|
21,322 |
customink/strainer
|
lib/strainer/command.rb
|
Strainer.Command.run_as_pty
|
def run_as_pty(command)
Strainer.ui.debug 'Using PTY'
PTY.spawn(command) do |r, _, pid|
begin
r.sync
r.each_line { |line| speak line }
rescue Errno::EIO => e
# Ignore this. Otherwise errors will be thrown whenever
# the process is closed
ensure
::Process.wait pid
end
end
end
|
ruby
|
def run_as_pty(command)
Strainer.ui.debug 'Using PTY'
PTY.spawn(command) do |r, _, pid|
begin
r.sync
r.each_line { |line| speak line }
rescue Errno::EIO => e
# Ignore this. Otherwise errors will be thrown whenever
# the process is closed
ensure
::Process.wait pid
end
end
end
|
[
"def",
"run_as_pty",
"(",
"command",
")",
"Strainer",
".",
"ui",
".",
"debug",
"'Using PTY'",
"PTY",
".",
"spawn",
"(",
"command",
")",
"do",
"|",
"r",
",",
"_",
",",
"pid",
"|",
"begin",
"r",
".",
"sync",
"r",
".",
"each_line",
"{",
"|",
"line",
"|",
"speak",
"line",
"}",
"rescue",
"Errno",
"::",
"EIO",
"=>",
"e",
"# Ignore this. Otherwise errors will be thrown whenever",
"# the process is closed",
"ensure",
"::",
"Process",
".",
"wait",
"pid",
"end",
"end",
"end"
] |
Run a command using PTY
@param [String] command
the command to run
|
[
"Run",
"a",
"command",
"using",
"PTY"
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/command.rb#L179-L192
|
21,323 |
customink/strainer
|
lib/strainer/ui.rb
|
Strainer.UI.error
|
def error(message, color = :red)
Strainer.log.error(message)
return if quiet?
message = set_color(message, *color) if color
super(message)
end
|
ruby
|
def error(message, color = :red)
Strainer.log.error(message)
return if quiet?
message = set_color(message, *color) if color
super(message)
end
|
[
"def",
"error",
"(",
"message",
",",
"color",
"=",
":red",
")",
"Strainer",
".",
"log",
".",
"error",
"(",
"message",
")",
"return",
"if",
"quiet?",
"message",
"=",
"set_color",
"(",
"message",
",",
"color",
")",
"if",
"color",
"super",
"(",
"message",
")",
"end"
] |
Print a red error message to the STDERR.
@param [String] message
the message to print
@param [Symbol] color
the color to use
|
[
"Print",
"a",
"red",
"error",
"message",
"to",
"the",
"STDERR",
"."
] |
5a49c4f7896e35e402777395b8160a0b5623546d
|
https://github.com/customink/strainer/blob/5a49c4f7896e35e402777395b8160a0b5623546d/lib/strainer/ui.rb#L104-L110
|
21,324 |
berk/tr8n
|
lib/tr8n/token.rb
|
Tr8n.Token.token_value
|
def token_value(object, options, language)
# token is an array
if object.is_a?(Array)
# if you provided an array, it better have some values
if object.empty?
return raise Tr8n::TokenException.new("Invalid array value for a token: #{full_name}")
end
# if the first value of an array is an array handle it here
if object.first.kind_of?(Enumerable)
return token_array_value(object, options, language)
end
# if the first item in the array is an object, process it
return evaluate_token_method_array(object.first, object, options, language)
elsif object.is_a?(Hash)
# if object is a hash, it must be of a form: {:object => {}, :value => "", :attribute => ""}
# either value can be passed, or the attribute. attribute will be used first
if object[:object].nil?
return raise Tr8n::TokenException.new("Hash token is missing an object key for a token: #{full_name}")
end
value = object[:value]
unless object[:attribute].blank?
value = object[:object][object[:attribute]]
end
if value.blank?
return raise Tr8n::TokenException.new("Hash object is missing a value or attribute key for a token: #{full_name}")
end
object = value
end
# simple token
sanitize_token_value(object, object.to_s, options, language)
end
|
ruby
|
def token_value(object, options, language)
# token is an array
if object.is_a?(Array)
# if you provided an array, it better have some values
if object.empty?
return raise Tr8n::TokenException.new("Invalid array value for a token: #{full_name}")
end
# if the first value of an array is an array handle it here
if object.first.kind_of?(Enumerable)
return token_array_value(object, options, language)
end
# if the first item in the array is an object, process it
return evaluate_token_method_array(object.first, object, options, language)
elsif object.is_a?(Hash)
# if object is a hash, it must be of a form: {:object => {}, :value => "", :attribute => ""}
# either value can be passed, or the attribute. attribute will be used first
if object[:object].nil?
return raise Tr8n::TokenException.new("Hash token is missing an object key for a token: #{full_name}")
end
value = object[:value]
unless object[:attribute].blank?
value = object[:object][object[:attribute]]
end
if value.blank?
return raise Tr8n::TokenException.new("Hash object is missing a value or attribute key for a token: #{full_name}")
end
object = value
end
# simple token
sanitize_token_value(object, object.to_s, options, language)
end
|
[
"def",
"token_value",
"(",
"object",
",",
"options",
",",
"language",
")",
"# token is an array",
"if",
"object",
".",
"is_a?",
"(",
"Array",
")",
"# if you provided an array, it better have some values",
"if",
"object",
".",
"empty?",
"return",
"raise",
"Tr8n",
"::",
"TokenException",
".",
"new",
"(",
"\"Invalid array value for a token: #{full_name}\"",
")",
"end",
"# if the first value of an array is an array handle it here",
"if",
"object",
".",
"first",
".",
"kind_of?",
"(",
"Enumerable",
")",
"return",
"token_array_value",
"(",
"object",
",",
"options",
",",
"language",
")",
"end",
"# if the first item in the array is an object, process it",
"return",
"evaluate_token_method_array",
"(",
"object",
".",
"first",
",",
"object",
",",
"options",
",",
"language",
")",
"elsif",
"object",
".",
"is_a?",
"(",
"Hash",
")",
"# if object is a hash, it must be of a form: {:object => {}, :value => \"\", :attribute => \"\"}",
"# either value can be passed, or the attribute. attribute will be used first",
"if",
"object",
"[",
":object",
"]",
".",
"nil?",
"return",
"raise",
"Tr8n",
"::",
"TokenException",
".",
"new",
"(",
"\"Hash token is missing an object key for a token: #{full_name}\"",
")",
"end",
"value",
"=",
"object",
"[",
":value",
"]",
"unless",
"object",
"[",
":attribute",
"]",
".",
"blank?",
"value",
"=",
"object",
"[",
":object",
"]",
"[",
"object",
"[",
":attribute",
"]",
"]",
"end",
"if",
"value",
".",
"blank?",
"return",
"raise",
"Tr8n",
"::",
"TokenException",
".",
"new",
"(",
"\"Hash object is missing a value or attribute key for a token: #{full_name}\"",
")",
"end",
"object",
"=",
"value",
"end",
"# simple token",
"sanitize_token_value",
"(",
"object",
",",
"object",
".",
"to_s",
",",
"options",
",",
"language",
")",
"end"
] |
evaluate all possible methods for the token value and return sanitized result
|
[
"evaluate",
"all",
"possible",
"methods",
"for",
"the",
"token",
"value",
"and",
"return",
"sanitized",
"result"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/lib/tr8n/token.rb#L378-L415
|
21,325 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.update_rules
|
def update_rules
@rules = rules_by_dependency(parse_language_rules)
unless params[:rule_action]
return render(:partial => "edit_rules")
end
if params[:rule_action].index("add_at")
position = params[:rule_action].split("_").last.to_i
cls = Tr8n::Config.language_rule_dependencies[params[:rule_type]]
@rules[cls.dependency].insert(position, cls.new(:language => tr8n_current_language))
elsif params[:rule_action].index("delete_at")
position = params[:rule_action].split("_").last.to_i
cls = Tr8n::Config.language_rule_dependencies[params[:rule_type]]
@rules[cls.dependency].delete_at(position)
end
render :partial => "edit_rules"
end
|
ruby
|
def update_rules
@rules = rules_by_dependency(parse_language_rules)
unless params[:rule_action]
return render(:partial => "edit_rules")
end
if params[:rule_action].index("add_at")
position = params[:rule_action].split("_").last.to_i
cls = Tr8n::Config.language_rule_dependencies[params[:rule_type]]
@rules[cls.dependency].insert(position, cls.new(:language => tr8n_current_language))
elsif params[:rule_action].index("delete_at")
position = params[:rule_action].split("_").last.to_i
cls = Tr8n::Config.language_rule_dependencies[params[:rule_type]]
@rules[cls.dependency].delete_at(position)
end
render :partial => "edit_rules"
end
|
[
"def",
"update_rules",
"@rules",
"=",
"rules_by_dependency",
"(",
"parse_language_rules",
")",
"unless",
"params",
"[",
":rule_action",
"]",
"return",
"render",
"(",
":partial",
"=>",
"\"edit_rules\"",
")",
"end",
"if",
"params",
"[",
":rule_action",
"]",
".",
"index",
"(",
"\"add_at\"",
")",
"position",
"=",
"params",
"[",
":rule_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"cls",
"=",
"Tr8n",
"::",
"Config",
".",
"language_rule_dependencies",
"[",
"params",
"[",
":rule_type",
"]",
"]",
"@rules",
"[",
"cls",
".",
"dependency",
"]",
".",
"insert",
"(",
"position",
",",
"cls",
".",
"new",
"(",
":language",
"=>",
"tr8n_current_language",
")",
")",
"elsif",
"params",
"[",
":rule_action",
"]",
".",
"index",
"(",
"\"delete_at\"",
")",
"position",
"=",
"params",
"[",
":rule_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"cls",
"=",
"Tr8n",
"::",
"Config",
".",
"language_rule_dependencies",
"[",
"params",
"[",
":rule_type",
"]",
"]",
"@rules",
"[",
"cls",
".",
"dependency",
"]",
".",
"delete_at",
"(",
"position",
")",
"end",
"render",
":partial",
"=>",
"\"edit_rules\"",
"end"
] |
ajax method for updating language rules in edit mode
|
[
"ajax",
"method",
"for",
"updating",
"language",
"rules",
"in",
"edit",
"mode"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L99-L117
|
21,326 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.update_language_cases
|
def update_language_cases
@cases = parse_language_cases
unless params[:case_action]
return render(:partial => "edit_cases")
end
if params[:case_action].index("add_at")
position = params[:case_action].split("_").last.to_i
@cases.insert(position, Tr8n::LanguageCase.new(:language => tr8n_current_language))
elsif params[:case_action].index("delete_at")
position = params[:case_action].split("_").last.to_i
@cases.delete_at(position)
elsif params[:case_action].index("clear_all")
@cases = []
end
render :partial => "edit_language_cases"
end
|
ruby
|
def update_language_cases
@cases = parse_language_cases
unless params[:case_action]
return render(:partial => "edit_cases")
end
if params[:case_action].index("add_at")
position = params[:case_action].split("_").last.to_i
@cases.insert(position, Tr8n::LanguageCase.new(:language => tr8n_current_language))
elsif params[:case_action].index("delete_at")
position = params[:case_action].split("_").last.to_i
@cases.delete_at(position)
elsif params[:case_action].index("clear_all")
@cases = []
end
render :partial => "edit_language_cases"
end
|
[
"def",
"update_language_cases",
"@cases",
"=",
"parse_language_cases",
"unless",
"params",
"[",
":case_action",
"]",
"return",
"render",
"(",
":partial",
"=>",
"\"edit_cases\"",
")",
"end",
"if",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"add_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"@cases",
".",
"insert",
"(",
"position",
",",
"Tr8n",
"::",
"LanguageCase",
".",
"new",
"(",
":language",
"=>",
"tr8n_current_language",
")",
")",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"delete_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"@cases",
".",
"delete_at",
"(",
"position",
")",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"clear_all\"",
")",
"@cases",
"=",
"[",
"]",
"end",
"render",
":partial",
"=>",
"\"edit_language_cases\"",
"end"
] |
ajax method for updating language cases in edit mode
|
[
"ajax",
"method",
"for",
"updating",
"language",
"cases",
"in",
"edit",
"mode"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L120-L138
|
21,327 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.update_language_case_rules
|
def update_language_case_rules
cases = parse_language_cases
case_index = params[:case_index].to_i
lcase = cases[case_index]
if params[:case_action].index("add_rule_at")
position = params[:case_action].split("_").last.to_i
rule_data = params[:edit_rule].merge(:language => tr8n_current_language)
lcase.language_case_rules.insert(position, Tr8n::LanguageCaseRule.new(rule_data))
elsif params[:case_action].index("update_rule_at")
position = params[:case_action].split("_").last.to_i
rule_data = params[:edit_rule].merge(:language => tr8n_current_language)
lcase.language_case_rules[position].definition = params[:edit_rule][:definition]
elsif params[:case_action].index("move_rule_up_at")
position = params[:case_action].split("_").last.to_i
temp_node = lcase.language_case_rules[position-1]
lcase.language_case_rules[position-1] = lcase.language_case_rules[position]
lcase.language_case_rules[position] = temp_node
elsif params[:case_action].index("move_rule_down_at")
position = params[:case_action].split("_").last.to_i
temp_node = lcase.language_case_rules[position+1]
lcase.language_case_rules[position+1] = lcase.language_case_rules[position]
lcase.language_case_rules[position] = temp_node
elsif params[:case_action].index("delete_rule_at")
position = params[:case_action].split("_").last.to_i
lcase.language_case_rules.delete_at(position)
elsif params[:case_action].index("clear_all")
lcase.language_case_rules = []
end
render(:partial => "edit_language_case_rules", :locals => {:lcase => lcase, :case_index => case_index})
end
|
ruby
|
def update_language_case_rules
cases = parse_language_cases
case_index = params[:case_index].to_i
lcase = cases[case_index]
if params[:case_action].index("add_rule_at")
position = params[:case_action].split("_").last.to_i
rule_data = params[:edit_rule].merge(:language => tr8n_current_language)
lcase.language_case_rules.insert(position, Tr8n::LanguageCaseRule.new(rule_data))
elsif params[:case_action].index("update_rule_at")
position = params[:case_action].split("_").last.to_i
rule_data = params[:edit_rule].merge(:language => tr8n_current_language)
lcase.language_case_rules[position].definition = params[:edit_rule][:definition]
elsif params[:case_action].index("move_rule_up_at")
position = params[:case_action].split("_").last.to_i
temp_node = lcase.language_case_rules[position-1]
lcase.language_case_rules[position-1] = lcase.language_case_rules[position]
lcase.language_case_rules[position] = temp_node
elsif params[:case_action].index("move_rule_down_at")
position = params[:case_action].split("_").last.to_i
temp_node = lcase.language_case_rules[position+1]
lcase.language_case_rules[position+1] = lcase.language_case_rules[position]
lcase.language_case_rules[position] = temp_node
elsif params[:case_action].index("delete_rule_at")
position = params[:case_action].split("_").last.to_i
lcase.language_case_rules.delete_at(position)
elsif params[:case_action].index("clear_all")
lcase.language_case_rules = []
end
render(:partial => "edit_language_case_rules", :locals => {:lcase => lcase, :case_index => case_index})
end
|
[
"def",
"update_language_case_rules",
"cases",
"=",
"parse_language_cases",
"case_index",
"=",
"params",
"[",
":case_index",
"]",
".",
"to_i",
"lcase",
"=",
"cases",
"[",
"case_index",
"]",
"if",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"add_rule_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"rule_data",
"=",
"params",
"[",
":edit_rule",
"]",
".",
"merge",
"(",
":language",
"=>",
"tr8n_current_language",
")",
"lcase",
".",
"language_case_rules",
".",
"insert",
"(",
"position",
",",
"Tr8n",
"::",
"LanguageCaseRule",
".",
"new",
"(",
"rule_data",
")",
")",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"update_rule_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"rule_data",
"=",
"params",
"[",
":edit_rule",
"]",
".",
"merge",
"(",
":language",
"=>",
"tr8n_current_language",
")",
"lcase",
".",
"language_case_rules",
"[",
"position",
"]",
".",
"definition",
"=",
"params",
"[",
":edit_rule",
"]",
"[",
":definition",
"]",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"move_rule_up_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"temp_node",
"=",
"lcase",
".",
"language_case_rules",
"[",
"position",
"-",
"1",
"]",
"lcase",
".",
"language_case_rules",
"[",
"position",
"-",
"1",
"]",
"=",
"lcase",
".",
"language_case_rules",
"[",
"position",
"]",
"lcase",
".",
"language_case_rules",
"[",
"position",
"]",
"=",
"temp_node",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"move_rule_down_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"temp_node",
"=",
"lcase",
".",
"language_case_rules",
"[",
"position",
"+",
"1",
"]",
"lcase",
".",
"language_case_rules",
"[",
"position",
"+",
"1",
"]",
"=",
"lcase",
".",
"language_case_rules",
"[",
"position",
"]",
"lcase",
".",
"language_case_rules",
"[",
"position",
"]",
"=",
"temp_node",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"delete_rule_at\"",
")",
"position",
"=",
"params",
"[",
":case_action",
"]",
".",
"split",
"(",
"\"_\"",
")",
".",
"last",
".",
"to_i",
"lcase",
".",
"language_case_rules",
".",
"delete_at",
"(",
"position",
")",
"elsif",
"params",
"[",
":case_action",
"]",
".",
"index",
"(",
"\"clear_all\"",
")",
"lcase",
".",
"language_case_rules",
"=",
"[",
"]",
"end",
"render",
"(",
":partial",
"=>",
"\"edit_language_case_rules\"",
",",
":locals",
"=>",
"{",
":lcase",
"=>",
"lcase",
",",
":case_index",
"=>",
"case_index",
"}",
")",
"end"
] |
ajax method for updating language case rules in edit mode
|
[
"ajax",
"method",
"for",
"updating",
"language",
"case",
"rules",
"in",
"edit",
"mode"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L141-L178
|
21,328 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.select
|
def select
@inline_translations_allowed = false
@inline_translations_enabled = false
if tr8n_current_user_is_translator?
unless tr8n_current_translator.blocked?
@inline_translations_allowed = true
@inline_translations_enabled = tr8n_current_translator.enable_inline_translations?
end
else
@inline_translations_allowed = Tr8n::Config.open_registration_mode?
end
@inline_translations_allowed = true if tr8n_current_user_is_admin?
@source_url = request.env['HTTP_REFERER']
@source_url.gsub!("locale", "previous_locale") if @source_url
@all_languages = Tr8n::Language.enabled_languages
@user_languages = Tr8n::LanguageUser.languages_for(tr8n_current_user) unless tr8n_current_user_is_guest?
render_lightbox
end
|
ruby
|
def select
@inline_translations_allowed = false
@inline_translations_enabled = false
if tr8n_current_user_is_translator?
unless tr8n_current_translator.blocked?
@inline_translations_allowed = true
@inline_translations_enabled = tr8n_current_translator.enable_inline_translations?
end
else
@inline_translations_allowed = Tr8n::Config.open_registration_mode?
end
@inline_translations_allowed = true if tr8n_current_user_is_admin?
@source_url = request.env['HTTP_REFERER']
@source_url.gsub!("locale", "previous_locale") if @source_url
@all_languages = Tr8n::Language.enabled_languages
@user_languages = Tr8n::LanguageUser.languages_for(tr8n_current_user) unless tr8n_current_user_is_guest?
render_lightbox
end
|
[
"def",
"select",
"@inline_translations_allowed",
"=",
"false",
"@inline_translations_enabled",
"=",
"false",
"if",
"tr8n_current_user_is_translator?",
"unless",
"tr8n_current_translator",
".",
"blocked?",
"@inline_translations_allowed",
"=",
"true",
"@inline_translations_enabled",
"=",
"tr8n_current_translator",
".",
"enable_inline_translations?",
"end",
"else",
"@inline_translations_allowed",
"=",
"Tr8n",
"::",
"Config",
".",
"open_registration_mode?",
"end",
"@inline_translations_allowed",
"=",
"true",
"if",
"tr8n_current_user_is_admin?",
"@source_url",
"=",
"request",
".",
"env",
"[",
"'HTTP_REFERER'",
"]",
"@source_url",
".",
"gsub!",
"(",
"\"locale\"",
",",
"\"previous_locale\"",
")",
"if",
"@source_url",
"@all_languages",
"=",
"Tr8n",
"::",
"Language",
".",
"enabled_languages",
"@user_languages",
"=",
"Tr8n",
"::",
"LanguageUser",
".",
"languages_for",
"(",
"tr8n_current_user",
")",
"unless",
"tr8n_current_user_is_guest?",
"render_lightbox",
"end"
] |
language selector window
|
[
"language",
"selector",
"window"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L181-L203
|
21,329 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.switch
|
def switch
language_action = params[:language_action]
return redirect_to_source if tr8n_current_user_is_guest?
if tr8n_current_user_is_translator? # translator mode
if language_action == "toggle_inline_mode"
if tr8n_current_translator.enable_inline_translations?
language_action = "disable_inline_mode"
else
language_action = "enable_inline_mode"
end
end
if language_action == "enable_inline_mode"
tr8n_current_translator.enable_inline_translations!
elsif language_action == "disable_inline_mode"
tr8n_current_translator.disable_inline_translations!
elsif language_action == "switch_language"
tr8n_current_translator.switched_language!(Tr8n::Language.find_by_locale(params[:locale]))
end
elsif language_action == "switch_language" # non-translator mode
Tr8n::LanguageUser.create_or_touch(tr8n_current_user, Tr8n::Language.find_by_locale(params[:locale]))
elsif language_action == "become_translator" # non-translator mode
Tr8n::Translator.register
elsif language_action == "enable_inline_mode" or language_action == "toggle_inline_mode" # non-translator mode
Tr8n::Translator.register.enable_inline_translations!
end
redirect_to_source
end
|
ruby
|
def switch
language_action = params[:language_action]
return redirect_to_source if tr8n_current_user_is_guest?
if tr8n_current_user_is_translator? # translator mode
if language_action == "toggle_inline_mode"
if tr8n_current_translator.enable_inline_translations?
language_action = "disable_inline_mode"
else
language_action = "enable_inline_mode"
end
end
if language_action == "enable_inline_mode"
tr8n_current_translator.enable_inline_translations!
elsif language_action == "disable_inline_mode"
tr8n_current_translator.disable_inline_translations!
elsif language_action == "switch_language"
tr8n_current_translator.switched_language!(Tr8n::Language.find_by_locale(params[:locale]))
end
elsif language_action == "switch_language" # non-translator mode
Tr8n::LanguageUser.create_or_touch(tr8n_current_user, Tr8n::Language.find_by_locale(params[:locale]))
elsif language_action == "become_translator" # non-translator mode
Tr8n::Translator.register
elsif language_action == "enable_inline_mode" or language_action == "toggle_inline_mode" # non-translator mode
Tr8n::Translator.register.enable_inline_translations!
end
redirect_to_source
end
|
[
"def",
"switch",
"language_action",
"=",
"params",
"[",
":language_action",
"]",
"return",
"redirect_to_source",
"if",
"tr8n_current_user_is_guest?",
"if",
"tr8n_current_user_is_translator?",
"# translator mode",
"if",
"language_action",
"==",
"\"toggle_inline_mode\"",
"if",
"tr8n_current_translator",
".",
"enable_inline_translations?",
"language_action",
"=",
"\"disable_inline_mode\"",
"else",
"language_action",
"=",
"\"enable_inline_mode\"",
"end",
"end",
"if",
"language_action",
"==",
"\"enable_inline_mode\"",
"tr8n_current_translator",
".",
"enable_inline_translations!",
"elsif",
"language_action",
"==",
"\"disable_inline_mode\"",
"tr8n_current_translator",
".",
"disable_inline_translations!",
"elsif",
"language_action",
"==",
"\"switch_language\"",
"tr8n_current_translator",
".",
"switched_language!",
"(",
"Tr8n",
"::",
"Language",
".",
"find_by_locale",
"(",
"params",
"[",
":locale",
"]",
")",
")",
"end",
"elsif",
"language_action",
"==",
"\"switch_language\"",
"# non-translator mode",
"Tr8n",
"::",
"LanguageUser",
".",
"create_or_touch",
"(",
"tr8n_current_user",
",",
"Tr8n",
"::",
"Language",
".",
"find_by_locale",
"(",
"params",
"[",
":locale",
"]",
")",
")",
"elsif",
"language_action",
"==",
"\"become_translator\"",
"# non-translator mode",
"Tr8n",
"::",
"Translator",
".",
"register",
"elsif",
"language_action",
"==",
"\"enable_inline_mode\"",
"or",
"language_action",
"==",
"\"toggle_inline_mode\"",
"# non-translator mode",
"Tr8n",
"::",
"Translator",
".",
"register",
".",
"enable_inline_translations!",
"end",
"redirect_to_source",
"end"
] |
language selector processor
|
[
"language",
"selector",
"processor"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L222-L252
|
21,330 |
berk/tr8n
|
app/controllers/tr8n/language_controller.rb
|
Tr8n.LanguageController.parse_language_rules
|
def parse_language_rules
rulz = []
return rulz unless params[:rules]
Tr8n::Config.language_rule_classes.each do |cls|
next unless params[:rules][cls.dependency]
index = 0
while params[:rules][cls.dependency]["#{index}"]
rule_params = params[:rules][cls.dependency]["#{index}"]
rule_definition = params[:rules][cls.dependency]["#{index}"][:definition]
if rule_params.delete(:reset_values) == "true"
rule_definition = {}
end
rule_id = rule_params[:id]
keyword = rule_params[:keyword]
if rule_id.blank?
rulz << cls.new(:keyword => keyword, :definition => rule_definition)
else
rule = cls.find_by_id(rule_id)
rule = cls.new unless rule
rule.keyword = keyword
rule.definition = rule_definition
rulz << rule
end
index += 1
end
end
rulz
end
|
ruby
|
def parse_language_rules
rulz = []
return rulz unless params[:rules]
Tr8n::Config.language_rule_classes.each do |cls|
next unless params[:rules][cls.dependency]
index = 0
while params[:rules][cls.dependency]["#{index}"]
rule_params = params[:rules][cls.dependency]["#{index}"]
rule_definition = params[:rules][cls.dependency]["#{index}"][:definition]
if rule_params.delete(:reset_values) == "true"
rule_definition = {}
end
rule_id = rule_params[:id]
keyword = rule_params[:keyword]
if rule_id.blank?
rulz << cls.new(:keyword => keyword, :definition => rule_definition)
else
rule = cls.find_by_id(rule_id)
rule = cls.new unless rule
rule.keyword = keyword
rule.definition = rule_definition
rulz << rule
end
index += 1
end
end
rulz
end
|
[
"def",
"parse_language_rules",
"rulz",
"=",
"[",
"]",
"return",
"rulz",
"unless",
"params",
"[",
":rules",
"]",
"Tr8n",
"::",
"Config",
".",
"language_rule_classes",
".",
"each",
"do",
"|",
"cls",
"|",
"next",
"unless",
"params",
"[",
":rules",
"]",
"[",
"cls",
".",
"dependency",
"]",
"index",
"=",
"0",
"while",
"params",
"[",
":rules",
"]",
"[",
"cls",
".",
"dependency",
"]",
"[",
"\"#{index}\"",
"]",
"rule_params",
"=",
"params",
"[",
":rules",
"]",
"[",
"cls",
".",
"dependency",
"]",
"[",
"\"#{index}\"",
"]",
"rule_definition",
"=",
"params",
"[",
":rules",
"]",
"[",
"cls",
".",
"dependency",
"]",
"[",
"\"#{index}\"",
"]",
"[",
":definition",
"]",
"if",
"rule_params",
".",
"delete",
"(",
":reset_values",
")",
"==",
"\"true\"",
"rule_definition",
"=",
"{",
"}",
"end",
"rule_id",
"=",
"rule_params",
"[",
":id",
"]",
"keyword",
"=",
"rule_params",
"[",
":keyword",
"]",
"if",
"rule_id",
".",
"blank?",
"rulz",
"<<",
"cls",
".",
"new",
"(",
":keyword",
"=>",
"keyword",
",",
":definition",
"=>",
"rule_definition",
")",
"else",
"rule",
"=",
"cls",
".",
"find_by_id",
"(",
"rule_id",
")",
"rule",
"=",
"cls",
".",
"new",
"unless",
"rule",
"rule",
".",
"keyword",
"=",
"keyword",
"rule",
".",
"definition",
"=",
"rule_definition",
"rulz",
"<<",
"rule",
"end",
"index",
"+=",
"1",
"end",
"end",
"rulz",
"end"
] |
parse with safety - we don't want to disconnect existing translations from those rules
|
[
"parse",
"with",
"safety",
"-",
"we",
"don",
"t",
"want",
"to",
"disconnect",
"existing",
"translations",
"from",
"those",
"rules"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_controller.rb#L275-L308
|
21,331 |
berk/tr8n
|
app/controllers/tr8n/language_cases_controller.rb
|
Tr8n.LanguageCasesController.index
|
def index
@maps = Tr8n::LanguageCaseValueMap.where("language_id = ? and (reported is null or reported = ?)", tr8n_current_language.id, false)
@maps = @maps.where("keyword like ?", "%#{params[:search]}%") unless params[:search].blank?
@maps = @maps.order("updated_at desc").page(page).per(per_page)
end
|
ruby
|
def index
@maps = Tr8n::LanguageCaseValueMap.where("language_id = ? and (reported is null or reported = ?)", tr8n_current_language.id, false)
@maps = @maps.where("keyword like ?", "%#{params[:search]}%") unless params[:search].blank?
@maps = @maps.order("updated_at desc").page(page).per(per_page)
end
|
[
"def",
"index",
"@maps",
"=",
"Tr8n",
"::",
"LanguageCaseValueMap",
".",
"where",
"(",
"\"language_id = ? and (reported is null or reported = ?)\"",
",",
"tr8n_current_language",
".",
"id",
",",
"false",
")",
"@maps",
"=",
"@maps",
".",
"where",
"(",
"\"keyword like ?\"",
",",
"\"%#{params[:search]}%\"",
")",
"unless",
"params",
"[",
":search",
"]",
".",
"blank?",
"@maps",
"=",
"@maps",
".",
"order",
"(",
"\"updated_at desc\"",
")",
".",
"page",
"(",
"page",
")",
".",
"per",
"(",
"per_page",
")",
"end"
] |
used by a client app
|
[
"used",
"by",
"a",
"client",
"app"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/language_cases_controller.rb#L31-L35
|
21,332 |
berk/tr8n
|
app/controllers/tr8n/base_controller.rb
|
Tr8n.BaseController.validate_current_translator
|
def validate_current_translator
if tr8n_current_user_is_translator? and tr8n_current_translator.blocked?
trfe("Your translation privileges have been revoked. Please contact the site administrator for more details.")
return redirect_to(Tr8n::Config.default_url)
end
return if Tr8n::Config.current_user_is_translator?
redirect_to("/tr8n/translator/registration")
end
|
ruby
|
def validate_current_translator
if tr8n_current_user_is_translator? and tr8n_current_translator.blocked?
trfe("Your translation privileges have been revoked. Please contact the site administrator for more details.")
return redirect_to(Tr8n::Config.default_url)
end
return if Tr8n::Config.current_user_is_translator?
redirect_to("/tr8n/translator/registration")
end
|
[
"def",
"validate_current_translator",
"if",
"tr8n_current_user_is_translator?",
"and",
"tr8n_current_translator",
".",
"blocked?",
"trfe",
"(",
"\"Your translation privileges have been revoked. Please contact the site administrator for more details.\"",
")",
"return",
"redirect_to",
"(",
"Tr8n",
"::",
"Config",
".",
"default_url",
")",
"end",
"return",
"if",
"Tr8n",
"::",
"Config",
".",
"current_user_is_translator?",
"redirect_to",
"(",
"\"/tr8n/translator/registration\"",
")",
"end"
] |
make sure that the current user is a translator
|
[
"make",
"sure",
"that",
"the",
"current",
"user",
"is",
"a",
"translator"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/base_controller.rb#L133-L142
|
21,333 |
berk/tr8n
|
app/controllers/tr8n/base_controller.rb
|
Tr8n.BaseController.validate_language_management
|
def validate_language_management
# admins can do everything
return if tr8n_current_user_is_admin?
if tr8n_current_language.default?
trfe("Only administrators can modify this language")
return redirect_to(tr8n_features_tabs.first[:link])
end
unless tr8n_current_user_is_translator? and tr8n_current_translator.manager?
trfe("In order to manage a language you first must request to become a manager of that language.")
return redirect_to(tr8n_features_tabs.first[:link])
end
end
|
ruby
|
def validate_language_management
# admins can do everything
return if tr8n_current_user_is_admin?
if tr8n_current_language.default?
trfe("Only administrators can modify this language")
return redirect_to(tr8n_features_tabs.first[:link])
end
unless tr8n_current_user_is_translator? and tr8n_current_translator.manager?
trfe("In order to manage a language you first must request to become a manager of that language.")
return redirect_to(tr8n_features_tabs.first[:link])
end
end
|
[
"def",
"validate_language_management",
"# admins can do everything",
"return",
"if",
"tr8n_current_user_is_admin?",
"if",
"tr8n_current_language",
".",
"default?",
"trfe",
"(",
"\"Only administrators can modify this language\"",
")",
"return",
"redirect_to",
"(",
"tr8n_features_tabs",
".",
"first",
"[",
":link",
"]",
")",
"end",
"unless",
"tr8n_current_user_is_translator?",
"and",
"tr8n_current_translator",
".",
"manager?",
"trfe",
"(",
"\"In order to manage a language you first must request to become a manager of that language.\"",
")",
"return",
"redirect_to",
"(",
"tr8n_features_tabs",
".",
"first",
"[",
":link",
"]",
")",
"end",
"end"
] |
make sure that the current user is a language manager
|
[
"make",
"sure",
"that",
"the",
"current",
"user",
"is",
"a",
"language",
"manager"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/app/controllers/tr8n/base_controller.rb#L145-L158
|
21,334 |
rapid7/elasticsearch-drain
|
lib/elasticsearch/drain.rb
|
Elasticsearch.Drain.client
|
def client
return @client unless @client.nil?
@client = ::Elasticsearch::Client.new(
hosts: hosts,
retry_on_failure: true,
log: true,
logger: ::Logger.new('es_client.log', 10, 1_024_000)
)
end
|
ruby
|
def client
return @client unless @client.nil?
@client = ::Elasticsearch::Client.new(
hosts: hosts,
retry_on_failure: true,
log: true,
logger: ::Logger.new('es_client.log', 10, 1_024_000)
)
end
|
[
"def",
"client",
"return",
"@client",
"unless",
"@client",
".",
"nil?",
"@client",
"=",
"::",
"Elasticsearch",
"::",
"Client",
".",
"new",
"(",
"hosts",
":",
"hosts",
",",
"retry_on_failure",
":",
"true",
",",
"log",
":",
"true",
",",
"logger",
":",
"::",
"Logger",
".",
"new",
"(",
"'es_client.log'",
",",
"10",
",",
"1_024_000",
")",
")",
"end"
] |
Sets up the Elasticsearch client
@option [String] :hosts ('localhost:9200') The Elasticsearch hosts
to connect to
@return [Elasticsearch::Transport::Client] Elasticsearch transport client
The Elasticsearch client object
|
[
"Sets",
"up",
"the",
"Elasticsearch",
"client"
] |
c2e47d0bfbeeb96eb9ebbb4627d0d127faf1f730
|
https://github.com/rapid7/elasticsearch-drain/blob/c2e47d0bfbeeb96eb9ebbb4627d0d127faf1f730/lib/elasticsearch/drain.rb#L26-L34
|
21,335 |
berk/tr8n
|
lib/tr8n/extensions/action_view_extension.rb
|
Tr8n.ActionViewExtension.tr8n_client_sdk_tag
|
def tr8n_client_sdk_tag(opts = {})
# opts[:default_source] ||= tr8n_default_client_source
opts[:scheduler_interval] ||= Tr8n::Config.default_client_interval
opts[:enable_inline_translations] = (Tr8n::Config.current_user_is_translator? and Tr8n::Config.current_translator.enable_inline_translations? and (not Tr8n::Config.current_language.default?))
opts[:default_decorations] = Tr8n::Config.default_decoration_tokens
opts[:default_tokens] = Tr8n::Config.default_data_tokens
opts[:rules] = {
:number => Tr8n::Config.rules_engine[:numeric_rule],
:gender => Tr8n::Config.rules_engine[:gender_rule],
:list => Tr8n::Config.rules_engine[:gender_list_rule],
:date => Tr8n::Config.rules_engine[:date_rule]
}
# build a list of actual rules of the language
client_var_name = opts[:client_var_name] || :tr8nProxy
opts.merge!(:enable_tml => Tr8n::Config.enable_tml?)
"<script>Tr8n.SDK.Proxy.init(#{opts.to_json});</script>".html_safe
end
|
ruby
|
def tr8n_client_sdk_tag(opts = {})
# opts[:default_source] ||= tr8n_default_client_source
opts[:scheduler_interval] ||= Tr8n::Config.default_client_interval
opts[:enable_inline_translations] = (Tr8n::Config.current_user_is_translator? and Tr8n::Config.current_translator.enable_inline_translations? and (not Tr8n::Config.current_language.default?))
opts[:default_decorations] = Tr8n::Config.default_decoration_tokens
opts[:default_tokens] = Tr8n::Config.default_data_tokens
opts[:rules] = {
:number => Tr8n::Config.rules_engine[:numeric_rule],
:gender => Tr8n::Config.rules_engine[:gender_rule],
:list => Tr8n::Config.rules_engine[:gender_list_rule],
:date => Tr8n::Config.rules_engine[:date_rule]
}
# build a list of actual rules of the language
client_var_name = opts[:client_var_name] || :tr8nProxy
opts.merge!(:enable_tml => Tr8n::Config.enable_tml?)
"<script>Tr8n.SDK.Proxy.init(#{opts.to_json});</script>".html_safe
end
|
[
"def",
"tr8n_client_sdk_tag",
"(",
"opts",
"=",
"{",
"}",
")",
"# opts[:default_source] ||= tr8n_default_client_source",
"opts",
"[",
":scheduler_interval",
"]",
"||=",
"Tr8n",
"::",
"Config",
".",
"default_client_interval",
"opts",
"[",
":enable_inline_translations",
"]",
"=",
"(",
"Tr8n",
"::",
"Config",
".",
"current_user_is_translator?",
"and",
"Tr8n",
"::",
"Config",
".",
"current_translator",
".",
"enable_inline_translations?",
"and",
"(",
"not",
"Tr8n",
"::",
"Config",
".",
"current_language",
".",
"default?",
")",
")",
"opts",
"[",
":default_decorations",
"]",
"=",
"Tr8n",
"::",
"Config",
".",
"default_decoration_tokens",
"opts",
"[",
":default_tokens",
"]",
"=",
"Tr8n",
"::",
"Config",
".",
"default_data_tokens",
"opts",
"[",
":rules",
"]",
"=",
"{",
":number",
"=>",
"Tr8n",
"::",
"Config",
".",
"rules_engine",
"[",
":numeric_rule",
"]",
",",
":gender",
"=>",
"Tr8n",
"::",
"Config",
".",
"rules_engine",
"[",
":gender_rule",
"]",
",",
":list",
"=>",
"Tr8n",
"::",
"Config",
".",
"rules_engine",
"[",
":gender_list_rule",
"]",
",",
":date",
"=>",
"Tr8n",
"::",
"Config",
".",
"rules_engine",
"[",
":date_rule",
"]",
"}",
"# build a list of actual rules of the language",
"client_var_name",
"=",
"opts",
"[",
":client_var_name",
"]",
"||",
":tr8nProxy",
"opts",
".",
"merge!",
"(",
":enable_tml",
"=>",
"Tr8n",
"::",
"Config",
".",
"enable_tml?",
")",
"\"<script>Tr8n.SDK.Proxy.init(#{opts.to_json});</script>\"",
".",
"html_safe",
"end"
] |
Creates an instance of tr8nProxy object
|
[
"Creates",
"an",
"instance",
"of",
"tr8nProxy",
"object"
] |
b95c42c55f429348524841a683de7d7f2e13e8a3
|
https://github.com/berk/tr8n/blob/b95c42c55f429348524841a683de7d7f2e13e8a3/lib/tr8n/extensions/action_view_extension.rb#L61-L82
|
21,336 |
kayac/rebi
|
lib/rebi/zip_helper.rb
|
Rebi.ZipHelper.gen
|
def gen
log("Creating zip archivement", env_conf.name)
start = Time.now
ebextensions = env_conf.ebextensions
tmp_file = raw_zip_archive
tmp_folder = Dir.mktmpdir
Zip::File.open(tmp_file.path) do |z|
ebextensions.each do |ex_folder|
z.remove_folder ex_folder unless ex_folder == ".ebextensions"
Dir.glob("#{ex_folder}/*.config*") do |fname|
next unless File.file?(fname)
basename = File.basename(fname)
source_file = fname
if fname.match(/\.erb$/)
next unless y = YAML::load(ErbHelper.new(File.read(fname), env_conf).result)
basename = basename.gsub(/\.erb$/,'')
source_file = "#{tmp_folder}/#{basename}"
File.open(source_file, 'w') do |f|
f.write y.to_yaml
end
end
target = ".ebextensions/#{basename}"
z.remove target if z.find_entry target
z.remove fname if z.find_entry fname
z.add target, source_file
end
end
dockerrun_file = env_conf.dockerrun || "Dockerrun.aws.json"
if File.exists?(dockerrun_file)
dockerrun = JSON.parse ErbHelper.new(File.read(dockerrun_file), env_conf).result
tmp_dockerrun = "#{tmp_folder}/Dockerrun.aws.json"
File.open(tmp_dockerrun, 'w') do |f|
f.write dockerrun.to_json
end
z.remove env_conf.dockerrun if z.find_entry env_conf.dockerrun
z.remove "Dockerrun.aws.json" if z.find_entry "Dockerrun.aws.json"
z.add "Dockerrun.aws.json", tmp_dockerrun
end
end
FileUtils.rm_rf tmp_folder
log("Zip was created in: #{Time.now - start}s", env_conf.name)
return {
label: Time.now.strftime("app_#{env_conf.name}_#{version_label}_%Y%m%d_%H%M%S"),
file: File.open(tmp_file.path),
message: message,
}
end
|
ruby
|
def gen
log("Creating zip archivement", env_conf.name)
start = Time.now
ebextensions = env_conf.ebextensions
tmp_file = raw_zip_archive
tmp_folder = Dir.mktmpdir
Zip::File.open(tmp_file.path) do |z|
ebextensions.each do |ex_folder|
z.remove_folder ex_folder unless ex_folder == ".ebextensions"
Dir.glob("#{ex_folder}/*.config*") do |fname|
next unless File.file?(fname)
basename = File.basename(fname)
source_file = fname
if fname.match(/\.erb$/)
next unless y = YAML::load(ErbHelper.new(File.read(fname), env_conf).result)
basename = basename.gsub(/\.erb$/,'')
source_file = "#{tmp_folder}/#{basename}"
File.open(source_file, 'w') do |f|
f.write y.to_yaml
end
end
target = ".ebextensions/#{basename}"
z.remove target if z.find_entry target
z.remove fname if z.find_entry fname
z.add target, source_file
end
end
dockerrun_file = env_conf.dockerrun || "Dockerrun.aws.json"
if File.exists?(dockerrun_file)
dockerrun = JSON.parse ErbHelper.new(File.read(dockerrun_file), env_conf).result
tmp_dockerrun = "#{tmp_folder}/Dockerrun.aws.json"
File.open(tmp_dockerrun, 'w') do |f|
f.write dockerrun.to_json
end
z.remove env_conf.dockerrun if z.find_entry env_conf.dockerrun
z.remove "Dockerrun.aws.json" if z.find_entry "Dockerrun.aws.json"
z.add "Dockerrun.aws.json", tmp_dockerrun
end
end
FileUtils.rm_rf tmp_folder
log("Zip was created in: #{Time.now - start}s", env_conf.name)
return {
label: Time.now.strftime("app_#{env_conf.name}_#{version_label}_%Y%m%d_%H%M%S"),
file: File.open(tmp_file.path),
message: message,
}
end
|
[
"def",
"gen",
"log",
"(",
"\"Creating zip archivement\"",
",",
"env_conf",
".",
"name",
")",
"start",
"=",
"Time",
".",
"now",
"ebextensions",
"=",
"env_conf",
".",
"ebextensions",
"tmp_file",
"=",
"raw_zip_archive",
"tmp_folder",
"=",
"Dir",
".",
"mktmpdir",
"Zip",
"::",
"File",
".",
"open",
"(",
"tmp_file",
".",
"path",
")",
"do",
"|",
"z",
"|",
"ebextensions",
".",
"each",
"do",
"|",
"ex_folder",
"|",
"z",
".",
"remove_folder",
"ex_folder",
"unless",
"ex_folder",
"==",
"\".ebextensions\"",
"Dir",
".",
"glob",
"(",
"\"#{ex_folder}/*.config*\"",
")",
"do",
"|",
"fname",
"|",
"next",
"unless",
"File",
".",
"file?",
"(",
"fname",
")",
"basename",
"=",
"File",
".",
"basename",
"(",
"fname",
")",
"source_file",
"=",
"fname",
"if",
"fname",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"next",
"unless",
"y",
"=",
"YAML",
"::",
"load",
"(",
"ErbHelper",
".",
"new",
"(",
"File",
".",
"read",
"(",
"fname",
")",
",",
"env_conf",
")",
".",
"result",
")",
"basename",
"=",
"basename",
".",
"gsub",
"(",
"/",
"\\.",
"/",
",",
"''",
")",
"source_file",
"=",
"\"#{tmp_folder}/#{basename}\"",
"File",
".",
"open",
"(",
"source_file",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"y",
".",
"to_yaml",
"end",
"end",
"target",
"=",
"\".ebextensions/#{basename}\"",
"z",
".",
"remove",
"target",
"if",
"z",
".",
"find_entry",
"target",
"z",
".",
"remove",
"fname",
"if",
"z",
".",
"find_entry",
"fname",
"z",
".",
"add",
"target",
",",
"source_file",
"end",
"end",
"dockerrun_file",
"=",
"env_conf",
".",
"dockerrun",
"||",
"\"Dockerrun.aws.json\"",
"if",
"File",
".",
"exists?",
"(",
"dockerrun_file",
")",
"dockerrun",
"=",
"JSON",
".",
"parse",
"ErbHelper",
".",
"new",
"(",
"File",
".",
"read",
"(",
"dockerrun_file",
")",
",",
"env_conf",
")",
".",
"result",
"tmp_dockerrun",
"=",
"\"#{tmp_folder}/Dockerrun.aws.json\"",
"File",
".",
"open",
"(",
"tmp_dockerrun",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"dockerrun",
".",
"to_json",
"end",
"z",
".",
"remove",
"env_conf",
".",
"dockerrun",
"if",
"z",
".",
"find_entry",
"env_conf",
".",
"dockerrun",
"z",
".",
"remove",
"\"Dockerrun.aws.json\"",
"if",
"z",
".",
"find_entry",
"\"Dockerrun.aws.json\"",
"z",
".",
"add",
"\"Dockerrun.aws.json\"",
",",
"tmp_dockerrun",
"end",
"end",
"FileUtils",
".",
"rm_rf",
"tmp_folder",
"log",
"(",
"\"Zip was created in: #{Time.now - start}s\"",
",",
"env_conf",
".",
"name",
")",
"return",
"{",
"label",
":",
"Time",
".",
"now",
".",
"strftime",
"(",
"\"app_#{env_conf.name}_#{version_label}_%Y%m%d_%H%M%S\"",
")",
",",
"file",
":",
"File",
".",
"open",
"(",
"tmp_file",
".",
"path",
")",
",",
"message",
":",
"message",
",",
"}",
"end"
] |
Create zip archivement
|
[
"Create",
"zip",
"archivement"
] |
fa4962e152811c3fe703c637cf1d95ea2d019393
|
https://github.com/kayac/rebi/blob/fa4962e152811c3fe703c637cf1d95ea2d019393/lib/rebi/zip_helper.rb#L57-L110
|
21,337 |
liquidm/ext
|
lib/liquid/configuration.rb
|
Liquid.Configuration.reload!
|
def reload!
clear
@mixins.each do |file|
mixin(file)
end
@callbacks.each do |callback|
callback.call(self)
end
end
|
ruby
|
def reload!
clear
@mixins.each do |file|
mixin(file)
end
@callbacks.each do |callback|
callback.call(self)
end
end
|
[
"def",
"reload!",
"clear",
"@mixins",
".",
"each",
"do",
"|",
"file",
"|",
"mixin",
"(",
"file",
")",
"end",
"@callbacks",
".",
"each",
"do",
"|",
"callback",
"|",
"callback",
".",
"call",
"(",
"self",
")",
"end",
"end"
] |
Reload all mixins.
@return [void]
|
[
"Reload",
"all",
"mixins",
"."
] |
0b7e16ac361460165ba40211720e20cafca62591
|
https://github.com/liquidm/ext/blob/0b7e16ac361460165ba40211720e20cafca62591/lib/liquid/configuration.rb#L121-L131
|
21,338 |
liquidm/ext
|
lib/liquid/logger.rb
|
Liquid.Logger.called_from
|
def called_from
location = caller.detect('unknown:0') do |line|
line.match(/\/liquid(-|\/)ext/).nil?
end
file, line, _ = location.split(':')
{ :file => file, :line => line }
end
|
ruby
|
def called_from
location = caller.detect('unknown:0') do |line|
line.match(/\/liquid(-|\/)ext/).nil?
end
file, line, _ = location.split(':')
{ :file => file, :line => line }
end
|
[
"def",
"called_from",
"location",
"=",
"caller",
".",
"detect",
"(",
"'unknown:0'",
")",
"do",
"|",
"line",
"|",
"line",
".",
"match",
"(",
"/",
"\\/",
"\\/",
"/",
")",
".",
"nil?",
"end",
"file",
",",
"line",
",",
"_",
"=",
"location",
".",
"split",
"(",
"':'",
")",
"{",
":file",
"=>",
"file",
",",
":line",
"=>",
"line",
"}",
"end"
] |
Return the first callee outside the liquid-ext gem
|
[
"Return",
"the",
"first",
"callee",
"outside",
"the",
"liquid",
"-",
"ext",
"gem"
] |
0b7e16ac361460165ba40211720e20cafca62591
|
https://github.com/liquidm/ext/blob/0b7e16ac361460165ba40211720e20cafca62591/lib/liquid/logger.rb#L148-L154
|
21,339 |
relevance/log_buddy
|
lib/log_buddy/utils.rb
|
LogBuddy.Utils.read_line
|
def read_line(frame)
file, line_number = frame.split(/:/, 2)
line_number = line_number.to_i
lines = File.readlines(file)
lines[line_number - 1]
end
|
ruby
|
def read_line(frame)
file, line_number = frame.split(/:/, 2)
line_number = line_number.to_i
lines = File.readlines(file)
lines[line_number - 1]
end
|
[
"def",
"read_line",
"(",
"frame",
")",
"file",
",",
"line_number",
"=",
"frame",
".",
"split",
"(",
"/",
"/",
",",
"2",
")",
"line_number",
"=",
"line_number",
".",
"to_i",
"lines",
"=",
"File",
".",
"readlines",
"(",
"file",
")",
"lines",
"[",
"line_number",
"-",
"1",
"]",
"end"
] |
Return the calling line
|
[
"Return",
"the",
"calling",
"line"
] |
851dc7a5b4246cbce18bbd999b46f9da22eda61c
|
https://github.com/relevance/log_buddy/blob/851dc7a5b4246cbce18bbd999b46f9da22eda61c/lib/log_buddy/utils.rb#L29-L35
|
21,340 |
0exp/symbiont-ruby
|
lib/symbiont/public_trigger.rb
|
Symbiont.PublicTrigger.method
|
def method(method_name)
__context__ = __actual_context__(method_name)
# NOTE:
# block is used cuz #__actual_context__can raise
# ::NoMethodError (ContextNoMethodError) too (and we should raise it)
begin
__context__.method(method_name)
rescue ::NoMethodError
# NOTE:
# this situation is caused when the context object does not respond
# to #method method (BasicObject instances for example). We can extract
# method objects via it's singleton class.
__context_singleton__ = __extract_singleton_class__(__context__)
__context_singleton__.public_instance_method(method_name).bind(__context__)
end
end
|
ruby
|
def method(method_name)
__context__ = __actual_context__(method_name)
# NOTE:
# block is used cuz #__actual_context__can raise
# ::NoMethodError (ContextNoMethodError) too (and we should raise it)
begin
__context__.method(method_name)
rescue ::NoMethodError
# NOTE:
# this situation is caused when the context object does not respond
# to #method method (BasicObject instances for example). We can extract
# method objects via it's singleton class.
__context_singleton__ = __extract_singleton_class__(__context__)
__context_singleton__.public_instance_method(method_name).bind(__context__)
end
end
|
[
"def",
"method",
"(",
"method_name",
")",
"__context__",
"=",
"__actual_context__",
"(",
"method_name",
")",
"# NOTE:",
"# block is used cuz #__actual_context__can raise",
"# ::NoMethodError (ContextNoMethodError) too (and we should raise it)",
"begin",
"__context__",
".",
"method",
"(",
"method_name",
")",
"rescue",
"::",
"NoMethodError",
"# NOTE:",
"# this situation is caused when the context object does not respond",
"# to #method method (BasicObject instances for example). We can extract",
"# method objects via it's singleton class.",
"__context_singleton__",
"=",
"__extract_singleton_class__",
"(",
"__context__",
")",
"__context_singleton__",
".",
"public_instance_method",
"(",
"method_name",
")",
".",
"bind",
"(",
"__context__",
")",
"end",
"end"
] |
Returns a corresponding public method object of the actual context.
@param method_name [String,Symbol] Method name
@raise [::NameError]
@raise [Symbiont::Trigger::ContextNoMethodError, ::NoMethodError]
@return [Method]
@see [Symbiont::Trigger#method]
@api private
@since 0.5.0
|
[
"Returns",
"a",
"corresponding",
"public",
"method",
"object",
"of",
"the",
"actual",
"context",
"."
] |
a514a9a145fda118f2947ed5d82986fb2e18896d
|
https://github.com/0exp/symbiont-ruby/blob/a514a9a145fda118f2947ed5d82986fb2e18896d/lib/symbiont/public_trigger.rb#L53-L70
|
21,341 |
0exp/symbiont-ruby
|
lib/symbiont/isolator.rb
|
Symbiont.Isolator.public_method
|
def public_method(method_name, *required_contexts, direction: default_direction)
public_trigger(*required_contexts, direction: direction).method(method_name)
end
|
ruby
|
def public_method(method_name, *required_contexts, direction: default_direction)
public_trigger(*required_contexts, direction: direction).method(method_name)
end
|
[
"def",
"public_method",
"(",
"method_name",
",",
"*",
"required_contexts",
",",
"direction",
":",
"default_direction",
")",
"public_trigger",
"(",
"required_contexts",
",",
"direction",
":",
"direction",
")",
".",
"method",
"(",
"method_name",
")",
"end"
] |
Gets the method object taken from the context that can respond to it.
Considers only public methods.
@param method_name [Symbol,String] A name of required method.
@param required_contexts [Array<Object>]
A set of objects that should be used as the main context series for method resolving
algorithm.
@param direction [Array<Symbol>]
An array of symbols that represents the direction of contexts.
@return [Method]
@see Symbiont::PublicTrigger
@see Symbiont::Trigger#method
@api public
@since 0.3.0
|
[
"Gets",
"the",
"method",
"object",
"taken",
"from",
"the",
"context",
"that",
"can",
"respond",
"to",
"it",
".",
"Considers",
"only",
"public",
"methods",
"."
] |
a514a9a145fda118f2947ed5d82986fb2e18896d
|
https://github.com/0exp/symbiont-ruby/blob/a514a9a145fda118f2947ed5d82986fb2e18896d/lib/symbiont/isolator.rb#L107-L109
|
21,342 |
0exp/symbiont-ruby
|
lib/symbiont/isolator.rb
|
Symbiont.Isolator.private_method
|
def private_method(method_name, *required_contexts, direction: default_direction)
private_trigger(*required_contexts, direction: direction).method(method_name)
end
|
ruby
|
def private_method(method_name, *required_contexts, direction: default_direction)
private_trigger(*required_contexts, direction: direction).method(method_name)
end
|
[
"def",
"private_method",
"(",
"method_name",
",",
"*",
"required_contexts",
",",
"direction",
":",
"default_direction",
")",
"private_trigger",
"(",
"required_contexts",
",",
"direction",
":",
"direction",
")",
".",
"method",
"(",
"method_name",
")",
"end"
] |
Gets the method object taken from the context that can respond to it.
Considers private methods and public methods.
@param method_name [Symbol,String] A name of required method.
@param required_contexts [Array<Object>]
A set of objects that should be used as the main context series for method resolving
algorithm.
@param direction [Array<Symbol>]
An array of symbols that represents the direction of contexts.
@return [Method]
@see Symbiont::PrivateTrigger
@see Symbiont::Trigger#method
@api public
@since 0.3.0
|
[
"Gets",
"the",
"method",
"object",
"taken",
"from",
"the",
"context",
"that",
"can",
"respond",
"to",
"it",
".",
"Considers",
"private",
"methods",
"and",
"public",
"methods",
"."
] |
a514a9a145fda118f2947ed5d82986fb2e18896d
|
https://github.com/0exp/symbiont-ruby/blob/a514a9a145fda118f2947ed5d82986fb2e18896d/lib/symbiont/isolator.rb#L127-L129
|
21,343 |
0exp/symbiont-ruby
|
lib/symbiont/isolator.rb
|
Symbiont.Isolator.public_trigger
|
def public_trigger(*required_contexts, direction: default_direction)
PublicTrigger.new(*required_contexts, context_direction: direction, &closure)
end
|
ruby
|
def public_trigger(*required_contexts, direction: default_direction)
PublicTrigger.new(*required_contexts, context_direction: direction, &closure)
end
|
[
"def",
"public_trigger",
"(",
"*",
"required_contexts",
",",
"direction",
":",
"default_direction",
")",
"PublicTrigger",
".",
"new",
"(",
"required_contexts",
",",
"context_direction",
":",
"direction",
",",
"closure",
")",
"end"
] |
Factory method that instantiates a public trigger with the desired execution context,
the direction of method dispatching and the closure that needs to be performed.
@param required_contexts [Array<Object>]
A set of objects that should be used as the main context series for method resolving
algorithm.
@param direction [Array<Symbol>]
An array of symbols that represents the direction of contexts. Possible values:
- Symbiont::IOK
- Symbiont::OIK
- Symbiont::OKI
- Symbiont::IKO
- Symbiont::KOI
- Symbiont::KIO
@return [Symbiont::PublicTrigger]
@see Symbiont::PublicTrigger
@see Symbiont::Trigger
@api private
@since 0.3.0
|
[
"Factory",
"method",
"that",
"instantiates",
"a",
"public",
"trigger",
"with",
"the",
"desired",
"execution",
"context",
"the",
"direction",
"of",
"method",
"dispatching",
"and",
"the",
"closure",
"that",
"needs",
"to",
"be",
"performed",
"."
] |
a514a9a145fda118f2947ed5d82986fb2e18896d
|
https://github.com/0exp/symbiont-ruby/blob/a514a9a145fda118f2947ed5d82986fb2e18896d/lib/symbiont/isolator.rb#L155-L157
|
21,344 |
0exp/symbiont-ruby
|
lib/symbiont/isolator.rb
|
Symbiont.Isolator.private_trigger
|
def private_trigger(*required_contexts, direction: default_direction)
PrivateTrigger.new(*required_contexts, context_direction: direction, &closure)
end
|
ruby
|
def private_trigger(*required_contexts, direction: default_direction)
PrivateTrigger.new(*required_contexts, context_direction: direction, &closure)
end
|
[
"def",
"private_trigger",
"(",
"*",
"required_contexts",
",",
"direction",
":",
"default_direction",
")",
"PrivateTrigger",
".",
"new",
"(",
"required_contexts",
",",
"context_direction",
":",
"direction",
",",
"closure",
")",
"end"
] |
Factory method that instantiates a private trigger with the desired execution context,
the direction of method dispatching and the closure that needs to be performed.
@param required_contexts [Array<Object>]
A set of objects that should be used as the main context series for method resolving
algorithm.
@param direction [Array<Symbol>]
An array of symbols that represents the direction of contexts. Possible values:
- Symbiont::IOK
- Symbiont::OIK
- Symbiont::OKI
- Symbiont::IKO
- Symbiont::KOI
- Symbiont::KIO
@return [Symbiont::PrivateTrigger]
@see Symbiont::PrivateTrigger
@see Symbiont::Trigger
@api private
@since 0.3.0
|
[
"Factory",
"method",
"that",
"instantiates",
"a",
"private",
"trigger",
"with",
"the",
"desired",
"execution",
"context",
"the",
"direction",
"of",
"method",
"dispatching",
"and",
"the",
"closure",
"that",
"needs",
"to",
"be",
"performed",
"."
] |
a514a9a145fda118f2947ed5d82986fb2e18896d
|
https://github.com/0exp/symbiont-ruby/blob/a514a9a145fda118f2947ed5d82986fb2e18896d/lib/symbiont/isolator.rb#L181-L183
|
21,345 |
kennyp/potracer
|
lib/potracer.rb
|
Potracer.Trace.trace
|
def trace(bitmap = nil, params = nil, &block)
if block_given?
do_trace(bitmap || @bitmap, params || @params, &block)
else
do_trace(bitmap || @bitmap, params || @params)
end
end
|
ruby
|
def trace(bitmap = nil, params = nil, &block)
if block_given?
do_trace(bitmap || @bitmap, params || @params, &block)
else
do_trace(bitmap || @bitmap, params || @params)
end
end
|
[
"def",
"trace",
"(",
"bitmap",
"=",
"nil",
",",
"params",
"=",
"nil",
",",
"&",
"block",
")",
"if",
"block_given?",
"do_trace",
"(",
"bitmap",
"||",
"@bitmap",
",",
"params",
"||",
"@params",
",",
"block",
")",
"else",
"do_trace",
"(",
"bitmap",
"||",
"@bitmap",
",",
"params",
"||",
"@params",
")",
"end",
"end"
] |
Trace the given +bitmap+
==== Attributes
* +bitmap+ - an instance of Potracer::Bitmap. If not given the +@bitmap+
is used.
* +params+ - an instance of Potracer::Params. If not given +@params+ is
used.
* +block+ - optional block called to report trace progress
|
[
"Trace",
"the",
"given",
"+",
"bitmap",
"+"
] |
b67d3ff6a1ae672ccc6701fa5245fa532b461ef3
|
https://github.com/kennyp/potracer/blob/b67d3ff6a1ae672ccc6701fa5245fa532b461ef3/lib/potracer.rb#L23-L29
|
21,346 |
nedap/railjet
|
lib/railjet/context.rb
|
Railjet.Context.method_missing
|
def method_missing(name, *args, &block)
getter_name = name[0..-2]
if name =~ /^[a-z]+=$/ && !respond_to?(getter_name)
define_accessor(getter_name, args.first)
else
super
end
end
|
ruby
|
def method_missing(name, *args, &block)
getter_name = name[0..-2]
if name =~ /^[a-z]+=$/ && !respond_to?(getter_name)
define_accessor(getter_name, args.first)
else
super
end
end
|
[
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
",",
"&",
"block",
")",
"getter_name",
"=",
"name",
"[",
"0",
"..",
"-",
"2",
"]",
"if",
"name",
"=~",
"/",
"/",
"&&",
"!",
"respond_to?",
"(",
"getter_name",
")",
"define_accessor",
"(",
"getter_name",
",",
"args",
".",
"first",
")",
"else",
"super",
"end",
"end"
] |
New values can be assigned to context on-the-fly,
but it's not possible to change anything.
|
[
"New",
"values",
"can",
"be",
"assigned",
"to",
"context",
"on",
"-",
"the",
"-",
"fly",
"but",
"it",
"s",
"not",
"possible",
"to",
"change",
"anything",
"."
] |
38fbf1619eee78af6ae01f9339fdee8881fabbf4
|
https://github.com/nedap/railjet/blob/38fbf1619eee78af6ae01f9339fdee8881fabbf4/lib/railjet/context.rb#L9-L17
|
21,347 |
lukebayes/project-sprouts
|
lib/sprout/executable/session.rb
|
Sprout::Executable.Session.handle_user_input
|
def handle_user_input
while true
begin
break if !wait_for_prompt
input = $stdin.gets.chomp!
execute_action(input, true)
rescue SignalException => e
return false
end
end
wait
end
|
ruby
|
def handle_user_input
while true
begin
break if !wait_for_prompt
input = $stdin.gets.chomp!
execute_action(input, true)
rescue SignalException => e
return false
end
end
wait
end
|
[
"def",
"handle_user_input",
"while",
"true",
"begin",
"break",
"if",
"!",
"wait_for_prompt",
"input",
"=",
"$stdin",
".",
"gets",
".",
"chomp!",
"execute_action",
"(",
"input",
",",
"true",
")",
"rescue",
"SignalException",
"=>",
"e",
"return",
"false",
"end",
"end",
"wait",
"end"
] |
Expose the running process to manual
input on the terminal, and write stdout
back to the user.
|
[
"Expose",
"the",
"running",
"process",
"to",
"manual",
"input",
"on",
"the",
"terminal",
"and",
"write",
"stdout",
"back",
"to",
"the",
"user",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/executable/session.rb#L225-L236
|
21,348 |
lukebayes/project-sprouts
|
lib/sprout/executable/session.rb
|
Sprout::Executable.Session.execute_action
|
def execute_action action, silence=false
action = action.strip
if wait_for_prompt
stdout.puts(action) unless silence
@prompted = false
process_runner.puts action
end
end
|
ruby
|
def execute_action action, silence=false
action = action.strip
if wait_for_prompt
stdout.puts(action) unless silence
@prompted = false
process_runner.puts action
end
end
|
[
"def",
"execute_action",
"action",
",",
"silence",
"=",
"false",
"action",
"=",
"action",
".",
"strip",
"if",
"wait_for_prompt",
"stdout",
".",
"puts",
"(",
"action",
")",
"unless",
"silence",
"@prompted",
"=",
"false",
"process_runner",
".",
"puts",
"action",
"end",
"end"
] |
Execute a single action.
|
[
"Execute",
"a",
"single",
"action",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/executable/session.rb#L304-L311
|
21,349 |
alphagov/govuk_message_queue_consumer
|
lib/govuk_message_queue_consumer/consumer.rb
|
GovukMessageQueueConsumer.Consumer.run
|
def run(subscribe_opts: {})
@rabbitmq_connection.start
subscribe_opts = { block: true, manual_ack: true}.merge(subscribe_opts)
queue.subscribe(subscribe_opts) do |delivery_info, headers, payload|
begin
message = Message.new(payload, headers, delivery_info)
@statsd_client.increment("#{@queue_name}.started")
message_consumer.process(message)
@statsd_client.increment("#{@queue_name}.#{message.status}")
rescue Exception => e
@statsd_client.increment("#{@queue_name}.uncaught_exception")
GovukError.notify(e) if defined?(GovukError)
@logger.error "Uncaught exception in processor: \n\n #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}"
exit(1) # Ensure rabbitmq requeues outstanding messages
end
end
end
|
ruby
|
def run(subscribe_opts: {})
@rabbitmq_connection.start
subscribe_opts = { block: true, manual_ack: true}.merge(subscribe_opts)
queue.subscribe(subscribe_opts) do |delivery_info, headers, payload|
begin
message = Message.new(payload, headers, delivery_info)
@statsd_client.increment("#{@queue_name}.started")
message_consumer.process(message)
@statsd_client.increment("#{@queue_name}.#{message.status}")
rescue Exception => e
@statsd_client.increment("#{@queue_name}.uncaught_exception")
GovukError.notify(e) if defined?(GovukError)
@logger.error "Uncaught exception in processor: \n\n #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}"
exit(1) # Ensure rabbitmq requeues outstanding messages
end
end
end
|
[
"def",
"run",
"(",
"subscribe_opts",
":",
"{",
"}",
")",
"@rabbitmq_connection",
".",
"start",
"subscribe_opts",
"=",
"{",
"block",
":",
"true",
",",
"manual_ack",
":",
"true",
"}",
".",
"merge",
"(",
"subscribe_opts",
")",
"queue",
".",
"subscribe",
"(",
"subscribe_opts",
")",
"do",
"|",
"delivery_info",
",",
"headers",
",",
"payload",
"|",
"begin",
"message",
"=",
"Message",
".",
"new",
"(",
"payload",
",",
"headers",
",",
"delivery_info",
")",
"@statsd_client",
".",
"increment",
"(",
"\"#{@queue_name}.started\"",
")",
"message_consumer",
".",
"process",
"(",
"message",
")",
"@statsd_client",
".",
"increment",
"(",
"\"#{@queue_name}.#{message.status}\"",
")",
"rescue",
"Exception",
"=>",
"e",
"@statsd_client",
".",
"increment",
"(",
"\"#{@queue_name}.uncaught_exception\"",
")",
"GovukError",
".",
"notify",
"(",
"e",
")",
"if",
"defined?",
"(",
"GovukError",
")",
"@logger",
".",
"error",
"\"Uncaught exception in processor: \\n\\n #{e.class}: #{e.message}\\n\\n#{e.backtrace.join(\"\\n\")}\"",
"exit",
"(",
"1",
")",
"# Ensure rabbitmq requeues outstanding messages",
"end",
"end",
"end"
] |
Create a new consumer
@param queue_name [String] Your queue name. This is specific to your application,
and should already exist and have a binding via puppet
@param processor [Object] An object that responds to `process`
@param rabbitmq_connection [Object] A Bunny connection object derived from `Bunny.new`
@param statsd_client [Statsd] An instance of the Statsd class
@param logger [Object] A Logger object for emitting errors (to stderr by default)
|
[
"Create",
"a",
"new",
"consumer"
] |
c944ed6273e2c4505a6826ad187a1fa496182a13
|
https://github.com/alphagov/govuk_message_queue_consumer/blob/c944ed6273e2c4505a6826ad187a1fa496182a13/lib/govuk_message_queue_consumer/consumer.rb#L29-L46
|
21,350 |
lukebayes/project-sprouts
|
lib/sprout/process_runner.rb
|
Sprout.ProcessRunner.update_status
|
def update_status sig=0
pid_int = Integer("#{ @pid }")
begin
Process::kill sig, pid_int
true
rescue Errno::ESRCH
false
end
end
|
ruby
|
def update_status sig=0
pid_int = Integer("#{ @pid }")
begin
Process::kill sig, pid_int
true
rescue Errno::ESRCH
false
end
end
|
[
"def",
"update_status",
"sig",
"=",
"0",
"pid_int",
"=",
"Integer",
"(",
"\"#{ @pid }\"",
")",
"begin",
"Process",
"::",
"kill",
"sig",
",",
"pid_int",
"true",
"rescue",
"Errno",
"::",
"ESRCH",
"false",
"end",
"end"
] |
Send an update signal to the process.
@param sig [Integer] The signal to send, default 0 (or no action requested)
|
[
"Send",
"an",
"update",
"signal",
"to",
"the",
"process",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/process_runner.rb#L93-L101
|
21,351 |
xuanxu/random_sources
|
lib/providers/hot_bits.rb
|
RandomSources.HotBits.bytes
|
def bytes(num=10)
num = [[2048, num.to_i].min , 0].max
numbers = []
response = REXML::Document.new( open("https://www.fourmilab.ch/cgi-bin/Hotbits?fmt=xml&nbytes=#{num}"))
status = REXML::XPath.first( response, "//status")
case status.attributes['result'].to_i
when 200
data = REXML::XPath.first( response, "//random-data" ).text.split
data.each{|byte| numbers << byte.hex}
when 503
raise StandardError.new "#{status.text}"
end
numbers
end
|
ruby
|
def bytes(num=10)
num = [[2048, num.to_i].min , 0].max
numbers = []
response = REXML::Document.new( open("https://www.fourmilab.ch/cgi-bin/Hotbits?fmt=xml&nbytes=#{num}"))
status = REXML::XPath.first( response, "//status")
case status.attributes['result'].to_i
when 200
data = REXML::XPath.first( response, "//random-data" ).text.split
data.each{|byte| numbers << byte.hex}
when 503
raise StandardError.new "#{status.text}"
end
numbers
end
|
[
"def",
"bytes",
"(",
"num",
"=",
"10",
")",
"num",
"=",
"[",
"[",
"2048",
",",
"num",
".",
"to_i",
"]",
".",
"min",
",",
"0",
"]",
".",
"max",
"numbers",
"=",
"[",
"]",
"response",
"=",
"REXML",
"::",
"Document",
".",
"new",
"(",
"open",
"(",
"\"https://www.fourmilab.ch/cgi-bin/Hotbits?fmt=xml&nbytes=#{num}\"",
")",
")",
"status",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"response",
",",
"\"//status\"",
")",
"case",
"status",
".",
"attributes",
"[",
"'result'",
"]",
".",
"to_i",
"when",
"200",
"data",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"response",
",",
"\"//random-data\"",
")",
".",
"text",
".",
"split",
"data",
".",
"each",
"{",
"|",
"byte",
"|",
"numbers",
"<<",
"byte",
".",
"hex",
"}",
"when",
"503",
"raise",
"StandardError",
".",
"new",
"\"#{status.text}\"",
"end",
"numbers",
"end"
] |
Random bytes generator.
It returns an Array of integers with values between 0 and 255
It receives the number of random bytes to generate (max 2048, default 10)
|
[
"Random",
"bytes",
"generator",
"."
] |
8fb43ea50e97191bc5d68b634887b72752f6d63e
|
https://github.com/xuanxu/random_sources/blob/8fb43ea50e97191bc5d68b634887b72752f6d63e/lib/providers/hot_bits.rb#L31-L46
|
21,352 |
lukebayes/project-sprouts
|
lib/sprout/system/unix_system.rb
|
Sprout::System.UnixSystem.should_repair_executable
|
def should_repair_executable path
return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!\/bin\/sh/))
end
|
ruby
|
def should_repair_executable path
return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!\/bin\/sh/))
end
|
[
"def",
"should_repair_executable",
"path",
"return",
"(",
"File",
".",
"exists?",
"(",
"path",
")",
"&&",
"!",
"File",
".",
"directory?",
"(",
"path",
")",
"&&",
"File",
".",
"read",
"(",
"path",
")",
".",
"match",
"(",
"/",
"\\#",
"\\!",
"\\/",
"\\/",
"/",
")",
")",
"end"
] |
Determine if we should call +repair_executable+
for the file at the provided +path+ String.
Will this corrupt binaries? Yes... Yes. it. will.
This also fails on UTF-8 files since Ruby's regex
appears to choke on UTF-8??
|
[
"Determine",
"if",
"we",
"should",
"call",
"+",
"repair_executable",
"+",
"for",
"the",
"file",
"at",
"the",
"provided",
"+",
"path",
"+",
"String",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/system/unix_system.rb#L69-L71
|
21,353 |
xuanxu/random_sources
|
lib/providers/random_org.rb
|
RandomSources.RandomOrg.integers
|
def integers(options = {})
url_params = { max: clean(options[:max]) || 100,
min: clean(options[:min]) || 1,
num: clean(options[:num]) || 10,
base: clean(options[:base]) || 10,
rnd: 'new',
format: 'plain',
col: 1
}
numbers=[]
check_for_http_errors{
response=open("#{@website}integers/?max=#{url_params[:max]}&min=#{url_params[:min]}&base=#{url_params[:base]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}&num=#{url_params[:num]}")
response.each_line{|line| numbers << line.to_i}
}
numbers
end
|
ruby
|
def integers(options = {})
url_params = { max: clean(options[:max]) || 100,
min: clean(options[:min]) || 1,
num: clean(options[:num]) || 10,
base: clean(options[:base]) || 10,
rnd: 'new',
format: 'plain',
col: 1
}
numbers=[]
check_for_http_errors{
response=open("#{@website}integers/?max=#{url_params[:max]}&min=#{url_params[:min]}&base=#{url_params[:base]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}&num=#{url_params[:num]}")
response.each_line{|line| numbers << line.to_i}
}
numbers
end
|
[
"def",
"integers",
"(",
"options",
"=",
"{",
"}",
")",
"url_params",
"=",
"{",
"max",
":",
"clean",
"(",
"options",
"[",
":max",
"]",
")",
"||",
"100",
",",
"min",
":",
"clean",
"(",
"options",
"[",
":min",
"]",
")",
"||",
"1",
",",
"num",
":",
"clean",
"(",
"options",
"[",
":num",
"]",
")",
"||",
"10",
",",
"base",
":",
"clean",
"(",
"options",
"[",
":base",
"]",
")",
"||",
"10",
",",
"rnd",
":",
"'new'",
",",
"format",
":",
"'plain'",
",",
"col",
":",
"1",
"}",
"numbers",
"=",
"[",
"]",
"check_for_http_errors",
"{",
"response",
"=",
"open",
"(",
"\"#{@website}integers/?max=#{url_params[:max]}&min=#{url_params[:min]}&base=#{url_params[:base]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}&num=#{url_params[:num]}\"",
")",
"response",
".",
"each_line",
"{",
"|",
"line",
"|",
"numbers",
"<<",
"line",
".",
"to_i",
"}",
"}",
"numbers",
"end"
] |
Random Integers Generator.
Configuration options:
* <tt>:num</tt> - The number of integers requested. Posibles values: [1,1e4]. Default: 10
* <tt>:min</tt> - The smallest value allowed for each integer. Posibles values: [-1e9,1e9]. Default: 1
* <tt>:max</tt> - The smallest value allowed for each integer. Posibles values: [-1e9,1e9]. Default: 100
* <tt>:base</tt> - The base that will be used to print the numbers. Posibles values: 2, 8, 10, 16 (binary, octal, decimal or hexadecimal). Default: 10
It returns an Array of integers with the size indicated by <tt>:num</tt>
integers(num: 15, max: 2, min: 200, base: 8) #=> array of 15 base 8 numbers between 2 and 200
integers(num: 4, max: 33) #=> [31, 25, 28, 6]
|
[
"Random",
"Integers",
"Generator",
"."
] |
8fb43ea50e97191bc5d68b634887b72752f6d63e
|
https://github.com/xuanxu/random_sources/blob/8fb43ea50e97191bc5d68b634887b72752f6d63e/lib/providers/random_org.rb#L36-L54
|
21,354 |
xuanxu/random_sources
|
lib/providers/random_org.rb
|
RandomSources.RandomOrg.sequence
|
def sequence(min, max)
url_params = { max: clean(max) || 10,
min: clean(min) || 1,
rnd: 'new',
format: 'plain',
col: 1
}
sequence_numbers=[]
check_for_http_errors{
response=open("#{@website}sequences/?max=#{url_params[:max]}&min=#{url_params[:min]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}")
response.each_line{|line| sequence_numbers << line.to_i}
}
sequence_numbers
end
|
ruby
|
def sequence(min, max)
url_params = { max: clean(max) || 10,
min: clean(min) || 1,
rnd: 'new',
format: 'plain',
col: 1
}
sequence_numbers=[]
check_for_http_errors{
response=open("#{@website}sequences/?max=#{url_params[:max]}&min=#{url_params[:min]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}")
response.each_line{|line| sequence_numbers << line.to_i}
}
sequence_numbers
end
|
[
"def",
"sequence",
"(",
"min",
",",
"max",
")",
"url_params",
"=",
"{",
"max",
":",
"clean",
"(",
"max",
")",
"||",
"10",
",",
"min",
":",
"clean",
"(",
"min",
")",
"||",
"1",
",",
"rnd",
":",
"'new'",
",",
"format",
":",
"'plain'",
",",
"col",
":",
"1",
"}",
"sequence_numbers",
"=",
"[",
"]",
"check_for_http_errors",
"{",
"response",
"=",
"open",
"(",
"\"#{@website}sequences/?max=#{url_params[:max]}&min=#{url_params[:min]}&col=#{url_params[:col]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}\"",
")",
"response",
".",
"each_line",
"{",
"|",
"line",
"|",
"sequence_numbers",
"<<",
"line",
".",
"to_i",
"}",
"}",
"sequence_numbers",
"end"
] |
The Sequence Generator
It will randomize a given interval of integers, i.e., arrange them in random order.
It needs two params:
* <tt>min</tt> - The lower bound of the interval (inclusive). Posibles values: [-1e9,1e9]
* <tt>max</tt> - The upper bound of the interval (inclusive). Posibles values: [-1e9,1e9]
The length of the sequence (the largest minus the smallest value plus 1) can be no greater than 10,000.
It returns an Array of all the integers of the given interval arranged randomly
sequence(2, 15) #=> [13, 2, 10, 4, 9, 15 ,12, 3, 5, 7, 6, 14, 8, 11]
|
[
"The",
"Sequence",
"Generator"
] |
8fb43ea50e97191bc5d68b634887b72752f6d63e
|
https://github.com/xuanxu/random_sources/blob/8fb43ea50e97191bc5d68b634887b72752f6d63e/lib/providers/random_org.rb#L69-L84
|
21,355 |
xuanxu/random_sources
|
lib/providers/random_org.rb
|
RandomSources.RandomOrg.strings
|
def strings(options = {})
url_params = { num: clean(options[:num]) || 10,
len: clean(options[:len]) || 8,
digits: check_on_off(options[:digits]) || 'on',
unique: check_on_off(options[:unique]) || 'on',
upperalpha: check_on_off(options[:upperalpha]) || 'on',
loweralpha: check_on_off(options[:loweralpha]) || 'on',
rnd: 'new',
format: 'plain'
}
strings=[]
check_for_http_errors{
response=open("#{@website}strings/?num=#{url_params[:num]}&len=#{url_params[:len]}&digits=#{url_params[:digits]}&unique=#{url_params[:unique]}&upperalpha=#{url_params[:upperalpha]}&loweralpha=#{url_params[:loweralpha]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}")
response.each_line{|line| strings << line.strip}
}
strings
end
|
ruby
|
def strings(options = {})
url_params = { num: clean(options[:num]) || 10,
len: clean(options[:len]) || 8,
digits: check_on_off(options[:digits]) || 'on',
unique: check_on_off(options[:unique]) || 'on',
upperalpha: check_on_off(options[:upperalpha]) || 'on',
loweralpha: check_on_off(options[:loweralpha]) || 'on',
rnd: 'new',
format: 'plain'
}
strings=[]
check_for_http_errors{
response=open("#{@website}strings/?num=#{url_params[:num]}&len=#{url_params[:len]}&digits=#{url_params[:digits]}&unique=#{url_params[:unique]}&upperalpha=#{url_params[:upperalpha]}&loweralpha=#{url_params[:loweralpha]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}")
response.each_line{|line| strings << line.strip}
}
strings
end
|
[
"def",
"strings",
"(",
"options",
"=",
"{",
"}",
")",
"url_params",
"=",
"{",
"num",
":",
"clean",
"(",
"options",
"[",
":num",
"]",
")",
"||",
"10",
",",
"len",
":",
"clean",
"(",
"options",
"[",
":len",
"]",
")",
"||",
"8",
",",
"digits",
":",
"check_on_off",
"(",
"options",
"[",
":digits",
"]",
")",
"||",
"'on'",
",",
"unique",
":",
"check_on_off",
"(",
"options",
"[",
":unique",
"]",
")",
"||",
"'on'",
",",
"upperalpha",
":",
"check_on_off",
"(",
"options",
"[",
":upperalpha",
"]",
")",
"||",
"'on'",
",",
"loweralpha",
":",
"check_on_off",
"(",
"options",
"[",
":loweralpha",
"]",
")",
"||",
"'on'",
",",
"rnd",
":",
"'new'",
",",
"format",
":",
"'plain'",
"}",
"strings",
"=",
"[",
"]",
"check_for_http_errors",
"{",
"response",
"=",
"open",
"(",
"\"#{@website}strings/?num=#{url_params[:num]}&len=#{url_params[:len]}&digits=#{url_params[:digits]}&unique=#{url_params[:unique]}&upperalpha=#{url_params[:upperalpha]}&loweralpha=#{url_params[:loweralpha]}&rnd=#{url_params[:rnd]}&format=#{url_params[:format]}\"",
")",
"response",
".",
"each_line",
"{",
"|",
"line",
"|",
"strings",
"<<",
"line",
".",
"strip",
"}",
"}",
"strings",
"end"
] |
Random Strings Generator.
It will generate truly random strings of various length and character compositions.
Configuration options:
* <tt>:num</tt> - The number of strings requested. Posibles values: [1,1e4]. Default: 10
* <tt>:len</tt> - The length of the strings. All the strings produced will have the same length. Posibles values: [1,20]. Default: 8
* <tt>:digits</tt> - Determines whether digits (0-9) are allowed to occur in the strings. Posibles values: ['on', 'off']. Default: on
* <tt>:upperalpha</tt> - Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings. Posibles values: ['on', 'off']. Default: on
* <tt>:loweralpha</tt> - Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings. Posibles values: ['on', 'off']. Default: on
* <tt>:unique</tt> - Determines whether the strings picked should be unique (as a series of raffle tickets drawn from a hat) or not (as a series of die rolls).
If unique is set to on, then there is the additional constraint that the number of strings requested (num) must be less than or equal to the number of strings
that exist with the selected length and characters. Posibles values: ['on', 'off']. Default: on
It returns an Array of Strings of the size indicated with <tt>:num</tt>
strings(num: 15, len: 2, digits: 'off', upperalpha: 'off') #=> array of 15 strings of size 2 composed by diggits and lowercase letters with no repetition.
strings(num: 4, len: 10) #=> ["iloqQz2nGa", "D2mgs12kD6", "yMe1eDsinJ", "ZQPaEol6xr"]
|
[
"Random",
"Strings",
"Generator",
"."
] |
8fb43ea50e97191bc5d68b634887b72752f6d63e
|
https://github.com/xuanxu/random_sources/blob/8fb43ea50e97191bc5d68b634887b72752f6d63e/lib/providers/random_org.rb#L104-L123
|
21,356 |
lukebayes/project-sprouts
|
lib/sprout/file_target.rb
|
Sprout.FileTarget.add_library
|
def add_library name, path
if path.is_a?(Array)
path = path.collect { |p| expand_local_path(p) }
else
path = expand_local_path path
end
library = Sprout::Library.new( :name => name, :path => path, :file_target => self )
libraries << library
library
end
|
ruby
|
def add_library name, path
if path.is_a?(Array)
path = path.collect { |p| expand_local_path(p) }
else
path = expand_local_path path
end
library = Sprout::Library.new( :name => name, :path => path, :file_target => self )
libraries << library
library
end
|
[
"def",
"add_library",
"name",
",",
"path",
"if",
"path",
".",
"is_a?",
"(",
"Array",
")",
"path",
"=",
"path",
".",
"collect",
"{",
"|",
"p",
"|",
"expand_local_path",
"(",
"p",
")",
"}",
"else",
"path",
"=",
"expand_local_path",
"path",
"end",
"library",
"=",
"Sprout",
"::",
"Library",
".",
"new",
"(",
":name",
"=>",
"name",
",",
":path",
"=>",
"path",
",",
":file_target",
"=>",
"self",
")",
"libraries",
"<<",
"library",
"library",
"end"
] |
Add a library to the package.
@return [Sprout::Library] The newly created library that was added.
@param name [Symbol] Name that will be used to retrieve this library on +load+.
@param path [File, Path, Array] File or files that will be associated with
this library and copied into the target project library folder when loaded.
(If the path is a directory, all files forward of that directory will be included.)
|
[
"Add",
"a",
"library",
"to",
"the",
"package",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/file_target.rb#L46-L55
|
21,357 |
lukebayes/project-sprouts
|
lib/sprout/file_target.rb
|
Sprout.FileTarget.add_executable
|
def add_executable name, path
path = expand_local_path path
executables << OpenStruct.new( :name => name, :path => path, :file_target => self )
end
|
ruby
|
def add_executable name, path
path = expand_local_path path
executables << OpenStruct.new( :name => name, :path => path, :file_target => self )
end
|
[
"def",
"add_executable",
"name",
",",
"path",
"path",
"=",
"expand_local_path",
"path",
"executables",
"<<",
"OpenStruct",
".",
"new",
"(",
":name",
"=>",
"name",
",",
":path",
"=>",
"path",
",",
":file_target",
"=>",
"self",
")",
"end"
] |
Add an executable to the RubyGem package.
@param name [Symbol] that will be used to retrieve this executable later.
@param path [File] relative path to the executable that will be associated
with this name.
|
[
"Add",
"an",
"executable",
"to",
"the",
"RubyGem",
"package",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/file_target.rb#L64-L67
|
21,358 |
lukebayes/project-sprouts
|
lib/sprout/system/base_system.rb
|
Sprout::System.BaseSystem.execute
|
def execute(tool, options='')
Sprout.stdout.puts("#{tool} #{options}")
runner = get_and_execute_process_runner(tool, options)
error = runner.read_err
result = runner.read
if(result.size > 0)
Sprout.stdout.puts result
end
if(error.size > 0)
raise Sprout::Errors::ExecutionError.new("[ERROR] #{error}")
end
result || error
end
|
ruby
|
def execute(tool, options='')
Sprout.stdout.puts("#{tool} #{options}")
runner = get_and_execute_process_runner(tool, options)
error = runner.read_err
result = runner.read
if(result.size > 0)
Sprout.stdout.puts result
end
if(error.size > 0)
raise Sprout::Errors::ExecutionError.new("[ERROR] #{error}")
end
result || error
end
|
[
"def",
"execute",
"(",
"tool",
",",
"options",
"=",
"''",
")",
"Sprout",
".",
"stdout",
".",
"puts",
"(",
"\"#{tool} #{options}\"",
")",
"runner",
"=",
"get_and_execute_process_runner",
"(",
"tool",
",",
"options",
")",
"error",
"=",
"runner",
".",
"read_err",
"result",
"=",
"runner",
".",
"read",
"if",
"(",
"result",
".",
"size",
">",
"0",
")",
"Sprout",
".",
"stdout",
".",
"puts",
"result",
"end",
"if",
"(",
"error",
".",
"size",
">",
"0",
")",
"raise",
"Sprout",
"::",
"Errors",
"::",
"ExecutionError",
".",
"new",
"(",
"\"[ERROR] #{error}\"",
")",
"end",
"result",
"||",
"error",
"end"
] |
Creates a new process, executes the command
and returns whatever the process wrote to stdout, or stderr.
Raises a +Sprout::Errors::ExecutionError+ if the process writes to stderr
|
[
"Creates",
"a",
"new",
"process",
"executes",
"the",
"command",
"and",
"returns",
"whatever",
"the",
"process",
"wrote",
"to",
"stdout",
"or",
"stderr",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/system/base_system.rb#L70-L85
|
21,359 |
lukebayes/project-sprouts
|
lib/sprout/system/base_system.rb
|
Sprout::System.BaseSystem.execute_thread
|
def execute_thread tool, options='', prompt=nil, &block
t = Thread.new do
Thread.current.abort_on_exception = true
runner = execute_silent(tool, options)
Thread.current['runner'] = runner
out = read_from runner.r, prompt, &block
err = read_from runner.e, prompt, &block
out.join && err.kill
end
# Wait for the runner to be created
# before returning a nil reference
# that never gets populated...
while t['runner'].nil? do
sleep(0.1)
end
if !t.alive?
raise Sprout::Errors::UsageError.new(t['runner'].read_err)
end
t
end
|
ruby
|
def execute_thread tool, options='', prompt=nil, &block
t = Thread.new do
Thread.current.abort_on_exception = true
runner = execute_silent(tool, options)
Thread.current['runner'] = runner
out = read_from runner.r, prompt, &block
err = read_from runner.e, prompt, &block
out.join && err.kill
end
# Wait for the runner to be created
# before returning a nil reference
# that never gets populated...
while t['runner'].nil? do
sleep(0.1)
end
if !t.alive?
raise Sprout::Errors::UsageError.new(t['runner'].read_err)
end
t
end
|
[
"def",
"execute_thread",
"tool",
",",
"options",
"=",
"''",
",",
"prompt",
"=",
"nil",
",",
"&",
"block",
"t",
"=",
"Thread",
".",
"new",
"do",
"Thread",
".",
"current",
".",
"abort_on_exception",
"=",
"true",
"runner",
"=",
"execute_silent",
"(",
"tool",
",",
"options",
")",
"Thread",
".",
"current",
"[",
"'runner'",
"]",
"=",
"runner",
"out",
"=",
"read_from",
"runner",
".",
"r",
",",
"prompt",
",",
"block",
"err",
"=",
"read_from",
"runner",
".",
"e",
",",
"prompt",
",",
"block",
"out",
".",
"join",
"&&",
"err",
".",
"kill",
"end",
"# Wait for the runner to be created",
"# before returning a nil reference",
"# that never gets populated...",
"while",
"t",
"[",
"'runner'",
"]",
".",
"nil?",
"do",
"sleep",
"(",
"0.1",
")",
"end",
"if",
"!",
"t",
".",
"alive?",
"raise",
"Sprout",
"::",
"Errors",
"::",
"UsageError",
".",
"new",
"(",
"t",
"[",
"'runner'",
"]",
".",
"read_err",
")",
"end",
"t",
"end"
] |
Execute a new process in a separate thread and yield whatever output
is written to its stderr and stdout.
@return [Sprout::ProcessRunner]
@param tool [File] Path to the executable.
@param options [String] The command line options that the executable accepts.
@param prompt [Regex] The prompt that will trigger the listener block to be called.
@yield [String] Message that was received from the process, called when #prompt is encountered.
|
[
"Execute",
"a",
"new",
"process",
"in",
"a",
"separate",
"thread",
"and",
"yield",
"whatever",
"output",
"is",
"written",
"to",
"its",
"stderr",
"and",
"stdout",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/system/base_system.rb#L107-L129
|
21,360 |
lukebayes/project-sprouts
|
lib/sprout/system/base_system.rb
|
Sprout::System.BaseSystem.get_and_execute_process_runner
|
def get_and_execute_process_runner tool, options=nil
runner = get_process_runner
runner.execute_open4 clean_path(tool), options
runner
end
|
ruby
|
def get_and_execute_process_runner tool, options=nil
runner = get_process_runner
runner.execute_open4 clean_path(tool), options
runner
end
|
[
"def",
"get_and_execute_process_runner",
"tool",
",",
"options",
"=",
"nil",
"runner",
"=",
"get_process_runner",
"runner",
".",
"execute_open4",
"clean_path",
"(",
"tool",
")",
",",
"options",
"runner",
"end"
] |
Get a process runner and execute the provided +executable+,
with the provided +options+.
+executable+ String path to the external executable file.
+options+ String commandline options to send to the +executable+.
|
[
"Get",
"a",
"process",
"runner",
"and",
"execute",
"the",
"provided",
"+",
"executable",
"+",
"with",
"the",
"provided",
"+",
"options",
"+",
"."
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/system/base_system.rb#L255-L259
|
21,361 |
lukebayes/project-sprouts
|
lib/sprout/system/win_system.rb
|
Sprout::System.WinSystem.get_and_execute_process_runner
|
def get_and_execute_process_runner tool, options=nil
tool = clean_path find_tool(tool)
runner = get_process_runner
runner.execute_win32 tool, options
runner
end
|
ruby
|
def get_and_execute_process_runner tool, options=nil
tool = clean_path find_tool(tool)
runner = get_process_runner
runner.execute_win32 tool, options
runner
end
|
[
"def",
"get_and_execute_process_runner",
"tool",
",",
"options",
"=",
"nil",
"tool",
"=",
"clean_path",
"find_tool",
"(",
"tool",
")",
"runner",
"=",
"get_process_runner",
"runner",
".",
"execute_win32",
"tool",
",",
"options",
"runner",
"end"
] |
Gets the process runner and calls
platform-specific execute method
|
[
"Gets",
"the",
"process",
"runner",
"and",
"calls",
"platform",
"-",
"specific",
"execute",
"method"
] |
6882d7309d617e35350749df84fac5e7d9c5e843
|
https://github.com/lukebayes/project-sprouts/blob/6882d7309d617e35350749df84fac5e7d9c5e843/lib/sprout/system/win_system.rb#L55-L60
|
21,362 |
cheef/shell-spinner
|
lib/shell-spinner.rb
|
ShellSpinner.Runner.build_new_exception
|
def build_new_exception e
e.class.new(e.message)
rescue
Exception.new e.message
end
|
ruby
|
def build_new_exception e
e.class.new(e.message)
rescue
Exception.new e.message
end
|
[
"def",
"build_new_exception",
"e",
"e",
".",
"class",
".",
"new",
"(",
"e",
".",
"message",
")",
"rescue",
"Exception",
".",
"new",
"e",
".",
"message",
"end"
] |
Needs for cases when custom exceptions needs a several required arguments
|
[
"Needs",
"for",
"cases",
"when",
"custom",
"exceptions",
"needs",
"a",
"several",
"required",
"arguments"
] |
4693953da0c714eb839ef5793f0124a080c49bc3
|
https://github.com/cheef/shell-spinner/blob/4693953da0c714eb839ef5793f0124a080c49bc3/lib/shell-spinner.rb#L70-L74
|
21,363 |
akerl/githubstats
|
lib/githubstats.rb
|
GithubStats.User.streak
|
def streak
return [] if streaks.empty?
streaks.last.last.date >= Date.today - 1 ? streaks.last : []
end
|
ruby
|
def streak
return [] if streaks.empty?
streaks.last.last.date >= Date.today - 1 ? streaks.last : []
end
|
[
"def",
"streak",
"return",
"[",
"]",
"if",
"streaks",
".",
"empty?",
"streaks",
".",
"last",
".",
"last",
".",
"date",
">=",
"Date",
".",
"today",
"-",
"1",
"?",
"streaks",
".",
"last",
":",
"[",
"]",
"end"
] |
Set a custom streaks value that takes into account GitHub,
which makes available streak data for longer than a year
|
[
"Set",
"a",
"custom",
"streaks",
"value",
"that",
"takes",
"into",
"account",
"GitHub",
"which",
"makes",
"available",
"streak",
"data",
"for",
"longer",
"than",
"a",
"year"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats.rb#L69-L72
|
21,364 |
akerl/githubstats
|
lib/githubstats.rb
|
GithubStats.User.guess_user
|
def guess_user(names = [])
names << Rugged::Config.global['github.user'] if USE_RUGGED
names << ENV['USER']
names.find { |name| name } || (raise 'Failed to guess username')
end
|
ruby
|
def guess_user(names = [])
names << Rugged::Config.global['github.user'] if USE_RUGGED
names << ENV['USER']
names.find { |name| name } || (raise 'Failed to guess username')
end
|
[
"def",
"guess_user",
"(",
"names",
"=",
"[",
"]",
")",
"names",
"<<",
"Rugged",
"::",
"Config",
".",
"global",
"[",
"'github.user'",
"]",
"if",
"USE_RUGGED",
"names",
"<<",
"ENV",
"[",
"'USER'",
"]",
"names",
".",
"find",
"{",
"|",
"name",
"|",
"name",
"}",
"||",
"(",
"raise",
"'Failed to guess username'",
")",
"end"
] |
Guesses the user's name based on system environment
|
[
"Guesses",
"the",
"user",
"s",
"name",
"based",
"on",
"system",
"environment"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats.rb#L109-L113
|
21,365 |
akerl/githubstats
|
lib/githubstats.rb
|
GithubStats.User.real_streak_rewind
|
def real_streak_rewind(partial_streak)
new_data = download(partial_streak.first.date - 1)
old_data = partial_streak.map(&:to_a)
new_stats = GithubStats::Data.new(new_data + old_data)
partial_streak = new_stats.streaks.last
return partial_streak if partial_streak.first.date != new_stats.start_date
real_streak_rewind partial_streak
end
|
ruby
|
def real_streak_rewind(partial_streak)
new_data = download(partial_streak.first.date - 1)
old_data = partial_streak.map(&:to_a)
new_stats = GithubStats::Data.new(new_data + old_data)
partial_streak = new_stats.streaks.last
return partial_streak if partial_streak.first.date != new_stats.start_date
real_streak_rewind partial_streak
end
|
[
"def",
"real_streak_rewind",
"(",
"partial_streak",
")",
"new_data",
"=",
"download",
"(",
"partial_streak",
".",
"first",
".",
"date",
"-",
"1",
")",
"old_data",
"=",
"partial_streak",
".",
"map",
"(",
":to_a",
")",
"new_stats",
"=",
"GithubStats",
"::",
"Data",
".",
"new",
"(",
"new_data",
"+",
"old_data",
")",
"partial_streak",
"=",
"new_stats",
".",
"streaks",
".",
"last",
"return",
"partial_streak",
"if",
"partial_streak",
".",
"first",
".",
"date",
"!=",
"new_stats",
".",
"start_date",
"real_streak_rewind",
"partial_streak",
"end"
] |
Set a custom longest_streak that takes into account GitHub's
historical records
|
[
"Set",
"a",
"custom",
"longest_streak",
"that",
"takes",
"into",
"account",
"GitHub",
"s",
"historical",
"records"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats.rb#L127-L134
|
21,366 |
akerl/githubstats
|
lib/githubstats.rb
|
GithubStats.User.download
|
def download(to_date = nil)
url = to_date ? @url + "?to=#{to_date.strftime('%Y-%m-%d')}" : @url
res = Curl::Easy.perform(url)
code = res.response_code
raise("Failed loading data from GitHub: #{url} #{code}") if code != 200
html = Nokogiri::HTML(res.body_str)
html.css('.day').map do |x|
x.attributes.values_at('data-date', 'data-count').map(&:value)
end
end
|
ruby
|
def download(to_date = nil)
url = to_date ? @url + "?to=#{to_date.strftime('%Y-%m-%d')}" : @url
res = Curl::Easy.perform(url)
code = res.response_code
raise("Failed loading data from GitHub: #{url} #{code}") if code != 200
html = Nokogiri::HTML(res.body_str)
html.css('.day').map do |x|
x.attributes.values_at('data-date', 'data-count').map(&:value)
end
end
|
[
"def",
"download",
"(",
"to_date",
"=",
"nil",
")",
"url",
"=",
"to_date",
"?",
"@url",
"+",
"\"?to=#{to_date.strftime('%Y-%m-%d')}\"",
":",
"@url",
"res",
"=",
"Curl",
"::",
"Easy",
".",
"perform",
"(",
"url",
")",
"code",
"=",
"res",
".",
"response_code",
"raise",
"(",
"\"Failed loading data from GitHub: #{url} #{code}\"",
")",
"if",
"code",
"!=",
"200",
"html",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"res",
".",
"body_str",
")",
"html",
".",
"css",
"(",
"'.day'",
")",
".",
"map",
"do",
"|",
"x",
"|",
"x",
".",
"attributes",
".",
"values_at",
"(",
"'data-date'",
",",
"'data-count'",
")",
".",
"map",
"(",
":value",
")",
"end",
"end"
] |
Downloads new data from Github
|
[
"Downloads",
"new",
"data",
"from",
"Github"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats.rb#L143-L152
|
21,367 |
airslie/renalware-core
|
app/models/renalware/patient.rb
|
Renalware.Patient.to_s
|
def to_s(format = :default)
title_suffix = " (#{title})" if has_title?
formatted_name = "#{family_name.upcase}, #{given_name}#{title_suffix}"
formatted_nhs_number = " (#{nhs_number})" if nhs_number.present?
case format
when :default then formatted_name
when :long then "#{formatted_name}#{formatted_nhs_number}"
else full_name
end
end
|
ruby
|
def to_s(format = :default)
title_suffix = " (#{title})" if has_title?
formatted_name = "#{family_name.upcase}, #{given_name}#{title_suffix}"
formatted_nhs_number = " (#{nhs_number})" if nhs_number.present?
case format
when :default then formatted_name
when :long then "#{formatted_name}#{formatted_nhs_number}"
else full_name
end
end
|
[
"def",
"to_s",
"(",
"format",
"=",
":default",
")",
"title_suffix",
"=",
"\" (#{title})\"",
"if",
"has_title?",
"formatted_name",
"=",
"\"#{family_name.upcase}, #{given_name}#{title_suffix}\"",
"formatted_nhs_number",
"=",
"\" (#{nhs_number})\"",
"if",
"nhs_number",
".",
"present?",
"case",
"format",
"when",
":default",
"then",
"formatted_name",
"when",
":long",
"then",
"\"#{formatted_name}#{formatted_nhs_number}\"",
"else",
"full_name",
"end",
"end"
] |
Overrides Personable mixin
|
[
"Overrides",
"Personable",
"mixin"
] |
07f20ed4071fc88666590c43a848e7413d5e384b
|
https://github.com/airslie/renalware-core/blob/07f20ed4071fc88666590c43a848e7413d5e384b/app/models/renalware/patient.rb#L120-L129
|
21,368 |
auser/poolparty
|
lib/cloud_providers/connections.rb
|
CloudProviders.Connections.ssh_cleanup_known_hosts!
|
def ssh_cleanup_known_hosts!(hosts=[host, public_ip])
hosts = [hosts] unless hosts.respond_to? :each
hosts.compact.each do |name|
system_run "ssh-keygen -R %s" % name
end
end
|
ruby
|
def ssh_cleanup_known_hosts!(hosts=[host, public_ip])
hosts = [hosts] unless hosts.respond_to? :each
hosts.compact.each do |name|
system_run "ssh-keygen -R %s" % name
end
end
|
[
"def",
"ssh_cleanup_known_hosts!",
"(",
"hosts",
"=",
"[",
"host",
",",
"public_ip",
"]",
")",
"hosts",
"=",
"[",
"hosts",
"]",
"unless",
"hosts",
".",
"respond_to?",
":each",
"hosts",
".",
"compact",
".",
"each",
"do",
"|",
"name",
"|",
"system_run",
"\"ssh-keygen -R %s\"",
"%",
"name",
"end",
"end"
] |
remove hostname and corresponding from known_hosts file. Avoids warning when reusing elastic_ip, and
less likely, if amazone reassigns ip. By default removes both dns_name and ip
|
[
"remove",
"hostname",
"and",
"corresponding",
"from",
"known_hosts",
"file",
".",
"Avoids",
"warning",
"when",
"reusing",
"elastic_ip",
"and",
"less",
"likely",
"if",
"amazone",
"reassigns",
"ip",
".",
"By",
"default",
"removes",
"both",
"dns_name",
"and",
"ip"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/connections.rb#L83-L88
|
21,369 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.to_h
|
def to_h
@raw.reduce(Hash.new(0)) do |acc, elem|
acc.merge(elem.date => elem.score)
end
end
|
ruby
|
def to_h
@raw.reduce(Hash.new(0)) do |acc, elem|
acc.merge(elem.date => elem.score)
end
end
|
[
"def",
"to_h",
"@raw",
".",
"reduce",
"(",
"Hash",
".",
"new",
"(",
"0",
")",
")",
"do",
"|",
"acc",
",",
"elem",
"|",
"acc",
".",
"merge",
"(",
"elem",
".",
"date",
"=>",
"elem",
".",
"score",
")",
"end",
"end"
] |
Create a data object and turn on caching
The data as a hash where the keys are dates and values are scores
|
[
"Create",
"a",
"data",
"object",
"and",
"turn",
"on",
"caching"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L45-L49
|
21,370 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.streaks
|
def streaks
streaks = @raw.each_with_object(Array.new(1, [])) do |point, acc|
point.score.zero? ? acc << [] : acc.last << point
end
streaks.reject!(&:empty?)
streaks
end
|
ruby
|
def streaks
streaks = @raw.each_with_object(Array.new(1, [])) do |point, acc|
point.score.zero? ? acc << [] : acc.last << point
end
streaks.reject!(&:empty?)
streaks
end
|
[
"def",
"streaks",
"streaks",
"=",
"@raw",
".",
"each_with_object",
"(",
"Array",
".",
"new",
"(",
"1",
",",
"[",
"]",
")",
")",
"do",
"|",
"point",
",",
"acc",
"|",
"point",
".",
"score",
".",
"zero?",
"?",
"acc",
"<<",
"[",
"]",
":",
"acc",
".",
"last",
"<<",
"point",
"end",
"streaks",
".",
"reject!",
"(",
":empty?",
")",
"streaks",
"end"
] |
All streaks for a user
|
[
"All",
"streaks",
"for",
"a",
"user"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L88-L94
|
21,371 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.outliers
|
def outliers
return [] if scores.uniq.size < 5
scores.select { |x| ((mean - x) / std_var).abs > GITHUB_MAGIC }.uniq
end
|
ruby
|
def outliers
return [] if scores.uniq.size < 5
scores.select { |x| ((mean - x) / std_var).abs > GITHUB_MAGIC }.uniq
end
|
[
"def",
"outliers",
"return",
"[",
"]",
"if",
"scores",
".",
"uniq",
".",
"size",
"<",
"5",
"scores",
".",
"select",
"{",
"|",
"x",
"|",
"(",
"(",
"mean",
"-",
"x",
")",
"/",
"std_var",
")",
".",
"abs",
">",
"GITHUB_MAGIC",
"}",
".",
"uniq",
"end"
] |
Outliers of the set
|
[
"Outliers",
"of",
"the",
"set"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L139-L142
|
21,372 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.quartiles
|
def quartiles
quartiles = Array.new(5) { [] }
@raw.each_with_object(quartiles) do |elem, acc|
acc[quartile(elem.score)] << elem
end
end
|
ruby
|
def quartiles
quartiles = Array.new(5) { [] }
@raw.each_with_object(quartiles) do |elem, acc|
acc[quartile(elem.score)] << elem
end
end
|
[
"def",
"quartiles",
"quartiles",
"=",
"Array",
".",
"new",
"(",
"5",
")",
"{",
"[",
"]",
"}",
"@raw",
".",
"each_with_object",
"(",
"quartiles",
")",
"do",
"|",
"elem",
",",
"acc",
"|",
"acc",
"[",
"quartile",
"(",
"elem",
".",
"score",
")",
"]",
"<<",
"elem",
"end",
"end"
] |
Return the list split into quartiles
|
[
"Return",
"the",
"list",
"split",
"into",
"quartiles"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L172-L177
|
21,373 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.quartile
|
def quartile(score)
return nil if score < 0 || score > max.score
quartile_boundaries.count { |bound| score > bound }
end
|
ruby
|
def quartile(score)
return nil if score < 0 || score > max.score
quartile_boundaries.count { |bound| score > bound }
end
|
[
"def",
"quartile",
"(",
"score",
")",
"return",
"nil",
"if",
"score",
"<",
"0",
"||",
"score",
">",
"max",
".",
"score",
"quartile_boundaries",
".",
"count",
"{",
"|",
"bound",
"|",
"score",
">",
"bound",
"}",
"end"
] |
Return the quartile of a given score
|
[
"Return",
"the",
"quartile",
"of",
"a",
"given",
"score"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L182-L185
|
21,374 |
akerl/githubstats
|
lib/githubstats/data.rb
|
GithubStats.Data.pad
|
def pad(fill_value = -1, data = @raw.clone)
data = _pad data, 0, fill_value, 0
_pad data, -1, fill_value, 6
end
|
ruby
|
def pad(fill_value = -1, data = @raw.clone)
data = _pad data, 0, fill_value, 0
_pad data, -1, fill_value, 6
end
|
[
"def",
"pad",
"(",
"fill_value",
"=",
"-",
"1",
",",
"data",
"=",
"@raw",
".",
"clone",
")",
"data",
"=",
"_pad",
"data",
",",
"0",
",",
"fill_value",
",",
"0",
"_pad",
"data",
",",
"-",
"1",
",",
"fill_value",
",",
"6",
"end"
] |
Pad the dataset to full week increments
|
[
"Pad",
"the",
"dataset",
"to",
"full",
"week",
"increments"
] |
39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2
|
https://github.com/akerl/githubstats/blob/39ac2383a6e7b83e36ea5f8ac67a0fdb74f4f5c2/lib/githubstats/data.rb#L190-L193
|
21,375 |
airslie/renalware-core
|
app/helpers/renalware/application_helper.rb
|
Renalware.ApplicationHelper.page_title
|
def page_title(separator = Renalware.config.page_title_spearator)
[
content_for(:page_title),
Renalware.config.site_name
].compact.join(separator)
end
|
ruby
|
def page_title(separator = Renalware.config.page_title_spearator)
[
content_for(:page_title),
Renalware.config.site_name
].compact.join(separator)
end
|
[
"def",
"page_title",
"(",
"separator",
"=",
"Renalware",
".",
"config",
".",
"page_title_spearator",
")",
"[",
"content_for",
"(",
":page_title",
")",
",",
"Renalware",
".",
"config",
".",
"site_name",
"]",
".",
"compact",
".",
"join",
"(",
"separator",
")",
"end"
] |
For use in layouts
|
[
"For",
"use",
"in",
"layouts"
] |
07f20ed4071fc88666590c43a848e7413d5e384b
|
https://github.com/airslie/renalware-core/blob/07f20ed4071fc88666590c43a848e7413d5e384b/app/helpers/renalware/application_helper.rb#L24-L29
|
21,376 |
auser/poolparty
|
lib/cloud_providers/ec2/ec2_instance.rb
|
CloudProviders.Ec2Instance.make_image
|
def make_image(opts={})
opts = {:volume => '/',
:size => 6000,
:destination => '/mnt/bundle',
:exclude => nil
}.merge(opts)
image_file = File.join(opts[:destination], opts[:prefix] )
cmds = ["mkdir -p #{opts[:destination]}"]
cmds << "dd if=/dev/zero of=#{image_file} bs=1M count=#{opts[:size]}"
cmds << "mkfs.ext3 -F -j #{image_file}"
cmds << "mkdir -p #{opts[:destination]}/loop"
cmds << "mount -o loop #{image_file} #{opts[:destination]}/loop"
cmds << "rsync -ax #{rsync_excludes(opts[:exclude])} #{opts[:volume]}/ #{opts[:destination]}/loop/"
cmds << "if [[ -f /etc/init.d/ec2-ssh-host-key-gen ]]; then chmod u+x /etc/init.d/ec2-ssh-host-key-gen ;fi"
cmds << "umount #{opts[:destination]}/loop"
self.ssh cmds
image_file
end
|
ruby
|
def make_image(opts={})
opts = {:volume => '/',
:size => 6000,
:destination => '/mnt/bundle',
:exclude => nil
}.merge(opts)
image_file = File.join(opts[:destination], opts[:prefix] )
cmds = ["mkdir -p #{opts[:destination]}"]
cmds << "dd if=/dev/zero of=#{image_file} bs=1M count=#{opts[:size]}"
cmds << "mkfs.ext3 -F -j #{image_file}"
cmds << "mkdir -p #{opts[:destination]}/loop"
cmds << "mount -o loop #{image_file} #{opts[:destination]}/loop"
cmds << "rsync -ax #{rsync_excludes(opts[:exclude])} #{opts[:volume]}/ #{opts[:destination]}/loop/"
cmds << "if [[ -f /etc/init.d/ec2-ssh-host-key-gen ]]; then chmod u+x /etc/init.d/ec2-ssh-host-key-gen ;fi"
cmds << "umount #{opts[:destination]}/loop"
self.ssh cmds
image_file
end
|
[
"def",
"make_image",
"(",
"opts",
"=",
"{",
"}",
")",
"opts",
"=",
"{",
":volume",
"=>",
"'/'",
",",
":size",
"=>",
"6000",
",",
":destination",
"=>",
"'/mnt/bundle'",
",",
":exclude",
"=>",
"nil",
"}",
".",
"merge",
"(",
"opts",
")",
"image_file",
"=",
"File",
".",
"join",
"(",
"opts",
"[",
":destination",
"]",
",",
"opts",
"[",
":prefix",
"]",
")",
"cmds",
"=",
"[",
"\"mkdir -p #{opts[:destination]}\"",
"]",
"cmds",
"<<",
"\"dd if=/dev/zero of=#{image_file} bs=1M count=#{opts[:size]}\"",
"cmds",
"<<",
"\"mkfs.ext3 -F -j #{image_file}\"",
"cmds",
"<<",
"\"mkdir -p #{opts[:destination]}/loop\"",
"cmds",
"<<",
"\"mount -o loop #{image_file} #{opts[:destination]}/loop\"",
"cmds",
"<<",
"\"rsync -ax #{rsync_excludes(opts[:exclude])} #{opts[:volume]}/ #{opts[:destination]}/loop/\"",
"cmds",
"<<",
"\"if [[ -f /etc/init.d/ec2-ssh-host-key-gen ]]; then chmod u+x /etc/init.d/ec2-ssh-host-key-gen ;fi\"",
"cmds",
"<<",
"\"umount #{opts[:destination]}/loop\"",
"self",
".",
"ssh",
"cmds",
"image_file",
"end"
] |
create an image file and copy this instance to the image file.
|
[
"create",
"an",
"image",
"file",
"and",
"copy",
"this",
"instance",
"to",
"the",
"image",
"file",
"."
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/ec2_instance.rb#L149-L166
|
21,377 |
auser/poolparty
|
lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb
|
CloudProviders.ElasticAutoScaler.teardown
|
def teardown
triggers.each do |trigger|
trigger.teardown
end
if autoscaling_groups.select {|n| n.name == name }.empty?
puts "Cloud #{cloud.name} autoscaling group does not exist"
else
self.minimum_instances = 0
self.maximum_instances = 0
@new_launch_configuration_name = old_launch_configuration_name
puts "Updating autoscaling group: #{@new_launch_configuration_name}"
update_autoscaling_group!
puts "Terminating nodes in autoscaling group: #{name}"
reset!
# cloud.nodes.each {|n| n.terminate! }
delete_autoscaling_group!
delete_launch_configuration!
puts ""
end
end
|
ruby
|
def teardown
triggers.each do |trigger|
trigger.teardown
end
if autoscaling_groups.select {|n| n.name == name }.empty?
puts "Cloud #{cloud.name} autoscaling group does not exist"
else
self.minimum_instances = 0
self.maximum_instances = 0
@new_launch_configuration_name = old_launch_configuration_name
puts "Updating autoscaling group: #{@new_launch_configuration_name}"
update_autoscaling_group!
puts "Terminating nodes in autoscaling group: #{name}"
reset!
# cloud.nodes.each {|n| n.terminate! }
delete_autoscaling_group!
delete_launch_configuration!
puts ""
end
end
|
[
"def",
"teardown",
"triggers",
".",
"each",
"do",
"|",
"trigger",
"|",
"trigger",
".",
"teardown",
"end",
"if",
"autoscaling_groups",
".",
"select",
"{",
"|",
"n",
"|",
"n",
".",
"name",
"==",
"name",
"}",
".",
"empty?",
"puts",
"\"Cloud #{cloud.name} autoscaling group does not exist\"",
"else",
"self",
".",
"minimum_instances",
"=",
"0",
"self",
".",
"maximum_instances",
"=",
"0",
"@new_launch_configuration_name",
"=",
"old_launch_configuration_name",
"puts",
"\"Updating autoscaling group: #{@new_launch_configuration_name}\"",
"update_autoscaling_group!",
"puts",
"\"Terminating nodes in autoscaling group: #{name}\"",
"reset!",
"# cloud.nodes.each {|n| n.terminate! }",
"delete_autoscaling_group!",
"delete_launch_configuration!",
"puts",
"\"\"",
"end",
"end"
] |
First, change the min_count to
|
[
"First",
"change",
"the",
"min_count",
"to"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb#L32-L51
|
21,378 |
reevoo/sapience-rb
|
lib/sapience/configuration.rb
|
Sapience.Configuration.map_levels
|
def map_levels
return [] unless defined?(::Logger::Severity)
@@map_levels ||=
::Logger::Severity.constants.each_with_object([]) do |constant, levels|
levels[::Logger::Severity.const_get(constant)] = level_by_index_or_error(constant)
end
end
|
ruby
|
def map_levels
return [] unless defined?(::Logger::Severity)
@@map_levels ||=
::Logger::Severity.constants.each_with_object([]) do |constant, levels|
levels[::Logger::Severity.const_get(constant)] = level_by_index_or_error(constant)
end
end
|
[
"def",
"map_levels",
"return",
"[",
"]",
"unless",
"defined?",
"(",
"::",
"Logger",
"::",
"Severity",
")",
"@@map_levels",
"||=",
"::",
"Logger",
"::",
"Severity",
".",
"constants",
".",
"each_with_object",
"(",
"[",
"]",
")",
"do",
"|",
"constant",
",",
"levels",
"|",
"levels",
"[",
"::",
"Logger",
"::",
"Severity",
".",
"const_get",
"(",
"constant",
")",
"]",
"=",
"level_by_index_or_error",
"(",
"constant",
")",
"end",
"end"
] |
Mapping of Rails and Ruby Logger levels to Sapience levels
|
[
"Mapping",
"of",
"Rails",
"and",
"Ruby",
"Logger",
"levels",
"to",
"Sapience",
"levels"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/configuration.rb#L85-L91
|
21,379 |
airslie/renalware-core
|
app/models/concerns/renalware/broadcasting.rb
|
Renalware.Broadcasting.broadcasting_to_configured_subscribers
|
def broadcasting_to_configured_subscribers
subscribers = Array(Renalware.config.broadcast_subscription_map[self.class.name])
subscribers.each do |subscriber|
# Support String subscribers eg a simple class name as well as Subscriber instances.
subscriber = Subscriber.new(subscriber) unless subscriber.respond_to?(:klass)
subscribe(subscriber.instance, async: subscriber.async?)
end
self
end
|
ruby
|
def broadcasting_to_configured_subscribers
subscribers = Array(Renalware.config.broadcast_subscription_map[self.class.name])
subscribers.each do |subscriber|
# Support String subscribers eg a simple class name as well as Subscriber instances.
subscriber = Subscriber.new(subscriber) unless subscriber.respond_to?(:klass)
subscribe(subscriber.instance, async: subscriber.async?)
end
self
end
|
[
"def",
"broadcasting_to_configured_subscribers",
"subscribers",
"=",
"Array",
"(",
"Renalware",
".",
"config",
".",
"broadcast_subscription_map",
"[",
"self",
".",
"class",
".",
"name",
"]",
")",
"subscribers",
".",
"each",
"do",
"|",
"subscriber",
"|",
"# Support String subscribers eg a simple class name as well as Subscriber instances.",
"subscriber",
"=",
"Subscriber",
".",
"new",
"(",
"subscriber",
")",
"unless",
"subscriber",
".",
"respond_to?",
"(",
":klass",
")",
"subscribe",
"(",
"subscriber",
".",
"instance",
",",
"async",
":",
"subscriber",
".",
"async?",
")",
"end",
"self",
"end"
] |
Subscribes any listeners configured in Renalware.config.broadcast_subscription_map
to the current instance.
Example usage
class SomeServiceObject
include Broadcasting
def call
..
end
end
SomeServiceObject.new(..).broadcasting_to_configured_subscribers.call(..)
See https://github.com/krisleech/wisper
|
[
"Subscribes",
"any",
"listeners",
"configured",
"in",
"Renalware",
".",
"config",
".",
"broadcast_subscription_map",
"to",
"the",
"current",
"instance",
"."
] |
07f20ed4071fc88666590c43a848e7413d5e384b
|
https://github.com/airslie/renalware-core/blob/07f20ed4071fc88666590c43a848e7413d5e384b/app/models/concerns/renalware/broadcasting.rb#L49-L57
|
21,380 |
auser/poolparty
|
lib/poolparty/chef.rb
|
PoolParty.Chef.recipe
|
def recipe(recipe_name, hsh={})
_recipes << recipe_name unless _recipes.include?(recipe_name)
head = {}
tail = head
recipe_name.split("::").each do |key|
unless key == "default"
n = {}
tail[key] = n
tail = n
end
end
tail.replace hsh
override_attributes.merge!(head) unless hsh.empty?
end
|
ruby
|
def recipe(recipe_name, hsh={})
_recipes << recipe_name unless _recipes.include?(recipe_name)
head = {}
tail = head
recipe_name.split("::").each do |key|
unless key == "default"
n = {}
tail[key] = n
tail = n
end
end
tail.replace hsh
override_attributes.merge!(head) unless hsh.empty?
end
|
[
"def",
"recipe",
"(",
"recipe_name",
",",
"hsh",
"=",
"{",
"}",
")",
"_recipes",
"<<",
"recipe_name",
"unless",
"_recipes",
".",
"include?",
"(",
"recipe_name",
")",
"head",
"=",
"{",
"}",
"tail",
"=",
"head",
"recipe_name",
".",
"split",
"(",
"\"::\"",
")",
".",
"each",
"do",
"|",
"key",
"|",
"unless",
"key",
"==",
"\"default\"",
"n",
"=",
"{",
"}",
"tail",
"[",
"key",
"]",
"=",
"n",
"tail",
"=",
"n",
"end",
"end",
"tail",
".",
"replace",
"hsh",
"override_attributes",
".",
"merge!",
"(",
"head",
")",
"unless",
"hsh",
".",
"empty?",
"end"
] |
Adds a chef recipe to the cloud
The hsh parameter is inserted into the override_attributes.
The insertion is performed as follows. If
the recipe name = "foo::bar" then effectively the call is
override_attributes.merge! { :foo => { :bar => hsh } }
|
[
"Adds",
"a",
"chef",
"recipe",
"to",
"the",
"cloud"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/poolparty/chef.rb#L93-L108
|
21,381 |
reevoo/sapience-rb
|
lib/sapience/log_methods.rb
|
Sapience.LogMethods.measure
|
def measure(level, message, params = {}, &block)
index = Sapience.config.level_to_index(level)
if level_index <= index
measure_internal(level, index, message, params, &block)
else
yield params if block
end
end
|
ruby
|
def measure(level, message, params = {}, &block)
index = Sapience.config.level_to_index(level)
if level_index <= index
measure_internal(level, index, message, params, &block)
else
yield params if block
end
end
|
[
"def",
"measure",
"(",
"level",
",",
"message",
",",
"params",
"=",
"{",
"}",
",",
"&",
"block",
")",
"index",
"=",
"Sapience",
".",
"config",
".",
"level_to_index",
"(",
"level",
")",
"if",
"level_index",
"<=",
"index",
"measure_internal",
"(",
"level",
",",
"index",
",",
"message",
",",
"params",
",",
"block",
")",
"else",
"yield",
"params",
"if",
"block",
"end",
"end"
] |
Dynamically supply the log level with every measurement call
|
[
"Dynamically",
"supply",
"the",
"log",
"level",
"with",
"every",
"measurement",
"call"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/log_methods.rb#L109-L116
|
21,382 |
airslie/renalware-core
|
app/helpers/renalware/pd_regimes_helper.rb
|
Renalware.PDRegimesHelper.available_pd_treatments_for
|
def available_pd_treatments_for(regime)
scope = "renalware.pd.treatments"
key = regime.capd? ? "capd" : "apd"
I18n.t(key, scope: scope)
end
|
ruby
|
def available_pd_treatments_for(regime)
scope = "renalware.pd.treatments"
key = regime.capd? ? "capd" : "apd"
I18n.t(key, scope: scope)
end
|
[
"def",
"available_pd_treatments_for",
"(",
"regime",
")",
"scope",
"=",
"\"renalware.pd.treatments\"",
"key",
"=",
"regime",
".",
"capd?",
"?",
"\"capd\"",
":",
"\"apd\"",
"I18n",
".",
"t",
"(",
"key",
",",
"scope",
":",
"scope",
")",
"end"
] |
The list of treatment options, stored in I18n
|
[
"The",
"list",
"of",
"treatment",
"options",
"stored",
"in",
"I18n"
] |
07f20ed4071fc88666590c43a848e7413d5e384b
|
https://github.com/airslie/renalware-core/blob/07f20ed4071fc88666590c43a848e7413d5e384b/app/helpers/renalware/pd_regimes_helper.rb#L24-L28
|
21,383 |
reevoo/sapience-rb
|
lib/sapience/logger.rb
|
Sapience.Logger.log
|
def log(log, message = nil, progname = nil, &block)
# Compatibility with ::Logger
return add(log, message, progname, &block) unless log.is_a?(Sapience::Log)
if @@appender_thread
@@appender_thread << lambda do
Sapience.appenders.each do |appender|
next unless appender.valid?
begin
appender.log(log)
rescue StandardError => exc
$stderr.write("Appender thread: Failed to log to appender: #{appender.inspect}\n #{exc.inspect}")
end
end
Sapience.clear_tags!
end
end
end
|
ruby
|
def log(log, message = nil, progname = nil, &block)
# Compatibility with ::Logger
return add(log, message, progname, &block) unless log.is_a?(Sapience::Log)
if @@appender_thread
@@appender_thread << lambda do
Sapience.appenders.each do |appender|
next unless appender.valid?
begin
appender.log(log)
rescue StandardError => exc
$stderr.write("Appender thread: Failed to log to appender: #{appender.inspect}\n #{exc.inspect}")
end
end
Sapience.clear_tags!
end
end
end
|
[
"def",
"log",
"(",
"log",
",",
"message",
"=",
"nil",
",",
"progname",
"=",
"nil",
",",
"&",
"block",
")",
"# Compatibility with ::Logger",
"return",
"add",
"(",
"log",
",",
"message",
",",
"progname",
",",
"block",
")",
"unless",
"log",
".",
"is_a?",
"(",
"Sapience",
"::",
"Log",
")",
"if",
"@@appender_thread",
"@@appender_thread",
"<<",
"lambda",
"do",
"Sapience",
".",
"appenders",
".",
"each",
"do",
"|",
"appender",
"|",
"next",
"unless",
"appender",
".",
"valid?",
"begin",
"appender",
".",
"log",
"(",
"log",
")",
"rescue",
"StandardError",
"=>",
"exc",
"$stderr",
".",
"write",
"(",
"\"Appender thread: Failed to log to appender: #{appender.inspect}\\n #{exc.inspect}\"",
")",
"end",
"end",
"Sapience",
".",
"clear_tags!",
"end",
"end",
"end"
] |
Returns a Logger instance
Return the logger for a specific class, supports class specific log levels
logger = Sapience::Logger.new(self)
OR
logger = Sapience::Logger.new('MyClass')
Parameters:
application
A class, module or a string with the application/class name
to be used in the logger
level
The initial log level to start with for this logger instance
Default: Sapience.config.default_level
filter [Regexp|Proc]
RegExp: Only include log messages where the class name matches the supplied
regular expression. All other messages will be ignored
Proc: Only include log messages where the supplied Proc returns true
The Proc must return true or false
Place log request on the queue for the Appender thread to write to each
appender in the order that they were registered
|
[
"Returns",
"a",
"Logger",
"instance"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/logger.rb#L132-L148
|
21,384 |
reevoo/sapience-rb
|
lib/sapience/base.rb
|
Sapience.Base.with_payload
|
def with_payload(payload)
current_payload = self.payload
Thread.current[:sapience_payload] = current_payload ? current_payload.merge(payload) : payload
yield
ensure
Thread.current[:sapience_payload] = current_payload
end
|
ruby
|
def with_payload(payload)
current_payload = self.payload
Thread.current[:sapience_payload] = current_payload ? current_payload.merge(payload) : payload
yield
ensure
Thread.current[:sapience_payload] = current_payload
end
|
[
"def",
"with_payload",
"(",
"payload",
")",
"current_payload",
"=",
"self",
".",
"payload",
"Thread",
".",
"current",
"[",
":sapience_payload",
"]",
"=",
"current_payload",
"?",
"current_payload",
".",
"merge",
"(",
"payload",
")",
":",
"payload",
"yield",
"ensure",
"Thread",
".",
"current",
"[",
":sapience_payload",
"]",
"=",
"current_payload",
"end"
] |
Thread specific context information to be logged with every log entry
Add a payload to all log calls on This Thread within the supplied block
logger.with_payload(tracking_number: 12345) do
logger.debug('Hello World')
end
If a log call already includes a pyload, this payload will be merged with
the supplied payload, with the supplied payload taking precedence
logger.with_payload(tracking_number: 12345) do
logger.debug('Hello World', result: 'blah')
end
|
[
"Thread",
"specific",
"context",
"information",
"to",
"be",
"logged",
"with",
"every",
"log",
"entry"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/base.rb#L135-L141
|
21,385 |
reevoo/sapience-rb
|
lib/sapience/base.rb
|
Sapience.Base.include_message?
|
def include_message?(log)
return true if @filter.nil?
if @filter.is_a?(Regexp)
!(@filter =~ log.name).nil?
elsif @filter.is_a?(Proc)
@filter.call(log) == true
end
end
|
ruby
|
def include_message?(log)
return true if @filter.nil?
if @filter.is_a?(Regexp)
!(@filter =~ log.name).nil?
elsif @filter.is_a?(Proc)
@filter.call(log) == true
end
end
|
[
"def",
"include_message?",
"(",
"log",
")",
"return",
"true",
"if",
"@filter",
".",
"nil?",
"if",
"@filter",
".",
"is_a?",
"(",
"Regexp",
")",
"!",
"(",
"@filter",
"=~",
"log",
".",
"name",
")",
".",
"nil?",
"elsif",
"@filter",
".",
"is_a?",
"(",
"Proc",
")",
"@filter",
".",
"call",
"(",
"log",
")",
"==",
"true",
"end",
"end"
] |
Whether to log the supplied message based on the current filter if any
|
[
"Whether",
"to",
"log",
"the",
"supplied",
"message",
"based",
"on",
"the",
"current",
"filter",
"if",
"any"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/base.rb#L205-L213
|
21,386 |
reevoo/sapience-rb
|
lib/sapience/base.rb
|
Sapience.Base.extract_backtrace
|
def extract_backtrace
stack = caller
while (first = stack.first) && first.include?(SELF_PATTERN)
stack.shift
end
stack
end
|
ruby
|
def extract_backtrace
stack = caller
while (first = stack.first) && first.include?(SELF_PATTERN)
stack.shift
end
stack
end
|
[
"def",
"extract_backtrace",
"stack",
"=",
"caller",
"while",
"(",
"first",
"=",
"stack",
".",
"first",
")",
"&&",
"first",
".",
"include?",
"(",
"SELF_PATTERN",
")",
"stack",
".",
"shift",
"end",
"stack",
"end"
] |
Extract the callers backtrace leaving out Sapience
|
[
"Extract",
"the",
"callers",
"backtrace",
"leaving",
"out",
"Sapience"
] |
db0da794d51d209fa3eddf4bc44bebdae6c321bd
|
https://github.com/reevoo/sapience-rb/blob/db0da794d51d209fa3eddf4bc44bebdae6c321bd/lib/sapience/base.rb#L290-L296
|
21,387 |
frictionlessdata/datapackage-rb
|
lib/datapackage/helpers.rb
|
DataPackage.Helpers.dereference_descriptor
|
def dereference_descriptor(resource, base_path: nil, reference_fields: nil)
options = {
base_path: base_path,
reference_fields: reference_fields,
}
case resource
when Hash
resource.inject({}) do |new_resource, (key, val)|
if reference_fields.nil? || reference_fields.include?(key)
new_resource[key] = dereference_descriptor(val, **options)
else
new_resource[key] = val
end
new_resource
end
when Enumerable
resource.map{ |el| dereference_descriptor(el, **options)}
when String
begin
resolve_json_reference(resource, deep_dereference: true, base_path: base_path)
rescue Errno::ENOENT
resource
end
else
resource
end
end
|
ruby
|
def dereference_descriptor(resource, base_path: nil, reference_fields: nil)
options = {
base_path: base_path,
reference_fields: reference_fields,
}
case resource
when Hash
resource.inject({}) do |new_resource, (key, val)|
if reference_fields.nil? || reference_fields.include?(key)
new_resource[key] = dereference_descriptor(val, **options)
else
new_resource[key] = val
end
new_resource
end
when Enumerable
resource.map{ |el| dereference_descriptor(el, **options)}
when String
begin
resolve_json_reference(resource, deep_dereference: true, base_path: base_path)
rescue Errno::ENOENT
resource
end
else
resource
end
end
|
[
"def",
"dereference_descriptor",
"(",
"resource",
",",
"base_path",
":",
"nil",
",",
"reference_fields",
":",
"nil",
")",
"options",
"=",
"{",
"base_path",
":",
"base_path",
",",
"reference_fields",
":",
"reference_fields",
",",
"}",
"case",
"resource",
"when",
"Hash",
"resource",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"new_resource",
",",
"(",
"key",
",",
"val",
")",
"|",
"if",
"reference_fields",
".",
"nil?",
"||",
"reference_fields",
".",
"include?",
"(",
"key",
")",
"new_resource",
"[",
"key",
"]",
"=",
"dereference_descriptor",
"(",
"val",
",",
"**",
"options",
")",
"else",
"new_resource",
"[",
"key",
"]",
"=",
"val",
"end",
"new_resource",
"end",
"when",
"Enumerable",
"resource",
".",
"map",
"{",
"|",
"el",
"|",
"dereference_descriptor",
"(",
"el",
",",
"**",
"options",
")",
"}",
"when",
"String",
"begin",
"resolve_json_reference",
"(",
"resource",
",",
"deep_dereference",
":",
"true",
",",
"base_path",
":",
"base_path",
")",
"rescue",
"Errno",
"::",
"ENOENT",
"resource",
"end",
"else",
"resource",
"end",
"end"
] |
Dereference a resource that can be a URL or path to a JSON file or a hash
Returns a Hash with all values that are URLs or paths dereferenced
|
[
"Dereference",
"a",
"resource",
"that",
"can",
"be",
"a",
"URL",
"or",
"path",
"to",
"a",
"JSON",
"file",
"or",
"a",
"hash",
"Returns",
"a",
"Hash",
"with",
"all",
"values",
"that",
"are",
"URLs",
"or",
"paths",
"dereferenced"
] |
75c082ab928ad417ed046819cde5b64fd0a98d20
|
https://github.com/frictionlessdata/datapackage-rb/blob/75c082ab928ad417ed046819cde5b64fd0a98d20/lib/datapackage/helpers.rb#L6-L32
|
21,388 |
auser/poolparty
|
lib/cloud_providers/ec2/ec2.rb
|
CloudProviders.Ec2.describe_instances
|
def describe_instances(id=nil)
begin
@describe_instances = ec2.describe_instances.reservationSet.item.map do |r|
r.instancesSet.item.map do |i|
inst_options = i.merge(r.merge(:cloud => cloud)).merge(cloud.cloud_provider.dsl_options)
Ec2Instance.new(inst_options)
end
end.flatten
rescue AWS::InvalidClientTokenId => e # AWS credentials invalid
puts "Error contacting AWS: #{e}"
raise e
rescue Exception => e
[]
end
end
|
ruby
|
def describe_instances(id=nil)
begin
@describe_instances = ec2.describe_instances.reservationSet.item.map do |r|
r.instancesSet.item.map do |i|
inst_options = i.merge(r.merge(:cloud => cloud)).merge(cloud.cloud_provider.dsl_options)
Ec2Instance.new(inst_options)
end
end.flatten
rescue AWS::InvalidClientTokenId => e # AWS credentials invalid
puts "Error contacting AWS: #{e}"
raise e
rescue Exception => e
[]
end
end
|
[
"def",
"describe_instances",
"(",
"id",
"=",
"nil",
")",
"begin",
"@describe_instances",
"=",
"ec2",
".",
"describe_instances",
".",
"reservationSet",
".",
"item",
".",
"map",
"do",
"|",
"r",
"|",
"r",
".",
"instancesSet",
".",
"item",
".",
"map",
"do",
"|",
"i",
"|",
"inst_options",
"=",
"i",
".",
"merge",
"(",
"r",
".",
"merge",
"(",
":cloud",
"=>",
"cloud",
")",
")",
".",
"merge",
"(",
"cloud",
".",
"cloud_provider",
".",
"dsl_options",
")",
"Ec2Instance",
".",
"new",
"(",
"inst_options",
")",
"end",
"end",
".",
"flatten",
"rescue",
"AWS",
"::",
"InvalidClientTokenId",
"=>",
"e",
"# AWS credentials invalid",
"puts",
"\"Error contacting AWS: #{e}\"",
"raise",
"e",
"rescue",
"Exception",
"=>",
"e",
"[",
"]",
"end",
"end"
] |
Describe instances
Describe the instances that are available on this cloud
@params id (optional) if present, details about the instance
with the id given will be returned
if not given, details for all instances will be returned
|
[
"Describe",
"instances",
"Describe",
"the",
"instances",
"that",
"are",
"available",
"on",
"this",
"cloud"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/ec2.rb#L335-L349
|
21,389 |
auser/poolparty
|
lib/cloud_providers/ec2/ec2.rb
|
CloudProviders.Ec2.aws_options
|
def aws_options(opts={})
uri=URI.parse(ec2_url)
{ :access_key_id => access_key,
:secret_access_key=> secret_access_key,
:use_ssl => (uri.scheme=='https'),
:path => uri.path,
:host => uri.host,
:port => uri.port
}.merge(opts)
end
|
ruby
|
def aws_options(opts={})
uri=URI.parse(ec2_url)
{ :access_key_id => access_key,
:secret_access_key=> secret_access_key,
:use_ssl => (uri.scheme=='https'),
:path => uri.path,
:host => uri.host,
:port => uri.port
}.merge(opts)
end
|
[
"def",
"aws_options",
"(",
"opts",
"=",
"{",
"}",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"ec2_url",
")",
"{",
":access_key_id",
"=>",
"access_key",
",",
":secret_access_key",
"=>",
"secret_access_key",
",",
":use_ssl",
"=>",
"(",
"uri",
".",
"scheme",
"==",
"'https'",
")",
",",
":path",
"=>",
"uri",
".",
"path",
",",
":host",
"=>",
"uri",
".",
"host",
",",
":port",
"=>",
"uri",
".",
"port",
"}",
".",
"merge",
"(",
"opts",
")",
"end"
] |
prepare options for AWS gem
|
[
"prepare",
"options",
"for",
"AWS",
"gem"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/ec2.rb#L384-L394
|
21,390 |
auser/poolparty
|
lib/cloud_providers/ec2/ec2.rb
|
CloudProviders.Ec2.ec2
|
def ec2
@ec2 ||= begin
AWS::EC2::Base.new( aws_options )
rescue AWS::ArgumentError => e # AWS credentials missing?
puts "Error contacting AWS: #{e}"
raise e
rescue Exception => e
puts "Generic error #{e.class}: #{e}"
end
end
|
ruby
|
def ec2
@ec2 ||= begin
AWS::EC2::Base.new( aws_options )
rescue AWS::ArgumentError => e # AWS credentials missing?
puts "Error contacting AWS: #{e}"
raise e
rescue Exception => e
puts "Generic error #{e.class}: #{e}"
end
end
|
[
"def",
"ec2",
"@ec2",
"||=",
"begin",
"AWS",
"::",
"EC2",
"::",
"Base",
".",
"new",
"(",
"aws_options",
")",
"rescue",
"AWS",
"::",
"ArgumentError",
"=>",
"e",
"# AWS credentials missing?",
"puts",
"\"Error contacting AWS: #{e}\"",
"raise",
"e",
"rescue",
"Exception",
"=>",
"e",
"puts",
"\"Generic error #{e.class}: #{e}\"",
"end",
"end"
] |
Proxy to the raw Grempe amazon-aws @ec2 instance
|
[
"Proxy",
"to",
"the",
"raw",
"Grempe",
"amazon",
"-",
"aws"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/ec2.rb#L397-L406
|
21,391 |
auser/poolparty
|
lib/cloud_providers/ec2/ec2.rb
|
CloudProviders.Ec2.credential_file
|
def credential_file(file=nil)
unless file.nil?
dsl_options[:credential_file]=file
dsl_options.merge!(Ec2.load_keys_from_credential_file(file))
else
fetch(:credential_file)
end
end
|
ruby
|
def credential_file(file=nil)
unless file.nil?
dsl_options[:credential_file]=file
dsl_options.merge!(Ec2.load_keys_from_credential_file(file))
else
fetch(:credential_file)
end
end
|
[
"def",
"credential_file",
"(",
"file",
"=",
"nil",
")",
"unless",
"file",
".",
"nil?",
"dsl_options",
"[",
":credential_file",
"]",
"=",
"file",
"dsl_options",
".",
"merge!",
"(",
"Ec2",
".",
"load_keys_from_credential_file",
"(",
"file",
")",
")",
"else",
"fetch",
"(",
":credential_file",
")",
"end",
"end"
] |
Read credentials from credential_file if one exists
|
[
"Read",
"credentials",
"from",
"credential_file",
"if",
"one",
"exists"
] |
8b4af051833addd84f4282bcedbdffa814d8e033
|
https://github.com/auser/poolparty/blob/8b4af051833addd84f4282bcedbdffa814d8e033/lib/cloud_providers/ec2/ec2.rb#L489-L496
|
21,392 |
config-files-api/config_files_api
|
lib/cfa/base_model.rb
|
CFA.BaseModel.generic_set
|
def generic_set(key, value, tree = data)
modify(key, value, tree) || uncomment(key, value, tree) ||
add_new(key, value, tree)
end
|
ruby
|
def generic_set(key, value, tree = data)
modify(key, value, tree) || uncomment(key, value, tree) ||
add_new(key, value, tree)
end
|
[
"def",
"generic_set",
"(",
"key",
",",
"value",
",",
"tree",
"=",
"data",
")",
"modify",
"(",
"key",
",",
"value",
",",
"tree",
")",
"||",
"uncomment",
"(",
"key",
",",
"value",
",",
"tree",
")",
"||",
"add_new",
"(",
"key",
",",
"value",
",",
"tree",
")",
"end"
] |
powerfull method that sets any value in config. It try to be
smart to at first modify existing value, then replace commented out code
and if even that doesn't work, then append it at the end
@note prefer to use specialized methods of children
|
[
"powerfull",
"method",
"that",
"sets",
"any",
"value",
"in",
"config",
".",
"It",
"try",
"to",
"be",
"smart",
"to",
"at",
"first",
"modify",
"existing",
"value",
"then",
"replace",
"commented",
"out",
"code",
"and",
"if",
"even",
"that",
"doesn",
"t",
"work",
"then",
"append",
"it",
"at",
"the",
"end"
] |
b5e62c465e278b048f82a8173832dbd631e6cf0a
|
https://github.com/config-files-api/config_files_api/blob/b5e62c465e278b048f82a8173832dbd631e6cf0a/lib/cfa/base_model.rb#L64-L67
|
21,393 |
tjchambers/paper_trail_scrapbook
|
lib/paper_trail_scrapbook/chapter.rb
|
PaperTrailScrapbook.Chapter.story
|
def story
updates = changes
return unless tell_story?(updates)
[preface, (updates unless destroy?)].compact.join("\n")
end
|
ruby
|
def story
updates = changes
return unless tell_story?(updates)
[preface, (updates unless destroy?)].compact.join("\n")
end
|
[
"def",
"story",
"updates",
"=",
"changes",
"return",
"unless",
"tell_story?",
"(",
"updates",
")",
"[",
"preface",
",",
"(",
"updates",
"unless",
"destroy?",
")",
"]",
".",
"compact",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] |
Single version historical analysis
@return [String] Human readable description of changes
|
[
"Single",
"version",
"historical",
"analysis"
] |
0503a74909248fc052c56965eee53aa8f5634013
|
https://github.com/tjchambers/paper_trail_scrapbook/blob/0503a74909248fc052c56965eee53aa8f5634013/lib/paper_trail_scrapbook/chapter.rb#L19-L24
|
21,394 |
config-files-api/config_files_api
|
lib/cfa/augeas_parser/writer.rb
|
CFA.AugeasWriter.report_error
|
def report_error
return if yield
error = aug.error
# zero is no error, so problem in lense
if aug.error[:code].nonzero?
raise "Augeas error #{error[:message]}. Details: #{error[:details]}."
end
msg = aug.get("/augeas/text/store/error/message")
location = aug.get("/augeas/text/store/error/lens")
raise "Augeas serializing error: #{msg} at #{location}"
end
|
ruby
|
def report_error
return if yield
error = aug.error
# zero is no error, so problem in lense
if aug.error[:code].nonzero?
raise "Augeas error #{error[:message]}. Details: #{error[:details]}."
end
msg = aug.get("/augeas/text/store/error/message")
location = aug.get("/augeas/text/store/error/lens")
raise "Augeas serializing error: #{msg} at #{location}"
end
|
[
"def",
"report_error",
"return",
"if",
"yield",
"error",
"=",
"aug",
".",
"error",
"# zero is no error, so problem in lense",
"if",
"aug",
".",
"error",
"[",
":code",
"]",
".",
"nonzero?",
"raise",
"\"Augeas error #{error[:message]}. Details: #{error[:details]}.\"",
"end",
"msg",
"=",
"aug",
".",
"get",
"(",
"\"/augeas/text/store/error/message\"",
")",
"location",
"=",
"aug",
".",
"get",
"(",
"\"/augeas/text/store/error/lens\"",
")",
"raise",
"\"Augeas serializing error: #{msg} at #{location}\"",
"end"
] |
Calls block and if it failed, raise exception with details from augeas
why it failed
@yield call to aug that is secured
@raise [RuntimeError]
|
[
"Calls",
"block",
"and",
"if",
"it",
"failed",
"raise",
"exception",
"with",
"details",
"from",
"augeas",
"why",
"it",
"failed"
] |
b5e62c465e278b048f82a8173832dbd631e6cf0a
|
https://github.com/config-files-api/config_files_api/blob/b5e62c465e278b048f82a8173832dbd631e6cf0a/lib/cfa/augeas_parser/writer.rb#L345-L357
|
21,395 |
tjchambers/paper_trail_scrapbook
|
lib/paper_trail_scrapbook/changes.rb
|
PaperTrailScrapbook.Changes.change_log
|
def change_log
text =
changes
.map { |k, v| digest(k, v) }
.compact
.join("\n")
text = text.gsub(' id:', ':') if PaperTrailScrapbook.config.drop_id_suffix
text
end
|
ruby
|
def change_log
text =
changes
.map { |k, v| digest(k, v) }
.compact
.join("\n")
text = text.gsub(' id:', ':') if PaperTrailScrapbook.config.drop_id_suffix
text
end
|
[
"def",
"change_log",
"text",
"=",
"changes",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"digest",
"(",
"k",
",",
"v",
")",
"}",
".",
"compact",
".",
"join",
"(",
"\"\\n\"",
")",
"text",
"=",
"text",
".",
"gsub",
"(",
"' id:'",
",",
"':'",
")",
"if",
"PaperTrailScrapbook",
".",
"config",
".",
"drop_id_suffix",
"text",
"end"
] |
Attribute change analysis
@return [String] Summary analysis of changes
|
[
"Attribute",
"change",
"analysis"
] |
0503a74909248fc052c56965eee53aa8f5634013
|
https://github.com/tjchambers/paper_trail_scrapbook/blob/0503a74909248fc052c56965eee53aa8f5634013/lib/paper_trail_scrapbook/changes.rb#L30-L39
|
21,396 |
heroku/configvar
|
lib/configvar/context.rb
|
ConfigVar.Context.method_missing
|
def method_missing(name, *args)
value = @values[name]
if value.nil? && [email protected]_key?(name)
address = "<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>"
raise NoMethodError.new("undefined method `#{name}' for ##{address}")
end
value
end
|
ruby
|
def method_missing(name, *args)
value = @values[name]
if value.nil? && [email protected]_key?(name)
address = "<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>"
raise NoMethodError.new("undefined method `#{name}' for ##{address}")
end
value
end
|
[
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
")",
"value",
"=",
"@values",
"[",
"name",
"]",
"if",
"value",
".",
"nil?",
"&&",
"!",
"@values",
".",
"has_key?",
"(",
"name",
")",
"address",
"=",
"\"<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>\"",
"raise",
"NoMethodError",
".",
"new",
"(",
"\"undefined method `#{name}' for ##{address}\"",
")",
"end",
"value",
"end"
] |
Fetch a configuration value. The name must be a lowercase version of an
uppercase name defined in the environment. A NoMethodError is raised if
no value matching the specified name is available.
|
[
"Fetch",
"a",
"configuration",
"value",
".",
"The",
"name",
"must",
"be",
"a",
"lowercase",
"version",
"of",
"an",
"uppercase",
"name",
"defined",
"in",
"the",
"environment",
".",
"A",
"NoMethodError",
"is",
"raised",
"if",
"no",
"value",
"matching",
"the",
"specified",
"name",
"is",
"available",
"."
] |
1778604a7878bb49d4512a189c3e7664a0874295
|
https://github.com/heroku/configvar/blob/1778604a7878bb49d4512a189c3e7664a0874295/lib/configvar/context.rb#L19-L26
|
21,397 |
heroku/configvar
|
lib/configvar/context.rb
|
ConfigVar.Context.required_string
|
def required_string(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => value}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
ruby
|
def required_string(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => value}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
[
"def",
"required_string",
"(",
"name",
")",
"required_custom",
"(",
"name",
")",
"do",
"|",
"env",
"|",
"if",
"value",
"=",
"env",
"[",
"name",
".",
"to_s",
".",
"upcase",
"]",
"{",
"name",
"=>",
"value",
"}",
"else",
"raise",
"ConfigError",
".",
"new",
"(",
"\"A value must be provided for #{name.to_s.upcase}\"",
")",
"end",
"end",
"end"
] |
Define a required string config var.
|
[
"Define",
"a",
"required",
"string",
"config",
"var",
"."
] |
1778604a7878bb49d4512a189c3e7664a0874295
|
https://github.com/heroku/configvar/blob/1778604a7878bb49d4512a189c3e7664a0874295/lib/configvar/context.rb#L29-L37
|
21,398 |
heroku/configvar
|
lib/configvar/context.rb
|
ConfigVar.Context.required_int
|
def required_int(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => parse_int(name, value)}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
ruby
|
def required_int(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => parse_int(name, value)}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
[
"def",
"required_int",
"(",
"name",
")",
"required_custom",
"(",
"name",
")",
"do",
"|",
"env",
"|",
"if",
"value",
"=",
"env",
"[",
"name",
".",
"to_s",
".",
"upcase",
"]",
"{",
"name",
"=>",
"parse_int",
"(",
"name",
",",
"value",
")",
"}",
"else",
"raise",
"ConfigError",
".",
"new",
"(",
"\"A value must be provided for #{name.to_s.upcase}\"",
")",
"end",
"end",
"end"
] |
Define a required integer config var.
|
[
"Define",
"a",
"required",
"integer",
"config",
"var",
"."
] |
1778604a7878bb49d4512a189c3e7664a0874295
|
https://github.com/heroku/configvar/blob/1778604a7878bb49d4512a189c3e7664a0874295/lib/configvar/context.rb#L40-L48
|
21,399 |
heroku/configvar
|
lib/configvar/context.rb
|
ConfigVar.Context.required_bool
|
def required_bool(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => parse_bool(name, value)}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
ruby
|
def required_bool(name)
required_custom(name) do |env|
if value = env[name.to_s.upcase]
{name => parse_bool(name, value)}
else
raise ConfigError.new("A value must be provided for #{name.to_s.upcase}")
end
end
end
|
[
"def",
"required_bool",
"(",
"name",
")",
"required_custom",
"(",
"name",
")",
"do",
"|",
"env",
"|",
"if",
"value",
"=",
"env",
"[",
"name",
".",
"to_s",
".",
"upcase",
"]",
"{",
"name",
"=>",
"parse_bool",
"(",
"name",
",",
"value",
")",
"}",
"else",
"raise",
"ConfigError",
".",
"new",
"(",
"\"A value must be provided for #{name.to_s.upcase}\"",
")",
"end",
"end",
"end"
] |
Define a required boolean config var.
|
[
"Define",
"a",
"required",
"boolean",
"config",
"var",
"."
] |
1778604a7878bb49d4512a189c3e7664a0874295
|
https://github.com/heroku/configvar/blob/1778604a7878bb49d4512a189c3e7664a0874295/lib/configvar/context.rb#L51-L59
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.