id int32 0 24.9k | repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 |
|---|---|---|---|---|---|---|---|---|---|---|---|
15,500 | piotrmurach/strings | lib/strings/pad.rb | Strings.Pad.pad_around | def pad_around(text, padding, fill: SPACE)
fill * padding.left + text + fill * padding.right
end | ruby | def pad_around(text, padding, fill: SPACE)
fill * padding.left + text + fill * padding.right
end | [
"def",
"pad_around",
"(",
"text",
",",
"padding",
",",
"fill",
":",
"SPACE",
")",
"fill",
"*",
"padding",
".",
"left",
"+",
"text",
"+",
"fill",
"*",
"padding",
".",
"right",
"end"
] | Apply padding to left and right side of string
@param [String] text
@return [String]
@api private | [
"Apply",
"padding",
"to",
"left",
"and",
"right",
"side",
"of",
"string"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/pad.rb#L65-L67 |
15,501 | piotrmurach/strings | lib/strings/align.rb | Strings.Align.align_left | def align_left(text, width, fill: SPACE, separator: NEWLINE)
return if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
line + fill * width_diff
else
line
end
end
end | ruby | def align_left(text, width, fill: SPACE, separator: NEWLINE)
return if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
line + fill * width_diff
else
line
end
end
end | [
"def",
"align_left",
"(",
"text",
",",
"width",
",",
"fill",
":",
"SPACE",
",",
"separator",
":",
"NEWLINE",
")",
"return",
"if",
"width",
".",
"nil?",
"each_line",
"(",
"text",
",",
"separator",
")",
"do",
"|",
"line",
"|",
"width_diff",
"=",
"width",... | Aligns text to the left at given length
@return [String]
@api public | [
"Aligns",
"text",
"to",
"the",
"left",
"at",
"given",
"length"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/align.rb#L65-L75 |
15,502 | piotrmurach/strings | lib/strings/align.rb | Strings.Align.align_center | def align_center(text, width, fill: SPACE, separator: NEWLINE)
return text if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
right_count = (width_diff.to_f / 2).ceil
left_count = width_diff - right_count
... | ruby | def align_center(text, width, fill: SPACE, separator: NEWLINE)
return text if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
right_count = (width_diff.to_f / 2).ceil
left_count = width_diff - right_count
... | [
"def",
"align_center",
"(",
"text",
",",
"width",
",",
"fill",
":",
"SPACE",
",",
"separator",
":",
"NEWLINE",
")",
"return",
"text",
"if",
"width",
".",
"nil?",
"each_line",
"(",
"text",
",",
"separator",
")",
"do",
"|",
"line",
"|",
"width_diff",
"="... | Centers text within the width
@return [String]
@api public | [
"Centers",
"text",
"within",
"the",
"width"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/align.rb#L83-L95 |
15,503 | piotrmurach/strings | lib/strings/align.rb | Strings.Align.each_line | def each_line(text, separator)
lines = text.split(separator)
return yield(text) if text.empty?
lines.reduce([]) do |aligned, line|
aligned << yield(line)
end.join(separator)
end | ruby | def each_line(text, separator)
lines = text.split(separator)
return yield(text) if text.empty?
lines.reduce([]) do |aligned, line|
aligned << yield(line)
end.join(separator)
end | [
"def",
"each_line",
"(",
"text",
",",
"separator",
")",
"lines",
"=",
"text",
".",
"split",
"(",
"separator",
")",
"return",
"yield",
"(",
"text",
")",
"if",
"text",
".",
"empty?",
"lines",
".",
"reduce",
"(",
"[",
"]",
")",
"do",
"|",
"aligned",
"... | Enumerate text line by line
@param [String] text
@return [String]
@api private | [
"Enumerate",
"text",
"line",
"by",
"line"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/align.rb#L123-L129 |
15,504 | nylas/nylas-ruby | lib/nylas/http_client.rb | Nylas.HttpClient.execute | def execute(method:, path: nil, headers: {}, query: {}, payload: nil)
timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
request = build_request(
method: method,
path: path,
headers: headers,
query: query,
payload: payload,
timeout: timeout
)
rest_client... | ruby | def execute(method:, path: nil, headers: {}, query: {}, payload: nil)
timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
request = build_request(
method: method,
path: path,
headers: headers,
query: query,
payload: payload,
timeout: timeout
)
rest_client... | [
"def",
"execute",
"(",
"method",
":",
",",
"path",
":",
"nil",
",",
"headers",
":",
"{",
"}",
",",
"query",
":",
"{",
"}",
",",
"payload",
":",
"nil",
")",
"timeout",
"=",
"ENDPOINT_TIMEOUTS",
".",
"fetch",
"(",
"path",
",",
"230",
")",
"request",
... | Sends a request to the Nylas API and rai
@param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch
@param path [String] (Optional, defaults to nil) - Relative path from the API Base. Preferred way to
execute arbitrary or-not-yet-SDK-ified API commands.
@param h... | [
"Sends",
"a",
"request",
"to",
"the",
"Nylas",
"API",
"and",
"rai"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/http_client.rb#L72-L87 |
15,505 | nylas/nylas-ruby | lib/nylas/http_client.rb | Nylas.HttpClient.get | def get(path: nil, headers: {}, query: {})
execute(method: :get, path: path, query: query, headers: headers)
end | ruby | def get(path: nil, headers: {}, query: {})
execute(method: :get, path: path, query: query, headers: headers)
end | [
"def",
"get",
"(",
"path",
":",
"nil",
",",
"headers",
":",
"{",
"}",
",",
"query",
":",
"{",
"}",
")",
"execute",
"(",
"method",
":",
":get",
",",
"path",
":",
"path",
",",
"query",
":",
"query",
",",
"headers",
":",
"headers",
")",
"end"
] | Syntactical sugar for making GET requests via the API.
@see #execute | [
"Syntactical",
"sugar",
"for",
"making",
"GET",
"requests",
"via",
"the",
"API",
"."
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/http_client.rb#L101-L103 |
15,506 | nylas/nylas-ruby | lib/nylas/http_client.rb | Nylas.HttpClient.post | def post(path: nil, payload: nil, headers: {}, query: {})
execute(method: :post, path: path, headers: headers, query: query, payload: payload)
end | ruby | def post(path: nil, payload: nil, headers: {}, query: {})
execute(method: :post, path: path, headers: headers, query: query, payload: payload)
end | [
"def",
"post",
"(",
"path",
":",
"nil",
",",
"payload",
":",
"nil",
",",
"headers",
":",
"{",
"}",
",",
"query",
":",
"{",
"}",
")",
"execute",
"(",
"method",
":",
":post",
",",
"path",
":",
"path",
",",
"headers",
":",
"headers",
",",
"query",
... | Syntactical sugar for making POST requests via the API.
@see #execute | [
"Syntactical",
"sugar",
"for",
"making",
"POST",
"requests",
"via",
"the",
"API",
"."
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/http_client.rb#L107-L109 |
15,507 | nylas/nylas-ruby | lib/nylas/http_client.rb | Nylas.HttpClient.put | def put(path: nil, payload:, headers: {}, query: {})
execute(method: :put, path: path, headers: headers, query: query, payload: payload)
end | ruby | def put(path: nil, payload:, headers: {}, query: {})
execute(method: :put, path: path, headers: headers, query: query, payload: payload)
end | [
"def",
"put",
"(",
"path",
":",
"nil",
",",
"payload",
":",
",",
"headers",
":",
"{",
"}",
",",
"query",
":",
"{",
"}",
")",
"execute",
"(",
"method",
":",
":put",
",",
"path",
":",
"path",
",",
"headers",
":",
"headers",
",",
"query",
":",
"qu... | Syntactical sugar for making PUT requests via the API.
@see #execute | [
"Syntactical",
"sugar",
"for",
"making",
"PUT",
"requests",
"via",
"the",
"API",
"."
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/http_client.rb#L113-L115 |
15,508 | nylas/nylas-ruby | lib/nylas/http_client.rb | Nylas.HttpClient.delete | def delete(path: nil, payload: nil, headers: {}, query: {})
execute(method: :delete, path: path, headers: headers, query: query, payload: payload)
end | ruby | def delete(path: nil, payload: nil, headers: {}, query: {})
execute(method: :delete, path: path, headers: headers, query: query, payload: payload)
end | [
"def",
"delete",
"(",
"path",
":",
"nil",
",",
"payload",
":",
"nil",
",",
"headers",
":",
"{",
"}",
",",
"query",
":",
"{",
"}",
")",
"execute",
"(",
"method",
":",
":delete",
",",
"path",
":",
"path",
",",
"headers",
":",
"headers",
",",
"query... | Syntactical sugar for making DELETE requests via the API.
@see #execute | [
"Syntactical",
"sugar",
"for",
"making",
"DELETE",
"requests",
"via",
"the",
"API",
"."
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/http_client.rb#L119-L121 |
15,509 | nylas/nylas-ruby | lib/nylas/collection.rb | Nylas.Collection.where | def where(filters)
raise ModelNotFilterableError, model unless model.filterable?
self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
end | ruby | def where(filters)
raise ModelNotFilterableError, model unless model.filterable?
self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
end | [
"def",
"where",
"(",
"filters",
")",
"raise",
"ModelNotFilterableError",
",",
"model",
"unless",
"model",
".",
"filterable?",
"self",
".",
"class",
".",
"new",
"(",
"model",
":",
"model",
",",
"api",
":",
"api",
",",
"constraints",
":",
"constraints",
".",... | Merges in additional filters when querying the collection
@return [Collection<Model>] | [
"Merges",
"in",
"additional",
"filters",
"when",
"querying",
"the",
"collection"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/collection.rb#L30-L34 |
15,510 | nylas/nylas-ruby | lib/nylas/collection.rb | Nylas.Collection.raw | def raw
raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw?
self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type))
end | ruby | def raw
raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw?
self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type))
end | [
"def",
"raw",
"raise",
"ModelNotAvailableAsRawError",
",",
"model",
"unless",
"model",
".",
"exposable_as_raw?",
"self",
".",
"class",
".",
"new",
"(",
"model",
":",
"model",
",",
"api",
":",
"api",
",",
"constraints",
":",
"constraints",
".",
"merge",
"(",
... | The collection now returns a string representation of the model in a particular mime type instead of
Model objects
@return [Collection<String>] | [
"The",
"collection",
"now",
"returns",
"a",
"string",
"representation",
"of",
"the",
"model",
"in",
"a",
"particular",
"mime",
"type",
"instead",
"of",
"Model",
"objects"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/collection.rb#L45-L49 |
15,511 | nylas/nylas-ruby | lib/nylas/collection.rb | Nylas.Collection.each | def each
return enum_for(:each) unless block_given?
execute.each do |result|
yield(model.new(result.merge(api: api)))
end
end | ruby | def each
return enum_for(:each) unless block_given?
execute.each do |result|
yield(model.new(result.merge(api: api)))
end
end | [
"def",
"each",
"return",
"enum_for",
"(",
":each",
")",
"unless",
"block_given?",
"execute",
".",
"each",
"do",
"|",
"result",
"|",
"yield",
"(",
"model",
".",
"new",
"(",
"result",
".",
"merge",
"(",
"api",
":",
"api",
")",
")",
")",
"end",
"end"
] | Iterates over a single page of results based upon current pagination settings | [
"Iterates",
"over",
"a",
"single",
"page",
"of",
"results",
"based",
"upon",
"current",
"pagination",
"settings"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/collection.rb#L67-L73 |
15,512 | nylas/nylas-ruby | lib/nylas/collection.rb | Nylas.Collection.find_each | def find_each
return enum_for(:find_each) unless block_given?
query = self
accumulated = 0
while query
results = query.each do |instance|
yield(instance)
end
accumulated += results.length
query = query.next_page(accumulated: accumulated, current_page:... | ruby | def find_each
return enum_for(:find_each) unless block_given?
query = self
accumulated = 0
while query
results = query.each do |instance|
yield(instance)
end
accumulated += results.length
query = query.next_page(accumulated: accumulated, current_page:... | [
"def",
"find_each",
"return",
"enum_for",
"(",
":find_each",
")",
"unless",
"block_given?",
"query",
"=",
"self",
"accumulated",
"=",
"0",
"while",
"query",
"results",
"=",
"query",
".",
"each",
"do",
"|",
"instance",
"|",
"yield",
"(",
"instance",
")",
"e... | Iterates over every result that meets the filters, retrieving a page at a time | [
"Iterates",
"over",
"every",
"result",
"that",
"meets",
"the",
"filters",
"retrieving",
"a",
"page",
"at",
"a",
"time"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/collection.rb#L84-L98 |
15,513 | nylas/nylas-ruby | lib/nylas/file.rb | Nylas.File.download! | def download!
return download if file.nil?
file.close
file.unlink
self.file = nil
download
end | ruby | def download!
return download if file.nil?
file.close
file.unlink
self.file = nil
download
end | [
"def",
"download!",
"return",
"download",
"if",
"file",
".",
"nil?",
"file",
".",
"close",
"file",
".",
"unlink",
"self",
".",
"file",
"=",
"nil",
"download",
"end"
] | Redownloads a file even if it's been cached. Closes and unlinks the tempfile to help memory usage. | [
"Redownloads",
"a",
"file",
"even",
"if",
"it",
"s",
"been",
"cached",
".",
"Closes",
"and",
"unlinks",
"the",
"tempfile",
"to",
"help",
"memory",
"usage",
"."
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/file.rb#L32-L39 |
15,514 | nylas/nylas-ruby | lib/nylas/api.rb | Nylas.API.revoke | def revoke(access_token)
response = client.as(access_token).post(path: "/oauth/revoke")
response.code == 200 && response.empty?
end | ruby | def revoke(access_token)
response = client.as(access_token).post(path: "/oauth/revoke")
response.code == 200 && response.empty?
end | [
"def",
"revoke",
"(",
"access_token",
")",
"response",
"=",
"client",
".",
"as",
"(",
"access_token",
")",
".",
"post",
"(",
"path",
":",
"\"/oauth/revoke\"",
")",
"response",
".",
"code",
"==",
"200",
"&&",
"response",
".",
"empty?",
"end"
] | Revokes access to the Nylas API for the given access token
@return [Boolean] | [
"Revokes",
"access",
"to",
"the",
"Nylas",
"API",
"for",
"the",
"given",
"access",
"token"
] | 5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d | https://github.com/nylas/nylas-ruby/blob/5453cf9b2e9d80ee55e38ff5a6c8b19b8d5c262d/lib/nylas/api.rb#L97-L100 |
15,515 | Foodcritic/foodcritic | lib/foodcritic/command_line.rb | FoodCritic.CommandLine.valid_paths? | def valid_paths?
paths = options[:cookbook_paths] + options[:role_paths] +
options[:environment_paths]
paths.any? && paths.all? { |path| File.exist?(path) }
end | ruby | def valid_paths?
paths = options[:cookbook_paths] + options[:role_paths] +
options[:environment_paths]
paths.any? && paths.all? { |path| File.exist?(path) }
end | [
"def",
"valid_paths?",
"paths",
"=",
"options",
"[",
":cookbook_paths",
"]",
"+",
"options",
"[",
":role_paths",
"]",
"+",
"options",
"[",
":environment_paths",
"]",
"paths",
".",
"any?",
"&&",
"paths",
".",
"all?",
"{",
"|",
"path",
"|",
"File",
".",
"e... | If the paths provided are valid
@return [Boolean] True if the paths exist. | [
"If",
"the",
"paths",
"provided",
"are",
"valid"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/command_line.rb#L147-L151 |
15,516 | Foodcritic/foodcritic | lib/foodcritic/command_line.rb | FoodCritic.CommandLine.valid_grammar? | def valid_grammar?
return true unless options.key?(:search_grammar)
return false unless File.exist?(options[:search_grammar])
search = FoodCritic::Chef::Search.new
search.create_parser([options[:search_grammar]])
search.parser?
end | ruby | def valid_grammar?
return true unless options.key?(:search_grammar)
return false unless File.exist?(options[:search_grammar])
search = FoodCritic::Chef::Search.new
search.create_parser([options[:search_grammar]])
search.parser?
end | [
"def",
"valid_grammar?",
"return",
"true",
"unless",
"options",
".",
"key?",
"(",
":search_grammar",
")",
"return",
"false",
"unless",
"File",
".",
"exist?",
"(",
"options",
"[",
":search_grammar",
"]",
")",
"search",
"=",
"FoodCritic",
"::",
"Chef",
"::",
"... | Is the search grammar specified valid?
@return [Boolean] True if the grammar has not been provided or can be
loaded. | [
"Is",
"the",
"search",
"grammar",
"specified",
"valid?"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/command_line.rb#L157-L163 |
15,517 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.list | def list(options = {})
options = setup_defaults(options)
@options = options
load_rules
if options[:tags].any?
@rules = active_rules(options[:tags])
end
RuleList.new(@rules)
end | ruby | def list(options = {})
options = setup_defaults(options)
@options = options
load_rules
if options[:tags].any?
@rules = active_rules(options[:tags])
end
RuleList.new(@rules)
end | [
"def",
"list",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"setup_defaults",
"(",
"options",
")",
"@options",
"=",
"options",
"load_rules",
"if",
"options",
"[",
":tags",
"]",
".",
"any?",
"@rules",
"=",
"active_rules",
"(",
"options",
"[",
":tag... | List the rules that are currently in effect.
The `options` are a hash where the valid keys are:
* `:include_rules` - Paths to additional rules to apply
* `:search_gems - If true then search for custom rules in installed gems.
* `:tags` - The tags to filter rules based on | [
"List",
"the",
"rules",
"that",
"are",
"currently",
"in",
"effect",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L42-L52 |
15,518 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.check | def check(options = {})
options = setup_defaults(options)
@options = options
@chef_version = options[:chef_version] || DEFAULT_CHEF_VERSION
warnings = []; last_dir = nil; matched_rule_tags = Set.new
load_rules
paths = specified_paths!(options)
# Loop through each file to be p... | ruby | def check(options = {})
options = setup_defaults(options)
@options = options
@chef_version = options[:chef_version] || DEFAULT_CHEF_VERSION
warnings = []; last_dir = nil; matched_rule_tags = Set.new
load_rules
paths = specified_paths!(options)
# Loop through each file to be p... | [
"def",
"check",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"setup_defaults",
"(",
"options",
")",
"@options",
"=",
"options",
"@chef_version",
"=",
"options",
"[",
":chef_version",
"]",
"||",
"DEFAULT_CHEF_VERSION",
"warnings",
"=",
"[",
"]",
";",
... | Review the cookbooks at the provided path, identifying potential
improvements.
The `options` are a hash where the valid keys are:
* `:cookbook_paths` - Cookbook paths to lint
* `:role_paths` - Role paths to lint
* `:include_rules` - Paths to additional rules to apply
* `:search_gems - If true then search for cu... | [
"Review",
"the",
"cookbooks",
"at",
"the",
"provided",
"path",
"identifying",
"potential",
"improvements",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L67-L128 |
15,519 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.applies_to_version? | def applies_to_version?(rule, version)
return true unless version
rule.applies_to.yield(Gem::Version.create(version))
end | ruby | def applies_to_version?(rule, version)
return true unless version
rule.applies_to.yield(Gem::Version.create(version))
end | [
"def",
"applies_to_version?",
"(",
"rule",
",",
"version",
")",
"return",
"true",
"unless",
"version",
"rule",
".",
"applies_to",
".",
"yield",
"(",
"Gem",
"::",
"Version",
".",
"create",
"(",
"version",
")",
")",
"end"
] | Some rules are version specific. | [
"Some",
"rules",
"are",
"version",
"specific",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L197-L200 |
15,520 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.rule_file_tags | def rule_file_tags(file)
cookbook = cookbook_dir(file)
@tag_cache ||= {}
# lookup the tags in the cache has and return that if we find something
cb_tags = @tag_cache[cookbook]
return cb_tags unless cb_tags.nil?
# if a rule file has been specified use that. Otherwise use the .foodcr... | ruby | def rule_file_tags(file)
cookbook = cookbook_dir(file)
@tag_cache ||= {}
# lookup the tags in the cache has and return that if we find something
cb_tags = @tag_cache[cookbook]
return cb_tags unless cb_tags.nil?
# if a rule file has been specified use that. Otherwise use the .foodcr... | [
"def",
"rule_file_tags",
"(",
"file",
")",
"cookbook",
"=",
"cookbook_dir",
"(",
"file",
")",
"@tag_cache",
"||=",
"{",
"}",
"# lookup the tags in the cache has and return that if we find something",
"cb_tags",
"=",
"@tag_cache",
"[",
"cookbook",
"]",
"return",
"cb_tags... | given a file in the cookbook lookup all the applicable tag rules defined in rule
files. The rule file is either that specified via CLI or the .foodcritic file
in the cookbook. We cache this information at the cookbook level to prevent looking
up the same thing dozens of times
@param [String] file in the cookbook
... | [
"given",
"a",
"file",
"in",
"the",
"cookbook",
"lookup",
"all",
"the",
"applicable",
"tag",
"rules",
"defined",
"in",
"rule",
"files",
".",
"The",
"rule",
"file",
"is",
"either",
"that",
"specified",
"via",
"CLI",
"or",
"the",
".",
"foodcritic",
"file",
... | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L209-L227 |
15,521 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.parse_rule_file | def parse_rule_file(file)
tags = []
begin
tag_text = File.read file
tags = tag_text.split(/\s/)
rescue
raise "ERROR: Could not read or parse the specified rule file at #{file}"
end
tags
end | ruby | def parse_rule_file(file)
tags = []
begin
tag_text = File.read file
tags = tag_text.split(/\s/)
rescue
raise "ERROR: Could not read or parse the specified rule file at #{file}"
end
tags
end | [
"def",
"parse_rule_file",
"(",
"file",
")",
"tags",
"=",
"[",
"]",
"begin",
"tag_text",
"=",
"File",
".",
"read",
"file",
"tags",
"=",
"tag_text",
".",
"split",
"(",
"/",
"\\s",
"/",
")",
"rescue",
"raise",
"\"ERROR: Could not read or parse the specified rule ... | given a filename parse any tag rules in that file
@param [String] rule file path
@return [Array] array of tag rules from the file | [
"given",
"a",
"filename",
"parse",
"any",
"tag",
"rules",
"in",
"that",
"file"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L233-L242 |
15,522 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.cookbook_dir | def cookbook_dir(file)
@dir_cache ||= {}
abs_file = File.absolute_path(file)
# lookup the file in the cache has and return that if we find something
cook_val = @dir_cache[abs_file]
return cook_val unless cook_val.nil?
if file =~ /\.erb$/
# split each directory into an item ... | ruby | def cookbook_dir(file)
@dir_cache ||= {}
abs_file = File.absolute_path(file)
# lookup the file in the cache has and return that if we find something
cook_val = @dir_cache[abs_file]
return cook_val unless cook_val.nil?
if file =~ /\.erb$/
# split each directory into an item ... | [
"def",
"cookbook_dir",
"(",
"file",
")",
"@dir_cache",
"||=",
"{",
"}",
"abs_file",
"=",
"File",
".",
"absolute_path",
"(",
"file",
")",
"# lookup the file in the cache has and return that if we find something",
"cook_val",
"=",
"@dir_cache",
"[",
"abs_file",
"]",
"re... | provides the path to the cookbook from a file within the cookbook
we cache this data in a hash because this method gets called often
for the same files.
@param [String] file - a file path in the cookbook
@return [String] the path to the cookbook | [
"provides",
"the",
"path",
"to",
"the",
"cookbook",
"from",
"a",
"file",
"within",
"the",
"cookbook",
"we",
"cache",
"this",
"data",
"in",
"a",
"hash",
"because",
"this",
"method",
"gets",
"called",
"often",
"for",
"the",
"same",
"files",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L256-L290 |
15,523 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.files_to_process | def files_to_process(paths)
paths.reject { |type, _| type == :exclude }.map do |path_type, dirs|
dirs.map do |dir|
exclusions = []
unless paths[:exclude].empty?
exclusions = Dir.glob(paths[:exclude].map do |p|
File.join(dir, p, "**/**")
end)
... | ruby | def files_to_process(paths)
paths.reject { |type, _| type == :exclude }.map do |path_type, dirs|
dirs.map do |dir|
exclusions = []
unless paths[:exclude].empty?
exclusions = Dir.glob(paths[:exclude].map do |p|
File.join(dir, p, "**/**")
end)
... | [
"def",
"files_to_process",
"(",
"paths",
")",
"paths",
".",
"reject",
"{",
"|",
"type",
",",
"_",
"|",
"type",
"==",
":exclude",
"}",
".",
"map",
"do",
"|",
"path_type",
",",
"dirs",
"|",
"dirs",
".",
"map",
"do",
"|",
"dir",
"|",
"exclusions",
"="... | Return the files within a cookbook tree that we are interested in trying to match rules against.
@param [Hash] paths - paths of interest: {:exclude=>[], :cookbook=>[], :role=>[], :environment=>[]}
@return [Array] array of hashes for each file {:filename=>"./metadata.rb", :path_type=>:cookbook} | [
"Return",
"the",
"files",
"within",
"a",
"cookbook",
"tree",
"that",
"we",
"are",
"interested",
"in",
"trying",
"to",
"match",
"rules",
"against",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L311-L339 |
15,524 | Foodcritic/foodcritic | lib/foodcritic/linter.rb | FoodCritic.Linter.matches | def matches(match_method, *params)
return [] unless match_method.respond_to?(:yield)
matches = match_method.yield(*params)
return [] unless matches.respond_to?(:each)
# We convert Nokogiri nodes to matches transparently
matches.map do |m|
if m.respond_to?(:node_name)
mat... | ruby | def matches(match_method, *params)
return [] unless match_method.respond_to?(:yield)
matches = match_method.yield(*params)
return [] unless matches.respond_to?(:each)
# We convert Nokogiri nodes to matches transparently
matches.map do |m|
if m.respond_to?(:node_name)
mat... | [
"def",
"matches",
"(",
"match_method",
",",
"*",
"params",
")",
"return",
"[",
"]",
"unless",
"match_method",
".",
"respond_to?",
"(",
":yield",
")",
"matches",
"=",
"match_method",
".",
"yield",
"(",
"params",
")",
"return",
"[",
"]",
"unless",
"matches",... | Invoke the DSL method with the provided parameters. | [
"Invoke",
"the",
"DSL",
"method",
"with",
"the",
"provided",
"parameters",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/linter.rb#L342-L357 |
15,525 | Foodcritic/foodcritic | lib/foodcritic/chef.rb | FoodCritic.Chef.valid_query? | def valid_query?(query)
raise ArgumentError, "Query cannot be nil or empty" if query.to_s.empty?
# Attempt to create a search query parser
search = FoodCritic::Chef::Search.new
search.create_parser(search.chef_search_grammars)
if search.parser?
search.parser.parse(query.to_s)
... | ruby | def valid_query?(query)
raise ArgumentError, "Query cannot be nil or empty" if query.to_s.empty?
# Attempt to create a search query parser
search = FoodCritic::Chef::Search.new
search.create_parser(search.chef_search_grammars)
if search.parser?
search.parser.parse(query.to_s)
... | [
"def",
"valid_query?",
"(",
"query",
")",
"raise",
"ArgumentError",
",",
"\"Query cannot be nil or empty\"",
"if",
"query",
".",
"to_s",
".",
"empty?",
"# Attempt to create a search query parser",
"search",
"=",
"FoodCritic",
"::",
"Chef",
"::",
"Search",
".",
"new",
... | Is this a valid Lucene query? | [
"Is",
"this",
"a",
"valid",
"Lucene",
"query?"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/chef.rb#L25-L39 |
15,526 | Foodcritic/foodcritic | lib/foodcritic/chef.rb | FoodCritic.Chef.load_metadata | def load_metadata
version = if respond_to?(:chef_version)
chef_version
else
Linter::DEFAULT_CHEF_VERSION
end
metadata_path = [version, version.sub(/\.[a-z].*/, ""),
Linter::DEFAULT_CHEF_VERSION].map do |ver|
metadata_path(... | ruby | def load_metadata
version = if respond_to?(:chef_version)
chef_version
else
Linter::DEFAULT_CHEF_VERSION
end
metadata_path = [version, version.sub(/\.[a-z].*/, ""),
Linter::DEFAULT_CHEF_VERSION].map do |ver|
metadata_path(... | [
"def",
"load_metadata",
"version",
"=",
"if",
"respond_to?",
"(",
":chef_version",
")",
"chef_version",
"else",
"Linter",
"::",
"DEFAULT_CHEF_VERSION",
"end",
"metadata_path",
"=",
"[",
"version",
",",
"version",
".",
"sub",
"(",
"/",
"\\.",
"/",
",",
"\"\"",
... | To avoid the runtime hit of loading the Chef gem and its dependencies
we load the DSL metadata from a JSON file shipped with our gem.
The DSL metadata doesn't necessarily reflect the version of Chef in the
local user gemset. | [
"To",
"avoid",
"the",
"runtime",
"hit",
"of",
"loading",
"the",
"Chef",
"gem",
"and",
"its",
"dependencies",
"we",
"load",
"the",
"DSL",
"metadata",
"from",
"a",
"JSON",
"file",
"shipped",
"with",
"our",
"gem",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/chef.rb#L48-L60 |
15,527 | Foodcritic/foodcritic | lib/foodcritic/output.rb | FoodCritic.ContextOutput.output | def output(review)
unless review.respond_to?(:warnings)
puts review; return
end
context = 3
print_fn = lambda { |fn| ansi_print(fn, :red, nil, :bold) }
print_rule = lambda { |warn| ansi_print(warn, :cyan, nil, :bold) }
print_line = lambda { |line| ansi_print(line, nil, :red... | ruby | def output(review)
unless review.respond_to?(:warnings)
puts review; return
end
context = 3
print_fn = lambda { |fn| ansi_print(fn, :red, nil, :bold) }
print_rule = lambda { |warn| ansi_print(warn, :cyan, nil, :bold) }
print_line = lambda { |line| ansi_print(line, nil, :red... | [
"def",
"output",
"(",
"review",
")",
"unless",
"review",
".",
"respond_to?",
"(",
":warnings",
")",
"puts",
"review",
";",
"return",
"end",
"context",
"=",
"3",
"print_fn",
"=",
"lambda",
"{",
"|",
"fn",
"|",
"ansi_print",
"(",
"fn",
",",
":red",
",",
... | Output the review showing matching lines with context.
@param [Review] review The review to output. | [
"Output",
"the",
"review",
"showing",
"matching",
"lines",
"with",
"context",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/output.rb#L34-L88 |
15,528 | Foodcritic/foodcritic | lib/foodcritic/output.rb | FoodCritic.ContextOutput.key_by_file_and_line | def key_by_file_and_line(review)
warn_hash = {}
review.warnings.each do |warning|
filename = Pathname.new(warning.match[:filename]).cleanpath.to_s
line_num = warning.match[:line].to_i
warn_hash[filename] = {} unless warn_hash.key?(filename)
unless warn_hash[filename].key?(lin... | ruby | def key_by_file_and_line(review)
warn_hash = {}
review.warnings.each do |warning|
filename = Pathname.new(warning.match[:filename]).cleanpath.to_s
line_num = warning.match[:line].to_i
warn_hash[filename] = {} unless warn_hash.key?(filename)
unless warn_hash[filename].key?(lin... | [
"def",
"key_by_file_and_line",
"(",
"review",
")",
"warn_hash",
"=",
"{",
"}",
"review",
".",
"warnings",
".",
"each",
"do",
"|",
"warning",
"|",
"filename",
"=",
"Pathname",
".",
"new",
"(",
"warning",
".",
"match",
"[",
":filename",
"]",
")",
".",
"c... | Build a hash lookup by filename and line number for warnings found in the
specified review.
@param [Review] review The review to convert.
@return [Hash] Nested hashes keyed by filename and line number. | [
"Build",
"a",
"hash",
"lookup",
"by",
"filename",
"and",
"line",
"number",
"for",
"warnings",
"found",
"in",
"the",
"specified",
"review",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/output.rb#L97-L109 |
15,529 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.ensure_file_exists | def ensure_file_exists(basepath, filepath)
path = File.join(basepath, filepath)
[file_match(path)] unless File.exist?(path)
end | ruby | def ensure_file_exists(basepath, filepath)
path = File.join(basepath, filepath)
[file_match(path)] unless File.exist?(path)
end | [
"def",
"ensure_file_exists",
"(",
"basepath",
",",
"filepath",
")",
"path",
"=",
"File",
".",
"join",
"(",
"basepath",
",",
"filepath",
")",
"[",
"file_match",
"(",
"path",
")",
"]",
"unless",
"File",
".",
"exist?",
"(",
"path",
")",
"end"
] | Match unless a file exists using the basepath of the cookbook and the filepath
@author Joseph Holsten - joseph@josephholsten.com
@since 10.3
@param basepath [String] base path of the cookbook
@param filepath [String] path to the file within the cookbook
@return [String] the absolute path to the base of the cookbo... | [
"Match",
"unless",
"a",
"file",
"exists",
"using",
"the",
"basepath",
"of",
"the",
"cookbook",
"and",
"the",
"filepath"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L22-L25 |
15,530 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.attribute_access | def attribute_access(ast, options = {})
options = { type: :any, ignore_calls: false }.merge!(options)
return [] unless ast.respond_to?(:xpath)
unless [:any, :string, :symbol, :vivified].include?(options[:type])
raise ArgumentError, "Node type not recognised"
end
case options[:typ... | ruby | def attribute_access(ast, options = {})
options = { type: :any, ignore_calls: false }.merge!(options)
return [] unless ast.respond_to?(:xpath)
unless [:any, :string, :symbol, :vivified].include?(options[:type])
raise ArgumentError, "Node type not recognised"
end
case options[:typ... | [
"def",
"attribute_access",
"(",
"ast",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"type",
":",
":any",
",",
"ignore_calls",
":",
"false",
"}",
".",
"merge!",
"(",
"options",
")",
"return",
"[",
"]",
"unless",
"ast",
".",
"respond_to?",
... | Find attribute access by type. | [
"Find",
"attribute",
"access",
"by",
"type",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L28-L45 |
15,531 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.cookbook_base_path | def cookbook_base_path(file)
file = File.expand_path(file) # make sure we get an absolute path
file = File.dirname(file) unless File.directory?(file) # get the dir only
# get list of items in the dir and intersect with metadata array.
# until we get an interfact (we have a metadata) walk up the... | ruby | def cookbook_base_path(file)
file = File.expand_path(file) # make sure we get an absolute path
file = File.dirname(file) unless File.directory?(file) # get the dir only
# get list of items in the dir and intersect with metadata array.
# until we get an interfact (we have a metadata) walk up the... | [
"def",
"cookbook_base_path",
"(",
"file",
")",
"file",
"=",
"File",
".",
"expand_path",
"(",
"file",
")",
"# make sure we get an absolute path",
"file",
"=",
"File",
".",
"dirname",
"(",
"file",
")",
"unless",
"File",
".",
"directory?",
"(",
"file",
")",
"# ... | The absolute path of a cookbook from the specified file.
@author Tim Smith - tsmith@chef.io
@since 10.1
@param file [String, Pathname] relative or absolute path to a file in the cookbook
@return [String] the absolute path to the base of the cookbook | [
"The",
"absolute",
"path",
"of",
"a",
"cookbook",
"from",
"the",
"specified",
"file",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L53-L64 |
15,532 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.metadata_field | def metadata_field(file, field)
until (file.split(File::SEPARATOR) & standard_cookbook_subdirs).empty?
file = File.absolute_path(File.dirname(file.to_s))
end
file = File.dirname(file) unless File.extname(file).empty?
md_path = File.join(file, "metadata.rb")
if File.exist?(md_path)... | ruby | def metadata_field(file, field)
until (file.split(File::SEPARATOR) & standard_cookbook_subdirs).empty?
file = File.absolute_path(File.dirname(file.to_s))
end
file = File.dirname(file) unless File.extname(file).empty?
md_path = File.join(file, "metadata.rb")
if File.exist?(md_path)... | [
"def",
"metadata_field",
"(",
"file",
",",
"field",
")",
"until",
"(",
"file",
".",
"split",
"(",
"File",
"::",
"SEPARATOR",
")",
"&",
"standard_cookbook_subdirs",
")",
".",
"empty?",
"file",
"=",
"File",
".",
"absolute_path",
"(",
"File",
".",
"dirname",
... | Retrieves a value of a metadata field.
@author Miguel Fonseca
@since 7.0.0
@return [String] the value of the metadata field | [
"Retrieves",
"a",
"value",
"of",
"a",
"metadata",
"field",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L71-L87 |
15,533 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.cookbook_name | def cookbook_name(file)
raise ArgumentError, "File cannot be nil or empty" if file.to_s.empty?
# Name is a special case as we want to fallback to the cookbook directory
# name if metadata_field fails
begin
metadata_field(file, "name")
rescue RuntimeError
until (file.split(... | ruby | def cookbook_name(file)
raise ArgumentError, "File cannot be nil or empty" if file.to_s.empty?
# Name is a special case as we want to fallback to the cookbook directory
# name if metadata_field fails
begin
metadata_field(file, "name")
rescue RuntimeError
until (file.split(... | [
"def",
"cookbook_name",
"(",
"file",
")",
"raise",
"ArgumentError",
",",
"\"File cannot be nil or empty\"",
"if",
"file",
".",
"to_s",
".",
"empty?",
"# Name is a special case as we want to fallback to the cookbook directory",
"# name if metadata_field fails",
"begin",
"metadata_... | The name of the cookbook containing the specified file.
@param file [String] file within a cookbook
@return [String] name of the cookbook | [
"The",
"name",
"of",
"the",
"cookbook",
"containing",
"the",
"specified",
"file",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L93-L107 |
15,534 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.declared_dependencies | def declared_dependencies(ast)
raise_unless_xpath!(ast)
deps = []
# String literals.
#
# depends 'foo'
deps += field(ast, "depends").xpath("descendant::args_add/descendant::tstring_content[1]")
# Quoted word arrays are also common.
#
# %w{foo bar baz}.each... | ruby | def declared_dependencies(ast)
raise_unless_xpath!(ast)
deps = []
# String literals.
#
# depends 'foo'
deps += field(ast, "depends").xpath("descendant::args_add/descendant::tstring_content[1]")
# Quoted word arrays are also common.
#
# %w{foo bar baz}.each... | [
"def",
"declared_dependencies",
"(",
"ast",
")",
"raise_unless_xpath!",
"(",
"ast",
")",
"deps",
"=",
"[",
"]",
"# String literals.",
"#",
"# depends 'foo'",
"deps",
"+=",
"field",
"(",
"ast",
",",
"\"depends\"",
")",
".",
"xpath",
"(",
"\"descendant::args_a... | The dependencies declared in cookbook metadata. | [
"The",
"dependencies",
"declared",
"in",
"cookbook",
"metadata",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L130-L148 |
15,535 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.field | def field(ast, field_name)
if field_name.nil? || field_name.to_s.empty?
raise ArgumentError, "Field name cannot be nil or empty"
end
ast.xpath("(.//command[ident/@value='#{field_name}']|.//fcall[ident/@value='#{field_name}']/..)")
end | ruby | def field(ast, field_name)
if field_name.nil? || field_name.to_s.empty?
raise ArgumentError, "Field name cannot be nil or empty"
end
ast.xpath("(.//command[ident/@value='#{field_name}']|.//fcall[ident/@value='#{field_name}']/..)")
end | [
"def",
"field",
"(",
"ast",
",",
"field_name",
")",
"if",
"field_name",
".",
"nil?",
"||",
"field_name",
".",
"to_s",
".",
"empty?",
"raise",
"ArgumentError",
",",
"\"Field name cannot be nil or empty\"",
"end",
"ast",
".",
"xpath",
"(",
"\"(.//command[ident/@valu... | Look for a method call with a given name.
@param ast [Nokogiri::XML::Node] Document to search under
@param field_name [String] Method name to search for
@return [Nokogiri::XML::NodeSet] | [
"Look",
"for",
"a",
"method",
"call",
"with",
"a",
"given",
"name",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L155-L160 |
15,536 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.field_value | def field_value(ast, field_name)
field(ast, field_name).xpath('.//args_add_block//tstring_content
[count(ancestor::args_add) = 1][count(ancestor::string_add) = 1]
/@value').map { |a| a.to_s }.last
end | ruby | def field_value(ast, field_name)
field(ast, field_name).xpath('.//args_add_block//tstring_content
[count(ancestor::args_add) = 1][count(ancestor::string_add) = 1]
/@value').map { |a| a.to_s }.last
end | [
"def",
"field_value",
"(",
"ast",
",",
"field_name",
")",
"field",
"(",
"ast",
",",
"field_name",
")",
".",
"xpath",
"(",
"'.//args_add_block//tstring_content\n [count(ancestor::args_add) = 1][count(ancestor::string_add) = 1]\n /@value'",
")",
".",
"map",
"{",
... | The value for a specific key in an environment or role ruby file | [
"The",
"value",
"for",
"a",
"specific",
"key",
"in",
"an",
"environment",
"or",
"role",
"ruby",
"file"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L163-L167 |
15,537 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.file_match | def file_match(file)
raise ArgumentError, "Filename cannot be nil" if file.nil?
{ filename: file, matched: file, line: 1, column: 1 }
end | ruby | def file_match(file)
raise ArgumentError, "Filename cannot be nil" if file.nil?
{ filename: file, matched: file, line: 1, column: 1 }
end | [
"def",
"file_match",
"(",
"file",
")",
"raise",
"ArgumentError",
",",
"\"Filename cannot be nil\"",
"if",
"file",
".",
"nil?",
"{",
"filename",
":",
"file",
",",
"matched",
":",
"file",
",",
"line",
":",
"1",
",",
"column",
":",
"1",
"}",
"end"
] | Create a match for a specified file. Use this if the presence of the file
triggers the warning rather than content. | [
"Create",
"a",
"match",
"for",
"a",
"specified",
"file",
".",
"Use",
"this",
"if",
"the",
"presence",
"of",
"the",
"file",
"triggers",
"the",
"warning",
"rather",
"than",
"content",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L171-L174 |
15,538 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.included_recipes | def included_recipes(ast, options = { with_partial_names: true })
raise_unless_xpath!(ast)
filter = ["[count(descendant::args_add) = 1]"]
# If `:with_partial_names` is false then we won't include the string
# literal portions of any string that has an embedded expression.
unless options[... | ruby | def included_recipes(ast, options = { with_partial_names: true })
raise_unless_xpath!(ast)
filter = ["[count(descendant::args_add) = 1]"]
# If `:with_partial_names` is false then we won't include the string
# literal portions of any string that has an embedded expression.
unless options[... | [
"def",
"included_recipes",
"(",
"ast",
",",
"options",
"=",
"{",
"with_partial_names",
":",
"true",
"}",
")",
"raise_unless_xpath!",
"(",
"ast",
")",
"filter",
"=",
"[",
"\"[count(descendant::args_add) = 1]\"",
"]",
"# If `:with_partial_names` is false then we won't inclu... | Retrieve the recipes that are included within the given recipe AST.
These two usages are equivalent:
included_recipes(ast)
included_recipes(ast, :with_partial_names => true) | [
"Retrieve",
"the",
"recipes",
"that",
"are",
"included",
"within",
"the",
"given",
"recipe",
"AST",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L215-L238 |
15,539 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.match | def match(node)
raise_unless_xpath!(node)
pos = node.xpath("descendant::pos").first
return nil if pos.nil?
{ matched: node.respond_to?(:name) ? node.name : "",
line: pos["line"].to_i, column: pos["column"].to_i }
end | ruby | def match(node)
raise_unless_xpath!(node)
pos = node.xpath("descendant::pos").first
return nil if pos.nil?
{ matched: node.respond_to?(:name) ? node.name : "",
line: pos["line"].to_i, column: pos["column"].to_i }
end | [
"def",
"match",
"(",
"node",
")",
"raise_unless_xpath!",
"(",
"node",
")",
"pos",
"=",
"node",
".",
"xpath",
"(",
"\"descendant::pos\"",
")",
".",
"first",
"return",
"nil",
"if",
"pos",
".",
"nil?",
"{",
"matched",
":",
"node",
".",
"respond_to?",
"(",
... | Create a match from the specified node. | [
"Create",
"a",
"match",
"from",
"the",
"specified",
"node",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L249-L255 |
15,540 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.read_ast | def read_ast(file)
@ast_cache ||= Rufus::Lru::Hash.new(5)
if @ast_cache.include?(file)
@ast_cache[file]
else
@ast_cache[file] = uncached_read_ast(file)
end
end | ruby | def read_ast(file)
@ast_cache ||= Rufus::Lru::Hash.new(5)
if @ast_cache.include?(file)
@ast_cache[file]
else
@ast_cache[file] = uncached_read_ast(file)
end
end | [
"def",
"read_ast",
"(",
"file",
")",
"@ast_cache",
"||=",
"Rufus",
"::",
"Lru",
"::",
"Hash",
".",
"new",
"(",
"5",
")",
"if",
"@ast_cache",
".",
"include?",
"(",
"file",
")",
"@ast_cache",
"[",
"file",
"]",
"else",
"@ast_cache",
"[",
"file",
"]",
"=... | Read the AST for the given Ruby source file | [
"Read",
"the",
"AST",
"for",
"the",
"given",
"Ruby",
"source",
"file"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L258-L265 |
15,541 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.resource_attribute | def resource_attribute(resource, name)
raise ArgumentError, "Attribute name cannot be empty" if name.empty?
resource_attributes(resource)[name.to_s]
end | ruby | def resource_attribute(resource, name)
raise ArgumentError, "Attribute name cannot be empty" if name.empty?
resource_attributes(resource)[name.to_s]
end | [
"def",
"resource_attribute",
"(",
"resource",
",",
"name",
")",
"raise",
"ArgumentError",
",",
"\"Attribute name cannot be empty\"",
"if",
"name",
".",
"empty?",
"resource_attributes",
"(",
"resource",
")",
"[",
"name",
".",
"to_s",
"]",
"end"
] | Retrieve a single-valued attribute from the specified resource. | [
"Retrieve",
"a",
"single",
"-",
"valued",
"attribute",
"from",
"the",
"specified",
"resource",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L268-L271 |
15,542 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.resource_attributes | def resource_attributes(resource, options = {})
atts = {}
name = resource_name(resource, options)
atts[:name] = name unless name.empty?
atts.merge!(normal_attributes(resource, options))
atts.merge!(block_attributes(resource))
atts
end | ruby | def resource_attributes(resource, options = {})
atts = {}
name = resource_name(resource, options)
atts[:name] = name unless name.empty?
atts.merge!(normal_attributes(resource, options))
atts.merge!(block_attributes(resource))
atts
end | [
"def",
"resource_attributes",
"(",
"resource",
",",
"options",
"=",
"{",
"}",
")",
"atts",
"=",
"{",
"}",
"name",
"=",
"resource_name",
"(",
"resource",
",",
"options",
")",
"atts",
"[",
":name",
"]",
"=",
"name",
"unless",
"name",
".",
"empty?",
"atts... | Retrieve all attributes from the specified resource. | [
"Retrieve",
"all",
"attributes",
"from",
"the",
"specified",
"resource",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L274-L281 |
15,543 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.resource_attributes_by_type | def resource_attributes_by_type(ast)
result = {}
resources_by_type(ast).each do |type, resources|
result[type] = resources.map do |resource|
resource_attributes(resource)
end
end
result
end | ruby | def resource_attributes_by_type(ast)
result = {}
resources_by_type(ast).each do |type, resources|
result[type] = resources.map do |resource|
resource_attributes(resource)
end
end
result
end | [
"def",
"resource_attributes_by_type",
"(",
"ast",
")",
"result",
"=",
"{",
"}",
"resources_by_type",
"(",
"ast",
")",
".",
"each",
"do",
"|",
"type",
",",
"resources",
"|",
"result",
"[",
"type",
"]",
"=",
"resources",
".",
"map",
"do",
"|",
"resource",
... | Resources keyed by type, with an array of matching nodes for each. | [
"Resources",
"keyed",
"by",
"type",
"with",
"an",
"array",
"of",
"matching",
"nodes",
"for",
"each",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L284-L292 |
15,544 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.resource_name | def resource_name(resource, options = {})
raise_unless_xpath!(resource)
options = { return_expressions: false }.merge(options)
if options[:return_expressions]
name = resource.xpath("command/args_add_block")
if name.xpath("descendant::string_add").size == 1 &&
name.xpath("de... | ruby | def resource_name(resource, options = {})
raise_unless_xpath!(resource)
options = { return_expressions: false }.merge(options)
if options[:return_expressions]
name = resource.xpath("command/args_add_block")
if name.xpath("descendant::string_add").size == 1 &&
name.xpath("de... | [
"def",
"resource_name",
"(",
"resource",
",",
"options",
"=",
"{",
"}",
")",
"raise_unless_xpath!",
"(",
"resource",
")",
"options",
"=",
"{",
"return_expressions",
":",
"false",
"}",
".",
"merge",
"(",
"options",
")",
"if",
"options",
"[",
":return_expressi... | Retrieve the name attribute associated with the specified resource. | [
"Retrieve",
"the",
"name",
"attribute",
"associated",
"with",
"the",
"specified",
"resource",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L295-L312 |
15,545 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.resources_by_type | def resources_by_type(ast)
raise_unless_xpath!(ast)
result = Hash.new { |hash, key| hash[key] = Array.new }
find_resources(ast).each do |resource|
result[resource_type(resource)] << resource
end
result
end | ruby | def resources_by_type(ast)
raise_unless_xpath!(ast)
result = Hash.new { |hash, key| hash[key] = Array.new }
find_resources(ast).each do |resource|
result[resource_type(resource)] << resource
end
result
end | [
"def",
"resources_by_type",
"(",
"ast",
")",
"raise_unless_xpath!",
"(",
"ast",
")",
"result",
"=",
"Hash",
".",
"new",
"{",
"|",
"hash",
",",
"key",
"|",
"hash",
"[",
"key",
"]",
"=",
"Array",
".",
"new",
"}",
"find_resources",
"(",
"ast",
")",
".",... | Resources in an AST, keyed by type. | [
"Resources",
"in",
"an",
"AST",
"keyed",
"by",
"type",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L315-L322 |
15,546 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.ruby_code? | def ruby_code?(str)
str = str.to_s
return false if str.empty?
checker = FoodCritic::ErrorChecker.new(str)
checker.parse
!checker.error?
end | ruby | def ruby_code?(str)
str = str.to_s
return false if str.empty?
checker = FoodCritic::ErrorChecker.new(str)
checker.parse
!checker.error?
end | [
"def",
"ruby_code?",
"(",
"str",
")",
"str",
"=",
"str",
".",
"to_s",
"return",
"false",
"if",
"str",
".",
"empty?",
"checker",
"=",
"FoodCritic",
"::",
"ErrorChecker",
".",
"new",
"(",
"str",
")",
"checker",
".",
"parse",
"!",
"checker",
".",
"error?"... | Does the provided string look like ruby code? | [
"Does",
"the",
"provided",
"string",
"look",
"like",
"ruby",
"code?"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L335-L342 |
15,547 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.supported_platforms | def supported_platforms(ast)
# Find the supports() method call.
platforms_ast = field(ast, "supports")
# Look for the first argument (the node next to the top args_new) and
# filter out anything with a string_embexpr since that can't be parsed
# statically. Then grab the static value for b... | ruby | def supported_platforms(ast)
# Find the supports() method call.
platforms_ast = field(ast, "supports")
# Look for the first argument (the node next to the top args_new) and
# filter out anything with a string_embexpr since that can't be parsed
# statically. Then grab the static value for b... | [
"def",
"supported_platforms",
"(",
"ast",
")",
"# Find the supports() method call.",
"platforms_ast",
"=",
"field",
"(",
"ast",
",",
"\"supports\"",
")",
"# Look for the first argument (the node next to the top args_new) and",
"# filter out anything with a string_embexpr since that can... | Platforms declared as supported in cookbook metadata. Returns an array
of hashes containing the name and version constraints for each platform.
@param ast [Nokogiri::XML::Node] Document to search from.
@return [Array<Hash>] | [
"Platforms",
"declared",
"as",
"supported",
"in",
"cookbook",
"metadata",
".",
"Returns",
"an",
"array",
"of",
"hashes",
"containing",
"the",
"name",
"and",
"version",
"constraints",
"for",
"each",
"platform",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L364-L378 |
15,548 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.template_paths | def template_paths(recipe_path)
Dir.glob(Pathname.new(recipe_path).dirname.dirname + "templates" +
"**/*", File::FNM_DOTMATCH).select do |path|
File.file?(path)
end.reject do |path|
File.basename(path) == ".DS_Store" || File.extname(path) == ".swp"
end
end | ruby | def template_paths(recipe_path)
Dir.glob(Pathname.new(recipe_path).dirname.dirname + "templates" +
"**/*", File::FNM_DOTMATCH).select do |path|
File.file?(path)
end.reject do |path|
File.basename(path) == ".DS_Store" || File.extname(path) == ".swp"
end
end | [
"def",
"template_paths",
"(",
"recipe_path",
")",
"Dir",
".",
"glob",
"(",
"Pathname",
".",
"new",
"(",
"recipe_path",
")",
".",
"dirname",
".",
"dirname",
"+",
"\"templates\"",
"+",
"\"**/*\"",
",",
"File",
"::",
"FNM_DOTMATCH",
")",
".",
"select",
"do",
... | Templates in the current cookbook | [
"Templates",
"in",
"the",
"current",
"cookbook"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L410-L417 |
15,549 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.json_file_to_hash | def json_file_to_hash(filename)
raise "File #{filename} not found" unless File.exist?(filename)
file = File.read(filename)
begin
FFI_Yajl::Parser.parse(file)
rescue FFI_Yajl::ParseError
raise "File #{filename} does not appear to contain valid JSON"
end
end | ruby | def json_file_to_hash(filename)
raise "File #{filename} not found" unless File.exist?(filename)
file = File.read(filename)
begin
FFI_Yajl::Parser.parse(file)
rescue FFI_Yajl::ParseError
raise "File #{filename} does not appear to contain valid JSON"
end
end | [
"def",
"json_file_to_hash",
"(",
"filename",
")",
"raise",
"\"File #{filename} not found\"",
"unless",
"File",
".",
"exist?",
"(",
"filename",
")",
"file",
"=",
"File",
".",
"read",
"(",
"filename",
")",
"begin",
"FFI_Yajl",
"::",
"Parser",
".",
"parse",
"(",
... | Give a filename path it returns the hash of the JSON contents
@author Tim Smith - tsmith@chef.io
@since 11.0
@param filename [String] path to a file in JSON format
@return [Hash] hash of JSON content | [
"Give",
"a",
"filename",
"path",
"it",
"returns",
"the",
"hash",
"of",
"the",
"JSON",
"contents"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L425-L434 |
15,550 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.build_xml | def build_xml(node, doc = nil, xml_node = nil)
doc, xml_node = xml_document(doc, xml_node)
if node.respond_to?(:each)
node.each do |child|
if position_node?(child)
xml_position_node(doc, xml_node, child)
else
if ast_node_has_children?(child)
... | ruby | def build_xml(node, doc = nil, xml_node = nil)
doc, xml_node = xml_document(doc, xml_node)
if node.respond_to?(:each)
node.each do |child|
if position_node?(child)
xml_position_node(doc, xml_node, child)
else
if ast_node_has_children?(child)
... | [
"def",
"build_xml",
"(",
"node",
",",
"doc",
"=",
"nil",
",",
"xml_node",
"=",
"nil",
")",
"doc",
",",
"xml_node",
"=",
"xml_document",
"(",
"doc",
",",
"xml_node",
")",
"if",
"node",
".",
"respond_to?",
"(",
":each",
")",
"node",
".",
"each",
"do",
... | Recurse the nested arrays provided by Ripper to create a tree we can more
easily apply expressions to. | [
"Recurse",
"the",
"nested",
"arrays",
"provided",
"by",
"Ripper",
"to",
"create",
"a",
"tree",
"we",
"can",
"more",
"easily",
"apply",
"expressions",
"to",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L458-L481 |
15,551 | Foodcritic/foodcritic | lib/foodcritic/api.rb | FoodCritic.Api.node_method? | def node_method?(meth, cookbook_dir)
chef_dsl_methods.include?(meth) || meth == :set || meth == :set_unless ||
patched_node_method?(meth, cookbook_dir)
end | ruby | def node_method?(meth, cookbook_dir)
chef_dsl_methods.include?(meth) || meth == :set || meth == :set_unless ||
patched_node_method?(meth, cookbook_dir)
end | [
"def",
"node_method?",
"(",
"meth",
",",
"cookbook_dir",
")",
"chef_dsl_methods",
".",
"include?",
"(",
"meth",
")",
"||",
"meth",
"==",
":set",
"||",
"meth",
"==",
":set_unless",
"||",
"patched_node_method?",
"(",
"meth",
",",
"cookbook_dir",
")",
"end"
] | check to see if the passed method is a node method
we generally look this up from the chef DSL data we have
but we specifically check for 'set' and 'set_unless' since
those exist in cookbooks, but are not longer part of chef 14+
this prevents false positives in FC019 anytime node.set is found | [
"check",
"to",
"see",
"if",
"the",
"passed",
"method",
"is",
"a",
"node",
"method",
"we",
"generally",
"look",
"this",
"up",
"from",
"the",
"chef",
"DSL",
"data",
"we",
"have",
"but",
"we",
"specifically",
"check",
"for",
"set",
"and",
"set_unless",
"sin... | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/api.rb#L519-L522 |
15,552 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.CommandHelpers.expect_warning | def expect_warning(code, options = {})
if options.has_key?(:file_type)
options[:file] = { :attributes => "attributes/default.rb", :definition => "definitions/apache_site.rb",
:metadata => "metadata.rb", :provider => "providers/site.rb",
:resource => "r... | ruby | def expect_warning(code, options = {})
if options.has_key?(:file_type)
options[:file] = { :attributes => "attributes/default.rb", :definition => "definitions/apache_site.rb",
:metadata => "metadata.rb", :provider => "providers/site.rb",
:resource => "r... | [
"def",
"expect_warning",
"(",
"code",
",",
"options",
"=",
"{",
"}",
")",
"if",
"options",
".",
"has_key?",
"(",
":file_type",
")",
"options",
"[",
":file",
"]",
"=",
"{",
":attributes",
"=>",
"\"attributes/default.rb\"",
",",
":definition",
"=>",
"\"definit... | Expect a warning to be included in the command output.
@param [String] code The warning code to check for.
@param [Hash] options The warning options.
@option options [Integer] :line The line number the warning should appear on - nil for any line.
@option options [Boolean] :expect_warning If false then assert that ... | [
"Expect",
"a",
"warning",
"to",
"be",
"included",
"in",
"the",
"command",
"output",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L115-L132 |
15,553 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.CommandHelpers.usage_displayed | def usage_displayed(is_exit_zero)
expect_output "foodcritic [cookbook_paths]"
usage_options.each do |option|
expect_usage_option(option[:short], option[:long], option[:description])
end
if is_exit_zero
assert_no_error_occurred
else
assert_error_occurred
end
... | ruby | def usage_displayed(is_exit_zero)
expect_output "foodcritic [cookbook_paths]"
usage_options.each do |option|
expect_usage_option(option[:short], option[:long], option[:description])
end
if is_exit_zero
assert_no_error_occurred
else
assert_error_occurred
end
... | [
"def",
"usage_displayed",
"(",
"is_exit_zero",
")",
"expect_output",
"\"foodcritic [cookbook_paths]\"",
"usage_options",
".",
"each",
"do",
"|",
"option",
"|",
"expect_usage_option",
"(",
"option",
"[",
":short",
"]",
",",
"option",
"[",
":long",
"]",
",",
"option... | Assert that the usage message is displayed.
@param [Boolean] is_exit_zero The exit code to check for. | [
"Assert",
"that",
"the",
"usage",
"message",
"is",
"displayed",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L173-L185 |
15,554 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.InProcessHelpers.run_lint | def run_lint(cmd_args)
cd "." do
show_context = cmd_args.include?("-C")
review, @status = FoodCritic::Linter.run(CommandLine.new(cmd_args))
@review =
if review.nil? || (review.respond_to?(:warnings) && review.warnings.empty?)
""
elsif show_context
... | ruby | def run_lint(cmd_args)
cd "." do
show_context = cmd_args.include?("-C")
review, @status = FoodCritic::Linter.run(CommandLine.new(cmd_args))
@review =
if review.nil? || (review.respond_to?(:warnings) && review.warnings.empty?)
""
elsif show_context
... | [
"def",
"run_lint",
"(",
"cmd_args",
")",
"cd",
"\".\"",
"do",
"show_context",
"=",
"cmd_args",
".",
"include?",
"(",
"\"-C\"",
")",
"review",
",",
"@status",
"=",
"FoodCritic",
"::",
"Linter",
".",
"run",
"(",
"CommandLine",
".",
"new",
"(",
"cmd_args",
... | Run a lint check with the provided command line arguments.
@param [Array] cmd_args The command line arguments. | [
"Run",
"a",
"lint",
"check",
"with",
"the",
"provided",
"command",
"line",
"arguments",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L287-L300 |
15,555 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.BuildHelpers.assert_build_result | def assert_build_result(success, warnings)
success ? assert_no_error_occurred : assert_error_occurred
warnings.each do |code|
expect_warning(code, :warning_only => true)
end
end | ruby | def assert_build_result(success, warnings)
success ? assert_no_error_occurred : assert_error_occurred
warnings.each do |code|
expect_warning(code, :warning_only => true)
end
end | [
"def",
"assert_build_result",
"(",
"success",
",",
"warnings",
")",
"success",
"?",
"assert_no_error_occurred",
":",
"assert_error_occurred",
"warnings",
".",
"each",
"do",
"|",
"code",
"|",
"expect_warning",
"(",
"code",
",",
":warning_only",
"=>",
"true",
")",
... | Assert the build outcome
@param [Boolean] success True if the build should succeed
@param [Array] warnings The warnings expected | [
"Assert",
"the",
"build",
"outcome"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L312-L317 |
15,556 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.BuildHelpers.build_tasks | def build_tasks
all_output.split("\n").map do |task|
next unless task.start_with? "rake"
task.split("#").map { |t| t.strip.sub(/^rake /, "") }
end.compact
end | ruby | def build_tasks
all_output.split("\n").map do |task|
next unless task.start_with? "rake"
task.split("#").map { |t| t.strip.sub(/^rake /, "") }
end.compact
end | [
"def",
"build_tasks",
"all_output",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"do",
"|",
"task",
"|",
"next",
"unless",
"task",
".",
"start_with?",
"\"rake\"",
"task",
".",
"split",
"(",
"\"#\"",
")",
".",
"map",
"{",
"|",
"t",
"|",
"t",
".",
... | The available tasks for this build
@return [Array] Task name and description | [
"The",
"available",
"tasks",
"for",
"this",
"build"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L334-L339 |
15,557 | Foodcritic/foodcritic | features/support/command_helpers.rb | FoodCritic.ArubaHelpers.expect_output | def expect_output(output)
if output.respond_to?(:~)
assert_matching_output(output.to_s, all_output)
else
assert_partial_output(output, all_output)
end
end | ruby | def expect_output(output)
if output.respond_to?(:~)
assert_matching_output(output.to_s, all_output)
else
assert_partial_output(output, all_output)
end
end | [
"def",
"expect_output",
"(",
"output",
")",
"if",
"output",
".",
"respond_to?",
"(",
":~",
")",
"assert_matching_output",
"(",
"output",
".",
"to_s",
",",
"all_output",
")",
"else",
"assert_partial_output",
"(",
"output",
",",
"all_output",
")",
"end",
"end"
] | Assert that the output contains the specified warning.
@param [String] output The output to check for. | [
"Assert",
"that",
"the",
"output",
"contains",
"the",
"specified",
"warning",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/command_helpers.rb#L374-L380 |
15,558 | Foodcritic/foodcritic | lib/foodcritic/notifications.rb | FoodCritic.Notifications.notifications | def notifications(ast)
# Sanity check the AST provided.
return [] unless ast.respond_to?(:xpath)
# We are mapping each `notifies` or `subscribes` line in the provided
# AST to a Hash with the extracted details.
notification_nodes(ast).map do |notify|
# Chef supports two styles of... | ruby | def notifications(ast)
# Sanity check the AST provided.
return [] unless ast.respond_to?(:xpath)
# We are mapping each `notifies` or `subscribes` line in the provided
# AST to a Hash with the extracted details.
notification_nodes(ast).map do |notify|
# Chef supports two styles of... | [
"def",
"notifications",
"(",
"ast",
")",
"# Sanity check the AST provided.",
"return",
"[",
"]",
"unless",
"ast",
".",
"respond_to?",
"(",
":xpath",
")",
"# We are mapping each `notifies` or `subscribes` line in the provided",
"# AST to a Hash with the extracted details.",
"notif... | Extracts notification details from the provided AST, returning an
array of notification hashes.
template "/etc/www/configures-apache.conf" do
notifies :restart, "service[apache]"
end
=> [{:resource_name=>"apache",
:resource_type=>:service,
:type=>:notifies,
:style=>:new,
... | [
"Extracts",
"notification",
"details",
"from",
"the",
"provided",
"AST",
"returning",
"an",
"array",
"of",
"notification",
"hashes",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/notifications.rb#L20-L58 |
15,559 | Foodcritic/foodcritic | lib/foodcritic/notifications.rb | FoodCritic.Notifications.notification_action | def notification_action(notify)
is_variable = true unless notify.xpath("args_add_block/args_add//args_add[aref or vcall or call or var_ref]").empty?
string_val = notify.xpath("descendant::args_add/string_literal/string_add/tstring_content/@value").first
symbol_val = notify.xpath('descendant::args_add/... | ruby | def notification_action(notify)
is_variable = true unless notify.xpath("args_add_block/args_add//args_add[aref or vcall or call or var_ref]").empty?
string_val = notify.xpath("descendant::args_add/string_literal/string_add/tstring_content/@value").first
symbol_val = notify.xpath('descendant::args_add/... | [
"def",
"notification_action",
"(",
"notify",
")",
"is_variable",
"=",
"true",
"unless",
"notify",
".",
"xpath",
"(",
"\"args_add_block/args_add//args_add[aref or vcall or call or var_ref]\"",
")",
".",
"empty?",
"string_val",
"=",
"notify",
".",
"xpath",
"(",
"\"descend... | return the notification action as either a symbol or string or nil if it's a variable.
Yes you can notify an action as a string but it's wrong and we want to return it as
a string so we can tell people not to do that. | [
"return",
"the",
"notification",
"action",
"as",
"either",
"a",
"symbol",
"or",
"string",
"or",
"nil",
"if",
"it",
"s",
"a",
"variable",
".",
"Yes",
"you",
"can",
"notify",
"an",
"action",
"as",
"a",
"string",
"but",
"it",
"s",
"wrong",
"and",
"we",
... | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/notifications.rb#L132-L144 |
15,560 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.cookbook_that_matches_rules | def cookbook_that_matches_rules(codes)
recipe = ""
codes.each do |code|
if code == "FC002"
recipe += %q{
directory "#{node['base_dir']}" do
action :create
end
}
elsif code == "FC004"
recipe += %q{
execute "stop-j... | ruby | def cookbook_that_matches_rules(codes)
recipe = ""
codes.each do |code|
if code == "FC002"
recipe += %q{
directory "#{node['base_dir']}" do
action :create
end
}
elsif code == "FC004"
recipe += %q{
execute "stop-j... | [
"def",
"cookbook_that_matches_rules",
"(",
"codes",
")",
"recipe",
"=",
"\"\"",
"codes",
".",
"each",
"do",
"|",
"code",
"|",
"if",
"code",
"==",
"\"FC002\"",
"recipe",
"+=",
"%q{\n directory \"#{node['base_dir']}\" do\n action :create\n e... | Create a cookbook that will match the specified rules.
@param [Array] codes The codes to match. Only FC002, FC004 and FC005 and FC006 are supported. | [
"Create",
"a",
"cookbook",
"that",
"will",
"match",
"the",
"specified",
"rules",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L47-L95 |
15,561 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.cookbook_with_lwrp | def cookbook_with_lwrp(lwrp)
lwrp = { :default_action => false, :notifies => :does_not_notify,
:use_inline_resources => false }.merge!(lwrp)
ruby_default_action = %q{
def initialize(*args)
super
@action = :create
end
}.strip
write_resource("site... | ruby | def cookbook_with_lwrp(lwrp)
lwrp = { :default_action => false, :notifies => :does_not_notify,
:use_inline_resources => false }.merge!(lwrp)
ruby_default_action = %q{
def initialize(*args)
super
@action = :create
end
}.strip
write_resource("site... | [
"def",
"cookbook_with_lwrp",
"(",
"lwrp",
")",
"lwrp",
"=",
"{",
":default_action",
"=>",
"false",
",",
":notifies",
"=>",
":does_not_notify",
",",
":use_inline_resources",
"=>",
"false",
"}",
".",
"merge!",
"(",
"lwrp",
")",
"ruby_default_action",
"=",
"%q{\n ... | Create a cookbook with a LRWP
@param [Hash] lwrp The options to use for the created LWRP
@option lwrp [Symbol] :default_action One of :no_default_action, :ruby_default_action, :dsl_default_action
@option lwrp [Symbol] :notifies One of :does_not_notify, :does_notify, :does_notify_without_parens, :deprecated_syntax, ... | [
"Create",
"a",
"cookbook",
"with",
"a",
"LRWP"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L124-L150 |
15,562 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.cookbook_with_maintainer | def cookbook_with_maintainer(name, email)
write_recipe %q{
#
# Cookbook Name:: example
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
}
fields = {}
fields["maintainer"] = na... | ruby | def cookbook_with_maintainer(name, email)
write_recipe %q{
#
# Cookbook Name:: example
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
}
fields = {}
fields["maintainer"] = na... | [
"def",
"cookbook_with_maintainer",
"(",
"name",
",",
"email",
")",
"write_recipe",
"%q{\n #\n # Cookbook Name:: example\n # Recipe:: default\n #\n # Copyright 2011, YOUR_COMPANY_NAME\n #\n # All rights reserved - Do Not Redistribute\n #\n ... | Create an cookbook with the maintainer specified in the metadata
@param [String] name The maintainer name
@param [String] email The maintainer email address | [
"Create",
"an",
"cookbook",
"with",
"the",
"maintainer",
"specified",
"in",
"the",
"metadata"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L164-L186 |
15,563 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.rakefile | def rakefile(task, options)
rakefile_content = "task :default => []"
task_def = case task
when :no_block then "FoodCritic::Rake::LintTask.new"
else %Q{
FoodCritic::Rake::LintTask.new do |t|
#{"t.name = '#{options[:name]}'" if options[:name]}
#{"t.files = #{o... | ruby | def rakefile(task, options)
rakefile_content = "task :default => []"
task_def = case task
when :no_block then "FoodCritic::Rake::LintTask.new"
else %Q{
FoodCritic::Rake::LintTask.new do |t|
#{"t.name = '#{options[:name]}'" if options[:name]}
#{"t.files = #{o... | [
"def",
"rakefile",
"(",
"task",
",",
"options",
")",
"rakefile_content",
"=",
"\"task :default => []\"",
"task_def",
"=",
"case",
"task",
"when",
":no_block",
"then",
"\"FoodCritic::Rake::LintTask.new\"",
"else",
"%Q{\n FoodCritic::Rake::LintTask.new do |t|\n ... | Create a Rakefile that uses the linter rake task
@param [Symbol] task Type of task
@param [Hash] options Task options
@option options [String] :name Task name
@option options [String] :files Files to process
@option options [String] :options The options to set on the rake task | [
"Create",
"a",
"Rakefile",
"that",
"uses",
"the",
"linter",
"rake",
"task"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L242-L262 |
15,564 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.recipe_installs_gem | def recipe_installs_gem(type, action = :install)
case type
when :simple
write_recipe %Q{
gem_package "bluepill" do
action :#{action}
end
}.strip
when :compile_time
write_recipe %Q{
r = gem_package "mysql" do
... | ruby | def recipe_installs_gem(type, action = :install)
case type
when :simple
write_recipe %Q{
gem_package "bluepill" do
action :#{action}
end
}.strip
when :compile_time
write_recipe %Q{
r = gem_package "mysql" do
... | [
"def",
"recipe_installs_gem",
"(",
"type",
",",
"action",
"=",
":install",
")",
"case",
"type",
"when",
":simple",
"write_recipe",
"%Q{\n gem_package \"bluepill\" do\n action :#{action}\n end\n }",
".",
"strip",
"when",
":compile_time"... | Install a gem using the specified approach.
@param [Symbol] type The type of approach, one of :simple, :compile_time,
:compile_time_from_array, :compile_time_from_word_list
@param [Symbol] action Either :install or :upgrade | [
"Install",
"a",
"gem",
"using",
"the",
"specified",
"approach",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L284-L322 |
15,565 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.recipe_with_dependency | def recipe_with_dependency(dep)
dep = { :is_scoped => true, :is_declared => true,
:parentheses => false }.merge!(dep)
recipe = "foo#{dep[:is_scoped] ? '::default' : ''}"
write_recipe(if dep[:parentheses]
"include_recipe('#{recipe}')"
else
... | ruby | def recipe_with_dependency(dep)
dep = { :is_scoped => true, :is_declared => true,
:parentheses => false }.merge!(dep)
recipe = "foo#{dep[:is_scoped] ? '::default' : ''}"
write_recipe(if dep[:parentheses]
"include_recipe('#{recipe}')"
else
... | [
"def",
"recipe_with_dependency",
"(",
"dep",
")",
"dep",
"=",
"{",
":is_scoped",
"=>",
"true",
",",
":is_declared",
"=>",
"true",
",",
":parentheses",
"=>",
"false",
"}",
".",
"merge!",
"(",
"dep",
")",
"recipe",
"=",
"\"foo#{dep[:is_scoped] ? '::default' : ''}\... | Create a recipe with an external dependency on another cookbook.
@param [Hash] dep The options to use for dependency
@option dep [Boolean] :is_declared True if this dependency has been declared in the cookbook metadata
@option dep [Boolean] :is_scoped True if the include_recipe references a specific recipe or the c... | [
"Create",
"a",
"recipe",
"with",
"an",
"external",
"dependency",
"on",
"another",
"cookbook",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L348-L361 |
15,566 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.recipe_with_ruby_block | def recipe_with_ruby_block(length)
recipe = ""
if length == :short || length == :both
recipe << %q{
ruby_block "subexpressions" do
block do
rc = Chef::Util::FileEdit.new("/foo/bar.conf")
rc.search_file_replace_line(/^search/, "search #{node["foo"]["bar"]} compute-... | ruby | def recipe_with_ruby_block(length)
recipe = ""
if length == :short || length == :both
recipe << %q{
ruby_block "subexpressions" do
block do
rc = Chef::Util::FileEdit.new("/foo/bar.conf")
rc.search_file_replace_line(/^search/, "search #{node["foo"]["bar"]} compute-... | [
"def",
"recipe_with_ruby_block",
"(",
"length",
")",
"recipe",
"=",
"\"\"",
"if",
"length",
"==",
":short",
"||",
"length",
"==",
":both",
"recipe",
"<<",
"%q{\n ruby_block \"subexpressions\" do\n\t block do\n\t rc = Chef::Util::FileEdit.new(\"/foo/bar.conf\")\n ... | Create a recipe with a ruby_block resource.
@param [Symbol] length A :short or :long block, or :both | [
"Create",
"a",
"recipe",
"with",
"a",
"ruby_block",
"resource",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L396-L441 |
15,567 | Foodcritic/foodcritic | features/support/cookbook_helpers.rb | FoodCritic.CookbookHelpers.role | def role(options = {})
options = { :format => :ruby, :dir => "roles" }.merge(options)
content = if options[:format] == :json
%Q{
{
"chef_type": "role",
"json_class": "Chef::Role",
#{Array(options[:role_na... | ruby | def role(options = {})
options = { :format => :ruby, :dir => "roles" }.merge(options)
content = if options[:format] == :json
%Q{
{
"chef_type": "role",
"json_class": "Chef::Role",
#{Array(options[:role_na... | [
"def",
"role",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
":format",
"=>",
":ruby",
",",
":dir",
"=>",
"\"roles\"",
"}",
".",
"merge",
"(",
"options",
")",
"content",
"=",
"if",
"options",
"[",
":format",
"]",
"==",
":json",
"%Q{\n ... | Create a role file
@param [Hash] options The options to use for the role
@option options [String] :role_name The name of the role declared in the role file
@option options [String] :file_name The containing file relative to the roles directory
@option options [Symbol] :format Either :ruby or :json. Default is :rub... | [
"Create",
"a",
"role",
"file"
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/features/support/cookbook_helpers.rb#L462-L482 |
15,568 | Foodcritic/foodcritic | lib/foodcritic/domain.rb | FoodCritic.Review.to_s | def to_s
# Sorted by filename and line number.
#
# FC123: My rule name: foo/recipes/default.rb
@warnings.map do |w|
["#{w.rule.code}: #{w.rule.name}: #{w.match[:filename]}",
w.match[:line].to_i]
end.sort do |x, y|
x.first == y.first ? x[1] <=> y[1] : x.first <=... | ruby | def to_s
# Sorted by filename and line number.
#
# FC123: My rule name: foo/recipes/default.rb
@warnings.map do |w|
["#{w.rule.code}: #{w.rule.name}: #{w.match[:filename]}",
w.match[:line].to_i]
end.sort do |x, y|
x.first == y.first ? x[1] <=> y[1] : x.first <=... | [
"def",
"to_s",
"# Sorted by filename and line number.",
"#",
"# FC123: My rule name: foo/recipes/default.rb",
"@warnings",
".",
"map",
"do",
"|",
"w",
"|",
"[",
"\"#{w.rule.code}: #{w.rule.name}: #{w.match[:filename]}\"",
",",
"w",
".",
"match",
"[",
":line",
"]",
".",
... | Returns a string representation of this review. This representation is
liable to change. | [
"Returns",
"a",
"string",
"representation",
"of",
"this",
"review",
".",
"This",
"representation",
"is",
"liable",
"to",
"change",
"."
] | f06e354833c75caa91a800e0f9343ece5185a737 | https://github.com/Foodcritic/foodcritic/blob/f06e354833c75caa91a800e0f9343ece5185a737/lib/foodcritic/domain.rb#L63-L73 |
15,569 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.get_artifact | def get_artifact(job_name,filename)
@artifact = job.find_artifact(job_name)
response = make_http_request(Net::HTTP::Get.new(@artifact))
if response.code == "200"
File.write(File.expand_path(filename), response.body)
else
raise "Couldn't get the artifact"
end
end | ruby | def get_artifact(job_name,filename)
@artifact = job.find_artifact(job_name)
response = make_http_request(Net::HTTP::Get.new(@artifact))
if response.code == "200"
File.write(File.expand_path(filename), response.body)
else
raise "Couldn't get the artifact"
end
end | [
"def",
"get_artifact",
"(",
"job_name",
",",
"filename",
")",
"@artifact",
"=",
"job",
".",
"find_artifact",
"(",
"job_name",
")",
"response",
"=",
"make_http_request",
"(",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"@artifact",
")",
")",
"if",
... | Connects to the server and downloads artifacts to a specified location
@param [String] job_name
@param [String] filename location to save artifact | [
"Connects",
"to",
"the",
"server",
"and",
"downloads",
"artifacts",
"to",
"a",
"specified",
"location"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L286-L294 |
15,570 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.get_artifacts | def get_artifacts(job_name, dldir, build_number = nil)
@artifacts = job.find_artifacts(job_name,build_number)
results = []
@artifacts.each do |artifact|
uri = URI.parse(artifact)
http = Net::HTTP.new(uri.host, uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.... | ruby | def get_artifacts(job_name, dldir, build_number = nil)
@artifacts = job.find_artifacts(job_name,build_number)
results = []
@artifacts.each do |artifact|
uri = URI.parse(artifact)
http = Net::HTTP.new(uri.host, uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.... | [
"def",
"get_artifacts",
"(",
"job_name",
",",
"dldir",
",",
"build_number",
"=",
"nil",
")",
"@artifacts",
"=",
"job",
".",
"find_artifacts",
"(",
"job_name",
",",
"build_number",
")",
"results",
"=",
"[",
"]",
"@artifacts",
".",
"each",
"do",
"|",
"artifa... | Connects to the server and download all artifacts of a build to a specified location
@param [String] job_name
@param [String] dldir location to save artifacts
@param [Integer] build_number optional, defaults to current build
@returns [String, Array] list of retrieved artifacts | [
"Connects",
"to",
"the",
"server",
"and",
"download",
"all",
"artifacts",
"of",
"a",
"build",
"to",
"a",
"specified",
"location"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L303-L329 |
15,571 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.make_http_request | def make_http_request(request, follow_redirect = @follow_redirects)
request.basic_auth @username, @password if @username
request['Cookie'] = @cookies if @cookies
if @proxy_ip
case @proxy_protocol
when 'http'
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @se... | ruby | def make_http_request(request, follow_redirect = @follow_redirects)
request.basic_auth @username, @password if @username
request['Cookie'] = @cookies if @cookies
if @proxy_ip
case @proxy_protocol
when 'http'
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @se... | [
"def",
"make_http_request",
"(",
"request",
",",
"follow_redirect",
"=",
"@follow_redirects",
")",
"request",
".",
"basic_auth",
"@username",
",",
"@password",
"if",
"@username",
"request",
"[",
"'Cookie'",
"]",
"=",
"@cookies",
"if",
"@cookies",
"if",
"@proxy_ip"... | Connects to the Jenkins server, sends the specified request and returns
the response.
@param [Net::HTTPRequest] request The request object to send
@param [Boolean] follow_redirect whether to follow redirects or not
@return [Net::HTTPResponse] Response from Jenkins | [
"Connects",
"to",
"the",
"Jenkins",
"server",
"sends",
"the",
"specified",
"request",
"and",
"returns",
"the",
"response",
"."
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L339-L390 |
15,572 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.api_get_request | def api_get_request(url_prefix, tree = nil, url_suffix ="/api/json",
raw_response = false)
url_prefix = "#{@jenkins_path}#{url_prefix}"
to_get = ""
if tree
to_get = "#{url_prefix}#{url_suffix}?#{tree}"
else
to_get = "#{url_prefix}#{url_suffix}"
end
... | ruby | def api_get_request(url_prefix, tree = nil, url_suffix ="/api/json",
raw_response = false)
url_prefix = "#{@jenkins_path}#{url_prefix}"
to_get = ""
if tree
to_get = "#{url_prefix}#{url_suffix}?#{tree}"
else
to_get = "#{url_prefix}#{url_suffix}"
end
... | [
"def",
"api_get_request",
"(",
"url_prefix",
",",
"tree",
"=",
"nil",
",",
"url_suffix",
"=",
"\"/api/json\"",
",",
"raw_response",
"=",
"false",
")",
"url_prefix",
"=",
"\"#{@jenkins_path}#{url_prefix}\"",
"to_get",
"=",
"\"\"",
"if",
"tree",
"to_get",
"=",
"\"... | Sends a GET request to the Jenkins CI server with the specified URL
@param [String] url_prefix The prefix to use in the URL
@param [String] tree A specific JSON tree to optimize the API call
@param [String] url_suffix The suffix to be used in the URL
@param [Boolean] raw_response Return complete Response object in... | [
"Sends",
"a",
"GET",
"request",
"to",
"the",
"Jenkins",
"CI",
"server",
"with",
"the",
"specified",
"URL"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L414-L431 |
15,573 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.api_post_request | def api_post_request(url_prefix, form_data = {}, raw_response = false)
retries = @crumb_max_retries
begin
refresh_crumbs
# Added form_data default {} instead of nil to help with proxies
# that barf with empty post
request = Net::HTTP::Post.new("#{@jenkins_path}#{url_prefix}"... | ruby | def api_post_request(url_prefix, form_data = {}, raw_response = false)
retries = @crumb_max_retries
begin
refresh_crumbs
# Added form_data default {} instead of nil to help with proxies
# that barf with empty post
request = Net::HTTP::Post.new("#{@jenkins_path}#{url_prefix}"... | [
"def",
"api_post_request",
"(",
"url_prefix",
",",
"form_data",
"=",
"{",
"}",
",",
"raw_response",
"=",
"false",
")",
"retries",
"=",
"@crumb_max_retries",
"begin",
"refresh_crumbs",
"# Added form_data default {} instead of nil to help with proxies",
"# that barf with empty ... | Sends a POST message to the Jenkins CI server with the specified URL
@param [String] url_prefix The prefix to be used in the URL
@param [Hash] form_data Form data to send with POST request
@param [Boolean] raw_response Return complete Response object instead of
JSON body of response
@return [String] Response c... | [
"Sends",
"a",
"POST",
"message",
"to",
"the",
"Jenkins",
"CI",
"server",
"with",
"the",
"specified",
"URL"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L442-L478 |
15,574 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.get_config | def get_config(url_prefix)
request = Net::HTTP::Get.new("#{@jenkins_path}#{url_prefix}/config.xml")
@logger.debug "GET #{url_prefix}/config.xml"
response = make_http_request(request)
handle_exception(response, "body")
end | ruby | def get_config(url_prefix)
request = Net::HTTP::Get.new("#{@jenkins_path}#{url_prefix}/config.xml")
@logger.debug "GET #{url_prefix}/config.xml"
response = make_http_request(request)
handle_exception(response, "body")
end | [
"def",
"get_config",
"(",
"url_prefix",
")",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"\"#{@jenkins_path}#{url_prefix}/config.xml\"",
")",
"@logger",
".",
"debug",
"\"GET #{url_prefix}/config.xml\"",
"response",
"=",
"make_http_request",
"(",... | Obtains the configuration of a component from the Jenkins CI server
@param [String] url_prefix The prefix to be used in the URL
@return [String] XML configuration obtained from Jenkins | [
"Obtains",
"the",
"configuration",
"of",
"a",
"component",
"from",
"the",
"Jenkins",
"CI",
"server"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L486-L491 |
15,575 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.exec_cli | def exec_cli(command, args = [])
base_dir = File.dirname(__FILE__)
server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
... | ruby | def exec_cli(command, args = [])
base_dir = File.dirname(__FILE__)
server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
... | [
"def",
"exec_cli",
"(",
"command",
",",
"args",
"=",
"[",
"]",
")",
"base_dir",
"=",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"server_url",
"=",
"\"http://#{@server_ip}:#{@server_port}/#{@jenkins_path}\"",
"cmd",
"=",
"\"java -jar #{base_dir}/../../java_deps/jenkin... | Execute the Jenkins CLI
@param command [String] command name
@param args [Array] the arguments for the command
@return [String] command output from the CLI
@raise [Exceptions::CLIException] if there are issues in running the
commands using CLI | [
"Execute",
"the",
"Jenkins",
"CLI"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L669-L693 |
15,576 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.symbolize_keys | def symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
else value
end
result[new_key] = new_value
... | ruby | def symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
else value
end
result[new_key] = new_value
... | [
"def",
"symbolize_keys",
"(",
"hash",
")",
"hash",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"result",
",",
"(",
"key",
",",
"value",
")",
"|",
"new_key",
"=",
"case",
"key",
"when",
"String",
"then",
"key",
".",
"to_sym",
"else",
"key",
"end",
... | Private method. Converts keys passed in as strings into symbols.
@param hash [Hash] Hash containing arguments to login to jenkins. | [
"Private",
"method",
".",
"Converts",
"keys",
"passed",
"in",
"as",
"strings",
"into",
"symbols",
"."
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L763-L776 |
15,577 | arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.handle_exception | def handle_exception(response, to_send = "code", send_json = false)
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
@logger.debug msg
case response.code.to_i
# As of Jenkins version 1.519, the job builds return a 201 status code
# with a Location HTTP header with the p... | ruby | def handle_exception(response, to_send = "code", send_json = false)
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
@logger.debug msg
case response.code.to_i
# As of Jenkins version 1.519, the job builds return a 201 status code
# with a Location HTTP header with the p... | [
"def",
"handle_exception",
"(",
"response",
",",
"to_send",
"=",
"\"code\"",
",",
"send_json",
"=",
"false",
")",
"msg",
"=",
"\"HTTP Code: #{response.code}, Response Body: #{response.body}\"",
"@logger",
".",
"debug",
"msg",
"case",
"response",
".",
"code",
".",
"t... | Private method that handles the exception and raises with proper error
message with the type of exception and returns the required values if no
exceptions are raised.
@param [Net::HTTP::Response] response Response from Jenkins
@param [String] to_send What should be returned as a response. Allowed
values: "code"... | [
"Private",
"method",
"that",
"handles",
"the",
"exception",
"and",
"raises",
"with",
"proper",
"error",
"message",
"with",
"the",
"type",
"of",
"exception",
"and",
"returns",
"the",
"required",
"values",
"if",
"no",
"exceptions",
"are",
"raised",
"."
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L800-L852 |
15,578 | bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.add_tab | def add_tab(name, value)
return if name.nil?
if value.is_a? Hash
meta_data[name] ||= {}
meta_data[name].merge! value
else
meta_data["custom"] = {} unless meta_data["custom"]
meta_data["custom"][name.to_s] = value
end
end | ruby | def add_tab(name, value)
return if name.nil?
if value.is_a? Hash
meta_data[name] ||= {}
meta_data[name].merge! value
else
meta_data["custom"] = {} unless meta_data["custom"]
meta_data["custom"][name.to_s] = value
end
end | [
"def",
"add_tab",
"(",
"name",
",",
"value",
")",
"return",
"if",
"name",
".",
"nil?",
"if",
"value",
".",
"is_a?",
"Hash",
"meta_data",
"[",
"name",
"]",
"||=",
"{",
"}",
"meta_data",
"[",
"name",
"]",
".",
"merge!",
"value",
"else",
"meta_data",
"[... | Initializes a new report from an exception.
Add a new metadata tab to this notification. | [
"Initializes",
"a",
"new",
"report",
"from",
"an",
"exception",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L67-L78 |
15,579 | bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.as_json | def as_json
# Build the payload's exception event
payload_event = {
app: {
version: app_version,
releaseStage: release_stage,
type: app_type
},
context: context,
device: {
hostname: hostname
},
exceptions: exceptions,
... | ruby | def as_json
# Build the payload's exception event
payload_event = {
app: {
version: app_version,
releaseStage: release_stage,
type: app_type
},
context: context,
device: {
hostname: hostname
},
exceptions: exceptions,
... | [
"def",
"as_json",
"# Build the payload's exception event",
"payload_event",
"=",
"{",
"app",
":",
"{",
"version",
":",
"app_version",
",",
"releaseStage",
":",
"release_stage",
",",
"type",
":",
"app_type",
"}",
",",
"context",
":",
"context",
",",
"device",
":"... | Builds and returns the exception payload for this notification. | [
"Builds",
"and",
"returns",
"the",
"exception",
"payload",
"for",
"this",
"notification",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L90-L135 |
15,580 | bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.summary | def summary
# Guard against the exceptions array being removed/changed or emptied here
if exceptions.respond_to?(:first) && exceptions.first
{
:error_class => exceptions.first[:errorClass],
:message => exceptions.first[:message],
:severity => severity
}
el... | ruby | def summary
# Guard against the exceptions array being removed/changed or emptied here
if exceptions.respond_to?(:first) && exceptions.first
{
:error_class => exceptions.first[:errorClass],
:message => exceptions.first[:message],
:severity => severity
}
el... | [
"def",
"summary",
"# Guard against the exceptions array being removed/changed or emptied here",
"if",
"exceptions",
".",
"respond_to?",
"(",
":first",
")",
"&&",
"exceptions",
".",
"first",
"{",
":error_class",
"=>",
"exceptions",
".",
"first",
"[",
":errorClass",
"]",
... | Generates a summary to be attached as a breadcrumb
@return [Hash] a Hash containing the report's error class, error message, and severity | [
"Generates",
"a",
"summary",
"to",
"be",
"attached",
"as",
"a",
"breadcrumb"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L169-L183 |
15,581 | bugsnag/bugsnag-ruby | lib/bugsnag/breadcrumbs/validator.rb | Bugsnag::Breadcrumbs.Validator.valid_meta_data_type? | def valid_meta_data_type?(value)
value.nil? || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
end | ruby | def valid_meta_data_type?(value)
value.nil? || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
end | [
"def",
"valid_meta_data_type?",
"(",
"value",
")",
"value",
".",
"nil?",
"||",
"value",
".",
"is_a?",
"(",
"String",
")",
"||",
"value",
".",
"is_a?",
"(",
"Numeric",
")",
"||",
"value",
".",
"is_a?",
"(",
"FalseClass",
")",
"||",
"value",
".",
"is_a?"... | Tests whether the meta_data types are non-complex objects.
Acceptable types are String, Numeric, TrueClass, FalseClass, and nil.
@param value [Object] the object to be type checked | [
"Tests",
"whether",
"the",
"meta_data",
"types",
"are",
"non",
"-",
"complex",
"objects",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/breadcrumbs/validator.rb#L55-L57 |
15,582 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/rack.rb | Bugsnag.Rack.call | def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.configuration.set_request_data(:rack_env, env)
if Bugsnag.configuration.auto_capture_sessions
Bugsnag.start_session
end
begin
response = @app.call(env)
rescue Exception => raised
# Not... | ruby | def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.configuration.set_request_data(:rack_env, env)
if Bugsnag.configuration.auto_capture_sessions
Bugsnag.start_session
end
begin
response = @app.call(env)
rescue Exception => raised
# Not... | [
"def",
"call",
"(",
"env",
")",
"# Set the request data for bugsnag middleware to use",
"Bugsnag",
".",
"configuration",
".",
"set_request_data",
"(",
":rack_env",
",",
"env",
")",
"if",
"Bugsnag",
".",
"configuration",
".",
"auto_capture_sessions",
"Bugsnag",
".",
"s... | Wraps a call to the application with error capturing | [
"Wraps",
"a",
"call",
"to",
"the",
"application",
"with",
"error",
"capturing"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/rack.rb#L38-L76 |
15,583 | bugsnag/bugsnag-ruby | lib/bugsnag/session_tracker.rb | Bugsnag.SessionTracker.start_session | def start_session
return unless Bugsnag.configuration.enable_sessions
start_delivery_thread
start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00')
new_session = {
:id => SecureRandom.uuid,
:startedAt => start_time,
:events => {
:handled => 0,
:unh... | ruby | def start_session
return unless Bugsnag.configuration.enable_sessions
start_delivery_thread
start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00')
new_session = {
:id => SecureRandom.uuid,
:startedAt => start_time,
:events => {
:handled => 0,
:unh... | [
"def",
"start_session",
"return",
"unless",
"Bugsnag",
".",
"configuration",
".",
"enable_sessions",
"start_delivery_thread",
"start_time",
"=",
"Time",
".",
"now",
"(",
")",
".",
"utc",
"(",
")",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:00'",
")",
"new_session",
... | Initializes the session tracker.
Starts a new session, storing it on the current thread.
This allows Bugsnag to track error rates for a release. | [
"Initializes",
"the",
"session",
"tracker",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/session_tracker.rb#L37-L51 |
15,584 | bugsnag/bugsnag-ruby | lib/bugsnag/session_tracker.rb | Bugsnag.SessionTracker.send_sessions | def send_sessions
sessions = []
counts = @session_counts
@session_counts = Concurrent::Hash.new(0)
counts.each do |min, count|
sessions << {
:startedAt => min,
:sessionsStarted => count
}
end
deliver(sessions)
end | ruby | def send_sessions
sessions = []
counts = @session_counts
@session_counts = Concurrent::Hash.new(0)
counts.each do |min, count|
sessions << {
:startedAt => min,
:sessionsStarted => count
}
end
deliver(sessions)
end | [
"def",
"send_sessions",
"sessions",
"=",
"[",
"]",
"counts",
"=",
"@session_counts",
"@session_counts",
"=",
"Concurrent",
"::",
"Hash",
".",
"new",
"(",
"0",
")",
"counts",
".",
"each",
"do",
"|",
"min",
",",
"count",
"|",
"sessions",
"<<",
"{",
":start... | Delivers the current session_counts lists to the session endpoint. | [
"Delivers",
"the",
"current",
"session_counts",
"lists",
"to",
"the",
"session",
"endpoint",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/session_tracker.rb#L57-L68 |
15,585 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/railtie.rb | Bugsnag.Railtie.event_subscription | def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id
if event[:id] == "sql.active_record"
binds... | ruby | def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id
if event[:id] == "sql.active_record"
binds... | [
"def",
"event_subscription",
"(",
"event",
")",
"ActiveSupport",
"::",
"Notifications",
".",
"subscribe",
"(",
"event",
"[",
":id",
"]",
")",
"do",
"|",
"*",
",",
"event_id",
",",
"data",
"|",
"filtered_data",
"=",
"data",
".",
"slice",
"(",
"event",
"["... | Subscribes to an ActiveSupport event, leaving a breadcrumb when it triggers
@api private
@param event [Hash] details of the event to subscribe to | [
"Subscribes",
"to",
"an",
"ActiveSupport",
"event",
"leaving",
"a",
"breadcrumb",
"when",
"it",
"triggers"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/railtie.rb#L76-L92 |
15,586 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/resque.rb | Bugsnag.Resque.save | def save
Bugsnag.notify(exception, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
context = "#{payload['class']}@#{queue}"
report.met... | ruby | def save
Bugsnag.notify(exception, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
context = "#{payload['class']}@#{queue}"
report.met... | [
"def",
"save",
"Bugsnag",
".",
"notify",
"(",
"exception",
",",
"true",
")",
"do",
"|",
"report",
"|",
"report",
".",
"severity",
"=",
"\"error\"",
"report",
".",
"severity_reason",
"=",
"{",
":type",
"=>",
"Bugsnag",
"::",
"Report",
"::",
"UNHANDLED_EXCEP... | Notifies Bugsnag of a raised exception. | [
"Notifies",
"Bugsnag",
"of",
"a",
"raised",
"exception",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/resque.rb#L39-L51 |
15,587 | bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.insert_after | def insert_after(after, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if after.is_a? Array
index = @middlewares.rindex {|el| after.include?(el)}
else
index = @middle... | ruby | def insert_after(after, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if after.is_a? Array
index = @middlewares.rindex {|el| after.include?(el)}
else
index = @middle... | [
"def",
"insert_after",
"(",
"after",
",",
"new_middleware",
")",
"@mutex",
".",
"synchronize",
"do",
"return",
"if",
"@disabled_middleware",
".",
"include?",
"(",
"new_middleware",
")",
"return",
"if",
"@middlewares",
".",
"include?",
"(",
"new_middleware",
")",
... | Inserts a new middleware to use after a given middleware already added.
Will return early if given middleware is disabled or already added.
New middleware will be inserted last if the existing middleware is not already included. | [
"Inserts",
"a",
"new",
"middleware",
"to",
"use",
"after",
"a",
"given",
"middleware",
"already",
"added",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L29-L46 |
15,588 | bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.insert_before | def insert_before(before, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if before.is_a? Array
index = @middlewares.index {|el| before.include?(el)}
else
index = @mid... | ruby | def insert_before(before, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if before.is_a? Array
index = @middlewares.index {|el| before.include?(el)}
else
index = @mid... | [
"def",
"insert_before",
"(",
"before",
",",
"new_middleware",
")",
"@mutex",
".",
"synchronize",
"do",
"return",
"if",
"@disabled_middleware",
".",
"include?",
"(",
"new_middleware",
")",
"return",
"if",
"@middlewares",
".",
"include?",
"(",
"new_middleware",
")",... | Inserts a new middleware to use before a given middleware already added.
Will return early if given middleware is disabled or already added.
New middleware will be inserted last if the existing middleware is not already included. | [
"Inserts",
"a",
"new",
"middleware",
"to",
"use",
"before",
"a",
"given",
"middleware",
"already",
"added",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L53-L66 |
15,589 | bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.run | def run(report)
# The final lambda is the termination of the middleware stack. It calls deliver on the notification
lambda_has_run = false
notify_lambda = lambda do |notif|
lambda_has_run = true
yield if block_given?
end
begin
# We reverse them, so we can call "cal... | ruby | def run(report)
# The final lambda is the termination of the middleware stack. It calls deliver on the notification
lambda_has_run = false
notify_lambda = lambda do |notif|
lambda_has_run = true
yield if block_given?
end
begin
# We reverse them, so we can call "cal... | [
"def",
"run",
"(",
"report",
")",
"# The final lambda is the termination of the middleware stack. It calls deliver on the notification",
"lambda_has_run",
"=",
"false",
"notify_lambda",
"=",
"lambda",
"do",
"|",
"notif",
"|",
"lambda_has_run",
"=",
"true",
"yield",
"if",
"b... | Runs the middleware stack. | [
"Runs",
"the",
"middleware",
"stack",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L84-L107 |
15,590 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.leave_mongo_breadcrumb | def leave_mongo_breadcrumb(event_name, event)
message = MONGO_MESSAGE_PREFIX + event_name
meta_data = {
:event_name => MONGO_EVENT_PREFIX + event_name,
:command_name => event.command_name,
:database_name => event.database_name,
:operation_id => event.operation_id,
:re... | ruby | def leave_mongo_breadcrumb(event_name, event)
message = MONGO_MESSAGE_PREFIX + event_name
meta_data = {
:event_name => MONGO_EVENT_PREFIX + event_name,
:command_name => event.command_name,
:database_name => event.database_name,
:operation_id => event.operation_id,
:re... | [
"def",
"leave_mongo_breadcrumb",
"(",
"event_name",
",",
"event",
")",
"message",
"=",
"MONGO_MESSAGE_PREFIX",
"+",
"event_name",
"meta_data",
"=",
"{",
":event_name",
"=>",
"MONGO_EVENT_PREFIX",
"+",
"event_name",
",",
":command_name",
"=>",
"event",
".",
"command_... | Generates breadcrumb data from an event
@param event_name [String] the type of event
@param event [Mongo::Event::Base] the mongo_ruby_driver generated event | [
"Generates",
"breadcrumb",
"data",
"from",
"an",
"event"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L46-L67 |
15,591 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_hash | def sanitize_filter_hash(filter_hash, depth = 0)
filter_hash.each_with_object({}) do |(key, value), output|
output[key] = sanitize_filter_value(value, depth)
end
end | ruby | def sanitize_filter_hash(filter_hash, depth = 0)
filter_hash.each_with_object({}) do |(key, value), output|
output[key] = sanitize_filter_value(value, depth)
end
end | [
"def",
"sanitize_filter_hash",
"(",
"filter_hash",
",",
"depth",
"=",
"0",
")",
"filter_hash",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"output",
"|",
"output",
"[",
"key",
"]",
"=",
"sanitize_filter_val... | Removes values from filter hashes, replacing them with '?'
@param filter_hash [Hash] the filter hash for the mongo transaction
@param depth [Integer] the current filter depth
@return [Hash] the filtered hash | [
"Removes",
"values",
"from",
"filter",
"hashes",
"replacing",
"them",
"with",
"?"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L76-L80 |
15,592 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_value | def sanitize_filter_value(value, depth)
depth += 1
if depth >= MAX_FILTER_DEPTH
'[MAX_FILTER_DEPTH_REACHED]'
elsif value.is_a?(Array)
value.map { |array_value| sanitize_filter_value(array_value, depth) }
elsif value.is_a?(Hash)
sanitize_filter_hash(value, depth)
els... | ruby | def sanitize_filter_value(value, depth)
depth += 1
if depth >= MAX_FILTER_DEPTH
'[MAX_FILTER_DEPTH_REACHED]'
elsif value.is_a?(Array)
value.map { |array_value| sanitize_filter_value(array_value, depth) }
elsif value.is_a?(Hash)
sanitize_filter_hash(value, depth)
els... | [
"def",
"sanitize_filter_value",
"(",
"value",
",",
"depth",
")",
"depth",
"+=",
"1",
"if",
"depth",
">=",
"MAX_FILTER_DEPTH",
"'[MAX_FILTER_DEPTH_REACHED]'",
"elsif",
"value",
".",
"is_a?",
"(",
"Array",
")",
"value",
".",
"map",
"{",
"|",
"array_value",
"|",
... | Transforms a value element into a useful, redacted, version
@param value [Object] the filter value
@param depth [Integer] the current filter depth
@return [Array, Hash, String] the sanitized value | [
"Transforms",
"a",
"value",
"element",
"into",
"a",
"useful",
"redacted",
"version"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L89-L100 |
15,593 | bugsnag/bugsnag-ruby | lib/bugsnag/configuration.rb | Bugsnag.Configuration.parse_proxy | def parse_proxy(uri)
proxy = URI.parse(uri)
self.proxy_host = proxy.host
self.proxy_port = proxy.port
self.proxy_user = proxy.user
self.proxy_password = proxy.password
end | ruby | def parse_proxy(uri)
proxy = URI.parse(uri)
self.proxy_host = proxy.host
self.proxy_port = proxy.port
self.proxy_user = proxy.user
self.proxy_password = proxy.password
end | [
"def",
"parse_proxy",
"(",
"uri",
")",
"proxy",
"=",
"URI",
".",
"parse",
"(",
"uri",
")",
"self",
".",
"proxy_host",
"=",
"proxy",
".",
"host",
"self",
".",
"proxy_port",
"=",
"proxy",
".",
"port",
"self",
".",
"proxy_user",
"=",
"proxy",
".",
"user... | Parses and sets proxy from a uri | [
"Parses",
"and",
"sets",
"proxy",
"from",
"a",
"uri"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/configuration.rb#L227-L233 |
15,594 | bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mailman.rb | Bugsnag.Mailman.call | def call(mail)
begin
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
yield
rescue Exception => ex
Bugsnag.notify(ex, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MID... | ruby | def call(mail)
begin
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
yield
rescue Exception => ex
Bugsnag.notify(ex, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MID... | [
"def",
"call",
"(",
"mail",
")",
"begin",
"Bugsnag",
".",
"configuration",
".",
"set_request_data",
":mailman_msg",
",",
"mail",
".",
"to_s",
"yield",
"rescue",
"Exception",
"=>",
"ex",
"Bugsnag",
".",
"notify",
"(",
"ex",
",",
"true",
")",
"do",
"|",
"r... | Calls the mailman middleware. | [
"Calls",
"the",
"mailman",
"middleware",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mailman.rb#L19-L35 |
15,595 | codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.render_navigation | def render_navigation(options = {}, &block)
container = active_navigation_item_container(options, &block)
container && container.render(options)
end | ruby | def render_navigation(options = {}, &block)
container = active_navigation_item_container(options, &block)
container && container.render(options)
end | [
"def",
"render_navigation",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"container",
"=",
"active_navigation_item_container",
"(",
"options",
",",
"block",
")",
"container",
"&&",
"container",
".",
"render",
"(",
"options",
")",
"end"
] | Renders the navigation according to the specified options-hash.
The following options are supported:
* <tt>:level</tt> - defaults to :all which renders the the sub_navigation
for an active primary_navigation inside that active
primary_navigation item.
Specify a specific level to only render that level of na... | [
"Renders",
"the",
"navigation",
"according",
"to",
"the",
"specified",
"options",
"-",
"hash",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L86-L89 |
15,596 | codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.active_navigation_item | def active_navigation_item(options = {}, value_for_nil = nil)
if options[:level].nil? || options[:level] == :all
options[:level] = :leaves
end
container = active_navigation_item_container(options)
if container && (item = container.selected_item)
block_given? ? yield(item) : item
... | ruby | def active_navigation_item(options = {}, value_for_nil = nil)
if options[:level].nil? || options[:level] == :all
options[:level] = :leaves
end
container = active_navigation_item_container(options)
if container && (item = container.selected_item)
block_given? ? yield(item) : item
... | [
"def",
"active_navigation_item",
"(",
"options",
"=",
"{",
"}",
",",
"value_for_nil",
"=",
"nil",
")",
"if",
"options",
"[",
":level",
"]",
".",
"nil?",
"||",
"options",
"[",
":level",
"]",
"==",
":all",
"options",
"[",
":level",
"]",
"=",
":leaves",
"... | Returns the currently active navigation item belonging to the specified
level.
The following options are supported:
* <tt>:level</tt> - defaults to :all which returns the
most specific/deepest selected item (the leaf).
Specify a specific level to only look for the selected item in the
specified level of na... | [
"Returns",
"the",
"currently",
"active",
"navigation",
"item",
"belonging",
"to",
"the",
"specified",
"level",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L140-L150 |
15,597 | codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.active_navigation_item_container | def active_navigation_item_container(options = {}, &block)
options = SimpleNavigation::Helpers.apply_defaults(options)
SimpleNavigation::Helpers.load_config(options, self, &block)
SimpleNavigation.active_item_container_for(options[:level])
end | ruby | def active_navigation_item_container(options = {}, &block)
options = SimpleNavigation::Helpers.apply_defaults(options)
SimpleNavigation::Helpers.load_config(options, self, &block)
SimpleNavigation.active_item_container_for(options[:level])
end | [
"def",
"active_navigation_item_container",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"=",
"SimpleNavigation",
"::",
"Helpers",
".",
"apply_defaults",
"(",
"options",
")",
"SimpleNavigation",
"::",
"Helpers",
".",
"load_config",
"(",
"opti... | Returns the currently active item container belonging to the specified
level.
The following options are supported:
* <tt>:level</tt> - defaults to :all which returns the
least specific/shallowest selected item.
Specify a specific level to only look for the selected item in the
specified level of navigation... | [
"Returns",
"the",
"currently",
"active",
"item",
"container",
"belonging",
"to",
"the",
"specified",
"level",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L175-L179 |
15,598 | codeplant/simple-navigation | lib/simple_navigation/item.rb | SimpleNavigation.Item.html_options | def html_options
html_opts = options.fetch(:html) { Hash.new }
html_opts[:id] ||= autogenerated_item_id
classes = [html_opts[:class], selected_class, active_leaf_class]
classes = classes.flatten.compact.join(' ')
html_opts[:class] = classes if classes && !classes.empty?
html_opts
... | ruby | def html_options
html_opts = options.fetch(:html) { Hash.new }
html_opts[:id] ||= autogenerated_item_id
classes = [html_opts[:class], selected_class, active_leaf_class]
classes = classes.flatten.compact.join(' ')
html_opts[:class] = classes if classes && !classes.empty?
html_opts
... | [
"def",
"html_options",
"html_opts",
"=",
"options",
".",
"fetch",
"(",
":html",
")",
"{",
"Hash",
".",
"new",
"}",
"html_opts",
"[",
":id",
"]",
"||=",
"autogenerated_item_id",
"classes",
"=",
"[",
"html_opts",
"[",
":class",
"]",
",",
"selected_class",
",... | Returns the html-options hash for the item, i.e. the options specified
for this item in the config-file.
It also adds the 'selected' class to the list of classes if necessary. | [
"Returns",
"the",
"html",
"-",
"options",
"hash",
"for",
"the",
"item",
"i",
".",
"e",
".",
"the",
"options",
"specified",
"for",
"this",
"item",
"in",
"the",
"config",
"-",
"file",
".",
"It",
"also",
"adds",
"the",
"selected",
"class",
"to",
"the",
... | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item.rb#L51-L60 |
15,599 | codeplant/simple-navigation | lib/simple_navigation/item_container.rb | SimpleNavigation.ItemContainer.item | def item(key, name, url = nil, options = {}, &block)
return unless should_add_item?(options)
item = Item.new(self, key, name, url, options, &block)
add_item item, options
end | ruby | def item(key, name, url = nil, options = {}, &block)
return unless should_add_item?(options)
item = Item.new(self, key, name, url, options, &block)
add_item item, options
end | [
"def",
"item",
"(",
"key",
",",
"name",
",",
"url",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"return",
"unless",
"should_add_item?",
"(",
"options",
")",
"item",
"=",
"Item",
".",
"new",
"(",
"self",
",",
"key",
",",
"na... | Creates a new navigation item.
The <tt>key</tt> is a symbol which uniquely defines your navigation item
in the scope of the primary_navigation or the sub_navigation.
The <tt>name</tt> will be displayed in the rendered navigation.
This can also be a call to your I18n-framework.
The <tt>url</tt> is the address th... | [
"Creates",
"a",
"new",
"navigation",
"item",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item_container.rb#L64-L68 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.