repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
sds/haml-lint
lib/haml_lint/linter.rb
HamlLint.Linter.inline_node_content
def inline_node_content(node) inline_content = node.script if contains_interpolation?(inline_content) strip_surrounding_quotes(inline_content) else inline_content end end
ruby
def inline_node_content(node) inline_content = node.script if contains_interpolation?(inline_content) strip_surrounding_quotes(inline_content) else inline_content end end
[ "def", "inline_node_content", "(", "node", ")", "inline_content", "=", "node", ".", "script", "if", "contains_interpolation?", "(", "inline_content", ")", "strip_surrounding_quotes", "(", "inline_content", ")", "else", "inline_content", "end", "end" ]
Get the inline content for this node. Inline content is the content that appears inline right after the tag/script. For example, in the code below... %tag Some inline content ..."Some inline content" would be the inline content. @param node [HamlLint::Tree::Node] @return [String]
[ "Get", "the", "inline", "content", "for", "this", "node", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L138-L146
train
sds/haml-lint
lib/haml_lint/linter.rb
HamlLint.Linter.next_node
def next_node(node) return unless node siblings = node.parent ? node.parent.children : [node] next_sibling = siblings[siblings.index(node) + 1] if siblings.count > 1 return next_sibling if next_sibling next_node(node.parent) end
ruby
def next_node(node) return unless node siblings = node.parent ? node.parent.children : [node] next_sibling = siblings[siblings.index(node) + 1] if siblings.count > 1 return next_sibling if next_sibling next_node(node.parent) end
[ "def", "next_node", "(", "node", ")", "return", "unless", "node", "siblings", "=", "node", ".", "parent", "?", "node", ".", "parent", ".", "children", ":", "[", "node", "]", "next_sibling", "=", "siblings", "[", "siblings", ".", "index", "(", "node", ")", "+", "1", "]", "if", "siblings", ".", "count", ">", "1", "return", "next_sibling", "if", "next_sibling", "next_node", "(", "node", ".", "parent", ")", "end" ]
Gets the next node following this node, ascending up the ancestor chain recursively if this node has no siblings. @param node [HamlLint::Tree::Node] @return [HamlLint::Tree::Node,nil]
[ "Gets", "the", "next", "node", "following", "this", "node", "ascending", "up", "the", "ancestor", "chain", "recursively", "if", "this", "node", "has", "no", "siblings", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L153-L161
train
sds/haml-lint
lib/haml_lint/ruby_parser.rb
HamlLint.RubyParser.parse
def parse(source) buffer = ::Parser::Source::Buffer.new('(string)') buffer.source = source @parser.reset @parser.parse(buffer) end
ruby
def parse(source) buffer = ::Parser::Source::Buffer.new('(string)') buffer.source = source @parser.reset @parser.parse(buffer) end
[ "def", "parse", "(", "source", ")", "buffer", "=", "::", "Parser", "::", "Source", "::", "Buffer", ".", "new", "(", "'(string)'", ")", "buffer", ".", "source", "=", "source", "@parser", ".", "reset", "@parser", ".", "parse", "(", "buffer", ")", "end" ]
Creates a reusable parser. Parse the given Ruby source into an abstract syntax tree. @param source [String] Ruby source code @return [Array] syntax tree in the form returned by Parser gem
[ "Creates", "a", "reusable", "parser", ".", "Parse", "the", "given", "Ruby", "source", "into", "an", "abstract", "syntax", "tree", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/ruby_parser.rb#L25-L31
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.act_on_options
def act_on_options(options) configure_logger(options) if options[:help] print_help(options) Sysexits::EX_OK elsif options[:version] || options[:verbose_version] print_version(options) Sysexits::EX_OK elsif options[:show_linters] print_available_linters Sysexits::EX_OK elsif options[:show_reporters] print_available_reporters Sysexits::EX_OK else scan_for_lints(options) end end
ruby
def act_on_options(options) configure_logger(options) if options[:help] print_help(options) Sysexits::EX_OK elsif options[:version] || options[:verbose_version] print_version(options) Sysexits::EX_OK elsif options[:show_linters] print_available_linters Sysexits::EX_OK elsif options[:show_reporters] print_available_reporters Sysexits::EX_OK else scan_for_lints(options) end end
[ "def", "act_on_options", "(", "options", ")", "configure_logger", "(", "options", ")", "if", "options", "[", ":help", "]", "print_help", "(", "options", ")", "Sysexits", "::", "EX_OK", "elsif", "options", "[", ":version", "]", "||", "options", "[", ":verbose_version", "]", "print_version", "(", "options", ")", "Sysexits", "::", "EX_OK", "elsif", "options", "[", ":show_linters", "]", "print_available_linters", "Sysexits", "::", "EX_OK", "elsif", "options", "[", ":show_reporters", "]", "print_available_reporters", "Sysexits", "::", "EX_OK", "else", "scan_for_lints", "(", "options", ")", "end", "end" ]
Given the provided options, execute the appropriate command. @return [Integer] exit status code
[ "Given", "the", "provided", "options", "execute", "the", "appropriate", "command", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L37-L55
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.configure_logger
def configure_logger(options) log.color_enabled = options.fetch(:color, log.tty?) log.summary_enabled = options.fetch(:summary, true) end
ruby
def configure_logger(options) log.color_enabled = options.fetch(:color, log.tty?) log.summary_enabled = options.fetch(:summary, true) end
[ "def", "configure_logger", "(", "options", ")", "log", ".", "color_enabled", "=", "options", ".", "fetch", "(", ":color", ",", "log", ".", "tty?", ")", "log", ".", "summary_enabled", "=", "options", ".", "fetch", "(", ":summary", ",", "true", ")", "end" ]
Given the provided options, configure the logger. @return [void]
[ "Given", "the", "provided", "options", "configure", "the", "logger", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L60-L63
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.handle_exception
def handle_exception(exception) case exception when HamlLint::Exceptions::ConfigurationError log.error exception.message Sysexits::EX_CONFIG when HamlLint::Exceptions::InvalidCLIOption log.error exception.message log.log "Run `#{APP_NAME}` --help for usage documentation" Sysexits::EX_USAGE when HamlLint::Exceptions::InvalidFilePath log.error exception.message Sysexits::EX_NOINPUT when HamlLint::Exceptions::NoLintersError log.error exception.message Sysexits::EX_NOINPUT else print_unexpected_exception(exception) Sysexits::EX_SOFTWARE end end
ruby
def handle_exception(exception) case exception when HamlLint::Exceptions::ConfigurationError log.error exception.message Sysexits::EX_CONFIG when HamlLint::Exceptions::InvalidCLIOption log.error exception.message log.log "Run `#{APP_NAME}` --help for usage documentation" Sysexits::EX_USAGE when HamlLint::Exceptions::InvalidFilePath log.error exception.message Sysexits::EX_NOINPUT when HamlLint::Exceptions::NoLintersError log.error exception.message Sysexits::EX_NOINPUT else print_unexpected_exception(exception) Sysexits::EX_SOFTWARE end end
[ "def", "handle_exception", "(", "exception", ")", "case", "exception", "when", "HamlLint", "::", "Exceptions", "::", "ConfigurationError", "log", ".", "error", "exception", ".", "message", "Sysexits", "::", "EX_CONFIG", "when", "HamlLint", "::", "Exceptions", "::", "InvalidCLIOption", "log", ".", "error", "exception", ".", "message", "log", ".", "log", "\"Run `#{APP_NAME}` --help for usage documentation\"", "Sysexits", "::", "EX_USAGE", "when", "HamlLint", "::", "Exceptions", "::", "InvalidFilePath", "log", ".", "error", "exception", ".", "message", "Sysexits", "::", "EX_NOINPUT", "when", "HamlLint", "::", "Exceptions", "::", "NoLintersError", "log", ".", "error", "exception", ".", "message", "Sysexits", "::", "EX_NOINPUT", "else", "print_unexpected_exception", "(", "exception", ")", "Sysexits", "::", "EX_SOFTWARE", "end", "end" ]
Outputs a message and returns an appropriate error code for the specified exception.
[ "Outputs", "a", "message", "and", "returns", "an", "appropriate", "error", "code", "for", "the", "specified", "exception", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L67-L86
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.reporter_from_options
def reporter_from_options(options) if options[:auto_gen_config] HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Metrics/LineLength else options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log) end end
ruby
def reporter_from_options(options) if options[:auto_gen_config] HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Metrics/LineLength else options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log) end end
[ "def", "reporter_from_options", "(", "options", ")", "if", "options", "[", ":auto_gen_config", "]", "HamlLint", "::", "Reporter", "::", "DisabledConfigReporter", ".", "new", "(", "log", ",", "limit", ":", "options", "[", ":auto_gen_exclude_limit", "]", "||", "15", ")", "# rubocop:disable Metrics/LineLength", "else", "options", ".", "fetch", "(", ":reporter", ",", "HamlLint", "::", "Reporter", "::", "DefaultReporter", ")", ".", "new", "(", "log", ")", "end", "end" ]
Instantiates a new reporter based on the options. @param options [HamlLint::Configuration] @option options [true, nil] :auto_gen_config whether to use the config generating reporter @option options [Class] :reporter the class of reporter to use @return [HamlLint::Reporter]
[ "Instantiates", "a", "new", "reporter", "based", "on", "the", "options", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L95-L101
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.scan_for_lints
def scan_for_lints(options) reporter = reporter_from_options(options) report = Runner.new.run(options.merge(reporter: reporter)) report.display report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK end
ruby
def scan_for_lints(options) reporter = reporter_from_options(options) report = Runner.new.run(options.merge(reporter: reporter)) report.display report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK end
[ "def", "scan_for_lints", "(", "options", ")", "reporter", "=", "reporter_from_options", "(", "options", ")", "report", "=", "Runner", ".", "new", ".", "run", "(", "options", ".", "merge", "(", "reporter", ":", "reporter", ")", ")", "report", ".", "display", "report", ".", "failed?", "?", "Sysexits", "::", "EX_DATAERR", ":", "Sysexits", "::", "EX_OK", "end" ]
Scans the files specified by the given options for lints. @return [Integer] exit status code
[ "Scans", "the", "files", "specified", "by", "the", "given", "options", "for", "lints", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L106-L111
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.print_available_linters
def print_available_linters log.info 'Available linters:' linter_names = HamlLint::LinterRegistry.linters.map do |linter| linter.name.split('::').last end linter_names.sort.each do |linter_name| log.log " - #{linter_name}" end end
ruby
def print_available_linters log.info 'Available linters:' linter_names = HamlLint::LinterRegistry.linters.map do |linter| linter.name.split('::').last end linter_names.sort.each do |linter_name| log.log " - #{linter_name}" end end
[ "def", "print_available_linters", "log", ".", "info", "'Available linters:'", "linter_names", "=", "HamlLint", "::", "LinterRegistry", ".", "linters", ".", "map", "do", "|", "linter", "|", "linter", ".", "name", ".", "split", "(", "'::'", ")", ".", "last", "end", "linter_names", ".", "sort", ".", "each", "do", "|", "linter_name", "|", "log", ".", "log", "\" - #{linter_name}\"", "end", "end" ]
Outputs a list of all currently available linters.
[ "Outputs", "a", "list", "of", "all", "currently", "available", "linters", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L114-L124
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.print_available_reporters
def print_available_reporters log.info 'Available reporters:' HamlLint::Reporter.available.map(&:cli_name).sort.each do |reporter_name| log.log " - #{reporter_name}" end end
ruby
def print_available_reporters log.info 'Available reporters:' HamlLint::Reporter.available.map(&:cli_name).sort.each do |reporter_name| log.log " - #{reporter_name}" end end
[ "def", "print_available_reporters", "log", ".", "info", "'Available reporters:'", "HamlLint", "::", "Reporter", ".", "available", ".", "map", "(", ":cli_name", ")", ".", "sort", ".", "each", "do", "|", "reporter_name", "|", "log", ".", "log", "\" - #{reporter_name}\"", "end", "end" ]
Outputs a list of currently available reporters.
[ "Outputs", "a", "list", "of", "currently", "available", "reporters", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L127-L133
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.print_version
def print_version(options) log.log "#{HamlLint::APP_NAME} #{HamlLint::VERSION}" if options[:verbose_version] log.log "haml #{Gem.loaded_specs['haml'].version}" log.log "rubocop #{Gem.loaded_specs['rubocop'].version}" log.log RUBY_DESCRIPTION end end
ruby
def print_version(options) log.log "#{HamlLint::APP_NAME} #{HamlLint::VERSION}" if options[:verbose_version] log.log "haml #{Gem.loaded_specs['haml'].version}" log.log "rubocop #{Gem.loaded_specs['rubocop'].version}" log.log RUBY_DESCRIPTION end end
[ "def", "print_version", "(", "options", ")", "log", ".", "log", "\"#{HamlLint::APP_NAME} #{HamlLint::VERSION}\"", "if", "options", "[", ":verbose_version", "]", "log", ".", "log", "\"haml #{Gem.loaded_specs['haml'].version}\"", "log", ".", "log", "\"rubocop #{Gem.loaded_specs['rubocop'].version}\"", "log", ".", "log", "RUBY_DESCRIPTION", "end", "end" ]
Outputs the application name and version.
[ "Outputs", "the", "application", "name", "and", "version", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L141-L149
train
sds/haml-lint
lib/haml_lint/cli.rb
HamlLint.CLI.print_unexpected_exception
def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize log.bold_error exception.message log.error exception.backtrace.join("\n") log.warning 'Report this bug at ', false log.info HamlLint::BUG_REPORT_URL log.newline log.success 'To help fix this issue, please include:' log.log '- The above stack trace' log.log '- Haml-Lint version: ', false log.info HamlLint::VERSION log.log '- Haml version: ', false log.info Gem.loaded_specs['haml'].version log.log '- RuboCop version: ', false log.info Gem.loaded_specs['rubocop'].version log.log '- Ruby version: ', false log.info RUBY_VERSION end
ruby
def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize log.bold_error exception.message log.error exception.backtrace.join("\n") log.warning 'Report this bug at ', false log.info HamlLint::BUG_REPORT_URL log.newline log.success 'To help fix this issue, please include:' log.log '- The above stack trace' log.log '- Haml-Lint version: ', false log.info HamlLint::VERSION log.log '- Haml version: ', false log.info Gem.loaded_specs['haml'].version log.log '- RuboCop version: ', false log.info Gem.loaded_specs['rubocop'].version log.log '- Ruby version: ', false log.info RUBY_VERSION end
[ "def", "print_unexpected_exception", "(", "exception", ")", "# rubocop:disable Metrics/AbcSize", "log", ".", "bold_error", "exception", ".", "message", "log", ".", "error", "exception", ".", "backtrace", ".", "join", "(", "\"\\n\"", ")", "log", ".", "warning", "'Report this bug at '", ",", "false", "log", ".", "info", "HamlLint", "::", "BUG_REPORT_URL", "log", ".", "newline", "log", ".", "success", "'To help fix this issue, please include:'", "log", ".", "log", "'- The above stack trace'", "log", ".", "log", "'- Haml-Lint version: '", ",", "false", "log", ".", "info", "HamlLint", "::", "VERSION", "log", ".", "log", "'- Haml version: '", ",", "false", "log", ".", "info", "Gem", ".", "loaded_specs", "[", "'haml'", "]", ".", "version", "log", ".", "log", "'- RuboCop version: '", ",", "false", "log", ".", "info", "Gem", ".", "loaded_specs", "[", "'rubocop'", "]", ".", "version", "log", ".", "log", "'- Ruby version: '", ",", "false", "log", ".", "info", "RUBY_VERSION", "end" ]
Outputs the backtrace of an exception with instructions on how to report the issue.
[ "Outputs", "the", "backtrace", "of", "an", "exception", "with", "instructions", "on", "how", "to", "report", "the", "issue", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L153-L169
train
sds/haml-lint
lib/haml_lint/document.rb
HamlLint.Document.strip_frontmatter
def strip_frontmatter(source) frontmatter = / # From the start of the string \A # First-capture match --- followed by optional whitespace up # to a newline then 0 or more chars followed by an optional newline. # This matches the --- and the contents of the frontmatter (---\s*\n.*?\n?) # From the start of the line ^ # Second capture match --- or ... followed by optional whitespace # and newline. This matches the closing --- for the frontmatter. (---|\.\.\.)\s*$\n?/mx if config['skip_frontmatter'] && match = source.match(frontmatter) newlines = match[0].count("\n") source.sub!(frontmatter, "\n" * newlines) end source end
ruby
def strip_frontmatter(source) frontmatter = / # From the start of the string \A # First-capture match --- followed by optional whitespace up # to a newline then 0 or more chars followed by an optional newline. # This matches the --- and the contents of the frontmatter (---\s*\n.*?\n?) # From the start of the line ^ # Second capture match --- or ... followed by optional whitespace # and newline. This matches the closing --- for the frontmatter. (---|\.\.\.)\s*$\n?/mx if config['skip_frontmatter'] && match = source.match(frontmatter) newlines = match[0].count("\n") source.sub!(frontmatter, "\n" * newlines) end source end
[ "def", "strip_frontmatter", "(", "source", ")", "frontmatter", "=", "/", "\\A", "\\s", "\\n", "\\n", "\\.", "\\.", "\\.", "\\s", "\\n", "/mx", "if", "config", "[", "'skip_frontmatter'", "]", "&&", "match", "=", "source", ".", "match", "(", "frontmatter", ")", "newlines", "=", "match", "[", "0", "]", ".", "count", "(", "\"\\n\"", ")", "source", ".", "sub!", "(", "frontmatter", ",", "\"\\n\"", "*", "newlines", ")", "end", "source", "end" ]
Removes YAML frontmatter
[ "Removes", "YAML", "frontmatter" ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/document.rb#L102-L122
train
sds/haml-lint
lib/haml_lint/tree/node.rb
HamlLint::Tree.Node.disabled?
def disabled?(visitor) visitor.is_a?(HamlLint::Linter) && comment_configuration.disabled?(visitor.name) end
ruby
def disabled?(visitor) visitor.is_a?(HamlLint::Linter) && comment_configuration.disabled?(visitor.name) end
[ "def", "disabled?", "(", "visitor", ")", "visitor", ".", "is_a?", "(", "HamlLint", "::", "Linter", ")", "&&", "comment_configuration", ".", "disabled?", "(", "visitor", ".", "name", ")", "end" ]
Checks whether a visitor is disabled due to comment configuration. @param [HamlLint::HamlVisitor] @return [true, false]
[ "Checks", "whether", "a", "visitor", "is", "disabled", "due", "to", "comment", "configuration", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L43-L46
train
sds/haml-lint
lib/haml_lint/tree/node.rb
HamlLint::Tree.Node.each
def each return to_enum(__callee__) unless block_given? node = self loop do yield node break unless (node = node.next_node) end end
ruby
def each return to_enum(__callee__) unless block_given? node = self loop do yield node break unless (node = node.next_node) end end
[ "def", "each", "return", "to_enum", "(", "__callee__", ")", "unless", "block_given?", "node", "=", "self", "loop", "do", "yield", "node", "break", "unless", "(", "node", "=", "node", ".", "next_node", ")", "end", "end" ]
Implements the Enumerable interface to walk through an entire tree. @return [Enumerator, HamlLint::Tree::Node]
[ "Implements", "the", "Enumerable", "interface", "to", "walk", "through", "an", "entire", "tree", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L51-L59
train
sds/haml-lint
lib/haml_lint/tree/node.rb
HamlLint::Tree.Node.line_numbers
def line_numbers return (line..line) unless @value && text end_line = line + lines.count end_line = nontrivial_end_line if line == end_line (line..end_line) end
ruby
def line_numbers return (line..line) unless @value && text end_line = line + lines.count end_line = nontrivial_end_line if line == end_line (line..end_line) end
[ "def", "line_numbers", "return", "(", "line", "..", "line", ")", "unless", "@value", "&&", "text", "end_line", "=", "line", "+", "lines", ".", "count", "end_line", "=", "nontrivial_end_line", "if", "line", "==", "end_line", "(", "line", "..", "end_line", ")", "end" ]
The line numbers that are contained within the node. @api public @return [Range]
[ "The", "line", "numbers", "that", "are", "contained", "within", "the", "node", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L104-L111
train
sds/haml-lint
lib/haml_lint/tree/node.rb
HamlLint::Tree.Node.nontrivial_end_line
def nontrivial_end_line if (last_child = children.last) last_child.line_numbers.end - 1 elsif successor successor.line_numbers.begin - 1 else @document.source_lines.count end end
ruby
def nontrivial_end_line if (last_child = children.last) last_child.line_numbers.end - 1 elsif successor successor.line_numbers.begin - 1 else @document.source_lines.count end end
[ "def", "nontrivial_end_line", "if", "(", "last_child", "=", "children", ".", "last", ")", "last_child", ".", "line_numbers", ".", "end", "-", "1", "elsif", "successor", "successor", ".", "line_numbers", ".", "begin", "-", "1", "else", "@document", ".", "source_lines", ".", "count", "end", "end" ]
Discovers the end line of the node when there are no lines. @return [Integer] the end line of the node
[ "Discovers", "the", "end", "line", "of", "the", "node", "when", "there", "are", "no", "lines", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L163-L171
train
sds/haml-lint
lib/haml_lint/tree/root_node.rb
HamlLint::Tree.RootNode.node_for_line
def node_for_line(line) find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) } end
ruby
def node_for_line(line) find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) } end
[ "def", "node_for_line", "(", "line", ")", "find", "(", "->", "{", "HamlLint", "::", "Tree", "::", "NullNode", ".", "new", "}", ")", "{", "|", "node", "|", "node", ".", "line_numbers", ".", "cover?", "(", "line", ")", "}", "end" ]
Gets the node of the syntax tree for a given line number. @param line [Integer] the line number of the node @return [HamlLint::Node]
[ "Gets", "the", "node", "of", "the", "syntax", "tree", "for", "a", "given", "line", "number", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/root_node.rb#L19-L21
train
sds/haml-lint
lib/haml_lint/linter_selector.rb
HamlLint.LinterSelector.extract_enabled_linters
def extract_enabled_linters(config, options) included_linters = LinterRegistry.extract_linters_from(options.fetch(:included_linters, [])) included_linters = LinterRegistry.linters if included_linters.empty? excluded_linters = LinterRegistry.extract_linters_from(options.fetch(:excluded_linters, [])) # After filtering out explicitly included/excluded linters, only include # linters which are enabled in the configuration linters = (included_linters - excluded_linters).map do |linter_class| linter_config = config.for_linter(linter_class) linter_class.new(linter_config) if linter_config['enabled'] end.compact # Highlight condition where all linters were filtered out, as this was # likely a mistake on the user's part if linters.empty? raise HamlLint::Exceptions::NoLintersError, 'No linters specified' end linters end
ruby
def extract_enabled_linters(config, options) included_linters = LinterRegistry.extract_linters_from(options.fetch(:included_linters, [])) included_linters = LinterRegistry.linters if included_linters.empty? excluded_linters = LinterRegistry.extract_linters_from(options.fetch(:excluded_linters, [])) # After filtering out explicitly included/excluded linters, only include # linters which are enabled in the configuration linters = (included_linters - excluded_linters).map do |linter_class| linter_config = config.for_linter(linter_class) linter_class.new(linter_config) if linter_config['enabled'] end.compact # Highlight condition where all linters were filtered out, as this was # likely a mistake on the user's part if linters.empty? raise HamlLint::Exceptions::NoLintersError, 'No linters specified' end linters end
[ "def", "extract_enabled_linters", "(", "config", ",", "options", ")", "included_linters", "=", "LinterRegistry", ".", "extract_linters_from", "(", "options", ".", "fetch", "(", ":included_linters", ",", "[", "]", ")", ")", "included_linters", "=", "LinterRegistry", ".", "linters", "if", "included_linters", ".", "empty?", "excluded_linters", "=", "LinterRegistry", ".", "extract_linters_from", "(", "options", ".", "fetch", "(", ":excluded_linters", ",", "[", "]", ")", ")", "# After filtering out explicitly included/excluded linters, only include", "# linters which are enabled in the configuration", "linters", "=", "(", "included_linters", "-", "excluded_linters", ")", ".", "map", "do", "|", "linter_class", "|", "linter_config", "=", "config", ".", "for_linter", "(", "linter_class", ")", "linter_class", ".", "new", "(", "linter_config", ")", "if", "linter_config", "[", "'enabled'", "]", "end", ".", "compact", "# Highlight condition where all linters were filtered out, as this was", "# likely a mistake on the user's part", "if", "linters", ".", "empty?", "raise", "HamlLint", "::", "Exceptions", "::", "NoLintersError", ",", "'No linters specified'", "end", "linters", "end" ]
Returns a list of linters that are enabled given the specified configuration and additional options. @param config [HamlLint::Configuration] @param options [Hash] @return [Array<HamlLint::Linter>]
[ "Returns", "a", "list", "of", "linters", "that", "are", "enabled", "given", "the", "specified", "configuration", "and", "additional", "options", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter_selector.rb#L33-L56
train
sds/haml-lint
lib/haml_lint/linter_selector.rb
HamlLint.LinterSelector.run_linter_on_file?
def run_linter_on_file?(config, linter, file) linter_config = config.for_linter(linter) if linter_config['include'].any? && !HamlLint::Utils.any_glob_matches?(linter_config['include'], file) return false end if HamlLint::Utils.any_glob_matches?(linter_config['exclude'], file) return false end true end
ruby
def run_linter_on_file?(config, linter, file) linter_config = config.for_linter(linter) if linter_config['include'].any? && !HamlLint::Utils.any_glob_matches?(linter_config['include'], file) return false end if HamlLint::Utils.any_glob_matches?(linter_config['exclude'], file) return false end true end
[ "def", "run_linter_on_file?", "(", "config", ",", "linter", ",", "file", ")", "linter_config", "=", "config", ".", "for_linter", "(", "linter", ")", "if", "linter_config", "[", "'include'", "]", ".", "any?", "&&", "!", "HamlLint", "::", "Utils", ".", "any_glob_matches?", "(", "linter_config", "[", "'include'", "]", ",", "file", ")", "return", "false", "end", "if", "HamlLint", "::", "Utils", ".", "any_glob_matches?", "(", "linter_config", "[", "'exclude'", "]", ",", "file", ")", "return", "false", "end", "true", "end" ]
Whether to run the given linter against the specified file. @param config [HamlLint::Configuration] @param linter [HamlLint::Linter] @param file [String] @return [Boolean]
[ "Whether", "to", "run", "the", "given", "linter", "against", "the", "specified", "file", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter_selector.rb#L64-L77
train
sds/haml-lint
lib/haml_lint/tree/tag_node.rb
HamlLint::Tree.TagNode.attributes_source
def attributes_source @attributes_source ||= begin _explicit_tag, static_attrs, rest = source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0] attr_types = { '{' => [:hash, %w[{ }]], '(' => [:html, %w[( )]], '[' => [:object_ref, %w[[ ]]], } attr_source = { static: static_attrs } while rest type, chars = attr_types[rest[0]] break unless type # Not an attribute opening character, so we're done # Can't define multiple of the same attribute type (e.g. two {...}) break if attr_source[type] attr_source[type], rest = Haml::Util.balance(rest, *chars) end attr_source end end
ruby
def attributes_source @attributes_source ||= begin _explicit_tag, static_attrs, rest = source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0] attr_types = { '{' => [:hash, %w[{ }]], '(' => [:html, %w[( )]], '[' => [:object_ref, %w[[ ]]], } attr_source = { static: static_attrs } while rest type, chars = attr_types[rest[0]] break unless type # Not an attribute opening character, so we're done # Can't define multiple of the same attribute type (e.g. two {...}) break if attr_source[type] attr_source[type], rest = Haml::Util.balance(rest, *chars) end attr_source end end
[ "def", "attributes_source", "@attributes_source", "||=", "begin", "_explicit_tag", ",", "static_attrs", ",", "rest", "=", "source_code", ".", "scan", "(", "/", "\\A", "\\s", "\\w", "\\w", "\\.", "\\#", "/m", ")", "[", "0", "]", "attr_types", "=", "{", "'{'", "=>", "[", ":hash", ",", "%w[", "{", "}", "]", "]", ",", "'('", "=>", "[", ":html", ",", "%w[", "(", ")", "]", "]", ",", "'['", "=>", "[", ":object_ref", ",", "%w[", "[", "]", "]", "]", ",", "}", "attr_source", "=", "{", "static", ":", "static_attrs", "}", "while", "rest", "type", ",", "chars", "=", "attr_types", "[", "rest", "[", "0", "]", "]", "break", "unless", "type", "# Not an attribute opening character, so we're done", "# Can't define multiple of the same attribute type (e.g. two {...})", "break", "if", "attr_source", "[", "type", "]", "attr_source", "[", "type", "]", ",", "rest", "=", "Haml", "::", "Util", ".", "balance", "(", "rest", ",", "chars", ")", "end", "attr_source", "end", "end" ]
Returns the source code for the static and dynamic attributes of a tag. @example For `%tag.class{ id: 'hello' }(lang=en)`, this returns: { :static => '.class', :hash => " id: 'hello' ", :html => "lang=en" } @return [Hash]
[ "Returns", "the", "source", "code", "for", "the", "static", "and", "dynamic", "attributes", "of", "a", "tag", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/tag_node.rb#L100-L125
train
sds/haml-lint
lib/haml_lint/linter/rubocop.rb
HamlLint.Linter::RuboCop.find_lints
def find_lints(ruby, source_map) rubocop = ::RuboCop::CLI.new filename = if document.file "#{document.file}.rb" else 'ruby_script.rb' end with_ruby_from_stdin(ruby) do extract_lints_from_offenses(lint_file(rubocop, filename), source_map) end end
ruby
def find_lints(ruby, source_map) rubocop = ::RuboCop::CLI.new filename = if document.file "#{document.file}.rb" else 'ruby_script.rb' end with_ruby_from_stdin(ruby) do extract_lints_from_offenses(lint_file(rubocop, filename), source_map) end end
[ "def", "find_lints", "(", "ruby", ",", "source_map", ")", "rubocop", "=", "::", "RuboCop", "::", "CLI", ".", "new", "filename", "=", "if", "document", ".", "file", "\"#{document.file}.rb\"", "else", "'ruby_script.rb'", "end", "with_ruby_from_stdin", "(", "ruby", ")", "do", "extract_lints_from_offenses", "(", "lint_file", "(", "rubocop", ",", "filename", ")", ",", "source_map", ")", "end", "end" ]
Executes RuboCop against the given Ruby code and records the offenses as lints. @param ruby [String] Ruby code @param source_map [Hash] map of Ruby code line numbers to original line numbers in the template
[ "Executes", "RuboCop", "against", "the", "given", "Ruby", "code", "and", "records", "the", "offenses", "as", "lints", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/rubocop.rb#L38-L51
train
sds/haml-lint
lib/haml_lint/linter/rubocop.rb
HamlLint.Linter::RuboCop.with_ruby_from_stdin
def with_ruby_from_stdin(ruby, &_block) original_stdin = $stdin stdin = StringIO.new stdin.write(ruby) stdin.rewind $stdin = stdin yield ensure $stdin = original_stdin end
ruby
def with_ruby_from_stdin(ruby, &_block) original_stdin = $stdin stdin = StringIO.new stdin.write(ruby) stdin.rewind $stdin = stdin yield ensure $stdin = original_stdin end
[ "def", "with_ruby_from_stdin", "(", "ruby", ",", "&", "_block", ")", "original_stdin", "=", "$stdin", "stdin", "=", "StringIO", ".", "new", "stdin", ".", "write", "(", "ruby", ")", "stdin", ".", "rewind", "$stdin", "=", "stdin", "yield", "ensure", "$stdin", "=", "original_stdin", "end" ]
Overrides the global stdin to allow RuboCop to read Ruby code from it. @param ruby [String] the Ruby code to write to the overridden stdin @param _block [Block] the block to perform with the overridden stdin @return [void]
[ "Overrides", "the", "global", "stdin", "to", "allow", "RuboCop", "to", "read", "Ruby", "code", "from", "it", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/rubocop.rb#L103-L112
train
sds/haml-lint
lib/haml_lint/utils.rb
HamlLint.Utils.get_abs_and_rel_path
def get_abs_and_rel_path(path) original_path = Pathname.new(path) root_dir_path = Pathname.new(File.expand_path(Dir.pwd)) if original_path.absolute? [path, original_path.relative_path_from(root_dir_path)] else [root_dir_path + original_path, path] end end
ruby
def get_abs_and_rel_path(path) original_path = Pathname.new(path) root_dir_path = Pathname.new(File.expand_path(Dir.pwd)) if original_path.absolute? [path, original_path.relative_path_from(root_dir_path)] else [root_dir_path + original_path, path] end end
[ "def", "get_abs_and_rel_path", "(", "path", ")", "original_path", "=", "Pathname", ".", "new", "(", "path", ")", "root_dir_path", "=", "Pathname", ".", "new", "(", "File", ".", "expand_path", "(", "Dir", ".", "pwd", ")", ")", "if", "original_path", ".", "absolute?", "[", "path", ",", "original_path", ".", "relative_path_from", "(", "root_dir_path", ")", "]", "else", "[", "root_dir_path", "+", "original_path", ",", "path", "]", "end", "end" ]
Returns an array of two items, the first being the absolute path, the second the relative path. The relative path is relative to the current working dir. The path passed can be either relative or absolute. @param path [String] Path to get absolute and relative path of @return [Array<String>] Absolute and relative path
[ "Returns", "an", "array", "of", "two", "items", "the", "first", "being", "the", "absolute", "path", "the", "second", "the", "relative", "path", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L37-L46
train
sds/haml-lint
lib/haml_lint/utils.rb
HamlLint.Utils.extract_interpolated_values
def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize dumped_text = text.dump newline_positions = extract_substring_positions(dumped_text, '\\\n') Haml::Util.handle_interpolation(dumped_text) do |scan| line = (newline_positions.find_index { |marker| scan.pos <= marker } || newline_positions.size) + 1 escape_count = (scan[2].size - 1) / 2 break unless escape_count.even? dumped_interpolated_str = Haml::Util.balance(scan, '{', '}', 1)[0][0...-1] # Hacky way to turn a dumped string back into a regular string yield [eval('"' + dumped_interpolated_str + '"'), line] # rubocop:disable Eval end end
ruby
def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize dumped_text = text.dump newline_positions = extract_substring_positions(dumped_text, '\\\n') Haml::Util.handle_interpolation(dumped_text) do |scan| line = (newline_positions.find_index { |marker| scan.pos <= marker } || newline_positions.size) + 1 escape_count = (scan[2].size - 1) / 2 break unless escape_count.even? dumped_interpolated_str = Haml::Util.balance(scan, '{', '}', 1)[0][0...-1] # Hacky way to turn a dumped string back into a regular string yield [eval('"' + dumped_interpolated_str + '"'), line] # rubocop:disable Eval end end
[ "def", "extract_interpolated_values", "(", "text", ")", "# rubocop:disable Metrics/AbcSize", "dumped_text", "=", "text", ".", "dump", "newline_positions", "=", "extract_substring_positions", "(", "dumped_text", ",", "'\\\\\\n'", ")", "Haml", "::", "Util", ".", "handle_interpolation", "(", "dumped_text", ")", "do", "|", "scan", "|", "line", "=", "(", "newline_positions", ".", "find_index", "{", "|", "marker", "|", "scan", ".", "pos", "<=", "marker", "}", "||", "newline_positions", ".", "size", ")", "+", "1", "escape_count", "=", "(", "scan", "[", "2", "]", ".", "size", "-", "1", ")", "/", "2", "break", "unless", "escape_count", ".", "even?", "dumped_interpolated_str", "=", "Haml", "::", "Util", ".", "balance", "(", "scan", ",", "'{'", ",", "'}'", ",", "1", ")", "[", "0", "]", "[", "0", "...", "-", "1", "]", "# Hacky way to turn a dumped string back into a regular string", "yield", "[", "eval", "(", "'\"'", "+", "dumped_interpolated_str", "+", "'\"'", ")", ",", "line", "]", "# rubocop:disable Eval", "end", "end" ]
Yields interpolated values within a block of text. @param text [String] @yield Passes interpolated code and line number that code appears on in the text. @yieldparam interpolated_code [String] code that was interpolated @yieldparam line [Integer] line number code appears on in text
[ "Yields", "interpolated", "values", "within", "a", "block", "of", "text", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L55-L71
train
sds/haml-lint
lib/haml_lint/utils.rb
HamlLint.Utils.for_consecutive_items
def for_consecutive_items(items, satisfies, min_consecutive = 2) current_index = -1 while (current_index += 1) < items.count next unless satisfies[items[current_index]] count = count_consecutive(items, current_index, &satisfies) next unless count >= min_consecutive # Yield the chunk of consecutive items yield items[current_index...(current_index + count)] current_index += count # Skip this patch of consecutive items to find more end end
ruby
def for_consecutive_items(items, satisfies, min_consecutive = 2) current_index = -1 while (current_index += 1) < items.count next unless satisfies[items[current_index]] count = count_consecutive(items, current_index, &satisfies) next unless count >= min_consecutive # Yield the chunk of consecutive items yield items[current_index...(current_index + count)] current_index += count # Skip this patch of consecutive items to find more end end
[ "def", "for_consecutive_items", "(", "items", ",", "satisfies", ",", "min_consecutive", "=", "2", ")", "current_index", "=", "-", "1", "while", "(", "current_index", "+=", "1", ")", "<", "items", ".", "count", "next", "unless", "satisfies", "[", "items", "[", "current_index", "]", "]", "count", "=", "count_consecutive", "(", "items", ",", "current_index", ",", "satisfies", ")", "next", "unless", "count", ">=", "min_consecutive", "# Yield the chunk of consecutive items", "yield", "items", "[", "current_index", "...", "(", "current_index", "+", "count", ")", "]", "current_index", "+=", "count", "# Skip this patch of consecutive items to find more", "end", "end" ]
Find all consecutive items satisfying the given block of a minimum size, yielding each group of consecutive items to the provided block. @param items [Array] @param satisfies [Proc] function that takes an item and returns true/false @param min_consecutive [Fixnum] minimum number of consecutive items before yielding the group @yield Passes list of consecutive items all matching the criteria defined by the `satisfies` {Proc} to the provided block @yieldparam group [Array] List of consecutive items @yieldreturn [Boolean] block should return whether item matches criteria for inclusion
[ "Find", "all", "consecutive", "items", "satisfying", "the", "given", "block", "of", "a", "minimum", "size", "yielding", "each", "group", "of", "consecutive", "items", "to", "the", "provided", "block", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L108-L122
train
sds/haml-lint
lib/haml_lint/utils.rb
HamlLint.Utils.with_environment
def with_environment(env) old_env = {} env.each do |var, value| old_env[var] = ENV[var.to_s] ENV[var.to_s] = value end yield ensure old_env.each { |var, value| ENV[var.to_s] = value } end
ruby
def with_environment(env) old_env = {} env.each do |var, value| old_env[var] = ENV[var.to_s] ENV[var.to_s] = value end yield ensure old_env.each { |var, value| ENV[var.to_s] = value } end
[ "def", "with_environment", "(", "env", ")", "old_env", "=", "{", "}", "env", ".", "each", "do", "|", "var", ",", "value", "|", "old_env", "[", "var", "]", "=", "ENV", "[", "var", ".", "to_s", "]", "ENV", "[", "var", ".", "to_s", "]", "=", "value", "end", "yield", "ensure", "old_env", ".", "each", "{", "|", "var", ",", "value", "|", "ENV", "[", "var", ".", "to_s", "]", "=", "value", "}", "end" ]
Calls a block of code with a modified set of environment variables, restoring them once the code has executed. @param env [Hash] environment variables to set
[ "Calls", "a", "block", "of", "code", "with", "a", "modified", "set", "of", "environment", "variables", "restoring", "them", "once", "the", "code", "has", "executed", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L143-L153
train
sds/haml-lint
lib/haml_lint/rake_task.rb
HamlLint.RakeTask.run_cli
def run_cli(task_args) cli_args = parse_args logger = quiet ? HamlLint::Logger.silent : HamlLint::Logger.new(STDOUT) result = HamlLint::CLI.new(logger).run(Array(cli_args) + files_to_lint(task_args)) fail "#{HamlLint::APP_NAME} failed with exit code #{result}" unless result == 0 end
ruby
def run_cli(task_args) cli_args = parse_args logger = quiet ? HamlLint::Logger.silent : HamlLint::Logger.new(STDOUT) result = HamlLint::CLI.new(logger).run(Array(cli_args) + files_to_lint(task_args)) fail "#{HamlLint::APP_NAME} failed with exit code #{result}" unless result == 0 end
[ "def", "run_cli", "(", "task_args", ")", "cli_args", "=", "parse_args", "logger", "=", "quiet", "?", "HamlLint", "::", "Logger", ".", "silent", ":", "HamlLint", "::", "Logger", ".", "new", "(", "STDOUT", ")", "result", "=", "HamlLint", "::", "CLI", ".", "new", "(", "logger", ")", ".", "run", "(", "Array", "(", "cli_args", ")", "+", "files_to_lint", "(", "task_args", ")", ")", "fail", "\"#{HamlLint::APP_NAME} failed with exit code #{result}\"", "unless", "result", "==", "0", "end" ]
Executes the CLI given the specified task arguments. @param task_args [Rake::TaskArguments]
[ "Executes", "the", "CLI", "given", "the", "specified", "task", "arguments", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/rake_task.rb#L105-L111
train
sds/haml-lint
lib/haml_lint/rake_task.rb
HamlLint.RakeTask.files_to_lint
def files_to_lint(task_args) # Note: we're abusing Rake's argument handling a bit here. We call the # first argument `files` but it's actually only the first file--we pull # the rest out of the `extras` from the task arguments. This is so we # can specify an arbitrary list of files separated by commas on the # command line or in a custom task definition. explicit_files = Array(task_args[:files]) + Array(task_args.extras) explicit_files.any? ? explicit_files : files end
ruby
def files_to_lint(task_args) # Note: we're abusing Rake's argument handling a bit here. We call the # first argument `files` but it's actually only the first file--we pull # the rest out of the `extras` from the task arguments. This is so we # can specify an arbitrary list of files separated by commas on the # command line or in a custom task definition. explicit_files = Array(task_args[:files]) + Array(task_args.extras) explicit_files.any? ? explicit_files : files end
[ "def", "files_to_lint", "(", "task_args", ")", "# Note: we're abusing Rake's argument handling a bit here. We call the", "# first argument `files` but it's actually only the first file--we pull", "# the rest out of the `extras` from the task arguments. This is so we", "# can specify an arbitrary list of files separated by commas on the", "# command line or in a custom task definition.", "explicit_files", "=", "Array", "(", "task_args", "[", ":files", "]", ")", "+", "Array", "(", "task_args", ".", "extras", ")", "explicit_files", ".", "any?", "?", "explicit_files", ":", "files", "end" ]
Returns the list of files that should be linted given the specified task arguments. @param task_args [Rake::TaskArguments]
[ "Returns", "the", "list", "of", "files", "that", "should", "be", "linted", "given", "the", "specified", "task", "arguments", "." ]
024c773667e54cf88db938c2b368977005d70ee8
https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/rake_task.rb#L117-L126
train
sensu/sensu
lib/sensu/daemon.rb
Sensu.Daemon.log_notices
def log_notices(notices=[], level=:warn) notices.each do |concern| message = concern.delete(:message) @logger.send(level, message, redact_sensitive(concern)) end end
ruby
def log_notices(notices=[], level=:warn) notices.each do |concern| message = concern.delete(:message) @logger.send(level, message, redact_sensitive(concern)) end end
[ "def", "log_notices", "(", "notices", "=", "[", "]", ",", "level", "=", ":warn", ")", "notices", ".", "each", "do", "|", "concern", "|", "message", "=", "concern", ".", "delete", "(", ":message", ")", "@logger", ".", "send", "(", "level", ",", "message", ",", "redact_sensitive", "(", "concern", ")", ")", "end", "end" ]
Log setting or extension loading notices, sensitive information is redacted. @param notices [Array] to be logged. @param level [Symbol] to log the notices at.
[ "Log", "setting", "or", "extension", "loading", "notices", "sensitive", "information", "is", "redacted", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/daemon.rb#L111-L116
train
sensu/sensu
lib/sensu/daemon.rb
Sensu.Daemon.setup_spawn
def setup_spawn @logger.info("configuring sensu spawn", :settings => @settings[:sensu][:spawn]) threadpool_size = @settings[:sensu][:spawn][:limit] + 10 @logger.debug("setting eventmachine threadpool size", :size => threadpool_size) EM::threadpool_size = threadpool_size Spawn.setup(@settings[:sensu][:spawn]) end
ruby
def setup_spawn @logger.info("configuring sensu spawn", :settings => @settings[:sensu][:spawn]) threadpool_size = @settings[:sensu][:spawn][:limit] + 10 @logger.debug("setting eventmachine threadpool size", :size => threadpool_size) EM::threadpool_size = threadpool_size Spawn.setup(@settings[:sensu][:spawn]) end
[ "def", "setup_spawn", "@logger", ".", "info", "(", "\"configuring sensu spawn\"", ",", ":settings", "=>", "@settings", "[", ":sensu", "]", "[", ":spawn", "]", ")", "threadpool_size", "=", "@settings", "[", ":sensu", "]", "[", ":spawn", "]", "[", ":limit", "]", "+", "10", "@logger", ".", "debug", "(", "\"setting eventmachine threadpool size\"", ",", ":size", "=>", "threadpool_size", ")", "EM", "::", "threadpool_size", "=", "threadpool_size", "Spawn", ".", "setup", "(", "@settings", "[", ":sensu", "]", "[", ":spawn", "]", ")", "end" ]
Set up Sensu spawn, creating a worker to create, control, and limit spawned child processes. This method adjusts the EventMachine thread pool size to accommodate the concurrent process spawn limit and other Sensu process operations. https://github.com/sensu/sensu-spawn
[ "Set", "up", "Sensu", "spawn", "creating", "a", "worker", "to", "create", "control", "and", "limit", "spawned", "child", "processes", ".", "This", "method", "adjusts", "the", "EventMachine", "thread", "pool", "size", "to", "accommodate", "the", "concurrent", "process", "spawn", "limit", "and", "other", "Sensu", "process", "operations", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/daemon.rb#L203-L209
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.retry_until_true
def retry_until_true(wait=0.5, &block) EM::Timer.new(wait) do unless block.call retry_until_true(wait, &block) end end end
ruby
def retry_until_true(wait=0.5, &block) EM::Timer.new(wait) do unless block.call retry_until_true(wait, &block) end end end
[ "def", "retry_until_true", "(", "wait", "=", "0.5", ",", "&", "block", ")", "EM", "::", "Timer", ".", "new", "(", "wait", ")", "do", "unless", "block", ".", "call", "retry_until_true", "(", "wait", ",", "block", ")", "end", "end", "end" ]
Retry a code block until it retures true. The first attempt and following retries are delayed. @param wait [Numeric] time to delay block calls. @param block [Proc] to call that needs to return true.
[ "Retry", "a", "code", "block", "until", "it", "retures", "true", ".", "The", "first", "attempt", "and", "following", "retries", "are", "delayed", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L25-L31
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.deep_merge
def deep_merge(hash_one, hash_two) merged = hash_one.dup hash_two.each do |key, value| merged[key] = case when hash_one[key].is_a?(Hash) && value.is_a?(Hash) deep_merge(hash_one[key], value) when hash_one[key].is_a?(Array) && value.is_a?(Array) (hash_one[key] + value).uniq else value end end merged end
ruby
def deep_merge(hash_one, hash_two) merged = hash_one.dup hash_two.each do |key, value| merged[key] = case when hash_one[key].is_a?(Hash) && value.is_a?(Hash) deep_merge(hash_one[key], value) when hash_one[key].is_a?(Array) && value.is_a?(Array) (hash_one[key] + value).uniq else value end end merged end
[ "def", "deep_merge", "(", "hash_one", ",", "hash_two", ")", "merged", "=", "hash_one", ".", "dup", "hash_two", ".", "each", "do", "|", "key", ",", "value", "|", "merged", "[", "key", "]", "=", "case", "when", "hash_one", "[", "key", "]", ".", "is_a?", "(", "Hash", ")", "&&", "value", ".", "is_a?", "(", "Hash", ")", "deep_merge", "(", "hash_one", "[", "key", "]", ",", "value", ")", "when", "hash_one", "[", "key", "]", ".", "is_a?", "(", "Array", ")", "&&", "value", ".", "is_a?", "(", "Array", ")", "(", "hash_one", "[", "key", "]", "+", "value", ")", ".", "uniq", "else", "value", "end", "end", "merged", "end" ]
Deep merge two hashes. Nested hashes are deep merged, arrays are concatenated and duplicate array items are removed. @param hash_one [Hash] @param hash_two [Hash] @return [Hash] deep merged hash.
[ "Deep", "merge", "two", "hashes", ".", "Nested", "hashes", "are", "deep", "merged", "arrays", "are", "concatenated", "and", "duplicate", "array", "items", "are", "removed", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L39-L52
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.deep_dup
def deep_dup(obj) if obj.class == Hash new_obj = obj.dup new_obj.each do |key, value| new_obj[deep_dup(key)] = deep_dup(value) end new_obj elsif obj.class == Array arr = [] obj.each do |item| arr << deep_dup(item) end arr elsif obj.class == String obj.dup else obj end end
ruby
def deep_dup(obj) if obj.class == Hash new_obj = obj.dup new_obj.each do |key, value| new_obj[deep_dup(key)] = deep_dup(value) end new_obj elsif obj.class == Array arr = [] obj.each do |item| arr << deep_dup(item) end arr elsif obj.class == String obj.dup else obj end end
[ "def", "deep_dup", "(", "obj", ")", "if", "obj", ".", "class", "==", "Hash", "new_obj", "=", "obj", ".", "dup", "new_obj", ".", "each", "do", "|", "key", ",", "value", "|", "new_obj", "[", "deep_dup", "(", "key", ")", "]", "=", "deep_dup", "(", "value", ")", "end", "new_obj", "elsif", "obj", ".", "class", "==", "Array", "arr", "=", "[", "]", "obj", ".", "each", "do", "|", "item", "|", "arr", "<<", "deep_dup", "(", "item", ")", "end", "arr", "elsif", "obj", ".", "class", "==", "String", "obj", ".", "dup", "else", "obj", "end", "end" ]
Creates a deep dup of basic ruby objects with support for walking hashes and arrays. @param obj [Object] @return [obj] a dup of the original object.
[ "Creates", "a", "deep", "dup", "of", "basic", "ruby", "objects", "with", "support", "for", "walking", "hashes", "and", "arrays", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L59-L77
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.system_address
def system_address ::Socket.ip_address_list.find { |address| address.ipv4? && !address.ipv4_loopback? }.ip_address rescue nil end
ruby
def system_address ::Socket.ip_address_list.find { |address| address.ipv4? && !address.ipv4_loopback? }.ip_address rescue nil end
[ "def", "system_address", "::", "Socket", ".", "ip_address_list", ".", "find", "{", "|", "address", "|", "address", ".", "ipv4?", "&&", "!", "address", ".", "ipv4_loopback?", "}", ".", "ip_address", "rescue", "nil", "end" ]
Retrieve the system IP address. If a valid non-loopback IPv4 address cannot be found and an error is thrown, `nil` will be returned. @return [String] system ip address
[ "Retrieve", "the", "system", "IP", "address", ".", "If", "a", "valid", "non", "-", "loopback", "IPv4", "address", "cannot", "be", "found", "and", "an", "error", "is", "thrown", "nil", "will", "be", "returned", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L92-L96
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.find_attribute_value
def find_attribute_value(tree, path, default) attribute = tree[path.shift] if attribute.is_a?(Hash) find_attribute_value(attribute, path, default) else attribute.nil? ? default : attribute end end
ruby
def find_attribute_value(tree, path, default) attribute = tree[path.shift] if attribute.is_a?(Hash) find_attribute_value(attribute, path, default) else attribute.nil? ? default : attribute end end
[ "def", "find_attribute_value", "(", "tree", ",", "path", ",", "default", ")", "attribute", "=", "tree", "[", "path", ".", "shift", "]", "if", "attribute", ".", "is_a?", "(", "Hash", ")", "find_attribute_value", "(", "attribute", ",", "path", ",", "default", ")", "else", "attribute", ".", "nil?", "?", "default", ":", "attribute", "end", "end" ]
Traverse a hash for an attribute value, with a fallback default value if nil. @param tree [Hash] to traverse. @param path [Array] of attribute keys. @param default [Object] value if attribute value is nil. @return [Object] attribute or fallback default value.
[ "Traverse", "a", "hash", "for", "an", "attribute", "value", "with", "a", "fallback", "default", "value", "if", "nil", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L168-L175
train
sensu/sensu
lib/sensu/utilities.rb
Sensu.Utilities.determine_check_cron_time
def determine_check_cron_time(check) cron_parser = CronParser.new(check[:cron]) current_time = Time.now next_cron_time = cron_parser.next(current_time) next_cron_time - current_time end
ruby
def determine_check_cron_time(check) cron_parser = CronParser.new(check[:cron]) current_time = Time.now next_cron_time = cron_parser.next(current_time) next_cron_time - current_time end
[ "def", "determine_check_cron_time", "(", "check", ")", "cron_parser", "=", "CronParser", ".", "new", "(", "check", "[", ":cron", "]", ")", "current_time", "=", "Time", ".", "now", "next_cron_time", "=", "cron_parser", ".", "next", "(", "current_time", ")", "next_cron_time", "-", "current_time", "end" ]
Determine the next check cron time. @param check [Hash] definition.
[ "Determine", "the", "next", "check", "cron", "time", "." ]
51319e4b58c8d9986f101ad71ff729aa3e51e951
https://github.com/sensu/sensu/blob/51319e4b58c8d9986f101ad71ff729aa3e51e951/lib/sensu/utilities.rb#L390-L395
train
envato/double_entry
lib/active_record/locking_extensions.rb
ActiveRecord.LockingExtensions.with_restart_on_deadlock
def with_restart_on_deadlock yield rescue ActiveRecord::StatementInvalid => exception if exception.message =~ /deadlock/i || exception.message =~ /database is locked/i ActiveSupport::Notifications.publish('deadlock_restart.double_entry', :exception => exception) raise ActiveRecord::RestartTransaction else raise end end
ruby
def with_restart_on_deadlock yield rescue ActiveRecord::StatementInvalid => exception if exception.message =~ /deadlock/i || exception.message =~ /database is locked/i ActiveSupport::Notifications.publish('deadlock_restart.double_entry', :exception => exception) raise ActiveRecord::RestartTransaction else raise end end
[ "def", "with_restart_on_deadlock", "yield", "rescue", "ActiveRecord", "::", "StatementInvalid", "=>", "exception", "if", "exception", ".", "message", "=~", "/", "/i", "||", "exception", ".", "message", "=~", "/", "/i", "ActiveSupport", "::", "Notifications", ".", "publish", "(", "'deadlock_restart.double_entry'", ",", ":exception", "=>", "exception", ")", "raise", "ActiveRecord", "::", "RestartTransaction", "else", "raise", "end", "end" ]
Execute the given block, and retry the current restartable transaction if a MySQL deadlock occurs.
[ "Execute", "the", "given", "block", "and", "retry", "the", "current", "restartable", "transaction", "if", "a", "MySQL", "deadlock", "occurs", "." ]
2bc7ce1810a5b443d8bcdda44444569425d98c44
https://github.com/envato/double_entry/blob/2bc7ce1810a5b443d8bcdda44444569425d98c44/lib/active_record/locking_extensions.rb#L17-L27
train
envato/double_entry
lib/double_entry/balance_calculator.rb
DoubleEntry.BalanceCalculator.calculate
def calculate(account, args = {}) options = Options.new(account, args) relations = RelationBuilder.new(options) lines = relations.build if options.between? || options.code? # from and to or code lookups have to be done via sum Money.new(lines.sum(:amount), account.currency) else # all other lookups can be performed with running balances result = lines. from(lines_table_name(options)). order('id DESC'). limit(1). pluck(:balance) result.empty? ? Money.zero(account.currency) : Money.new(result.first, account.currency) end end
ruby
def calculate(account, args = {}) options = Options.new(account, args) relations = RelationBuilder.new(options) lines = relations.build if options.between? || options.code? # from and to or code lookups have to be done via sum Money.new(lines.sum(:amount), account.currency) else # all other lookups can be performed with running balances result = lines. from(lines_table_name(options)). order('id DESC'). limit(1). pluck(:balance) result.empty? ? Money.zero(account.currency) : Money.new(result.first, account.currency) end end
[ "def", "calculate", "(", "account", ",", "args", "=", "{", "}", ")", "options", "=", "Options", ".", "new", "(", "account", ",", "args", ")", "relations", "=", "RelationBuilder", ".", "new", "(", "options", ")", "lines", "=", "relations", ".", "build", "if", "options", ".", "between?", "||", "options", ".", "code?", "# from and to or code lookups have to be done via sum", "Money", ".", "new", "(", "lines", ".", "sum", "(", ":amount", ")", ",", "account", ".", "currency", ")", "else", "# all other lookups can be performed with running balances", "result", "=", "lines", ".", "from", "(", "lines_table_name", "(", "options", ")", ")", ".", "order", "(", "'id DESC'", ")", ".", "limit", "(", "1", ")", ".", "pluck", "(", ":balance", ")", "result", ".", "empty?", "?", "Money", ".", "zero", "(", "account", ".", "currency", ")", ":", "Money", ".", "new", "(", "result", ".", "first", ",", "account", ".", "currency", ")", "end", "end" ]
Get the current or historic balance of an account. @param account [DoubleEntry::Account:Instance] @option args :from [Time] @option args :to [Time] @option args :at [Time] @option args :code [Symbol] @option args :codes [Array<Symbol>] @return [Money]
[ "Get", "the", "current", "or", "historic", "balance", "of", "an", "account", "." ]
2bc7ce1810a5b443d8bcdda44444569425d98c44
https://github.com/envato/double_entry/blob/2bc7ce1810a5b443d8bcdda44444569425d98c44/lib/double_entry/balance_calculator.rb#L16-L33
train
cheezy/page-object
lib/page-object/page_populator.rb
PageObject.PagePopulator.populate_page_with
def populate_page_with(data) data.to_h.each do |key, value| populate_section(key, value) if value.respond_to?(:to_h) populate_value(self, key, value) end end
ruby
def populate_page_with(data) data.to_h.each do |key, value| populate_section(key, value) if value.respond_to?(:to_h) populate_value(self, key, value) end end
[ "def", "populate_page_with", "(", "data", ")", "data", ".", "to_h", ".", "each", "do", "|", "key", ",", "value", "|", "populate_section", "(", "key", ",", "value", ")", "if", "value", ".", "respond_to?", "(", ":to_h", ")", "populate_value", "(", "self", ",", "key", ",", "value", ")", "end", "end" ]
This method will populate all matched page TextFields, TextAreas, SelectLists, FileFields, Checkboxes, and Radio Buttons from the Hash passed as an argument. The way it find an element is by matching the Hash key to the name you provided when declaring the element on your page. Checkbox and Radio Button values must be true or false. @example class ExamplePage include PageObject text_field(:username, :id => 'username_id') checkbox(:active, :id => 'active_id') end ... @browser = Watir::Browser.new :firefox example_page = ExamplePage.new(@browser) example_page.populate_page_with :username => 'a name', :active => true @param data [Hash] the data to use to populate this page. The key can be either a string or a symbol. The value must be a string for TextField, TextArea, SelectList, and FileField and must be true or false for a Checkbox or RadioButton.
[ "This", "method", "will", "populate", "all", "matched", "page", "TextFields", "TextAreas", "SelectLists", "FileFields", "Checkboxes", "and", "Radio", "Buttons", "from", "the", "Hash", "passed", "as", "an", "argument", ".", "The", "way", "it", "find", "an", "element", "is", "by", "matching", "the", "Hash", "key", "to", "the", "name", "you", "provided", "when", "declaring", "the", "element", "on", "your", "page", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/page_populator.rb#L32-L37
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.page_url
def page_url(url) define_method("goto") do platform.navigate_to self.page_url_value end define_method('page_url_value') do lookup = url.kind_of?(Symbol) ? self.send(url) : url erb = ERB.new(%Q{#{lookup}}) merged_params = self.class.instance_variable_get("@merged_params") params = merged_params ? merged_params : self.class.params erb.result(binding) end end
ruby
def page_url(url) define_method("goto") do platform.navigate_to self.page_url_value end define_method('page_url_value') do lookup = url.kind_of?(Symbol) ? self.send(url) : url erb = ERB.new(%Q{#{lookup}}) merged_params = self.class.instance_variable_get("@merged_params") params = merged_params ? merged_params : self.class.params erb.result(binding) end end
[ "def", "page_url", "(", "url", ")", "define_method", "(", "\"goto\"", ")", "do", "platform", ".", "navigate_to", "self", ".", "page_url_value", "end", "define_method", "(", "'page_url_value'", ")", "do", "lookup", "=", "url", ".", "kind_of?", "(", "Symbol", ")", "?", "self", ".", "send", "(", "url", ")", ":", "url", "erb", "=", "ERB", ".", "new", "(", "%Q{#{lookup}}", ")", "merged_params", "=", "self", ".", "class", ".", "instance_variable_get", "(", "\"@merged_params\"", ")", "params", "=", "merged_params", "?", "merged_params", ":", "self", ".", "class", ".", "params", "erb", ".", "result", "(", "binding", ")", "end", "end" ]
Specify the url for the page. A call to this method will generate a 'goto' method to take you to the page. @param [String] the url for the page. @param [Symbol] a method name to call to get the url
[ "Specify", "the", "url", "for", "the", "page", ".", "A", "call", "to", "this", "method", "will", "generate", "a", "goto", "method", "to", "take", "you", "to", "the", "page", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L37-L49
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.in_frame
def in_frame(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {frame: identifier} block.call(frame) end
ruby
def in_frame(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {frame: identifier} block.call(frame) end
[ "def", "in_frame", "(", "identifier", ",", "frame", "=", "nil", ",", "&", "block", ")", "frame", "=", "frame", ".", "nil?", "?", "[", "]", ":", "frame", ".", "dup", "frame", "<<", "{", "frame", ":", "identifier", "}", "block", ".", "call", "(", "frame", ")", "end" ]
Identify an element as existing within a frame . A frame parameter is passed to the block and must be passed to the other calls to PageObject. You can nest calls to in_frame by passing the frame to the next level. @example in_frame(:id => 'frame_id') do |frame| text_field(:first_name, :id => 'fname', :frame => frame) end @param [Hash] identifier how we find the frame. The valid keys are: * :id * :index * :name * :regexp @param frame passed from a previous call to in_frame. Used to nest calls @param block that contains the calls to elements that exist inside the frame.
[ "Identify", "an", "element", "as", "existing", "within", "a", "frame", ".", "A", "frame", "parameter", "is", "passed", "to", "the", "block", "and", "must", "be", "passed", "to", "the", "other", "calls", "to", "PageObject", ".", "You", "can", "nest", "calls", "to", "in_frame", "by", "passing", "the", "frame", "to", "the", "next", "level", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L152-L156
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.in_iframe
def in_iframe(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {iframe: identifier} block.call(frame) end
ruby
def in_iframe(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {iframe: identifier} block.call(frame) end
[ "def", "in_iframe", "(", "identifier", ",", "frame", "=", "nil", ",", "&", "block", ")", "frame", "=", "frame", ".", "nil?", "?", "[", "]", ":", "frame", ".", "dup", "frame", "<<", "{", "iframe", ":", "identifier", "}", "block", ".", "call", "(", "frame", ")", "end" ]
Identify an element as existing within an iframe. A frame parameter is passed to the block and must be passed to the other calls to PageObject. You can nest calls to in_frame by passing the frame to the next level. @example in_iframe(:id => 'frame_id') do |frame| text_field(:first_name, :id => 'fname', :frame => frame) end @param [Hash] identifier how we find the frame. The valid keys are: * :id * :index * :name * :regexp @param frame passed from a previous call to in_iframe. Used to nest calls @param block that contains the calls to elements that exist inside the iframe.
[ "Identify", "an", "element", "as", "existing", "within", "an", "iframe", ".", "A", "frame", "parameter", "is", "passed", "to", "the", "block", "and", "must", "be", "passed", "to", "the", "other", "calls", "to", "PageObject", ".", "You", "can", "nest", "calls", "to", "in_frame", "by", "passing", "the", "frame", "to", "the", "next", "level", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L176-L180
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.text_field
def text_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_field_for', &block) define_method(name) do return platform.text_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
ruby
def text_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_field_for', &block) define_method(name) do return platform.text_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
[ "def", "text_field", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'text_field_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "text_field_value_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "end", "define_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "return", "platform", ".", "text_field_value_set", "(", "identifier", ".", "clone", ",", "value", ")", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "=", "value", "end", "end" ]
adds four methods to the page object - one to set text in a text field, another to retrieve text from a text field, another to return the text field element, another to check the text field's existence. @example text_field(:first_name, :id => "first_name") # will generate 'first_name', 'first_name=', 'first_name_element', # 'first_name?' methods @param [String] the name used for the generated methods @param [Hash] identifier how we find a text field. @param optional block to be invoked when element method is called
[ "adds", "four", "methods", "to", "the", "page", "object", "-", "one", "to", "set", "text", "in", "a", "text", "field", "another", "to", "retrieve", "text", "from", "a", "text", "field", "another", "to", "return", "the", "text", "field", "element", "another", "to", "check", "the", "text", "field", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L196-L206
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.hidden_field
def hidden_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'hidden_field_for', &block) define_method(name) do return platform.hidden_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end end
ruby
def hidden_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'hidden_field_for', &block) define_method(name) do return platform.hidden_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end end
[ "def", "hidden_field", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'hidden_field_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "hidden_field_value_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "end", "end" ]
adds three methods to the page object - one to get the text from a hidden field, another to retrieve the hidden field element, and another to check the hidden field's existence. @example hidden_field(:user_id, :id => "user_identity") # will generate 'user_id', 'user_id_element' and 'user_id?' methods @param [String] the name used for the generated methods @param [Hash] identifier how we find a hidden field. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "to", "the", "page", "object", "-", "one", "to", "get", "the", "text", "from", "a", "hidden", "field", "another", "to", "retrieve", "the", "hidden", "field", "element", "and", "another", "to", "check", "the", "hidden", "field", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L221-L227
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.text_area
def text_area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_area_for', &block) define_method(name) do return platform.text_area_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_area_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
ruby
def text_area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_area_for', &block) define_method(name) do return platform.text_area_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_area_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
[ "def", "text_area", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'text_area_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "text_area_value_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "end", "define_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "return", "platform", ".", "text_area_value_set", "(", "identifier", ".", "clone", ",", "value", ")", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "=", "value", "end", "end" ]
adds four methods to the page object - one to set text in a text area, another to retrieve text from a text area, another to return the text area element, and another to check the text area's existence. @example text_area(:address, :id => "address") # will generate 'address', 'address=', 'address_element', # 'address?' methods @param [String] the name used for the generated methods @param [Hash] identifier how we find a text area. @param optional block to be invoked when element method is called
[ "adds", "four", "methods", "to", "the", "page", "object", "-", "one", "to", "set", "text", "in", "a", "text", "area", "another", "to", "retrieve", "text", "from", "a", "text", "area", "another", "to", "return", "the", "text", "area", "element", "and", "another", "to", "check", "the", "text", "area", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L244-L254
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.select_list
def select_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'select_list_for', &block) define_method(name) do return platform.select_list_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.select_list_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").select(value) end define_method("#{name}_options") do element = self.send("#{name}_element") (element && element.options) ? element.options.collect(&:text) : [] end end
ruby
def select_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'select_list_for', &block) define_method(name) do return platform.select_list_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.select_list_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").select(value) end define_method("#{name}_options") do element = self.send("#{name}_element") (element && element.options) ? element.options.collect(&:text) : [] end end
[ "def", "select_list", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'select_list_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "select_list_value_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "end", "define_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "return", "platform", ".", "select_list_value_set", "(", "identifier", ".", "clone", ",", "value", ")", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "select", "(", "value", ")", "end", "define_method", "(", "\"#{name}_options\"", ")", "do", "element", "=", "self", ".", "send", "(", "\"#{name}_element\"", ")", "(", "element", "&&", "element", ".", "options", ")", "?", "element", ".", "options", ".", "collect", "(", ":text", ")", ":", "[", "]", "end", "end" ]
adds five methods - one to select an item in a drop-down, another to fetch the currently selected item text, another to retrieve the select list element, another to check the drop down's existence and another to get all the available options to select from. @example select_list(:state, :id => "state") # will generate 'state', 'state=', 'state_element', 'state?', "state_options" methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a select list. @param optional block to be invoked when element method is called
[ "adds", "five", "methods", "-", "one", "to", "select", "an", "item", "in", "a", "drop", "-", "down", "another", "to", "fetch", "the", "currently", "selected", "item", "text", "another", "to", "retrieve", "the", "select", "list", "element", "another", "to", "check", "the", "drop", "down", "s", "existence", "and", "another", "to", "get", "all", "the", "available", "options", "to", "select", "from", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L272-L286
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.button
def button(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'button_for', &block) define_method(name) do return platform.click_button_for identifier.clone unless block_given? self.send("#{name}_element").click end end
ruby
def button(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'button_for', &block) define_method(name) do return platform.click_button_for identifier.clone unless block_given? self.send("#{name}_element").click end end
[ "def", "button", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'button_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "click_button_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "click", "end", "end" ]
adds three methods - one to click a button, another to return the button element, and another to check the button's existence. @example button(:purchase, :id => 'purchase') # will generate 'purchase', 'purchase_element', and 'purchase?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a button. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "click", "a", "button", "another", "to", "return", "the", "button", "element", "and", "another", "to", "check", "the", "button", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L432-L438
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.div
def div(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'div_for', &block) define_method(name) do return platform.div_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def div(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'div_for', &block) define_method(name) do return platform.div_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "div", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'div_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "div_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a div, another to return the div element, and another to check the div's existence. @example div(:message, :id => 'message') # will generate 'message', 'message_element', and 'message?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a div. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "div", "another", "to", "return", "the", "div", "element", "and", "another", "to", "check", "the", "div", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L452-L458
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.span
def span(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'span_for', &block) define_method(name) do return platform.span_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def span(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'span_for', &block) define_method(name) do return platform.span_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "span", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'span_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "span_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a span, another to return the span element, and another to check the span's existence. @example span(:alert, :id => 'alert') # will generate 'alert', 'alert_element', and 'alert?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a span. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "span", "another", "to", "return", "the", "span", "element", "and", "another", "to", "check", "the", "span", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L472-L478
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.table
def table(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'table_for', &block) define_method(name) do return platform.table_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def table(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'table_for', &block) define_method(name) do return platform.table_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "table", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'table_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "table_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to return the text for the table, one to retrieve the table element, and another to check the table's existence. @example table(:cart, :id => 'shopping_cart') # will generate a 'cart', 'cart_element' and 'cart?' method @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a table. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "return", "the", "text", "for", "the", "table", "one", "to", "retrieve", "the", "table", "element", "and", "another", "to", "check", "the", "table", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L493-L499
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.cell
def cell(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'cell_for', &block) define_method("#{name}") do return platform.cell_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def cell(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'cell_for', &block) define_method("#{name}") do return platform.cell_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "cell", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'cell_for'", ",", "block", ")", "define_method", "(", "\"#{name}\"", ")", "do", "return", "platform", ".", "cell_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a table cell, another to return the table cell element, and another to check the cell's existence. @example cell(:total, :id => 'total_cell') # will generate 'total', 'total_element', and 'total?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a cell. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "table", "cell", "another", "to", "return", "the", "table", "cell", "element", "and", "another", "to", "check", "the", "cell", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L514-L520
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.row
def row(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'row_for', &block) define_method("#{name}") do return platform.row_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def row(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'row_for', &block) define_method("#{name}") do return platform.row_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "row", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'row_for'", ",", "block", ")", "define_method", "(", "\"#{name}\"", ")", "do", "return", "platform", ".", "row_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a table row, another to return the table row element, and another to check the row's existence. @example row(:sums, :id => 'sum_row') # will generate 'sums', 'sums_element', and 'sums?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a cell. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "table", "row", "another", "to", "return", "the", "table", "row", "element", "and", "another", "to", "check", "the", "row", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L537-L543
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.image
def image(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'image_for', &block) define_method("#{name}_loaded?") do return platform.image_loaded_for identifier.clone unless block_given? self.send("#{name}_element").loaded? end end
ruby
def image(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'image_for', &block) define_method("#{name}_loaded?") do return platform.image_loaded_for identifier.clone unless block_given? self.send("#{name}_element").loaded? end end
[ "def", "image", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'image_for'", ",", "block", ")", "define_method", "(", "\"#{name}_loaded?\"", ")", "do", "return", "platform", ".", "image_loaded_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "loaded?", "end", "end" ]
adds three methods - one to retrieve the image element, another to check the load status of the image, and another to check the image's existence. @example image(:logo, :id => 'logo') # will generate 'logo_element', 'logo_loaded?', and 'logo?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find an image. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "image", "element", "another", "to", "check", "the", "load", "status", "of", "the", "image", "and", "another", "to", "check", "the", "image", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L558-L564
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.list_item
def list_item(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'list_item_for', &block) define_method(name) do return platform.list_item_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def list_item(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'list_item_for', &block) define_method(name) do return platform.list_item_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "list_item", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'list_item_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "list_item_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a list item, another to return the list item element, and another to check the list item's existence. @example list_item(:item_one, :id => 'one') # will generate 'item_one', 'item_one_element', and 'item_one?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a list item. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "list", "item", "another", "to", "return", "the", "list", "item", "element", "and", "another", "to", "check", "the", "list", "item", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L596-L602
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.unordered_list
def unordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'unordered_list_for', &block) define_method(name) do return platform.unordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def unordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'unordered_list_for', &block) define_method(name) do return platform.unordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "unordered_list", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'unordered_list_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "unordered_list_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to return the text within the unordered list, one to retrieve the unordered list element, and another to check it's existence. @example unordered_list(:menu, :id => 'main_menu') # will generate 'menu', 'menu_element' and 'menu?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find an unordered list. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "return", "the", "text", "within", "the", "unordered", "list", "one", "to", "retrieve", "the", "unordered", "list", "element", "and", "another", "to", "check", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L618-L624
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.ordered_list
def ordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'ordered_list_for', &block) define_method(name) do return platform.ordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def ordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'ordered_list_for', &block) define_method(name) do return platform.ordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "ordered_list", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'ordered_list_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "ordered_list_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to return the text within the ordered list, one to retrieve the ordered list element, and another to test it's existence. @example ordered_list(:top_five, :id => 'top') # will generate 'top_five', 'top_five_element' and 'top_five?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find an ordered list. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "return", "the", "text", "within", "the", "ordered", "list", "one", "to", "retrieve", "the", "ordered", "list", "element", "and", "another", "to", "test", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L640-L646
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h1
def h1(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'h1_for', &block) define_method(name) do return platform.h1_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h1(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'h1_for', &block) define_method(name) do return platform.h1_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h1", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h1_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h1_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h1 element, another to retrieve a h1 element, and another to check for it's existence. @example h1(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H1. You can use a multiple parameters by combining of any of the following except xpath. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h1", "element", "another", "to", "retrieve", "a", "h1", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L662-L668
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h2
def h2(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h2_for', &block) define_method(name) do return platform.h2_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h2(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h2_for', &block) define_method(name) do return platform.h2_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h2", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h2_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h2_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h2 element, another to retrieve a h2 element, and another to check for it's existence. @example h2(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H2. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h2", "element", "another", "to", "retrieve", "a", "h2", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L682-L688
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h3
def h3(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h3_for', &block) define_method(name) do return platform.h3_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h3(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h3_for', &block) define_method(name) do return platform.h3_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h3", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h3_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h3_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h3 element, another to return a h3 element, and another to check for it's existence. @example h3(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H3. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h3", "element", "another", "to", "return", "a", "h3", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L702-L708
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h4
def h4(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h4_for', &block) define_method(name) do return platform.h4_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h4(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h4_for', &block) define_method(name) do return platform.h4_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h4", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h4_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h4_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h4 element, another to return a h4 element, and another to check for it's existence. @example h4(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H4. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h4", "element", "another", "to", "return", "a", "h4", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L722-L728
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h5
def h5(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h5_for', &block) define_method(name) do return platform.h5_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h5(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h5_for', &block) define_method(name) do return platform.h5_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h5", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h5_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h5_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h5 element, another to return a h5 element, and another to check for it's existence. @example h5(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H5. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h5", "element", "another", "to", "return", "a", "h5", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L742-L748
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.h6
def h6(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h6_for', &block) define_method(name) do return platform.h6_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def h6(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h6_for', &block) define_method(name) do return platform.h6_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "h6", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'h6_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "h6_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a h6 element, another to return a h6 element, and another to check for it's existence. @example h6(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a H6. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "h6", "element", "another", "to", "return", "a", "h6", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L762-L768
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.paragraph
def paragraph(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'paragraph_for', &block) define_method(name) do return platform.paragraph_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def paragraph(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'paragraph_for', &block) define_method(name) do return platform.paragraph_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "paragraph", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'paragraph_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "paragraph_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a paragraph, another to retrieve a paragraph element, and another to check the paragraph's existence. @example paragraph(:title, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a paragraph. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "paragraph", "another", "to", "retrieve", "a", "paragraph", "element", "and", "another", "to", "check", "the", "paragraph", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L782-L788
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.file_field
def file_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'file_field_for', &block) define_method("#{name}=") do |value| return platform.file_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
ruby
def file_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'file_field_for', &block) define_method("#{name}=") do |value| return platform.file_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end
[ "def", "file_field", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'file_field_for'", ",", "block", ")", "define_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "return", "platform", ".", "file_field_value_set", "(", "identifier", ".", "clone", ",", "value", ")", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "value", "=", "value", "end", "end" ]
adds three methods - one to set the file for a file field, another to retrieve the file field element, and another to check it's existence. @example file_field(:the_file, :id => 'file_to_upload') # will generate 'the_file=', 'the_file_element', and 'the_file?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a file_field. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "set", "the", "file", "for", "a", "file", "field", "another", "to", "retrieve", "the", "file", "field", "element", "and", "another", "to", "check", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L803-L809
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.label
def label(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'label_for', &block) define_method(name) do return platform.label_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def label(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'label_for', &block) define_method(name) do return platform.label_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "label", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'label_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "label_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text from a label, another to return the label element, and another to check the label's existence. @example label(:message, :id => 'message') # will generate 'message', 'message_element', and 'message?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a label. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "from", "a", "label", "another", "to", "return", "the", "label", "element", "and", "another", "to", "check", "the", "label", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L823-L829
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.area
def area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'area_for', &block) define_method(name) do return platform.click_area_for identifier.clone unless block_given? self.send("#{name}_element").click end end
ruby
def area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'area_for', &block) define_method(name) do return platform.click_area_for identifier.clone unless block_given? self.send("#{name}_element").click end end
[ "def", "area", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'area_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "click_area_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "click", "end", "end" ]
adds three methods - one to click the area, another to return the area element, and another to check the area's existence. @example area(:message, :id => 'message') # will generate 'message', 'message_element', and 'message?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find an area. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "click", "the", "area", "another", "to", "return", "the", "area", "element", "and", "another", "to", "check", "the", "area", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L843-L849
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.b
def b(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'b_for', &block) define_method(name) do return platform.b_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def b(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'b_for', &block) define_method(name) do return platform.b_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "b", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'b_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "b_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a b element, another to retrieve a b element, and another to check for it's existence. @example b(:bold, :id => 'title') # will generate 'bold', 'bold_element', and 'bold?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a b. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "b", "element", "another", "to", "retrieve", "a", "b", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L911-L917
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.i
def i(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'i_for', &block) define_method(name) do return platform.i_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
ruby
def i(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'i_for', &block) define_method(name) do return platform.i_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end
[ "def", "i", "(", "name", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "standard_methods", "(", "name", ",", "identifier", ",", "'i_for'", ",", "block", ")", "define_method", "(", "name", ")", "do", "return", "platform", ".", "i_text_for", "identifier", ".", "clone", "unless", "block_given?", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "text", "end", "end" ]
adds three methods - one to retrieve the text of a i element, another to retrieve a i element, and another to check for it's existence. @example i(:italic, :id => 'title') # will generate 'italic', 'italic_element', and 'italic?' methods @param [Symbol] the name used for the generated methods @param [Hash] identifier how we find a i. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "a", "i", "element", "another", "to", "retrieve", "a", "i", "element", "and", "another", "to", "check", "for", "it", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L931-L937
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.element
def element(name, tag=:element, identifier={ :index => 0 }, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end standard_methods(name, identifier, 'element_for', &block) define_method("#{name}") do element = self.send("#{name}_element") %w(Button TextField Radio Hidden CheckBox FileField).each do |klass| next unless element.element.class.to_s == "Watir::#{klass}" self.class.send(klass.gsub(/(.)([A-Z])/,'\1_\2').downcase, name, identifier, &block) return self.send name end element.text end define_method("#{name}_element") do return call_block(&block) if block_given? platform.element_for(tag, identifier.clone) end define_method("#{name}?") do self.send("#{name}_element").exists? end define_method("#{name}=") do |value| element = self.send("#{name}_element") klass = case element.element when Watir::TextField 'text_field' when Watir::TextArea 'text_area' when Watir::Select 'select_list' when Watir::FileField 'file_field' else raise "Can not set a #{element.element} element with #=" end self.class.send(klass, name, identifier, &block) self.send("#{name}=", value) end end
ruby
def element(name, tag=:element, identifier={ :index => 0 }, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end standard_methods(name, identifier, 'element_for', &block) define_method("#{name}") do element = self.send("#{name}_element") %w(Button TextField Radio Hidden CheckBox FileField).each do |klass| next unless element.element.class.to_s == "Watir::#{klass}" self.class.send(klass.gsub(/(.)([A-Z])/,'\1_\2').downcase, name, identifier, &block) return self.send name end element.text end define_method("#{name}_element") do return call_block(&block) if block_given? platform.element_for(tag, identifier.clone) end define_method("#{name}?") do self.send("#{name}_element").exists? end define_method("#{name}=") do |value| element = self.send("#{name}_element") klass = case element.element when Watir::TextField 'text_field' when Watir::TextArea 'text_area' when Watir::Select 'select_list' when Watir::FileField 'file_field' else raise "Can not set a #{element.element} element with #=" end self.class.send(klass, name, identifier, &block) self.send("#{name}=", value) end end
[ "def", "element", "(", "name", ",", "tag", "=", ":element", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "#", "# sets tag as element if not defined", "#", "if", "tag", ".", "is_a?", "(", "Hash", ")", "identifier", "=", "tag", "tag", "=", ":element", "end", "standard_methods", "(", "name", ",", "identifier", ",", "'element_for'", ",", "block", ")", "define_method", "(", "\"#{name}\"", ")", "do", "element", "=", "self", ".", "send", "(", "\"#{name}_element\"", ")", "%w(", "Button", "TextField", "Radio", "Hidden", "CheckBox", "FileField", ")", ".", "each", "do", "|", "klass", "|", "next", "unless", "element", ".", "element", ".", "class", ".", "to_s", "==", "\"Watir::#{klass}\"", "self", ".", "class", ".", "send", "(", "klass", ".", "gsub", "(", "/", "/", ",", "'\\1_\\2'", ")", ".", "downcase", ",", "name", ",", "identifier", ",", "block", ")", "return", "self", ".", "send", "name", "end", "element", ".", "text", "end", "define_method", "(", "\"#{name}_element\"", ")", "do", "return", "call_block", "(", "block", ")", "if", "block_given?", "platform", ".", "element_for", "(", "tag", ",", "identifier", ".", "clone", ")", "end", "define_method", "(", "\"#{name}?\"", ")", "do", "self", ".", "send", "(", "\"#{name}_element\"", ")", ".", "exists?", "end", "define_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "element", "=", "self", ".", "send", "(", "\"#{name}_element\"", ")", "klass", "=", "case", "element", ".", "element", "when", "Watir", "::", "TextField", "'text_field'", "when", "Watir", "::", "TextArea", "'text_area'", "when", "Watir", "::", "Select", "'select_list'", "when", "Watir", "::", "FileField", "'file_field'", "else", "raise", "\"Can not set a #{element.element} element with #=\"", "end", "self", ".", "class", ".", "send", "(", "klass", ",", "name", ",", "identifier", ",", "block", ")", "self", ".", "send", "(", "\"#{name}=\"", ",", "value", ")", "end", "end" ]
adds three methods - one to retrieve the text of an element, another to retrieve an element, and another to check the element's existence. @example element(:title, :header, :id => 'title') # will generate 'title', 'title_element', and 'title?' methods @param [Symbol] the name used for the generated methods @param [Symbol] the name of the tag for the element @param [Hash] identifier how we find an element. @param optional block to be invoked when element method is called
[ "adds", "three", "methods", "-", "one", "to", "retrieve", "the", "text", "of", "an", "element", "another", "to", "retrieve", "an", "element", "and", "another", "to", "check", "the", "element", "s", "existence", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L970-L1016
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.elements
def elements(name, tag=:element, identifier={:index => 0}, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end define_method("#{name}_elements") do return call_block(&block) if block_given? platform.elements_for(tag, identifier.clone) end end
ruby
def elements(name, tag=:element, identifier={:index => 0}, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end define_method("#{name}_elements") do return call_block(&block) if block_given? platform.elements_for(tag, identifier.clone) end end
[ "def", "elements", "(", "name", ",", "tag", "=", ":element", ",", "identifier", "=", "{", ":index", "=>", "0", "}", ",", "&", "block", ")", "#", "# sets tag as element if not defined", "#", "if", "tag", ".", "is_a?", "(", "Hash", ")", "identifier", "=", "tag", "tag", "=", ":element", "end", "define_method", "(", "\"#{name}_elements\"", ")", "do", "return", "call_block", "(", "block", ")", "if", "block_given?", "platform", ".", "elements_for", "(", "tag", ",", "identifier", ".", "clone", ")", "end", "end" ]
adds a method to return a collection of generic Element objects for a specific tag. @example elements(:title, :header, :id => 'title') # will generate ''title_elements' @param [Symbol] the name used for the generated methods @param [Symbol] the name of the tag for the element @param [Hash] identifier how we find an element. @param optional block to be invoked when element method is called
[ "adds", "a", "method", "to", "return", "a", "collection", "of", "generic", "Element", "objects", "for", "a", "specific", "tag", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L1031-L1044
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.page_section
def page_section(name, section_class, identifier) define_method(name) do platform.page_for(identifier, section_class) end end
ruby
def page_section(name, section_class, identifier) define_method(name) do platform.page_for(identifier, section_class) end end
[ "def", "page_section", "(", "name", ",", "section_class", ",", "identifier", ")", "define_method", "(", "name", ")", "do", "platform", ".", "page_for", "(", "identifier", ",", "section_class", ")", "end", "end" ]
adds a method to return a page object rooted at an element @example page_section(:navigation_bar, NavigationBar, :id => 'nav-bar') # will generate 'navigation_bar' @param [Symbol] the name used for the generated methods @param [Class] the class to instantiate for the element @param [Hash] identifier how we find an element.
[ "adds", "a", "method", "to", "return", "a", "page", "object", "rooted", "at", "an", "element" ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L1057-L1061
train
cheezy/page-object
lib/page-object/accessors.rb
PageObject.Accessors.page_sections
def page_sections(name, section_class, identifier) define_method(name) do platform.pages_for(identifier, section_class) end end
ruby
def page_sections(name, section_class, identifier) define_method(name) do platform.pages_for(identifier, section_class) end end
[ "def", "page_sections", "(", "name", ",", "section_class", ",", "identifier", ")", "define_method", "(", "name", ")", "do", "platform", ".", "pages_for", "(", "identifier", ",", "section_class", ")", "end", "end" ]
adds a method to return a collection of page objects rooted at elements @example page_sections(:articles, Article, :class => 'article') # will generate 'articles' @param [Symbol] the name used for the generated method @param [Class] the class to instantiate for each element @param [Hash] identifier how we find an element.
[ "adds", "a", "method", "to", "return", "a", "collection", "of", "page", "objects", "rooted", "at", "elements" ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/accessors.rb#L1074-L1078
train
cheezy/page-object
lib/page-object/page_factory.rb
PageObject.PageFactory.on_page
def on_page(page_class, params={:using_params => {}}, visit=false, &block) page_class = class_from_string(page_class) if page_class.is_a? String return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject merged = page_class.params.merge(params[:using_params]) page_class.instance_variable_set("@merged_params", merged) unless merged.empty? @current_page = page_class.new(@browser, visit) block.call @current_page if block @current_page end
ruby
def on_page(page_class, params={:using_params => {}}, visit=false, &block) page_class = class_from_string(page_class) if page_class.is_a? String return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject merged = page_class.params.merge(params[:using_params]) page_class.instance_variable_set("@merged_params", merged) unless merged.empty? @current_page = page_class.new(@browser, visit) block.call @current_page if block @current_page end
[ "def", "on_page", "(", "page_class", ",", "params", "=", "{", ":using_params", "=>", "{", "}", "}", ",", "visit", "=", "false", ",", "&", "block", ")", "page_class", "=", "class_from_string", "(", "page_class", ")", "if", "page_class", ".", "is_a?", "String", "return", "super", "(", "page_class", ",", "params", ",", "visit", ",", "block", ")", "unless", "page_class", ".", "ancestors", ".", "include?", "PageObject", "merged", "=", "page_class", ".", "params", ".", "merge", "(", "params", "[", ":using_params", "]", ")", "page_class", ".", "instance_variable_set", "(", "\"@merged_params\"", ",", "merged", ")", "unless", "merged", ".", "empty?", "@current_page", "=", "page_class", ".", "new", "(", "@browser", ",", "visit", ")", "block", ".", "call", "@current_page", "if", "block", "@current_page", "end" ]
Create a page object. @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class @param Hash values that is pass through to page class a available in the @params instance variable. @param [Boolean] a boolean indicating if the page should be visited? default is false. @param [block] an optional block to be called @return [PageObject] the newly created page object
[ "Create", "a", "page", "object", "." ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/page_factory.rb#L69-L77
train
cheezy/page-object
lib/page-object/page_factory.rb
PageObject.PageFactory.if_page
def if_page(page_class, params={:using_params => {}},&block) page_class = class_from_string(page_class) if page_class.is_a? String return @current_page unless @current_page.class == page_class on_page(page_class, params, false, &block) end
ruby
def if_page(page_class, params={:using_params => {}},&block) page_class = class_from_string(page_class) if page_class.is_a? String return @current_page unless @current_page.class == page_class on_page(page_class, params, false, &block) end
[ "def", "if_page", "(", "page_class", ",", "params", "=", "{", ":using_params", "=>", "{", "}", "}", ",", "&", "block", ")", "page_class", "=", "class_from_string", "(", "page_class", ")", "if", "page_class", ".", "is_a?", "String", "return", "@current_page", "unless", "@current_page", ".", "class", "==", "page_class", "on_page", "(", "page_class", ",", "params", ",", "false", ",", "block", ")", "end" ]
Create a page object if and only if the current page is the same page to be created @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class @param Hash values that is pass through to page class a available in the @params instance variable. @param [block] an optional block to be called @return [PageObject] the newly created page object
[ "Create", "a", "page", "object", "if", "and", "only", "if", "the", "current", "page", "is", "the", "same", "page", "to", "be", "created" ]
850d775bf63768fbb1551a34480195785fe8e193
https://github.com/cheezy/page-object/blob/850d775bf63768fbb1551a34480195785fe8e193/lib/page-object/page_factory.rb#L91-L95
train
ohler55/oj
lib/oj/easy_hash.rb
Oj.EasyHash.method_missing
def method_missing(m, *args, &block) if m.to_s.end_with?('=') raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length m = m[0..-2] return store(m.to_s, args[0]) if has_key?(m.to_s) return store(m.to_sym, args[0]) if has_key?(m.to_sym) return store(m, args[0]) else raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty? return fetch(m, nil) if has_key?(m) return fetch(m.to_s, nil) if has_key?(m.to_s) return fetch(m.to_sym, nil) if has_key?(m.to_sym) end raise NoMethodError.new("undefined method #{m}", m) end
ruby
def method_missing(m, *args, &block) if m.to_s.end_with?('=') raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length m = m[0..-2] return store(m.to_s, args[0]) if has_key?(m.to_s) return store(m.to_sym, args[0]) if has_key?(m.to_sym) return store(m, args[0]) else raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty? return fetch(m, nil) if has_key?(m) return fetch(m.to_s, nil) if has_key?(m.to_s) return fetch(m.to_sym, nil) if has_key?(m.to_sym) end raise NoMethodError.new("undefined method #{m}", m) end
[ "def", "method_missing", "(", "m", ",", "*", "args", ",", "&", "block", ")", "if", "m", ".", "to_s", ".", "end_with?", "(", "'='", ")", "raise", "ArgumentError", ".", "new", "(", "\"wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}\"", ")", "if", "args", ".", "nil?", "or", "1", "!=", "args", ".", "length", "m", "=", "m", "[", "0", "..", "-", "2", "]", "return", "store", "(", "m", ".", "to_s", ",", "args", "[", "0", "]", ")", "if", "has_key?", "(", "m", ".", "to_s", ")", "return", "store", "(", "m", ".", "to_sym", ",", "args", "[", "0", "]", ")", "if", "has_key?", "(", "m", ".", "to_sym", ")", "return", "store", "(", "m", ",", "args", "[", "0", "]", ")", "else", "raise", "ArgumentError", ".", "new", "(", "\"wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}\"", ")", "unless", "args", ".", "nil?", "or", "args", ".", "empty?", "return", "fetch", "(", "m", ",", "nil", ")", "if", "has_key?", "(", "m", ")", "return", "fetch", "(", "m", ".", "to_s", ",", "nil", ")", "if", "has_key?", "(", "m", ".", "to_s", ")", "return", "fetch", "(", "m", ".", "to_sym", ",", "nil", ")", "if", "has_key?", "(", "m", ".", "to_sym", ")", "end", "raise", "NoMethodError", ".", "new", "(", "\"undefined method #{m}\"", ",", "m", ")", "end" ]
Handles requests for Hash values. Others cause an Exception to be raised. @param [Symbol|String] m method symbol @return [Boolean] the value of the specified instance variable. @raise [ArgumentError] if an argument is given. Zero arguments expected. @raise [NoMethodError] if the instance variable is not defined.
[ "Handles", "requests", "for", "Hash", "values", ".", "Others", "cause", "an", "Exception", "to", "be", "raised", "." ]
d11d2e5248293141f29dc2bb2419a26fab784d07
https://github.com/ohler55/oj/blob/d11d2e5248293141f29dc2bb2419a26fab784d07/lib/oj/easy_hash.rb#L35-L49
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.process
def process(css, opts = {}) opts = convert_options(opts) apply_wrapper = "(function(opts, pluginOpts) {" \ "return eval(process.apply(this, opts, pluginOpts));" \ "})" plugin_opts = params_with_browsers(opts[:from]).merge(opts) process_opts = { from: plugin_opts.delete(:from), to: plugin_opts.delete(:to), map: plugin_opts.delete(:map), } begin result = runtime.call(apply_wrapper, [css, process_opts, plugin_opts]) rescue ExecJS::ProgramError => e contry_error = "BrowserslistError: " \ "Country statistics is not supported " \ "in client-side build of Browserslist" if e.message == contry_error raise "Country statistics is not supported in AutoprefixerRails. " \ "Use Autoprefixer with webpack or other Node.js builder." else raise e end end Result.new(result["css"], result["map"], result["warnings"]) end
ruby
def process(css, opts = {}) opts = convert_options(opts) apply_wrapper = "(function(opts, pluginOpts) {" \ "return eval(process.apply(this, opts, pluginOpts));" \ "})" plugin_opts = params_with_browsers(opts[:from]).merge(opts) process_opts = { from: plugin_opts.delete(:from), to: plugin_opts.delete(:to), map: plugin_opts.delete(:map), } begin result = runtime.call(apply_wrapper, [css, process_opts, plugin_opts]) rescue ExecJS::ProgramError => e contry_error = "BrowserslistError: " \ "Country statistics is not supported " \ "in client-side build of Browserslist" if e.message == contry_error raise "Country statistics is not supported in AutoprefixerRails. " \ "Use Autoprefixer with webpack or other Node.js builder." else raise e end end Result.new(result["css"], result["map"], result["warnings"]) end
[ "def", "process", "(", "css", ",", "opts", "=", "{", "}", ")", "opts", "=", "convert_options", "(", "opts", ")", "apply_wrapper", "=", "\"(function(opts, pluginOpts) {\"", "\"return eval(process.apply(this, opts, pluginOpts));\"", "\"})\"", "plugin_opts", "=", "params_with_browsers", "(", "opts", "[", ":from", "]", ")", ".", "merge", "(", "opts", ")", "process_opts", "=", "{", "from", ":", "plugin_opts", ".", "delete", "(", ":from", ")", ",", "to", ":", "plugin_opts", ".", "delete", "(", ":to", ")", ",", "map", ":", "plugin_opts", ".", "delete", "(", ":map", ")", ",", "}", "begin", "result", "=", "runtime", ".", "call", "(", "apply_wrapper", ",", "[", "css", ",", "process_opts", ",", "plugin_opts", "]", ")", "rescue", "ExecJS", "::", "ProgramError", "=>", "e", "contry_error", "=", "\"BrowserslistError: \"", "\"Country statistics is not supported \"", "\"in client-side build of Browserslist\"", "if", "e", ".", "message", "==", "contry_error", "raise", "\"Country statistics is not supported in AutoprefixerRails. \"", "\"Use Autoprefixer with webpack or other Node.js builder.\"", "else", "raise", "e", "end", "end", "Result", ".", "new", "(", "result", "[", "\"css\"", "]", ",", "result", "[", "\"map\"", "]", ",", "result", "[", "\"warnings\"", "]", ")", "end" ]
Process `css` and return result. Options can be: * `from` with input CSS file name. Will be used in error messages. * `to` with output CSS file name. * `map` with true to generate new source map or with previous map.
[ "Process", "css", "and", "return", "result", "." ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L20-L50
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.parse_config
def parse_config(config) sections = {"defaults" => []} current = "defaults" config.gsub(/#[^\n]*/, "") .split(/\n/) .map(&:strip) .reject(&:empty?) .each do |line| if IS_SECTION =~ line current = line.match(IS_SECTION)[1].strip sections[current] ||= [] else sections[current] << line end end sections end
ruby
def parse_config(config) sections = {"defaults" => []} current = "defaults" config.gsub(/#[^\n]*/, "") .split(/\n/) .map(&:strip) .reject(&:empty?) .each do |line| if IS_SECTION =~ line current = line.match(IS_SECTION)[1].strip sections[current] ||= [] else sections[current] << line end end sections end
[ "def", "parse_config", "(", "config", ")", "sections", "=", "{", "\"defaults\"", "=>", "[", "]", "}", "current", "=", "\"defaults\"", "config", ".", "gsub", "(", "/", "\\n", "/", ",", "\"\"", ")", ".", "split", "(", "/", "\\n", "/", ")", ".", "map", "(", ":strip", ")", ".", "reject", "(", ":empty?", ")", ".", "each", "do", "|", "line", "|", "if", "IS_SECTION", "=~", "line", "current", "=", "line", ".", "match", "(", "IS_SECTION", ")", "[", "1", "]", ".", "strip", "sections", "[", "current", "]", "||=", "[", "]", "else", "sections", "[", "current", "]", "<<", "line", "end", "end", "sections", "end" ]
Parse Browserslist config
[ "Parse", "Browserslist", "config" ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L58-L74
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.convert_options
def convert_options(opts) converted = {} opts.each_pair do |name, value| if /_/ =~ name name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym end value = convert_options(value) if value.is_a? Hash converted[name] = value end converted end
ruby
def convert_options(opts) converted = {} opts.each_pair do |name, value| if /_/ =~ name name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym end value = convert_options(value) if value.is_a? Hash converted[name] = value end converted end
[ "def", "convert_options", "(", "opts", ")", "converted", "=", "{", "}", "opts", ".", "each_pair", "do", "|", "name", ",", "value", "|", "if", "/", "/", "=~", "name", "name", "=", "name", ".", "to_s", ".", "gsub", "(", "/", "\\w", "/", ")", "{", "|", "i", "|", "i", ".", "delete", "(", "\"_\"", ")", ".", "upcase", "}", ".", "to_sym", "end", "value", "=", "convert_options", "(", "value", ")", "if", "value", ".", "is_a?", "Hash", "converted", "[", "name", "]", "=", "value", "end", "converted", "end" ]
Convert ruby_options to jsOptions
[ "Convert", "ruby_options", "to", "jsOptions" ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L107-L119
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.find_config
def find_config(file) path = Pathname(file).expand_path while path.parent != path config1 = path.join("browserslist") return config1.read if config1.exist? && !config1.directory? config2 = path.join(".browserslistrc") return config2.read if config2.exist? && !config1.directory? path = path.parent end nil end
ruby
def find_config(file) path = Pathname(file).expand_path while path.parent != path config1 = path.join("browserslist") return config1.read if config1.exist? && !config1.directory? config2 = path.join(".browserslistrc") return config2.read if config2.exist? && !config1.directory? path = path.parent end nil end
[ "def", "find_config", "(", "file", ")", "path", "=", "Pathname", "(", "file", ")", ".", "expand_path", "while", "path", ".", "parent", "!=", "path", "config1", "=", "path", ".", "join", "(", "\"browserslist\"", ")", "return", "config1", ".", "read", "if", "config1", ".", "exist?", "&&", "!", "config1", ".", "directory?", "config2", "=", "path", ".", "join", "(", "\".browserslistrc\"", ")", "return", "config2", ".", "read", "if", "config2", ".", "exist?", "&&", "!", "config1", ".", "directory?", "path", "=", "path", ".", "parent", "end", "nil", "end" ]
Try to find Browserslist config
[ "Try", "to", "find", "Browserslist", "config" ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L122-L136
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.runtime
def runtime @runtime ||= begin if ExecJS.eval("typeof Uint8Array") != "function" if ExecJS.runtime.name.start_with?("therubyracer") raise "ExecJS::RubyRacerRuntime is not supported. " \ "Please replace therubyracer with mini_racer " \ "in your Gemfile or use Node.js as ExecJS runtime." else raise "#{ExecJS.runtime.name} runtime does’t support ES6. " \ "Please update or replace your current ExecJS runtime." end end if ExecJS.runtime == ExecJS::Runtimes::Node version = ExecJS.runtime.eval("process.version") first = version.match(/^v(\d+)/)[1].to_i if first < 6 raise "Autoprefixer doesn’t support Node #{version}. Update it." end end ExecJS.compile(build_js) end end
ruby
def runtime @runtime ||= begin if ExecJS.eval("typeof Uint8Array") != "function" if ExecJS.runtime.name.start_with?("therubyracer") raise "ExecJS::RubyRacerRuntime is not supported. " \ "Please replace therubyracer with mini_racer " \ "in your Gemfile or use Node.js as ExecJS runtime." else raise "#{ExecJS.runtime.name} runtime does’t support ES6. " \ "Please update or replace your current ExecJS runtime." end end if ExecJS.runtime == ExecJS::Runtimes::Node version = ExecJS.runtime.eval("process.version") first = version.match(/^v(\d+)/)[1].to_i if first < 6 raise "Autoprefixer doesn’t support Node #{version}. Update it." end end ExecJS.compile(build_js) end end
[ "def", "runtime", "@runtime", "||=", "begin", "if", "ExecJS", ".", "eval", "(", "\"typeof Uint8Array\"", ")", "!=", "\"function\"", "if", "ExecJS", ".", "runtime", ".", "name", ".", "start_with?", "(", "\"therubyracer\"", ")", "raise", "\"ExecJS::RubyRacerRuntime is not supported. \"", "\"Please replace therubyracer with mini_racer \"", "\"in your Gemfile or use Node.js as ExecJS runtime.\"", "else", "raise", "\"#{ExecJS.runtime.name} runtime does’t support ES6. \" \\", "\"Please update or replace your current ExecJS runtime.\"", "end", "end", "if", "ExecJS", ".", "runtime", "==", "ExecJS", "::", "Runtimes", "::", "Node", "version", "=", "ExecJS", ".", "runtime", ".", "eval", "(", "\"process.version\"", ")", "first", "=", "version", ".", "match", "(", "/", "\\d", "/", ")", "[", "1", "]", ".", "to_i", "if", "first", "<", "6", "raise", "\"Autoprefixer doesn’t support Node #{version}. Update it.\"", "end", "end", "ExecJS", ".", "compile", "(", "build_js", ")", "end", "end" ]
Lazy load for JS library
[ "Lazy", "load", "for", "JS", "library" ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L139-L162
train
ai/autoprefixer-rails
lib/autoprefixer-rails/processor.rb
AutoprefixerRails.Processor.read_js
def read_js @@js ||= begin root = Pathname(File.dirname(__FILE__)) path = root.join("../../vendor/autoprefixer.js") path.read end end
ruby
def read_js @@js ||= begin root = Pathname(File.dirname(__FILE__)) path = root.join("../../vendor/autoprefixer.js") path.read end end
[ "def", "read_js", "@@js", "||=", "begin", "root", "=", "Pathname", "(", "File", ".", "dirname", "(", "__FILE__", ")", ")", "path", "=", "root", ".", "join", "(", "\"../../vendor/autoprefixer.js\"", ")", "path", ".", "read", "end", "end" ]
Cache autoprefixer.js content
[ "Cache", "autoprefixer", ".", "js", "content" ]
22543372b33c688c409b46adfef4d1763041961f
https://github.com/ai/autoprefixer-rails/blob/22543372b33c688c409b46adfef4d1763041961f/lib/autoprefixer-rails/processor.rb#L165-L171
train
github/licensed
lib/licensed/dependency_record.rb
Licensed.DependencyRecord.save
def save(filename) data_to_save = @metadata.merge({ "licenses" => licenses, "notices" => notices }) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, data_to_save.to_yaml) end
ruby
def save(filename) data_to_save = @metadata.merge({ "licenses" => licenses, "notices" => notices }) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, data_to_save.to_yaml) end
[ "def", "save", "(", "filename", ")", "data_to_save", "=", "@metadata", ".", "merge", "(", "{", "\"licenses\"", "=>", "licenses", ",", "\"notices\"", "=>", "notices", "}", ")", "FileUtils", ".", "mkdir_p", "(", "File", ".", "dirname", "(", "filename", ")", ")", "File", ".", "write", "(", "filename", ",", "data_to_save", ".", "to_yaml", ")", "end" ]
Construct a new record licenses - a string, or array of strings, representing the content of each license notices - a string, or array of strings, representing the content of each legal notice metadata - a Hash of the metadata for the package Save the metadata and text to a file filename - The destination file to save record contents at
[ "Construct", "a", "new", "record" ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/dependency_record.rb#L47-L55
train
github/licensed
lib/licensed/dependency.rb
Licensed.Dependency.license_contents
def license_contents matched_files.reject { |f| f == package_file } .group_by(&:content) .map { |content, files| { "sources" => license_content_sources(files), "text" => content } } end
ruby
def license_contents matched_files.reject { |f| f == package_file } .group_by(&:content) .map { |content, files| { "sources" => license_content_sources(files), "text" => content } } end
[ "def", "license_contents", "matched_files", ".", "reject", "{", "|", "f", "|", "f", "==", "package_file", "}", ".", "group_by", "(", ":content", ")", ".", "map", "{", "|", "content", ",", "files", "|", "{", "\"sources\"", "=>", "license_content_sources", "(", "files", ")", ",", "\"text\"", "=>", "content", "}", "}", "end" ]
Returns the license text content from all matched sources except the package file, which doesn't contain license text.
[ "Returns", "the", "license", "text", "content", "from", "all", "matched", "sources", "except", "the", "package", "file", "which", "doesn", "t", "contain", "license", "text", "." ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/dependency.rb#L74-L78
train
github/licensed
lib/licensed/dependency.rb
Licensed.Dependency.notice_contents
def notice_contents Dir.glob(dir_path.join("*")) .grep(LEGAL_FILES_PATTERN) .select { |path| File.file?(path) } .sort # sorted by the path .map { |path| { "sources" => normalize_source_path(path), "text" => File.read(path).rstrip } } .select { |notice| notice["text"].length > 0 } # files with content only end
ruby
def notice_contents Dir.glob(dir_path.join("*")) .grep(LEGAL_FILES_PATTERN) .select { |path| File.file?(path) } .sort # sorted by the path .map { |path| { "sources" => normalize_source_path(path), "text" => File.read(path).rstrip } } .select { |notice| notice["text"].length > 0 } # files with content only end
[ "def", "notice_contents", "Dir", ".", "glob", "(", "dir_path", ".", "join", "(", "\"*\"", ")", ")", ".", "grep", "(", "LEGAL_FILES_PATTERN", ")", ".", "select", "{", "|", "path", "|", "File", ".", "file?", "(", "path", ")", "}", ".", "sort", "# sorted by the path", ".", "map", "{", "|", "path", "|", "{", "\"sources\"", "=>", "normalize_source_path", "(", "path", ")", ",", "\"text\"", "=>", "File", ".", "read", "(", "path", ")", ".", "rstrip", "}", "}", ".", "select", "{", "|", "notice", "|", "notice", "[", "\"text\"", "]", ".", "length", ">", "0", "}", "# files with content only", "end" ]
Returns legal notices found at the dependency path
[ "Returns", "legal", "notices", "found", "at", "the", "dependency", "path" ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/dependency.rb#L81-L88
train
github/licensed
lib/licensed/dependency.rb
Licensed.Dependency.license_content_sources
def license_content_sources(files) paths = Array(files).map do |file| next file[:uri] if file[:uri] path = dir_path.join(file[:dir], file[:name]) normalize_source_path(path) end paths.join(", ") end
ruby
def license_content_sources(files) paths = Array(files).map do |file| next file[:uri] if file[:uri] path = dir_path.join(file[:dir], file[:name]) normalize_source_path(path) end paths.join(", ") end
[ "def", "license_content_sources", "(", "files", ")", "paths", "=", "Array", "(", "files", ")", ".", "map", "do", "|", "file", "|", "next", "file", "[", ":uri", "]", "if", "file", "[", ":uri", "]", "path", "=", "dir_path", ".", "join", "(", "file", "[", ":dir", "]", ",", "file", "[", ":name", "]", ")", "normalize_source_path", "(", "path", ")", "end", "paths", ".", "join", "(", "\", \"", ")", "end" ]
Returns the sources for a group of license file contents Sources are returned as a single string with sources separated by ", "
[ "Returns", "the", "sources", "for", "a", "group", "of", "license", "file", "contents" ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/dependency.rb#L95-L104
train
github/licensed
lib/licensed/configuration.rb
Licensed.AppConfiguration.sources
def sources @sources ||= Licensed::Sources::Source.sources .select { |source_class| enabled?(source_class.type) } .map { |source_class| source_class.new(self) } end
ruby
def sources @sources ||= Licensed::Sources::Source.sources .select { |source_class| enabled?(source_class.type) } .map { |source_class| source_class.new(self) } end
[ "def", "sources", "@sources", "||=", "Licensed", "::", "Sources", "::", "Source", ".", "sources", ".", "select", "{", "|", "source_class", "|", "enabled?", "(", "source_class", ".", "type", ")", "}", ".", "map", "{", "|", "source_class", "|", "source_class", ".", "new", "(", "self", ")", "}", "end" ]
Returns an array of enabled app sources
[ "Returns", "an", "array", "of", "enabled", "app", "sources" ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/configuration.rb#L58-L62
train
github/licensed
lib/licensed/configuration.rb
Licensed.AppConfiguration.enabled?
def enabled?(source_type) # the default is false if any sources are set to true, true otherwise default = !self["sources"].any? { |_, enabled| enabled } self["sources"].fetch(source_type, default) end
ruby
def enabled?(source_type) # the default is false if any sources are set to true, true otherwise default = !self["sources"].any? { |_, enabled| enabled } self["sources"].fetch(source_type, default) end
[ "def", "enabled?", "(", "source_type", ")", "# the default is false if any sources are set to true, true otherwise", "default", "=", "!", "self", "[", "\"sources\"", "]", ".", "any?", "{", "|", "_", ",", "enabled", "|", "enabled", "}", "self", "[", "\"sources\"", "]", ".", "fetch", "(", "source_type", ",", "default", ")", "end" ]
Returns whether a source type is enabled
[ "Returns", "whether", "a", "source", "type", "is", "enabled" ]
afba288df344e001d43e94ad9217635a011b79c2
https://github.com/github/licensed/blob/afba288df344e001d43e94ad9217635a011b79c2/lib/licensed/configuration.rb#L65-L69
train
mikker/passwordless
lib/passwordless/controller_helpers.rb
Passwordless.ControllerHelpers.authenticate_by_cookie
def authenticate_by_cookie(authenticatable_class) key = cookie_name(authenticatable_class) authenticatable_id = cookies.encrypted[key] return unless authenticatable_id authenticatable_class.find_by(id: authenticatable_id) end
ruby
def authenticate_by_cookie(authenticatable_class) key = cookie_name(authenticatable_class) authenticatable_id = cookies.encrypted[key] return unless authenticatable_id authenticatable_class.find_by(id: authenticatable_id) end
[ "def", "authenticate_by_cookie", "(", "authenticatable_class", ")", "key", "=", "cookie_name", "(", "authenticatable_class", ")", "authenticatable_id", "=", "cookies", ".", "encrypted", "[", "key", "]", "return", "unless", "authenticatable_id", "authenticatable_class", ".", "find_by", "(", "id", ":", "authenticatable_id", ")", "end" ]
Authenticate a record using cookies. Looks for a cookie corresponding to the _authenticatable_class_. If found try to find it in the database. @param authenticatable_class [ActiveRecord::Base] any Model connected to passwordless. (e.g - _User_ or _Admin_). @return [ActiveRecord::Base|nil] an instance of Model found by id stored in cookies.encrypted or nil if nothing is found. @see ModelHelpers#passwordless_with
[ "Authenticate", "a", "record", "using", "cookies", ".", "Looks", "for", "a", "cookie", "corresponding", "to", "the", "_authenticatable_class_", ".", "If", "found", "try", "to", "find", "it", "in", "the", "database", "." ]
80d3e00c78114aed01f336514a236dfc17d0a91a
https://github.com/mikker/passwordless/blob/80d3e00c78114aed01f336514a236dfc17d0a91a/lib/passwordless/controller_helpers.rb#L27-L33
train
mikker/passwordless
lib/passwordless/controller_helpers.rb
Passwordless.ControllerHelpers.sign_in
def sign_in(authenticatable) key = cookie_name(authenticatable.class) cookies.encrypted.permanent[key] = {value: authenticatable.id} authenticatable end
ruby
def sign_in(authenticatable) key = cookie_name(authenticatable.class) cookies.encrypted.permanent[key] = {value: authenticatable.id} authenticatable end
[ "def", "sign_in", "(", "authenticatable", ")", "key", "=", "cookie_name", "(", "authenticatable", ".", "class", ")", "cookies", ".", "encrypted", ".", "permanent", "[", "key", "]", "=", "{", "value", ":", "authenticatable", ".", "id", "}", "authenticatable", "end" ]
Signs in user by assigning their id to a permanent cookie. @param authenticatable [ActiveRecord::Base] Instance of Model to sign in (e.g - @user when @user = User.find(id: some_id)). @return [ActiveRecord::Base] the record that is passed in.
[ "Signs", "in", "user", "by", "assigning", "their", "id", "to", "a", "permanent", "cookie", "." ]
80d3e00c78114aed01f336514a236dfc17d0a91a
https://github.com/mikker/passwordless/blob/80d3e00c78114aed01f336514a236dfc17d0a91a/lib/passwordless/controller_helpers.rb#L39-L43
train
mikker/passwordless
lib/passwordless/controller_helpers.rb
Passwordless.ControllerHelpers.sign_out
def sign_out(authenticatable_class) key = cookie_name(authenticatable_class) cookies.encrypted.permanent[key] = {value: nil} cookies.delete(key) true end
ruby
def sign_out(authenticatable_class) key = cookie_name(authenticatable_class) cookies.encrypted.permanent[key] = {value: nil} cookies.delete(key) true end
[ "def", "sign_out", "(", "authenticatable_class", ")", "key", "=", "cookie_name", "(", "authenticatable_class", ")", "cookies", ".", "encrypted", ".", "permanent", "[", "key", "]", "=", "{", "value", ":", "nil", "}", "cookies", ".", "delete", "(", "key", ")", "true", "end" ]
Signs out user by deleting their encrypted cookie. @param (see #authenticate_by_cookie) @return [boolean] Always true
[ "Signs", "out", "user", "by", "deleting", "their", "encrypted", "cookie", "." ]
80d3e00c78114aed01f336514a236dfc17d0a91a
https://github.com/mikker/passwordless/blob/80d3e00c78114aed01f336514a236dfc17d0a91a/lib/passwordless/controller_helpers.rb#L48-L53
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.count
def count(stat, count, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, count, COUNTER_TYPE, opts end
ruby
def count(stat, count, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, count, COUNTER_TYPE, opts end
[ "def", "count", "(", "stat", ",", "count", ",", "opts", "=", "EMPTY_OPTIONS", ")", "opts", "=", "{", ":sample_rate", "=>", "opts", "}", "if", "opts", ".", "is_a?", "Numeric", "send_stats", "stat", ",", "count", ",", "COUNTER_TYPE", ",", "opts", "end" ]
Sends an arbitrary count for the given stat to the statsd server. @param [String] stat stat name @param [Integer] count count @param [Hash] opts the options to create the metric with @option opts [Numeric] :sample_rate sample rate, 1 for always @option opts [Array<String>] :tags An array of tags
[ "Sends", "an", "arbitrary", "count", "for", "the", "given", "stat", "to", "the", "statsd", "server", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L276-L279
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.gauge
def gauge(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, value, GAUGE_TYPE, opts end
ruby
def gauge(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, value, GAUGE_TYPE, opts end
[ "def", "gauge", "(", "stat", ",", "value", ",", "opts", "=", "EMPTY_OPTIONS", ")", "opts", "=", "{", ":sample_rate", "=>", "opts", "}", "if", "opts", ".", "is_a?", "Numeric", "send_stats", "stat", ",", "value", ",", "GAUGE_TYPE", ",", "opts", "end" ]
Sends an arbitary gauge value for the given stat to the statsd server. This is useful for recording things like available disk space, memory usage, and the like, which have different semantics than counters. @param [String] stat stat name. @param [Numeric] value gauge value. @param [Hash] opts the options to create the metric with @option opts [Numeric] :sample_rate sample rate, 1 for always @option opts [Array<String>] :tags An array of tags @example Report the current user count: $statsd.gauge('user.count', User.count)
[ "Sends", "an", "arbitary", "gauge", "value", "for", "the", "given", "stat", "to", "the", "statsd", "server", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L294-L297
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.histogram
def histogram(stat, value, opts=EMPTY_OPTIONS) send_stats stat, value, HISTOGRAM_TYPE, opts end
ruby
def histogram(stat, value, opts=EMPTY_OPTIONS) send_stats stat, value, HISTOGRAM_TYPE, opts end
[ "def", "histogram", "(", "stat", ",", "value", ",", "opts", "=", "EMPTY_OPTIONS", ")", "send_stats", "stat", ",", "value", ",", "HISTOGRAM_TYPE", ",", "opts", "end" ]
Sends a value to be tracked as a histogram to the statsd server. @param [String] stat stat name. @param [Numeric] value histogram value. @param [Hash] opts the options to create the metric with @option opts [Numeric] :sample_rate sample rate, 1 for always @option opts [Array<String>] :tags An array of tags @example Report the current user count: $statsd.histogram('user.count', User.count)
[ "Sends", "a", "value", "to", "be", "tracked", "as", "a", "histogram", "to", "the", "statsd", "server", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L308-L310
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.set
def set(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, value, SET_TYPE, opts end
ruby
def set(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric send_stats stat, value, SET_TYPE, opts end
[ "def", "set", "(", "stat", ",", "value", ",", "opts", "=", "EMPTY_OPTIONS", ")", "opts", "=", "{", ":sample_rate", "=>", "opts", "}", "if", "opts", ".", "is_a?", "Numeric", "send_stats", "stat", ",", "value", ",", "SET_TYPE", ",", "opts", "end" ]
Sends a value to be tracked as a set to the statsd server. @param [String] stat stat name. @param [Numeric] value set value. @param [Hash] opts the options to create the metric with @option opts [Numeric] :sample_rate sample rate, 1 for always @option opts [Array<String>] :tags An array of tags @example Record a unique visitory by id: $statsd.set('visitors.uniques', User.id)
[ "Sends", "a", "value", "to", "be", "tracked", "as", "a", "set", "to", "the", "statsd", "server", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L374-L377
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.service_check
def service_check(name, status, opts=EMPTY_OPTIONS) send_stat format_service_check(name, status, opts) end
ruby
def service_check(name, status, opts=EMPTY_OPTIONS) send_stat format_service_check(name, status, opts) end
[ "def", "service_check", "(", "name", ",", "status", ",", "opts", "=", "EMPTY_OPTIONS", ")", "send_stat", "format_service_check", "(", "name", ",", "status", ",", "opts", ")", "end" ]
This method allows you to send custom service check statuses. @param [String] name Service check name @param [String] status Service check status. @param [Hash] opts the additional data about the service check @option opts [Integer, nil] :timestamp (nil) Assign a timestamp to the event. Default is now when none @option opts [String, nil] :hostname (nil) Assign a hostname to the event. @option opts [Array<String>, nil] :tags (nil) An array of tags @option opts [String, nil] :message (nil) A message to associate with this service check status @example Report a critical service check status $statsd.service_check('my.service.check', Statsd::CRITICAL, :tags=>['urgent'])
[ "This", "method", "allows", "you", "to", "send", "custom", "service", "check", "statuses", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L390-L392
train
DataDog/dogstatsd-ruby
lib/datadog/statsd.rb
Datadog.Statsd.event
def event(title, text, opts=EMPTY_OPTIONS) send_stat format_event(title, text, opts) end
ruby
def event(title, text, opts=EMPTY_OPTIONS) send_stat format_event(title, text, opts) end
[ "def", "event", "(", "title", ",", "text", ",", "opts", "=", "EMPTY_OPTIONS", ")", "send_stat", "format_event", "(", "title", ",", "text", ",", "opts", ")", "end" ]
This end point allows you to post events to the stream. You can tag them, set priority and even aggregate them with other events. Aggregation in the stream is made on hostname/event_type/source_type/aggregation_key. If there's no event type, for example, then that won't matter; it will be grouped with other events that don't have an event type. @param [String] title Event title @param [String] text Event text. Supports newlines (+\n+) @param [Hash] opts the additional data about the event @option opts [Integer, nil] :date_happened (nil) Assign a timestamp to the event. Default is now when none @option opts [String, nil] :hostname (nil) Assign a hostname to the event. @option opts [String, nil] :aggregation_key (nil) Assign an aggregation key to the event, to group it with some others @option opts [String, nil] :priority ('normal') Can be "normal" or "low" @option opts [String, nil] :source_type_name (nil) Assign a source type to the event @option opts [String, nil] :alert_type ('info') Can be "error", "warning", "info" or "success". @option opts [Array<String>] :tags tags to be added to every metric @example Report an awful event: $statsd.event('Something terrible happened', 'The end is near if we do nothing', :alert_type=>'warning', :tags=>['end_of_times','urgent'])
[ "This", "end", "point", "allows", "you", "to", "post", "events", "to", "the", "stream", ".", "You", "can", "tag", "them", "set", "priority", "and", "even", "aggregate", "them", "with", "other", "events", "." ]
0ea2a4d011958ad0d092654cae950e64b6475077
https://github.com/DataDog/dogstatsd-ruby/blob/0ea2a4d011958ad0d092654cae950e64b6475077/lib/datadog/statsd.rb#L412-L414
train
jekyll/jekyll-redirect-from
lib/jekyll-redirect-from/generator.rb
JekyllRedirectFrom.Generator.generate_redirect_from
def generate_redirect_from(doc) doc.redirect_from.each do |path| page = RedirectPage.redirect_from(doc, path) doc.site.pages << page redirects[page.redirect_from] = page.redirect_to end end
ruby
def generate_redirect_from(doc) doc.redirect_from.each do |path| page = RedirectPage.redirect_from(doc, path) doc.site.pages << page redirects[page.redirect_from] = page.redirect_to end end
[ "def", "generate_redirect_from", "(", "doc", ")", "doc", ".", "redirect_from", ".", "each", "do", "|", "path", "|", "page", "=", "RedirectPage", ".", "redirect_from", "(", "doc", ",", "path", ")", "doc", ".", "site", ".", "pages", "<<", "page", "redirects", "[", "page", ".", "redirect_from", "]", "=", "page", ".", "redirect_to", "end", "end" ]
For every `redirect_from` entry, generate a redirect page
[ "For", "every", "redirect_from", "entry", "generate", "a", "redirect", "page" ]
21d18e0751df69a0d1a6951cb3462c77f291201b
https://github.com/jekyll/jekyll-redirect-from/blob/21d18e0751df69a0d1a6951cb3462c77f291201b/lib/jekyll-redirect-from/generator.rb#L31-L37
train
jekyll/jekyll-redirect-from
lib/jekyll-redirect-from/redirect_page.rb
JekyllRedirectFrom.RedirectPage.set_paths
def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from, "to" => to =~ %r!^https?://! ? to : absolute_url(to), } ) end
ruby
def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from, "to" => to =~ %r!^https?://! ? to : absolute_url(to), } ) end
[ "def", "set_paths", "(", "from", ",", "to", ")", "@context", "||=", "context", "from", "=", "ensure_leading_slash", "(", "from", ")", "data", ".", "merge!", "(", "\"permalink\"", "=>", "from", ",", "\"redirect\"", "=>", "{", "\"from\"", "=>", "from", ",", "\"to\"", "=>", "to", "=~", "%r!", "!", "?", "to", ":", "absolute_url", "(", "to", ")", ",", "}", ")", "end" ]
Helper function to set the appropriate path metadata from - the relative path to the redirect page to - the relative path or absolute URL to the redirect target
[ "Helper", "function", "to", "set", "the", "appropriate", "path", "metadata" ]
21d18e0751df69a0d1a6951cb3462c77f291201b
https://github.com/jekyll/jekyll-redirect-from/blob/21d18e0751df69a0d1a6951cb3462c77f291201b/lib/jekyll-redirect-from/redirect_page.rb#L45-L55
train
opal/opal
lib/opal/compiler.rb
Opal.Compiler.compile
def compile parse @fragments = re_raise_with_location { process(@sexp).flatten } @fragments << fragment("\n", nil, s(:newline)) unless @fragments.last.code.end_with?("\n") @result = @fragments.map(&:code).join('') end
ruby
def compile parse @fragments = re_raise_with_location { process(@sexp).flatten } @fragments << fragment("\n", nil, s(:newline)) unless @fragments.last.code.end_with?("\n") @result = @fragments.map(&:code).join('') end
[ "def", "compile", "parse", "@fragments", "=", "re_raise_with_location", "{", "process", "(", "@sexp", ")", ".", "flatten", "}", "@fragments", "<<", "fragment", "(", "\"\\n\"", ",", "nil", ",", "s", "(", ":newline", ")", ")", "unless", "@fragments", ".", "last", ".", "code", ".", "end_with?", "(", "\"\\n\"", ")", "@result", "=", "@fragments", ".", "map", "(", ":code", ")", ".", "join", "(", "''", ")", "end" ]
Compile some ruby code to a string. @return [String] javascript code
[ "Compile", "some", "ruby", "code", "to", "a", "string", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/lib/opal/compiler.rb#L172-L179
train