id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
11,600
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
11,601
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
11,602
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
11,603
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
11,604
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
11,605
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
11,606
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
11,607
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
11,608
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
11,609
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
11,610
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
11,611
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
11,612
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
11,613
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
11,614
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
11,615
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
11,616
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
11,617
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
11,618
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
11,619
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
11,620
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
11,621
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
11,622
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
11,623
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
11,624
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
11,625
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
11,626
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
11,627
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
11,628
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
11,629
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
11,630
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
11,631
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
11,632
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
11,633
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
11,634
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
11,635
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
11,636
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
11,637
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
11,638
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
11,639
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
11,640
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
11,641
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
11,642
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
11,643
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
11,644
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
11,645
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
11,646
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
11,647
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
11,648
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
11,649
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
11,650
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
11,651
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
11,652
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
11,653
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
11,654
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
11,655
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
11,656
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
11,657
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
11,658
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
11,659
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
11,660
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
11,661
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
11,662
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
11,663
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
11,664
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
11,665
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
11,666
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
11,667
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
11,668
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
11,669
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
11,670
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
11,671
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
11,672
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
11,673
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
11,674
opal/opal
lib/opal/compiler.rb
Opal.Compiler.unique_temp
def unique_temp(name) name = name.to_s if name && !name.empty? name = name .to_s .gsub('<=>', '$lt_eq_gt') .gsub('===', '$eq_eq_eq') .gsub('==', '$eq_eq') .gsub('=~', '$eq_tilde') .gsub('!~', '$excl_tilde') .gsub('!=', '$not_eq') .gsub('<=', '$lt_eq') .gsub('>=', '$gt_eq') .gsub('=', '$eq') .gsub('?', '$ques') .gsub('!', '$excl') .gsub('/', '$slash') .gsub('%', '$percent') .gsub('+', '$plus') .gsub('-', '$minus') .gsub('<', '$lt') .gsub('>', '$gt') .gsub(/[^\w\$]/, '$') end unique = (@unique += 1) "#{'$' unless name.start_with?('$')}#{name}$#{unique}" end
ruby
def unique_temp(name) name = name.to_s if name && !name.empty? name = name .to_s .gsub('<=>', '$lt_eq_gt') .gsub('===', '$eq_eq_eq') .gsub('==', '$eq_eq') .gsub('=~', '$eq_tilde') .gsub('!~', '$excl_tilde') .gsub('!=', '$not_eq') .gsub('<=', '$lt_eq') .gsub('>=', '$gt_eq') .gsub('=', '$eq') .gsub('?', '$ques') .gsub('!', '$excl') .gsub('/', '$slash') .gsub('%', '$percent') .gsub('+', '$plus') .gsub('-', '$minus') .gsub('<', '$lt') .gsub('>', '$gt') .gsub(/[^\w\$]/, '$') end unique = (@unique += 1) "#{'$' unless name.start_with?('$')}#{name}$#{unique}" end
[ "def", "unique_temp", "(", "name", ")", "name", "=", "name", ".", "to_s", "if", "name", "&&", "!", "name", ".", "empty?", "name", "=", "name", ".", "to_s", ".", "gsub", "(", "'<=>'", ",", "'$lt_eq_gt'", ")", ".", "gsub", "(", "'==='", ",", "'$eq_eq_eq'", ")", ".", "gsub", "(", "'=='", ",", "'$eq_eq'", ")", ".", "gsub", "(", "'=~'", ",", "'$eq_tilde'", ")", ".", "gsub", "(", "'!~'", ",", "'$excl_tilde'", ")", ".", "gsub", "(", "'!='", ",", "'$not_eq'", ")", ".", "gsub", "(", "'<='", ",", "'$lt_eq'", ")", ".", "gsub", "(", "'>='", ",", "'$gt_eq'", ")", ".", "gsub", "(", "'='", ",", "'$eq'", ")", ".", "gsub", "(", "'?'", ",", "'$ques'", ")", ".", "gsub", "(", "'!'", ",", "'$excl'", ")", ".", "gsub", "(", "'/'", ",", "'$slash'", ")", ".", "gsub", "(", "'%'", ",", "'$percent'", ")", ".", "gsub", "(", "'+'", ",", "'$plus'", ")", ".", "gsub", "(", "'-'", ",", "'$minus'", ")", ".", "gsub", "(", "'<'", ",", "'$lt'", ")", ".", "gsub", "(", "'>'", ",", "'$gt'", ")", ".", "gsub", "(", "/", "\\w", "\\$", "/", ",", "'$'", ")", "end", "unique", "=", "(", "@unique", "+=", "1", ")", "\"#{'$' unless name.start_with?('$')}#{name}$#{unique}\"", "end" ]
Used to generate a unique id name per file. These are used mainly to name method bodies for methods that use blocks.
[ "Used", "to", "generate", "a", "unique", "id", "name", "per", "file", ".", "These", "are", "used", "mainly", "to", "name", "method", "bodies", "for", "methods", "that", "use", "blocks", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/lib/opal/compiler.rb#L270-L296
11,675
opal/opal
lib/opal/compiler.rb
Opal.Compiler.process
def process(sexp, level = :expr) return fragment('', scope) if sexp.nil? if handler = handlers[sexp.type] return handler.new(sexp, level, self).compile_to_fragments else error "Unsupported sexp: #{sexp.type}" end end
ruby
def process(sexp, level = :expr) return fragment('', scope) if sexp.nil? if handler = handlers[sexp.type] return handler.new(sexp, level, self).compile_to_fragments else error "Unsupported sexp: #{sexp.type}" end end
[ "def", "process", "(", "sexp", ",", "level", "=", ":expr", ")", "return", "fragment", "(", "''", ",", "scope", ")", "if", "sexp", ".", "nil?", "if", "handler", "=", "handlers", "[", "sexp", ".", "type", "]", "return", "handler", ".", "new", "(", "sexp", ",", "level", ",", "self", ")", ".", "compile_to_fragments", "else", "error", "\"Unsupported sexp: #{sexp.type}\"", "end", "end" ]
Process the given sexp by creating a node instance, based on its type, and compiling it to fragments.
[ "Process", "the", "given", "sexp", "by", "creating", "a", "node", "instance", "based", "on", "its", "type", "and", "compiling", "it", "to", "fragments", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/lib/opal/compiler.rb#L354-L362
11,676
opal/opal
lib/opal/compiler.rb
Opal.Compiler.returns
def returns(sexp) return returns s(:nil) unless sexp case sexp.type when :undef # undef :method_name always returns nil returns s(:begin, sexp, s(:nil)) when :break, :next, :redo sexp when :yield sexp.updated(:returnable_yield, nil) when :when *when_sexp, then_sexp = *sexp sexp.updated(nil, [*when_sexp, returns(then_sexp)]) when :rescue body_sexp, *resbodies, else_sexp = *sexp resbodies = resbodies.map do |resbody| returns(resbody) end if else_sexp else_sexp = returns(else_sexp) end sexp.updated( nil, [ returns(body_sexp), *resbodies, else_sexp ] ) when :resbody klass, lvar, body = *sexp sexp.updated(nil, [klass, lvar, returns(body)]) when :ensure rescue_sexp, ensure_body = *sexp sexp = sexp.updated(nil, [returns(rescue_sexp), ensure_body]) s(:js_return, sexp) when :begin, :kwbegin # Wrapping last expression with s(:js_return, ...) *rest, last = *sexp sexp.updated(nil, [*rest, returns(last)]) when :while, :until, :while_post, :until_post sexp when :return, :js_return, :returnable_yield sexp when :xstr sexp.updated(nil, [s(:js_return, *sexp.children)]) when :if cond, true_body, false_body = *sexp sexp.updated( nil, [ cond, returns(true_body), returns(false_body) ] ) else s(:js_return, sexp).updated( nil, nil, location: sexp.loc, ) end end
ruby
def returns(sexp) return returns s(:nil) unless sexp case sexp.type when :undef # undef :method_name always returns nil returns s(:begin, sexp, s(:nil)) when :break, :next, :redo sexp when :yield sexp.updated(:returnable_yield, nil) when :when *when_sexp, then_sexp = *sexp sexp.updated(nil, [*when_sexp, returns(then_sexp)]) when :rescue body_sexp, *resbodies, else_sexp = *sexp resbodies = resbodies.map do |resbody| returns(resbody) end if else_sexp else_sexp = returns(else_sexp) end sexp.updated( nil, [ returns(body_sexp), *resbodies, else_sexp ] ) when :resbody klass, lvar, body = *sexp sexp.updated(nil, [klass, lvar, returns(body)]) when :ensure rescue_sexp, ensure_body = *sexp sexp = sexp.updated(nil, [returns(rescue_sexp), ensure_body]) s(:js_return, sexp) when :begin, :kwbegin # Wrapping last expression with s(:js_return, ...) *rest, last = *sexp sexp.updated(nil, [*rest, returns(last)]) when :while, :until, :while_post, :until_post sexp when :return, :js_return, :returnable_yield sexp when :xstr sexp.updated(nil, [s(:js_return, *sexp.children)]) when :if cond, true_body, false_body = *sexp sexp.updated( nil, [ cond, returns(true_body), returns(false_body) ] ) else s(:js_return, sexp).updated( nil, nil, location: sexp.loc, ) end end
[ "def", "returns", "(", "sexp", ")", "return", "returns", "s", "(", ":nil", ")", "unless", "sexp", "case", "sexp", ".", "type", "when", ":undef", "# undef :method_name always returns nil", "returns", "s", "(", ":begin", ",", "sexp", ",", "s", "(", ":nil", ")", ")", "when", ":break", ",", ":next", ",", ":redo", "sexp", "when", ":yield", "sexp", ".", "updated", "(", ":returnable_yield", ",", "nil", ")", "when", ":when", "*", "when_sexp", ",", "then_sexp", "=", "sexp", "sexp", ".", "updated", "(", "nil", ",", "[", "when_sexp", ",", "returns", "(", "then_sexp", ")", "]", ")", "when", ":rescue", "body_sexp", ",", "*", "resbodies", ",", "else_sexp", "=", "sexp", "resbodies", "=", "resbodies", ".", "map", "do", "|", "resbody", "|", "returns", "(", "resbody", ")", "end", "if", "else_sexp", "else_sexp", "=", "returns", "(", "else_sexp", ")", "end", "sexp", ".", "updated", "(", "nil", ",", "[", "returns", "(", "body_sexp", ")", ",", "resbodies", ",", "else_sexp", "]", ")", "when", ":resbody", "klass", ",", "lvar", ",", "body", "=", "sexp", "sexp", ".", "updated", "(", "nil", ",", "[", "klass", ",", "lvar", ",", "returns", "(", "body", ")", "]", ")", "when", ":ensure", "rescue_sexp", ",", "ensure_body", "=", "sexp", "sexp", "=", "sexp", ".", "updated", "(", "nil", ",", "[", "returns", "(", "rescue_sexp", ")", ",", "ensure_body", "]", ")", "s", "(", ":js_return", ",", "sexp", ")", "when", ":begin", ",", ":kwbegin", "# Wrapping last expression with s(:js_return, ...)", "*", "rest", ",", "last", "=", "sexp", "sexp", ".", "updated", "(", "nil", ",", "[", "rest", ",", "returns", "(", "last", ")", "]", ")", "when", ":while", ",", ":until", ",", ":while_post", ",", ":until_post", "sexp", "when", ":return", ",", ":js_return", ",", ":returnable_yield", "sexp", "when", ":xstr", "sexp", ".", "updated", "(", "nil", ",", "[", "s", "(", ":js_return", ",", "sexp", ".", "children", ")", "]", ")", "when", ":if", "cond", ",", "true_body", ",", "false_body", "=", "sexp", "sexp", ".", "updated", "(", "nil", ",", "[", "cond", ",", "returns", "(", "true_body", ")", ",", "returns", "(", "false_body", ")", "]", ")", "else", "s", "(", ":js_return", ",", "sexp", ")", ".", "updated", "(", "nil", ",", "nil", ",", "location", ":", "sexp", ".", "loc", ",", ")", "end", "end" ]
The last sexps in method bodies, for example, need to be returned in the compiled javascript. Due to syntax differences between javascript any ruby, some sexps need to be handled specially. For example, `if` statemented cannot be returned in javascript, so instead the "truthy" and "falsy" parts of the if statement both need to be returned instead. Sexps that need to be returned are passed to this method, and the alterned/new sexps are returned and should be used instead. Most sexps can just be added into a `s(:return) sexp`, so that is the default action if no special case is required.
[ "The", "last", "sexps", "in", "method", "bodies", "for", "example", "need", "to", "be", "returned", "in", "the", "compiled", "javascript", ".", "Due", "to", "syntax", "differences", "between", "javascript", "any", "ruby", "some", "sexps", "need", "to", "be", "handled", "specially", ".", "For", "example", "if", "statemented", "cannot", "be", "returned", "in", "javascript", "so", "instead", "the", "truthy", "and", "falsy", "parts", "of", "the", "if", "statement", "both", "need", "to", "be", "returned", "instead", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/lib/opal/compiler.rb#L390-L455
11,677
opal/opal
stdlib/racc/parser.rb
Racc.Parser.on_error
def on_error(t, val, vstack) raise ParseError, sprintf("\nparse error on value %s (%s)", val.inspect, token_to_str(t) || '?') end
ruby
def on_error(t, val, vstack) raise ParseError, sprintf("\nparse error on value %s (%s)", val.inspect, token_to_str(t) || '?') end
[ "def", "on_error", "(", "t", ",", "val", ",", "vstack", ")", "raise", "ParseError", ",", "sprintf", "(", "\"\\nparse error on value %s (%s)\"", ",", "val", ".", "inspect", ",", "token_to_str", "(", "t", ")", "||", "'?'", ")", "end" ]
This method is called when a parse error is found. ERROR_TOKEN_ID is an internal ID of token which caused error. You can get string representation of this ID by calling #token_to_str. ERROR_VALUE is a value of error token. value_stack is a stack of symbol values. DO NOT MODIFY this object. This method raises ParseError by default. If this method returns, parsers enter "error recovering mode".
[ "This", "method", "is", "called", "when", "a", "parse", "error", "is", "found", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/stdlib/racc/parser.rb#L532-L535
11,678
opal/opal
stdlib/racc/parser.rb
Racc.Parser.racc_read_token
def racc_read_token(t, tok, val) @racc_debug_out.print 'read ' @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') ' @racc_debug_out.puts val.inspect @racc_debug_out.puts end
ruby
def racc_read_token(t, tok, val) @racc_debug_out.print 'read ' @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') ' @racc_debug_out.puts val.inspect @racc_debug_out.puts end
[ "def", "racc_read_token", "(", "t", ",", "tok", ",", "val", ")", "@racc_debug_out", ".", "print", "'read '", "@racc_debug_out", ".", "print", "tok", ".", "inspect", ",", "'('", ",", "racc_token2str", "(", "t", ")", ",", "') '", "@racc_debug_out", ".", "puts", "val", ".", "inspect", "@racc_debug_out", ".", "puts", "end" ]
For debugging output
[ "For", "debugging", "output" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/stdlib/racc/parser.rb#L555-L560
11,679
opal/opal
stdlib/benchmark.rb
Benchmark.Tms.memberwise
def memberwise(op, x) case x when Benchmark::Tms Benchmark::Tms.new(utime.__send__(op, x.utime), stime.__send__(op, x.stime), cutime.__send__(op, x.cutime), cstime.__send__(op, x.cstime), real.__send__(op, x.real) ) else Benchmark::Tms.new(utime.__send__(op, x), stime.__send__(op, x), cutime.__send__(op, x), cstime.__send__(op, x), real.__send__(op, x) ) end end
ruby
def memberwise(op, x) case x when Benchmark::Tms Benchmark::Tms.new(utime.__send__(op, x.utime), stime.__send__(op, x.stime), cutime.__send__(op, x.cutime), cstime.__send__(op, x.cstime), real.__send__(op, x.real) ) else Benchmark::Tms.new(utime.__send__(op, x), stime.__send__(op, x), cutime.__send__(op, x), cstime.__send__(op, x), real.__send__(op, x) ) end end
[ "def", "memberwise", "(", "op", ",", "x", ")", "case", "x", "when", "Benchmark", "::", "Tms", "Benchmark", "::", "Tms", ".", "new", "(", "utime", ".", "__send__", "(", "op", ",", "x", ".", "utime", ")", ",", "stime", ".", "__send__", "(", "op", ",", "x", ".", "stime", ")", ",", "cutime", ".", "__send__", "(", "op", ",", "x", ".", "cutime", ")", ",", "cstime", ".", "__send__", "(", "op", ",", "x", ".", "cstime", ")", ",", "real", ".", "__send__", "(", "op", ",", "x", ".", "real", ")", ")", "else", "Benchmark", "::", "Tms", ".", "new", "(", "utime", ".", "__send__", "(", "op", ",", "x", ")", ",", "stime", ".", "__send__", "(", "op", ",", "x", ")", ",", "cutime", ".", "__send__", "(", "op", ",", "x", ")", ",", "cstime", ".", "__send__", "(", "op", ",", "x", ")", ",", "real", ".", "__send__", "(", "op", ",", "x", ")", ")", "end", "end" ]
Returns a new Tms object obtained by memberwise operation +op+ of the individual times for this Tms object with those of the other Tms object. +op+ can be a mathematical operation such as <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt>
[ "Returns", "a", "new", "Tms", "object", "obtained", "by", "memberwise", "operation", "+", "op", "+", "of", "the", "individual", "times", "for", "this", "Tms", "object", "with", "those", "of", "the", "other", "Tms", "object", "." ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/stdlib/benchmark.rb#L532-L549
11,680
opal/opal
lib/opal/config.rb
Opal.Config.config_option
def config_option(name, default_value, options = {}) compiler = options.fetch(:compiler_option, nil) valid_values = options.fetch(:valid_values, [true, false]) config_options[name] = { default: default_value, compiler: compiler } define_singleton_method(name) { config.fetch(name, default_value) } define_singleton_method("#{name}=") do |value| unless valid_values.any? { |valid_value| valid_value === value } raise ArgumentError, "Not a valid value for option #{self}.#{name}, provided #{value.inspect}. "\ "Must be #{valid_values.inspect} === #{value.inspect}" end config[name] = value end end
ruby
def config_option(name, default_value, options = {}) compiler = options.fetch(:compiler_option, nil) valid_values = options.fetch(:valid_values, [true, false]) config_options[name] = { default: default_value, compiler: compiler } define_singleton_method(name) { config.fetch(name, default_value) } define_singleton_method("#{name}=") do |value| unless valid_values.any? { |valid_value| valid_value === value } raise ArgumentError, "Not a valid value for option #{self}.#{name}, provided #{value.inspect}. "\ "Must be #{valid_values.inspect} === #{value.inspect}" end config[name] = value end end
[ "def", "config_option", "(", "name", ",", "default_value", ",", "options", "=", "{", "}", ")", "compiler", "=", "options", ".", "fetch", "(", ":compiler_option", ",", "nil", ")", "valid_values", "=", "options", ".", "fetch", "(", ":valid_values", ",", "[", "true", ",", "false", "]", ")", "config_options", "[", "name", "]", "=", "{", "default", ":", "default_value", ",", "compiler", ":", "compiler", "}", "define_singleton_method", "(", "name", ")", "{", "config", ".", "fetch", "(", "name", ",", "default_value", ")", "}", "define_singleton_method", "(", "\"#{name}=\"", ")", "do", "|", "value", "|", "unless", "valid_values", ".", "any?", "{", "|", "valid_value", "|", "valid_value", "===", "value", "}", "raise", "ArgumentError", ",", "\"Not a valid value for option #{self}.#{name}, provided #{value.inspect}. \"", "\"Must be #{valid_values.inspect} === #{value.inspect}\"", "end", "config", "[", "name", "]", "=", "value", "end", "end" ]
Defines a new configuration option @param [String] name the option name @param [Object] default_value the option's default value @!macro [attach] property @!attribute [rw] $1
[ "Defines", "a", "new", "configuration", "option" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/lib/opal/config.rb#L21-L39
11,681
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_float
def read_float s = read_string(cache: false) result = if s == 'nan' 0.0 / 0 elsif s == 'inf' 1.0 / 0 elsif s == '-inf' -1.0 / 0 else s.to_f end @object_cache << result result end
ruby
def read_float s = read_string(cache: false) result = if s == 'nan' 0.0 / 0 elsif s == 'inf' 1.0 / 0 elsif s == '-inf' -1.0 / 0 else s.to_f end @object_cache << result result end
[ "def", "read_float", "s", "=", "read_string", "(", "cache", ":", "false", ")", "result", "=", "if", "s", "==", "'nan'", "0.0", "/", "0", "elsif", "s", "==", "'inf'", "1.0", "/", "0", "elsif", "s", "==", "'-inf'", "-", "1.0", "/", "0", "else", "s", ".", "to_f", "end", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns Float from an input stream @example 123.456 Is encoded as 'f', '123.456'
[ "Reads", "and", "returns", "Float", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L155-L168
11,682
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_bignum
def read_bignum sign = read_char == '-' ? -1 : 1 size = read_fixnum * 2 result = 0 (0...size).each do |exp| result += read_char.ord * 2**(exp * 8) end result = result.to_i * sign @object_cache << result result end
ruby
def read_bignum sign = read_char == '-' ? -1 : 1 size = read_fixnum * 2 result = 0 (0...size).each do |exp| result += read_char.ord * 2**(exp * 8) end result = result.to_i * sign @object_cache << result result end
[ "def", "read_bignum", "sign", "=", "read_char", "==", "'-'", "?", "-", "1", ":", "1", "size", "=", "read_fixnum", "*", "2", "result", "=", "0", "(", "0", "...", "size", ")", ".", "each", "do", "|", "exp", "|", "result", "+=", "read_char", ".", "ord", "*", "2", "**", "(", "exp", "*", "8", ")", "end", "result", "=", "result", ".", "to_i", "*", "sign", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns Bignum from an input stream
[ "Reads", "and", "returns", "Bignum", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L172-L182
11,683
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_regexp
def read_regexp string = read_string(cache: false) options = read_byte result = Regexp.new(string, options) @object_cache << result result end
ruby
def read_regexp string = read_string(cache: false) options = read_byte result = Regexp.new(string, options) @object_cache << result result end
[ "def", "read_regexp", "string", "=", "read_string", "(", "cache", ":", "false", ")", "options", "=", "read_byte", "result", "=", "Regexp", ".", "new", "(", "string", ",", "options", ")", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns Regexp from an input stream @example r = /regexp/mix is encoded as '/', 'regexp', r.options.chr
[ "Reads", "and", "returns", "Regexp", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L311-L318
11,684
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_struct
def read_struct klass_name = read(cache: false) klass = safe_const_get(klass_name) attributes = read_hash(cache: false) args = attributes.values_at(*klass.members) result = klass.new(*args) @object_cache << result result end
ruby
def read_struct klass_name = read(cache: false) klass = safe_const_get(klass_name) attributes = read_hash(cache: false) args = attributes.values_at(*klass.members) result = klass.new(*args) @object_cache << result result end
[ "def", "read_struct", "klass_name", "=", "read", "(", "cache", ":", "false", ")", "klass", "=", "safe_const_get", "(", "klass_name", ")", "attributes", "=", "read_hash", "(", "cache", ":", "false", ")", "args", "=", "attributes", ".", "values_at", "(", "klass", ".", "members", ")", "result", "=", "klass", ".", "new", "(", "args", ")", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns a Struct from an input stream @example Point = Struct.new(:x, :y) Point.new(100, 200) is encoded as 'S', :Point, {:x => 100, :y => 200}
[ "Reads", "and", "returns", "a", "Struct", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L328-L336
11,685
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_class
def read_class klass_name = read_string(cache: false) result = safe_const_get(klass_name) unless result.class == Class raise ArgumentError, "#{klass_name} does not refer to a Class" end @object_cache << result result end
ruby
def read_class klass_name = read_string(cache: false) result = safe_const_get(klass_name) unless result.class == Class raise ArgumentError, "#{klass_name} does not refer to a Class" end @object_cache << result result end
[ "def", "read_class", "klass_name", "=", "read_string", "(", "cache", ":", "false", ")", "result", "=", "safe_const_get", "(", "klass_name", ")", "unless", "result", ".", "class", "==", "Class", "raise", "ArgumentError", ",", "\"#{klass_name} does not refer to a Class\"", "end", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns a Class from an input stream @example String is encoded as 'c', 'String'
[ "Reads", "and", "returns", "a", "Class", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L345-L353
11,686
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_module
def read_module mod_name = read_string(cache: false) result = safe_const_get(mod_name) unless result.class == Module raise ArgumentError, "#{mod_name} does not refer to a Module" end @object_cache << result result end
ruby
def read_module mod_name = read_string(cache: false) result = safe_const_get(mod_name) unless result.class == Module raise ArgumentError, "#{mod_name} does not refer to a Module" end @object_cache << result result end
[ "def", "read_module", "mod_name", "=", "read_string", "(", "cache", ":", "false", ")", "result", "=", "safe_const_get", "(", "mod_name", ")", "unless", "result", ".", "class", "==", "Module", "raise", "ArgumentError", ",", "\"#{mod_name} does not refer to a Module\"", "end", "@object_cache", "<<", "result", "result", "end" ]
Reads and returns a Module from an input stream @example Kernel is encoded as 'm', 'Kernel'
[ "Reads", "and", "returns", "a", "Module", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L362-L370
11,687
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_object
def read_object klass_name = read(cache: false) klass = safe_const_get(klass_name) object = klass.allocate @object_cache << object ivars = read_hash(cache: false) ivars.each do |name, value| if name[0] == '@' object.instance_variable_set(name, value) else # MRI allows an object to have ivars that do not start from '@' # https://github.com/ruby/ruby/blob/ab3a40c1031ff3a0535f6bcf26de40de37dbb1db/range.c#L1225 `object[name] = value` end end object end
ruby
def read_object klass_name = read(cache: false) klass = safe_const_get(klass_name) object = klass.allocate @object_cache << object ivars = read_hash(cache: false) ivars.each do |name, value| if name[0] == '@' object.instance_variable_set(name, value) else # MRI allows an object to have ivars that do not start from '@' # https://github.com/ruby/ruby/blob/ab3a40c1031ff3a0535f6bcf26de40de37dbb1db/range.c#L1225 `object[name] = value` end end object end
[ "def", "read_object", "klass_name", "=", "read", "(", "cache", ":", "false", ")", "klass", "=", "safe_const_get", "(", "klass_name", ")", "object", "=", "klass", ".", "allocate", "@object_cache", "<<", "object", "ivars", "=", "read_hash", "(", "cache", ":", "false", ")", "ivars", ".", "each", "do", "|", "name", ",", "value", "|", "if", "name", "[", "0", "]", "==", "'@'", "object", ".", "instance_variable_set", "(", "name", ",", "value", ")", "else", "# MRI allows an object to have ivars that do not start from '@'", "# https://github.com/ruby/ruby/blob/ab3a40c1031ff3a0535f6bcf26de40de37dbb1db/range.c#L1225", "`", "`", "end", "end", "object", "end" ]
Reads and returns an abstract object from an input stream @example obj = Object.new obj.instance_variable_set(:@ivar, 100) obj is encoded as 'o', :Object, {:@ivar => 100} The only exception is a Range class (and its subclasses) For some reason in MRI isntances of this class have instance variables - begin - end - excl without '@' perfix.
[ "Reads", "and", "returns", "an", "abstract", "object", "from", "an", "input", "stream" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L388-L407
11,688
opal/opal
opal/corelib/marshal/read_buffer.rb
Marshal.ReadBuffer.read_extended_object
def read_extended_object mod = safe_const_get(read) object = read object.extend(mod) object end
ruby
def read_extended_object mod = safe_const_get(read) object = read object.extend(mod) object end
[ "def", "read_extended_object", "mod", "=", "safe_const_get", "(", "read", ")", "object", "=", "read", "object", ".", "extend", "(", "mod", ")", "object", "end" ]
Reads an object that was dynamically extended before marshaling like @example M1 = Module.new M2 = Module.new obj = Object.new obj.extend(M1) obj.extend(M2) obj is encoded as 'e', :M2, :M1, obj
[ "Reads", "an", "object", "that", "was", "dynamically", "extended", "before", "marshaling", "like" ]
41aedc0fd62aab00d3c117ba0caf00206bedd981
https://github.com/opal/opal/blob/41aedc0fd62aab00d3c117ba0caf00206bedd981/opal/corelib/marshal/read_buffer.rb#L437-L442
11,689
SamSaffron/memory_profiler
lib/memory_profiler/reporter.rb
MemoryProfiler.Reporter.run
def run(&block) start begin yield rescue Exception ObjectSpace.trace_object_allocations_stop GC.enable raise else stop end end
ruby
def run(&block) start begin yield rescue Exception ObjectSpace.trace_object_allocations_stop GC.enable raise else stop end end
[ "def", "run", "(", "&", "block", ")", "start", "begin", "yield", "rescue", "Exception", "ObjectSpace", ".", "trace_object_allocations_stop", "GC", ".", "enable", "raise", "else", "stop", "end", "end" ]
Collects object allocation and memory of ruby code inside of passed block.
[ "Collects", "object", "allocation", "and", "memory", "of", "ruby", "code", "inside", "of", "passed", "block", "." ]
bd87ff68559623d12c827800ee795475db4d5b8b
https://github.com/SamSaffron/memory_profiler/blob/bd87ff68559623d12c827800ee795475db4d5b8b/lib/memory_profiler/reporter.rb#L71-L82
11,690
SamSaffron/memory_profiler
lib/memory_profiler/reporter.rb
MemoryProfiler.Reporter.object_list
def object_list(generation) rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] helper = Helpers.new result = StatHash.new.compare_by_identity ObjectSpace.each_object do |obj| next unless ObjectSpace.allocation_generation(obj) == generation file = ObjectSpace.allocation_sourcefile(obj) || "(no name)" next if @ignore_files && @ignore_files =~ file next if @allow_files && !(@allow_files =~ file) klass = obj.class rescue nil unless Class === klass # attempt to determine the true Class when .class returns something other than a Class klass = Kernel.instance_method(:class).bind(obj).call end next if @trace && !trace.include?(klass) begin line = ObjectSpace.allocation_sourceline(obj) location = helper.lookup_location(file, line) class_name = helper.lookup_class_name(klass) gem = helper.guess_gem(file) # we do memsize first to avoid freezing as a side effect and shifting # storage to the new frozen string, this happens on @hash[s] in lookup_string memsize = ObjectSpace.memsize_of(obj) string = klass == String ? helper.lookup_string(obj) : nil # compensate for API bug memsize = rvalue_size if memsize > 100_000_000_000 result[obj.__id__] = MemoryProfiler::Stat.new(class_name, gem, file, location, memsize, string) rescue # give up if any any error occurs inspecting the object end end result end
ruby
def object_list(generation) rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] helper = Helpers.new result = StatHash.new.compare_by_identity ObjectSpace.each_object do |obj| next unless ObjectSpace.allocation_generation(obj) == generation file = ObjectSpace.allocation_sourcefile(obj) || "(no name)" next if @ignore_files && @ignore_files =~ file next if @allow_files && !(@allow_files =~ file) klass = obj.class rescue nil unless Class === klass # attempt to determine the true Class when .class returns something other than a Class klass = Kernel.instance_method(:class).bind(obj).call end next if @trace && !trace.include?(klass) begin line = ObjectSpace.allocation_sourceline(obj) location = helper.lookup_location(file, line) class_name = helper.lookup_class_name(klass) gem = helper.guess_gem(file) # we do memsize first to avoid freezing as a side effect and shifting # storage to the new frozen string, this happens on @hash[s] in lookup_string memsize = ObjectSpace.memsize_of(obj) string = klass == String ? helper.lookup_string(obj) : nil # compensate for API bug memsize = rvalue_size if memsize > 100_000_000_000 result[obj.__id__] = MemoryProfiler::Stat.new(class_name, gem, file, location, memsize, string) rescue # give up if any any error occurs inspecting the object end end result end
[ "def", "object_list", "(", "generation", ")", "rvalue_size", "=", "GC", "::", "INTERNAL_CONSTANTS", "[", ":RVALUE_SIZE", "]", "helper", "=", "Helpers", ".", "new", "result", "=", "StatHash", ".", "new", ".", "compare_by_identity", "ObjectSpace", ".", "each_object", "do", "|", "obj", "|", "next", "unless", "ObjectSpace", ".", "allocation_generation", "(", "obj", ")", "==", "generation", "file", "=", "ObjectSpace", ".", "allocation_sourcefile", "(", "obj", ")", "||", "\"(no name)\"", "next", "if", "@ignore_files", "&&", "@ignore_files", "=~", "file", "next", "if", "@allow_files", "&&", "!", "(", "@allow_files", "=~", "file", ")", "klass", "=", "obj", ".", "class", "rescue", "nil", "unless", "Class", "===", "klass", "# attempt to determine the true Class when .class returns something other than a Class", "klass", "=", "Kernel", ".", "instance_method", "(", ":class", ")", ".", "bind", "(", "obj", ")", ".", "call", "end", "next", "if", "@trace", "&&", "!", "trace", ".", "include?", "(", "klass", ")", "begin", "line", "=", "ObjectSpace", ".", "allocation_sourceline", "(", "obj", ")", "location", "=", "helper", ".", "lookup_location", "(", "file", ",", "line", ")", "class_name", "=", "helper", ".", "lookup_class_name", "(", "klass", ")", "gem", "=", "helper", ".", "guess_gem", "(", "file", ")", "# we do memsize first to avoid freezing as a side effect and shifting", "# storage to the new frozen string, this happens on @hash[s] in lookup_string", "memsize", "=", "ObjectSpace", ".", "memsize_of", "(", "obj", ")", "string", "=", "klass", "==", "String", "?", "helper", ".", "lookup_string", "(", "obj", ")", ":", "nil", "# compensate for API bug", "memsize", "=", "rvalue_size", "if", "memsize", ">", "100_000_000_000", "result", "[", "obj", ".", "__id__", "]", "=", "MemoryProfiler", "::", "Stat", ".", "new", "(", "class_name", ",", "gem", ",", "file", ",", "location", ",", "memsize", ",", "string", ")", "rescue", "# give up if any any error occurs inspecting the object", "end", "end", "result", "end" ]
Iterates through objects in memory of a given generation. Stores results along with meta data of objects collected.
[ "Iterates", "through", "objects", "in", "memory", "of", "a", "given", "generation", ".", "Stores", "results", "along", "with", "meta", "data", "of", "objects", "collected", "." ]
bd87ff68559623d12c827800ee795475db4d5b8b
https://github.com/SamSaffron/memory_profiler/blob/bd87ff68559623d12c827800ee795475db4d5b8b/lib/memory_profiler/reporter.rb#L88-L129
11,691
SamSaffron/memory_profiler
lib/memory_profiler/results.rb
MemoryProfiler.Results.pretty_print
def pretty_print(io = $stdout, **options) # Handle the special case that Ruby PrettyPrint expects `pretty_print` # to be a customized pretty printing function for a class return io.pp_object(self) if defined?(PP) && io.is_a?(PP) io = File.open(options[:to_file], "w") if options[:to_file] color_output = options.fetch(:color_output) { io.respond_to?(:isatty) && io.isatty } @colorize = color_output ? Polychrome.new : Monochrome.new if options[:scale_bytes] total_allocated_output = scale_bytes(total_allocated_memsize) total_retained_output = scale_bytes(total_retained_memsize) else total_allocated_output = "#{total_allocated_memsize} bytes" total_retained_output = "#{total_retained_memsize} bytes" end io.puts "Total allocated: #{total_allocated_output} (#{total_allocated} objects)" io.puts "Total retained: #{total_retained_output} (#{total_retained} objects)" if options[:detailed_report] != false io.puts TYPES.each do |type| METRICS.each do |metric| NAMES.each do |name| scale_data = metric == "memory" && options[:scale_bytes] dump "#{type} #{metric} by #{name}", self.send("#{type}_#{metric}_by_#{name}"), io, scale_data end end end end io.puts dump_strings(io, "Allocated", strings_allocated, limit: options[:allocated_strings]) io.puts dump_strings(io, "Retained", strings_retained, limit: options[:retained_strings]) io.close if io.is_a? File end
ruby
def pretty_print(io = $stdout, **options) # Handle the special case that Ruby PrettyPrint expects `pretty_print` # to be a customized pretty printing function for a class return io.pp_object(self) if defined?(PP) && io.is_a?(PP) io = File.open(options[:to_file], "w") if options[:to_file] color_output = options.fetch(:color_output) { io.respond_to?(:isatty) && io.isatty } @colorize = color_output ? Polychrome.new : Monochrome.new if options[:scale_bytes] total_allocated_output = scale_bytes(total_allocated_memsize) total_retained_output = scale_bytes(total_retained_memsize) else total_allocated_output = "#{total_allocated_memsize} bytes" total_retained_output = "#{total_retained_memsize} bytes" end io.puts "Total allocated: #{total_allocated_output} (#{total_allocated} objects)" io.puts "Total retained: #{total_retained_output} (#{total_retained} objects)" if options[:detailed_report] != false io.puts TYPES.each do |type| METRICS.each do |metric| NAMES.each do |name| scale_data = metric == "memory" && options[:scale_bytes] dump "#{type} #{metric} by #{name}", self.send("#{type}_#{metric}_by_#{name}"), io, scale_data end end end end io.puts dump_strings(io, "Allocated", strings_allocated, limit: options[:allocated_strings]) io.puts dump_strings(io, "Retained", strings_retained, limit: options[:retained_strings]) io.close if io.is_a? File end
[ "def", "pretty_print", "(", "io", "=", "$stdout", ",", "**", "options", ")", "# Handle the special case that Ruby PrettyPrint expects `pretty_print`", "# to be a customized pretty printing function for a class", "return", "io", ".", "pp_object", "(", "self", ")", "if", "defined?", "(", "PP", ")", "&&", "io", ".", "is_a?", "(", "PP", ")", "io", "=", "File", ".", "open", "(", "options", "[", ":to_file", "]", ",", "\"w\"", ")", "if", "options", "[", ":to_file", "]", "color_output", "=", "options", ".", "fetch", "(", ":color_output", ")", "{", "io", ".", "respond_to?", "(", ":isatty", ")", "&&", "io", ".", "isatty", "}", "@colorize", "=", "color_output", "?", "Polychrome", ".", "new", ":", "Monochrome", ".", "new", "if", "options", "[", ":scale_bytes", "]", "total_allocated_output", "=", "scale_bytes", "(", "total_allocated_memsize", ")", "total_retained_output", "=", "scale_bytes", "(", "total_retained_memsize", ")", "else", "total_allocated_output", "=", "\"#{total_allocated_memsize} bytes\"", "total_retained_output", "=", "\"#{total_retained_memsize} bytes\"", "end", "io", ".", "puts", "\"Total allocated: #{total_allocated_output} (#{total_allocated} objects)\"", "io", ".", "puts", "\"Total retained: #{total_retained_output} (#{total_retained} objects)\"", "if", "options", "[", ":detailed_report", "]", "!=", "false", "io", ".", "puts", "TYPES", ".", "each", "do", "|", "type", "|", "METRICS", ".", "each", "do", "|", "metric", "|", "NAMES", ".", "each", "do", "|", "name", "|", "scale_data", "=", "metric", "==", "\"memory\"", "&&", "options", "[", ":scale_bytes", "]", "dump", "\"#{type} #{metric} by #{name}\"", ",", "self", ".", "send", "(", "\"#{type}_#{metric}_by_#{name}\"", ")", ",", "io", ",", "scale_data", "end", "end", "end", "end", "io", ".", "puts", "dump_strings", "(", "io", ",", "\"Allocated\"", ",", "strings_allocated", ",", "limit", ":", "options", "[", ":allocated_strings", "]", ")", "io", ".", "puts", "dump_strings", "(", "io", ",", "\"Retained\"", ",", "strings_retained", ",", "limit", ":", "options", "[", ":retained_strings", "]", ")", "io", ".", "close", "if", "io", ".", "is_a?", "File", "end" ]
Output the results of the report @param [Hash] options the options for output @option opts [String] :to_file a path to your log file @option opts [Boolean] :color_output a flag for whether to colorize output @option opts [Integer] :retained_strings how many retained strings to print @option opts [Integer] :allocated_strings how many allocated strings to print @option opts [Boolean] :detailed_report should report include detailed information @option opts [Boolean] :scale_bytes calculates unit prefixes for the numbers of bytes
[ "Output", "the", "results", "of", "the", "report" ]
bd87ff68559623d12c827800ee795475db4d5b8b
https://github.com/SamSaffron/memory_profiler/blob/bd87ff68559623d12c827800ee795475db4d5b8b/lib/memory_profiler/results.rb#L107-L146
11,692
soundcloud/lhm
lib/lhm/chunker.rb
Lhm.Chunker.execute
def execute return unless @start && @limit @next_to_insert = @start while @next_to_insert <= @limit stride = @throttler.stride affected_rows = @connection.update(copy(bottom, top(stride))) if @throttler && affected_rows > 0 @throttler.run end @printer.notify(bottom, @limit) @next_to_insert = top(stride) + 1 break if @start == @limit end @printer.end end
ruby
def execute return unless @start && @limit @next_to_insert = @start while @next_to_insert <= @limit stride = @throttler.stride affected_rows = @connection.update(copy(bottom, top(stride))) if @throttler && affected_rows > 0 @throttler.run end @printer.notify(bottom, @limit) @next_to_insert = top(stride) + 1 break if @start == @limit end @printer.end end
[ "def", "execute", "return", "unless", "@start", "&&", "@limit", "@next_to_insert", "=", "@start", "while", "@next_to_insert", "<=", "@limit", "stride", "=", "@throttler", ".", "stride", "affected_rows", "=", "@connection", ".", "update", "(", "copy", "(", "bottom", ",", "top", "(", "stride", ")", ")", ")", "if", "@throttler", "&&", "affected_rows", ">", "0", "@throttler", ".", "run", "end", "@printer", ".", "notify", "(", "bottom", ",", "@limit", ")", "@next_to_insert", "=", "top", "(", "stride", ")", "+", "1", "break", "if", "@start", "==", "@limit", "end", "@printer", ".", "end", "end" ]
Copy from origin to destination in chunks of size `stride`. Use the `throttler` class to sleep between each stride.
[ "Copy", "from", "origin", "to", "destination", "in", "chunks", "of", "size", "stride", ".", "Use", "the", "throttler", "class", "to", "sleep", "between", "each", "stride", "." ]
50907121eee514649fa944fb300d5d8a64fa873e
https://github.com/soundcloud/lhm/blob/50907121eee514649fa944fb300d5d8a64fa873e/lib/lhm/chunker.rb#L27-L43
11,693
soundcloud/lhm
lib/lhm/migrator.rb
Lhm.Migrator.rename_column
def rename_column(old, nu) col = @origin.columns[old.to_s] definition = col[:type] definition += ' NOT NULL' unless col[:is_nullable] definition += " DEFAULT #{@connection.quote(col[:column_default])}" if col[:column_default] ddl('alter table `%s` change column `%s` `%s` %s' % [@name, old, nu, definition]) @renames[old.to_s] = nu.to_s end
ruby
def rename_column(old, nu) col = @origin.columns[old.to_s] definition = col[:type] definition += ' NOT NULL' unless col[:is_nullable] definition += " DEFAULT #{@connection.quote(col[:column_default])}" if col[:column_default] ddl('alter table `%s` change column `%s` `%s` %s' % [@name, old, nu, definition]) @renames[old.to_s] = nu.to_s end
[ "def", "rename_column", "(", "old", ",", "nu", ")", "col", "=", "@origin", ".", "columns", "[", "old", ".", "to_s", "]", "definition", "=", "col", "[", ":type", "]", "definition", "+=", "' NOT NULL'", "unless", "col", "[", ":is_nullable", "]", "definition", "+=", "\" DEFAULT #{@connection.quote(col[:column_default])}\"", "if", "col", "[", ":column_default", "]", "ddl", "(", "'alter table `%s` change column `%s` `%s` %s'", "%", "[", "@name", ",", "old", ",", "nu", ",", "definition", "]", ")", "@renames", "[", "old", ".", "to_s", "]", "=", "nu", ".", "to_s", "end" ]
Rename an existing column. @example Lhm.change_table(:users) do |m| m.rename_column(:login, :username) end @param [String] old Name of the column to change @param [String] nu New name to use for the column
[ "Rename", "an", "existing", "column", "." ]
50907121eee514649fa944fb300d5d8a64fa873e
https://github.com/soundcloud/lhm/blob/50907121eee514649fa944fb300d5d8a64fa873e/lib/lhm/migrator.rb#L83-L92
11,694
soundcloud/lhm
lib/lhm/migrator.rb
Lhm.Migrator.remove_index
def remove_index(columns, index_name = nil) columns = [columns].flatten.map(&:to_sym) from_origin = @origin.indices.find { |_, cols| cols.map(&:to_sym) == columns } index_name ||= from_origin[0] unless from_origin.nil? index_name ||= idx_name(@origin.name, columns) ddl('drop index `%s` on `%s`' % [index_name, @name]) end
ruby
def remove_index(columns, index_name = nil) columns = [columns].flatten.map(&:to_sym) from_origin = @origin.indices.find { |_, cols| cols.map(&:to_sym) == columns } index_name ||= from_origin[0] unless from_origin.nil? index_name ||= idx_name(@origin.name, columns) ddl('drop index `%s` on `%s`' % [index_name, @name]) end
[ "def", "remove_index", "(", "columns", ",", "index_name", "=", "nil", ")", "columns", "=", "[", "columns", "]", ".", "flatten", ".", "map", "(", ":to_sym", ")", "from_origin", "=", "@origin", ".", "indices", ".", "find", "{", "|", "_", ",", "cols", "|", "cols", ".", "map", "(", ":to_sym", ")", "==", "columns", "}", "index_name", "||=", "from_origin", "[", "0", "]", "unless", "from_origin", ".", "nil?", "index_name", "||=", "idx_name", "(", "@origin", ".", "name", ",", "columns", ")", "ddl", "(", "'drop index `%s` on `%s`'", "%", "[", "index_name", ",", "@name", "]", ")", "end" ]
Remove an index from a table @example Lhm.change_table(:users) do |m| m.remove_index(:comment) m.remove_index([:username, :created_at]) end @param [String, Symbol, Array<String, Symbol>] columns A column name given as String or Symbol. An Array of Strings or Symbols for compound indexes. @param [String, Symbol] index_name Optional name of the index to be removed
[ "Remove", "an", "index", "from", "a", "table" ]
50907121eee514649fa944fb300d5d8a64fa873e
https://github.com/soundcloud/lhm/blob/50907121eee514649fa944fb300d5d8a64fa873e/lib/lhm/migrator.rb#L159-L165
11,695
gocardless/hutch
lib/hutch/worker.rb
Hutch.Worker.setup_queues
def setup_queues logger.info 'setting up queues' vetted = @consumers.reject { |c| group_configured? && group_restricted?(c) } vetted.each do |c| setup_queue(c) end end
ruby
def setup_queues logger.info 'setting up queues' vetted = @consumers.reject { |c| group_configured? && group_restricted?(c) } vetted.each do |c| setup_queue(c) end end
[ "def", "setup_queues", "logger", ".", "info", "'setting up queues'", "vetted", "=", "@consumers", ".", "reject", "{", "|", "c", "|", "group_configured?", "&&", "group_restricted?", "(", "c", ")", "}", "vetted", ".", "each", "do", "|", "c", "|", "setup_queue", "(", "c", ")", "end", "end" ]
Set up the queues for each of the worker's consumers.
[ "Set", "up", "the", "queues", "for", "each", "of", "the", "worker", "s", "consumers", "." ]
9314b3b8c84abeb78170730757f3eb8ccc4f54c5
https://github.com/gocardless/hutch/blob/9314b3b8c84abeb78170730757f3eb8ccc4f54c5/lib/hutch/worker.rb#L37-L43
11,696
gocardless/hutch
lib/hutch/worker.rb
Hutch.Worker.setup_queue
def setup_queue(consumer) logger.info "setting up queue: #{consumer.get_queue_name}" queue = @broker.queue(consumer.get_queue_name, consumer.get_arguments) @broker.bind_queue(queue, consumer.routing_keys) queue.subscribe(consumer_tag: unique_consumer_tag, manual_ack: true) do |*args| delivery_info, properties, payload = Hutch::Adapter.decode_message(*args) handle_message(consumer, delivery_info, properties, payload) end end
ruby
def setup_queue(consumer) logger.info "setting up queue: #{consumer.get_queue_name}" queue = @broker.queue(consumer.get_queue_name, consumer.get_arguments) @broker.bind_queue(queue, consumer.routing_keys) queue.subscribe(consumer_tag: unique_consumer_tag, manual_ack: true) do |*args| delivery_info, properties, payload = Hutch::Adapter.decode_message(*args) handle_message(consumer, delivery_info, properties, payload) end end
[ "def", "setup_queue", "(", "consumer", ")", "logger", ".", "info", "\"setting up queue: #{consumer.get_queue_name}\"", "queue", "=", "@broker", ".", "queue", "(", "consumer", ".", "get_queue_name", ",", "consumer", ".", "get_arguments", ")", "@broker", ".", "bind_queue", "(", "queue", ",", "consumer", ".", "routing_keys", ")", "queue", ".", "subscribe", "(", "consumer_tag", ":", "unique_consumer_tag", ",", "manual_ack", ":", "true", ")", "do", "|", "*", "args", "|", "delivery_info", ",", "properties", ",", "payload", "=", "Hutch", "::", "Adapter", ".", "decode_message", "(", "args", ")", "handle_message", "(", "consumer", ",", "delivery_info", ",", "properties", ",", "payload", ")", "end", "end" ]
Bind a consumer's routing keys to its queue, and set up a subscription to receive messages sent to the queue.
[ "Bind", "a", "consumer", "s", "routing", "keys", "to", "its", "queue", "and", "set", "up", "a", "subscription", "to", "receive", "messages", "sent", "to", "the", "queue", "." ]
9314b3b8c84abeb78170730757f3eb8ccc4f54c5
https://github.com/gocardless/hutch/blob/9314b3b8c84abeb78170730757f3eb8ccc4f54c5/lib/hutch/worker.rb#L47-L57
11,697
gocardless/hutch
lib/hutch/worker.rb
Hutch.Worker.handle_message
def handle_message(consumer, delivery_info, properties, payload) serializer = consumer.get_serializer || Hutch::Config[:serializer] logger.debug { spec = serializer.binary? ? "#{payload.bytesize} bytes" : "#{payload}" "message(#{properties.message_id || '-'}): " + "routing key: #{delivery_info.routing_key}, " + "consumer: #{consumer}, " + "payload: #{spec}" } message = Message.new(delivery_info, properties, payload, serializer) consumer_instance = consumer.new.tap { |c| c.broker, c.delivery_info = @broker, delivery_info } with_tracing(consumer_instance).handle(message) @broker.ack(delivery_info.delivery_tag) rescue => ex acknowledge_error(delivery_info, properties, @broker, ex) handle_error(properties, payload, consumer, ex) end
ruby
def handle_message(consumer, delivery_info, properties, payload) serializer = consumer.get_serializer || Hutch::Config[:serializer] logger.debug { spec = serializer.binary? ? "#{payload.bytesize} bytes" : "#{payload}" "message(#{properties.message_id || '-'}): " + "routing key: #{delivery_info.routing_key}, " + "consumer: #{consumer}, " + "payload: #{spec}" } message = Message.new(delivery_info, properties, payload, serializer) consumer_instance = consumer.new.tap { |c| c.broker, c.delivery_info = @broker, delivery_info } with_tracing(consumer_instance).handle(message) @broker.ack(delivery_info.delivery_tag) rescue => ex acknowledge_error(delivery_info, properties, @broker, ex) handle_error(properties, payload, consumer, ex) end
[ "def", "handle_message", "(", "consumer", ",", "delivery_info", ",", "properties", ",", "payload", ")", "serializer", "=", "consumer", ".", "get_serializer", "||", "Hutch", "::", "Config", "[", ":serializer", "]", "logger", ".", "debug", "{", "spec", "=", "serializer", ".", "binary?", "?", "\"#{payload.bytesize} bytes\"", ":", "\"#{payload}\"", "\"message(#{properties.message_id || '-'}): \"", "+", "\"routing key: #{delivery_info.routing_key}, \"", "+", "\"consumer: #{consumer}, \"", "+", "\"payload: #{spec}\"", "}", "message", "=", "Message", ".", "new", "(", "delivery_info", ",", "properties", ",", "payload", ",", "serializer", ")", "consumer_instance", "=", "consumer", ".", "new", ".", "tap", "{", "|", "c", "|", "c", ".", "broker", ",", "c", ".", "delivery_info", "=", "@broker", ",", "delivery_info", "}", "with_tracing", "(", "consumer_instance", ")", ".", "handle", "(", "message", ")", "@broker", ".", "ack", "(", "delivery_info", ".", "delivery_tag", ")", "rescue", "=>", "ex", "acknowledge_error", "(", "delivery_info", ",", "properties", ",", "@broker", ",", "ex", ")", "handle_error", "(", "properties", ",", "payload", ",", "consumer", ",", "ex", ")", "end" ]
Called internally when a new messages comes in from RabbitMQ. Responsible for wrapping up the message and passing it to the consumer.
[ "Called", "internally", "when", "a", "new", "messages", "comes", "in", "from", "RabbitMQ", ".", "Responsible", "for", "wrapping", "up", "the", "message", "and", "passing", "it", "to", "the", "consumer", "." ]
9314b3b8c84abeb78170730757f3eb8ccc4f54c5
https://github.com/gocardless/hutch/blob/9314b3b8c84abeb78170730757f3eb8ccc4f54c5/lib/hutch/worker.rb#L61-L78
11,698
gocardless/hutch
lib/hutch/broker.rb
Hutch.Broker.set_up_api_connection
def set_up_api_connection logger.info "connecting to rabbitmq HTTP API (#{api_config.sanitized_uri})" with_authentication_error_handler do with_connection_error_handler do @api_client = CarrotTop.new(host: api_config.host, port: api_config.port, user: api_config.username, password: api_config.password, ssl: api_config.ssl) @api_client.exchanges end end end
ruby
def set_up_api_connection logger.info "connecting to rabbitmq HTTP API (#{api_config.sanitized_uri})" with_authentication_error_handler do with_connection_error_handler do @api_client = CarrotTop.new(host: api_config.host, port: api_config.port, user: api_config.username, password: api_config.password, ssl: api_config.ssl) @api_client.exchanges end end end
[ "def", "set_up_api_connection", "logger", ".", "info", "\"connecting to rabbitmq HTTP API (#{api_config.sanitized_uri})\"", "with_authentication_error_handler", "do", "with_connection_error_handler", "do", "@api_client", "=", "CarrotTop", ".", "new", "(", "host", ":", "api_config", ".", "host", ",", "port", ":", "api_config", ".", "port", ",", "user", ":", "api_config", ".", "username", ",", "password", ":", "api_config", ".", "password", ",", "ssl", ":", "api_config", ".", "ssl", ")", "@api_client", ".", "exchanges", "end", "end", "end" ]
Set up the connection to the RabbitMQ management API. Unfortunately, this is necessary to do a few things that are impossible over AMQP. E.g. listing queues and bindings.
[ "Set", "up", "the", "connection", "to", "the", "RabbitMQ", "management", "API", ".", "Unfortunately", "this", "is", "necessary", "to", "do", "a", "few", "things", "that", "are", "impossible", "over", "AMQP", ".", "E", ".", "g", ".", "listing", "queues", "and", "bindings", "." ]
9314b3b8c84abeb78170730757f3eb8ccc4f54c5
https://github.com/gocardless/hutch/blob/9314b3b8c84abeb78170730757f3eb8ccc4f54c5/lib/hutch/broker.rb#L144-L155
11,699
gocardless/hutch
lib/hutch/broker.rb
Hutch.Broker.bindings
def bindings results = Hash.new { |hash, key| hash[key] = [] } api_client.bindings.each do |binding| next if binding['destination'] == binding['routing_key'] next unless binding['source'] == @config[:mq_exchange] next unless binding['vhost'] == @config[:mq_vhost] results[binding['destination']] << binding['routing_key'] end results end
ruby
def bindings results = Hash.new { |hash, key| hash[key] = [] } api_client.bindings.each do |binding| next if binding['destination'] == binding['routing_key'] next unless binding['source'] == @config[:mq_exchange] next unless binding['vhost'] == @config[:mq_vhost] results[binding['destination']] << binding['routing_key'] end results end
[ "def", "bindings", "results", "=", "Hash", ".", "new", "{", "|", "hash", ",", "key", "|", "hash", "[", "key", "]", "=", "[", "]", "}", "api_client", ".", "bindings", ".", "each", "do", "|", "binding", "|", "next", "if", "binding", "[", "'destination'", "]", "==", "binding", "[", "'routing_key'", "]", "next", "unless", "binding", "[", "'source'", "]", "==", "@config", "[", ":mq_exchange", "]", "next", "unless", "binding", "[", "'vhost'", "]", "==", "@config", "[", ":mq_vhost", "]", "results", "[", "binding", "[", "'destination'", "]", "]", "<<", "binding", "[", "'routing_key'", "]", "end", "results", "end" ]
Return a mapping of queue names to the routing keys they're bound to.
[ "Return", "a", "mapping", "of", "queue", "names", "to", "the", "routing", "keys", "they", "re", "bound", "to", "." ]
9314b3b8c84abeb78170730757f3eb8ccc4f54c5
https://github.com/gocardless/hutch/blob/9314b3b8c84abeb78170730757f3eb8ccc4f54c5/lib/hutch/broker.rb#L182-L191