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
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
4,200
scrapper/perobs
lib/perobs/FlatFileBlobHeader.rb
PEROBS.FlatFileBlobHeader.write
def write begin buf = [ @flags, @length, @id, @crc].pack(FORMAT) crc = Zlib.crc32(buf, 0) @file.seek(@addr) @file.write(buf + [ crc ].pack('L')) rescue IOError => e PEROBS.log.fatal "Cannot write blob header into flat file DB: " + e.message end end
ruby
def write begin buf = [ @flags, @length, @id, @crc].pack(FORMAT) crc = Zlib.crc32(buf, 0) @file.seek(@addr) @file.write(buf + [ crc ].pack('L')) rescue IOError => e PEROBS.log.fatal "Cannot write blob header into flat file DB: " + e.message end end
[ "def", "write", "begin", "buf", "=", "[", "@flags", ",", "@length", ",", "@id", ",", "@crc", "]", ".", "pack", "(", "FORMAT", ")", "crc", "=", "Zlib", ".", "crc32", "(", "buf", ",", "0", ")", "@file", ".", "seek", "(", "@addr", ")", "@file", ".", "write", "(", "buf", "+", "[", "crc", "]", ".", "pack", "(", "'L'", ")", ")", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot write blob header into flat file DB: \"", "+", "e", ".", "message", "end", "end" ]
Write the header to a given File.
[ "Write", "the", "header", "to", "a", "given", "File", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFileBlobHeader.rb#L182-L192
4,201
jeffnyman/tapestry
lib/tapestry/extensions/dom_observer.rb
Watir.Element.dom_updated?
def dom_updated?(delay: 1.1) element_call do begin driver.manage.timeouts.script_timeout = delay + 1 driver.execute_async_script(DOM_OBSERVER, wd, delay) rescue Selenium::WebDriver::Error::StaleElementReferenceError # This situation can occur when the DOM changes between two calls to # some element or aspect of the page. In this case, we are expecting # the DOM to be different so what's being handled here are those hard # to anticipate race conditions when "weird things happen" and DOM # updating plus script execution get interleaved. retry rescue Selenium::WebDriver::Error::JavascriptError => e # This situation can occur if the script execution has started before # a new page is fully loaded. The specific error being checked for # here is one that occurs when a new page is loaded as that page is # trying to execute a JavaScript function. retry if e.message.include?( 'document unloaded while waiting for result' ) raise ensure # Note that this setting here means any user-defined timeout would # effectively be overwritten. driver.manage.timeouts.script_timeout = 1 end end end
ruby
def dom_updated?(delay: 1.1) element_call do begin driver.manage.timeouts.script_timeout = delay + 1 driver.execute_async_script(DOM_OBSERVER, wd, delay) rescue Selenium::WebDriver::Error::StaleElementReferenceError # This situation can occur when the DOM changes between two calls to # some element or aspect of the page. In this case, we are expecting # the DOM to be different so what's being handled here are those hard # to anticipate race conditions when "weird things happen" and DOM # updating plus script execution get interleaved. retry rescue Selenium::WebDriver::Error::JavascriptError => e # This situation can occur if the script execution has started before # a new page is fully loaded. The specific error being checked for # here is one that occurs when a new page is loaded as that page is # trying to execute a JavaScript function. retry if e.message.include?( 'document unloaded while waiting for result' ) raise ensure # Note that this setting here means any user-defined timeout would # effectively be overwritten. driver.manage.timeouts.script_timeout = 1 end end end
[ "def", "dom_updated?", "(", "delay", ":", "1.1", ")", "element_call", "do", "begin", "driver", ".", "manage", ".", "timeouts", ".", "script_timeout", "=", "delay", "+", "1", "driver", ".", "execute_async_script", "(", "DOM_OBSERVER", ",", "wd", ",", "delay", ")", "rescue", "Selenium", "::", "WebDriver", "::", "Error", "::", "StaleElementReferenceError", "# This situation can occur when the DOM changes between two calls to", "# some element or aspect of the page. In this case, we are expecting", "# the DOM to be different so what's being handled here are those hard", "# to anticipate race conditions when \"weird things happen\" and DOM", "# updating plus script execution get interleaved.", "retry", "rescue", "Selenium", "::", "WebDriver", "::", "Error", "::", "JavascriptError", "=>", "e", "# This situation can occur if the script execution has started before", "# a new page is fully loaded. The specific error being checked for", "# here is one that occurs when a new page is loaded as that page is", "# trying to execute a JavaScript function.", "retry", "if", "e", ".", "message", ".", "include?", "(", "'document unloaded while waiting for result'", ")", "raise", "ensure", "# Note that this setting here means any user-defined timeout would", "# effectively be overwritten.", "driver", ".", "manage", ".", "timeouts", ".", "script_timeout", "=", "1", "end", "end", "end" ]
This method makes a call to `execute_async_script` which means that the DOM observer script must explicitly signal that it is finished by invoking a callback. In this case, the callback is nothing more than a delay. The delay is being used to allow the DOM to be updated before script actions continue. The method returns true if the DOM has been changed within the element context, while false means that the DOM has not yet finished changing. Note the wording: "has not finished changing." It's known that the DOM is changing because the observer has recognized that. So the question this method is helping to answer is "has it finished?" Consider the following element definition: p :page_list, id: 'navlist' You could then do this: page_list.dom_updated? That would return true if the DOM content for page_list has finished updating. If the DOM was in the process of being updated, this would return false. You could also do this: page_list.wait_until(&:dom_updated?).click This will use Watir's wait until functionality to wait for the DOM to be updated within the context of the element. Note that the "&:" is that the object that `dom_updated?` is being called on (in this case `page_list`) substitutes the ampersand. You can also structure it like this: page_list.wait_until do |element| element.dom_updated? end The default delay of waiting for the DOM to start updating is 1.1 second. However, you can pass a delay value when you call the method to set your own value, which can be useful for particular sensitivities in the application you are testing.
[ "This", "method", "makes", "a", "call", "to", "execute_async_script", "which", "means", "that", "the", "DOM", "observer", "script", "must", "explicitly", "signal", "that", "it", "is", "finished", "by", "invoking", "a", "callback", ".", "In", "this", "case", "the", "callback", "is", "nothing", "more", "than", "a", "delay", ".", "The", "delay", "is", "being", "used", "to", "allow", "the", "DOM", "to", "be", "updated", "before", "script", "actions", "continue", "." ]
da28652dd6de71e415cd2c01afd89f641938a05b
https://github.com/jeffnyman/tapestry/blob/da28652dd6de71e415cd2c01afd89f641938a05b/lib/tapestry/extensions/dom_observer.rb#L46-L73
4,202
scrapper/perobs
lib/perobs/DataBase.rb
PEROBS.DataBase.serialize
def serialize(obj) begin case @serializer when :marshal Marshal.dump(obj) when :json obj.to_json when :yaml YAML.dump(obj) end rescue => e PEROBS.log.fatal "Cannot serialize object as #{@serializer}: " + e.message end end
ruby
def serialize(obj) begin case @serializer when :marshal Marshal.dump(obj) when :json obj.to_json when :yaml YAML.dump(obj) end rescue => e PEROBS.log.fatal "Cannot serialize object as #{@serializer}: " + e.message end end
[ "def", "serialize", "(", "obj", ")", "begin", "case", "@serializer", "when", ":marshal", "Marshal", ".", "dump", "(", "obj", ")", "when", ":json", "obj", ".", "to_json", "when", ":yaml", "YAML", ".", "dump", "(", "obj", ")", "end", "rescue", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot serialize object as #{@serializer}: \"", "+", "e", ".", "message", "end", "end" ]
Serialize the given object using the object serializer. @param obj [ObjectBase] Object to serialize @return [String] Serialized version
[ "Serialize", "the", "given", "object", "using", "the", "object", "serializer", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DataBase.rb#L64-L78
4,203
scrapper/perobs
lib/perobs/DataBase.rb
PEROBS.DataBase.deserialize
def deserialize(raw) begin case @serializer when :marshal Marshal.load(raw) when :json JSON.parse(raw, :create_additions => true) when :yaml YAML.load(raw) end rescue => e PEROBS.log.fatal "Cannot de-serialize object with #{@serializer} " + "parser: " + e.message end end
ruby
def deserialize(raw) begin case @serializer when :marshal Marshal.load(raw) when :json JSON.parse(raw, :create_additions => true) when :yaml YAML.load(raw) end rescue => e PEROBS.log.fatal "Cannot de-serialize object with #{@serializer} " + "parser: " + e.message end end
[ "def", "deserialize", "(", "raw", ")", "begin", "case", "@serializer", "when", ":marshal", "Marshal", ".", "load", "(", "raw", ")", "when", ":json", "JSON", ".", "parse", "(", "raw", ",", ":create_additions", "=>", "true", ")", "when", ":yaml", "YAML", ".", "load", "(", "raw", ")", "end", "rescue", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot de-serialize object with #{@serializer} \"", "+", "\"parser: \"", "+", "e", ".", "message", "end", "end" ]
De-serialize the given String into a Ruby object. @param raw [String] @return [Hash] Deserialized version
[ "De", "-", "serialize", "the", "given", "String", "into", "a", "Ruby", "object", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DataBase.rb#L83-L97
4,204
scrapper/perobs
lib/perobs/DataBase.rb
PEROBS.DataBase.check_option
def check_option(name) value = instance_variable_get('@' + name) if @config.include?(name) # The database already existed and has a setting for this config # option. If it does not match the instance variable, adjust the # instance variable accordingly. unless @config[name] == value instance_variable_set('@' + name, @config[name]) end else # There is no such config option yet. Create it with the value of the # corresponding instance variable. @config[name] = value end end
ruby
def check_option(name) value = instance_variable_get('@' + name) if @config.include?(name) # The database already existed and has a setting for this config # option. If it does not match the instance variable, adjust the # instance variable accordingly. unless @config[name] == value instance_variable_set('@' + name, @config[name]) end else # There is no such config option yet. Create it with the value of the # corresponding instance variable. @config[name] = value end end
[ "def", "check_option", "(", "name", ")", "value", "=", "instance_variable_get", "(", "'@'", "+", "name", ")", "if", "@config", ".", "include?", "(", "name", ")", "# The database already existed and has a setting for this config", "# option. If it does not match the instance variable, adjust the", "# instance variable accordingly.", "unless", "@config", "[", "name", "]", "==", "value", "instance_variable_set", "(", "'@'", "+", "name", ",", "@config", "[", "name", "]", ")", "end", "else", "# There is no such config option yet. Create it with the value of the", "# corresponding instance variable.", "@config", "[", "name", "]", "=", "value", "end", "end" ]
Check a config option and adjust it if needed. @param name [String] Name of the config option.
[ "Check", "a", "config", "option", "and", "adjust", "it", "if", "needed", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DataBase.rb#L101-L116
4,205
scrapper/perobs
lib/perobs/DataBase.rb
PEROBS.DataBase.ensure_dir_exists
def ensure_dir_exists(dir) unless Dir.exist?(dir) begin Dir.mkdir(dir) rescue IOError => e PEROBS.log.fatal "Cannote create DB directory '#{dir}': #{e.message}" end end end
ruby
def ensure_dir_exists(dir) unless Dir.exist?(dir) begin Dir.mkdir(dir) rescue IOError => e PEROBS.log.fatal "Cannote create DB directory '#{dir}': #{e.message}" end end end
[ "def", "ensure_dir_exists", "(", "dir", ")", "unless", "Dir", ".", "exist?", "(", "dir", ")", "begin", "Dir", ".", "mkdir", "(", "dir", ")", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannote create DB directory '#{dir}': #{e.message}\"", "end", "end", "end" ]
Ensure that we have a directory to store the DB items.
[ "Ensure", "that", "we", "have", "a", "directory", "to", "store", "the", "DB", "items", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DataBase.rb#L121-L129
4,206
xinminlabs/synvert-core
lib/synvert/core/rewriter/gem_spec.rb
Synvert::Core.Rewriter::GemSpec.match?
def match? gemfile_lock_path = File.join(Configuration.instance.get(:path), 'Gemfile.lock') if File.exists? gemfile_lock_path parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path)) if spec = parser.specs.find { |spec| spec.name == @name } Gem::Version.new(spec.version).send(OPERATORS[@operator], @version) else false end else raise GemfileLockNotFound.new 'Gemfile.lock does not exist' end end
ruby
def match? gemfile_lock_path = File.join(Configuration.instance.get(:path), 'Gemfile.lock') if File.exists? gemfile_lock_path parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path)) if spec = parser.specs.find { |spec| spec.name == @name } Gem::Version.new(spec.version).send(OPERATORS[@operator], @version) else false end else raise GemfileLockNotFound.new 'Gemfile.lock does not exist' end end
[ "def", "match?", "gemfile_lock_path", "=", "File", ".", "join", "(", "Configuration", ".", "instance", ".", "get", "(", ":path", ")", ",", "'Gemfile.lock'", ")", "if", "File", ".", "exists?", "gemfile_lock_path", "parser", "=", "Bundler", "::", "LockfileParser", ".", "new", "(", "File", ".", "read", "(", "gemfile_lock_path", ")", ")", "if", "spec", "=", "parser", ".", "specs", ".", "find", "{", "|", "spec", "|", "spec", ".", "name", "==", "@name", "}", "Gem", "::", "Version", ".", "new", "(", "spec", ".", "version", ")", ".", "send", "(", "OPERATORS", "[", "@operator", "]", ",", "@version", ")", "else", "false", "end", "else", "raise", "GemfileLockNotFound", ".", "new", "'Gemfile.lock does not exist'", "end", "end" ]
Initialize a gem_spec. @param name [String] gem name @param comparator [Hash] comparator to gem version, e.g. {eq: '2.0.0'}, comparator key can be eq, lt, gt, lte, gte or ne. Check if the specified gem version in Gemfile.lock matches gem_spec comparator. @return [Boolean] true if matches, otherwise false. @raise [Synvert::Core::GemfileLockNotFound] raise if Gemfile.lock does not exist.
[ "Initialize", "a", "gem_spec", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/gem_spec.rb#L28-L40
4,207
sethvargo/community-zero
lib/community_zero/endpoints/cookbook_versions_version_endpoint.rb
CommunityZero.CookbookVersionsVersionEndpoint.response_hash_for
def response_hash_for(cookbook) { 'cookbook' => url_for(cookbook), 'average_rating' => cookbook.average_rating, 'version' => cookbook.version, 'license' => cookbook.license, 'file' => "http://s3.amazonaws.com/#{cookbook.name}.tgz", 'tarball_file_size' => cookbook.name.split('').map(&:ord).inject(&:+) * 25, # don't even 'created_at' => cookbook.created_at, 'updated_at' => cookbook.upadated_at, } end
ruby
def response_hash_for(cookbook) { 'cookbook' => url_for(cookbook), 'average_rating' => cookbook.average_rating, 'version' => cookbook.version, 'license' => cookbook.license, 'file' => "http://s3.amazonaws.com/#{cookbook.name}.tgz", 'tarball_file_size' => cookbook.name.split('').map(&:ord).inject(&:+) * 25, # don't even 'created_at' => cookbook.created_at, 'updated_at' => cookbook.upadated_at, } end
[ "def", "response_hash_for", "(", "cookbook", ")", "{", "'cookbook'", "=>", "url_for", "(", "cookbook", ")", ",", "'average_rating'", "=>", "cookbook", ".", "average_rating", ",", "'version'", "=>", "cookbook", ".", "version", ",", "'license'", "=>", "cookbook", ".", "license", ",", "'file'", "=>", "\"http://s3.amazonaws.com/#{cookbook.name}.tgz\"", ",", "'tarball_file_size'", "=>", "cookbook", ".", "name", ".", "split", "(", "''", ")", ".", "map", "(", ":ord", ")", ".", "inject", "(", ":+", ")", "*", "25", ",", "# don't even", "'created_at'", "=>", "cookbook", ".", "created_at", ",", "'updated_at'", "=>", "cookbook", ".", "upadated_at", ",", "}", "end" ]
The response hash for this cookbook. @param [CommunityZero::Cookbook] cookbook the cookbook to generate a hash for
[ "The", "response", "hash", "for", "this", "cookbook", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/endpoints/cookbook_versions_version_endpoint.rb#L45-L56
4,208
notonthehighstreet/chicago
lib/chicago/query.rb
Chicago.Query.order
def order(*ordering) @order = ordering.map do |c| if c.kind_of?(String) {:column => c, :ascending => true} else c.symbolize_keys! end end self end
ruby
def order(*ordering) @order = ordering.map do |c| if c.kind_of?(String) {:column => c, :ascending => true} else c.symbolize_keys! end end self end
[ "def", "order", "(", "*", "ordering", ")", "@order", "=", "ordering", ".", "map", "do", "|", "c", "|", "if", "c", ".", "kind_of?", "(", "String", ")", "{", ":column", "=>", "c", ",", ":ascending", "=>", "true", "}", "else", "c", ".", "symbolize_keys!", "end", "end", "self", "end" ]
Order the results by the specified columns. @param ordering an array of hashes, of the form {:column => "name", :ascending => true} @api public
[ "Order", "the", "results", "by", "the", "specified", "columns", "." ]
428e94f8089d2f36fdcff2e27ea2af572b816def
https://github.com/notonthehighstreet/chicago/blob/428e94f8089d2f36fdcff2e27ea2af572b816def/lib/chicago/query.rb#L79-L88
4,209
scrapper/perobs
lib/perobs/StackFile.rb
PEROBS.StackFile.close
def close begin @f.flush @f.flock(File::LOCK_UN) @f.close rescue IOError => e PEROBS.log.fatal "Cannot close stack file #{@file_name}: #{e.message}" end end
ruby
def close begin @f.flush @f.flock(File::LOCK_UN) @f.close rescue IOError => e PEROBS.log.fatal "Cannot close stack file #{@file_name}: #{e.message}" end end
[ "def", "close", "begin", "@f", ".", "flush", "@f", ".", "flock", "(", "File", "::", "LOCK_UN", ")", "@f", ".", "close", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot close stack file #{@file_name}: #{e.message}\"", "end", "end" ]
Close the stack file. This method must be called before the program is terminated to avoid data loss.
[ "Close", "the", "stack", "file", ".", "This", "method", "must", "be", "called", "before", "the", "program", "is", "terminated", "to", "avoid", "data", "loss", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/StackFile.rb#L64-L72
4,210
scrapper/perobs
lib/perobs/StackFile.rb
PEROBS.StackFile.push
def push(bytes) if bytes.length != @entry_bytes PEROBS.log.fatal "All stack entries must be #{@entry_bytes} " + "long. This entry is #{bytes.length} bytes long." end begin @f.seek(0, IO::SEEK_END) @f.write(bytes) rescue => e PEROBS.log.fatal "Cannot push to stack file #{@file_name}: #{e.message}" end end
ruby
def push(bytes) if bytes.length != @entry_bytes PEROBS.log.fatal "All stack entries must be #{@entry_bytes} " + "long. This entry is #{bytes.length} bytes long." end begin @f.seek(0, IO::SEEK_END) @f.write(bytes) rescue => e PEROBS.log.fatal "Cannot push to stack file #{@file_name}: #{e.message}" end end
[ "def", "push", "(", "bytes", ")", "if", "bytes", ".", "length", "!=", "@entry_bytes", "PEROBS", ".", "log", ".", "fatal", "\"All stack entries must be #{@entry_bytes} \"", "+", "\"long. This entry is #{bytes.length} bytes long.\"", "end", "begin", "@f", ".", "seek", "(", "0", ",", "IO", "::", "SEEK_END", ")", "@f", ".", "write", "(", "bytes", ")", "rescue", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot push to stack file #{@file_name}: #{e.message}\"", "end", "end" ]
Push the given bytes onto the stack file. @param bytes [String] Bytes to write.
[ "Push", "the", "given", "bytes", "onto", "the", "stack", "file", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/StackFile.rb#L85-L96
4,211
scrapper/perobs
lib/perobs/StackFile.rb
PEROBS.StackFile.pop
def pop begin return nil if @f.size == 0 @f.seek(-@entry_bytes, IO::SEEK_END) bytes = @f.read(@entry_bytes) @f.truncate(@f.size - @entry_bytes) @f.flush rescue => e PEROBS.log.fatal "Cannot pop from stack file #{@file_name}: " + e.message end bytes end
ruby
def pop begin return nil if @f.size == 0 @f.seek(-@entry_bytes, IO::SEEK_END) bytes = @f.read(@entry_bytes) @f.truncate(@f.size - @entry_bytes) @f.flush rescue => e PEROBS.log.fatal "Cannot pop from stack file #{@file_name}: " + e.message end bytes end
[ "def", "pop", "begin", "return", "nil", "if", "@f", ".", "size", "==", "0", "@f", ".", "seek", "(", "-", "@entry_bytes", ",", "IO", "::", "SEEK_END", ")", "bytes", "=", "@f", ".", "read", "(", "@entry_bytes", ")", "@f", ".", "truncate", "(", "@f", ".", "size", "-", "@entry_bytes", ")", "@f", ".", "flush", "rescue", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot pop from stack file #{@file_name}: \"", "+", "e", ".", "message", "end", "bytes", "end" ]
Pop the last entry from the stack file. @return [String or nil] Popped entry or nil if stack is already empty.
[ "Pop", "the", "last", "entry", "from", "the", "stack", "file", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/StackFile.rb#L100-L114
4,212
tagoh/ruby-bugzilla
lib/bugzilla/bug.rb
Bugzilla.Bug.get_comments
def get_comments(bugs) params = {} if bugs.kind_of?(Array) then params['ids'] = bugs elsif bugs.kind_of?(Integer) || bugs.kind_of?(String) then params['ids'] = [bugs] else raise ArgumentError, sprintf("Unknown type of arguments: %s", bugs.class) end result = comments(params) # not supporting comment_ids. so drop "comments". result['bugs'] end
ruby
def get_comments(bugs) params = {} if bugs.kind_of?(Array) then params['ids'] = bugs elsif bugs.kind_of?(Integer) || bugs.kind_of?(String) then params['ids'] = [bugs] else raise ArgumentError, sprintf("Unknown type of arguments: %s", bugs.class) end result = comments(params) # not supporting comment_ids. so drop "comments". result['bugs'] end
[ "def", "get_comments", "(", "bugs", ")", "params", "=", "{", "}", "if", "bugs", ".", "kind_of?", "(", "Array", ")", "then", "params", "[", "'ids'", "]", "=", "bugs", "elsif", "bugs", ".", "kind_of?", "(", "Integer", ")", "||", "bugs", ".", "kind_of?", "(", "String", ")", "then", "params", "[", "'ids'", "]", "=", "[", "bugs", "]", "else", "raise", "ArgumentError", ",", "sprintf", "(", "\"Unknown type of arguments: %s\"", ",", "bugs", ".", "class", ")", "end", "result", "=", "comments", "(", "params", ")", "# not supporting comment_ids. so drop \"comments\".", "result", "[", "'bugs'", "]", "end" ]
def get_bugs =begin rdoc ==== Bugzilla::Bug#get_comments(bugs) =end
[ "def", "get_bugs", "=", "begin", "rdoc" ]
5aabec1b045473bcd6e6ac7427b68adb3e3b4886
https://github.com/tagoh/ruby-bugzilla/blob/5aabec1b045473bcd6e6ac7427b68adb3e3b4886/lib/bugzilla/bug.rb#L107-L123
4,213
jeffnyman/tapestry
lib/tapestry/ready.rb
Tapestry.Ready.when_ready
def when_ready(simple_check = false, &_block) already_marked_ready = ready unless simple_check no_ready_check_possible unless block_given? end self.ready = ready? not_ready_validation(ready_error || 'NO REASON PROVIDED') unless ready yield self if block_given? ensure self.ready = already_marked_ready end
ruby
def when_ready(simple_check = false, &_block) already_marked_ready = ready unless simple_check no_ready_check_possible unless block_given? end self.ready = ready? not_ready_validation(ready_error || 'NO REASON PROVIDED') unless ready yield self if block_given? ensure self.ready = already_marked_ready end
[ "def", "when_ready", "(", "simple_check", "=", "false", ",", "&", "_block", ")", "already_marked_ready", "=", "ready", "unless", "simple_check", "no_ready_check_possible", "unless", "block_given?", "end", "self", ".", "ready", "=", "ready?", "not_ready_validation", "(", "ready_error", "||", "'NO REASON PROVIDED'", ")", "unless", "ready", "yield", "self", "if", "block_given?", "ensure", "self", ".", "ready", "=", "already_marked_ready", "end" ]
The `when_ready` method is called on an instance of an interface. This executes the provided validation block after the page has been loaded. The Ready object instance is yielded into the block. Calls to the `ready?` method use a poor-man's cache approach. The idea here being that when a page has confirmed that it is ready, meaning that no ready validations have failed, that information is stored so that any subsequent calls to `ready?` do not query the ready validations again.
[ "The", "when_ready", "method", "is", "called", "on", "an", "instance", "of", "an", "interface", ".", "This", "executes", "the", "provided", "validation", "block", "after", "the", "page", "has", "been", "loaded", ".", "The", "Ready", "object", "instance", "is", "yielded", "into", "the", "block", "." ]
da28652dd6de71e415cd2c01afd89f641938a05b
https://github.com/jeffnyman/tapestry/blob/da28652dd6de71e415cd2c01afd89f641938a05b/lib/tapestry/ready.rb#L55-L68
4,214
jeffnyman/tapestry
lib/tapestry/ready.rb
Tapestry.Ready.ready_validations_pass?
def ready_validations_pass? self.class.ready_validations.all? do |validation| passed, message = instance_eval(&validation) self.ready_error = message if message && !passed passed end end
ruby
def ready_validations_pass? self.class.ready_validations.all? do |validation| passed, message = instance_eval(&validation) self.ready_error = message if message && !passed passed end end
[ "def", "ready_validations_pass?", "self", ".", "class", ".", "ready_validations", ".", "all?", "do", "|", "validation", "|", "passed", ",", "message", "=", "instance_eval", "(", "validation", ")", "self", ".", "ready_error", "=", "message", "if", "message", "&&", "!", "passed", "passed", "end", "end" ]
This method checks if the ready validations that have been specified have passed. If any ready validation fails, no matter if others have succeeded, this method immediately returns false.
[ "This", "method", "checks", "if", "the", "ready", "validations", "that", "have", "been", "specified", "have", "passed", ".", "If", "any", "ready", "validation", "fails", "no", "matter", "if", "others", "have", "succeeded", "this", "method", "immediately", "returns", "false", "." ]
da28652dd6de71e415cd2c01afd89f641938a05b
https://github.com/jeffnyman/tapestry/blob/da28652dd6de71e415cd2c01afd89f641938a05b/lib/tapestry/ready.rb#L92-L98
4,215
xinminlabs/synvert-core
lib/synvert/core/rewriter/condition/unless_exist_condition.rb
Synvert::Core.Rewriter::UnlessExistCondition.match?
def match? match = false @instance.current_node.recursive_children do |child_node| match = match || (child_node && child_node.match?(@rules)) end !match end
ruby
def match? match = false @instance.current_node.recursive_children do |child_node| match = match || (child_node && child_node.match?(@rules)) end !match end
[ "def", "match?", "match", "=", "false", "@instance", ".", "current_node", ".", "recursive_children", "do", "|", "child_node", "|", "match", "=", "match", "||", "(", "child_node", "&&", "child_node", ".", "match?", "(", "@rules", ")", ")", "end", "!", "match", "end" ]
check if none of child node matches the rules.
[ "check", "if", "none", "of", "child", "node", "matches", "the", "rules", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/condition/unless_exist_condition.rb#L7-L13
4,216
pupeno/random_unique_id
lib/random_unique_id.rb
RandomUniqueId.ClassMethods.add_rid_related_validations
def add_rid_related_validations(options) validates(options[:field], presence: true) validates(options[:field], uniqueness: true) if options[:random_generation_method] != :uuid # If we're generating UUIDs, don't check for uniqueness end
ruby
def add_rid_related_validations(options) validates(options[:field], presence: true) validates(options[:field], uniqueness: true) if options[:random_generation_method] != :uuid # If we're generating UUIDs, don't check for uniqueness end
[ "def", "add_rid_related_validations", "(", "options", ")", "validates", "(", "options", "[", ":field", "]", ",", "presence", ":", "true", ")", "validates", "(", "options", "[", ":field", "]", ",", "uniqueness", ":", "true", ")", "if", "options", "[", ":random_generation_method", "]", "!=", ":uuid", "# If we're generating UUIDs, don't check for uniqueness", "end" ]
Add the rid related validations to the model. @param options [Hash] same as in RandomUniqueID.config
[ "Add", "the", "rid", "related", "validations", "to", "the", "model", "." ]
bab61f23a17a3f6ba9f7bc255805d4f9d34b8bfc
https://github.com/pupeno/random_unique_id/blob/bab61f23a17a3f6ba9f7bc255805d4f9d34b8bfc/lib/random_unique_id.rb#L118-L121
4,217
pupeno/random_unique_id
lib/random_unique_id.rb
RandomUniqueId.ClassMethods.define_rid_accessors
def define_rid_accessors(related_class, relationship_name) define_method("#{relationship_name}_rid") do self.send(relationship_name).try(random_unique_id_options[:field]) end define_method("#{relationship_name}_rid=") do |rid| record = related_class.find_by_rid(rid) self.send("#{relationship_name}=", record) record end end
ruby
def define_rid_accessors(related_class, relationship_name) define_method("#{relationship_name}_rid") do self.send(relationship_name).try(random_unique_id_options[:field]) end define_method("#{relationship_name}_rid=") do |rid| record = related_class.find_by_rid(rid) self.send("#{relationship_name}=", record) record end end
[ "def", "define_rid_accessors", "(", "related_class", ",", "relationship_name", ")", "define_method", "(", "\"#{relationship_name}_rid\"", ")", "do", "self", ".", "send", "(", "relationship_name", ")", ".", "try", "(", "random_unique_id_options", "[", ":field", "]", ")", "end", "define_method", "(", "\"#{relationship_name}_rid=\"", ")", "do", "|", "rid", "|", "record", "=", "related_class", ".", "find_by_rid", "(", "rid", ")", "self", ".", "send", "(", "\"#{relationship_name}=\"", ",", "record", ")", "record", "end", "end" ]
Defines the setter and getter for the RID of a relationship. @param related_class [Class] class in which the RID methods are going to be defined. @param relationship_name [String] name of the relationship for which the RID methods are going to be defined. @see RandomUniqueId::ClassMethods.belongs_to
[ "Defines", "the", "setter", "and", "getter", "for", "the", "RID", "of", "a", "relationship", "." ]
bab61f23a17a3f6ba9f7bc255805d4f9d34b8bfc
https://github.com/pupeno/random_unique_id/blob/bab61f23a17a3f6ba9f7bc255805d4f9d34b8bfc/lib/random_unique_id.rb#L128-L138
4,218
code-and-effect/effective_pages
app/models/effective/menu.rb
Effective.Menu.build
def build(&block) raise 'build must be called with a block' if !block_given? root = menu_items.build(title: 'Home', url: '/', lft: 1, rgt: 2) root.parent = true instance_exec(&block) # A call to dropdown or item root.rgt = menu_items.map(&:rgt).max self end
ruby
def build(&block) raise 'build must be called with a block' if !block_given? root = menu_items.build(title: 'Home', url: '/', lft: 1, rgt: 2) root.parent = true instance_exec(&block) # A call to dropdown or item root.rgt = menu_items.map(&:rgt).max self end
[ "def", "build", "(", "&", "block", ")", "raise", "'build must be called with a block'", "if", "!", "block_given?", "root", "=", "menu_items", ".", "build", "(", "title", ":", "'Home'", ",", "url", ":", "'/'", ",", "lft", ":", "1", ",", "rgt", ":", "2", ")", "root", ".", "parent", "=", "true", "instance_exec", "(", "block", ")", "# A call to dropdown or item", "root", ".", "rgt", "=", "menu_items", ".", "map", "(", ":rgt", ")", ".", "max", "self", "end" ]
This is the entry point to the DSL method for creating menu items
[ "This", "is", "the", "entry", "point", "to", "the", "DSL", "method", "for", "creating", "menu", "items" ]
ff00e2d76055985ab65f570747bc9a5f2748f817
https://github.com/code-and-effect/effective_pages/blob/ff00e2d76055985ab65f570747bc9a5f2748f817/app/models/effective/menu.rb#L58-L66
4,219
scrapper/perobs
lib/perobs/BTreeNode.rb
PEROBS.BTreeNode.search_key_index
def search_key_index(key) # Handle special case for empty keys list. return 0 if @keys.empty? # Keys are unique and always sorted. Use a binary search to find the # index that fits the given key. li = pi = 0 ui = @keys.size - 1 while li <= ui # The pivot element is always in the middle between the lower and upper # index. pi = li + (ui - li) / 2 if key < @keys[pi] # The pivot element is smaller than the key. Set the upper index to # the pivot index. ui = pi - 1 elsif key > @keys[pi] # The pivot element is larger than the key. Set the lower index to # the pivot index. li = pi + 1 else # We've found an exact match. For leaf nodes return the found index. # For branch nodes we have to add one to the index since the larger # child is the right one. return @is_leaf ? pi : pi + 1 end end # No exact match was found. For the insert operaton we need to return # the index of the first key that is larger than the given key. @keys[pi] < key ? pi + 1 : pi end
ruby
def search_key_index(key) # Handle special case for empty keys list. return 0 if @keys.empty? # Keys are unique and always sorted. Use a binary search to find the # index that fits the given key. li = pi = 0 ui = @keys.size - 1 while li <= ui # The pivot element is always in the middle between the lower and upper # index. pi = li + (ui - li) / 2 if key < @keys[pi] # The pivot element is smaller than the key. Set the upper index to # the pivot index. ui = pi - 1 elsif key > @keys[pi] # The pivot element is larger than the key. Set the lower index to # the pivot index. li = pi + 1 else # We've found an exact match. For leaf nodes return the found index. # For branch nodes we have to add one to the index since the larger # child is the right one. return @is_leaf ? pi : pi + 1 end end # No exact match was found. For the insert operaton we need to return # the index of the first key that is larger than the given key. @keys[pi] < key ? pi + 1 : pi end
[ "def", "search_key_index", "(", "key", ")", "# Handle special case for empty keys list.", "return", "0", "if", "@keys", ".", "empty?", "# Keys are unique and always sorted. Use a binary search to find the", "# index that fits the given key.", "li", "=", "pi", "=", "0", "ui", "=", "@keys", ".", "size", "-", "1", "while", "li", "<=", "ui", "# The pivot element is always in the middle between the lower and upper", "# index.", "pi", "=", "li", "+", "(", "ui", "-", "li", ")", "/", "2", "if", "key", "<", "@keys", "[", "pi", "]", "# The pivot element is smaller than the key. Set the upper index to", "# the pivot index.", "ui", "=", "pi", "-", "1", "elsif", "key", ">", "@keys", "[", "pi", "]", "# The pivot element is larger than the key. Set the lower index to", "# the pivot index.", "li", "=", "pi", "+", "1", "else", "# We've found an exact match. For leaf nodes return the found index.", "# For branch nodes we have to add one to the index since the larger", "# child is the right one.", "return", "@is_leaf", "?", "pi", ":", "pi", "+", "1", "end", "end", "# No exact match was found. For the insert operaton we need to return", "# the index of the first key that is larger than the given key.", "@keys", "[", "pi", "]", "<", "key", "?", "pi", "+", "1", ":", "pi", "end" ]
Search the keys of the node that fits the given key. The result is either the index of an exact match or the index of the position where the given key would have to be inserted. @param key [Integer] key to search for @return [Integer] Index of the matching key or the insert position.
[ "Search", "the", "keys", "of", "the", "node", "that", "fits", "the", "given", "key", ".", "The", "result", "is", "either", "the", "index", "of", "an", "exact", "match", "or", "the", "index", "of", "the", "position", "where", "the", "given", "key", "would", "have", "to", "be", "inserted", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeNode.rb#L563-L594
4,220
astro/ruby-sasl
lib/sasl/digest_md5.rb
SASL.DigestMD5.response_value
def response_value(nonce, nc, cnonce, qop, a2_prefix='AUTHENTICATE') a1_h = h("#{preferences.username}:#{preferences.realm}:#{preferences.password}") a1 = "#{a1_h}:#{nonce}:#{cnonce}" if preferences.authzid a1 += ":#{preferences.authzid}" end if qop && (qop.downcase == 'auth-int' || qop.downcase == 'auth-conf') a2 = "#{a2_prefix}:#{preferences.digest_uri}:00000000000000000000000000000000" else a2 = "#{a2_prefix}:#{preferences.digest_uri}" end hh("#{hh(a1)}:#{nonce}:#{nc}:#{cnonce}:#{qop}:#{hh(a2)}") end
ruby
def response_value(nonce, nc, cnonce, qop, a2_prefix='AUTHENTICATE') a1_h = h("#{preferences.username}:#{preferences.realm}:#{preferences.password}") a1 = "#{a1_h}:#{nonce}:#{cnonce}" if preferences.authzid a1 += ":#{preferences.authzid}" end if qop && (qop.downcase == 'auth-int' || qop.downcase == 'auth-conf') a2 = "#{a2_prefix}:#{preferences.digest_uri}:00000000000000000000000000000000" else a2 = "#{a2_prefix}:#{preferences.digest_uri}" end hh("#{hh(a1)}:#{nonce}:#{nc}:#{cnonce}:#{qop}:#{hh(a2)}") end
[ "def", "response_value", "(", "nonce", ",", "nc", ",", "cnonce", ",", "qop", ",", "a2_prefix", "=", "'AUTHENTICATE'", ")", "a1_h", "=", "h", "(", "\"#{preferences.username}:#{preferences.realm}:#{preferences.password}\"", ")", "a1", "=", "\"#{a1_h}:#{nonce}:#{cnonce}\"", "if", "preferences", ".", "authzid", "a1", "+=", "\":#{preferences.authzid}\"", "end", "if", "qop", "&&", "(", "qop", ".", "downcase", "==", "'auth-int'", "||", "qop", ".", "downcase", "==", "'auth-conf'", ")", "a2", "=", "\"#{a2_prefix}:#{preferences.digest_uri}:00000000000000000000000000000000\"", "else", "a2", "=", "\"#{a2_prefix}:#{preferences.digest_uri}\"", "end", "hh", "(", "\"#{hh(a1)}:#{nonce}:#{nc}:#{cnonce}:#{qop}:#{hh(a2)}\"", ")", "end" ]
Calculate the value for the response field
[ "Calculate", "the", "value", "for", "the", "response", "field" ]
e54d8950c9cfb6a51066fcbbe3ada9f0121aa7f4
https://github.com/astro/ruby-sasl/blob/e54d8950c9cfb6a51066fcbbe3ada9f0121aa7f4/lib/sasl/digest_md5.rb#L139-L151
4,221
regru/reg_api2-ruby
lib/reg_api2/request_contract.rb
RegApi2.RequestContract.to_hash
def to_hash arr return {} if arr.nil? return arr if arr.kind_of?(Hash) arr = [ arr.to_sym ] unless arr.kind_of?(Array) ret = {} arr.each { |key| ret[key.to_sym] = {} } ret end
ruby
def to_hash arr return {} if arr.nil? return arr if arr.kind_of?(Hash) arr = [ arr.to_sym ] unless arr.kind_of?(Array) ret = {} arr.each { |key| ret[key.to_sym] = {} } ret end
[ "def", "to_hash", "arr", "return", "{", "}", "if", "arr", ".", "nil?", "return", "arr", "if", "arr", ".", "kind_of?", "(", "Hash", ")", "arr", "=", "[", "arr", ".", "to_sym", "]", "unless", "arr", ".", "kind_of?", "(", "Array", ")", "ret", "=", "{", "}", "arr", ".", "each", "{", "|", "key", "|", "ret", "[", "key", ".", "to_sym", "]", "=", "{", "}", "}", "ret", "end" ]
Normalizes `required` and `optional` fields to the form of Hash with options. @param [NilClass,Hash,Array, etc.] arr Something to normalize.
[ "Normalizes", "required", "and", "optional", "fields", "to", "the", "form", "of", "Hash", "with", "options", "." ]
82fadffc9da6534761003b8a33edb77ab617df70
https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/request_contract.rb#L21-L28
4,222
regru/reg_api2-ruby
lib/reg_api2/request_contract.rb
RegApi2.RequestContract.fields_to_validate
def fields_to_validate required_fields = to_hash opts[:required] optional_fields = to_hash opts[:optional] required_fields.keys.each { |key| required_fields[key][:required] = true } optional_fields.merge(required_fields) end
ruby
def fields_to_validate required_fields = to_hash opts[:required] optional_fields = to_hash opts[:optional] required_fields.keys.each { |key| required_fields[key][:required] = true } optional_fields.merge(required_fields) end
[ "def", "fields_to_validate", "required_fields", "=", "to_hash", "opts", "[", ":required", "]", "optional_fields", "=", "to_hash", "opts", "[", ":optional", "]", "required_fields", ".", "keys", ".", "each", "{", "|", "key", "|", "required_fields", "[", "key", "]", "[", ":required", "]", "=", "true", "}", "optional_fields", ".", "merge", "(", "required_fields", ")", "end" ]
Gets fields to validate @return [Hash] Fields to validate.
[ "Gets", "fields", "to", "validate" ]
82fadffc9da6534761003b8a33edb77ab617df70
https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/request_contract.rb#L32-L37
4,223
regru/reg_api2-ruby
lib/reg_api2/request_contract.rb
RegApi2.RequestContract.validate_ipaddr
def validate_ipaddr key, value, opts if opts[:ipaddr] == true && value.kind_of?(String) value = IPAddr.new(value) end value.to_s end
ruby
def validate_ipaddr key, value, opts if opts[:ipaddr] == true && value.kind_of?(String) value = IPAddr.new(value) end value.to_s end
[ "def", "validate_ipaddr", "key", ",", "value", ",", "opts", "if", "opts", "[", ":ipaddr", "]", "==", "true", "&&", "value", ".", "kind_of?", "(", "String", ")", "value", "=", "IPAddr", ".", "new", "(", "value", ")", "end", "value", ".", "to_s", "end" ]
Validates specified `value` with `ipaddr` field. @param [Object] key Value to validate. @param [Object] value Value to validate. @param [Hash] opts opts with optional ipaddr field. @return [String] Updated `value`
[ "Validates", "specified", "value", "with", "ipaddr", "field", "." ]
82fadffc9da6534761003b8a33edb77ab617df70
https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/request_contract.rb#L73-L78
4,224
regru/reg_api2-ruby
lib/reg_api2/request_contract.rb
RegApi2.RequestContract.validate_presence_of_required_fields
def validate_presence_of_required_fields form, fields absent_fields = [] fields.each_pair do |key, opts| next unless opts[:required] if !form.has_key?(key) || form[key].nil? absent_fields << key end end unless absent_fields.empty? raise RegApi2::ContractError.new( "Required fields missed: #{absent_fields.join(', ')}", absent_fields ) end nil end
ruby
def validate_presence_of_required_fields form, fields absent_fields = [] fields.each_pair do |key, opts| next unless opts[:required] if !form.has_key?(key) || form[key].nil? absent_fields << key end end unless absent_fields.empty? raise RegApi2::ContractError.new( "Required fields missed: #{absent_fields.join(', ')}", absent_fields ) end nil end
[ "def", "validate_presence_of_required_fields", "form", ",", "fields", "absent_fields", "=", "[", "]", "fields", ".", "each_pair", "do", "|", "key", ",", "opts", "|", "next", "unless", "opts", "[", ":required", "]", "if", "!", "form", ".", "has_key?", "(", "key", ")", "||", "form", "[", "key", "]", ".", "nil?", "absent_fields", "<<", "key", "end", "end", "unless", "absent_fields", ".", "empty?", "raise", "RegApi2", "::", "ContractError", ".", "new", "(", "\"Required fields missed: #{absent_fields.join(', ')}\"", ",", "absent_fields", ")", "end", "nil", "end" ]
Validates specified `form` for presence of all required fields. @param [Hash] form Form to validate. @param [Hash] fields Fields to test. return void @raise ContractError
[ "Validates", "specified", "form", "for", "presence", "of", "all", "required", "fields", "." ]
82fadffc9da6534761003b8a33edb77ab617df70
https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/request_contract.rb#L85-L100
4,225
regru/reg_api2-ruby
lib/reg_api2/request_contract.rb
RegApi2.RequestContract.validate
def validate(form) fields = fields_to_validate return form if fields.empty? validate_presence_of_required_fields form, fields fields.each_pair do |key, opts| next if !form.has_key?(key) || form[key].nil? form[key] = validate_re key, form[key], opts form[key] = validate_iso_date key, form[key], opts form[key] = validate_ipaddr key, form[key], opts end form end
ruby
def validate(form) fields = fields_to_validate return form if fields.empty? validate_presence_of_required_fields form, fields fields.each_pair do |key, opts| next if !form.has_key?(key) || form[key].nil? form[key] = validate_re key, form[key], opts form[key] = validate_iso_date key, form[key], opts form[key] = validate_ipaddr key, form[key], opts end form end
[ "def", "validate", "(", "form", ")", "fields", "=", "fields_to_validate", "return", "form", "if", "fields", ".", "empty?", "validate_presence_of_required_fields", "form", ",", "fields", "fields", ".", "each_pair", "do", "|", "key", ",", "opts", "|", "next", "if", "!", "form", ".", "has_key?", "(", "key", ")", "||", "form", "[", "key", "]", ".", "nil?", "form", "[", "key", "]", "=", "validate_re", "key", ",", "form", "[", "key", "]", ",", "opts", "form", "[", "key", "]", "=", "validate_iso_date", "key", ",", "form", "[", "key", "]", ",", "opts", "form", "[", "key", "]", "=", "validate_ipaddr", "key", ",", "form", "[", "key", "]", ",", "opts", "end", "form", "end" ]
Validates specified `form` with `required` and `optional` fields. @param [Hash] form Form to validate. @return [Hash] Updated form. @raise ContractError
[ "Validates", "specified", "form", "with", "required", "and", "optional", "fields", "." ]
82fadffc9da6534761003b8a33edb77ab617df70
https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/request_contract.rb#L106-L121
4,226
scrapper/perobs
lib/perobs/BigTreeNode.rb
PEROBS.BigTreeNode.has_key?
def has_key?(key) node = self while node do # Find index of the entry that best fits the key. i = node.search_key_index(key) if node.is_leaf? # This is a leaf node. Check if there is an exact match for the # given key and return the corresponding value or nil. return node.keys[i] == key end # Descend into the right child node to continue the search. node = node.children[i] end PEROBS.log.fatal "Could not find proper node to get from while " + "looking for key #{key}" end
ruby
def has_key?(key) node = self while node do # Find index of the entry that best fits the key. i = node.search_key_index(key) if node.is_leaf? # This is a leaf node. Check if there is an exact match for the # given key and return the corresponding value or nil. return node.keys[i] == key end # Descend into the right child node to continue the search. node = node.children[i] end PEROBS.log.fatal "Could not find proper node to get from while " + "looking for key #{key}" end
[ "def", "has_key?", "(", "key", ")", "node", "=", "self", "while", "node", "do", "# Find index of the entry that best fits the key.", "i", "=", "node", ".", "search_key_index", "(", "key", ")", "if", "node", ".", "is_leaf?", "# This is a leaf node. Check if there is an exact match for the", "# given key and return the corresponding value or nil.", "return", "node", ".", "keys", "[", "i", "]", "==", "key", "end", "# Descend into the right child node to continue the search.", "node", "=", "node", ".", "children", "[", "i", "]", "end", "PEROBS", ".", "log", ".", "fatal", "\"Could not find proper node to get from while \"", "+", "\"looking for key #{key}\"", "end" ]
Return if given key is stored in the node. @param key [Integer] key to search for @return [Boolean] True if key was found, false otherwise
[ "Return", "if", "given", "key", "is", "stored", "in", "the", "node", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigTreeNode.rb#L169-L187
4,227
scrapper/perobs
lib/perobs/BigTreeNode.rb
PEROBS.BigTreeNode.remove_element
def remove_element(index) # Delete the key at the specified index. unless (key = @keys.delete_at(index)) PEROBS.log.fatal "Could not remove element #{index} from BigTreeNode " + "@#{@_id}" end update_branch_key(key) if index == 0 # Delete the corresponding value. removed_value = @values.delete_at(index) if @keys.length < min_keys if @prev_sibling && @prev_sibling.parent == @parent borrow_from_previous_sibling(@prev_sibling) || @prev_sibling.merge_with_leaf_node(myself) elsif @next_sibling && @next_sibling.parent == @parent borrow_from_next_sibling(@next_sibling) || merge_with_leaf_node(@next_sibling) elsif @parent PEROBS.log.fatal "Cannot not find adjecent leaf siblings" end end # The merge has potentially invalidated this node. After this method has # been called this copy of the node should no longer be used. removed_value end
ruby
def remove_element(index) # Delete the key at the specified index. unless (key = @keys.delete_at(index)) PEROBS.log.fatal "Could not remove element #{index} from BigTreeNode " + "@#{@_id}" end update_branch_key(key) if index == 0 # Delete the corresponding value. removed_value = @values.delete_at(index) if @keys.length < min_keys if @prev_sibling && @prev_sibling.parent == @parent borrow_from_previous_sibling(@prev_sibling) || @prev_sibling.merge_with_leaf_node(myself) elsif @next_sibling && @next_sibling.parent == @parent borrow_from_next_sibling(@next_sibling) || merge_with_leaf_node(@next_sibling) elsif @parent PEROBS.log.fatal "Cannot not find adjecent leaf siblings" end end # The merge has potentially invalidated this node. After this method has # been called this copy of the node should no longer be used. removed_value end
[ "def", "remove_element", "(", "index", ")", "# Delete the key at the specified index.", "unless", "(", "key", "=", "@keys", ".", "delete_at", "(", "index", ")", ")", "PEROBS", ".", "log", ".", "fatal", "\"Could not remove element #{index} from BigTreeNode \"", "+", "\"@#{@_id}\"", "end", "update_branch_key", "(", "key", ")", "if", "index", "==", "0", "# Delete the corresponding value.", "removed_value", "=", "@values", ".", "delete_at", "(", "index", ")", "if", "@keys", ".", "length", "<", "min_keys", "if", "@prev_sibling", "&&", "@prev_sibling", ".", "parent", "==", "@parent", "borrow_from_previous_sibling", "(", "@prev_sibling", ")", "||", "@prev_sibling", ".", "merge_with_leaf_node", "(", "myself", ")", "elsif", "@next_sibling", "&&", "@next_sibling", ".", "parent", "==", "@parent", "borrow_from_next_sibling", "(", "@next_sibling", ")", "||", "merge_with_leaf_node", "(", "@next_sibling", ")", "elsif", "@parent", "PEROBS", ".", "log", ".", "fatal", "\"Cannot not find adjecent leaf siblings\"", "end", "end", "# The merge has potentially invalidated this node. After this method has", "# been called this copy of the node should no longer be used.", "removed_value", "end" ]
Remove the element from a leaf node at the given index. @param index [Integer] The index of the entry to be removed @return [Object] The removed value
[ "Remove", "the", "element", "from", "a", "leaf", "node", "at", "the", "given", "index", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigTreeNode.rb#L518-L543
4,228
scrapper/perobs
lib/perobs/BigTreeNode.rb
PEROBS.BigTreeNode.remove_child
def remove_child(node) unless (index = search_node_index(node)) PEROBS.log.fatal "Cannot remove child #{node._id} from node #{@_id}" end if index == 0 # Removing the first child is a bit more complicated as the # corresponding branch key is in a parent node. key = @keys.shift update_branch_key(key) else # For all other children we can just remove the corresponding key. @keys.delete_at(index - 1) end # Remove the child node link. child = @children.delete_at(index) # If we remove the first or last leaf node we must update the reference # in the BigTree object. @tree.first_leaf = child.next_sibling if child == @tree.first_leaf @tree.last_leaf = child.prev_sibling if child == @tree.last_leaf # Unlink the neighbouring siblings from the child child.prev_sibling.next_sibling = child.next_sibling if child.prev_sibling child.next_sibling.prev_sibling = child.prev_sibling if child.next_sibling if @keys.length < min_keys # The node has become too small. Try borrowing a node from an adjecent # sibling or merge with an adjecent node. if @prev_sibling && @prev_sibling.parent == @parent borrow_from_previous_sibling(@prev_sibling) || @prev_sibling.merge_with_branch_node(myself) elsif @next_sibling && @next_sibling.parent == @parent borrow_from_next_sibling(@next_sibling) || merge_with_branch_node(@next_sibling) end end if @parent.nil? && @children.length <= 1 # If the node just below the root only has one child it will become # the new root node. new_root = @children.first new_root.parent = nil @tree.root = new_root end end
ruby
def remove_child(node) unless (index = search_node_index(node)) PEROBS.log.fatal "Cannot remove child #{node._id} from node #{@_id}" end if index == 0 # Removing the first child is a bit more complicated as the # corresponding branch key is in a parent node. key = @keys.shift update_branch_key(key) else # For all other children we can just remove the corresponding key. @keys.delete_at(index - 1) end # Remove the child node link. child = @children.delete_at(index) # If we remove the first or last leaf node we must update the reference # in the BigTree object. @tree.first_leaf = child.next_sibling if child == @tree.first_leaf @tree.last_leaf = child.prev_sibling if child == @tree.last_leaf # Unlink the neighbouring siblings from the child child.prev_sibling.next_sibling = child.next_sibling if child.prev_sibling child.next_sibling.prev_sibling = child.prev_sibling if child.next_sibling if @keys.length < min_keys # The node has become too small. Try borrowing a node from an adjecent # sibling or merge with an adjecent node. if @prev_sibling && @prev_sibling.parent == @parent borrow_from_previous_sibling(@prev_sibling) || @prev_sibling.merge_with_branch_node(myself) elsif @next_sibling && @next_sibling.parent == @parent borrow_from_next_sibling(@next_sibling) || merge_with_branch_node(@next_sibling) end end if @parent.nil? && @children.length <= 1 # If the node just below the root only has one child it will become # the new root node. new_root = @children.first new_root.parent = nil @tree.root = new_root end end
[ "def", "remove_child", "(", "node", ")", "unless", "(", "index", "=", "search_node_index", "(", "node", ")", ")", "PEROBS", ".", "log", ".", "fatal", "\"Cannot remove child #{node._id} from node #{@_id}\"", "end", "if", "index", "==", "0", "# Removing the first child is a bit more complicated as the", "# corresponding branch key is in a parent node.", "key", "=", "@keys", ".", "shift", "update_branch_key", "(", "key", ")", "else", "# For all other children we can just remove the corresponding key.", "@keys", ".", "delete_at", "(", "index", "-", "1", ")", "end", "# Remove the child node link.", "child", "=", "@children", ".", "delete_at", "(", "index", ")", "# If we remove the first or last leaf node we must update the reference", "# in the BigTree object.", "@tree", ".", "first_leaf", "=", "child", ".", "next_sibling", "if", "child", "==", "@tree", ".", "first_leaf", "@tree", ".", "last_leaf", "=", "child", ".", "prev_sibling", "if", "child", "==", "@tree", ".", "last_leaf", "# Unlink the neighbouring siblings from the child", "child", ".", "prev_sibling", ".", "next_sibling", "=", "child", ".", "next_sibling", "if", "child", ".", "prev_sibling", "child", ".", "next_sibling", ".", "prev_sibling", "=", "child", ".", "prev_sibling", "if", "child", ".", "next_sibling", "if", "@keys", ".", "length", "<", "min_keys", "# The node has become too small. Try borrowing a node from an adjecent", "# sibling or merge with an adjecent node.", "if", "@prev_sibling", "&&", "@prev_sibling", ".", "parent", "==", "@parent", "borrow_from_previous_sibling", "(", "@prev_sibling", ")", "||", "@prev_sibling", ".", "merge_with_branch_node", "(", "myself", ")", "elsif", "@next_sibling", "&&", "@next_sibling", ".", "parent", "==", "@parent", "borrow_from_next_sibling", "(", "@next_sibling", ")", "||", "merge_with_branch_node", "(", "@next_sibling", ")", "end", "end", "if", "@parent", ".", "nil?", "&&", "@children", ".", "length", "<=", "1", "# If the node just below the root only has one child it will become", "# the new root node.", "new_root", "=", "@children", ".", "first", "new_root", ".", "parent", "=", "nil", "@tree", ".", "root", "=", "new_root", "end", "end" ]
Remove the specified node from this branch node. @param node [BigTreeNode] The child to remove
[ "Remove", "the", "specified", "node", "from", "this", "branch", "node", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigTreeNode.rb#L547-L591
4,229
scrapper/perobs
lib/perobs/BigTreeNode.rb
PEROBS.BigTreeNode.statistics
def statistics(stats) traverse do |node, position, stack| if position == 0 if node.is_leaf? stats.leaf_nodes += 1 depth = stack.size + 1 if stats.min_depth.nil? || stats.min_depth < depth stats.min_depth = depth end if stats.max_depth.nil? || stats.max_depth > depth stats.max_depth = depth end else stats.branch_nodes += 1 end end end end
ruby
def statistics(stats) traverse do |node, position, stack| if position == 0 if node.is_leaf? stats.leaf_nodes += 1 depth = stack.size + 1 if stats.min_depth.nil? || stats.min_depth < depth stats.min_depth = depth end if stats.max_depth.nil? || stats.max_depth > depth stats.max_depth = depth end else stats.branch_nodes += 1 end end end end
[ "def", "statistics", "(", "stats", ")", "traverse", "do", "|", "node", ",", "position", ",", "stack", "|", "if", "position", "==", "0", "if", "node", ".", "is_leaf?", "stats", ".", "leaf_nodes", "+=", "1", "depth", "=", "stack", ".", "size", "+", "1", "if", "stats", ".", "min_depth", ".", "nil?", "||", "stats", ".", "min_depth", "<", "depth", "stats", ".", "min_depth", "=", "depth", "end", "if", "stats", ".", "max_depth", ".", "nil?", "||", "stats", ".", "max_depth", ">", "depth", "stats", ".", "max_depth", "=", "depth", "end", "else", "stats", ".", "branch_nodes", "+=", "1", "end", "end", "end", "end" ]
Gather some statistics about the node and all sub nodes. @param stats [Stats] Data structure that stores the gathered data
[ "Gather", "some", "statistics", "about", "the", "node", "and", "all", "sub", "nodes", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigTreeNode.rb#L702-L719
4,230
scrapper/perobs
lib/perobs/BTreeDB.rb
PEROBS.BTreeDB.include?
def include?(id) !(blob = find_blob(id)).nil? && !blob.find(id).nil? end
ruby
def include?(id) !(blob = find_blob(id)).nil? && !blob.find(id).nil? end
[ "def", "include?", "(", "id", ")", "!", "(", "blob", "=", "find_blob", "(", "id", ")", ")", ".", "nil?", "&&", "!", "blob", ".", "find", "(", "id", ")", ".", "nil?", "end" ]
Return true if the object with given ID exists @param id [Integer]
[ "Return", "true", "if", "the", "object", "with", "given", "ID", "exists" ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeDB.rb#L107-L109
4,231
scrapper/perobs
lib/perobs/BTreeDB.rb
PEROBS.BTreeDB.get_object
def get_object(id) return nil unless (blob = find_blob(id)) && (obj = blob.read_object(id)) deserialize(obj) end
ruby
def get_object(id) return nil unless (blob = find_blob(id)) && (obj = blob.read_object(id)) deserialize(obj) end
[ "def", "get_object", "(", "id", ")", "return", "nil", "unless", "(", "blob", "=", "find_blob", "(", "id", ")", ")", "&&", "(", "obj", "=", "blob", ".", "read_object", "(", "id", ")", ")", "deserialize", "(", "obj", ")", "end" ]
Load the given object from the filesystem. @param id [Integer] object ID @return [Hash] Object as defined by PEROBS::ObjectBase or nil if ID does not exist
[ "Load", "the", "given", "object", "from", "the", "filesystem", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeDB.rb#L149-L152
4,232
scrapper/perobs
lib/perobs/BTreeDB.rb
PEROBS.BTreeDB.is_marked?
def is_marked?(id, ignore_errors = false) (blob = find_blob(id)) && blob.is_marked?(id, ignore_errors) end
ruby
def is_marked?(id, ignore_errors = false) (blob = find_blob(id)) && blob.is_marked?(id, ignore_errors) end
[ "def", "is_marked?", "(", "id", ",", "ignore_errors", "=", "false", ")", "(", "blob", "=", "find_blob", "(", "id", ")", ")", "&&", "blob", ".", "is_marked?", "(", "id", ",", "ignore_errors", ")", "end" ]
Check if the object is marked. @param id [Integer] ID of the object to check @param ignore_errors [Boolean] If set to true no errors will be raised for non-existing objects.
[ "Check", "if", "the", "object", "is", "marked", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeDB.rb#L178-L180
4,233
dalehamel/cloudshaper
lib/cloudshaper/command.rb
Cloudshaper.Command.env
def env vars = {} @stack.variables.each { |k, v| vars["TF_VAR_#{k}"] = v } SECRETS.each do |_provider, secrets| if secrets.is_a?(Hash) secrets.each do |k, v| vars[k.to_s] = v end end end vars end
ruby
def env vars = {} @stack.variables.each { |k, v| vars["TF_VAR_#{k}"] = v } SECRETS.each do |_provider, secrets| if secrets.is_a?(Hash) secrets.each do |k, v| vars[k.to_s] = v end end end vars end
[ "def", "env", "vars", "=", "{", "}", "@stack", ".", "variables", ".", "each", "{", "|", "k", ",", "v", "|", "vars", "[", "\"TF_VAR_#{k}\"", "]", "=", "v", "}", "SECRETS", ".", "each", "do", "|", "_provider", ",", "secrets", "|", "if", "secrets", ".", "is_a?", "(", "Hash", ")", "secrets", ".", "each", "do", "|", "k", ",", "v", "|", "vars", "[", "k", ".", "to_s", "]", "=", "v", "end", "end", "end", "vars", "end" ]
fixme - make these shell safe
[ "fixme", "-", "make", "these", "shell", "safe" ]
bcfeb18fd9853f782b7aa81ebe3f84d69e17e5b4
https://github.com/dalehamel/cloudshaper/blob/bcfeb18fd9853f782b7aa81ebe3f84d69e17e5b4/lib/cloudshaper/command.rb#L14-L25
4,234
sethvargo/community-zero
lib/community_zero/store.rb
CommunityZero.Store.search
def search(query) regex = Regexp.new(query, 'i') _cookbooks.collect do |_, v| v[v.keys.first] if regex.match(v[v.keys.first].name) end.compact end
ruby
def search(query) regex = Regexp.new(query, 'i') _cookbooks.collect do |_, v| v[v.keys.first] if regex.match(v[v.keys.first].name) end.compact end
[ "def", "search", "(", "query", ")", "regex", "=", "Regexp", ".", "new", "(", "query", ",", "'i'", ")", "_cookbooks", ".", "collect", "do", "|", "_", ",", "v", "|", "v", "[", "v", ".", "keys", ".", "first", "]", "if", "regex", ".", "match", "(", "v", "[", "v", ".", "keys", ".", "first", "]", ".", "name", ")", "end", ".", "compact", "end" ]
Query the installed cookbooks, returning those who's name matches the given query. @param [String] query the query parameter @return [Array<CommunityZero::Cookbook>] the list of cookbooks that match the given query
[ "Query", "the", "installed", "cookbooks", "returning", "those", "who", "s", "name", "matches", "the", "given", "query", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/store.rb#L51-L56
4,235
sethvargo/community-zero
lib/community_zero/store.rb
CommunityZero.Store.add
def add(cookbook) cookbook = cookbook.dup cookbook.created_at = Time.now cookbook.updated_at = Time.now entry = _cookbooks[cookbook.name] ||= {} entry[cookbook.version] = cookbook end
ruby
def add(cookbook) cookbook = cookbook.dup cookbook.created_at = Time.now cookbook.updated_at = Time.now entry = _cookbooks[cookbook.name] ||= {} entry[cookbook.version] = cookbook end
[ "def", "add", "(", "cookbook", ")", "cookbook", "=", "cookbook", ".", "dup", "cookbook", ".", "created_at", "=", "Time", ".", "now", "cookbook", ".", "updated_at", "=", "Time", ".", "now", "entry", "=", "_cookbooks", "[", "cookbook", ".", "name", "]", "||=", "{", "}", "entry", "[", "cookbook", ".", "version", "]", "=", "cookbook", "end" ]
Add the given cookbook to the cookbook store. This method's implementation prohibits duplicate cookbooks from entering the store. @param [CommunityZero::Cookbook] cookbook the cookbook to add
[ "Add", "the", "given", "cookbook", "to", "the", "cookbook", "store", ".", "This", "method", "s", "implementation", "prohibits", "duplicate", "cookbooks", "from", "entering", "the", "store", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/store.rb#L68-L75
4,236
sethvargo/community-zero
lib/community_zero/store.rb
CommunityZero.Store.remove
def remove(cookbook) return unless has_cookbook?(cookbook.name, cookbook.version) _cookbooks[cookbook.name].delete(cookbook.version) end
ruby
def remove(cookbook) return unless has_cookbook?(cookbook.name, cookbook.version) _cookbooks[cookbook.name].delete(cookbook.version) end
[ "def", "remove", "(", "cookbook", ")", "return", "unless", "has_cookbook?", "(", "cookbook", ".", "name", ",", "cookbook", ".", "version", ")", "_cookbooks", "[", "cookbook", ".", "name", "]", ".", "delete", "(", "cookbook", ".", "version", ")", "end" ]
Remove the cookbook from the store. @param [CommunityZero::Cookbook] cookbook the cookbook to remove
[ "Remove", "the", "cookbook", "from", "the", "store", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/store.rb#L82-L85
4,237
sethvargo/community-zero
lib/community_zero/store.rb
CommunityZero.Store.find
def find(name, version = nil) possibles = _cookbooks[name] return nil if possibles.nil? version ||= possibles.keys.sort.last possibles[version] end
ruby
def find(name, version = nil) possibles = _cookbooks[name] return nil if possibles.nil? version ||= possibles.keys.sort.last possibles[version] end
[ "def", "find", "(", "name", ",", "version", "=", "nil", ")", "possibles", "=", "_cookbooks", "[", "name", "]", "return", "nil", "if", "possibles", ".", "nil?", "version", "||=", "possibles", ".", "keys", ".", "sort", ".", "last", "possibles", "[", "version", "]", "end" ]
Determine if the cookbook store contains a cookbook. If the version attribute is nil, this method will return the latest cookbook version by that name that exists. If the version is specified, this method will only return that specific version, or nil if that cookbook at that version exists. @param [String] name the name of the cookbook to find @param [String, nil] version the version of the cookbook to search @return [CommunityZero::Cookbook, nil] the cookbook in the store, or nil if one does not exist
[ "Determine", "if", "the", "cookbook", "store", "contains", "a", "cookbook", ".", "If", "the", "version", "attribute", "is", "nil", "this", "method", "will", "return", "the", "latest", "cookbook", "version", "by", "that", "name", "that", "exists", ".", "If", "the", "version", "is", "specified", "this", "method", "will", "only", "return", "that", "specific", "version", "or", "nil", "if", "that", "cookbook", "at", "that", "version", "exists", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/store.rb#L107-L113
4,238
sethvargo/community-zero
lib/community_zero/store.rb
CommunityZero.Store.versions
def versions(name) name = name.respond_to?(:name) ? name.name : name (_cookbooks[name] && _cookbooks[name].keys.sort) || [] end
ruby
def versions(name) name = name.respond_to?(:name) ? name.name : name (_cookbooks[name] && _cookbooks[name].keys.sort) || [] end
[ "def", "versions", "(", "name", ")", "name", "=", "name", ".", "respond_to?", "(", ":name", ")", "?", "name", ".", "name", ":", "name", "(", "_cookbooks", "[", "name", "]", "&&", "_cookbooks", "[", "name", "]", ".", "keys", ".", "sort", ")", "||", "[", "]", "end" ]
Return a list of all versions for the given cookbook. @param [String, CommunityZero::Cookbook] name the cookbook or name of the cookbook to get versions for
[ "Return", "a", "list", "of", "all", "versions", "for", "the", "given", "cookbook", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/store.rb#L119-L122
4,239
scrapper/perobs
lib/perobs/Hash.rb
PEROBS.Hash._referenced_object_ids
def _referenced_object_ids @data.each_value.select { |v| v && v.respond_to?(:is_poxreference?) }. map { |o| o.id } end
ruby
def _referenced_object_ids @data.each_value.select { |v| v && v.respond_to?(:is_poxreference?) }. map { |o| o.id } end
[ "def", "_referenced_object_ids", "@data", ".", "each_value", ".", "select", "{", "|", "v", "|", "v", "&&", "v", ".", "respond_to?", "(", ":is_poxreference?", ")", "}", ".", "map", "{", "|", "o", "|", "o", ".", "id", "}", "end" ]
Return a list of all object IDs of all persistend objects that this Hash is referencing. @return [Array of Integer] IDs of referenced objects
[ "Return", "a", "list", "of", "all", "object", "IDs", "of", "all", "persistend", "objects", "that", "this", "Hash", "is", "referencing", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Hash.rb#L141-L144
4,240
scrapper/perobs
lib/perobs/Hash.rb
PEROBS.Hash._delete_reference_to_id
def _delete_reference_to_id(id) @data.delete_if do |k, v| v && v.respond_to?(:is_poxreference?) && v.id == id end @store.cache.cache_write(self) end
ruby
def _delete_reference_to_id(id) @data.delete_if do |k, v| v && v.respond_to?(:is_poxreference?) && v.id == id end @store.cache.cache_write(self) end
[ "def", "_delete_reference_to_id", "(", "id", ")", "@data", ".", "delete_if", "do", "|", "k", ",", "v", "|", "v", "&&", "v", ".", "respond_to?", "(", ":is_poxreference?", ")", "&&", "v", ".", "id", "==", "id", "end", "@store", ".", "cache", ".", "cache_write", "(", "self", ")", "end" ]
This method should only be used during store repair operations. It will delete all referenced to the given object ID. @param id [Integer] targeted object ID
[ "This", "method", "should", "only", "be", "used", "during", "store", "repair", "operations", ".", "It", "will", "delete", "all", "referenced", "to", "the", "given", "object", "ID", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Hash.rb#L149-L154
4,241
scrapper/perobs
lib/perobs/IDListPageRecord.rb
PEROBS.IDListPageRecord.split
def split # Determine the new max_id for the old page. max_id = @min_id + (@max_id - @min_id) / 2 # Create a new page that stores the upper half of the ID range. Remove # all IDs from this page that now belong into the new page and transfer # them. new_page_record = IDListPageRecord.new(@page_file, max_id + 1, @max_id, page.delete(max_id)) # Adjust the max_id of the current page. @max_id = max_id new_page_record end
ruby
def split # Determine the new max_id for the old page. max_id = @min_id + (@max_id - @min_id) / 2 # Create a new page that stores the upper half of the ID range. Remove # all IDs from this page that now belong into the new page and transfer # them. new_page_record = IDListPageRecord.new(@page_file, max_id + 1, @max_id, page.delete(max_id)) # Adjust the max_id of the current page. @max_id = max_id new_page_record end
[ "def", "split", "# Determine the new max_id for the old page.", "max_id", "=", "@min_id", "+", "(", "@max_id", "-", "@min_id", ")", "/", "2", "# Create a new page that stores the upper half of the ID range. Remove", "# all IDs from this page that now belong into the new page and transfer", "# them.", "new_page_record", "=", "IDListPageRecord", ".", "new", "(", "@page_file", ",", "max_id", "+", "1", ",", "@max_id", ",", "page", ".", "delete", "(", "max_id", ")", ")", "# Adjust the max_id of the current page.", "@max_id", "=", "max_id", "new_page_record", "end" ]
Split the current page. This split is done by splitting the ID range in half. This page will keep the first half, the newly created page will get the second half. This may not actually yield an empty page as all values could remain with one of the pages. In this case further splits need to be issued by the caller. @return [IDListPageRecord] A new IDListPageRecord object.
[ "Split", "the", "current", "page", ".", "This", "split", "is", "done", "by", "splitting", "the", "ID", "range", "in", "half", ".", "This", "page", "will", "keep", "the", "first", "half", "the", "newly", "created", "page", "will", "get", "the", "second", "half", ".", "This", "may", "not", "actually", "yield", "an", "empty", "page", "as", "all", "values", "could", "remain", "with", "one", "of", "the", "pages", ".", "In", "this", "case", "further", "splits", "need", "to", "be", "issued", "by", "the", "caller", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/IDListPageRecord.rb#L84-L96
4,242
notonthehighstreet/chicago
lib/chicago/schema/builders/shrunken_dimension_builder.rb
Chicago::Schema::Builders.ShrunkenDimensionBuilder.columns
def columns(*names) columns = @base.columns.select {|c| names.include?(c.name) } check_columns_subset_of_base_dimension names, columns @options[:columns] = columns end
ruby
def columns(*names) columns = @base.columns.select {|c| names.include?(c.name) } check_columns_subset_of_base_dimension names, columns @options[:columns] = columns end
[ "def", "columns", "(", "*", "names", ")", "columns", "=", "@base", ".", "columns", ".", "select", "{", "|", "c", "|", "names", ".", "include?", "(", "c", ".", "name", ")", "}", "check_columns_subset_of_base_dimension", "names", ",", "columns", "@options", "[", ":columns", "]", "=", "columns", "end" ]
Defines which columns of the base dimension are present in the shrunken dimension. Takes an array of the column names as symbols. The columns must be a subset of the base dimension's columns; additional names will raise a Chicago::MissingDefinitionError.
[ "Defines", "which", "columns", "of", "the", "base", "dimension", "are", "present", "in", "the", "shrunken", "dimension", "." ]
428e94f8089d2f36fdcff2e27ea2af572b816def
https://github.com/notonthehighstreet/chicago/blob/428e94f8089d2f36fdcff2e27ea2af572b816def/lib/chicago/schema/builders/shrunken_dimension_builder.rb#L29-L33
4,243
xinminlabs/synvert-core
lib/synvert/core/rewriter/action/insert_action.rb
Synvert::Core.Rewriter::InsertAction.insert_position
def insert_position(node) case node.type when :block node.children[1].children.empty? ? node.children[0].loc.expression.end_pos + 3 : node.children[1].loc.expression.end_pos when :class node.children[1] ? node.children[1].loc.expression.end_pos : node.children[0].loc.expression.end_pos else node.children.last.loc.expression.end_pos end end
ruby
def insert_position(node) case node.type when :block node.children[1].children.empty? ? node.children[0].loc.expression.end_pos + 3 : node.children[1].loc.expression.end_pos when :class node.children[1] ? node.children[1].loc.expression.end_pos : node.children[0].loc.expression.end_pos else node.children.last.loc.expression.end_pos end end
[ "def", "insert_position", "(", "node", ")", "case", "node", ".", "type", "when", ":block", "node", ".", "children", "[", "1", "]", ".", "children", ".", "empty?", "?", "node", ".", "children", "[", "0", "]", ".", "loc", ".", "expression", ".", "end_pos", "+", "3", ":", "node", ".", "children", "[", "1", "]", ".", "loc", ".", "expression", ".", "end_pos", "when", ":class", "node", ".", "children", "[", "1", "]", "?", "node", ".", "children", "[", "1", "]", ".", "loc", ".", "expression", ".", "end_pos", ":", "node", ".", "children", "[", "0", "]", ".", "loc", ".", "expression", ".", "end_pos", "else", "node", ".", "children", ".", "last", ".", "loc", ".", "expression", ".", "end_pos", "end", "end" ]
Insert position. @return [Integer] insert position.
[ "Insert", "position", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/action/insert_action.rb#L25-L34
4,244
jeffnyman/tapestry
lib/tapestry/element.rb
Tapestry.Element.accessor_aspects
def accessor_aspects(element, *signature) identifier = signature.shift locator_args = {} qualifier_args = {} gather_aspects(identifier, element, locator_args, qualifier_args) [locator_args, qualifier_args] end
ruby
def accessor_aspects(element, *signature) identifier = signature.shift locator_args = {} qualifier_args = {} gather_aspects(identifier, element, locator_args, qualifier_args) [locator_args, qualifier_args] end
[ "def", "accessor_aspects", "(", "element", ",", "*", "signature", ")", "identifier", "=", "signature", ".", "shift", "locator_args", "=", "{", "}", "qualifier_args", "=", "{", "}", "gather_aspects", "(", "identifier", ",", "element", ",", "locator_args", ",", "qualifier_args", ")", "[", "locator_args", ",", "qualifier_args", "]", "end" ]
This method provides the means to get the aspects of an accessor signature. The "aspects" refer to the locator information and any qualifier information that was provided along with the locator. This is important because the qualifier is not used to locate an element but rather to put conditions on how the state of the element is checked as it is being looked for. Note that "qualifiers" here refers to Watir boolean methods.
[ "This", "method", "provides", "the", "means", "to", "get", "the", "aspects", "of", "an", "accessor", "signature", ".", "The", "aspects", "refer", "to", "the", "locator", "information", "and", "any", "qualifier", "information", "that", "was", "provided", "along", "with", "the", "locator", ".", "This", "is", "important", "because", "the", "qualifier", "is", "not", "used", "to", "locate", "an", "element", "but", "rather", "to", "put", "conditions", "on", "how", "the", "state", "of", "the", "element", "is", "checked", "as", "it", "is", "being", "looked", "for", "." ]
da28652dd6de71e415cd2c01afd89f641938a05b
https://github.com/jeffnyman/tapestry/blob/da28652dd6de71e415cd2c01afd89f641938a05b/lib/tapestry/element.rb#L78-L84
4,245
scrapper/perobs
lib/perobs/DynamoDB.rb
PEROBS.DynamoDB.delete_database
def delete_database dynamodb = Aws::DynamoDB::Client.new dynamodb.delete_table(:table_name => @table_name) dynamodb.wait_until(:table_not_exists, table_name: @table_name) end
ruby
def delete_database dynamodb = Aws::DynamoDB::Client.new dynamodb.delete_table(:table_name => @table_name) dynamodb.wait_until(:table_not_exists, table_name: @table_name) end
[ "def", "delete_database", "dynamodb", "=", "Aws", "::", "DynamoDB", "::", "Client", ".", "new", "dynamodb", ".", "delete_table", "(", ":table_name", "=>", "@table_name", ")", "dynamodb", ".", "wait_until", "(", ":table_not_exists", ",", "table_name", ":", "@table_name", ")", "end" ]
Create a new DynamoDB object. @param db_name [String] name of the DB directory @param options [Hash] options to customize the behavior. Currently only the following options are supported: :serializer : Can be :json and :yaml :aws_id : AWS credentials ID :aws_key : AWS credentials key :aws_region : AWS region to host the data Delete the entire database. The database is no longer usable after this method was called.
[ "Create", "a", "new", "DynamoDB", "object", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DynamoDB.rb#L93-L97
4,246
scrapper/perobs
lib/perobs/DynamoDB.rb
PEROBS.DynamoDB.delete_unmarked_objects
def delete_unmarked_objects deleted_objects_count = 0 each_item do |id| unless dynamo_is_marked?(id) dynamo_delete_item(id) deleted_objects_count += 1 @item_counter -= 1 end end dynamo_put_item('item_counter', @item_counter.to_s) deleted_objects_count end
ruby
def delete_unmarked_objects deleted_objects_count = 0 each_item do |id| unless dynamo_is_marked?(id) dynamo_delete_item(id) deleted_objects_count += 1 @item_counter -= 1 end end dynamo_put_item('item_counter', @item_counter.to_s) deleted_objects_count end
[ "def", "delete_unmarked_objects", "deleted_objects_count", "=", "0", "each_item", "do", "|", "id", "|", "unless", "dynamo_is_marked?", "(", "id", ")", "dynamo_delete_item", "(", "id", ")", "deleted_objects_count", "+=", "1", "@item_counter", "-=", "1", "end", "end", "dynamo_put_item", "(", "'item_counter'", ",", "@item_counter", ".", "to_s", ")", "deleted_objects_count", "end" ]
Permanently delete all objects that have not been marked. Those are orphaned and are no longer referenced by any actively used object. @return [Integer] Count of the deleted objects.
[ "Permanently", "delete", "all", "objects", "that", "have", "not", "been", "marked", ".", "Those", "are", "orphaned", "and", "are", "no", "longer", "referenced", "by", "any", "actively", "used", "object", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DynamoDB.rb#L161-L173
4,247
scrapper/perobs
lib/perobs/DynamoDB.rb
PEROBS.DynamoDB.check_db
def check_db(repair = false) unless (item_counter = dynamo_get_item('item_counter')) && item_counter == @item_counter PEROBS.log.error "@item_counter variable (#{@item_counter}) and " + "item_counter table entry (#{item_counter}) don't match" end item_counter = 0 each_item { item_counter += 1 } unless item_counter == @item_counter PEROBS.log.error "Table contains #{item_counter} items but " + "@item_counter is #{@item_counter}" end end
ruby
def check_db(repair = false) unless (item_counter = dynamo_get_item('item_counter')) && item_counter == @item_counter PEROBS.log.error "@item_counter variable (#{@item_counter}) and " + "item_counter table entry (#{item_counter}) don't match" end item_counter = 0 each_item { item_counter += 1 } unless item_counter == @item_counter PEROBS.log.error "Table contains #{item_counter} items but " + "@item_counter is #{@item_counter}" end end
[ "def", "check_db", "(", "repair", "=", "false", ")", "unless", "(", "item_counter", "=", "dynamo_get_item", "(", "'item_counter'", ")", ")", "&&", "item_counter", "==", "@item_counter", "PEROBS", ".", "log", ".", "error", "\"@item_counter variable (#{@item_counter}) and \"", "+", "\"item_counter table entry (#{item_counter}) don't match\"", "end", "item_counter", "=", "0", "each_item", "{", "item_counter", "+=", "1", "}", "unless", "item_counter", "==", "@item_counter", "PEROBS", ".", "log", ".", "error", "\"Table contains #{item_counter} items but \"", "+", "\"@item_counter is #{@item_counter}\"", "end", "end" ]
Basic consistency check. @param repair [TrueClass/FalseClass] True if found errors should be repaired.
[ "Basic", "consistency", "check", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/DynamoDB.rb#L190-L202
4,248
scrapper/perobs
lib/perobs/ObjectBase.rb
PEROBS.POXReference.method_missing
def method_missing(method_sym, *args, &block) unless (obj = _referenced_object) ::PEROBS.log.fatal "Internal consistency error. No object with ID " + "#{@id} found in the store." end if obj.respond_to?(:is_poxreference?) ::PEROBS.log.fatal "POXReference that references a POXReference found." end obj.send(method_sym, *args, &block) end
ruby
def method_missing(method_sym, *args, &block) unless (obj = _referenced_object) ::PEROBS.log.fatal "Internal consistency error. No object with ID " + "#{@id} found in the store." end if obj.respond_to?(:is_poxreference?) ::PEROBS.log.fatal "POXReference that references a POXReference found." end obj.send(method_sym, *args, &block) end
[ "def", "method_missing", "(", "method_sym", ",", "*", "args", ",", "&", "block", ")", "unless", "(", "obj", "=", "_referenced_object", ")", "::", "PEROBS", ".", "log", ".", "fatal", "\"Internal consistency error. No object with ID \"", "+", "\"#{@id} found in the store.\"", "end", "if", "obj", ".", "respond_to?", "(", ":is_poxreference?", ")", "::", "PEROBS", ".", "log", ".", "fatal", "\"POXReference that references a POXReference found.\"", "end", "obj", ".", "send", "(", "method_sym", ",", "args", ",", "block", ")", "end" ]
Proxy all calls to unknown methods to the referenced object.
[ "Proxy", "all", "calls", "to", "unknown", "methods", "to", "the", "referenced", "object", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/ObjectBase.rb#L49-L58
4,249
scrapper/perobs
lib/perobs/ObjectBase.rb
PEROBS.ObjectBase._transfer
def _transfer(store) @store = store # Remove the previously defined finalizer as it is attached to the old # store. ObjectSpace.undefine_finalizer(self) # Register the object as in-memory object with the new store. @store._register_in_memory(self, @_id) # Register the finalizer for the new store. ObjectSpace.define_finalizer( self, ObjectBase._finalize(@store, @_id, object_id)) @myself = POXReference.new(@store, @_id) end
ruby
def _transfer(store) @store = store # Remove the previously defined finalizer as it is attached to the old # store. ObjectSpace.undefine_finalizer(self) # Register the object as in-memory object with the new store. @store._register_in_memory(self, @_id) # Register the finalizer for the new store. ObjectSpace.define_finalizer( self, ObjectBase._finalize(@store, @_id, object_id)) @myself = POXReference.new(@store, @_id) end
[ "def", "_transfer", "(", "store", ")", "@store", "=", "store", "# Remove the previously defined finalizer as it is attached to the old", "# store.", "ObjectSpace", ".", "undefine_finalizer", "(", "self", ")", "# Register the object as in-memory object with the new store.", "@store", ".", "_register_in_memory", "(", "self", ",", "@_id", ")", "# Register the finalizer for the new store.", "ObjectSpace", ".", "define_finalizer", "(", "self", ",", "ObjectBase", ".", "_finalize", "(", "@store", ",", "@_id", ",", "object_id", ")", ")", "@myself", "=", "POXReference", ".", "new", "(", "@store", ",", "@_id", ")", "end" ]
Library internal method to transfer the Object to a new store. @param store [Store] New store
[ "Library", "internal", "method", "to", "transfer", "the", "Object", "to", "a", "new", "store", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/ObjectBase.rb#L172-L183
4,250
scrapper/perobs
lib/perobs/ObjectBase.rb
PEROBS.ObjectBase._restore
def _restore(level) # Find the most recently stored state of this object. This could be on # any previous stash level or in the regular object DB. If the object # was created during the transaction, there is not previous state to # restore to. data = nil if @_stash_map (level - 1).downto(0) do |lvl| break if (data = @_stash_map[lvl]) end end if data # We have a stashed version that we can restore from. _deserialize(data) elsif @store.db.include?(@_id) # We have no stashed version but can restore from the database. db_obj = store.db.get_object(@_id) _deserialize(db_obj['data']) end end
ruby
def _restore(level) # Find the most recently stored state of this object. This could be on # any previous stash level or in the regular object DB. If the object # was created during the transaction, there is not previous state to # restore to. data = nil if @_stash_map (level - 1).downto(0) do |lvl| break if (data = @_stash_map[lvl]) end end if data # We have a stashed version that we can restore from. _deserialize(data) elsif @store.db.include?(@_id) # We have no stashed version but can restore from the database. db_obj = store.db.get_object(@_id) _deserialize(db_obj['data']) end end
[ "def", "_restore", "(", "level", ")", "# Find the most recently stored state of this object. This could be on", "# any previous stash level or in the regular object DB. If the object", "# was created during the transaction, there is not previous state to", "# restore to.", "data", "=", "nil", "if", "@_stash_map", "(", "level", "-", "1", ")", ".", "downto", "(", "0", ")", "do", "|", "lvl", "|", "break", "if", "(", "data", "=", "@_stash_map", "[", "lvl", "]", ")", "end", "end", "if", "data", "# We have a stashed version that we can restore from.", "_deserialize", "(", "data", ")", "elsif", "@store", ".", "db", ".", "include?", "(", "@_id", ")", "# We have no stashed version but can restore from the database.", "db_obj", "=", "store", ".", "db", ".", "get_object", "(", "@_id", ")", "_deserialize", "(", "db_obj", "[", "'data'", "]", ")", "end", "end" ]
Restore the object state from the storage back-end. @param level [Integer] the transaction nesting level
[ "Restore", "the", "object", "state", "from", "the", "storage", "back", "-", "end", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/ObjectBase.rb#L250-L269
4,251
Absolight/epp-client
lib/epp-client/domain.rb
EPPClient.Domain.domain_check
def domain_check(*domains) domains.flatten! response = send_request(domain_check_xml(*domains)) get_result(:xml => response, :callback => :domain_check_process) end
ruby
def domain_check(*domains) domains.flatten! response = send_request(domain_check_xml(*domains)) get_result(:xml => response, :callback => :domain_check_process) end
[ "def", "domain_check", "(", "*", "domains", ")", "domains", ".", "flatten!", "response", "=", "send_request", "(", "domain_check_xml", "(", "domains", ")", ")", "get_result", "(", ":xml", "=>", "response", ",", ":callback", "=>", ":domain_check_process", ")", "end" ]
Check the availability of domains takes a list of domains as arguments returns an array of hashes containing three fields : [<tt>:name</tt>] The domain name [<tt>:avail</tt>] Wether the domain is available or not. [<tt>:reason</tt>] The reason for non availability, if given.
[ "Check", "the", "availability", "of", "domains" ]
c0025daee5e7087f60b654595a8e7d92e966c54e
https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/domain.rb#L29-L34
4,252
Absolight/epp-client
lib/epp-client/domain.rb
EPPClient.Domain.domain_info
def domain_info(args) args = { :name => args } if args.is_a?(String) response = send_request(domain_info_xml(args)) get_result(:xml => response, :callback => :domain_info_process) end
ruby
def domain_info(args) args = { :name => args } if args.is_a?(String) response = send_request(domain_info_xml(args)) get_result(:xml => response, :callback => :domain_info_process) end
[ "def", "domain_info", "(", "args", ")", "args", "=", "{", ":name", "=>", "args", "}", "if", "args", ".", "is_a?", "(", "String", ")", "response", "=", "send_request", "(", "domain_info_xml", "(", "args", ")", ")", "get_result", "(", ":xml", "=>", "response", ",", ":callback", "=>", ":domain_info_process", ")", "end" ]
Returns the informations about a domain Takes either a unique argument, a string, representing the domain, or a hash with : <tt>:name</tt> the domain name, and optionnaly <tt>:authInfo</tt> the authentication information and possibly <tt>:roid</tt> the contact the authInfo is about. Returned is a hash mapping as closely as possible the result expected from the command as per Section {3.1.2}[https://tools.ietf.org/html/rfc5731#section-3.1.2] of {RFC 5731}[https://tools.ietf.org/html/rfc5731] : [<tt>:name</tt>] The fully qualified name of the domain object. [<tt>:roid</tt>] The Repository Object IDentifier assigned to the domain object when the object was created. [<tt>:status</tt>] an optionnal array of elements that contain the current status descriptors associated with the domain. [<tt>:registrant</tt>] one optionnal registrant nic handle. [<tt>:contacts</tt>] an optionnal hash which keys are choosen between +admin+, +billing+ and +tech+ and which values are arrays of nic handles for the corresponding contact types. [<tt>:ns</tt>] an optional array containing nameservers informations, which can either be an array of strings containing the the fully qualified name of a host, or an array of hashes containing the following keys : [<tt>:hostName</tt>] the fully qualified name of a host. [<tt>:hostAddrv4</tt>] an optionnal array of ipv4 addresses to be associated with the host. [<tt>:hostAddrv6</tt>] an optionnal array of ipv6 addresses to be associated with the host. [<tt>:host</tt>] an optionnal array of fully qualified names of the subordinate host objects that exist under this superordinate domain object. [<tt>:clID</tt>] the identifier of the sponsoring client. [<tt>:crID</tt>] an optional identifier of the client that created the domain object. [<tt>:crDate</tt>] an optional date and time of domain object creation. [<tt>:exDate</tt>] the date and time identifying the end of the domain object's registration period. [<tt>:upID</tt>] the identifier of the client that last updated the domain object. [<tt>:upDate</tt>] the date and time of the most recent domain-object modification. [<tt>:trDate</tt>] the date and time of the most recent successful domain-object transfer. [<tt>:authInfo</tt>] authorization information associated with the domain object.
[ "Returns", "the", "informations", "about", "a", "domain" ]
c0025daee5e7087f60b654595a8e7d92e966c54e
https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/domain.rb#L118-L123
4,253
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.set_custom_data
def set_custom_data(name, value) unless @custom_data_labels.include?(name) PEROBS.log.fatal "Unknown custom data field #{name}" end @custom_data_values[@custom_data_labels.index(name)] = value write_header if @f end
ruby
def set_custom_data(name, value) unless @custom_data_labels.include?(name) PEROBS.log.fatal "Unknown custom data field #{name}" end @custom_data_values[@custom_data_labels.index(name)] = value write_header if @f end
[ "def", "set_custom_data", "(", "name", ",", "value", ")", "unless", "@custom_data_labels", ".", "include?", "(", "name", ")", "PEROBS", ".", "log", ".", "fatal", "\"Unknown custom data field #{name}\"", "end", "@custom_data_values", "[", "@custom_data_labels", ".", "index", "(", "name", ")", "]", "=", "value", "write_header", "if", "@f", "end" ]
Set the registered custom data field to the given value. @param name [String] Label of the offset @param value [Integer] Value
[ "Set", "the", "registered", "custom", "data", "field", "to", "the", "given", "value", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L146-L153
4,254
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.free_address
def free_address if @first_space == 0 # There is currently no free entry. Create a new reserved entry at the # end of the file. begin offset = @f.size @f.seek(offset) write_n_bytes([1] + ::Array.new(@entry_bytes, 0)) write_header return offset_to_address(offset) rescue IOError => e PEROBS.log.fatal "Cannot create reserved space at #{@first_space} " + "in EquiBlobsFile #{@file_name}: #{e.message}" end else begin free_space_address = offset_to_address(@first_space) @f.seek(@first_space) marker = read_char @first_space = read_unsigned_int unless marker == 0 PEROBS.log.fatal "Free space list of EquiBlobsFile #{@file_name} " + "points to non-empty entry at address #{@first_space}" end # Mark entry as reserved by setting the mark byte to 1. @f.seek(-(1 + 8), IO::SEEK_CUR) write_char(1) # Update the file header @total_spaces -= 1 write_header return free_space_address rescue IOError => e PEROBS.log.fatal "Cannot mark reserved space at " + "#{free_space_address} in EquiBlobsFile #{@file_name}: " + "#{e.message}" end end end
ruby
def free_address if @first_space == 0 # There is currently no free entry. Create a new reserved entry at the # end of the file. begin offset = @f.size @f.seek(offset) write_n_bytes([1] + ::Array.new(@entry_bytes, 0)) write_header return offset_to_address(offset) rescue IOError => e PEROBS.log.fatal "Cannot create reserved space at #{@first_space} " + "in EquiBlobsFile #{@file_name}: #{e.message}" end else begin free_space_address = offset_to_address(@first_space) @f.seek(@first_space) marker = read_char @first_space = read_unsigned_int unless marker == 0 PEROBS.log.fatal "Free space list of EquiBlobsFile #{@file_name} " + "points to non-empty entry at address #{@first_space}" end # Mark entry as reserved by setting the mark byte to 1. @f.seek(-(1 + 8), IO::SEEK_CUR) write_char(1) # Update the file header @total_spaces -= 1 write_header return free_space_address rescue IOError => e PEROBS.log.fatal "Cannot mark reserved space at " + "#{free_space_address} in EquiBlobsFile #{@file_name}: " + "#{e.message}" end end end
[ "def", "free_address", "if", "@first_space", "==", "0", "# There is currently no free entry. Create a new reserved entry at the", "# end of the file.", "begin", "offset", "=", "@f", ".", "size", "@f", ".", "seek", "(", "offset", ")", "write_n_bytes", "(", "[", "1", "]", "+", "::", "Array", ".", "new", "(", "@entry_bytes", ",", "0", ")", ")", "write_header", "return", "offset_to_address", "(", "offset", ")", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot create reserved space at #{@first_space} \"", "+", "\"in EquiBlobsFile #{@file_name}: #{e.message}\"", "end", "else", "begin", "free_space_address", "=", "offset_to_address", "(", "@first_space", ")", "@f", ".", "seek", "(", "@first_space", ")", "marker", "=", "read_char", "@first_space", "=", "read_unsigned_int", "unless", "marker", "==", "0", "PEROBS", ".", "log", ".", "fatal", "\"Free space list of EquiBlobsFile #{@file_name} \"", "+", "\"points to non-empty entry at address #{@first_space}\"", "end", "# Mark entry as reserved by setting the mark byte to 1.", "@f", ".", "seek", "(", "-", "(", "1", "+", "8", ")", ",", "IO", "::", "SEEK_CUR", ")", "write_char", "(", "1", ")", "# Update the file header", "@total_spaces", "-=", "1", "write_header", "return", "free_space_address", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot mark reserved space at \"", "+", "\"#{free_space_address} in EquiBlobsFile #{@file_name}: \"", "+", "\"#{e.message}\"", "end", "end", "end" ]
Return the address of a free blob storage space. Addresses start at 0 and increase linearly. @return [Integer] address of a free blob space
[ "Return", "the", "address", "of", "a", "free", "blob", "storage", "space", ".", "Addresses", "start", "at", "0", "and", "increase", "linearly", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L204-L242
4,255
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.store_blob
def store_blob(address, bytes) unless address >= 0 PEROBS.log.fatal "Blob storage address must be larger than 0, " + "not #{address}" end if bytes.length != @entry_bytes PEROBS.log.fatal "All stack entries must be #{@entry_bytes} " + "long. This entry is #{bytes.length} bytes long." end marker = 1 begin offset = address_to_offset(address) if offset > (file_size = @f.size) PEROBS.log.fatal "Cannot store blob at address #{address} in " + "EquiBlobsFile #{@file_name}. Address is larger than file size. " + "Offset: #{offset} File size: #{file_size}" end @f.seek(offset) # The first byte is the marker byte. It's set to 2 for cells that hold # a blob. 1 for reserved cells and 0 for empty cells. The cell must be # either already be in use or be reserved. It must not be 0. if file_size > offset && (marker = read_char) != 1 && marker != 2 PEROBS.log.fatal "Marker for entry at address #{address} of " + "EquiBlobsFile #{@file_name} must be 1 or 2 but is #{marker}" end @f.seek(offset) write_char(2) @f.write(bytes) @f.flush rescue IOError => e PEROBS.log.fatal "Cannot store blob at address #{address} in " + "EquiBlobsFile #{@file_name}: #{e.message}" end # Update the entries counter if we inserted a new blob. if marker == 1 @total_entries += 1 write_header end end
ruby
def store_blob(address, bytes) unless address >= 0 PEROBS.log.fatal "Blob storage address must be larger than 0, " + "not #{address}" end if bytes.length != @entry_bytes PEROBS.log.fatal "All stack entries must be #{@entry_bytes} " + "long. This entry is #{bytes.length} bytes long." end marker = 1 begin offset = address_to_offset(address) if offset > (file_size = @f.size) PEROBS.log.fatal "Cannot store blob at address #{address} in " + "EquiBlobsFile #{@file_name}. Address is larger than file size. " + "Offset: #{offset} File size: #{file_size}" end @f.seek(offset) # The first byte is the marker byte. It's set to 2 for cells that hold # a blob. 1 for reserved cells and 0 for empty cells. The cell must be # either already be in use or be reserved. It must not be 0. if file_size > offset && (marker = read_char) != 1 && marker != 2 PEROBS.log.fatal "Marker for entry at address #{address} of " + "EquiBlobsFile #{@file_name} must be 1 or 2 but is #{marker}" end @f.seek(offset) write_char(2) @f.write(bytes) @f.flush rescue IOError => e PEROBS.log.fatal "Cannot store blob at address #{address} in " + "EquiBlobsFile #{@file_name}: #{e.message}" end # Update the entries counter if we inserted a new blob. if marker == 1 @total_entries += 1 write_header end end
[ "def", "store_blob", "(", "address", ",", "bytes", ")", "unless", "address", ">=", "0", "PEROBS", ".", "log", ".", "fatal", "\"Blob storage address must be larger than 0, \"", "+", "\"not #{address}\"", "end", "if", "bytes", ".", "length", "!=", "@entry_bytes", "PEROBS", ".", "log", ".", "fatal", "\"All stack entries must be #{@entry_bytes} \"", "+", "\"long. This entry is #{bytes.length} bytes long.\"", "end", "marker", "=", "1", "begin", "offset", "=", "address_to_offset", "(", "address", ")", "if", "offset", ">", "(", "file_size", "=", "@f", ".", "size", ")", "PEROBS", ".", "log", ".", "fatal", "\"Cannot store blob at address #{address} in \"", "+", "\"EquiBlobsFile #{@file_name}. Address is larger than file size. \"", "+", "\"Offset: #{offset} File size: #{file_size}\"", "end", "@f", ".", "seek", "(", "offset", ")", "# The first byte is the marker byte. It's set to 2 for cells that hold", "# a blob. 1 for reserved cells and 0 for empty cells. The cell must be", "# either already be in use or be reserved. It must not be 0.", "if", "file_size", ">", "offset", "&&", "(", "marker", "=", "read_char", ")", "!=", "1", "&&", "marker", "!=", "2", "PEROBS", ".", "log", ".", "fatal", "\"Marker for entry at address #{address} of \"", "+", "\"EquiBlobsFile #{@file_name} must be 1 or 2 but is #{marker}\"", "end", "@f", ".", "seek", "(", "offset", ")", "write_char", "(", "2", ")", "@f", ".", "write", "(", "bytes", ")", "@f", ".", "flush", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot store blob at address #{address} in \"", "+", "\"EquiBlobsFile #{@file_name}: #{e.message}\"", "end", "# Update the entries counter if we inserted a new blob.", "if", "marker", "==", "1", "@total_entries", "+=", "1", "write_header", "end", "end" ]
Store the given byte blob at the specified address. If the blob space is already in use the content will be overwritten. @param address [Integer] Address to store the blob @param bytes [String] bytes to store
[ "Store", "the", "given", "byte", "blob", "at", "the", "specified", "address", ".", "If", "the", "blob", "space", "is", "already", "in", "use", "the", "content", "will", "be", "overwritten", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L248-L290
4,256
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.retrieve_blob
def retrieve_blob(address) unless address > 0 PEROBS.log.fatal "Blob retrieval address must be larger than 0, " + "not #{address}" end begin if (offset = address_to_offset(address)) >= @f.size PEROBS.log.fatal "Cannot retrieve blob at address #{address} " + "of EquiBlobsFile #{@file_name}. Address is beyond end of file." end @f.seek(address_to_offset(address)) if (marker = read_char) != 2 PEROBS.log.fatal "Cannot retrieve blob at address #{address} " + "of EquiBlobsFile #{@file_name}. Blob is " + (marker == 0 ? 'empty' : marker == 1 ? 'reserved' : 'corrupted') + '.' end bytes = @f.read(@entry_bytes) rescue IOError => e PEROBS.log.fatal "Cannot retrieve blob at adress #{address} " + "of EquiBlobsFile #{@file_name}: " + e.message end bytes end
ruby
def retrieve_blob(address) unless address > 0 PEROBS.log.fatal "Blob retrieval address must be larger than 0, " + "not #{address}" end begin if (offset = address_to_offset(address)) >= @f.size PEROBS.log.fatal "Cannot retrieve blob at address #{address} " + "of EquiBlobsFile #{@file_name}. Address is beyond end of file." end @f.seek(address_to_offset(address)) if (marker = read_char) != 2 PEROBS.log.fatal "Cannot retrieve blob at address #{address} " + "of EquiBlobsFile #{@file_name}. Blob is " + (marker == 0 ? 'empty' : marker == 1 ? 'reserved' : 'corrupted') + '.' end bytes = @f.read(@entry_bytes) rescue IOError => e PEROBS.log.fatal "Cannot retrieve blob at adress #{address} " + "of EquiBlobsFile #{@file_name}: " + e.message end bytes end
[ "def", "retrieve_blob", "(", "address", ")", "unless", "address", ">", "0", "PEROBS", ".", "log", ".", "fatal", "\"Blob retrieval address must be larger than 0, \"", "+", "\"not #{address}\"", "end", "begin", "if", "(", "offset", "=", "address_to_offset", "(", "address", ")", ")", ">=", "@f", ".", "size", "PEROBS", ".", "log", ".", "fatal", "\"Cannot retrieve blob at address #{address} \"", "+", "\"of EquiBlobsFile #{@file_name}. Address is beyond end of file.\"", "end", "@f", ".", "seek", "(", "address_to_offset", "(", "address", ")", ")", "if", "(", "marker", "=", "read_char", ")", "!=", "2", "PEROBS", ".", "log", ".", "fatal", "\"Cannot retrieve blob at address #{address} \"", "+", "\"of EquiBlobsFile #{@file_name}. Blob is \"", "+", "(", "marker", "==", "0", "?", "'empty'", ":", "marker", "==", "1", "?", "'reserved'", ":", "'corrupted'", ")", "+", "'.'", "end", "bytes", "=", "@f", ".", "read", "(", "@entry_bytes", ")", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot retrieve blob at adress #{address} \"", "+", "\"of EquiBlobsFile #{@file_name}: \"", "+", "e", ".", "message", "end", "bytes", "end" ]
Retrieve a blob from the given address. @param address [Integer] Address to store the blob @return [String] blob bytes
[ "Retrieve", "a", "blob", "from", "the", "given", "address", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L295-L321
4,257
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.delete_blob
def delete_blob(address) unless address >= 0 PEROBS.log.fatal "Blob address must be larger than 0, " + "not #{address}" end offset = address_to_offset(address) begin @f.seek(offset) if (marker = read_char) != 1 && marker != 2 PEROBS.log.fatal "Cannot delete blob stored at address #{address} " + "of EquiBlobsFile #{@file_name}. Blob is " + (marker == 0 ? 'empty' : 'corrupted') + '.' end @f.seek(address_to_offset(address)) write_char(0) write_unsigned_int(@first_space) rescue IOError => e PEROBS.log.fatal "Cannot delete blob at address #{address}: " + e.message end @first_space = offset @total_spaces += 1 @total_entries -= 1 unless marker == 1 write_header if offset == @f.size - 1 - @entry_bytes # We have deleted the last entry in the file. Make sure that all empty # entries are removed up to the now new last used entry. trim_file end end
ruby
def delete_blob(address) unless address >= 0 PEROBS.log.fatal "Blob address must be larger than 0, " + "not #{address}" end offset = address_to_offset(address) begin @f.seek(offset) if (marker = read_char) != 1 && marker != 2 PEROBS.log.fatal "Cannot delete blob stored at address #{address} " + "of EquiBlobsFile #{@file_name}. Blob is " + (marker == 0 ? 'empty' : 'corrupted') + '.' end @f.seek(address_to_offset(address)) write_char(0) write_unsigned_int(@first_space) rescue IOError => e PEROBS.log.fatal "Cannot delete blob at address #{address}: " + e.message end @first_space = offset @total_spaces += 1 @total_entries -= 1 unless marker == 1 write_header if offset == @f.size - 1 - @entry_bytes # We have deleted the last entry in the file. Make sure that all empty # entries are removed up to the now new last used entry. trim_file end end
[ "def", "delete_blob", "(", "address", ")", "unless", "address", ">=", "0", "PEROBS", ".", "log", ".", "fatal", "\"Blob address must be larger than 0, \"", "+", "\"not #{address}\"", "end", "offset", "=", "address_to_offset", "(", "address", ")", "begin", "@f", ".", "seek", "(", "offset", ")", "if", "(", "marker", "=", "read_char", ")", "!=", "1", "&&", "marker", "!=", "2", "PEROBS", ".", "log", ".", "fatal", "\"Cannot delete blob stored at address #{address} \"", "+", "\"of EquiBlobsFile #{@file_name}. Blob is \"", "+", "(", "marker", "==", "0", "?", "'empty'", ":", "'corrupted'", ")", "+", "'.'", "end", "@f", ".", "seek", "(", "address_to_offset", "(", "address", ")", ")", "write_char", "(", "0", ")", "write_unsigned_int", "(", "@first_space", ")", "rescue", "IOError", "=>", "e", "PEROBS", ".", "log", ".", "fatal", "\"Cannot delete blob at address #{address}: \"", "+", "e", ".", "message", "end", "@first_space", "=", "offset", "@total_spaces", "+=", "1", "@total_entries", "-=", "1", "unless", "marker", "==", "1", "write_header", "if", "offset", "==", "@f", ".", "size", "-", "1", "-", "@entry_bytes", "# We have deleted the last entry in the file. Make sure that all empty", "# entries are removed up to the now new last used entry.", "trim_file", "end", "end" ]
Delete the blob at the given address. @param address [Integer] Address of blob to delete
[ "Delete", "the", "blob", "at", "the", "given", "address", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L325-L357
4,258
scrapper/perobs
lib/perobs/EquiBlobsFile.rb
PEROBS.EquiBlobsFile.check
def check sync return false unless check_spaces return false unless check_entries expected_size = address_to_offset(@total_entries + @total_spaces + 1) actual_size = @f.size if actual_size != expected_size PEROBS.log.error "Size mismatch in EquiBlobsFile #{@file_name}. " + "Expected #{expected_size} bytes but found #{actual_size} bytes." return false end true end
ruby
def check sync return false unless check_spaces return false unless check_entries expected_size = address_to_offset(@total_entries + @total_spaces + 1) actual_size = @f.size if actual_size != expected_size PEROBS.log.error "Size mismatch in EquiBlobsFile #{@file_name}. " + "Expected #{expected_size} bytes but found #{actual_size} bytes." return false end true end
[ "def", "check", "sync", "return", "false", "unless", "check_spaces", "return", "false", "unless", "check_entries", "expected_size", "=", "address_to_offset", "(", "@total_entries", "+", "@total_spaces", "+", "1", ")", "actual_size", "=", "@f", ".", "size", "if", "actual_size", "!=", "expected_size", "PEROBS", ".", "log", ".", "error", "\"Size mismatch in EquiBlobsFile #{@file_name}. \"", "+", "\"Expected #{expected_size} bytes but found #{actual_size} bytes.\"", "return", "false", "end", "true", "end" ]
Check the file for logical errors. @return [Boolean] true of file has no errors, false otherwise.
[ "Check", "the", "file", "for", "logical", "errors", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/EquiBlobsFile.rb#L361-L376
4,259
scrapper/perobs
lib/perobs/Log.rb
PEROBS.ILogger.open
def open(io) begin @@logger = Logger.new(io, *@@options) rescue IOError => e @@logger = Logger.new($stderr) $stderr.puts "Cannot open log file: #{e.message}" end @@logger.level = @@level @@logger.formatter = @@formatter end
ruby
def open(io) begin @@logger = Logger.new(io, *@@options) rescue IOError => e @@logger = Logger.new($stderr) $stderr.puts "Cannot open log file: #{e.message}" end @@logger.level = @@level @@logger.formatter = @@formatter end
[ "def", "open", "(", "io", ")", "begin", "@@logger", "=", "Logger", ".", "new", "(", "io", ",", "@@options", ")", "rescue", "IOError", "=>", "e", "@@logger", "=", "Logger", ".", "new", "(", "$stderr", ")", "$stderr", ".", "puts", "\"Cannot open log file: #{e.message}\"", "end", "@@logger", ".", "level", "=", "@@level", "@@logger", ".", "formatter", "=", "@@formatter", "end" ]
Redirect all log messages to the given IO. @param io [IO] Output file descriptor
[ "Redirect", "all", "log", "messages", "to", "the", "given", "IO", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Log.rb#L81-L90
4,260
scrapper/perobs
lib/perobs/ClassMap.rb
PEROBS.ClassMap.rename
def rename(rename_map) @by_id.each.with_index do |klass, id| # Some entries can be nil. Ignore them. next unless klass if (new_name = rename_map[klass]) # We have a rename request. Update the current @by_id entry. @by_id[id] = new_name # Remove the old class name from @by_class hash. @by_class.delete(klass) # Insert the new one with the current ID. @by_class[new_name] = id end end end
ruby
def rename(rename_map) @by_id.each.with_index do |klass, id| # Some entries can be nil. Ignore them. next unless klass if (new_name = rename_map[klass]) # We have a rename request. Update the current @by_id entry. @by_id[id] = new_name # Remove the old class name from @by_class hash. @by_class.delete(klass) # Insert the new one with the current ID. @by_class[new_name] = id end end end
[ "def", "rename", "(", "rename_map", ")", "@by_id", ".", "each", ".", "with_index", "do", "|", "klass", ",", "id", "|", "# Some entries can be nil. Ignore them.", "next", "unless", "klass", "if", "(", "new_name", "=", "rename_map", "[", "klass", "]", ")", "# We have a rename request. Update the current @by_id entry.", "@by_id", "[", "id", "]", "=", "new_name", "# Remove the old class name from @by_class hash.", "@by_class", ".", "delete", "(", "klass", ")", "# Insert the new one with the current ID.", "@by_class", "[", "new_name", "]", "=", "id", "end", "end", "end" ]
Rename a set of classes to new names. @param rename_map [Hash] Hash that maps old names to new names
[ "Rename", "a", "set", "of", "classes", "to", "new", "names", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/ClassMap.rb#L65-L79
4,261
scrapper/perobs
lib/perobs/ClassMap.rb
PEROBS.ClassMap.keep
def keep(classes) @by_id.each.with_index do |klass, id| unless classes.include?(klass) # Delete the class from the @by_id list by setting the entry to nil. @by_id[id] = nil # Delete the corresponding @by_class entry as well. @by_class.delete(klass) end end end
ruby
def keep(classes) @by_id.each.with_index do |klass, id| unless classes.include?(klass) # Delete the class from the @by_id list by setting the entry to nil. @by_id[id] = nil # Delete the corresponding @by_class entry as well. @by_class.delete(klass) end end end
[ "def", "keep", "(", "classes", ")", "@by_id", ".", "each", ".", "with_index", "do", "|", "klass", ",", "id", "|", "unless", "classes", ".", "include?", "(", "klass", ")", "# Delete the class from the @by_id list by setting the entry to nil.", "@by_id", "[", "id", "]", "=", "nil", "# Delete the corresponding @by_class entry as well.", "@by_class", ".", "delete", "(", "klass", ")", "end", "end", "end" ]
Delete all classes unless they are contained in _classes_. @param classes [Array of String] List of the class names
[ "Delete", "all", "classes", "unless", "they", "are", "contained", "in", "_classes_", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/ClassMap.rb#L83-L92
4,262
mreq/wmctile
lib/wmctile/memory.rb
Wmctile.Memory.read_file
def read_file @file_path = '~/.local/share/wmctile' @file_name = 'memory.yml' @file_full = File.expand_path([@file_path, @file_name].join('/')) if File.exist? @file_full file_contents = File.read(@file_full) @memory = YAML.load(file_contents) else create_file write_file end end
ruby
def read_file @file_path = '~/.local/share/wmctile' @file_name = 'memory.yml' @file_full = File.expand_path([@file_path, @file_name].join('/')) if File.exist? @file_full file_contents = File.read(@file_full) @memory = YAML.load(file_contents) else create_file write_file end end
[ "def", "read_file", "@file_path", "=", "'~/.local/share/wmctile'", "@file_name", "=", "'memory.yml'", "@file_full", "=", "File", ".", "expand_path", "(", "[", "@file_path", ",", "@file_name", "]", ".", "join", "(", "'/'", ")", ")", "if", "File", ".", "exist?", "@file_full", "file_contents", "=", "File", ".", "read", "(", "@file_full", ")", "@memory", "=", "YAML", ".", "load", "(", "file_contents", ")", "else", "create_file", "write_file", "end", "end" ]
Memory init function. Creates a default yaml file if it's non-existent. Reads the yaml file, creating it if non-existent. @return [void]
[ "Memory", "init", "function", ".", "Creates", "a", "default", "yaml", "file", "if", "it", "s", "non", "-", "existent", "." ]
a41af5afa310b09c8ba1bd45a134b9b2a87d1a35
https://github.com/mreq/wmctile/blob/a41af5afa310b09c8ba1bd45a134b9b2a87d1a35/lib/wmctile/memory.rb#L20-L32
4,263
sethvargo/community-zero
lib/community_zero/endpoint.rb
CommunityZero.Endpoint.call
def call(request) m = request.method.downcase.to_sym # Only respond to listed methods unless respond_to?(m) allowed = METHODS.select { |m| respond_to?(m) }.map(&:upcase).join(', ') return [ 405, { 'Content-Type' => 'text/plain', 'Allow' => allowed }, "Method not allowed: '#{request.env['REQUEST_METHOD']}'" ] end begin send(m, request) rescue RestError => e error(e.response_code, e.error) end end
ruby
def call(request) m = request.method.downcase.to_sym # Only respond to listed methods unless respond_to?(m) allowed = METHODS.select { |m| respond_to?(m) }.map(&:upcase).join(', ') return [ 405, { 'Content-Type' => 'text/plain', 'Allow' => allowed }, "Method not allowed: '#{request.env['REQUEST_METHOD']}'" ] end begin send(m, request) rescue RestError => e error(e.response_code, e.error) end end
[ "def", "call", "(", "request", ")", "m", "=", "request", ".", "method", ".", "downcase", ".", "to_sym", "# Only respond to listed methods", "unless", "respond_to?", "(", "m", ")", "allowed", "=", "METHODS", ".", "select", "{", "|", "m", "|", "respond_to?", "(", "m", ")", "}", ".", "map", "(", ":upcase", ")", ".", "join", "(", "', '", ")", "return", "[", "405", ",", "{", "'Content-Type'", "=>", "'text/plain'", ",", "'Allow'", "=>", "allowed", "}", ",", "\"Method not allowed: '#{request.env['REQUEST_METHOD']}'\"", "]", "end", "begin", "send", "(", "m", ",", "request", ")", "rescue", "RestError", "=>", "e", "error", "(", "e", ".", "response_code", ",", "e", ".", "error", ")", "end", "end" ]
Call the request. @param [CommunityZero::Request] request the request object
[ "Call", "the", "request", "." ]
08a22c47c865deb6a5f931cb4d9f747a2b9d3459
https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/endpoint.rb#L76-L94
4,264
code-and-effect/effective_pages
app/models/effective/page.rb
Effective.Page.duplicate!
def duplicate! Page.new(attributes.except('id', 'updated_at', 'created_at')).tap do |page| page.title = page.title + ' (Copy)' page.slug = page.slug + '-copy' page.draft = true regions.each do |region| page.regions.build(region.attributes.except('id', 'updated_at', 'created_at')) end page.save! end end
ruby
def duplicate! Page.new(attributes.except('id', 'updated_at', 'created_at')).tap do |page| page.title = page.title + ' (Copy)' page.slug = page.slug + '-copy' page.draft = true regions.each do |region| page.regions.build(region.attributes.except('id', 'updated_at', 'created_at')) end page.save! end end
[ "def", "duplicate!", "Page", ".", "new", "(", "attributes", ".", "except", "(", "'id'", ",", "'updated_at'", ",", "'created_at'", ")", ")", ".", "tap", "do", "|", "page", "|", "page", ".", "title", "=", "page", ".", "title", "+", "' (Copy)'", "page", ".", "slug", "=", "page", ".", "slug", "+", "'-copy'", "page", ".", "draft", "=", "true", "regions", ".", "each", "do", "|", "region", "|", "page", ".", "regions", ".", "build", "(", "region", ".", "attributes", ".", "except", "(", "'id'", ",", "'updated_at'", ",", "'created_at'", ")", ")", "end", "page", ".", "save!", "end", "end" ]
Returns a duplicated post object, or throws an exception
[ "Returns", "a", "duplicated", "post", "object", "or", "throws", "an", "exception" ]
ff00e2d76055985ab65f570747bc9a5f2748f817
https://github.com/code-and-effect/effective_pages/blob/ff00e2d76055985ab65f570747bc9a5f2748f817/app/models/effective/page.rb#L46-L58
4,265
sagmor/yard-mruby
lib/yard/mruby/parser/c/header_parser.rb
YARD::MRuby::Parser::C.HeaderParser.consume_directive
def consume_directive super if @in_body_statements @newline = false start = @index line = @line statement = DirectiveStatement.new(nil, @file, line) @statements << statement attach_comment(statement) multiline = false advance_loop do chr = char case chr when '\\'; multiline=true; advance when /\s/; consume_whitespace else advance end if @newline if multiline multiline = false else break end end end decl = @content[start...@index] statement.declaration = decl end
ruby
def consume_directive super if @in_body_statements @newline = false start = @index line = @line statement = DirectiveStatement.new(nil, @file, line) @statements << statement attach_comment(statement) multiline = false advance_loop do chr = char case chr when '\\'; multiline=true; advance when /\s/; consume_whitespace else advance end if @newline if multiline multiline = false else break end end end decl = @content[start...@index] statement.declaration = decl end
[ "def", "consume_directive", "super", "if", "@in_body_statements", "@newline", "=", "false", "start", "=", "@index", "line", "=", "@line", "statement", "=", "DirectiveStatement", ".", "new", "(", "nil", ",", "@file", ",", "line", ")", "@statements", "<<", "statement", "attach_comment", "(", "statement", ")", "multiline", "=", "false", "advance_loop", "do", "chr", "=", "char", "case", "chr", "when", "'\\\\'", ";", "multiline", "=", "true", ";", "advance", "when", "/", "\\s", "/", ";", "consume_whitespace", "else", "advance", "end", "if", "@newline", "if", "multiline", "multiline", "=", "false", "else", "break", "end", "end", "end", "decl", "=", "@content", "[", "start", "...", "@index", "]", "statement", ".", "declaration", "=", "decl", "end" ]
Consumes a directive and generates a DirectiveStatement
[ "Consumes", "a", "directive", "and", "generates", "a", "DirectiveStatement" ]
c20c2f415d15235fdc96ac177cb008eb3e11358a
https://github.com/sagmor/yard-mruby/blob/c20c2f415d15235fdc96ac177cb008eb3e11358a/lib/yard/mruby/parser/c/header_parser.rb#L5-L36
4,266
r7kamura/xrc
lib/xrc/client.rb
Xrc.Client.reply
def reply(options) say( body: options[:body], from: options[:to].to, to: options[:to].from, type: options[:to].type, ) end
ruby
def reply(options) say( body: options[:body], from: options[:to].to, to: options[:to].from, type: options[:to].type, ) end
[ "def", "reply", "(", "options", ")", "say", "(", "body", ":", "options", "[", ":body", "]", ",", "from", ":", "options", "[", ":to", "]", ".", "to", ",", "to", ":", "options", "[", ":to", "]", ".", "from", ",", "type", ":", "options", "[", ":to", "]", ".", "type", ",", ")", "end" ]
Replies to given message @option options [Xrc::Messages::Base] :to A message object given from server @option options [String] :body A text to be sent to server @return [REXML::Element] Returns an element sent to server @example client.reply(body: "Thanks", to: message)
[ "Replies", "to", "given", "message" ]
ddc0af9682fc2cdaf851f88a3f0953a1478f1954
https://github.com/r7kamura/xrc/blob/ddc0af9682fc2cdaf851f88a3f0953a1478f1954/lib/xrc/client.rb#L106-L113
4,267
r7kamura/xrc
lib/xrc/client.rb
Xrc.Client.say
def say(options) post Elements::Message.new( body: options[:body], from: options[:from], to: options[:to], type: options[:type], ) end
ruby
def say(options) post Elements::Message.new( body: options[:body], from: options[:from], to: options[:to], type: options[:type], ) end
[ "def", "say", "(", "options", ")", "post", "Elements", "::", "Message", ".", "new", "(", "body", ":", "options", "[", ":body", "]", ",", "from", ":", "options", "[", ":from", "]", ",", "to", ":", "options", "[", ":to", "]", ",", "type", ":", "options", "[", ":type", "]", ",", ")", "end" ]
Send a message @option options [String] :body Message body @option options [String] :from Sender's JID @option options [String] :to Address JID @option options [String] :type Message type (e.g. chat, groupchat) @return [REXML::Element] Returns an element sent to server @example client.say(body: "Thanks", from: "[email protected]", to: "[email protected]", type: "chat")
[ "Send", "a", "message" ]
ddc0af9682fc2cdaf851f88a3f0953a1478f1954
https://github.com/r7kamura/xrc/blob/ddc0af9682fc2cdaf851f88a3f0953a1478f1954/lib/xrc/client.rb#L123-L130
4,268
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.[]=
def []=(index, value) index = validate_index_range(index) @store.transaction do if index < @entry_counter # Overwrite of an existing element @root.set(index, value) elsif index == @entry_counter # Append right at the end @root.insert(index, value) self.entry_counter += 1 else # Append with nil padding @entry_counter.upto(index - 1) do |i| @root.insert(i, nil) end @root.insert(index, value) self.entry_counter = index + 1 end end end
ruby
def []=(index, value) index = validate_index_range(index) @store.transaction do if index < @entry_counter # Overwrite of an existing element @root.set(index, value) elsif index == @entry_counter # Append right at the end @root.insert(index, value) self.entry_counter += 1 else # Append with nil padding @entry_counter.upto(index - 1) do |i| @root.insert(i, nil) end @root.insert(index, value) self.entry_counter = index + 1 end end end
[ "def", "[]=", "(", "index", ",", "value", ")", "index", "=", "validate_index_range", "(", "index", ")", "@store", ".", "transaction", "do", "if", "index", "<", "@entry_counter", "# Overwrite of an existing element", "@root", ".", "set", "(", "index", ",", "value", ")", "elsif", "index", "==", "@entry_counter", "# Append right at the end", "@root", ".", "insert", "(", "index", ",", "value", ")", "self", ".", "entry_counter", "+=", "1", "else", "# Append with nil padding", "@entry_counter", ".", "upto", "(", "index", "-", "1", ")", "do", "|", "i", "|", "@root", ".", "insert", "(", "i", ",", "nil", ")", "end", "@root", ".", "insert", "(", "index", ",", "value", ")", "self", ".", "entry_counter", "=", "index", "+", "1", "end", "end", "end" ]
Store the value at the given index. If the index already exists the old value will be overwritten. @param index [Integer] Position in the array @param value [Integer] value
[ "Store", "the", "value", "at", "the", "given", "index", ".", "If", "the", "index", "already", "exists", "the", "old", "value", "will", "be", "overwritten", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L78-L98
4,269
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.insert
def insert(index, value) index = validate_index_range(index) if index < @entry_counter # Insert in between existing elements @store.transaction do @root.insert(index, value) self.entry_counter += 1 end else self[index] = value end end
ruby
def insert(index, value) index = validate_index_range(index) if index < @entry_counter # Insert in between existing elements @store.transaction do @root.insert(index, value) self.entry_counter += 1 end else self[index] = value end end
[ "def", "insert", "(", "index", ",", "value", ")", "index", "=", "validate_index_range", "(", "index", ")", "if", "index", "<", "@entry_counter", "# Insert in between existing elements", "@store", ".", "transaction", "do", "@root", ".", "insert", "(", "index", ",", "value", ")", "self", ".", "entry_counter", "+=", "1", "end", "else", "self", "[", "index", "]", "=", "value", "end", "end" ]
Insert the value at the given index. If the index already exists the old value will be overwritten. @param index [Integer] Position in the array @param value [Integer] value
[ "Insert", "the", "value", "at", "the", "given", "index", ".", "If", "the", "index", "already", "exists", "the", "old", "value", "will", "be", "overwritten", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L108-L120
4,270
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.delete_if
def delete_if old_root = @root clear old_root.each do |k, v| if !yield(k, v) insert(k, v) end end end
ruby
def delete_if old_root = @root clear old_root.each do |k, v| if !yield(k, v) insert(k, v) end end end
[ "def", "delete_if", "old_root", "=", "@root", "clear", "old_root", ".", "each", "do", "|", "k", ",", "v", "|", "if", "!", "yield", "(", "k", ",", "v", ")", "insert", "(", "k", ",", "v", ")", "end", "end", "end" ]
Delete all entries for which the passed block yields true. The implementation is optimized for large bulk deletes. It rebuilds a new BTree for the elements to keep. If only few elements are deleted the overhead of rebuilding the BTree is rather high. @yield [key, value]
[ "Delete", "all", "entries", "for", "which", "the", "passed", "block", "yields", "true", ".", "The", "implementation", "is", "optimized", "for", "large", "bulk", "deletes", ".", "It", "rebuilds", "a", "new", "BTree", "for", "the", "elements", "to", "keep", ".", "If", "only", "few", "elements", "are", "deleted", "the", "overhead", "of", "rebuilding", "the", "BTree", "is", "rather", "high", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L171-L179
4,271
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.each
def each(&block) node = @first_leaf while node break unless node.each(&block) node = node.next_sibling end end
ruby
def each(&block) node = @first_leaf while node break unless node.each(&block) node = node.next_sibling end end
[ "def", "each", "(", "&", "block", ")", "node", "=", "@first_leaf", "while", "node", "break", "unless", "node", ".", "each", "(", "block", ")", "node", "=", "node", ".", "next_sibling", "end", "end" ]
Iterate over all entries in the tree. Entries are always sorted by the key. @yield [key, value]
[ "Iterate", "over", "all", "entries", "in", "the", "tree", ".", "Entries", "are", "always", "sorted", "by", "the", "key", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L196-L202
4,272
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.reverse_each
def reverse_each(&block) node = @last_leaf while node break unless node.reverse_each(&block) node = node.prev_sibling end end
ruby
def reverse_each(&block) node = @last_leaf while node break unless node.reverse_each(&block) node = node.prev_sibling end end
[ "def", "reverse_each", "(", "&", "block", ")", "node", "=", "@last_leaf", "while", "node", "break", "unless", "node", ".", "reverse_each", "(", "block", ")", "node", "=", "node", ".", "prev_sibling", "end", "end" ]
Iterate over all entries in the tree in reverse order. Entries are always sorted by the key. @yield [key, value]
[ "Iterate", "over", "all", "entries", "in", "the", "tree", "in", "reverse", "order", ".", "Entries", "are", "always", "sorted", "by", "the", "key", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L207-L213
4,273
scrapper/perobs
lib/perobs/BigArray.rb
PEROBS.BigArray.to_a
def to_a ary = [] node = @first_leaf while node do ary += node.values node = node.next_sibling end ary end
ruby
def to_a ary = [] node = @first_leaf while node do ary += node.values node = node.next_sibling end ary end
[ "def", "to_a", "ary", "=", "[", "]", "node", "=", "@first_leaf", "while", "node", "do", "ary", "+=", "node", ".", "values", "node", "=", "node", ".", "next_sibling", "end", "ary", "end" ]
Convert the BigArray into a Ruby Array. This is primarily intended for debugging as real-world BigArray objects are likely too big to fit into memory.
[ "Convert", "the", "BigArray", "into", "a", "Ruby", "Array", ".", "This", "is", "primarily", "intended", "for", "debugging", "as", "real", "-", "world", "BigArray", "objects", "are", "likely", "too", "big", "to", "fit", "into", "memory", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BigArray.rb#L218-L227
4,274
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.save
def save bytes = [ @blob_address, @size, @parent ? @parent.node_address : 0, @smaller ? @smaller.node_address : 0, @equal ? @equal.node_address : 0, @larger ? @larger.node_address : 0].pack(NODE_BYTES_FORMAT) @tree.nodes.store_blob(@node_address, bytes) end
ruby
def save bytes = [ @blob_address, @size, @parent ? @parent.node_address : 0, @smaller ? @smaller.node_address : 0, @equal ? @equal.node_address : 0, @larger ? @larger.node_address : 0].pack(NODE_BYTES_FORMAT) @tree.nodes.store_blob(@node_address, bytes) end
[ "def", "save", "bytes", "=", "[", "@blob_address", ",", "@size", ",", "@parent", "?", "@parent", ".", "node_address", ":", "0", ",", "@smaller", "?", "@smaller", ".", "node_address", ":", "0", ",", "@equal", "?", "@equal", ".", "node_address", ":", "0", ",", "@larger", "?", "@larger", ".", "node_address", ":", "0", "]", ".", "pack", "(", "NODE_BYTES_FORMAT", ")", "@tree", ".", "nodes", ".", "store_blob", "(", "@node_address", ",", "bytes", ")", "end" ]
Save the node into the blob file.
[ "Save", "the", "node", "into", "the", "blob", "file", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L128-L135
4,275
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.add_space
def add_space(address, size) node = self loop do if node.size == 0 # This happens only for the root node if the tree is empty. node.set_size_and_address(size, address) break elsif size < node.size # The new size is smaller than this node. if node.smaller # There is already a smaller node, so pass it on. node = node.smaller else # There is no smaller node yet, so we create a new one as a # smaller child of the current node. node.set_link('@smaller', SpaceTreeNode::create(@tree, address, size, node)) break end elsif size > node.size # The new size is larger than this node. if node.larger # There is already a larger node, so pass it on. node = node.larger else # There is no larger node yet, so we create a new one as a larger # child of the current node. node.set_link('@larger', SpaceTreeNode::create(@tree, address, size, node)) break end else # Same size as current node. Insert new node as equal child at top of # equal list. new_node = SpaceTreeNode::create(@tree, address, size, node) new_node.set_link('@equal', node.equal) node.set_link('@equal', new_node) break end end end
ruby
def add_space(address, size) node = self loop do if node.size == 0 # This happens only for the root node if the tree is empty. node.set_size_and_address(size, address) break elsif size < node.size # The new size is smaller than this node. if node.smaller # There is already a smaller node, so pass it on. node = node.smaller else # There is no smaller node yet, so we create a new one as a # smaller child of the current node. node.set_link('@smaller', SpaceTreeNode::create(@tree, address, size, node)) break end elsif size > node.size # The new size is larger than this node. if node.larger # There is already a larger node, so pass it on. node = node.larger else # There is no larger node yet, so we create a new one as a larger # child of the current node. node.set_link('@larger', SpaceTreeNode::create(@tree, address, size, node)) break end else # Same size as current node. Insert new node as equal child at top of # equal list. new_node = SpaceTreeNode::create(@tree, address, size, node) new_node.set_link('@equal', node.equal) node.set_link('@equal', new_node) break end end end
[ "def", "add_space", "(", "address", ",", "size", ")", "node", "=", "self", "loop", "do", "if", "node", ".", "size", "==", "0", "# This happens only for the root node if the tree is empty.", "node", ".", "set_size_and_address", "(", "size", ",", "address", ")", "break", "elsif", "size", "<", "node", ".", "size", "# The new size is smaller than this node.", "if", "node", ".", "smaller", "# There is already a smaller node, so pass it on.", "node", "=", "node", ".", "smaller", "else", "# There is no smaller node yet, so we create a new one as a", "# smaller child of the current node.", "node", ".", "set_link", "(", "'@smaller'", ",", "SpaceTreeNode", "::", "create", "(", "@tree", ",", "address", ",", "size", ",", "node", ")", ")", "break", "end", "elsif", "size", ">", "node", ".", "size", "# The new size is larger than this node.", "if", "node", ".", "larger", "# There is already a larger node, so pass it on.", "node", "=", "node", ".", "larger", "else", "# There is no larger node yet, so we create a new one as a larger", "# child of the current node.", "node", ".", "set_link", "(", "'@larger'", ",", "SpaceTreeNode", "::", "create", "(", "@tree", ",", "address", ",", "size", ",", "node", ")", ")", "break", "end", "else", "# Same size as current node. Insert new node as equal child at top of", "# equal list.", "new_node", "=", "SpaceTreeNode", "::", "create", "(", "@tree", ",", "address", ",", "size", ",", "node", ")", "new_node", ".", "set_link", "(", "'@equal'", ",", "node", ".", "equal", ")", "node", ".", "set_link", "(", "'@equal'", ",", "new_node", ")", "break", "end", "end", "end" ]
Add a new node for the given address and size to the tree. @param address [Integer] address of the free space @param size [Integer] size of the free space
[ "Add", "a", "new", "node", "for", "the", "given", "address", "and", "size", "to", "the", "tree", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L140-L183
4,276
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.has_space?
def has_space?(address, size) node = self loop do if node.blob_address == address return size == node.size elsif size < node.size && node.smaller node = node.smaller elsif size > node.size && node.larger node = node.larger elsif size == node.size && node.equal node = node.equal else return false end end end
ruby
def has_space?(address, size) node = self loop do if node.blob_address == address return size == node.size elsif size < node.size && node.smaller node = node.smaller elsif size > node.size && node.larger node = node.larger elsif size == node.size && node.equal node = node.equal else return false end end end
[ "def", "has_space?", "(", "address", ",", "size", ")", "node", "=", "self", "loop", "do", "if", "node", ".", "blob_address", "==", "address", "return", "size", "==", "node", ".", "size", "elsif", "size", "<", "node", ".", "size", "&&", "node", ".", "smaller", "node", "=", "node", ".", "smaller", "elsif", "size", ">", "node", ".", "size", "&&", "node", ".", "larger", "node", "=", "node", ".", "larger", "elsif", "size", "==", "node", ".", "size", "&&", "node", ".", "equal", "node", "=", "node", ".", "equal", "else", "return", "false", "end", "end", "end" ]
Check if this node or any sub-node has an entry for the given address and size. @param address [Integer] address of the free space @param size [Integer] size of the free space @return [Boolean] True if found, otherwise false
[ "Check", "if", "this", "node", "or", "any", "sub", "-", "node", "has", "an", "entry", "for", "the", "given", "address", "and", "size", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L190-L205
4,277
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.relink_parent
def relink_parent(node) if @parent if @parent.smaller == self @parent.set_link('@smaller', node) elsif @parent.equal == self @parent.set_link('@equal', node) elsif @parent.larger == self @parent.set_link('@larger', node) else PEROBS.log.fatal "Cannot relink unknown child node with address " + "#{node.node_address} from #{parent.to_s}" end else if node @tree.set_root(node) node.parent = nil else set_size_and_address(0, 0) end end end
ruby
def relink_parent(node) if @parent if @parent.smaller == self @parent.set_link('@smaller', node) elsif @parent.equal == self @parent.set_link('@equal', node) elsif @parent.larger == self @parent.set_link('@larger', node) else PEROBS.log.fatal "Cannot relink unknown child node with address " + "#{node.node_address} from #{parent.to_s}" end else if node @tree.set_root(node) node.parent = nil else set_size_and_address(0, 0) end end end
[ "def", "relink_parent", "(", "node", ")", "if", "@parent", "if", "@parent", ".", "smaller", "==", "self", "@parent", ".", "set_link", "(", "'@smaller'", ",", "node", ")", "elsif", "@parent", ".", "equal", "==", "self", "@parent", ".", "set_link", "(", "'@equal'", ",", "node", ")", "elsif", "@parent", ".", "larger", "==", "self", "@parent", ".", "set_link", "(", "'@larger'", ",", "node", ")", "else", "PEROBS", ".", "log", ".", "fatal", "\"Cannot relink unknown child node with address \"", "+", "\"#{node.node_address} from #{parent.to_s}\"", "end", "else", "if", "node", "@tree", ".", "set_root", "(", "node", ")", "node", ".", "parent", "=", "nil", "else", "set_size_and_address", "(", "0", ",", "0", ")", "end", "end", "end" ]
Replace the link in the parent node of the current node that points to the current node with the given node. @param node [SpaceTreeNode]
[ "Replace", "the", "link", "in", "the", "parent", "node", "of", "the", "current", "node", "that", "points", "to", "the", "current", "node", "with", "the", "given", "node", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L382-L402
4,278
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.to_a
def to_a ary = [] each do |node, mode, stack| if mode == :on_enter ary << [ node.blob_address, node.size ] end end ary end
ruby
def to_a ary = [] each do |node, mode, stack| if mode == :on_enter ary << [ node.blob_address, node.size ] end end ary end
[ "def", "to_a", "ary", "=", "[", "]", "each", "do", "|", "node", ",", "mode", ",", "stack", "|", "if", "mode", "==", ":on_enter", "ary", "<<", "[", "node", ".", "blob_address", ",", "node", ".", "size", "]", "end", "end", "ary", "end" ]
Compare this node to another node. @return [Boolean] true if node address is identical, false otherwise Collects address and size touples of all nodes in the tree with a depth-first strategy and stores them in an Array. @return [Array] Array with [ address, size ] touples.
[ "Compare", "this", "node", "to", "another", "node", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L467-L477
4,279
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.check
def check(flat_file, count) node_counter = 0 max_depth = 0 @tree.progressmeter.start('Checking space list entries', count) do |pm| each do |node, mode, stack| max_depth = stack.size if stack.size > max_depth case mode when :smaller if node.smaller return false unless node.check_node_link('smaller', stack) smaller_node = node.smaller if smaller_node.size >= node.size PEROBS.log.error "Smaller SpaceTreeNode size " + "(#{smaller_node}) is not smaller than #{node}" return false end end when :equal if node.equal return false unless node.check_node_link('equal', stack) equal_node = node.equal if equal_node.smaller || equal_node.larger PEROBS.log.error "Equal node #{equal_node} must not have " + "smaller/larger childs" return false end if node.size != equal_node.size PEROBS.log.error "Equal SpaceTreeNode size (#{equal_node}) " + "is not equal parent node #{node}" return false end end when :larger if node.larger return false unless node.check_node_link('larger', stack) larger_node = node.larger if larger_node.size <= node.size PEROBS.log.error "Larger SpaceTreeNode size " + "(#{larger_node}) is not larger than #{node}" return false end end when :on_exit if flat_file && !flat_file.has_space?(node.blob_address, node.size) PEROBS.log.error "SpaceTreeNode has space at offset " + "#{node.blob_address} of size #{node.size} that isn't " + "available in the FlatFile." return false end pm.update(node_counter += 1) end end end PEROBS.log.debug "#{node_counter} SpaceTree nodes checked" PEROBS.log.debug "Maximum tree depth is #{max_depth}" return true end
ruby
def check(flat_file, count) node_counter = 0 max_depth = 0 @tree.progressmeter.start('Checking space list entries', count) do |pm| each do |node, mode, stack| max_depth = stack.size if stack.size > max_depth case mode when :smaller if node.smaller return false unless node.check_node_link('smaller', stack) smaller_node = node.smaller if smaller_node.size >= node.size PEROBS.log.error "Smaller SpaceTreeNode size " + "(#{smaller_node}) is not smaller than #{node}" return false end end when :equal if node.equal return false unless node.check_node_link('equal', stack) equal_node = node.equal if equal_node.smaller || equal_node.larger PEROBS.log.error "Equal node #{equal_node} must not have " + "smaller/larger childs" return false end if node.size != equal_node.size PEROBS.log.error "Equal SpaceTreeNode size (#{equal_node}) " + "is not equal parent node #{node}" return false end end when :larger if node.larger return false unless node.check_node_link('larger', stack) larger_node = node.larger if larger_node.size <= node.size PEROBS.log.error "Larger SpaceTreeNode size " + "(#{larger_node}) is not larger than #{node}" return false end end when :on_exit if flat_file && !flat_file.has_space?(node.blob_address, node.size) PEROBS.log.error "SpaceTreeNode has space at offset " + "#{node.blob_address} of size #{node.size} that isn't " + "available in the FlatFile." return false end pm.update(node_counter += 1) end end end PEROBS.log.debug "#{node_counter} SpaceTree nodes checked" PEROBS.log.debug "Maximum tree depth is #{max_depth}" return true end
[ "def", "check", "(", "flat_file", ",", "count", ")", "node_counter", "=", "0", "max_depth", "=", "0", "@tree", ".", "progressmeter", ".", "start", "(", "'Checking space list entries'", ",", "count", ")", "do", "|", "pm", "|", "each", "do", "|", "node", ",", "mode", ",", "stack", "|", "max_depth", "=", "stack", ".", "size", "if", "stack", ".", "size", ">", "max_depth", "case", "mode", "when", ":smaller", "if", "node", ".", "smaller", "return", "false", "unless", "node", ".", "check_node_link", "(", "'smaller'", ",", "stack", ")", "smaller_node", "=", "node", ".", "smaller", "if", "smaller_node", ".", "size", ">=", "node", ".", "size", "PEROBS", ".", "log", ".", "error", "\"Smaller SpaceTreeNode size \"", "+", "\"(#{smaller_node}) is not smaller than #{node}\"", "return", "false", "end", "end", "when", ":equal", "if", "node", ".", "equal", "return", "false", "unless", "node", ".", "check_node_link", "(", "'equal'", ",", "stack", ")", "equal_node", "=", "node", ".", "equal", "if", "equal_node", ".", "smaller", "||", "equal_node", ".", "larger", "PEROBS", ".", "log", ".", "error", "\"Equal node #{equal_node} must not have \"", "+", "\"smaller/larger childs\"", "return", "false", "end", "if", "node", ".", "size", "!=", "equal_node", ".", "size", "PEROBS", ".", "log", ".", "error", "\"Equal SpaceTreeNode size (#{equal_node}) \"", "+", "\"is not equal parent node #{node}\"", "return", "false", "end", "end", "when", ":larger", "if", "node", ".", "larger", "return", "false", "unless", "node", ".", "check_node_link", "(", "'larger'", ",", "stack", ")", "larger_node", "=", "node", ".", "larger", "if", "larger_node", ".", "size", "<=", "node", ".", "size", "PEROBS", ".", "log", ".", "error", "\"Larger SpaceTreeNode size \"", "+", "\"(#{larger_node}) is not larger than #{node}\"", "return", "false", "end", "end", "when", ":on_exit", "if", "flat_file", "&&", "!", "flat_file", ".", "has_space?", "(", "node", ".", "blob_address", ",", "node", ".", "size", ")", "PEROBS", ".", "log", ".", "error", "\"SpaceTreeNode has space at offset \"", "+", "\"#{node.blob_address} of size #{node.size} that isn't \"", "+", "\"available in the FlatFile.\"", "return", "false", "end", "pm", ".", "update", "(", "node_counter", "+=", "1", ")", "end", "end", "end", "PEROBS", ".", "log", ".", "debug", "\"#{node_counter} SpaceTree nodes checked\"", "PEROBS", ".", "log", ".", "debug", "\"Maximum tree depth is #{max_depth}\"", "return", "true", "end" ]
Check this node and all sub nodes for possible structural or logical errors. @param flat_file [FlatFile] If given, check that the space is also present in the given flat file. @param count [Integer] The total number of entries in the tree @return [false,true] True if OK, false otherwise
[ "Check", "this", "node", "and", "all", "sub", "nodes", "for", "possible", "structural", "or", "logical", "errors", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L523-L586
4,280
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.check_node_link
def check_node_link(link, stack) if (node = instance_variable_get('@' + link)) # Node links must only be of class SpaceTreeNodeLink unless node.nil? || node.is_a?(SpaceTreeNodeLink) PEROBS.log.error "Node link #{link} of node #{to_s} " + "is of class #{node.class}" return false end # Link must not point back to self. if node == self PEROBS.log.error "#{link} address of node " + "#{node.to_s} points to self #{to_s}" return false end # Link must not point to any of the parent nodes. if stack.include?(node) PEROBS.log.error "#{link} address of node #{to_s} " + "points to parent node #{node}" return false end # Parent link of node must point back to self. if node.parent != self PEROBS.log.error "@#{link} node #{node.to_s} does not have parent " + "link pointing " + "to parent node #{to_s}. Pointing at " + "#{node.parent.nil? ? 'nil' : node.parent.to_s} instead." return false end end true end
ruby
def check_node_link(link, stack) if (node = instance_variable_get('@' + link)) # Node links must only be of class SpaceTreeNodeLink unless node.nil? || node.is_a?(SpaceTreeNodeLink) PEROBS.log.error "Node link #{link} of node #{to_s} " + "is of class #{node.class}" return false end # Link must not point back to self. if node == self PEROBS.log.error "#{link} address of node " + "#{node.to_s} points to self #{to_s}" return false end # Link must not point to any of the parent nodes. if stack.include?(node) PEROBS.log.error "#{link} address of node #{to_s} " + "points to parent node #{node}" return false end # Parent link of node must point back to self. if node.parent != self PEROBS.log.error "@#{link} node #{node.to_s} does not have parent " + "link pointing " + "to parent node #{to_s}. Pointing at " + "#{node.parent.nil? ? 'nil' : node.parent.to_s} instead." return false end end true end
[ "def", "check_node_link", "(", "link", ",", "stack", ")", "if", "(", "node", "=", "instance_variable_get", "(", "'@'", "+", "link", ")", ")", "# Node links must only be of class SpaceTreeNodeLink", "unless", "node", ".", "nil?", "||", "node", ".", "is_a?", "(", "SpaceTreeNodeLink", ")", "PEROBS", ".", "log", ".", "error", "\"Node link #{link} of node #{to_s} \"", "+", "\"is of class #{node.class}\"", "return", "false", "end", "# Link must not point back to self.", "if", "node", "==", "self", "PEROBS", ".", "log", ".", "error", "\"#{link} address of node \"", "+", "\"#{node.to_s} points to self #{to_s}\"", "return", "false", "end", "# Link must not point to any of the parent nodes.", "if", "stack", ".", "include?", "(", "node", ")", "PEROBS", ".", "log", ".", "error", "\"#{link} address of node #{to_s} \"", "+", "\"points to parent node #{node}\"", "return", "false", "end", "# Parent link of node must point back to self.", "if", "node", ".", "parent", "!=", "self", "PEROBS", ".", "log", ".", "error", "\"@#{link} node #{node.to_s} does not have parent \"", "+", "\"link pointing \"", "+", "\"to parent node #{to_s}. Pointing at \"", "+", "\"#{node.parent.nil? ? 'nil' : node.parent.to_s} instead.\"", "return", "false", "end", "end", "true", "end" ]
Check the integrity of the given sub-node link and the parent link pointing back to this node. @param link [String] 'smaller', 'equal' or 'larger' @param stack [Array] List of parent nodes [ address, mode ] touples @return [Boolean] true of OK, false otherwise
[ "Check", "the", "integrity", "of", "the", "given", "sub", "-", "node", "link", "and", "the", "parent", "link", "pointing", "back", "to", "this", "node", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L593-L629
4,281
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.to_tree_s
def to_tree_s str = '' each do |node, mode, stack| if mode == :on_enter begin branch_mark = node.parent.nil? ? '' : node.parent.smaller == node ? '<' : node.parent.equal == node ? '=' : node.parent.larger == node ? '>' : '@' str += "#{node.text_tree_prefix}#{branch_mark}-" + "#{node.smaller || node.equal || node.larger ? 'v-' : '--'}" + "#{node.to_s}\n" rescue str += "#{node.text_tree_prefix}- @@@@@@@@@@\n" end end end str end
ruby
def to_tree_s str = '' each do |node, mode, stack| if mode == :on_enter begin branch_mark = node.parent.nil? ? '' : node.parent.smaller == node ? '<' : node.parent.equal == node ? '=' : node.parent.larger == node ? '>' : '@' str += "#{node.text_tree_prefix}#{branch_mark}-" + "#{node.smaller || node.equal || node.larger ? 'v-' : '--'}" + "#{node.to_s}\n" rescue str += "#{node.text_tree_prefix}- @@@@@@@@@@\n" end end end str end
[ "def", "to_tree_s", "str", "=", "''", "each", "do", "|", "node", ",", "mode", ",", "stack", "|", "if", "mode", "==", ":on_enter", "begin", "branch_mark", "=", "node", ".", "parent", ".", "nil?", "?", "''", ":", "node", ".", "parent", ".", "smaller", "==", "node", "?", "'<'", ":", "node", ".", "parent", ".", "equal", "==", "node", "?", "'='", ":", "node", ".", "parent", ".", "larger", "==", "node", "?", "'>'", ":", "'@'", "str", "+=", "\"#{node.text_tree_prefix}#{branch_mark}-\"", "+", "\"#{node.smaller || node.equal || node.larger ? 'v-' : '--'}\"", "+", "\"#{node.to_s}\\n\"", "rescue", "str", "+=", "\"#{node.text_tree_prefix}- @@@@@@@@@@\\n\"", "end", "end", "end", "str", "end" ]
Convert the node and all child nodes into a tree like text form. @return [String]
[ "Convert", "the", "node", "and", "all", "child", "nodes", "into", "a", "tree", "like", "text", "form", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L633-L654
4,282
scrapper/perobs
lib/perobs/SpaceTreeNode.rb
PEROBS.SpaceTreeNode.text_tree_prefix
def text_tree_prefix if (node = @parent) str = '+' else # Prefix start for root node line str = 'o' end while node last_child = false if node.parent if node.parent.smaller == node last_child = node.parent.equal.nil? && node.parent.larger.nil? elsif node.parent.equal == node last_child = node.parent.larger.nil? elsif node.parent.larger == node last_child = true end else # Padding for the root node str = ' ' + str break end str = (last_child ? ' ' : '| ') + str node = node.parent end str end
ruby
def text_tree_prefix if (node = @parent) str = '+' else # Prefix start for root node line str = 'o' end while node last_child = false if node.parent if node.parent.smaller == node last_child = node.parent.equal.nil? && node.parent.larger.nil? elsif node.parent.equal == node last_child = node.parent.larger.nil? elsif node.parent.larger == node last_child = true end else # Padding for the root node str = ' ' + str break end str = (last_child ? ' ' : '| ') + str node = node.parent end str end
[ "def", "text_tree_prefix", "if", "(", "node", "=", "@parent", ")", "str", "=", "'+'", "else", "# Prefix start for root node line", "str", "=", "'o'", "end", "while", "node", "last_child", "=", "false", "if", "node", ".", "parent", "if", "node", ".", "parent", ".", "smaller", "==", "node", "last_child", "=", "node", ".", "parent", ".", "equal", ".", "nil?", "&&", "node", ".", "parent", ".", "larger", ".", "nil?", "elsif", "node", ".", "parent", ".", "equal", "==", "node", "last_child", "=", "node", ".", "parent", ".", "larger", ".", "nil?", "elsif", "node", ".", "parent", ".", "larger", "==", "node", "last_child", "=", "true", "end", "else", "# Padding for the root node", "str", "=", "' '", "+", "str", "break", "end", "str", "=", "(", "last_child", "?", "' '", ":", "'| '", ")", "+", "str", "node", "=", "node", ".", "parent", "end", "str", "end" ]
The indentation and arch routing for the text tree. @return [String]
[ "The", "indentation", "and", "arch", "routing", "for", "the", "text", "tree", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/SpaceTreeNode.rb#L658-L687
4,283
scrapper/perobs
lib/perobs/PersistentObjectCacheLine.rb
PEROBS.PersistentObjectCacheLine.flush
def flush(now) if now || @entries.length > WATERMARK @entries.each do |e| if e.modified e.obj.save e.modified = false end end # Delete all but the first WATERMARK entry. @entries = @entries[0..WATERMARK - 1] if @entries.length > WATERMARK end end
ruby
def flush(now) if now || @entries.length > WATERMARK @entries.each do |e| if e.modified e.obj.save e.modified = false end end # Delete all but the first WATERMARK entry. @entries = @entries[0..WATERMARK - 1] if @entries.length > WATERMARK end end
[ "def", "flush", "(", "now", ")", "if", "now", "||", "@entries", ".", "length", ">", "WATERMARK", "@entries", ".", "each", "do", "|", "e", "|", "if", "e", ".", "modified", "e", ".", "obj", ".", "save", "e", ".", "modified", "=", "false", "end", "end", "# Delete all but the first WATERMARK entry.", "@entries", "=", "@entries", "[", "0", "..", "WATERMARK", "-", "1", "]", "if", "@entries", ".", "length", ">", "WATERMARK", "end", "end" ]
Save all modified entries and delete all but the most recently added.
[ "Save", "all", "modified", "entries", "and", "delete", "all", "but", "the", "most", "recently", "added", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/PersistentObjectCacheLine.rb#L82-L94
4,284
Absolight/epp-client
lib/epp-client/contact.rb
EPPClient.Contact.contact_check
def contact_check(*contacts) contacts.flatten! response = send_request(contact_check_xml(*contacts)) get_result(:xml => response, :callback => :contact_check_process) end
ruby
def contact_check(*contacts) contacts.flatten! response = send_request(contact_check_xml(*contacts)) get_result(:xml => response, :callback => :contact_check_process) end
[ "def", "contact_check", "(", "*", "contacts", ")", "contacts", ".", "flatten!", "response", "=", "send_request", "(", "contact_check_xml", "(", "contacts", ")", ")", "get_result", "(", ":xml", "=>", "response", ",", ":callback", "=>", ":contact_check_process", ")", "end" ]
Check the availability of contacts takes list of contacts as arguments returns an array of hashes containing three fields : [<tt>:id</tt>] the contact id [<tt>:avail</tt>] wether the contact id can be provisionned. [<tt>:reason</tt>] the server-specific text to help explain why the object cannot be provisioned.
[ "Check", "the", "availability", "of", "contacts" ]
c0025daee5e7087f60b654595a8e7d92e966c54e
https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/contact.rb#L31-L36
4,285
Absolight/epp-client
lib/epp-client/contact.rb
EPPClient.Contact.contact_info
def contact_info(args) args = { :id => args } if args.is_a?(String) response = send_request(contact_info_xml(args)) get_result(:xml => response, :callback => :contact_info_process) end
ruby
def contact_info(args) args = { :id => args } if args.is_a?(String) response = send_request(contact_info_xml(args)) get_result(:xml => response, :callback => :contact_info_process) end
[ "def", "contact_info", "(", "args", ")", "args", "=", "{", ":id", "=>", "args", "}", "if", "args", ".", "is_a?", "(", "String", ")", "response", "=", "send_request", "(", "contact_info_xml", "(", "args", ")", ")", "get_result", "(", ":xml", "=>", "response", ",", ":callback", "=>", ":contact_info_process", ")", "end" ]
Returns the informations about a contact Takes either a unique argument, either a string, representing the contact id or a hash with the following keys : [<tt>:id</tt>] the contact id, and optionnaly [<tt>:authInfo</tt>] an optional authentication information. Returned is a hash mapping as closely as possible the result expected from the command as per Section 3.1.2 of RFC 5733 : [<tt>:id</tt>] the server-unique identifier of the contact object. Most of the time, the nic handle. [<tt>:roid</tt>] the Repository Object IDentifier assigned to the contact object when the object was created. [<tt>:status</tt>] the status of the contact object. [<tt>:postalInfo</tt>] a hash containing one or two keys, +loc+ and +int+ representing the localized and internationalized version of the postal address information. The value is a hash with the following keys : [<tt>:name</tt>] the name of the individual or role represented by the contact. [<tt>:org</tt>] the name of the organization with which the contact is affiliated. [<tt>:addr</tt>] a hash with the following keys : [<tt>:street</tt>] an array that contains the contact's street address. [<tt>:city</tt>] the contact's city. [<tt>:sp</tt>] the contact's state or province. [<tt>:pc</tt>] the contact's postal code. [<tt>:cc</tt>] the contact's country code. [<tt>:voice</tt>] the contact's optional voice telephone number. [<tt>:fax</tt>] the contact's optional facsimile telephone number. [<tt>:email</tt>] the contact's email address. [<tt>:clID</tt>] the identifier of the sponsoring client. [<tt>:crID</tt>] the identifier of the client that created the contact object. [<tt>:crDate</tt>] the date and time of contact-object creation. [<tt>:upID</tt>] the optional identifier of the client that last updated the contact object. [<tt>:upDate</tt>] the optional date and time of the most recent contact-object modification. [<tt>:trDate</tt>] the optional date and time of the most recent successful contact-object transfer. [<tt>:authInfo</tt>] authorization information associated with the contact object. [<tt>:disclose</tt>] an optional array that identifies elements that require exceptional server-operator handling to allow or restrict disclosure to third parties. See {section 2.9 of RFC 5733}[http://tools.ietf.org/html/rfc5733#section-2.9] for details.
[ "Returns", "the", "informations", "about", "a", "contact" ]
c0025daee5e7087f60b654595a8e7d92e966c54e
https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/contact.rb#L122-L127
4,286
mreq/wmctile
lib/wmctile/window.rb
Wmctile.Window.find_window
def find_window(current_workspace_only = false) @matching_windows = Wmctile.window_list.grep(@regexp_string) filter_out_workspaces if current_workspace_only if @matching_windows.count > 1 filter_more_matching_windows elsif @matching_windows.count == 1 @matching_line = @matching_windows[0] else fail Errors::WindowNotFound, @window_string end extract_matching_line_information end
ruby
def find_window(current_workspace_only = false) @matching_windows = Wmctile.window_list.grep(@regexp_string) filter_out_workspaces if current_workspace_only if @matching_windows.count > 1 filter_more_matching_windows elsif @matching_windows.count == 1 @matching_line = @matching_windows[0] else fail Errors::WindowNotFound, @window_string end extract_matching_line_information end
[ "def", "find_window", "(", "current_workspace_only", "=", "false", ")", "@matching_windows", "=", "Wmctile", ".", "window_list", ".", "grep", "(", "@regexp_string", ")", "filter_out_workspaces", "if", "current_workspace_only", "if", "@matching_windows", ".", "count", ">", "1", "filter_more_matching_windows", "elsif", "@matching_windows", ".", "count", "==", "1", "@matching_line", "=", "@matching_windows", "[", "0", "]", "else", "fail", "Errors", "::", "WindowNotFound", ",", "@window_string", "end", "extract_matching_line_information", "end" ]
Window init function. Tries to find an id. @param [Hash] arguments command line options @param [String] window_string command line string given Filters down the window_list to @matching_windows. @param [Boolean] current_workspace_only Should only the current workspace be used? @return [void]
[ "Window", "init", "function", ".", "Tries", "to", "find", "an", "id", "." ]
a41af5afa310b09c8ba1bd45a134b9b2a87d1a35
https://github.com/mreq/wmctile/blob/a41af5afa310b09c8ba1bd45a134b9b2a87d1a35/lib/wmctile/window.rb#L26-L37
4,287
xinminlabs/synvert-core
lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
Synvert::Core.Rewriter::ReplaceErbStmtWithExprAction.begin_pos
def begin_pos node_begin_pos = @node.loc.expression.begin_pos while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' ' end node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1 end
ruby
def begin_pos node_begin_pos = @node.loc.expression.begin_pos while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' ' end node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1 end
[ "def", "begin_pos", "node_begin_pos", "=", "@node", ".", "loc", ".", "expression", ".", "begin_pos", "while", "@node", ".", "loc", ".", "expression", ".", "source_buffer", ".", "source", "[", "node_begin_pos", "-=", "1", "]", "==", "' '", "end", "node_begin_pos", "-", "Engine", "::", "ERUBY_STMT_SPLITTER", ".", "length", "+", "1", "end" ]
Begin position of code to replace. @return [Integer] begin position.
[ "Begin", "position", "of", "code", "to", "replace", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb#L14-L19
4,288
xinminlabs/synvert-core
lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
Synvert::Core.Rewriter::ReplaceErbStmtWithExprAction.end_pos
def end_pos node_begin_pos = @node.loc.expression.begin_pos node_begin_pos += @node.loc.expression.source.index "do" while @node.loc.expression.source_buffer.source[node_begin_pos += 1] != '@' end node_begin_pos end
ruby
def end_pos node_begin_pos = @node.loc.expression.begin_pos node_begin_pos += @node.loc.expression.source.index "do" while @node.loc.expression.source_buffer.source[node_begin_pos += 1] != '@' end node_begin_pos end
[ "def", "end_pos", "node_begin_pos", "=", "@node", ".", "loc", ".", "expression", ".", "begin_pos", "node_begin_pos", "+=", "@node", ".", "loc", ".", "expression", ".", "source", ".", "index", "\"do\"", "while", "@node", ".", "loc", ".", "expression", ".", "source_buffer", ".", "source", "[", "node_begin_pos", "+=", "1", "]", "!=", "'@'", "end", "node_begin_pos", "end" ]
End position of code to replace. @return [Integer] end position.
[ "End", "position", "of", "code", "to", "replace", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb#L24-L30
4,289
xinminlabs/synvert-core
lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
Synvert::Core.Rewriter::ReplaceErbStmtWithExprAction.rewritten_code
def rewritten_code @node.loc.expression.source_buffer.source[begin_pos...end_pos].sub(Engine::ERUBY_STMT_SPLITTER, "@output_buffer.append= ") .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER) end
ruby
def rewritten_code @node.loc.expression.source_buffer.source[begin_pos...end_pos].sub(Engine::ERUBY_STMT_SPLITTER, "@output_buffer.append= ") .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER) end
[ "def", "rewritten_code", "@node", ".", "loc", ".", "expression", ".", "source_buffer", ".", "source", "[", "begin_pos", "...", "end_pos", "]", ".", "sub", "(", "Engine", "::", "ERUBY_STMT_SPLITTER", ",", "\"@output_buffer.append= \"", ")", ".", "sub", "(", "Engine", "::", "ERUBY_STMT_SPLITTER", ",", "Engine", "::", "ERUBY_EXPR_SPLITTER", ")", "end" ]
The rewritten erb expr code. @return [String] rewritten code.
[ "The", "rewritten", "erb", "expr", "code", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb#L35-L38
4,290
jeffnyman/tapestry
lib/tapestry/factory.rb
Tapestry.Factory.verify_page
def verify_page(context) return if context.url_match_attribute.nil? return if context.has_correct_url? raise Tapestry::Errors::PageURLFromFactoryNotVerified end
ruby
def verify_page(context) return if context.url_match_attribute.nil? return if context.has_correct_url? raise Tapestry::Errors::PageURLFromFactoryNotVerified end
[ "def", "verify_page", "(", "context", ")", "return", "if", "context", ".", "url_match_attribute", ".", "nil?", "return", "if", "context", ".", "has_correct_url?", "raise", "Tapestry", "::", "Errors", "::", "PageURLFromFactoryNotVerified", "end" ]
This method is used to provide a means for checking if a page has been navigated to correctly as part of a context. This is useful because the context signature should remain highly readable, and checks for whether a given page has been reached would make the context definition look sloppy.
[ "This", "method", "is", "used", "to", "provide", "a", "means", "for", "checking", "if", "a", "page", "has", "been", "navigated", "to", "correctly", "as", "part", "of", "a", "context", ".", "This", "is", "useful", "because", "the", "context", "signature", "should", "remain", "highly", "readable", "and", "checks", "for", "whether", "a", "given", "page", "has", "been", "reached", "would", "make", "the", "context", "definition", "look", "sloppy", "." ]
da28652dd6de71e415cd2c01afd89f641938a05b
https://github.com/jeffnyman/tapestry/blob/da28652dd6de71e415cd2c01afd89f641938a05b/lib/tapestry/factory.rb#L86-L90
4,291
scrapper/perobs
lib/perobs/Cache.rb
PEROBS.Cache.cache_read
def cache_read(obj) # This is just a safety check. It can probably be disabled in the future # to increase performance. if obj.respond_to?(:is_poxreference?) # If this condition triggers, we have a bug in the library. PEROBS.log.fatal "POXReference objects should never be cached" end @reads[index(obj)] = obj end
ruby
def cache_read(obj) # This is just a safety check. It can probably be disabled in the future # to increase performance. if obj.respond_to?(:is_poxreference?) # If this condition triggers, we have a bug in the library. PEROBS.log.fatal "POXReference objects should never be cached" end @reads[index(obj)] = obj end
[ "def", "cache_read", "(", "obj", ")", "# This is just a safety check. It can probably be disabled in the future", "# to increase performance.", "if", "obj", ".", "respond_to?", "(", ":is_poxreference?", ")", "# If this condition triggers, we have a bug in the library.", "PEROBS", ".", "log", ".", "fatal", "\"POXReference objects should never be cached\"", "end", "@reads", "[", "index", "(", "obj", ")", "]", "=", "obj", "end" ]
Create a new Cache object. @param bits [Integer] Number of bits for the cache index. This parameter heavilty affects the performance and memory consumption of the cache. Add an PEROBS::Object to the read cache. @param obj [PEROBS::ObjectBase]
[ "Create", "a", "new", "Cache", "object", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Cache.rb#L54-L62
4,292
scrapper/perobs
lib/perobs/Cache.rb
PEROBS.Cache.begin_transaction
def begin_transaction if @transaction_stack.empty? # The new transaction is the top-level transaction. Flush the write # buffer to save the current state of all objects. flush else # Save a copy of all objects that were modified during the enclosing # transaction. @transaction_stack.last.each do |id| @transaction_objects[id]._stash(@transaction_stack.length - 1) end end # Push a transaction buffer onto the transaction stack. This buffer will # hold a reference to all objects modified during this transaction. @transaction_stack.push(::Array.new) end
ruby
def begin_transaction if @transaction_stack.empty? # The new transaction is the top-level transaction. Flush the write # buffer to save the current state of all objects. flush else # Save a copy of all objects that were modified during the enclosing # transaction. @transaction_stack.last.each do |id| @transaction_objects[id]._stash(@transaction_stack.length - 1) end end # Push a transaction buffer onto the transaction stack. This buffer will # hold a reference to all objects modified during this transaction. @transaction_stack.push(::Array.new) end
[ "def", "begin_transaction", "if", "@transaction_stack", ".", "empty?", "# The new transaction is the top-level transaction. Flush the write", "# buffer to save the current state of all objects.", "flush", "else", "# Save a copy of all objects that were modified during the enclosing", "# transaction.", "@transaction_stack", ".", "last", ".", "each", "do", "|", "id", "|", "@transaction_objects", "[", "id", "]", ".", "_stash", "(", "@transaction_stack", ".", "length", "-", "1", ")", "end", "end", "# Push a transaction buffer onto the transaction stack. This buffer will", "# hold a reference to all objects modified during this transaction.", "@transaction_stack", ".", "push", "(", "::", "Array", ".", "new", ")", "end" ]
Tell the cache to start a new transaction. If no other transaction is active, the write cache is flushed before the transaction is started.
[ "Tell", "the", "cache", "to", "start", "a", "new", "transaction", ".", "If", "no", "other", "transaction", "is", "active", "the", "write", "cache", "is", "flushed", "before", "the", "transaction", "is", "started", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Cache.rb#L128-L143
4,293
scrapper/perobs
lib/perobs/Cache.rb
PEROBS.Cache.end_transaction
def end_transaction case @transaction_stack.length when 0 PEROBS.log.fatal 'No ongoing transaction to end' when 1 # All transactions completed successfully. Write all modified objects # into the backend storage. @transaction_stack.pop.each { |id| @transaction_objects[id]._sync } @transaction_objects = ::Hash.new else # A nested transaction completed successfully. We add the list of # modified objects to the list of the enclosing transaction. transactions = @transaction_stack.pop # Merge the two lists @transaction_stack.push(@transaction_stack.pop + transactions) # Ensure that each object is only included once in the list. @transaction_stack.last.uniq! end end
ruby
def end_transaction case @transaction_stack.length when 0 PEROBS.log.fatal 'No ongoing transaction to end' when 1 # All transactions completed successfully. Write all modified objects # into the backend storage. @transaction_stack.pop.each { |id| @transaction_objects[id]._sync } @transaction_objects = ::Hash.new else # A nested transaction completed successfully. We add the list of # modified objects to the list of the enclosing transaction. transactions = @transaction_stack.pop # Merge the two lists @transaction_stack.push(@transaction_stack.pop + transactions) # Ensure that each object is only included once in the list. @transaction_stack.last.uniq! end end
[ "def", "end_transaction", "case", "@transaction_stack", ".", "length", "when", "0", "PEROBS", ".", "log", ".", "fatal", "'No ongoing transaction to end'", "when", "1", "# All transactions completed successfully. Write all modified objects", "# into the backend storage.", "@transaction_stack", ".", "pop", ".", "each", "{", "|", "id", "|", "@transaction_objects", "[", "id", "]", ".", "_sync", "}", "@transaction_objects", "=", "::", "Hash", ".", "new", "else", "# A nested transaction completed successfully. We add the list of", "# modified objects to the list of the enclosing transaction.", "transactions", "=", "@transaction_stack", ".", "pop", "# Merge the two lists", "@transaction_stack", ".", "push", "(", "@transaction_stack", ".", "pop", "+", "transactions", ")", "# Ensure that each object is only included once in the list.", "@transaction_stack", ".", "last", ".", "uniq!", "end", "end" ]
Tell the cache to end the currently active transaction. All write operations of the current transaction will be synced to the storage back-end.
[ "Tell", "the", "cache", "to", "end", "the", "currently", "active", "transaction", ".", "All", "write", "operations", "of", "the", "current", "transaction", "will", "be", "synced", "to", "the", "storage", "back", "-", "end", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Cache.rb#L148-L166
4,294
scrapper/perobs
lib/perobs/Cache.rb
PEROBS.Cache.abort_transaction
def abort_transaction if @transaction_stack.empty? PEROBS.log.fatal 'No ongoing transaction to abort' end @transaction_stack.pop.each do |id| @transaction_objects[id]._restore(@transaction_stack.length) end end
ruby
def abort_transaction if @transaction_stack.empty? PEROBS.log.fatal 'No ongoing transaction to abort' end @transaction_stack.pop.each do |id| @transaction_objects[id]._restore(@transaction_stack.length) end end
[ "def", "abort_transaction", "if", "@transaction_stack", ".", "empty?", "PEROBS", ".", "log", ".", "fatal", "'No ongoing transaction to abort'", "end", "@transaction_stack", ".", "pop", ".", "each", "do", "|", "id", "|", "@transaction_objects", "[", "id", "]", ".", "_restore", "(", "@transaction_stack", ".", "length", ")", "end", "end" ]
Tell the cache to abort the currently active transaction. All modified objects will be restored from the storage back-end to their state before the transaction started.
[ "Tell", "the", "cache", "to", "abort", "the", "currently", "active", "transaction", ".", "All", "modified", "objects", "will", "be", "restored", "from", "the", "storage", "back", "-", "end", "to", "their", "state", "before", "the", "transaction", "started", "." ]
1c9327656912cf96683849f92d260546af856adf
https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Cache.rb#L171-L178
4,295
proglottis/glicko2
lib/glicko2/player.rb
Glicko2.Player.update_obj
def update_obj mean, sd = rating.to_glicko_rating @obj.rating = mean @obj.rating_deviation = sd @obj.volatility = volatility end
ruby
def update_obj mean, sd = rating.to_glicko_rating @obj.rating = mean @obj.rating_deviation = sd @obj.volatility = volatility end
[ "def", "update_obj", "mean", ",", "sd", "=", "rating", ".", "to_glicko_rating", "@obj", ".", "rating", "=", "mean", "@obj", ".", "rating_deviation", "=", "sd", "@obj", ".", "volatility", "=", "volatility", "end" ]
Update seed object with this player's values
[ "Update", "seed", "object", "with", "this", "player", "s", "values" ]
8ede9a758a1a35b2bc5e6d4706aad856ec8f7812
https://github.com/proglottis/glicko2/blob/8ede9a758a1a35b2bc5e6d4706aad856ec8f7812/lib/glicko2/player.rb#L22-L27
4,296
dirkholzapfel/abuelo
lib/abuelo/graph.rb
Abuelo.Graph.add_node
def add_node(node) raise Abuelo::Exceptions::NodeAlreadyExistsError if has_node?(node) @nodes[node.name] = node node.graph = self self end
ruby
def add_node(node) raise Abuelo::Exceptions::NodeAlreadyExistsError if has_node?(node) @nodes[node.name] = node node.graph = self self end
[ "def", "add_node", "(", "node", ")", "raise", "Abuelo", "::", "Exceptions", "::", "NodeAlreadyExistsError", "if", "has_node?", "(", "node", ")", "@nodes", "[", "node", ".", "name", "]", "=", "node", "node", ".", "graph", "=", "self", "self", "end" ]
Adds a node to the graph. @param [Abuelo::Node] node to add @return [Abuelo::Graph] the graph @raise [Abuelo::Exceptions::NodeAlreadyExistsError] if the node is already contained in the graph
[ "Adds", "a", "node", "to", "the", "graph", "." ]
3395b4ea386a12dfe747228eaf400029bcc1143a
https://github.com/dirkholzapfel/abuelo/blob/3395b4ea386a12dfe747228eaf400029bcc1143a/lib/abuelo/graph.rb#L80-L87
4,297
dirkholzapfel/abuelo
lib/abuelo/graph.rb
Abuelo.Graph.add_edge
def add_edge(edge, opts = {}) raise Abuelo::Exceptions::EdgeAlreadyExistsError if has_edge?(edge) @edges[edge.node_1] ||= {} @edges[edge.node_1][edge.node_2] = edge if undirected? && !opts[:symmetric] add_edge(edge.symmetric, symmetric: true) end self end
ruby
def add_edge(edge, opts = {}) raise Abuelo::Exceptions::EdgeAlreadyExistsError if has_edge?(edge) @edges[edge.node_1] ||= {} @edges[edge.node_1][edge.node_2] = edge if undirected? && !opts[:symmetric] add_edge(edge.symmetric, symmetric: true) end self end
[ "def", "add_edge", "(", "edge", ",", "opts", "=", "{", "}", ")", "raise", "Abuelo", "::", "Exceptions", "::", "EdgeAlreadyExistsError", "if", "has_edge?", "(", "edge", ")", "@edges", "[", "edge", ".", "node_1", "]", "||=", "{", "}", "@edges", "[", "edge", ".", "node_1", "]", "[", "edge", ".", "node_2", "]", "=", "edge", "if", "undirected?", "&&", "!", "opts", "[", ":symmetric", "]", "add_edge", "(", "edge", ".", "symmetric", ",", "symmetric", ":", "true", ")", "end", "self", "end" ]
Adds an edge to the graph. Auto-adds the symmetric counterpart if graph is undirected. @param [Abuelo::Edge] edge to add @return [Abuelo::Graph] the graph @raise [Abuelo::Exceptions::EdgeAlreadyExistsError] if the edge is already contained in the graph
[ "Adds", "an", "edge", "to", "the", "graph", ".", "Auto", "-", "adds", "the", "symmetric", "counterpart", "if", "graph", "is", "undirected", "." ]
3395b4ea386a12dfe747228eaf400029bcc1143a
https://github.com/dirkholzapfel/abuelo/blob/3395b4ea386a12dfe747228eaf400029bcc1143a/lib/abuelo/graph.rb#L154-L165
4,298
xinminlabs/synvert-core
lib/synvert/core/rewriter/instance.rb
Synvert::Core.Rewriter::Instance.process
def process file_pattern = File.join(Configuration.instance.get(:path), @file_pattern) Dir.glob(file_pattern).each do |file_path| unless Configuration.instance.get(:skip_files).include? file_path begin conflict_actions = [] source = self.class.file_source(file_path) ast = self.class.file_ast(file_path) @current_file = file_path self.process_with_node ast do begin instance_eval &@block rescue NoMethodError puts @current_node.debug_info raise end end if @actions.length > 0 @actions.sort_by! { |action| action.send(@options[:sort_by]) } conflict_actions = get_conflict_actions @actions.reverse.each do |action| source[action.begin_pos...action.end_pos] = action.rewritten_code source = remove_code_or_whole_line(source, action.line) end @actions = [] self.class.write_file(file_path, source) end rescue Parser::SyntaxError puts "[Warn] file #{file_path} was not parsed correctly." # do nothing, iterate next file end while !conflict_actions.empty? end end end
ruby
def process file_pattern = File.join(Configuration.instance.get(:path), @file_pattern) Dir.glob(file_pattern).each do |file_path| unless Configuration.instance.get(:skip_files).include? file_path begin conflict_actions = [] source = self.class.file_source(file_path) ast = self.class.file_ast(file_path) @current_file = file_path self.process_with_node ast do begin instance_eval &@block rescue NoMethodError puts @current_node.debug_info raise end end if @actions.length > 0 @actions.sort_by! { |action| action.send(@options[:sort_by]) } conflict_actions = get_conflict_actions @actions.reverse.each do |action| source[action.begin_pos...action.end_pos] = action.rewritten_code source = remove_code_or_whole_line(source, action.line) end @actions = [] self.class.write_file(file_path, source) end rescue Parser::SyntaxError puts "[Warn] file #{file_path} was not parsed correctly." # do nothing, iterate next file end while !conflict_actions.empty? end end end
[ "def", "process", "file_pattern", "=", "File", ".", "join", "(", "Configuration", ".", "instance", ".", "get", "(", ":path", ")", ",", "@file_pattern", ")", "Dir", ".", "glob", "(", "file_pattern", ")", ".", "each", "do", "|", "file_path", "|", "unless", "Configuration", ".", "instance", ".", "get", "(", ":skip_files", ")", ".", "include?", "file_path", "begin", "conflict_actions", "=", "[", "]", "source", "=", "self", ".", "class", ".", "file_source", "(", "file_path", ")", "ast", "=", "self", ".", "class", ".", "file_ast", "(", "file_path", ")", "@current_file", "=", "file_path", "self", ".", "process_with_node", "ast", "do", "begin", "instance_eval", "@block", "rescue", "NoMethodError", "puts", "@current_node", ".", "debug_info", "raise", "end", "end", "if", "@actions", ".", "length", ">", "0", "@actions", ".", "sort_by!", "{", "|", "action", "|", "action", ".", "send", "(", "@options", "[", ":sort_by", "]", ")", "}", "conflict_actions", "=", "get_conflict_actions", "@actions", ".", "reverse", ".", "each", "do", "|", "action", "|", "source", "[", "action", ".", "begin_pos", "...", "action", ".", "end_pos", "]", "=", "action", ".", "rewritten_code", "source", "=", "remove_code_or_whole_line", "(", "source", ",", "action", ".", "line", ")", "end", "@actions", "=", "[", "]", "self", ".", "class", ".", "write_file", "(", "file_path", ",", "source", ")", "end", "rescue", "Parser", "::", "SyntaxError", "puts", "\"[Warn] file #{file_path} was not parsed correctly.\"", "# do nothing, iterate next file", "end", "while", "!", "conflict_actions", ".", "empty?", "end", "end", "end" ]
Initialize an instance. @param rewriter [Synvert::Core::Rewriter] @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb @param options [Hash] instance options, it includes :sort_by. @param block [Block] block code to find nodes, match conditions and rewrite code. @return [Synvert::Core::Rewriter::Instance] Process the instance. It finds all files, for each file, it executes the block code, gets all rewrite actions, and rewrite source code back to original file.
[ "Initialize", "an", "instance", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/instance.rb#L88-L125
4,299
xinminlabs/synvert-core
lib/synvert/core/rewriter/instance.rb
Synvert::Core.Rewriter::Instance.get_conflict_actions
def get_conflict_actions i = @actions.length - 1 j = i - 1 conflict_actions = [] return if i < 0 begin_pos = @actions[i].begin_pos while j > -1 if begin_pos <= @actions[j].end_pos conflict_actions << @actions.delete_at(j) else i = j begin_pos = @actions[i].begin_pos end j -= 1 end conflict_actions end
ruby
def get_conflict_actions i = @actions.length - 1 j = i - 1 conflict_actions = [] return if i < 0 begin_pos = @actions[i].begin_pos while j > -1 if begin_pos <= @actions[j].end_pos conflict_actions << @actions.delete_at(j) else i = j begin_pos = @actions[i].begin_pos end j -= 1 end conflict_actions end
[ "def", "get_conflict_actions", "i", "=", "@actions", ".", "length", "-", "1", "j", "=", "i", "-", "1", "conflict_actions", "=", "[", "]", "return", "if", "i", "<", "0", "begin_pos", "=", "@actions", "[", "i", "]", ".", "begin_pos", "while", "j", ">", "-", "1", "if", "begin_pos", "<=", "@actions", "[", "j", "]", ".", "end_pos", "conflict_actions", "<<", "@actions", ".", "delete_at", "(", "j", ")", "else", "i", "=", "j", "begin_pos", "=", "@actions", "[", "i", "]", ".", "begin_pos", "end", "j", "-=", "1", "end", "conflict_actions", "end" ]
It changes source code from bottom to top, and it can change source code twice at the same time, So if there is an overlap between two actions, it removes the conflict actions and operate them in the next loop.
[ "It", "changes", "source", "code", "from", "bottom", "to", "top", "and", "it", "can", "change", "source", "code", "twice", "at", "the", "same", "time", "So", "if", "there", "is", "an", "overlap", "between", "two", "actions", "it", "removes", "the", "conflict", "actions", "and", "operate", "them", "in", "the", "next", "loop", "." ]
a490bfd30eaec81002d10f8fb61b49138708e46c
https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter/instance.rb#L265-L282