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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pkubicki/yamled_acl | lib/yamled_acl/controller_extension.rb | YamledAcl.ControllerExtension.authorize_action | def authorize_action
YamledAcl.init(current_user_group_name, params[:controller])
allowed_to?(params[:action]) or raise(YamledAcl::AccessDenied)
end | ruby | def authorize_action
YamledAcl.init(current_user_group_name, params[:controller])
allowed_to?(params[:action]) or raise(YamledAcl::AccessDenied)
end | [
"def",
"authorize_action",
"YamledAcl",
".",
"init",
"(",
"current_user_group_name",
",",
"params",
"[",
":controller",
"]",
")",
"allowed_to?",
"(",
"params",
"[",
":action",
"]",
")",
"or",
"raise",
"(",
"YamledAcl",
"::",
"AccessDenied",
")",
"end"
] | This method should be be called by +before_filter+.
before_filter :authorize_action | [
"This",
"method",
"should",
"be",
"be",
"called",
"by",
"+",
"before_filter",
"+",
"."
] | cd4a02e3b70977112830c5c1f2487e06d43b5a34 | https://github.com/pkubicki/yamled_acl/blob/cd4a02e3b70977112830c5c1f2487e06d43b5a34/lib/yamled_acl/controller_extension.rb#L56-L59 | train |
gluons/mysticonfig | lib/mysticonfig.rb | Mysticonfig.Loader.load | def load
config_file = find_file @filenames
config = Utils.load_auto config_file
config.empty? ? @default_config : @default_config.merge(config)
end | ruby | def load
config_file = find_file @filenames
config = Utils.load_auto config_file
config.empty? ? @default_config : @default_config.merge(config)
end | [
"def",
"load",
"config_file",
"=",
"find_file",
"@filenames",
"config",
"=",
"Utils",
".",
"load_auto",
"config_file",
"config",
".",
"empty?",
"?",
"@default_config",
":",
"@default_config",
".",
"merge",
"(",
"config",
")",
"end"
] | Find and load config file. | [
"Find",
"and",
"load",
"config",
"file",
"."
] | 4bc6354a3f1f77e76f1f1211e9f26acc044ff539 | https://github.com/gluons/mysticonfig/blob/4bc6354a3f1f77e76f1f1211e9f26acc044ff539/lib/mysticonfig.rb#L16-L21 | train |
gluons/mysticonfig | lib/mysticonfig.rb | Mysticonfig.Loader.load_json | def load_json
json_config_file = Utils.lookup_file @filenames[:json]
config = Utils.load_json json_config_file
config.empty? ? @default_config : @default_config.merge(config)
end | ruby | def load_json
json_config_file = Utils.lookup_file @filenames[:json]
config = Utils.load_json json_config_file
config.empty? ? @default_config : @default_config.merge(config)
end | [
"def",
"load_json",
"json_config_file",
"=",
"Utils",
".",
"lookup_file",
"@filenames",
"[",
":json",
"]",
"config",
"=",
"Utils",
".",
"load_json",
"json_config_file",
"config",
".",
"empty?",
"?",
"@default_config",
":",
"@default_config",
".",
"merge",
"(",
"... | Find and load JSON config file. | [
"Find",
"and",
"load",
"JSON",
"config",
"file",
"."
] | 4bc6354a3f1f77e76f1f1211e9f26acc044ff539 | https://github.com/gluons/mysticonfig/blob/4bc6354a3f1f77e76f1f1211e9f26acc044ff539/lib/mysticonfig.rb#L25-L30 | train |
gluons/mysticonfig | lib/mysticonfig.rb | Mysticonfig.Loader.load_yaml | def load_yaml
yaml_config_files = @filenames[:yaml]
yaml_config_file = nil
yaml_config_files.each do |file|
yaml_config_file = Utils.lookup_file file
unless yaml_config_file.nil?
config = Utils.load_yaml(yaml_config_file)
return config.empty? ? @default_config : @d... | ruby | def load_yaml
yaml_config_files = @filenames[:yaml]
yaml_config_file = nil
yaml_config_files.each do |file|
yaml_config_file = Utils.lookup_file file
unless yaml_config_file.nil?
config = Utils.load_yaml(yaml_config_file)
return config.empty? ? @default_config : @d... | [
"def",
"load_yaml",
"yaml_config_files",
"=",
"@filenames",
"[",
":yaml",
"]",
"yaml_config_file",
"=",
"nil",
"yaml_config_files",
".",
"each",
"do",
"|",
"file",
"|",
"yaml_config_file",
"=",
"Utils",
".",
"lookup_file",
"file",
"unless",
"yaml_config_file",
"."... | Find and load YAML config file. | [
"Find",
"and",
"load",
"YAML",
"config",
"file",
"."
] | 4bc6354a3f1f77e76f1f1211e9f26acc044ff539 | https://github.com/gluons/mysticonfig/blob/4bc6354a3f1f77e76f1f1211e9f26acc044ff539/lib/mysticonfig.rb#L34-L47 | train |
georgyangelov/vcs-toolkit | lib/vcs_toolkit/diff.rb | VCSToolkit.Diff.new_content | def new_content(conflict_start='<<<', conflict_switch='>>>', conflict_end='===')
flat_map do |change|
if change.conflict?
version_one = change.diff_one.new_content(conflict_start, conflict_switch, conflict_end)
version_two = change.diff_two.new_content(conflict_start, conflict_switch, ... | ruby | def new_content(conflict_start='<<<', conflict_switch='>>>', conflict_end='===')
flat_map do |change|
if change.conflict?
version_one = change.diff_one.new_content(conflict_start, conflict_switch, conflict_end)
version_two = change.diff_two.new_content(conflict_start, conflict_switch, ... | [
"def",
"new_content",
"(",
"conflict_start",
"=",
"'<<<'",
",",
"conflict_switch",
"=",
"'>>>'",
",",
"conflict_end",
"=",
"'==='",
")",
"flat_map",
"do",
"|",
"change",
"|",
"if",
"change",
".",
"conflict?",
"version_one",
"=",
"change",
".",
"diff_one",
".... | Reconstruct the new sequence from the diff | [
"Reconstruct",
"the",
"new",
"sequence",
"from",
"the",
"diff"
] | 9d73735da090a5e0f612aee04f423306fa512f38 | https://github.com/georgyangelov/vcs-toolkit/blob/9d73735da090a5e0f612aee04f423306fa512f38/lib/vcs_toolkit/diff.rb#L42-L55 | train |
finn-francis/ruby-edit | lib/ruby_edit/source_file.rb | RubyEdit.SourceFile.populate | def populate(content, **options)
generator.create_file(RubyEdit::SOURCE_FILE_LOCATION,
content,
force: true,
verbose: false,
**options)
end | ruby | def populate(content, **options)
generator.create_file(RubyEdit::SOURCE_FILE_LOCATION,
content,
force: true,
verbose: false,
**options)
end | [
"def",
"populate",
"(",
"content",
",",
"**",
"options",
")",
"generator",
".",
"create_file",
"(",
"RubyEdit",
"::",
"SOURCE_FILE_LOCATION",
",",
"content",
",",
"force",
":",
"true",
",",
"verbose",
":",
"false",
",",
"**",
"options",
")",
"end"
] | Populates the sourcefile with the given content
@param content [String] - Usually the output of a bash command
@param **options [key value pairs] -
See https://github.com/piotrmurach/tty-file for TTY::File docs | [
"Populates",
"the",
"sourcefile",
"with",
"the",
"given",
"content"
] | 90022f4de01b420f5321f12c490566d0a1e19a29 | https://github.com/finn-francis/ruby-edit/blob/90022f4de01b420f5321f12c490566d0a1e19a29/lib/ruby_edit/source_file.rb#L16-L22 | train |
cjfuller/rimageanalysistools | lib/rimageanalysistools/skeletonizer.rb | RImageAnalysisTools.Skeletonizer.compute_n | def compute_n(ic)
temp_ic = ImageCoordinate.cloneCoord(ic)
n = -1 # compensate for 0,0 case
x_off = [-1,0,1]
y_off = [-1,0,1]
x_off.each do |x|
y_off.each do |y|
temp_ic[:x] = ic[:x] + x
temp_ic[:y] = ic[:y] + y
if @im.inBounds(temp_ic) and @im[... | ruby | def compute_n(ic)
temp_ic = ImageCoordinate.cloneCoord(ic)
n = -1 # compensate for 0,0 case
x_off = [-1,0,1]
y_off = [-1,0,1]
x_off.each do |x|
y_off.each do |y|
temp_ic[:x] = ic[:x] + x
temp_ic[:y] = ic[:y] + y
if @im.inBounds(temp_ic) and @im[... | [
"def",
"compute_n",
"(",
"ic",
")",
"temp_ic",
"=",
"ImageCoordinate",
".",
"cloneCoord",
"(",
"ic",
")",
"n",
"=",
"-",
"1",
"# compensate for 0,0 case",
"x_off",
"=",
"[",
"-",
"1",
",",
"0",
",",
"1",
"]",
"y_off",
"=",
"[",
"-",
"1",
",",
"0",
... | implementation of skeletonization algorithm presented in Gonzalez & Woods, p 651-652 | [
"implementation",
"of",
"skeletonization",
"algorithm",
"presented",
"in",
"Gonzalez",
"&",
"Woods",
"p",
"651",
"-",
"652"
] | 991aa7a61a8ad7bd902a31d99a19ce135e3cc485 | https://github.com/cjfuller/rimageanalysistools/blob/991aa7a61a8ad7bd902a31d99a19ce135e3cc485/lib/rimageanalysistools/skeletonizer.rb#L44-L71 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.where | def where(hash)
res = hash.inject(squares) do |memo, (attribute, value)|
memo.select { |square| square.attribute_match?(attribute, value) }
end
self.class.new(squares: res)
end | ruby | def where(hash)
res = hash.inject(squares) do |memo, (attribute, value)|
memo.select { |square| square.attribute_match?(attribute, value) }
end
self.class.new(squares: res)
end | [
"def",
"where",
"(",
"hash",
")",
"res",
"=",
"hash",
".",
"inject",
"(",
"squares",
")",
"do",
"|",
"memo",
",",
"(",
"attribute",
",",
"value",
")",
"|",
"memo",
".",
"select",
"{",
"|",
"square",
"|",
"square",
".",
"attribute_match?",
"(",
"att... | Filter the squares with a hash of attribute and matching values.
@param [Hash] hash
attributes to query for.
@return [SquareSet]
==== Example:
# Find all squares where piece is nil
square_set.where(piece: nil) | [
"Filter",
"the",
"squares",
"with",
"a",
"hash",
"of",
"attribute",
"and",
"matching",
"values",
"."
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L128-L133 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.find_by_x_and_y | def find_by_x_and_y(x, y)
select { |square| square.x == x && square.y == y }.first
end | ruby | def find_by_x_and_y(x, y)
select { |square| square.x == x && square.y == y }.first
end | [
"def",
"find_by_x_and_y",
"(",
"x",
",",
"y",
")",
"select",
"{",
"|",
"square",
"|",
"square",
".",
"x",
"==",
"x",
"&&",
"square",
".",
"y",
"==",
"y",
"}",
".",
"first",
"end"
] | Find the square with the matching x and y co-ordinates
@param [Fixnum] x
the x co-ordinate.
@param [Fixnum] y
the y co-ordinate.
@return [Square]
==== Example:
# Find the square at 4,2
square_set.find_by_x_and_y(4, 2) | [
"Find",
"the",
"square",
"with",
"the",
"matching",
"x",
"and",
"y",
"co",
"-",
"ordinates"
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L160-L162 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.in_range | def in_range(origin, distance)
select { |square| Vector.new(origin, square).magnitude <= distance }
end | ruby | def in_range(origin, distance)
select { |square| Vector.new(origin, square).magnitude <= distance }
end | [
"def",
"in_range",
"(",
"origin",
",",
"distance",
")",
"select",
"{",
"|",
"square",
"|",
"Vector",
".",
"new",
"(",
"origin",
",",
"square",
")",
".",
"magnitude",
"<=",
"distance",
"}",
"end"
] | Find all squares within distance of square
@param [Square] square
the originating square
@param [Fixnum] distance
the specified distance from the square
@return [SquareSet]
==== Example:
# Get all squares within 2 squares of square_a
square_set.in_range(square_a, 2) | [
"Find",
"all",
"squares",
"within",
"distance",
"of",
"square"
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L176-L178 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.at_range | def at_range(origin, distance)
select { |square| Vector.new(origin, square).magnitude == distance }
end | ruby | def at_range(origin, distance)
select { |square| Vector.new(origin, square).magnitude == distance }
end | [
"def",
"at_range",
"(",
"origin",
",",
"distance",
")",
"select",
"{",
"|",
"square",
"|",
"Vector",
".",
"new",
"(",
"origin",
",",
"square",
")",
".",
"magnitude",
"==",
"distance",
"}",
"end"
] | Find all squares at distance of square
@param [Square] square
the originating square
@param [Fixnum] distance
the specified distance from the square
@return [SquareSet]
==== Example:
# Get all squares at 2 squares from square_a
square_set.at_range(square_a, 2) | [
"Find",
"all",
"squares",
"at",
"distance",
"of",
"square"
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L192-L194 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.unblocked | def unblocked(origin, square_set)
select { |destination| square_set.between(origin, destination).all?(&:unoccupied?) }
end | ruby | def unblocked(origin, square_set)
select { |destination| square_set.between(origin, destination).all?(&:unoccupied?) }
end | [
"def",
"unblocked",
"(",
"origin",
",",
"square_set",
")",
"select",
"{",
"|",
"destination",
"|",
"square_set",
".",
"between",
"(",
"origin",
",",
"destination",
")",
".",
"all?",
"(",
":unoccupied?",
")",
"}",
"end"
] | Returns destination from the origin that have a clear path
@param [Square] origin
the originating square.
@param [SquareSet] square_set
the board position.
@return [SquareSet] | [
"Returns",
"destination",
"from",
"the",
"origin",
"that",
"have",
"a",
"clear",
"path"
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L264-L266 | train |
mrlhumphreys/board_game_grid | lib/board_game_grid/square_set.rb | BoardGameGrid.SquareSet.between | def between(origin, destination)
vector = Vector.new(origin, destination)
if vector.diagonal? || vector.orthogonal?
point_counter = origin.point
direction = vector.direction
_squares = []
while point_counter != destination.point
point_counter = point_counter + dir... | ruby | def between(origin, destination)
vector = Vector.new(origin, destination)
if vector.diagonal? || vector.orthogonal?
point_counter = origin.point
direction = vector.direction
_squares = []
while point_counter != destination.point
point_counter = point_counter + dir... | [
"def",
"between",
"(",
"origin",
",",
"destination",
")",
"vector",
"=",
"Vector",
".",
"new",
"(",
"origin",
",",
"destination",
")",
"if",
"vector",
".",
"diagonal?",
"||",
"vector",
".",
"orthogonal?",
"point_counter",
"=",
"origin",
".",
"point",
"dire... | Returns squares between a and b.
Only squares that are in the same diagonal will return squares.
@param [Square] a
a square.
@param [Square] b
another square.
@return [SquareSet]
==== Example:
# Get all squares between square_a and square_b
square_set.between(square_a, square_b) | [
"Returns",
"squares",
"between",
"a",
"and",
"b",
".",
"Only",
"squares",
"that",
"are",
"in",
"the",
"same",
"diagonal",
"will",
"return",
"squares",
"."
] | df07a84c7f7db076d055c6063f1e418f0c8ed288 | https://github.com/mrlhumphreys/board_game_grid/blob/df07a84c7f7db076d055c6063f1e418f0c8ed288/lib/board_game_grid/square_set.rb#L282-L302 | train |
bradfeehan/derelict | lib/derelict/parser/version.rb | Derelict.Parser::Version.version | def version
logger.debug "Parsing version from output using #{description}"
matches = output.match PARSE_VERSION_FROM_OUTPUT
raise InvalidFormat.new output if matches.nil?
matches.captures[0]
end | ruby | def version
logger.debug "Parsing version from output using #{description}"
matches = output.match PARSE_VERSION_FROM_OUTPUT
raise InvalidFormat.new output if matches.nil?
matches.captures[0]
end | [
"def",
"version",
"logger",
".",
"debug",
"\"Parsing version from output using #{description}\"",
"matches",
"=",
"output",
".",
"match",
"PARSE_VERSION_FROM_OUTPUT",
"raise",
"InvalidFormat",
".",
"new",
"output",
"if",
"matches",
".",
"nil?",
"matches",
".",
"captures... | Determines the version of Vagrant based on the output | [
"Determines",
"the",
"version",
"of",
"Vagrant",
"based",
"on",
"the",
"output"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/version.rb#L13-L18 | train |
eunomie/valr | lib/valr/repo.rb | Valr.Repo.full_changelog | def full_changelog(first_parent: false, range: nil, branch: nil, from_ancestor_with: nil)
changelog_list = changelog first_parent: first_parent, range: range, branch: branch, from_ancestor_with: from_ancestor_with
if !range.nil?
header = full_changelog_header_range range
elsif !branch.nil?
... | ruby | def full_changelog(first_parent: false, range: nil, branch: nil, from_ancestor_with: nil)
changelog_list = changelog first_parent: first_parent, range: range, branch: branch, from_ancestor_with: from_ancestor_with
if !range.nil?
header = full_changelog_header_range range
elsif !branch.nil?
... | [
"def",
"full_changelog",
"(",
"first_parent",
":",
"false",
",",
"range",
":",
"nil",
",",
"branch",
":",
"nil",
",",
"from_ancestor_with",
":",
"nil",
")",
"changelog_list",
"=",
"changelog",
"first_parent",
":",
"first_parent",
",",
"range",
":",
"range",
... | Get the full changelog including metadata.
@param [Boolean] first_parent Optional, if true limits to first parent commits
@param [String] range Optional, define a specific range of commits
@param [String] branch Optional, show commits in a branch
@param [String] from_ancestor_with Optional, from common ancestor wit... | [
"Get",
"the",
"full",
"changelog",
"including",
"metadata",
"."
] | f6a79ab33dbed0be21b1609405a667139524a251 | https://github.com/eunomie/valr/blob/f6a79ab33dbed0be21b1609405a667139524a251/lib/valr/repo.rb#L38-L48 | train |
eunomie/valr | lib/valr/repo.rb | Valr.Repo.log_messages | def log_messages(first_parent = false, range = nil, branch = nil, from_ancestor_with = nil)
walker = Rugged::Walker.new @repo
if !range.nil?
begin
walker.push_range range
rescue Rugged::ReferenceError
raise Valr::NotValidRangeError.new range
end
elsif !branc... | ruby | def log_messages(first_parent = false, range = nil, branch = nil, from_ancestor_with = nil)
walker = Rugged::Walker.new @repo
if !range.nil?
begin
walker.push_range range
rescue Rugged::ReferenceError
raise Valr::NotValidRangeError.new range
end
elsif !branc... | [
"def",
"log_messages",
"(",
"first_parent",
"=",
"false",
",",
"range",
"=",
"nil",
",",
"branch",
"=",
"nil",
",",
"from_ancestor_with",
"=",
"nil",
")",
"walker",
"=",
"Rugged",
"::",
"Walker",
".",
"new",
"@repo",
"if",
"!",
"range",
".",
"nil?",
"b... | Get log messages for a repository
@param [Boolean] first_parent Optional, if true limit to first parent commits
@param [String] range Optional, define a specific range of commits
@param [String] branch Optional, show commits in a branch
@param [String] from_ancestor_with Optional, from common ancestor with this bra... | [
"Get",
"log",
"messages",
"for",
"a",
"repository"
] | f6a79ab33dbed0be21b1609405a667139524a251 | https://github.com/eunomie/valr/blob/f6a79ab33dbed0be21b1609405a667139524a251/lib/valr/repo.rb#L76-L102 | train |
eunomie/valr | lib/valr/repo.rb | Valr.Repo.full_changelog_header_range | def full_changelog_header_range(range)
from, to = range.split '..'
from_commit, to_commit = [from, to].map { |ref| rev_parse ref }
Koios::Doc.write {
[pre(["from: #{from} <#{from_commit.oid}>",
"to: #{to} <#{to_commit.oid}>"])]
}
end | ruby | def full_changelog_header_range(range)
from, to = range.split '..'
from_commit, to_commit = [from, to].map { |ref| rev_parse ref }
Koios::Doc.write {
[pre(["from: #{from} <#{from_commit.oid}>",
"to: #{to} <#{to_commit.oid}>"])]
}
end | [
"def",
"full_changelog_header_range",
"(",
"range",
")",
"from",
",",
"to",
"=",
"range",
".",
"split",
"'..'",
"from_commit",
",",
"to_commit",
"=",
"[",
"from",
",",
"to",
"]",
".",
"map",
"{",
"|",
"ref",
"|",
"rev_parse",
"ref",
"}",
"Koios",
"::",... | Get the header when a range is defined
@param [String] range Define a specific range of commits
@return [String] header with a range | [
"Get",
"the",
"header",
"when",
"a",
"range",
"is",
"defined"
] | f6a79ab33dbed0be21b1609405a667139524a251 | https://github.com/eunomie/valr/blob/f6a79ab33dbed0be21b1609405a667139524a251/lib/valr/repo.rb#L114-L121 | train |
eunomie/valr | lib/valr/repo.rb | Valr.Repo.full_changelog_header_branch | def full_changelog_header_branch(branch, ancestor)
h = ["branch: #{branch} <#{@repo.references["refs/heads/#{branch}"].target_id}>"]
h << "from ancestor with: #{ancestor} <#{@repo.references["refs/heads/#{ancestor}"].target_id}>" unless ancestor.nil?
Koios::Doc.write {[pre(h)]}
end | ruby | def full_changelog_header_branch(branch, ancestor)
h = ["branch: #{branch} <#{@repo.references["refs/heads/#{branch}"].target_id}>"]
h << "from ancestor with: #{ancestor} <#{@repo.references["refs/heads/#{ancestor}"].target_id}>" unless ancestor.nil?
Koios::Doc.write {[pre(h)]}
end | [
"def",
"full_changelog_header_branch",
"(",
"branch",
",",
"ancestor",
")",
"h",
"=",
"[",
"\"branch: #{branch} <#{@repo.references[\"refs/heads/#{branch}\"].target_id}>\"",
"]",
"h",
"<<",
"\"from ancestor with: #{ancestor} <#{@repo.references[\"refs/heads/#{ancestor}\"].target_id}>\"",... | Get the header when a branch is defined
@param [String] branch Show commits for a branch
@param [String] ancestor Ancestor or nil
@return [String] header with a branch | [
"Get",
"the",
"header",
"when",
"a",
"branch",
"is",
"defined"
] | f6a79ab33dbed0be21b1609405a667139524a251 | https://github.com/eunomie/valr/blob/f6a79ab33dbed0be21b1609405a667139524a251/lib/valr/repo.rb#L127-L131 | train |
OiNutter/grayskull | lib/grayskull/validator.rb | Grayskull.Validator.match_node | def match_node(node,expected,label)
#check type
if !check_type(node,expected['type'],label,expected['ok_empty'])
@errors.push('Error: node ' + label + ' is not of an accepted type. Should be one of ' + expected['accepts'].join(', '))
return false
end
... | ruby | def match_node(node,expected,label)
#check type
if !check_type(node,expected['type'],label,expected['ok_empty'])
@errors.push('Error: node ' + label + ' is not of an accepted type. Should be one of ' + expected['accepts'].join(', '))
return false
end
... | [
"def",
"match_node",
"(",
"node",
",",
"expected",
",",
"label",
")",
"#check type ",
"if",
"!",
"check_type",
"(",
"node",
",",
"expected",
"[",
"'type'",
"]",
",",
"label",
",",
"expected",
"[",
"'ok_empty'",
"]",
")",
"@errors",
".",
"push",
"(",
"'... | Checks file node matches the schema.
Checks type of node against expected type and
checks any children are of the accepted types. | [
"Checks",
"file",
"node",
"matches",
"the",
"schema",
"."
] | c0bcdebcd1ef8220c61953e75c941edf0ae5df16 | https://github.com/OiNutter/grayskull/blob/c0bcdebcd1ef8220c61953e75c941edf0ae5df16/lib/grayskull/validator.rb#L65-L164 | train |
OiNutter/grayskull | lib/grayskull/validator.rb | Grayskull.Validator.check_type | def check_type(node,expected_type,label,accept_nil = false)
valid_type = true;
if(@types.has_key?(expected_type))
valid_type = match_node(node,@types[expected_type],label)
elsif node.class.to_s != expected_type && !(node.kind_of?(NilClass) && (expected_type=='empty' || a... | ruby | def check_type(node,expected_type,label,accept_nil = false)
valid_type = true;
if(@types.has_key?(expected_type))
valid_type = match_node(node,@types[expected_type],label)
elsif node.class.to_s != expected_type && !(node.kind_of?(NilClass) && (expected_type=='empty' || a... | [
"def",
"check_type",
"(",
"node",
",",
"expected_type",
",",
"label",
",",
"accept_nil",
"=",
"false",
")",
"valid_type",
"=",
"true",
";",
"if",
"(",
"@types",
".",
"has_key?",
"(",
"expected_type",
")",
")",
"valid_type",
"=",
"match_node",
"(",
"node",
... | Checks that the node is of the correct type
If the expected node is a custom node type as defined in the schema
It will run `match_node` to check that the node schema matches the
custom type. | [
"Checks",
"that",
"the",
"node",
"is",
"of",
"the",
"correct",
"type"
] | c0bcdebcd1ef8220c61953e75c941edf0ae5df16 | https://github.com/OiNutter/grayskull/blob/c0bcdebcd1ef8220c61953e75c941edf0ae5df16/lib/grayskull/validator.rb#L171-L182 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.cleanup | def cleanup(sprocket_assets = [:javascripts, :stylesheets])
# Remove previous dist path
FileUtils.rm_r build_path if File.exists?(build_path)
# Clean compass project
Compass::Exec::SubCommandUI.new(["clean", project_root]).run!
# Don't initialize Compass assets, the config will take care o... | ruby | def cleanup(sprocket_assets = [:javascripts, :stylesheets])
# Remove previous dist path
FileUtils.rm_r build_path if File.exists?(build_path)
# Clean compass project
Compass::Exec::SubCommandUI.new(["clean", project_root]).run!
# Don't initialize Compass assets, the config will take care o... | [
"def",
"cleanup",
"(",
"sprocket_assets",
"=",
"[",
":javascripts",
",",
":stylesheets",
"]",
")",
"# Remove previous dist path",
"FileUtils",
".",
"rm_r",
"build_path",
"if",
"File",
".",
"exists?",
"(",
"build_path",
")",
"# Clean compass project",
"Compass",
"::"... | Public function for running cleanup of previous build | [
"Public",
"function",
"for",
"running",
"cleanup",
"of",
"previous",
"build"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L32-L46 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.sprockets_build | def sprockets_build(sprocket_assets = [:javascripts, :stylesheets])
sprocket_assets.each do |asset_type|
load_path = File.join(@project_root, asset_type.to_s)
next unless File.exists?(load_path)
sprockets_env.append_path load_path
Dir.new(load_path).each do |filename|
fil... | ruby | def sprockets_build(sprocket_assets = [:javascripts, :stylesheets])
sprocket_assets.each do |asset_type|
load_path = File.join(@project_root, asset_type.to_s)
next unless File.exists?(load_path)
sprockets_env.append_path load_path
Dir.new(load_path).each do |filename|
fil... | [
"def",
"sprockets_build",
"(",
"sprocket_assets",
"=",
"[",
":javascripts",
",",
":stylesheets",
"]",
")",
"sprocket_assets",
".",
"each",
"do",
"|",
"asset_type",
"|",
"load_path",
"=",
"File",
".",
"join",
"(",
"@project_root",
",",
"asset_type",
".",
"to_s"... | Public function for building sprockets assets and minifying | [
"Public",
"function",
"for",
"building",
"sprockets",
"assets",
"and",
"minifying"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L55-L74 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.mustache_template_build | def mustache_template_build(dir, template_file, logic_file)
# Get the class name from an underscore-named file
logic_class_name = underscore_to_camelcase(logic_file)
# Output file should match the syntax of the mustaches config
output_file = logic_file
# Now we can name the logic_file to u... | ruby | def mustache_template_build(dir, template_file, logic_file)
# Get the class name from an underscore-named file
logic_class_name = underscore_to_camelcase(logic_file)
# Output file should match the syntax of the mustaches config
output_file = logic_file
# Now we can name the logic_file to u... | [
"def",
"mustache_template_build",
"(",
"dir",
",",
"template_file",
",",
"logic_file",
")",
"# Get the class name from an underscore-named file",
"logic_class_name",
"=",
"underscore_to_camelcase",
"(",
"logic_file",
")",
"# Output file should match the syntax of the mustaches config... | Render html from a mustache template | [
"Render",
"html",
"from",
"a",
"mustache",
"template"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L128-L148 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.underscore_to_camelcase | def underscore_to_camelcase(underscore_string)
underscore_string = underscore_string.gsub(/(_)/,' ').split(' ').each { |word| word.capitalize! }.join("") unless underscore_string.match(/_/).nil?
underscore_string = underscore_string if underscore_string.match(/_/).nil?
return underscore_string
end | ruby | def underscore_to_camelcase(underscore_string)
underscore_string = underscore_string.gsub(/(_)/,' ').split(' ').each { |word| word.capitalize! }.join("") unless underscore_string.match(/_/).nil?
underscore_string = underscore_string if underscore_string.match(/_/).nil?
return underscore_string
end | [
"def",
"underscore_to_camelcase",
"(",
"underscore_string",
")",
"underscore_string",
"=",
"underscore_string",
".",
"gsub",
"(",
"/",
"/",
",",
"' '",
")",
".",
"split",
"(",
"' '",
")",
".",
"each",
"{",
"|",
"word",
"|",
"word",
".",
"capitalize!",
"}",... | Conver underscore to camelcase | [
"Conver",
"underscore",
"to",
"camelcase"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L156-L160 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.sprockets_env | def sprockets_env
@sprockets_env ||= Sprockets::Environment.new(project_root) { |env| env.logger = Logger.new(STDOUT) }
end | ruby | def sprockets_env
@sprockets_env ||= Sprockets::Environment.new(project_root) { |env| env.logger = Logger.new(STDOUT) }
end | [
"def",
"sprockets_env",
"@sprockets_env",
"||=",
"Sprockets",
"::",
"Environment",
".",
"new",
"(",
"project_root",
")",
"{",
"|",
"env",
"|",
"env",
".",
"logger",
"=",
"Logger",
".",
"new",
"(",
"STDOUT",
")",
"}",
"end"
] | Initialize sprockets environment | [
"Initialize",
"sprockets",
"environment"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L163-L165 | train |
barnabyalter/microservice_precompiler | lib/microservice_precompiler/builder.rb | MicroservicePrecompiler.Builder.minify | def minify(asset, format)
asset = asset.to_s
# Minify JS
return Uglifier.compile(asset) if format.eql?("js")
# Minify CSS
return YUI::CssCompressor.new.compress(asset) if format.eql?("css")
# Return string representation if not minimizing
return asset
end | ruby | def minify(asset, format)
asset = asset.to_s
# Minify JS
return Uglifier.compile(asset) if format.eql?("js")
# Minify CSS
return YUI::CssCompressor.new.compress(asset) if format.eql?("css")
# Return string representation if not minimizing
return asset
end | [
"def",
"minify",
"(",
"asset",
",",
"format",
")",
"asset",
"=",
"asset",
".",
"to_s",
"# Minify JS",
"return",
"Uglifier",
".",
"compile",
"(",
"asset",
")",
"if",
"format",
".",
"eql?",
"(",
"\"js\"",
")",
"# Minify CSS",
"return",
"YUI",
"::",
"CssCom... | Minify assets in format | [
"Minify",
"assets",
"in",
"format"
] | c485955eaf27ab70970426b4aeecd20740ac482c | https://github.com/barnabyalter/microservice_precompiler/blob/c485955eaf27ab70970426b4aeecd20740ac482c/lib/microservice_precompiler/builder.rb#L168-L176 | train |
jeremyd/virtualmonkey | lib/virtualmonkey/deployment_runner.rb | VirtualMonkey.DeploymentRunner.launch_all | def launch_all
@servers.each { |s|
begin
object_behavior(s, :start)
rescue Exception => e
raise e unless e.message =~ /AlreadyLaunchedError/
end
}
end | ruby | def launch_all
@servers.each { |s|
begin
object_behavior(s, :start)
rescue Exception => e
raise e unless e.message =~ /AlreadyLaunchedError/
end
}
end | [
"def",
"launch_all",
"@servers",
".",
"each",
"{",
"|",
"s",
"|",
"begin",
"object_behavior",
"(",
"s",
",",
":start",
")",
"rescue",
"Exception",
"=>",
"e",
"raise",
"e",
"unless",
"e",
".",
"message",
"=~",
"/",
"/",
"end",
"}",
"end"
] | Launch all servers in the deployment. | [
"Launch",
"all",
"servers",
"in",
"the",
"deployment",
"."
] | b2c7255f20ac5ec881eb90afbb5e712160db0dcb | https://github.com/jeremyd/virtualmonkey/blob/b2c7255f20ac5ec881eb90afbb5e712160db0dcb/lib/virtualmonkey/deployment_runner.rb#L57-L65 | train |
jeremyd/virtualmonkey | lib/virtualmonkey/deployment_runner.rb | VirtualMonkey.DeploymentRunner.check_monitoring | def check_monitoring
@servers.each do |server|
server.settings
response = nil
count = 0
until response || count > 20 do
begin
response = server.monitoring
rescue
response = nil
count += 1
sleep 10
end
... | ruby | def check_monitoring
@servers.each do |server|
server.settings
response = nil
count = 0
until response || count > 20 do
begin
response = server.monitoring
rescue
response = nil
count += 1
sleep 10
end
... | [
"def",
"check_monitoring",
"@servers",
".",
"each",
"do",
"|",
"server",
"|",
"server",
".",
"settings",
"response",
"=",
"nil",
"count",
"=",
"0",
"until",
"response",
"||",
"count",
">",
"20",
"do",
"begin",
"response",
"=",
"server",
".",
"monitoring",
... | Checks that monitoring is enabled on all servers in the deployment. Will raise an error if monitoring is not enabled. | [
"Checks",
"that",
"monitoring",
"is",
"enabled",
"on",
"all",
"servers",
"in",
"the",
"deployment",
".",
"Will",
"raise",
"an",
"error",
"if",
"monitoring",
"is",
"not",
"enabled",
"."
] | b2c7255f20ac5ec881eb90afbb5e712160db0dcb | https://github.com/jeremyd/virtualmonkey/blob/b2c7255f20ac5ec881eb90afbb5e712160db0dcb/lib/virtualmonkey/deployment_runner.rb#L248-L272 | train |
malditogeek/redisrecord | lib/redisrecord.rb | RedisRecord.Model.add_attributes | def add_attributes(hash)
hash.each_pair do |k,v|
k = k.to_sym
#raise DuplicateAttribute.new("#{k}") unless (k == :id or !self.respond_to?(k))
if k == :id or !self.respond_to?(k)
@cached_attrs[k] = v
meta = class << self; self; end
meta.send(:define_method, k) ... | ruby | def add_attributes(hash)
hash.each_pair do |k,v|
k = k.to_sym
#raise DuplicateAttribute.new("#{k}") unless (k == :id or !self.respond_to?(k))
if k == :id or !self.respond_to?(k)
@cached_attrs[k] = v
meta = class << self; self; end
meta.send(:define_method, k) ... | [
"def",
"add_attributes",
"(",
"hash",
")",
"hash",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"k",
"=",
"k",
".",
"to_sym",
"#raise DuplicateAttribute.new(\"#{k}\") unless (k == :id or !self.respond_to?(k))",
"if",
"k",
"==",
":id",
"or",
"!",
"self",
".",... | Add attributes to the instance cache and define the accessor methods | [
"Add",
"attributes",
"to",
"the",
"instance",
"cache",
"and",
"define",
"the",
"accessor",
"methods"
] | ae2d9904c622559904b9b6b02f00f9e9635525d1 | https://github.com/malditogeek/redisrecord/blob/ae2d9904c622559904b9b6b02f00f9e9635525d1/lib/redisrecord.rb#L343-L358 | train |
malditogeek/redisrecord | lib/redisrecord.rb | RedisRecord.Model.add_foreign_keys_as_attributes | def add_foreign_keys_as_attributes
@@reflections[self.class.name.to_sym][:belongs_to].each do |klass|
add_attribute klass.to_s.foreign_key.to_sym
end
end | ruby | def add_foreign_keys_as_attributes
@@reflections[self.class.name.to_sym][:belongs_to].each do |klass|
add_attribute klass.to_s.foreign_key.to_sym
end
end | [
"def",
"add_foreign_keys_as_attributes",
"@@reflections",
"[",
"self",
".",
"class",
".",
"name",
".",
"to_sym",
"]",
"[",
":belongs_to",
"]",
".",
"each",
"do",
"|",
"klass",
"|",
"add_attribute",
"klass",
".",
"to_s",
".",
"foreign_key",
".",
"to_sym",
"en... | Add the foreign key for the belongs_to relationships | [
"Add",
"the",
"foreign",
"key",
"for",
"the",
"belongs_to",
"relationships"
] | ae2d9904c622559904b9b6b02f00f9e9635525d1 | https://github.com/malditogeek/redisrecord/blob/ae2d9904c622559904b9b6b02f00f9e9635525d1/lib/redisrecord.rb#L366-L370 | train |
jutonz/dctl_rb | lib/dctl/main.rb | Dctl.Main.image_tag | def image_tag(image, version: current_version_for_image(image))
org = settings.org
project = settings.project
tag = "#{org}/#{project}-#{env}-#{image}"
if !version.nil?
version = version.to_i
tag +=
if version.negative?
current_version = current_ver... | ruby | def image_tag(image, version: current_version_for_image(image))
org = settings.org
project = settings.project
tag = "#{org}/#{project}-#{env}-#{image}"
if !version.nil?
version = version.to_i
tag +=
if version.negative?
current_version = current_ver... | [
"def",
"image_tag",
"(",
"image",
",",
"version",
":",
"current_version_for_image",
"(",
"image",
")",
")",
"org",
"=",
"settings",
".",
"org",
"project",
"=",
"settings",
".",
"project",
"tag",
"=",
"\"#{org}/#{project}-#{env}-#{image}\"",
"if",
"!",
"version",... | Generate the full tag for the given image, concatenating the org,
project, env, image name, and version.
Pass `version: nil` to exclude the version portion.
@example
image_tag("app") # => jutonz/dctl-dev-app:1 | [
"Generate",
"the",
"full",
"tag",
"for",
"the",
"given",
"image",
"concatenating",
"the",
"org",
"project",
"env",
"image",
"name",
"and",
"version",
"."
] | 55bae93a0ae642841231abe862a578344b732c5f | https://github.com/jutonz/dctl_rb/blob/55bae93a0ae642841231abe862a578344b732c5f/lib/dctl/main.rb#L18-L35 | train |
jutonz/dctl_rb | lib/dctl/main.rb | Dctl.Main.config_path | def config_path
path = File.expand_path ".dctl.yml", Dir.pwd
unless File.exist? path
error = "Could not find config file at #{path}"
puts Rainbow(error).red
exit 1
end
path
end | ruby | def config_path
path = File.expand_path ".dctl.yml", Dir.pwd
unless File.exist? path
error = "Could not find config file at #{path}"
puts Rainbow(error).red
exit 1
end
path
end | [
"def",
"config_path",
"path",
"=",
"File",
".",
"expand_path",
"\".dctl.yml\"",
",",
"Dir",
".",
"pwd",
"unless",
"File",
".",
"exist?",
"path",
"error",
"=",
"\"Could not find config file at #{path}\"",
"puts",
"Rainbow",
"(",
"error",
")",
".",
"red",
"exit",
... | Returns the path to the .dctl.yml file for the current project | [
"Returns",
"the",
"path",
"to",
"the",
".",
"dctl",
".",
"yml",
"file",
"for",
"the",
"current",
"project"
] | 55bae93a0ae642841231abe862a578344b732c5f | https://github.com/jutonz/dctl_rb/blob/55bae93a0ae642841231abe862a578344b732c5f/lib/dctl/main.rb#L90-L100 | train |
jutonz/dctl_rb | lib/dctl/main.rb | Dctl.Main.define_custom_commands | def define_custom_commands(klass)
Array(settings.custom_commands).each do |command, args|
klass.send(:desc, command, "[Custom Command] #{command}")
# Concat with string so we can use exec rather than executing multiple
# subshells. Exec allows us to reuse the shell in which dctl is being
... | ruby | def define_custom_commands(klass)
Array(settings.custom_commands).each do |command, args|
klass.send(:desc, command, "[Custom Command] #{command}")
# Concat with string so we can use exec rather than executing multiple
# subshells. Exec allows us to reuse the shell in which dctl is being
... | [
"def",
"define_custom_commands",
"(",
"klass",
")",
"Array",
"(",
"settings",
".",
"custom_commands",
")",
".",
"each",
"do",
"|",
"command",
",",
"args",
"|",
"klass",
".",
"send",
"(",
":desc",
",",
"command",
",",
"\"[Custom Command] #{command}\"",
")",
"... | If there are user defined commands in .dctl.yml, dynamically add them to
the passed thor CLI so they may be executed. | [
"If",
"there",
"are",
"user",
"defined",
"commands",
"in",
".",
"dctl",
".",
"yml",
"dynamically",
"add",
"them",
"to",
"the",
"passed",
"thor",
"CLI",
"so",
"they",
"may",
"be",
"executed",
"."
] | 55bae93a0ae642841231abe862a578344b732c5f | https://github.com/jutonz/dctl_rb/blob/55bae93a0ae642841231abe862a578344b732c5f/lib/dctl/main.rb#L164-L177 | train |
jutonz/dctl_rb | lib/dctl/main.rb | Dctl.Main.check_settings! | def check_settings!
required_keys = %w(
org
project
)
required_keys.each do |key|
unless Settings.send key
error = "Config is missing required key '#{key}'. Please add it " \
"to #{config_path} and try again."
error += "\n\nFor more info, see ht... | ruby | def check_settings!
required_keys = %w(
org
project
)
required_keys.each do |key|
unless Settings.send key
error = "Config is missing required key '#{key}'. Please add it " \
"to #{config_path} and try again."
error += "\n\nFor more info, see ht... | [
"def",
"check_settings!",
"required_keys",
"=",
"%w(",
"org",
"project",
")",
"required_keys",
".",
"each",
"do",
"|",
"key",
"|",
"unless",
"Settings",
".",
"send",
"key",
"error",
"=",
"\"Config is missing required key '#{key}'. Please add it \"",
"\"to #{config_path}... | Ensure the current project's .dctl.yml contains all the requisite keys. | [
"Ensure",
"the",
"current",
"project",
"s",
".",
"dctl",
".",
"yml",
"contains",
"all",
"the",
"requisite",
"keys",
"."
] | 55bae93a0ae642841231abe862a578344b732c5f | https://github.com/jutonz/dctl_rb/blob/55bae93a0ae642841231abe862a578344b732c5f/lib/dctl/main.rb#L181-L196 | train |
sinefunc/sinatra-helpers | lib/sinatra/helpers.rb | Sinatra.Helpers.select_options | def select_options(pairs, current = nil, prompt = nil)
pairs.unshift([prompt, '']) if prompt
pairs.map { |label, value|
tag(:option, label, :value => value, :selected => (current == value))
}.join("\n")
end | ruby | def select_options(pairs, current = nil, prompt = nil)
pairs.unshift([prompt, '']) if prompt
pairs.map { |label, value|
tag(:option, label, :value => value, :selected => (current == value))
}.join("\n")
end | [
"def",
"select_options",
"(",
"pairs",
",",
"current",
"=",
"nil",
",",
"prompt",
"=",
"nil",
")",
"pairs",
".",
"unshift",
"(",
"[",
"prompt",
",",
"''",
"]",
")",
"if",
"prompt",
"pairs",
".",
"map",
"{",
"|",
"label",
",",
"value",
"|",
"tag",
... | Accepts a list of pairs and produces option tags.
@example
select_options([['One', 1], ['Two', 2]])
select_options([['One', 1], ['Two', 2]], 1)
select_options([['One', 1], ['Two', 2]], 1, '- Choose -')
# using it with the provided date helpers...
select_options year_choices, 2010 # select 2010 as def... | [
"Accepts",
"a",
"list",
"of",
"pairs",
"and",
"produces",
"option",
"tags",
"."
] | d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4 | https://github.com/sinefunc/sinatra-helpers/blob/d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4/lib/sinatra/helpers.rb#L122-L128 | train |
sinefunc/sinatra-helpers | lib/sinatra/helpers.rb | Sinatra.Helpers.errors_on | def errors_on(object, options = { :class => 'errors' }, &block)
return if object.errors.empty?
lines = if object.errors.respond_to?(:full_messages)
object.errors.full_messages
else
HamlErrorPresenter.new(object.errors).present(self, &block)
end
haml_tag(:div, options) do
... | ruby | def errors_on(object, options = { :class => 'errors' }, &block)
return if object.errors.empty?
lines = if object.errors.respond_to?(:full_messages)
object.errors.full_messages
else
HamlErrorPresenter.new(object.errors).present(self, &block)
end
haml_tag(:div, options) do
... | [
"def",
"errors_on",
"(",
"object",
",",
"options",
"=",
"{",
":class",
"=>",
"'errors'",
"}",
",",
"&",
"block",
")",
"return",
"if",
"object",
".",
"errors",
".",
"empty?",
"lines",
"=",
"if",
"object",
".",
"errors",
".",
"respond_to?",
"(",
":full_m... | Presents errors on your form. Takes the explicit approach and assumes
that for every form you have, the copy for the errors are important,
instead of producing canned responses.
Allows you to do the following in your haml view:
@example
- errors_on @user do |e|
- e.on [:email, :not_present], "We need you... | [
"Presents",
"errors",
"on",
"your",
"form",
".",
"Takes",
"the",
"explicit",
"approach",
"and",
"assumes",
"that",
"for",
"every",
"form",
"you",
"have",
"the",
"copy",
"for",
"the",
"errors",
"are",
"important",
"instead",
"of",
"producing",
"canned",
"resp... | d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4 | https://github.com/sinefunc/sinatra-helpers/blob/d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4/lib/sinatra/helpers.rb#L161-L177 | train |
sinefunc/sinatra-helpers | lib/sinatra/helpers.rb | Sinatra.Helpers.percentage | def percentage(number, precision = 2)
return if number.to_s.empty?
ret = "%02.#{ precision }f%" % number
ret.gsub(/\.0*%$/, '%')
end | ruby | def percentage(number, precision = 2)
return if number.to_s.empty?
ret = "%02.#{ precision }f%" % number
ret.gsub(/\.0*%$/, '%')
end | [
"def",
"percentage",
"(",
"number",
",",
"precision",
"=",
"2",
")",
"return",
"if",
"number",
".",
"to_s",
".",
"empty?",
"ret",
"=",
"\"%02.#{ precision }f%\"",
"%",
"number",
"ret",
".",
"gsub",
"(",
"/",
"\\.",
"/",
",",
"'%'",
")",
"end"
] | Show the percentage representation of a numeric value.
@example
percentage(100) == "100.00%"
percentage(100, 0) == "100%"
@param [Numeric] number A numeric value
@param [Fixnum] precision (defaults to 2) Number of decimals to show.
@return [String] the number displayed as a percentage
@return [nil] giv... | [
"Show",
"the",
"percentage",
"representation",
"of",
"a",
"numeric",
"value",
"."
] | d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4 | https://github.com/sinefunc/sinatra-helpers/blob/d13b3caf83fdc0ba73a8d1a3fab80f562fbbcdb4/lib/sinatra/helpers.rb#L234-L239 | train |
minch/buoy_data | lib/buoy_data/noaa_buoy_observation.rb | BuoyData.NoaaBuoyObservation.google_chart_url | def google_chart_url
max = 120
response = get_all
return unless response
historical_data = []
response.each_with_index do |row, index|
break if index >= max
next if row.match(/^#/)
row = row.split(/ ?/)
historical_data << row[5]
end
return if ... | ruby | def google_chart_url
max = 120
response = get_all
return unless response
historical_data = []
response.each_with_index do |row, index|
break if index >= max
next if row.match(/^#/)
row = row.split(/ ?/)
historical_data << row[5]
end
return if ... | [
"def",
"google_chart_url",
"max",
"=",
"120",
"response",
"=",
"get_all",
"return",
"unless",
"response",
"historical_data",
"=",
"[",
"]",
"response",
".",
"each_with_index",
"do",
"|",
"row",
",",
"index",
"|",
"break",
"if",
"index",
">=",
"max",
"next",
... | Get a graph of the historical data for the given buoy.
Inspired by:
https://github.com/thepug/nbdc_graph/blob/master/generate_graphs.py | [
"Get",
"a",
"graph",
"of",
"the",
"historical",
"data",
"for",
"the",
"given",
"buoy",
"."
] | 6f1e36828ed6df1cb2610d09cc046118291dbe55 | https://github.com/minch/buoy_data/blob/6f1e36828ed6df1cb2610d09cc046118291dbe55/lib/buoy_data/noaa_buoy_observation.rb#L49-L66 | train |
octoai/gem-octocore-cassandra | lib/octocore-cassandra/models/contactus.rb | Octo.ContactUs.send_email | def send_email
# Send thankyou mail
subject = 'Thanks for contacting us - Octo.ai'
opts = {
text: 'Hey we will get in touch with you shortly. Thanks :)',
name: self.firstname + ' ' + self.lastname
}
Octo::Email.send(self.email, subject, opts)
# Send mail to aron and param
... | ruby | def send_email
# Send thankyou mail
subject = 'Thanks for contacting us - Octo.ai'
opts = {
text: 'Hey we will get in touch with you shortly. Thanks :)',
name: self.firstname + ' ' + self.lastname
}
Octo::Email.send(self.email, subject, opts)
# Send mail to aron and param
... | [
"def",
"send_email",
"# Send thankyou mail",
"subject",
"=",
"'Thanks for contacting us - Octo.ai'",
"opts",
"=",
"{",
"text",
":",
"'Hey we will get in touch with you shortly. Thanks :)'",
",",
"name",
":",
"self",
".",
"firstname",
"+",
"' '",
"+",
"self",
".",
"lastn... | Send Email after model save | [
"Send",
"Email",
"after",
"model",
"save"
] | c0977dce5ba0eb174ff810f161aba151069935df | https://github.com/octoai/gem-octocore-cassandra/blob/c0977dce5ba0eb174ff810f161aba151069935df/lib/octocore-cassandra/models/contactus.rb#L19-L39 | train |
conversation/raca | lib/raca/servers.rb | Raca.Servers.create | def create(server_name, flavor_name, image_name, files = {})
request = {
"server" => {
"name" => server_name,
"imageRef" => image_name_to_id(image_name),
"flavorRef" => flavor_name_to_id(flavor_name),
}
}
files.each do |path, blob|
request['server'... | ruby | def create(server_name, flavor_name, image_name, files = {})
request = {
"server" => {
"name" => server_name,
"imageRef" => image_name_to_id(image_name),
"flavorRef" => flavor_name_to_id(flavor_name),
}
}
files.each do |path, blob|
request['server'... | [
"def",
"create",
"(",
"server_name",
",",
"flavor_name",
",",
"image_name",
",",
"files",
"=",
"{",
"}",
")",
"request",
"=",
"{",
"\"server\"",
"=>",
"{",
"\"name\"",
"=>",
"server_name",
",",
"\"imageRef\"",
"=>",
"image_name_to_id",
"(",
"image_name",
")"... | create a new server on Rackspace.
server_name is a free text name you want to assign the server.
flavor_name is a string that describes the amount of RAM. If you enter
an invalid option a list of valid options will be raised.
image_name is a string that describes the OS image to use. If you enter
an invalid opt... | [
"create",
"a",
"new",
"server",
"on",
"Rackspace",
"."
] | fa69dfde22359cc0e06f655055be4eadcc7019c0 | https://github.com/conversation/raca/blob/fa69dfde22359cc0e06f655055be4eadcc7019c0/lib/raca/servers.rb#L43-L62 | train |
jeremyruppel/codependency | lib/codependency/graph.rb | Codependency.Graph.require | def require( file )
return if key?( file )
self[ file ] = deps( file )
self[ file ].each do |dependency|
self.require dependency
end
end | ruby | def require( file )
return if key?( file )
self[ file ] = deps( file )
self[ file ].each do |dependency|
self.require dependency
end
end | [
"def",
"require",
"(",
"file",
")",
"return",
"if",
"key?",
"(",
"file",
")",
"self",
"[",
"file",
"]",
"=",
"deps",
"(",
"file",
")",
"self",
"[",
"file",
"]",
".",
"each",
"do",
"|",
"dependency",
"|",
"self",
".",
"require",
"dependency",
"end",... | Add the given file to this graph. Creates a new entry in the
graph, the key of which is the relative path to this file and
the value is the array of relative paths to its dependencies.
Any dependent files will also be recursively added to this
graph. | [
"Add",
"the",
"given",
"file",
"to",
"this",
"graph",
".",
"Creates",
"a",
"new",
"entry",
"in",
"the",
"graph",
"the",
"key",
"of",
"which",
"is",
"the",
"relative",
"path",
"to",
"this",
"file",
"and",
"the",
"value",
"is",
"the",
"array",
"of",
"r... | 635eddcc0149211e71f89bcaddaa6603aacf942f | https://github.com/jeremyruppel/codependency/blob/635eddcc0149211e71f89bcaddaa6603aacf942f/lib/codependency/graph.rb#L12-L19 | train |
jeremyruppel/codependency | lib/codependency/graph.rb | Codependency.Graph.scan | def scan( glob )
Dir[ glob ].flat_map { |f| deps( f ) }.uniq.each do |dependency|
self.require dependency
end
end | ruby | def scan( glob )
Dir[ glob ].flat_map { |f| deps( f ) }.uniq.each do |dependency|
self.require dependency
end
end | [
"def",
"scan",
"(",
"glob",
")",
"Dir",
"[",
"glob",
"]",
".",
"flat_map",
"{",
"|",
"f",
"|",
"deps",
"(",
"f",
")",
"}",
".",
"uniq",
".",
"each",
"do",
"|",
"dependency",
"|",
"self",
".",
"require",
"dependency",
"end",
"end"
] | Parses all of the files in the given glob and adds their
dependencies to the graph. A file in this glob is not added
to the graph unless another file in the glob depends on it. | [
"Parses",
"all",
"of",
"the",
"files",
"in",
"the",
"given",
"glob",
"and",
"adds",
"their",
"dependencies",
"to",
"the",
"graph",
".",
"A",
"file",
"in",
"this",
"glob",
"is",
"not",
"added",
"to",
"the",
"graph",
"unless",
"another",
"file",
"in",
"t... | 635eddcc0149211e71f89bcaddaa6603aacf942f | https://github.com/jeremyruppel/codependency/blob/635eddcc0149211e71f89bcaddaa6603aacf942f/lib/codependency/graph.rb#L26-L30 | train |
jeremyruppel/codependency | lib/codependency/graph.rb | Codependency.Graph.deps | def deps( file )
parser.parse( file ).map { |f| path_to path[ f ] }
end | ruby | def deps( file )
parser.parse( file ).map { |f| path_to path[ f ] }
end | [
"def",
"deps",
"(",
"file",
")",
"parser",
".",
"parse",
"(",
"file",
")",
".",
"map",
"{",
"|",
"f",
"|",
"path_to",
"path",
"[",
"f",
"]",
"}",
"end"
] | Parses the file and returns the relative paths to its dependencies. | [
"Parses",
"the",
"file",
"and",
"returns",
"the",
"relative",
"paths",
"to",
"its",
"dependencies",
"."
] | 635eddcc0149211e71f89bcaddaa6603aacf942f | https://github.com/jeremyruppel/codependency/blob/635eddcc0149211e71f89bcaddaa6603aacf942f/lib/codependency/graph.rb#L85-L87 | train |
Deradon/Ruby-Rescuetime | lib/rescuetime/loop.rb | Rescuetime.Loop.run | def run
running!
@current_app = Application.create(:debug => debug?)
while true
sleep 1 # TODO: move to config
focus_changed if @current_app.finished? || backup?
end
end | ruby | def run
running!
@current_app = Application.create(:debug => debug?)
while true
sleep 1 # TODO: move to config
focus_changed if @current_app.finished? || backup?
end
end | [
"def",
"run",
"running!",
"@current_app",
"=",
"Application",
".",
"create",
"(",
":debug",
"=>",
"debug?",
")",
"while",
"true",
"sleep",
"1",
"# TODO: move to config",
"focus_changed",
"if",
"@current_app",
".",
"finished?",
"||",
"backup?",
"end",
"end"
] | Run the loop | [
"Run",
"the",
"loop"
] | 0a81fb2e889bd225e0a0714d23c61fb9b1e36ffd | https://github.com/Deradon/Ruby-Rescuetime/blob/0a81fb2e889bd225e0a0714d23c61fb9b1e36ffd/lib/rescuetime/loop.rb#L77-L85 | train |
mochnatiy/flexible_accessibility | lib/flexible_accessibility/controller_methods.rb | FlexibleAccessibility.ControllerMethods.has_access? | def has_access?(permission, user)
raise UnknownUserException if user.nil?
AccessProvider.action_permitted_for_user?(permission, user)
end | ruby | def has_access?(permission, user)
raise UnknownUserException if user.nil?
AccessProvider.action_permitted_for_user?(permission, user)
end | [
"def",
"has_access?",
"(",
"permission",
",",
"user",
")",
"raise",
"UnknownUserException",
"if",
"user",
".",
"nil?",
"AccessProvider",
".",
"action_permitted_for_user?",
"(",
"permission",
",",
"user",
")",
"end"
] | Check the url for each link in view to show it | [
"Check",
"the",
"url",
"for",
"each",
"link",
"in",
"view",
"to",
"show",
"it"
] | ffd7f76e0765aa28909625b3bfa282264b8a5195 | https://github.com/mochnatiy/flexible_accessibility/blob/ffd7f76e0765aa28909625b3bfa282264b8a5195/lib/flexible_accessibility/controller_methods.rb#L79-L83 | train |
GeoffWilliams/puppetbox | lib/puppetbox/puppetbox.rb | PuppetBox.PuppetBox.run_puppet | def run_puppet(driver_instance, puppet_tests, logger:nil, reset_after_run:true)
# use supplied logger in preference to the default puppetbox logger instance
logger = logger || @logger
logger.debug("#{driver_instance.node_name} running #{puppet_tests.size} tests")
if driver_instance.open
... | ruby | def run_puppet(driver_instance, puppet_tests, logger:nil, reset_after_run:true)
# use supplied logger in preference to the default puppetbox logger instance
logger = logger || @logger
logger.debug("#{driver_instance.node_name} running #{puppet_tests.size} tests")
if driver_instance.open
... | [
"def",
"run_puppet",
"(",
"driver_instance",
",",
"puppet_tests",
",",
"logger",
":",
"nil",
",",
"reset_after_run",
":",
"true",
")",
"# use supplied logger in preference to the default puppetbox logger instance",
"logger",
"=",
"logger",
"||",
"@logger",
"logger",
".",
... | Run puppet using `driver_instance` to execute `puppet_codes`
@param puppet_test Hash of test names <-> puppet code, eg {"apache"=>"include apache","nginx"=>"include nginx"}} | [
"Run",
"puppet",
"using",
"driver_instance",
"to",
"execute",
"puppet_codes"
] | 8ace050aa46e8908c1b266b9307f01929e222e53 | https://github.com/GeoffWilliams/puppetbox/blob/8ace050aa46e8908c1b266b9307f01929e222e53/lib/puppetbox/puppetbox.rb#L180-L225 | train |
elementar/shapewear | lib/shapewear/request.rb | Shapewear::Request.RequestHandler.extract_parameters | def extract_parameters(op_options, node)
logger.debug "Operation node: #{node.inspect}"
r = []
op_options[:parameters].each do |p|
logger.debug " Looking for: tns:#{p.first.camelize_if_symbol(:lower)}"
v = node.xpath("tns:#{p.first.camelize_if_symbol(:lower)}", namespaces).first
... | ruby | def extract_parameters(op_options, node)
logger.debug "Operation node: #{node.inspect}"
r = []
op_options[:parameters].each do |p|
logger.debug " Looking for: tns:#{p.first.camelize_if_symbol(:lower)}"
v = node.xpath("tns:#{p.first.camelize_if_symbol(:lower)}", namespaces).first
... | [
"def",
"extract_parameters",
"(",
"op_options",
",",
"node",
")",
"logger",
".",
"debug",
"\"Operation node: #{node.inspect}\"",
"r",
"=",
"[",
"]",
"op_options",
"[",
":parameters",
"]",
".",
"each",
"do",
"|",
"p",
"|",
"logger",
".",
"debug",
"\" Looking f... | Extracts all parameters from the operation node, and return as an array.
@param op_options [Hash] The operation options.
@param node [Nokogiri::XML] The operation node.
@return [Array] The parsed parameters. | [
"Extracts",
"all",
"parameters",
"from",
"the",
"operation",
"node",
"and",
"return",
"as",
"an",
"array",
"."
] | 18cef0227930dbe26a2c821e8e636fda5d2bc6e2 | https://github.com/elementar/shapewear/blob/18cef0227930dbe26a2c821e8e636fda5d2bc6e2/lib/shapewear/request.rb#L75-L94 | train |
elementar/shapewear | lib/shapewear/request.rb | Shapewear::Request.RequestHandler.serialize_soap_result | def serialize_soap_result(op_options, r)
xb = Builder::XmlMarkup.new
xb.instruct!
xb.Envelope :xmlns => soap_env_ns, 'xmlns:xsi' => namespaces['xsi'] do |xenv|
xenv.Body do |xbody|
xbody.tag! "#{op_options[:public_name]}Response", :xmlns => namespaces['tns'] do |xresp|
i... | ruby | def serialize_soap_result(op_options, r)
xb = Builder::XmlMarkup.new
xb.instruct!
xb.Envelope :xmlns => soap_env_ns, 'xmlns:xsi' => namespaces['xsi'] do |xenv|
xenv.Body do |xbody|
xbody.tag! "#{op_options[:public_name]}Response", :xmlns => namespaces['tns'] do |xresp|
i... | [
"def",
"serialize_soap_result",
"(",
"op_options",
",",
"r",
")",
"xb",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"xb",
".",
"instruct!",
"xb",
".",
"Envelope",
":xmlns",
"=>",
"soap_env_ns",
",",
"'xmlns:xsi'",
"=>",
"namespaces",
"[",
"'xsi'",
"]",
... | Serializes the result of an operation as a SOAP Envelope.
@param op_options [Hash] The operation options.
@param r [Hash,Object] The operation result.
noinspection RubyArgCount | [
"Serializes",
"the",
"result",
"of",
"an",
"operation",
"as",
"a",
"SOAP",
"Envelope",
"."
] | 18cef0227930dbe26a2c821e8e636fda5d2bc6e2 | https://github.com/elementar/shapewear/blob/18cef0227930dbe26a2c821e8e636fda5d2bc6e2/lib/shapewear/request.rb#L101-L128 | train |
elementar/shapewear | lib/shapewear/request.rb | Shapewear::Request.RequestHandler.extract_and_serialize_value | def extract_and_serialize_value(builder, obj, field, type)
v = if obj.is_a?(Hash)
obj[field] or obj[field.to_sym] or obj[field.to_s.underscore] or obj[field.to_s.underscore.to_sym]
elsif obj.respond_to?(field)
obj.send(field)
elsif obj.respond_to?(field.underscore)
obj.send(fie... | ruby | def extract_and_serialize_value(builder, obj, field, type)
v = if obj.is_a?(Hash)
obj[field] or obj[field.to_sym] or obj[field.to_s.underscore] or obj[field.to_s.underscore.to_sym]
elsif obj.respond_to?(field)
obj.send(field)
elsif obj.respond_to?(field.underscore)
obj.send(fie... | [
"def",
"extract_and_serialize_value",
"(",
"builder",
",",
"obj",
",",
"field",
",",
"type",
")",
"v",
"=",
"if",
"obj",
".",
"is_a?",
"(",
"Hash",
")",
"obj",
"[",
"field",
"]",
"or",
"obj",
"[",
"field",
".",
"to_sym",
"]",
"or",
"obj",
"[",
"fie... | Extracts a field from an object, casts it to the appropriate type, and serializes as XML.
@param builder [Builder::XmlMarkup] The XML builder.
@param obj [Hash,Object] The resulting object.
@param field [Symbol,String] The field to extract.
@param type [Class] The type to convert. | [
"Extracts",
"a",
"field",
"from",
"an",
"object",
"casts",
"it",
"to",
"the",
"appropriate",
"type",
"and",
"serializes",
"as",
"XML",
"."
] | 18cef0227930dbe26a2c821e8e636fda5d2bc6e2 | https://github.com/elementar/shapewear/blob/18cef0227930dbe26a2c821e8e636fda5d2bc6e2/lib/shapewear/request.rb#L136-L152 | train |
elementar/shapewear | lib/shapewear/request.rb | Shapewear::Request.RequestHandler.serialize_soap_fault | def serialize_soap_fault(ex)
logger.debug "Serializing SOAP Fault: #{ex.inspect}"
xb = Builder::XmlMarkup.new
xb.instruct!
xb.tag! 'e:Envelope', 'xmlns:e' => soap_env_ns do |xenv|
xenv.tag! 'e:Body' do |xbody|
xbody.tag! 'e:Fault' do |xf|
case soap_version
... | ruby | def serialize_soap_fault(ex)
logger.debug "Serializing SOAP Fault: #{ex.inspect}"
xb = Builder::XmlMarkup.new
xb.instruct!
xb.tag! 'e:Envelope', 'xmlns:e' => soap_env_ns do |xenv|
xenv.tag! 'e:Body' do |xbody|
xbody.tag! 'e:Fault' do |xf|
case soap_version
... | [
"def",
"serialize_soap_fault",
"(",
"ex",
")",
"logger",
".",
"debug",
"\"Serializing SOAP Fault: #{ex.inspect}\"",
"xb",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"xb",
".",
"instruct!",
"xb",
".",
"tag!",
"'e:Envelope'",
",",
"'xmlns:e'",
"=>",
"soap_env_ns... | Serializes an exception as a SOAP Envelope containing a SOAP Fault.
@param ex [Exception] The Exception to serialize.
@return [String] The SOAP Envelope containing the Fault.
noinspection RubyArgCount | [
"Serializes",
"an",
"exception",
"as",
"a",
"SOAP",
"Envelope",
"containing",
"a",
"SOAP",
"Fault",
"."
] | 18cef0227930dbe26a2c821e8e636fda5d2bc6e2 | https://github.com/elementar/shapewear/blob/18cef0227930dbe26a2c821e8e636fda5d2bc6e2/lib/shapewear/request.rb#L159-L186 | train |
nerboda/easy_breadcrumbs | lib/easy_breadcrumbs/sinatra_config.rb | Sinatra.EasyBreadcrumbs.view_variables | def view_variables
instance_variables
.select { |var| additional_var?(var) }
.map { |var| fetch_ivar_value(var) }
end | ruby | def view_variables
instance_variables
.select { |var| additional_var?(var) }
.map { |var| fetch_ivar_value(var) }
end | [
"def",
"view_variables",
"instance_variables",
".",
"select",
"{",
"|",
"var",
"|",
"additional_var?",
"(",
"var",
")",
"}",
".",
"map",
"{",
"|",
"var",
"|",
"fetch_ivar_value",
"(",
"var",
")",
"}",
"end"
] | All user defined instance variables for current request. | [
"All",
"user",
"defined",
"instance",
"variables",
"for",
"current",
"request",
"."
] | 53af89b4ba1329a4963ff6bc253f4714ac9030f8 | https://github.com/nerboda/easy_breadcrumbs/blob/53af89b4ba1329a4963ff6bc253f4714ac9030f8/lib/easy_breadcrumbs/sinatra_config.rb#L31-L35 | train |
starpeak/gricer | app/controllers/gricer/capture_controller.rb | Gricer.CaptureController.index | def index
gricer_request = ::Gricer.config.request_model.first_by_id(params[:id])
gricer_session = ::Gricer.config.session_model.first_by_id(session[:gricer_session])
if gricer_session
gricer_session.javascript = true
gricer_session.java = params[:j]
... | ruby | def index
gricer_request = ::Gricer.config.request_model.first_by_id(params[:id])
gricer_session = ::Gricer.config.session_model.first_by_id(session[:gricer_session])
if gricer_session
gricer_session.javascript = true
gricer_session.java = params[:j]
... | [
"def",
"index",
"gricer_request",
"=",
"::",
"Gricer",
".",
"config",
".",
"request_model",
".",
"first_by_id",
"(",
"params",
"[",
":id",
"]",
")",
"gricer_session",
"=",
"::",
"Gricer",
".",
"config",
".",
"session_model",
".",
"first_by_id",
"(",
"session... | This action stores the data submitted by the Javascript. | [
"This",
"action",
"stores",
"the",
"data",
"submitted",
"by",
"the",
"Javascript",
"."
] | 46bb77bd4fc7074ce294d0310ad459fef068f507 | https://github.com/starpeak/gricer/blob/46bb77bd4fc7074ce294d0310ad459fef068f507/app/controllers/gricer/capture_controller.rb#L7-L40 | train |
byu/optser | lib/optser/opt_set.rb | Optser.OptSet.get | def get(key, default=nil, &block)
value = options[key]
value = default if value.nil?
value = block.call if value.nil? && block
return value
end | ruby | def get(key, default=nil, &block)
value = options[key]
value = default if value.nil?
value = block.call if value.nil? && block
return value
end | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"nil",
",",
"&",
"block",
")",
"value",
"=",
"options",
"[",
"key",
"]",
"value",
"=",
"default",
"if",
"value",
".",
"nil?",
"value",
"=",
"block",
".",
"call",
"if",
"value",
".",
"nil?",
"&&",
"bl... | Lookup an option from our options set.
Examples:
# Optional parameter whose default value is nil.
do_extra = opt_set.get :do_extra
# Optional params that defaults to [1,2,3]
start_array = opt_set.get :start_array, [1,2,3]
Returns default value when:
* Key is non-existent in Options Hash.
* OR when t... | [
"Lookup",
"an",
"option",
"from",
"our",
"options",
"set",
"."
] | c88c19f15ca31874ad46fb6f15b20485635a5ffb | https://github.com/byu/optser/blob/c88c19f15ca31874ad46fb6f15b20485635a5ffb/lib/optser/opt_set.rb#L32-L37 | train |
byu/optser | lib/optser/opt_set.rb | Optser.OptSet.get! | def get!(key, default=nil, &block)
value = get key, default, &block
raise "Nil value found for option: #{key}, #{default}" if value.nil?
return value
end | ruby | def get!(key, default=nil, &block)
value = get key, default, &block
raise "Nil value found for option: #{key}, #{default}" if value.nil?
return value
end | [
"def",
"get!",
"(",
"key",
",",
"default",
"=",
"nil",
",",
"&",
"block",
")",
"value",
"=",
"get",
"key",
",",
"default",
",",
"block",
"raise",
"\"Nil value found for option: #{key}, #{default}\"",
"if",
"value",
".",
"nil?",
"return",
"value",
"end"
] | Use this the option is mandatory.
There are cases where an option may have a default value for a feature,
but the caller may just want to disable said feature. To do so,
users of this module should allow for the caller to pass in 'false'
as an option value instead of nil to disable said feature. The
implementer w... | [
"Use",
"this",
"the",
"option",
"is",
"mandatory",
"."
] | c88c19f15ca31874ad46fb6f15b20485635a5ffb | https://github.com/byu/optser/blob/c88c19f15ca31874ad46fb6f15b20485635a5ffb/lib/optser/opt_set.rb#L62-L66 | train |
samvera-deprecated/solrizer-fedora | lib/solrizer/fedora/indexer.rb | Solrizer::Fedora.Indexer.connect | def connect
if defined?(Blacklight)
solr_config = Blacklight.solr_config
elsif defined?(Rails.root.to_s)
solr_config = load_rails_config
else
solr_config = load_fallback_config
end
if index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?... | ruby | def connect
if defined?(Blacklight)
solr_config = Blacklight.solr_config
elsif defined?(Rails.root.to_s)
solr_config = load_rails_config
else
solr_config = load_fallback_config
end
if index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?... | [
"def",
"connect",
"if",
"defined?",
"(",
"Blacklight",
")",
"solr_config",
"=",
"Blacklight",
".",
"solr_config",
"elsif",
"defined?",
"(",
"Rails",
".",
"root",
".",
"to_s",
")",
"solr_config",
"=",
"load_rails_config",
"else",
"solr_config",
"=",
"load_fallbac... | This method performs initialization tasks
This method connects to the Solr instance. It looks to see if Blacklight is loaded first for the
Blacklight.solr_config. If not loaded, it then looks for the Rails.root.to_s/config/solr.yaml file and loads
it to get the solr url. The configuration strucuture can take both ... | [
"This",
"method",
"performs",
"initialization",
"tasks"
] | 277fab50a93a761fbccd07e2cfa01b22736d5cff | https://github.com/samvera-deprecated/solrizer-fedora/blob/277fab50a93a761fbccd07e2cfa01b22736d5cff/lib/solrizer/fedora/indexer.rb#L44-L66 | train |
samvera-deprecated/solrizer-fedora | lib/solrizer/fedora/indexer.rb | Solrizer::Fedora.Indexer.generate_dates | def generate_dates(solr_doc)
# This will check for valid dates, but it seems most of the dates are currently invalid....
#date_check = /^(19|20)\d\d([- \/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])/
#if there is not date_t, add on with easy-to-find value
if solr_doc[:date_t].nil?
::Solrize... | ruby | def generate_dates(solr_doc)
# This will check for valid dates, but it seems most of the dates are currently invalid....
#date_check = /^(19|20)\d\d([- \/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])/
#if there is not date_t, add on with easy-to-find value
if solr_doc[:date_t].nil?
::Solrize... | [
"def",
"generate_dates",
"(",
"solr_doc",
")",
"# This will check for valid dates, but it seems most of the dates are currently invalid....",
"#date_check = /^(19|20)\\d\\d([- \\/.])(0[1-9]|1[012])\\2(0[1-9]|[12][0-9]|3[01])/",
"#if there is not date_t, add on with easy-to-find value",
"if",
"sol... | This method generates the month and day facets from the date_t in solr_doc | [
"This",
"method",
"generates",
"the",
"month",
"and",
"day",
"facets",
"from",
"the",
"date_t",
"in",
"solr_doc"
] | 277fab50a93a761fbccd07e2cfa01b22736d5cff | https://github.com/samvera-deprecated/solrizer-fedora/blob/277fab50a93a761fbccd07e2cfa01b22736d5cff/lib/solrizer/fedora/indexer.rb#L100-L136 | train |
samvera-deprecated/solrizer-fedora | lib/solrizer/fedora/indexer.rb | Solrizer::Fedora.Indexer.create_document | def create_document( obj )
solr_doc = Hash.new
model_klazz_array = ActiveFedora::ContentModel.known_models_for( obj )
model_klazz_array.delete(ActiveFedora::Base)
# If the object was passed in as an ActiveFedora::Base, call to_solr in order to get the base field entries from Activ... | ruby | def create_document( obj )
solr_doc = Hash.new
model_klazz_array = ActiveFedora::ContentModel.known_models_for( obj )
model_klazz_array.delete(ActiveFedora::Base)
# If the object was passed in as an ActiveFedora::Base, call to_solr in order to get the base field entries from Activ... | [
"def",
"create_document",
"(",
"obj",
")",
"solr_doc",
"=",
"Hash",
".",
"new",
"model_klazz_array",
"=",
"ActiveFedora",
"::",
"ContentModel",
".",
"known_models_for",
"(",
"obj",
")",
"model_klazz_array",
".",
"delete",
"(",
"ActiveFedora",
"::",
"Base",
")",
... | This method creates a Solr-formatted XML document | [
"This",
"method",
"creates",
"a",
"Solr",
"-",
"formatted",
"XML",
"document"
] | 277fab50a93a761fbccd07e2cfa01b22736d5cff | https://github.com/samvera-deprecated/solrizer-fedora/blob/277fab50a93a761fbccd07e2cfa01b22736d5cff/lib/solrizer/fedora/indexer.rb#L141-L171 | train |
megamsys/megam_api | lib/megam/api/accounts.rb | Megam.API.post_accounts | def post_accounts(new_account)
@options = {path: '/accounts/content',
body: Megam::JSONCompat.to_json(new_account)}.merge(@options)
request(
:expects => 201,
:method => :post,
:body => @options[:body]
)
end | ruby | def post_accounts(new_account)
@options = {path: '/accounts/content',
body: Megam::JSONCompat.to_json(new_account)}.merge(@options)
request(
:expects => 201,
:method => :post,
:body => @options[:body]
)
end | [
"def",
"post_accounts",
"(",
"new_account",
")",
"@options",
"=",
"{",
"path",
":",
"'/accounts/content'",
",",
"body",
":",
"Megam",
"::",
"JSONCompat",
".",
"to_json",
"(",
"new_account",
")",
"}",
".",
"merge",
"(",
"@options",
")",
"request",
"(",
":ex... | The body content needs to be a json. | [
"The",
"body",
"content",
"needs",
"to",
"be",
"a",
"json",
"."
] | c28e743311706dfef9c7745ae64058a468f5b1a4 | https://github.com/megamsys/megam_api/blob/c28e743311706dfef9c7745ae64058a468f5b1a4/lib/megam/api/accounts.rb#L28-L37 | train |
michaelmior/mipper | lib/mipper/lp_solve/model.rb | MIPPeR.LPSolveModel.store_constraint_matrix | def store_constraint_matrix(constr, type)
# Initialize arrays used to hold the coefficients for each variable
row = []
colno = []
constr.expression.terms.each do |var, coeff|
row << coeff * 1.0
colno << var.index
end
row_buffer = build_pointer_array row, :double
... | ruby | def store_constraint_matrix(constr, type)
# Initialize arrays used to hold the coefficients for each variable
row = []
colno = []
constr.expression.terms.each do |var, coeff|
row << coeff * 1.0
colno << var.index
end
row_buffer = build_pointer_array row, :double
... | [
"def",
"store_constraint_matrix",
"(",
"constr",
",",
"type",
")",
"# Initialize arrays used to hold the coefficients for each variable",
"row",
"=",
"[",
"]",
"colno",
"=",
"[",
"]",
"constr",
".",
"expression",
".",
"terms",
".",
"each",
"do",
"|",
"var",
",",
... | Build the constraint matrix and add it to the model | [
"Build",
"the",
"constraint",
"matrix",
"and",
"add",
"it",
"to",
"the",
"model"
] | 4ab7f8b32c27f33fc5121756554a0a28d2077e06 | https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/lp_solve/model.rb#L70-L86 | train |
oniram88/imdb-scan | lib/imdb/person.rb | IMDB.Person.birthdate | def birthdate
month_data_element = bio_document.at("td.label[text()*='Date of Birth']").
next_element.first_element_child
date_month = month_data_element.inner_text.strip rescue ""
year = month_data_element.next_element.inner_text.strip rescue ""
Date.parse("#{date_month} #{year}"... | ruby | def birthdate
month_data_element = bio_document.at("td.label[text()*='Date of Birth']").
next_element.first_element_child
date_month = month_data_element.inner_text.strip rescue ""
year = month_data_element.next_element.inner_text.strip rescue ""
Date.parse("#{date_month} #{year}"... | [
"def",
"birthdate",
"month_data_element",
"=",
"bio_document",
".",
"at",
"(",
"\"td.label[text()*='Date of Birth']\"",
")",
".",
"next_element",
".",
"first_element_child",
"date_month",
"=",
"month_data_element",
".",
"inner_text",
".",
"strip",
"rescue",
"\"\"",
"yea... | Get The Birth Date
@return [Date] | [
"Get",
"The",
"Birth",
"Date"
] | e358adaba3db178df42c711c79c894f14d83c742 | https://github.com/oniram88/imdb-scan/blob/e358adaba3db178df42c711c79c894f14d83c742/lib/imdb/person.rb#L50-L56 | train |
oniram88/imdb-scan | lib/imdb/person.rb | IMDB.Person.deathdate | def deathdate
date_month = bio_document.at("h5[text()*='Date of Death']").next_element.inner_text.strip rescue ""
year = bio_document.at("a[@href*='death_date']").inner_text.strip rescue ""
Date.parse("#{date_month} #{year}") rescue nil
end | ruby | def deathdate
date_month = bio_document.at("h5[text()*='Date of Death']").next_element.inner_text.strip rescue ""
year = bio_document.at("a[@href*='death_date']").inner_text.strip rescue ""
Date.parse("#{date_month} #{year}") rescue nil
end | [
"def",
"deathdate",
"date_month",
"=",
"bio_document",
".",
"at",
"(",
"\"h5[text()*='Date of Death']\"",
")",
".",
"next_element",
".",
"inner_text",
".",
"strip",
"rescue",
"\"\"",
"year",
"=",
"bio_document",
".",
"at",
"(",
"\"a[@href*='death_date']\"",
")",
"... | Get The death date else nil
@return [Date] | [
"Get",
"The",
"death",
"date",
"else",
"nil"
] | e358adaba3db178df42c711c79c894f14d83c742 | https://github.com/oniram88/imdb-scan/blob/e358adaba3db178df42c711c79c894f14d83c742/lib/imdb/person.rb#L60-L64 | train |
oniram88/imdb-scan | lib/imdb/person.rb | IMDB.Person.filmography | def filmography
#@return [Hash]
# writer: [Movie]
# actor: [Movie]
# director: [Movie]
# composer: [Movie]
#as_writer = main_document.at("#filmo-head-Writer").next_element.search('b a').map { |e| e.get_attribute('href')[/tt(\d+)/, 1] } rescue []
#as_actor... | ruby | def filmography
#@return [Hash]
# writer: [Movie]
# actor: [Movie]
# director: [Movie]
# composer: [Movie]
#as_writer = main_document.at("#filmo-head-Writer").next_element.search('b a').map { |e| e.get_attribute('href')[/tt(\d+)/, 1] } rescue []
#as_actor... | [
"def",
"filmography",
"#@return [Hash]\r",
"# writer: [Movie]\r",
"# actor: [Movie]\r",
"# director: [Movie]\r",
"# composer: [Movie]\r",
"#as_writer = main_document.at(\"#filmo-head-Writer\").next_element.search('b a').map { |e| e.get_attribute('href')[/tt(\\d+)/, 1] } rescue []\r",
... | Return the Filmography
for the moment I can't make subdivision of this, then i take all in an array
@return [Movie] | [
"Return",
"the",
"Filmography",
"for",
"the",
"moment",
"I",
"can",
"t",
"make",
"subdivision",
"of",
"this",
"then",
"i",
"take",
"all",
"in",
"an",
"array"
] | e358adaba3db178df42c711c79c894f14d83c742 | https://github.com/oniram88/imdb-scan/blob/e358adaba3db178df42c711c79c894f14d83c742/lib/imdb/person.rb#L93-L106 | train |
rixth/tay | lib/tay/specification.rb | Tay.Specification.all_javascript_paths | def all_javascript_paths
all_paths = []
all_paths += @javascripts
all_paths += @background_scripts
all_paths += @content_scripts.map { |cs| cs.javascripts }.compact
all_paths.flatten.uniq
end | ruby | def all_javascript_paths
all_paths = []
all_paths += @javascripts
all_paths += @background_scripts
all_paths += @content_scripts.map { |cs| cs.javascripts }.compact
all_paths.flatten.uniq
end | [
"def",
"all_javascript_paths",
"all_paths",
"=",
"[",
"]",
"all_paths",
"+=",
"@javascripts",
"all_paths",
"+=",
"@background_scripts",
"all_paths",
"+=",
"@content_scripts",
".",
"map",
"{",
"|",
"cs",
"|",
"cs",
".",
"javascripts",
"}",
".",
"compact",
"all_pa... | Return all the javascript paths in the spec, included those nested
inside other objects | [
"Return",
"all",
"the",
"javascript",
"paths",
"in",
"the",
"spec",
"included",
"those",
"nested",
"inside",
"other",
"objects"
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/specification.rb#L261-L267 | train |
rixth/tay | lib/tay/specification.rb | Tay.Specification.all_stylesheet_paths | def all_stylesheet_paths
all_paths = []
all_paths += @stylesheets
all_paths += @content_scripts.map { |cs| cs.stylesheets }.compact
all_paths.flatten.uniq
end | ruby | def all_stylesheet_paths
all_paths = []
all_paths += @stylesheets
all_paths += @content_scripts.map { |cs| cs.stylesheets }.compact
all_paths.flatten.uniq
end | [
"def",
"all_stylesheet_paths",
"all_paths",
"=",
"[",
"]",
"all_paths",
"+=",
"@stylesheets",
"all_paths",
"+=",
"@content_scripts",
".",
"map",
"{",
"|",
"cs",
"|",
"cs",
".",
"stylesheets",
"}",
".",
"compact",
"all_paths",
".",
"flatten",
".",
"uniq",
"en... | Return all the stylesheet paths in the spec, included those nested
inside other objects | [
"Return",
"all",
"the",
"stylesheet",
"paths",
"in",
"the",
"spec",
"included",
"those",
"nested",
"inside",
"other",
"objects"
] | 60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5 | https://github.com/rixth/tay/blob/60a5d64aa54e7ef13d10d9c8fb7825e2febea8e5/lib/tay/specification.rb#L272-L277 | train |
ideonetwork/lato-blog | app/models/lato_blog/category/serializer_helpers.rb | LatoBlog.Category::SerializerHelpers.serialize | def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# add category father informations
serialized[:category_father] = category_father ? cat... | ruby | def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# add category father informations
serialized[:category_father] = category_father ? cat... | [
"def",
"serialize",
"serialized",
"=",
"{",
"}",
"# set basic info",
"serialized",
"[",
":id",
"]",
"=",
"id",
"serialized",
"[",
":title",
"]",
"=",
"title",
"serialized",
"[",
":meta_language",
"]",
"=",
"meta_language",
"serialized",
"[",
":meta_permalink",
... | This function serializes a complete version of the category. | [
"This",
"function",
"serializes",
"a",
"complete",
"version",
"of",
"the",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/category/serializer_helpers.rb#L5-L25 | train |
ideonetwork/lato-blog | app/models/lato_blog/category/serializer_helpers.rb | LatoBlog.Category::SerializerHelpers.serialize_base | def serialize_base
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# return serialized category
serialized
end | ruby | def serialize_base
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# return serialized category
serialized
end | [
"def",
"serialize_base",
"serialized",
"=",
"{",
"}",
"# set basic info",
"serialized",
"[",
":id",
"]",
"=",
"id",
"serialized",
"[",
":title",
"]",
"=",
"title",
"serialized",
"[",
":meta_language",
"]",
"=",
"meta_language",
"serialized",
"[",
":meta_permalin... | This function serializes a basic version of the category. | [
"This",
"function",
"serializes",
"a",
"basic",
"version",
"of",
"the",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/category/serializer_helpers.rb#L28-L39 | train |
paxtonhare/marklogic-ruby-driver | lib/marklogic/collection.rb | MarkLogic.Collection.from_criteria | def from_criteria(criteria)
queries = []
criteria.each do |k, v|
name, operator, index_type, value = nil
query_options = {}
if (v.is_a?(Hash))
name = k.to_s
query_options.merge!(v.delete(:options) || {})
sub_queries = []
v.each do |kk, vv|
... | ruby | def from_criteria(criteria)
queries = []
criteria.each do |k, v|
name, operator, index_type, value = nil
query_options = {}
if (v.is_a?(Hash))
name = k.to_s
query_options.merge!(v.delete(:options) || {})
sub_queries = []
v.each do |kk, vv|
... | [
"def",
"from_criteria",
"(",
"criteria",
")",
"queries",
"=",
"[",
"]",
"criteria",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"name",
",",
"operator",
",",
"index_type",
",",
"value",
"=",
"nil",
"query_options",
"=",
"{",
"}",
"if",
"(",
"v",
".... | Builds a MarkLogic Query from Mongo Style Criteria
@param [Hash] criteria The Criteria to use when searching
@example Build a query from criteria
# Query on age == 3
collection.from_criteria({ 'age' => { '$eq' => 3 } })
# Query on age < 3
collection.from_criteria({ 'age' => { '$lt' => 3 } })
... | [
"Builds",
"a",
"MarkLogic",
"Query",
"from",
"Mongo",
"Style",
"Criteria"
] | 76c3f2c2da7b8266cdbe786b7f3e910e0983eb9b | https://github.com/paxtonhare/marklogic-ruby-driver/blob/76c3f2c2da7b8266cdbe786b7f3e910e0983eb9b/lib/marklogic/collection.rb#L174-L218 | train |
cjfuller/rimageanalysistools | lib/rimageanalysistools/drawing.rb | RImageAnalysisTools.Drawing.draw | def draw(im, draw_value = 255.0)
im.each do |ic|
if (yield ic) then
im.setValue(ic, draw_value)
end
end
end | ruby | def draw(im, draw_value = 255.0)
im.each do |ic|
if (yield ic) then
im.setValue(ic, draw_value)
end
end
end | [
"def",
"draw",
"(",
"im",
",",
"draw_value",
"=",
"255.0",
")",
"im",
".",
"each",
"do",
"|",
"ic",
"|",
"if",
"(",
"yield",
"ic",
")",
"then",
"im",
".",
"setValue",
"(",
"ic",
",",
"draw_value",
")",
"end",
"end",
"end"
] | A basic drawing method that iterates through an entire image. At each coordinate,
an attached block is evaluated for a boolean response that determines whether that
coordinate is overwritten with a specified value. The attached block will be given
a single parameter, which is the current ImageCoordinate.
@param ... | [
"A",
"basic",
"drawing",
"method",
"that",
"iterates",
"through",
"an",
"entire",
"image",
".",
"At",
"each",
"coordinate",
"an",
"attached",
"block",
"is",
"evaluated",
"for",
"a",
"boolean",
"response",
"that",
"determines",
"whether",
"that",
"coordinate",
... | 991aa7a61a8ad7bd902a31d99a19ce135e3cc485 | https://github.com/cjfuller/rimageanalysistools/blob/991aa7a61a8ad7bd902a31d99a19ce135e3cc485/lib/rimageanalysistools/drawing.rb#L96-L108 | train |
cjfuller/rimageanalysistools | lib/rimageanalysistools/drawing.rb | RImageAnalysisTools.Drawing.draw_shape | def draw_shape(im, location, shape_name=:circle, shape_parameters= 10)
if self.respond_to?(shape_name) then
self.send(shape_name, im, location, shape_parameters)
end
end | ruby | def draw_shape(im, location, shape_name=:circle, shape_parameters= 10)
if self.respond_to?(shape_name) then
self.send(shape_name, im, location, shape_parameters)
end
end | [
"def",
"draw_shape",
"(",
"im",
",",
"location",
",",
"shape_name",
"=",
":circle",
",",
"shape_parameters",
"=",
"10",
")",
"if",
"self",
".",
"respond_to?",
"(",
"shape_name",
")",
"then",
"self",
".",
"send",
"(",
"shape_name",
",",
"im",
",",
"locati... | Draws a specified shape into an image.
@param [WritableImage] im the image into which to draw
@param [Array] location an array containing the coordinates of the shape to draw.
The exact meaning of this parameter depends on which shape is being drawn.
@param [Symbol] shape_name the name of the shape to draw. This... | [
"Draws",
"a",
"specified",
"shape",
"into",
"an",
"image",
"."
] | 991aa7a61a8ad7bd902a31d99a19ce135e3cc485 | https://github.com/cjfuller/rimageanalysistools/blob/991aa7a61a8ad7bd902a31d99a19ce135e3cc485/lib/rimageanalysistools/drawing.rb#L123-L131 | train |
cjfuller/rimageanalysistools | lib/rimageanalysistools/drawing.rb | RImageAnalysisTools.Drawing.circle | def circle(im, center, radius)
lower = ImageCoordinate[center[0]-radius-1, center[1]-radius-1, 0,0,0]
upper = ImageCoordinate[center[0]+radius+1, center[1]+radius+1, 0,0,0]
im.box_conservative(lower, upper, [:x, :y])
draw(im) do |ic|
xdiff = ic[:x] - center[0]
ydiff =... | ruby | def circle(im, center, radius)
lower = ImageCoordinate[center[0]-radius-1, center[1]-radius-1, 0,0,0]
upper = ImageCoordinate[center[0]+radius+1, center[1]+radius+1, 0,0,0]
im.box_conservative(lower, upper, [:x, :y])
draw(im) do |ic|
xdiff = ic[:x] - center[0]
ydiff =... | [
"def",
"circle",
"(",
"im",
",",
"center",
",",
"radius",
")",
"lower",
"=",
"ImageCoordinate",
"[",
"center",
"[",
"0",
"]",
"-",
"radius",
"-",
"1",
",",
"center",
"[",
"1",
"]",
"-",
"radius",
"-",
"1",
",",
"0",
",",
"0",
",",
"0",
"]",
"... | Draws a circle into an image.
@param [WritableImage] im the image into which to draw
@param [Array] center an array containing the x,y coordinates of the circle's center
@param [Numeric] radius the radius of the circle in pixels
@return [void] | [
"Draws",
"a",
"circle",
"into",
"an",
"image",
"."
] | 991aa7a61a8ad7bd902a31d99a19ce135e3cc485 | https://github.com/cjfuller/rimageanalysistools/blob/991aa7a61a8ad7bd902a31d99a19ce135e3cc485/lib/rimageanalysistools/drawing.rb#L142-L165 | train |
cjfuller/rimageanalysistools | lib/rimageanalysistools/drawing.rb | RImageAnalysisTools.Drawing.ellipse | def ellipse(im, foci, radius_inc)
min_x = foci[0][0]
max_x = foci[1][0]
min_y = foci[0][1]
max_y = foci[1][1]
if foci[1][0] < min_x then
min_x = foci[1][0]
max_x = foci[0][0]
end
if foci[1][1] < min_y then
min_y = foci[1][1]
max_y = foci[0][1]... | ruby | def ellipse(im, foci, radius_inc)
min_x = foci[0][0]
max_x = foci[1][0]
min_y = foci[0][1]
max_y = foci[1][1]
if foci[1][0] < min_x then
min_x = foci[1][0]
max_x = foci[0][0]
end
if foci[1][1] < min_y then
min_y = foci[1][1]
max_y = foci[0][1]... | [
"def",
"ellipse",
"(",
"im",
",",
"foci",
",",
"radius_inc",
")",
"min_x",
"=",
"foci",
"[",
"0",
"]",
"[",
"0",
"]",
"max_x",
"=",
"foci",
"[",
"1",
"]",
"[",
"0",
"]",
"min_y",
"=",
"foci",
"[",
"0",
"]",
"[",
"1",
"]",
"max_y",
"=",
"foc... | Draws an ellipse into an image.
@param [WritableImage] im the image into which to draw
@param [Array] foci an array containing two arrays, each of which contains the x,y
coordinates of one focus of the ellipse
@param [Numeric] radius_inc the extra amount of distance (in pixels) beyond the
distance between the f... | [
"Draws",
"an",
"ellipse",
"into",
"an",
"image",
"."
] | 991aa7a61a8ad7bd902a31d99a19ce135e3cc485 | https://github.com/cjfuller/rimageanalysistools/blob/991aa7a61a8ad7bd902a31d99a19ce135e3cc485/lib/rimageanalysistools/drawing.rb#L179-L219 | train |
assaf/css-annotate | lib/css/annotate.rb | CSS.Annotate.annotate | def annotate(filename)
engine = Sass::Engine.new(IO.read(filename), options.merge(:syntax=>guess_syntax(filename)))
tree = engine.to_tree
tree.perform!(Sass::Environment.new)
resolve_rules tree
@rows = to_rows(tree)
end | ruby | def annotate(filename)
engine = Sass::Engine.new(IO.read(filename), options.merge(:syntax=>guess_syntax(filename)))
tree = engine.to_tree
tree.perform!(Sass::Environment.new)
resolve_rules tree
@rows = to_rows(tree)
end | [
"def",
"annotate",
"(",
"filename",
")",
"engine",
"=",
"Sass",
"::",
"Engine",
".",
"new",
"(",
"IO",
".",
"read",
"(",
"filename",
")",
",",
"options",
".",
"merge",
"(",
":syntax",
"=>",
"guess_syntax",
"(",
"filename",
")",
")",
")",
"tree",
"=",... | Annotate the named file. Sets and returns rows. | [
"Annotate",
"the",
"named",
"file",
".",
"Sets",
"and",
"returns",
"rows",
"."
] | 5368d8f15e70b2f3cc6b38872a4685383b119d02 | https://github.com/assaf/css-annotate/blob/5368d8f15e70b2f3cc6b38872a4685383b119d02/lib/css/annotate.rb#L29-L35 | train |
assaf/css-annotate | lib/css/annotate.rb | CSS.Annotate.to_html | def to_html(filename)
rows = annotate(filename)
ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).result(binding)
rescue Sass::SyntaxError=>error
error = Sass::SyntaxError.exception_to_css error, @options.merge(:full_exception=>true)
ERB.new(IO.read(File.dirname(__FILE__) +... | ruby | def to_html(filename)
rows = annotate(filename)
ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).result(binding)
rescue Sass::SyntaxError=>error
error = Sass::SyntaxError.exception_to_css error, @options.merge(:full_exception=>true)
ERB.new(IO.read(File.dirname(__FILE__) +... | [
"def",
"to_html",
"(",
"filename",
")",
"rows",
"=",
"annotate",
"(",
"filename",
")",
"ERB",
".",
"new",
"(",
"IO",
".",
"read",
"(",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"+",
"\"/annotate/template.erb\"",
")",
")",
".",
"result",
"(",
"bindi... | Annotate the named file, returns HTML document. | [
"Annotate",
"the",
"named",
"file",
"returns",
"HTML",
"document",
"."
] | 5368d8f15e70b2f3cc6b38872a4685383b119d02 | https://github.com/assaf/css-annotate/blob/5368d8f15e70b2f3cc6b38872a4685383b119d02/lib/css/annotate.rb#L38-L44 | train |
assaf/css-annotate | lib/css/annotate.rb | CSS.Annotate.styles | def styles
Sass::Engine.new(IO.read(File.dirname(__FILE__) + "/annotate/style.scss"), :syntax=>:scss).render
end | ruby | def styles
Sass::Engine.new(IO.read(File.dirname(__FILE__) + "/annotate/style.scss"), :syntax=>:scss).render
end | [
"def",
"styles",
"Sass",
"::",
"Engine",
".",
"new",
"(",
"IO",
".",
"read",
"(",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"+",
"\"/annotate/style.scss\"",
")",
",",
":syntax",
"=>",
":scss",
")",
".",
"render",
"end"
] | ERB template uses this to obtain our own stylesheet. | [
"ERB",
"template",
"uses",
"this",
"to",
"obtain",
"our",
"own",
"stylesheet",
"."
] | 5368d8f15e70b2f3cc6b38872a4685383b119d02 | https://github.com/assaf/css-annotate/blob/5368d8f15e70b2f3cc6b38872a4685383b119d02/lib/css/annotate.rb#L52-L54 | train |
wapcaplet/kelp | lib/kelp/visibility.rb | Kelp.Visibility.page_contains? | def page_contains?(text_or_regexp)
if text_or_regexp.class == String
return page.has_content?(text_or_regexp)
elsif text_or_regexp.class == Regexp
return page.has_xpath?('.//*', :text => text_or_regexp)
else
raise ArgumentError, "Expected String or Regexp, got #{text_or_regexp.... | ruby | def page_contains?(text_or_regexp)
if text_or_regexp.class == String
return page.has_content?(text_or_regexp)
elsif text_or_regexp.class == Regexp
return page.has_xpath?('.//*', :text => text_or_regexp)
else
raise ArgumentError, "Expected String or Regexp, got #{text_or_regexp.... | [
"def",
"page_contains?",
"(",
"text_or_regexp",
")",
"if",
"text_or_regexp",
".",
"class",
"==",
"String",
"return",
"page",
".",
"has_content?",
"(",
"text_or_regexp",
")",
"elsif",
"text_or_regexp",
".",
"class",
"==",
"Regexp",
"return",
"page",
".",
"has_xpa... | Return `true` if the current page contains the given text or regular expression,
or `false` if it does not.
@param [String, Regexp] text_or_regexp
Text or regular expression to look for
@raise [ArgumentError]
If the given argument isn't a String or Regexp
@since 0.2.0 | [
"Return",
"true",
"if",
"the",
"current",
"page",
"contains",
"the",
"given",
"text",
"or",
"regular",
"expression",
"or",
"false",
"if",
"it",
"does",
"not",
"."
] | 592fe188db5a3d05e6120ed2157ad8d781601b7a | https://github.com/wapcaplet/kelp/blob/592fe188db5a3d05e6120ed2157ad8d781601b7a/lib/kelp/visibility.rb#L26-L34 | train |
wapcaplet/kelp | lib/kelp/visibility.rb | Kelp.Visibility.should_see | def should_see(texts, scope={})
in_scope(scope) do
texts = [texts] if (texts.class == String || texts.class == Regexp)
# Select all expected values that don't appear on the page
unexpected = texts.select do |text|
!page_contains?(text)
end
if !unexpected.empty?
... | ruby | def should_see(texts, scope={})
in_scope(scope) do
texts = [texts] if (texts.class == String || texts.class == Regexp)
# Select all expected values that don't appear on the page
unexpected = texts.select do |text|
!page_contains?(text)
end
if !unexpected.empty?
... | [
"def",
"should_see",
"(",
"texts",
",",
"scope",
"=",
"{",
"}",
")",
"in_scope",
"(",
"scope",
")",
"do",
"texts",
"=",
"[",
"texts",
"]",
"if",
"(",
"texts",
".",
"class",
"==",
"String",
"||",
"texts",
".",
"class",
"==",
"Regexp",
")",
"# Select... | Verify the presence of content on the page. Passes when all the given items
are found on the page, and fails if any of them are not found.
@example
should_see "Animaniacs"
should_see ["Yakko", "Wakko", "Dot"]
should_see "Baloney", :within => "#slacks"
should_see /(Animaney|Totally Insaney|Pinky and the B... | [
"Verify",
"the",
"presence",
"of",
"content",
"on",
"the",
"page",
".",
"Passes",
"when",
"all",
"the",
"given",
"items",
"are",
"found",
"on",
"the",
"page",
"and",
"fails",
"if",
"any",
"of",
"them",
"are",
"not",
"found",
"."
] | 592fe188db5a3d05e6120ed2157ad8d781601b7a | https://github.com/wapcaplet/kelp/blob/592fe188db5a3d05e6120ed2157ad8d781601b7a/lib/kelp/visibility.rb#L54-L66 | train |
wapcaplet/kelp | lib/kelp/visibility.rb | Kelp.Visibility.should_see_in_same_row | def should_see_in_same_row(texts, scope={})
in_scope(scope) do
if !page.has_xpath?(xpath_row_containing(texts))
raise Kelp::Unexpected, "Expected, but did not see: #{texts.inspect} in the same row"
end
end
end | ruby | def should_see_in_same_row(texts, scope={})
in_scope(scope) do
if !page.has_xpath?(xpath_row_containing(texts))
raise Kelp::Unexpected, "Expected, but did not see: #{texts.inspect} in the same row"
end
end
end | [
"def",
"should_see_in_same_row",
"(",
"texts",
",",
"scope",
"=",
"{",
"}",
")",
"in_scope",
"(",
"scope",
")",
"do",
"if",
"!",
"page",
".",
"has_xpath?",
"(",
"xpath_row_containing",
"(",
"texts",
")",
")",
"raise",
"Kelp",
"::",
"Unexpected",
",",
"\"... | Verify that all items appear in the same table row. Passes if a `tr`
element exists containing all the given `texts`, and fails if no such
`tr` exists. The texts may be in any order in the row.
@example
should_see_in_same_row ["Yakko", "Rob Paulsen"]
should_see_in_same_row ["Wakko", "Jess Harnell"]
should_... | [
"Verify",
"that",
"all",
"items",
"appear",
"in",
"the",
"same",
"table",
"row",
".",
"Passes",
"if",
"a",
"tr",
"element",
"exists",
"containing",
"all",
"the",
"given",
"texts",
"and",
"fails",
"if",
"no",
"such",
"tr",
"exists",
".",
"The",
"texts",
... | 592fe188db5a3d05e6120ed2157ad8d781601b7a | https://github.com/wapcaplet/kelp/blob/592fe188db5a3d05e6120ed2157ad8d781601b7a/lib/kelp/visibility.rb#L112-L118 | train |
jeremyd/virtualmonkey | lib/virtualmonkey/ebs.rb | VirtualMonkey.EBS.wait_for_snapshots | def wait_for_snapshots
timeout=1500
step=10
while timeout > 0
puts "Checking for snapshot completed"
snapshots = behavior(:find_snapshots)
status= snapshots.map { |x| x.aws_status }
break unless status.include?("pending")
sleep step
timeout -= step
... | ruby | def wait_for_snapshots
timeout=1500
step=10
while timeout > 0
puts "Checking for snapshot completed"
snapshots = behavior(:find_snapshots)
status= snapshots.map { |x| x.aws_status }
break unless status.include?("pending")
sleep step
timeout -= step
... | [
"def",
"wait_for_snapshots",
"timeout",
"=",
"1500",
"step",
"=",
"10",
"while",
"timeout",
">",
"0",
"puts",
"\"Checking for snapshot completed\"",
"snapshots",
"=",
"behavior",
"(",
":find_snapshots",
")",
"status",
"=",
"snapshots",
".",
"map",
"{",
"|",
"x",... | take the lineage name, find all snapshots and sleep until none are in the pending state. | [
"take",
"the",
"lineage",
"name",
"find",
"all",
"snapshots",
"and",
"sleep",
"until",
"none",
"are",
"in",
"the",
"pending",
"state",
"."
] | b2c7255f20ac5ec881eb90afbb5e712160db0dcb | https://github.com/jeremyd/virtualmonkey/blob/b2c7255f20ac5ec881eb90afbb5e712160db0dcb/lib/virtualmonkey/ebs.rb#L45-L57 | train |
jeremyd/virtualmonkey | lib/virtualmonkey/ebs.rb | VirtualMonkey.EBS.find_snapshot_timestamp | def find_snapshot_timestamp
last_snap = behavior(:find_snapshots).last
last_snap.tags.detect { |t| t["name"] =~ /timestamp=(\d+)$/ }
timestamp = $1
end | ruby | def find_snapshot_timestamp
last_snap = behavior(:find_snapshots).last
last_snap.tags.detect { |t| t["name"] =~ /timestamp=(\d+)$/ }
timestamp = $1
end | [
"def",
"find_snapshot_timestamp",
"last_snap",
"=",
"behavior",
"(",
":find_snapshots",
")",
".",
"last",
"last_snap",
".",
"tags",
".",
"detect",
"{",
"|",
"t",
"|",
"t",
"[",
"\"name\"",
"]",
"=~",
"/",
"\\d",
"/",
"}",
"timestamp",
"=",
"$1",
"end"
] | Returns the timestamp of the latest snapshot for testing OPT_DB_RESTORE_TIMESTAMP_OVERRIDE | [
"Returns",
"the",
"timestamp",
"of",
"the",
"latest",
"snapshot",
"for",
"testing",
"OPT_DB_RESTORE_TIMESTAMP_OVERRIDE"
] | b2c7255f20ac5ec881eb90afbb5e712160db0dcb | https://github.com/jeremyd/virtualmonkey/blob/b2c7255f20ac5ec881eb90afbb5e712160db0dcb/lib/virtualmonkey/ebs.rb#L70-L74 | train |
postmodern/open_namespace | lib/open_namespace/class_methods.rb | OpenNamespace.ClassMethods.require_file | def require_file(name)
name = name.to_s
path = File.join(namespace_root,File.expand_path(File.join('',name)))
begin
require path
rescue Gem::LoadError => e
raise(e)
rescue ::LoadError
return nil
end
return true
end | ruby | def require_file(name)
name = name.to_s
path = File.join(namespace_root,File.expand_path(File.join('',name)))
begin
require path
rescue Gem::LoadError => e
raise(e)
rescue ::LoadError
return nil
end
return true
end | [
"def",
"require_file",
"(",
"name",
")",
"name",
"=",
"name",
".",
"to_s",
"path",
"=",
"File",
".",
"join",
"(",
"namespace_root",
",",
"File",
".",
"expand_path",
"(",
"File",
".",
"join",
"(",
"''",
",",
"name",
")",
")",
")",
"begin",
"require",
... | Requires the file with the given name, within the namespace root
directory.
@param [Symbol, String] name
The name of the file to require.
@return [true, nil]
Returns `true` if the file was successfully loaded, returns `nil`
on a `LoadError` exception.
@raise [Gem::LoadError]
A dependency needed by th... | [
"Requires",
"the",
"file",
"with",
"the",
"given",
"name",
"within",
"the",
"namespace",
"root",
"directory",
"."
] | 305e3a794fda6a290faa935098fe528048ffed77 | https://github.com/postmodern/open_namespace/blob/305e3a794fda6a290faa935098fe528048ffed77/lib/open_namespace/class_methods.rb#L67-L80 | train |
postmodern/open_namespace | lib/open_namespace/class_methods.rb | OpenNamespace.ClassMethods.const_defined? | def const_defined?(name,*inherit)
if super(name,*inherit)
true
else
# attempt to load the file that might have the constant
require_file(OpenNamespace.const_path(name))
# check for the constant again
return super(name,*inherit)
end
end | ruby | def const_defined?(name,*inherit)
if super(name,*inherit)
true
else
# attempt to load the file that might have the constant
require_file(OpenNamespace.const_path(name))
# check for the constant again
return super(name,*inherit)
end
end | [
"def",
"const_defined?",
"(",
"name",
",",
"*",
"inherit",
")",
"if",
"super",
"(",
"name",
",",
"inherit",
")",
"true",
"else",
"# attempt to load the file that might have the constant",
"require_file",
"(",
"OpenNamespace",
".",
"const_path",
"(",
"name",
")",
"... | Checks if a constant is defined or attempts loading the constant.
@param [String] name
The name of the constant.
@param [Boolean] inherit
Specifies whether to search the ancestors for the constant.
@return [Boolean]
Specifies whether the constant is defined. | [
"Checks",
"if",
"a",
"constant",
"is",
"defined",
"or",
"attempts",
"loading",
"the",
"constant",
"."
] | 305e3a794fda6a290faa935098fe528048ffed77 | https://github.com/postmodern/open_namespace/blob/305e3a794fda6a290faa935098fe528048ffed77/lib/open_namespace/class_methods.rb#L94-L104 | train |
maxjacobson/todo_lint | lib/todo_lint/todo.rb | TodoLint.Todo.relative_path | def relative_path
current_dir = Pathname.new(File.expand_path("./"))
Pathname.new(path).relative_path_from(current_dir).to_s
end | ruby | def relative_path
current_dir = Pathname.new(File.expand_path("./"))
Pathname.new(path).relative_path_from(current_dir).to_s
end | [
"def",
"relative_path",
"current_dir",
"=",
"Pathname",
".",
"new",
"(",
"File",
".",
"expand_path",
"(",
"\"./\"",
")",
")",
"Pathname",
".",
"new",
"(",
"path",
")",
".",
"relative_path_from",
"(",
"current_dir",
")",
".",
"to_s",
"end"
] | Which todo is due sooner?
@example
[todo_one, todo_two].sort # this implicitly calls <=>
@return [Fixnum]
@api public
The relative path to the file where this todo was found
@example
todo.relative #=> "spec/spec_helper.rb"
@return [String]
@api public | [
"Which",
"todo",
"is",
"due",
"sooner?"
] | 0d1061383ea205ef4c74edc64568e308ac1af990 | https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/todo.rb#L179-L182 | train |
maxjacobson/todo_lint | lib/todo_lint/todo.rb | TodoLint.Todo.lookup_tag_due_date | def lookup_tag_due_date
config.fetch(:tags).fetch(match[:tag])
rescue KeyError
msg = "#{match[:tag]} tag not defined in config file"
raise KeyError, msg
end | ruby | def lookup_tag_due_date
config.fetch(:tags).fetch(match[:tag])
rescue KeyError
msg = "#{match[:tag]} tag not defined in config file"
raise KeyError, msg
end | [
"def",
"lookup_tag_due_date",
"config",
".",
"fetch",
"(",
":tags",
")",
".",
"fetch",
"(",
"match",
"[",
":tag",
"]",
")",
"rescue",
"KeyError",
"msg",
"=",
"\"#{match[:tag]} tag not defined in config file\"",
"raise",
"KeyError",
",",
"msg",
"end"
] | A tag was referenced, so let's see when that's due
@return [DueDate]
@raise [KeyError] if the tag does not reference a due date in the config
@api private | [
"A",
"tag",
"was",
"referenced",
"so",
"let",
"s",
"see",
"when",
"that",
"s",
"due"
] | 0d1061383ea205ef4c74edc64568e308ac1af990 | https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/todo.rb#L224-L229 | train |
Deradon/Rdcpu16 | lib/dcpu16/support/debug.rb | DCPU16.Debug.debug | def debug(msg = nil, &block)
return unless debug?
puts "\n[DEBUG] - #{caller.first}"
msg.each { |m| puts(m) } if msg.is_a?(Array)
if msg.is_a?(Hash)
msg.each do |k, v|
puts "[#{k.to_s}]"
if v.is_a?(Array)
v.each {|m| puts(m) }
else
... | ruby | def debug(msg = nil, &block)
return unless debug?
puts "\n[DEBUG] - #{caller.first}"
msg.each { |m| puts(m) } if msg.is_a?(Array)
if msg.is_a?(Hash)
msg.each do |k, v|
puts "[#{k.to_s}]"
if v.is_a?(Array)
v.each {|m| puts(m) }
else
... | [
"def",
"debug",
"(",
"msg",
"=",
"nil",
",",
"&",
"block",
")",
"return",
"unless",
"debug?",
"puts",
"\"\\n[DEBUG] - #{caller.first}\"",
"msg",
".",
"each",
"{",
"|",
"m",
"|",
"puts",
"(",
"m",
")",
"}",
"if",
"msg",
".",
"is_a?",
"(",
"Array",
")"... | Debug-Wrapper | [
"Debug",
"-",
"Wrapper"
] | a4460927aa64c2a514c57993e8ea13f5b48377e9 | https://github.com/Deradon/Rdcpu16/blob/a4460927aa64c2a514c57993e8ea13f5b48377e9/lib/dcpu16/support/debug.rb#L11-L33 | train |
sanichi/icu_tournament | lib/icu_tournament/result.rb | ICU.Result.rateable= | def rateable=(rateable)
if opponent.nil?
@rateable = false
return
end
@rateable = case rateable
when nil then true # default is true
when false then false # this is the only way to turn it off
else true
end
end | ruby | def rateable=(rateable)
if opponent.nil?
@rateable = false
return
end
@rateable = case rateable
when nil then true # default is true
when false then false # this is the only way to turn it off
else true
end
end | [
"def",
"rateable",
"=",
"(",
"rateable",
")",
"if",
"opponent",
".",
"nil?",
"@rateable",
"=",
"false",
"return",
"end",
"@rateable",
"=",
"case",
"rateable",
"when",
"nil",
"then",
"true",
"# default is true",
"when",
"false",
"then",
"false",
"# this is the ... | Rateable flag. If false, result is not rateable. Can only be true if there is an opponent. | [
"Rateable",
"flag",
".",
"If",
"false",
"result",
"is",
"not",
"rateable",
".",
"Can",
"only",
"be",
"true",
"if",
"there",
"is",
"an",
"opponent",
"."
] | badd2940189feaeb9f0edb4b4e07ff6b2548bd3d | https://github.com/sanichi/icu_tournament/blob/badd2940189feaeb9f0edb4b4e07ff6b2548bd3d/lib/icu_tournament/result.rb#L142-L152 | train |
groupdocs-storage-cloud/groupdocs-storage-cloud-ruby | lib/GroupDocs/Storage/configuration.rb | GroupDocsStorageCloud.Configuration.auth_settings | def auth_settings
{
'appsid' =>
{
type: 'api_key',
in: 'query',
key: 'appsid',
value: api_key_with_prefix('appsid')
},
'oauth' =>
{
type: 'oauth2',
in: 'header',
key: 'Authorization',
... | ruby | def auth_settings
{
'appsid' =>
{
type: 'api_key',
in: 'query',
key: 'appsid',
value: api_key_with_prefix('appsid')
},
'oauth' =>
{
type: 'oauth2',
in: 'header',
key: 'Authorization',
... | [
"def",
"auth_settings",
"{",
"'appsid'",
"=>",
"{",
"type",
":",
"'api_key'",
",",
"in",
":",
"'query'",
",",
"key",
":",
"'appsid'",
",",
"value",
":",
"api_key_with_prefix",
"(",
"'appsid'",
")",
"}",
",",
"'oauth'",
"=>",
"{",
"type",
":",
"'oauth2'",... | Returns Auth Settings hash for api client. | [
"Returns",
"Auth",
"Settings",
"hash",
"for",
"api",
"client",
"."
] | 0820b8b5582ea2a6bc0f5e7f694eb80aad5e67ce | https://github.com/groupdocs-storage-cloud/groupdocs-storage-cloud-ruby/blob/0820b8b5582ea2a6bc0f5e7f694eb80aad5e67ce/lib/GroupDocs/Storage/configuration.rb#L177-L201 | train |
chetan/bixby-common | lib/bixby-common/api/http_channel.rb | Bixby.HttpChannel.execute_internal | def execute_internal(json_request, &block)
if json_request.respond_to?(:headers) then
# always required for posting to API
json_request.headers["Content-Type"] = "application/json"
end
req = HTTPI::Request.new(:url => @uri, :body => json_request.to_wire)
# add in extra headers... | ruby | def execute_internal(json_request, &block)
if json_request.respond_to?(:headers) then
# always required for posting to API
json_request.headers["Content-Type"] = "application/json"
end
req = HTTPI::Request.new(:url => @uri, :body => json_request.to_wire)
# add in extra headers... | [
"def",
"execute_internal",
"(",
"json_request",
",",
"&",
"block",
")",
"if",
"json_request",
".",
"respond_to?",
"(",
":headers",
")",
"then",
"# always required for posting to API",
"json_request",
".",
"headers",
"[",
"\"Content-Type\"",
"]",
"=",
"\"application/js... | Execute the request, optionally passing a block to handle the response
@param [JsonRequest] json_request
@param [Block] block
@return [JsonResponse] response | [
"Execute",
"the",
"request",
"optionally",
"passing",
"a",
"block",
"to",
"handle",
"the",
"response"
] | 3fb8829987b115fc53ec820d97a20b4a8c49b4a2 | https://github.com/chetan/bixby-common/blob/3fb8829987b115fc53ec820d97a20b4a8c49b4a2/lib/bixby-common/api/http_channel.rb#L40-L67 | train |
ajeychronus/chronuscop_client | lib/chronuscop_client/synchronizer.rb | ChronuscopClient.Synchronizer.write_last_update | def write_last_update(last_update_at)
# Check for the presence of the tmp directory.
if(! File::directory?("tmp")) then
Dir.mkdir("tmp")
end
f = File.new("tmp/chronuscop.tmp","w")
f.printf("%d",last_update_at.to_i)
f.close()
end | ruby | def write_last_update(last_update_at)
# Check for the presence of the tmp directory.
if(! File::directory?("tmp")) then
Dir.mkdir("tmp")
end
f = File.new("tmp/chronuscop.tmp","w")
f.printf("%d",last_update_at.to_i)
f.close()
end | [
"def",
"write_last_update",
"(",
"last_update_at",
")",
"# Check for the presence of the tmp directory.",
"if",
"(",
"!",
"File",
"::",
"directory?",
"(",
"\"tmp\"",
")",
")",
"then",
"Dir",
".",
"mkdir",
"(",
"\"tmp\"",
")",
"end",
"f",
"=",
"File",
".",
"new... | Function to write the last update time to a temporary file. | [
"Function",
"to",
"write",
"the",
"last",
"update",
"time",
"to",
"a",
"temporary",
"file",
"."
] | 17834beba5215b122b399f145f8710da03ff7a0a | https://github.com/ajeychronus/chronuscop_client/blob/17834beba5215b122b399f145f8710da03ff7a0a/lib/chronuscop_client/synchronizer.rb#L19-L28 | train |
ajeychronus/chronuscop_client | lib/chronuscop_client/synchronizer.rb | ChronuscopClient.Synchronizer.xml_time_to_integer | def xml_time_to_integer(str)
arr = str.gsub(/T|Z|:/,"-").split(/-/)
year = arr[0]
month = arr[1]
day = arr[2]
hour = arr[3]
min = arr[4]
sec = arr[5]
Time.utc(year,month,day,hour,min,sec).to_i
end | ruby | def xml_time_to_integer(str)
arr = str.gsub(/T|Z|:/,"-").split(/-/)
year = arr[0]
month = arr[1]
day = arr[2]
hour = arr[3]
min = arr[4]
sec = arr[5]
Time.utc(year,month,day,hour,min,sec).to_i
end | [
"def",
"xml_time_to_integer",
"(",
"str",
")",
"arr",
"=",
"str",
".",
"gsub",
"(",
"/",
"/",
",",
"\"-\"",
")",
".",
"split",
"(",
"/",
"/",
")",
"year",
"=",
"arr",
"[",
"0",
"]",
"month",
"=",
"arr",
"[",
"1",
"]",
"day",
"=",
"arr",
"[",
... | To convert xml_time received from the server to integer. | [
"To",
"convert",
"xml_time",
"received",
"from",
"the",
"server",
"to",
"integer",
"."
] | 17834beba5215b122b399f145f8710da03ff7a0a | https://github.com/ajeychronus/chronuscop_client/blob/17834beba5215b122b399f145f8710da03ff7a0a/lib/chronuscop_client/synchronizer.rb#L58-L67 | train |
ajeychronus/chronuscop_client | lib/chronuscop_client/synchronizer.rb | ChronuscopClient.Synchronizer.sync_it_now | def sync_it_now
puts "Attempt Sync"
# Getting the last sync value.
last_update_at = get_last_update_at
# querying the page.
page = @mechanize_agent.get("#{ChronuscopClient.configuration_object.chronuscop_server_address}/projects/#{ChronuscopClient.configuration_object.project_number}/tra... | ruby | def sync_it_now
puts "Attempt Sync"
# Getting the last sync value.
last_update_at = get_last_update_at
# querying the page.
page = @mechanize_agent.get("#{ChronuscopClient.configuration_object.chronuscop_server_address}/projects/#{ChronuscopClient.configuration_object.project_number}/tra... | [
"def",
"sync_it_now",
"puts",
"\"Attempt Sync\"",
"# Getting the last sync value.",
"last_update_at",
"=",
"get_last_update_at",
"# querying the page.",
"page",
"=",
"@mechanize_agent",
".",
"get",
"(",
"\"#{ChronuscopClient.configuration_object.chronuscop_server_address}/projects/#{Ch... | This method keeps the remote-keys and the local-keys synchronized.
This method should be called only after initializing the configuration
object as it uses those configuration values. | [
"This",
"method",
"keeps",
"the",
"remote",
"-",
"keys",
"and",
"the",
"local",
"-",
"keys",
"synchronized",
".",
"This",
"method",
"should",
"be",
"called",
"only",
"after",
"initializing",
"the",
"configuration",
"object",
"as",
"it",
"uses",
"those",
"con... | 17834beba5215b122b399f145f8710da03ff7a0a | https://github.com/ajeychronus/chronuscop_client/blob/17834beba5215b122b399f145f8710da03ff7a0a/lib/chronuscop_client/synchronizer.rb#L74-L120 | train |
agilecreativity/vim_printer | lib/vim_printer/cli.rb | VimPrinter.CLI.get_input_files | def get_input_files(args = {})
command = args.fetch(:command, nil)
if command.nil?
CodeLister.files(args)
else
# Note: base_dir must be the the same the directory where the command is executed from
CodeLister.files_from_shell(command, args.fetch(:base_dir, "."))
end
... | ruby | def get_input_files(args = {})
command = args.fetch(:command, nil)
if command.nil?
CodeLister.files(args)
else
# Note: base_dir must be the the same the directory where the command is executed from
CodeLister.files_from_shell(command, args.fetch(:base_dir, "."))
end
... | [
"def",
"get_input_files",
"(",
"args",
"=",
"{",
"}",
")",
"command",
"=",
"args",
".",
"fetch",
"(",
":command",
",",
"nil",
")",
"if",
"command",
".",
"nil?",
"CodeLister",
".",
"files",
"(",
"args",
")",
"else",
"# Note: base_dir must be the the same the ... | Get the list of input file
@param [Hash<Symbol, Object>] args the input options
@option args [String] :command the shell command to be used to get list of files
@return [Array<String>] list of files in the format
["./Gemfile", "./lib/vim_printer/cli.rb", ..] | [
"Get",
"the",
"list",
"of",
"input",
"file"
] | 4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206 | https://github.com/agilecreativity/vim_printer/blob/4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206/lib/vim_printer/cli.rb#L84-L92 | train |
agilecreativity/vim_printer | lib/vim_printer/cli.rb | VimPrinter.CLI.execute | def execute(options = {})
input_files = get_input_files(options)
# we want to avoid printing the binary file
input_files.delete_if do |file|
File.binary?(file.gsub(/^\./, options[:base_dir]))
end
if input_files.empty?
puts "No file found for your option: #{options}"
... | ruby | def execute(options = {})
input_files = get_input_files(options)
# we want to avoid printing the binary file
input_files.delete_if do |file|
File.binary?(file.gsub(/^\./, options[:base_dir]))
end
if input_files.empty?
puts "No file found for your option: #{options}"
... | [
"def",
"execute",
"(",
"options",
"=",
"{",
"}",
")",
"input_files",
"=",
"get_input_files",
"(",
"options",
")",
"# we want to avoid printing the binary file",
"input_files",
".",
"delete_if",
"do",
"|",
"file",
"|",
"File",
".",
"binary?",
"(",
"file",
".",
... | Main entry point to export the code
@param [Hash<Symbol, Object>] options the options argument | [
"Main",
"entry",
"point",
"to",
"export",
"the",
"code"
] | 4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206 | https://github.com/agilecreativity/vim_printer/blob/4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206/lib/vim_printer/cli.rb#L97-L121 | train |
agilecreativity/vim_printer | lib/vim_printer/cli.rb | VimPrinter.CLI.to_htmls | def to_htmls(files, options = {})
FileUtils.chdir(File.expand_path(options[:base_dir]))
files.each_with_index do |file, index|
puts "FYI: process file #{index + 1} of #{files.size} : #{file}"
to_html(file, options)
end
end | ruby | def to_htmls(files, options = {})
FileUtils.chdir(File.expand_path(options[:base_dir]))
files.each_with_index do |file, index|
puts "FYI: process file #{index + 1} of #{files.size} : #{file}"
to_html(file, options)
end
end | [
"def",
"to_htmls",
"(",
"files",
",",
"options",
"=",
"{",
"}",
")",
"FileUtils",
".",
"chdir",
"(",
"File",
".",
"expand_path",
"(",
"options",
"[",
":base_dir",
"]",
")",
")",
"files",
".",
"each_with_index",
"do",
"|",
"file",
",",
"index",
"|",
"... | convert multiple files to html | [
"convert",
"multiple",
"files",
"to",
"html"
] | 4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206 | https://github.com/agilecreativity/vim_printer/blob/4ac22ca6034da299ffd2f6f8fb6c1b6efbc59206/lib/vim_printer/cli.rb#L124-L130 | train |
kylegrantlucas/takeout | lib/takeout/client.rb | Takeout.Client.substitute_template_values | def substitute_template_values(endpoint, request_type, options={})
# Gets the proper template for the give CUSTOM_SCHEMA string for this endpoint and substitutes value for it based on give options
endpoint_templates = @schemas.fetch(request_type.to_sym, nil)
template = endpoint_templates.fetch(endpoin... | ruby | def substitute_template_values(endpoint, request_type, options={})
# Gets the proper template for the give CUSTOM_SCHEMA string for this endpoint and substitutes value for it based on give options
endpoint_templates = @schemas.fetch(request_type.to_sym, nil)
template = endpoint_templates.fetch(endpoin... | [
"def",
"substitute_template_values",
"(",
"endpoint",
",",
"request_type",
",",
"options",
"=",
"{",
"}",
")",
"# Gets the proper template for the give CUSTOM_SCHEMA string for this endpoint and substitutes value for it based on give options",
"endpoint_templates",
"=",
"@schemas",
"... | Render out the template values and return the updated options hash
@param [String] endpoint
@param [String] request_type
@param [Hash] options
@return [String] rendered_template
@return [Hash] options | [
"Render",
"out",
"the",
"template",
"values",
"and",
"return",
"the",
"updated",
"options",
"hash"
] | c6ac62e5c0bcd2a33be6a2657dfc2ae1c1e712df | https://github.com/kylegrantlucas/takeout/blob/c6ac62e5c0bcd2a33be6a2657dfc2ae1c1e712df/lib/takeout/client.rb#L90-L102 | train |
pdorrell/regenerate | lib/regenerate/site-regenerator.rb | Regenerate.SiteRegenerator.copySrcToOutputFile | def copySrcToOutputFile(srcFile, outFile, makeBackup)
if makeBackup
makeBackupFile(outFile)
end
FileUtils.cp(srcFile, outFile, :verbose => true)
end | ruby | def copySrcToOutputFile(srcFile, outFile, makeBackup)
if makeBackup
makeBackupFile(outFile)
end
FileUtils.cp(srcFile, outFile, :verbose => true)
end | [
"def",
"copySrcToOutputFile",
"(",
"srcFile",
",",
"outFile",
",",
"makeBackup",
")",
"if",
"makeBackup",
"makeBackupFile",
"(",
"outFile",
")",
"end",
"FileUtils",
".",
"cp",
"(",
"srcFile",
",",
"outFile",
",",
":verbose",
"=>",
"true",
")",
"end"
] | Copy a source file directly to an output file | [
"Copy",
"a",
"source",
"file",
"directly",
"to",
"an",
"output",
"file"
] | 31f3beb3ff9b45384a90f20fed61be20f39da0d4 | https://github.com/pdorrell/regenerate/blob/31f3beb3ff9b45384a90f20fed61be20f39da0d4/lib/regenerate/site-regenerator.rb#L87-L92 | train |
niyireth/brownpapertickets | lib/brownpapertickets/httpost.rb | BrownPaperTickets.Httpost.handle_deflation | def handle_deflation
case last_response["content-encoding"]
when "gzip"
body_io = StringIO.new(last_response.body)
last_response.body.replace Zlib::GzipReader.new(body_io).read
when "deflate"
last_response.body.replace Zlib::Inflate.inflate(last_response.body)
end
end | ruby | def handle_deflation
case last_response["content-encoding"]
when "gzip"
body_io = StringIO.new(last_response.body)
last_response.body.replace Zlib::GzipReader.new(body_io).read
when "deflate"
last_response.body.replace Zlib::Inflate.inflate(last_response.body)
end
end | [
"def",
"handle_deflation",
"case",
"last_response",
"[",
"\"content-encoding\"",
"]",
"when",
"\"gzip\"",
"body_io",
"=",
"StringIO",
".",
"new",
"(",
"last_response",
".",
"body",
")",
"last_response",
".",
"body",
".",
"replace",
"Zlib",
"::",
"GzipReader",
".... | Inspired by Ruby 1.9 | [
"Inspired",
"by",
"Ruby",
"1",
".",
"9"
] | 1eae1dc6f02b183c55090b79a62023e0f572fb57 | https://github.com/niyireth/brownpapertickets/blob/1eae1dc6f02b183c55090b79a62023e0f572fb57/lib/brownpapertickets/httpost.rb#L169-L177 | train |
nragaz/timely | lib/timely/cell.rb | Timely.Cell.value_from_redis | def value_from_redis
if val = Timely.redis.hget(redis_hash_key, redis_value_key)
val = val.include?(".") ? val.to_f : val.to_i
else
val = value_without_caching
Timely.redis.hset(redis_hash_key, redis_value_key, val)
end
val
end | ruby | def value_from_redis
if val = Timely.redis.hget(redis_hash_key, redis_value_key)
val = val.include?(".") ? val.to_f : val.to_i
else
val = value_without_caching
Timely.redis.hset(redis_hash_key, redis_value_key, val)
end
val
end | [
"def",
"value_from_redis",
"if",
"val",
"=",
"Timely",
".",
"redis",
".",
"hget",
"(",
"redis_hash_key",
",",
"redis_value_key",
")",
"val",
"=",
"val",
".",
"include?",
"(",
"\".\"",
")",
"?",
"val",
".",
"to_f",
":",
"val",
".",
"to_i",
"else",
"val"... | retrieve a cached value from a redis hash.
hashes are accessed using the report title and row title. values within
the hash are keyed using the column's start/end timestamps | [
"retrieve",
"a",
"cached",
"value",
"from",
"a",
"redis",
"hash",
"."
] | 768c15630b2d4b28a96d3f89307175f058b32374 | https://github.com/nragaz/timely/blob/768c15630b2d4b28a96d3f89307175f058b32374/lib/timely/cell.rb#L59-L68 | train |
marcbowes/UsingYAML | lib/using_yaml.rb | UsingYAML.ClassMethods.using_yaml | def using_yaml(*args)
# Include the instance methods which provide accessors and
# mutators for reading/writing from/to the YAML objects.
include InstanceMethods
# Each argument is either a filename or a :path option
args.each do |arg|
case arg
when Symbol, String
... | ruby | def using_yaml(*args)
# Include the instance methods which provide accessors and
# mutators for reading/writing from/to the YAML objects.
include InstanceMethods
# Each argument is either a filename or a :path option
args.each do |arg|
case arg
when Symbol, String
... | [
"def",
"using_yaml",
"(",
"*",
"args",
")",
"# Include the instance methods which provide accessors and",
"# mutators for reading/writing from/to the YAML objects.",
"include",
"InstanceMethods",
"# Each argument is either a filename or a :path option",
"args",
".",
"each",
"do",
"|",
... | Used to configure UsingYAML for a class by defining what files
should be loaded and from where.
include UsingYAML
using_yaml :foo, :bar, :path => "/some/where"
+args+ can contain either filenames or a hash which specifices a
path which contains the corresponding files.
The value of :path must either be a s... | [
"Used",
"to",
"configure",
"UsingYAML",
"for",
"a",
"class",
"by",
"defining",
"what",
"files",
"should",
"be",
"loaded",
"and",
"from",
"where",
"."
] | 4485476ad0ad14850d41c8ed61673f7b08b9f007 | https://github.com/marcbowes/UsingYAML/blob/4485476ad0ad14850d41c8ed61673f7b08b9f007/lib/using_yaml.rb#L100-L119 | train |
device-independent/restless_router | lib/restless_router/route.rb | RestlessRouter.Route.url_for | def url_for(options={})
if templated?
template = Addressable::Template.new(base_path)
template = template.expand(options)
template.to_s
else
base_path
end
end | ruby | def url_for(options={})
if templated?
template = Addressable::Template.new(base_path)
template = template.expand(options)
template.to_s
else
base_path
end
end | [
"def",
"url_for",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"templated?",
"template",
"=",
"Addressable",
"::",
"Template",
".",
"new",
"(",
"base_path",
")",
"template",
"=",
"template",
".",
"expand",
"(",
"options",
")",
"template",
".",
"to_s",
"else... | Returns the URL for the route. If it's templated,
then we utilize the provided options hash to expand
the route. Otherwise we return the `path`
@return [String] The templated or base URI | [
"Returns",
"the",
"URL",
"for",
"the",
"route",
".",
"If",
"it",
"s",
"templated",
"then",
"we",
"utilize",
"the",
"provided",
"options",
"hash",
"to",
"expand",
"the",
"route",
".",
"Otherwise",
"we",
"return",
"the",
"path"
] | c20ea03ec53b889d192393c7ab18bcacb0b5e46f | https://github.com/device-independent/restless_router/blob/c20ea03ec53b889d192393c7ab18bcacb0b5e46f/lib/restless_router/route.rb#L63-L71 | train |
mnipper/serket | lib/serket/field_decrypter.rb | Serket.FieldDecrypter.decrypt | def decrypt(field)
return if field !~ /\S/
iv, encrypted_aes_key, encrypted_text = parse(field)
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_filepath))
decrypted_aes_key = private_key.private_decrypt(Base64.decode64(encrypted_aes_key))
decrypted_field = decrypt_data(iv, decry... | ruby | def decrypt(field)
return if field !~ /\S/
iv, encrypted_aes_key, encrypted_text = parse(field)
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_filepath))
decrypted_aes_key = private_key.private_decrypt(Base64.decode64(encrypted_aes_key))
decrypted_field = decrypt_data(iv, decry... | [
"def",
"decrypt",
"(",
"field",
")",
"return",
"if",
"field",
"!~",
"/",
"\\S",
"/",
"iv",
",",
"encrypted_aes_key",
",",
"encrypted_text",
"=",
"parse",
"(",
"field",
")",
"private_key",
"=",
"OpenSSL",
"::",
"PKey",
"::",
"RSA",
".",
"new",
"(",
"Fil... | Decrypt the provided cipher text, and return the plaintext
Return nil if whitespace | [
"Decrypt",
"the",
"provided",
"cipher",
"text",
"and",
"return",
"the",
"plaintext",
"Return",
"nil",
"if",
"whitespace"
] | a4606071fde8982d794ff1f8fc09c399ac92ba17 | https://github.com/mnipper/serket/blob/a4606071fde8982d794ff1f8fc09c399ac92ba17/lib/serket/field_decrypter.rb#L22-L29 | train |
Subsets and Splits
SQL Console for semeru/code-text-ruby
Retrieves 20,000 non-null code samples labeled as Ruby, providing a basic overview of the dataset but without deeper analysis.