input stringlengths 109 5.2k | output stringlengths 7 509 |
|---|---|
Summarize the following code: def perform_http_request #:nodoc:
request = Net::HTTP::Get.new(@uri.request_uri, @headers)
request.basic_auth(@username, @password) if @username || @password
http = instantiate_http
http.start do
http.request(request)
end
end | Perform an HTTP request and return the response |
Summarize the following code: def usb_open(vendor, product)
raise ArgumentError.new('vendor should be Fixnum') unless vendor.kind_of?(Fixnum)
raise ArgumentError.new('product should be Fixnum') unless product.kind_of?(Fixnum)
check_result(Ftdi.ftdi_usb_open(ctx, vendor, product))
end | Opens the first device with a given vendor and product ids . |
Summarize the following code: def usb_open_desc(vendor, product, description, serial)
raise ArgumentError.new('vendor should be Fixnum') unless vendor.kind_of?(Fixnum)
raise ArgumentError.new('product should be Fixnum') unless product.kind_of?(Fixnum)
check_result(Ftdi.ftdi_usb_open_desc(ctx, vendor... | Opens the first device with a given vendor and product ids description and serial . |
Summarize the following code: def usb_open_desc_index(vendor, product, description, serial, index)
raise ArgumentError.new('vendor should be Fixnum') unless vendor.kind_of?(Fixnum)
raise ArgumentError.new('product should be Fixnum') unless product.kind_of?(Fixnum)
raise ArgumentError.new('index shou... | Opens the index - th device with a given vendor and product ids description and serial . |
Summarize the following code: def baudrate=(new_baudrate)
raise ArgumentError.new('baudrate should be Fixnum') unless new_baudrate.kind_of?(Fixnum)
check_result(Ftdi.ftdi_set_baudrate(ctx, new_baudrate))
end | Sets the chip baud rate . |
Summarize the following code: def write_data_chunksize
p = FFI::MemoryPointer.new(:uint, 1)
check_result(Ftdi.ftdi_write_data_get_chunksize(ctx, p))
p.read_uint
end | Gets write buffer chunk size . |
Summarize the following code: def write_data(bytes)
bytes = bytes.pack('c*') if bytes.respond_to?(:pack)
size = bytes.respond_to?(:bytesize) ? bytes.bytesize : bytes.size
mem_buf = FFI::MemoryPointer.new(:char, size)
mem_buf.put_bytes(0, bytes)
bytes_written = Ftdi.ftdi_write_data(ctx, me... | Writes data . |
Summarize the following code: def read_data_chunksize
p = FFI::MemoryPointer.new(:uint, 1)
check_result(Ftdi.ftdi_read_data_get_chunksize(ctx, p))
p.read_uint
end | Gets read buffer chunk size . |
Summarize the following code: def read_data
chunksize = read_data_chunksize
p = FFI::MemoryPointer.new(:char, chunksize)
bytes_read = Ftdi.ftdi_read_data(ctx, p, chunksize)
check_result(bytes_read)
r = p.read_bytes(bytes_read)
r.force_encoding("ASCII-8BIT") if r.respond_to?(:force_e... | Reads data in chunks from the chip . Returns when at least one byte is available or when the latency timer has elapsed . Automatically strips the two modem status bytes transfered during every read . |
Summarize the following code: def read_pins
p = FFI::MemoryPointer.new(:uchar, 1)
check_result(Ftdi.ftdi_read_pins(ctx, p))
p.read_uchar
end | Directly read pin state circumventing the read buffer . Useful for bitbang mode . |
Summarize the following code: def to_g_marker_api2(marker_options = {}, options = {})
klass = if options[:short_class]
'GMarker'
else
'google.maps.Marker'
end
opts = Geos::Helper.camelize_keys(marker_options)
"new #{klass}(#{self.centroid.to_g_lat_lng(options)}, #{opts.to... | Returns a new GMarker at the centroid of the geometry . The options Hash works the same as the Google Maps API GMarkerOptions class does but allows for underscored Ruby - like options which are then converted to the appropriate camel - cased Javascript options . |
Summarize the following code: def to_g_polyline_api2(polyline_options = {}, options = {})
klass = if options[:short_class]
'GPolyline'
else
'google.maps.Polyline'
end
poly_opts = if polyline_options[:polyline_options]
Geos::Helper.camelize_keys(polyline_options[:polyline... | Returns a new GPolyline . Note that this GPolyline just uses whatever coordinates are found in the sequence in order so it might not make much sense at all . |
Summarize the following code: def to_g_polygon_api2(polygon_options = {}, options = {})
klass = if options[:short_class]
'GPolygon'
else
'google.maps.Polygon'
end
poly_opts = if polygon_options[:polygon_options]
Geos::Helper.camelize_keys(polygon_options[:polygon_options... | Returns a new GPolygon . Note that this GPolygon just uses whatever coordinates are found in the sequence in order so it might not make much sense at all . |
Summarize the following code: def to_bbox(long_or_short_names = :long)
case long_or_short_names
when :long
{
:north => self.north,
:east => self.east,
:south => self.south,
:west => self.west
}
when :short
{
... | Spits out a Hash containing the cardinal points that describe the Geometry s bbox . |
Summarize the following code: def to_georss(*args)
xml = Geos::Helper.xml_options(*args)[0]
xml.georss(:where) do
xml.gml(:Point) do
xml.gml(:pos, "#{self.lat} #{self.lng}")
end
end
end | Build some XmlMarkup for GeoRSS . You should include the appropriate georss and gml XML namespaces in your document . |
Summarize the following code: def to_g_marker_api3(marker_options = {}, options = {})
options = {
:escape => [],
:lat_lng_options => {}
}.merge(options)
opts = Geos::Helper.camelize_keys(marker_options)
opts[:position] = self.centroid.to_g_lat_lng(options[:lat_lng_options])
... | Returns a new Marker at the centroid of the geometry . The options Hash works the same as the Google Maps API MarkerOptions class does but allows for underscored Ruby - like options which are then converted to the appropriate camel - cased Javascript options . |
Summarize the following code: def to_g_polyline_api3(polyline_options = {}, options = {})
options = {
:escape => [],
:lat_lng_options => {}
}.merge(options)
opts = Geos::Helper.camelize_keys(polyline_options)
opts[:path] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).jo... | Returns a new Polyline . Note that this Polyline just uses whatever coordinates are found in the sequence in order so it might not make much sense at all . |
Summarize the following code: def to_georss(*args)
xml = Geos::Helper.xml_options(*args)[0]
xml.georss(:where) do
xml.gml(:LineString) do
xml.gml(:posList) do
xml << self.to_a.collect do |p|
"#{p[1]} #{p[0]}"
end.join(' ')
end
end
... | Build some XmlMarkup for GeoRSS GML . You should include the appropriate georss and gml XML namespaces in your document . |
Summarize the following code: def convert_to_price(price_str)
raise SolidusImportProducts::Exception::InvalidPrice unless price_str
punt = price_str.index('.')
coma = price_str.index(',')
if !coma.nil? && !punt.nil?
price_str.gsub!(punt < coma ? '.' : ',', '')
end
price_str.t... | Special process of prices because of locales and different decimal separator characters . We want to get a format with dot as decimal separator and without thousand separator |
Summarize the following code: def matches(regexp, word)
if regexp.respond_to?(:match?)
regexp.match?(word)
else
regexp.match(word)
end
end | match? was added in Ruby 2 . 4 this allows us to be backwards compatible with older Ruby versions |
Summarize the following code: def dump_points(cur_path = [])
points = [ self.exterior_ring.dump_points ]
self.interior_rings.each do |ring|
points.push(ring.dump_points)
end
cur_path.concat(points)
end | Dumps points similarly to the PostGIS ST_DumpPoints function . |
Summarize the following code: def generate_belongs_to_foreign_key_name(assoc)
source = assoc.source_table[0..7]
column = assoc.foreign_key_column[0..7]
destination = assoc.destination_table[0..7]
"fk_#{source}_#{column}_#{destination}_#{SecureRandom.hex}"
end | Limited to 64 characters |
Summarize the following code: def raw_exchange_rates
req = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
req.body = { lang: :en }.to_json
response = Net::HTTP.start(@uri.hostname, @uri.port) do |http|
http.request(req)
end
fail ResponseError, response.code unless ... | Send the request to URL and return the JSON response |
Summarize the following code: def validate_ipv4_addr(value)
ipaddr = IPAddr.new(value)
unless ipaddr.ipv4?
raise ValidationError, "IP address '#{value}' is not IPv4"
end
ipaddr
rescue ArgumentError => e
raise ValidationError, "invalid IPv4 address '#{value}' - #{e.message}"
... | Validate IPV4 using the standard ipaddr ruby module . |
Summarize the following code: def validate_ipv6_addr(value)
ipaddr = IPAddr.new(value)
unless ipaddr.ipv6?
raise ValidationError, "IP address '#{value}' is not IPv6"
end
ipaddr
rescue ArgumentError => e
raise ValidationError, "invalid IPv6 address '#{value}' - #{e.message}"
... | Validate that the given string _value_ describes a well - formed IPV6 network address using the standard ipaddr ruby module . |
Summarize the following code: def to_h(strict: false)
todo = @key_metadata.keys - @cache.keys
todo.each_with_object({}) do |key, hsh|
loaded_key = (strict ? load_key_strict(key) : load_key_lenient(key))
hsh[key] = loaded_key if exists_locally?(key)
end
end | Create an internal model with a reference to a public model . |
Summarize the following code: def exists_locally?(key_name)
return true if @cache.key?(key_name) || @writethrough.key?(key_name)
meta = ensure_metadata_exists(key_name)
@source.key?(meta.source_key)
end | Whether the key doesn t need to be lazily loaded . |
Summarize the following code: def write_attribute(key_name, new_value)
meta = ensure_metadata_exists(key_name)
@source.delete(meta.source_key)
@writethrough[key_name] = @cache[key_name] = new_value
end | Update an attribute . |
Summarize the following code: def delete_attribute(key_name)
key_name_sym = key_name.to_sym
meta = ensure_metadata_exists(key_name_sym)
@cache.delete(key_name)
@writethrough.delete(key_name)
@source.delete(meta.source_key)
nil
end | Delete an attribute |
Summarize the following code: def verify_required!
@key_metadata.required_properties.each do |key_name|
next if @source.key?(@key_metadata.get(key_name).source_key)
raise RequiredAttribute, "#{@parent} requires `#{key_name}`"
end
end | Verify that all the keys marked as required are present . |
Summarize the following code: def transform_value(value, transform)
case transform
when nil
value
when Proc
@parent.instance_exec(value, &transform)
when Symbol
value.public_send(transform)
end
end | Apply a transformation to a value . |
Summarize the following code: def response
response = Net::HTTP.get_response(@uri)
if response.is_a? Net::HTTPRedirection
response = Net::HTTP.get_response(URI.parse(response['location']))
end
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
response
end | Make a call to the |
Summarize the following code: def currencies(table_rows)
table_rows.lazy.map do |e|
e.css('img').map { |img| img.attribute('src').value }
end.force.flatten
end | Extract the currencies from the image components src attribute |
Summarize the following code: def add(key, meta)
@collection[key] = meta
if meta.required?
@required_properties << key
else
@required_properties.delete(key)
end
meta
end | Add a KeyMetadata to the store . |
Summarize the following code: def validate_constraints(value)
options.each do |option, arg|
if validator_class = Respect.validator_for(option)
validator_class.new(arg).validate(value)
end
end
end | Validate all the constraints listed in + options + to the given + value + . |
Summarize the following code: def validate(object)
sanitized_object = validate_type(object)
validate_constraints(sanitized_object) unless sanitized_object.nil? && allow_nil?
self.sanitized_object = sanitized_object
true
rescue ValidationError => e
# Reset sanitized object.
self.s... | Call + validate_type + with the given + object + apply the constraints and assign the sanitized object . |
Summarize the following code: def []=(name, schema)
case name
when Symbol, String, Regexp
if @properties.has_key?(name)
raise InvalidSchemaError, "property '#{name}' already defined"
end
@properties[name] = schema
else
raise InvalidSchemaError, "unsupported pr... | Set the given + schema + for the given property + name + . A name can be a Symbol a String or a Regexp . |
Summarize the following code: def []=(key, value)
case value
when String
string(key, equal_to: value.to_s)
else
any(key, equal_to: value.to_s)
end
end | Shortcut to say a schema + key + must be equal to a given + value + . When it does not recognize the value type it creates a any schema . |
Summarize the following code: def holiday?(arg)
date = to_date(arg)
holidays(start_date: date, end_date: date + 1.day, limit: 1).length > 0
end | whether arg is holiday |
Summarize the following code: def arrayize_arguments(args)
# Go through trailing arguments and suck them in if they don't seem
# to have an owner.
array = []
until args.empty? || args.first.match(/^-/)
array << args.shift
end
array
end | Turns trailing command line arguments into an array for an arrayed value |
Summarize the following code: def to_a
[
required,
short,
long,
desc,
default,
filter,
action,
cast,
valid,
validate
].compact
end | Returns Option converted to an array . |
Summarize the following code: def to_h
{
"required" => required,
"short" => short,
"long" => long,
"desc" => desc,
"default" => default,
"filter" => filter,
"action" => action,
"cast" => cast,
"valid" => valid,
"validate" => validate
... | Returns Option converted to a hash . |
Summarize the following code: def parse_options(argv = ARGV)
@config_file = File.join(Dir.getwd, 'config', "#{@name}.json")
OptionParser.new do |opts|
note = 'Define environment'
opts.on('-e', '--environment ENVIRONMENT', note) do |environment|
@environment = environment
e... | parse options from argument list |
Summarize the following code: def load!(args = {})
# for better rspec testing
@config_file = args[:config_file] if args[:config_file]
@environment = args[:environment] if args[:environment]
new_data = {}
begin
new_data = JSON.parse(File.read(@config_file), symbolize_names: true)
... | load configuration from file |
Summarize the following code: def keywords(limit = 20)
@keywords ||= {}
@keywords[limit] ||= begin
list = []
count = 0
_stopwords = Vidibus::Words.stopwords(*locales)
for word in sort
clean = word.permalink.gsub('-','')
unless _stopwords.include?(clean)
... | Returns top keywords from input string . |
Summarize the following code: def next_tempfile
p = nil
Tempfile.open("onix") do |tf|
p = tf.path
tf.close!
end
p
end | generate a temp filename |
Summarize the following code: def each(&block)
@reader.each do |node|
if @reader.node_type == 1 && @reader.name == "Product"
str = @reader.outer_xml
if str.nil?
yield @product_klass.new
else
yield @product_klass.from_xml(str)
end
end
... | Iterate over all the products in an ONIX file |
Summarize the following code: def title
composite = product.titles.first
if composite.nil?
nil
else
composite.title_text || composite.title_without_prefix
end
end | retrieve the current title |
Summarize the following code: def title=(str)
composite = product.titles.first
if composite.nil?
composite = ONIX::Title.new
composite.title_type = 1
product.titles << composite
end
composite.title_text = str
end | set a new title |
Summarize the following code: def subtitle=(str)
composite = product.titles.first
if composite.nil?
composite = ONIX::Title.new
composite.title_type = 1
product.titles << composite
end
composite.subtitle = str
end | set a new subtitle |
Summarize the following code: def bic_subjects
subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 12 }
subjects.collect { |sub| sub.subject_code}
end | return an array of BIC subjects for this title could be version 1 or version 2 most ONIX files don t specifiy |
Summarize the following code: def imprint=(str)
composite = product.imprints.first
if composite.nil?
composite = ONIX::Imprint.new
product.imprints << composite
end
composite.imprint_name = str
end | set a new imprint |
Summarize the following code: def sales_restriction_type=(type)
composite = product.sales_restrictions.first
if composite.nil?
composite = ONIX::SalesRestriction.new
product.sales_restrictions << composite
end
composite.sales_restriction_type = type
end | set a new sales restriction type |
Summarize the following code: def on_order
supply = find_or_create_supply_detail
composite = supply.stock.first
if composite.nil?
composite = ONIX::Stock.new
supply.stock << composite
end
composite.on_order
end | retrieve the number on order |
Summarize the following code: def proprietry_discount_code_for_rrp
price = price_get(2)
return nil if price.nil?
discount = price.discounts_coded.find { |disc| disc.discount_code_type == 2 }
discount.andand.discount_code
end | retrieve the discount code that describes the rrp in this file |
Summarize the following code: def proprietry_discount_code_for_rrp=(code)
price = price_get(2)
if price.nil?
self.rrp_inc_sales_tax = 0
price = price_get(2)
end
discount = price.discounts_coded.find { |disc| disc.discount_code_type == 2 }
if discount.nil?
di... | set the discount code that describes the rrp in this file |
Summarize the following code: def add_subject(str, type = "12")
subject = ::ONIX::Subject.new
subject.subject_scheme_id = type.to_i
subject.subject_code = str
product.subjects << subject
end | add a new subject to this product str should be the subject code type should be the code for the subject scheme you re using . See ONIX codelist 27 . 12 is BIC |
Summarize the following code: def measurement_set(type, value, unit)
measure = measurement(type)
# create a new isbn record if we need to
if measure.nil?
measure = ONIX::Measure.new
measure.measure_type_code = type
product.measurements << measure
end
# store the n... | set the value of a particular measurement |
Summarize the following code: def price_get(type)
supply = find_or_create_supply_detail
if type.nil?
supply.prices.first
else
supply.prices.find { |p| p.price_type_code == type }
end
end | retrieve the value of a particular price |
Summarize the following code: def price_set(type, num)
p = price_get(type)
# create a new isbn record if we need to
if p.nil?
supply = find_or_create_supply_detail
p = ONIX::Price.new
p.price_type_code = type
supply.prices << p
end
# store the new value
... | set the value of a particular price |
Summarize the following code: def other_text_set(type, value)
text = other_text(type)
if text.nil?
text = ONIX::OtherText.new
text.text_type_code = type
product.text << text
end
# store the new value
text.text = value.to_s
end | set the value of a particular other text value |
Summarize the following code: def website_set(type, value)
site = website(type)
# create a new website record if we need to
if site.nil?
site = ONIX::Website.new
site.website_role = type
product.websites << site
end
site.website_link = value.to_s
end | set the value of a particular website |
Summarize the following code: def befriend new_friend
run_callbacks :befriend do
friendships.create friend_id: new_friend.id, friend_type: new_friend.class.name
end
end | Adds a friend to an instance s friend s list |
Summarize the following code: def befriend! new_friend
run_callbacks :befriend do
friendships.create! friend_id: new_friend.id, friend_type: new_friend.class.name
end
end | Adds a friend to an instance s friend s list Similar to . befriend but will raise an error if the operation is not successful |
Summarize the following code: def unfriend friend
run_callbacks :unfriend do
friendships
.where( friend_type: friend.class.name )
.where( friend_id: friend.id )
.first.destroy
end
end | Removes a friend from an instance s friend s list |
Summarize the following code: def handle_timecop_offset
# Establish now
if session[TimecopConsole::SESSION_KEY_NAME].present?
Rails.logger.debug "[timecop-console] Time traveling to #{session[TimecopConsole::SESSION_KEY_NAME].to_s}"
Timecop.travel(session[TimecopConsole::SESSION_KEY_NAME])
... | to be used as an around_filter |
Summarize the following code: def default_app_directories
StatDirectory.from_list([
%w(Controllers app/controllers),
%w(Helpers app/helpers),
%w(Models app/models),
%w(Mailers app/mailers),
%w(Javascripts app/assets/javascript... | What Rails expects |
Summarize the following code: def collect_directories(glob_pattern, file_pattern='')
Pathname.glob(glob_pattern).select{|f| f.basename.to_s.include?(file_pattern) }.map(&:dirname).uniq.map(&:realpath)
end | collects non empty directories and names the metric by the folder name parent? or dirname? or basename? |
Summarize the following code: def []=(index, color)
if index.respond_to?(:to_a)
index.to_a.each do |i|
check_index(i)
ws2811_led_set(@channel, i, color.to_i)
end
else
check_index(index)
ws2811_led_set(@channel, index, color.to_i)
end
end | Set given pixel identified by + index + to + color + |
Summarize the following code: def set(index, r, g, b)
check_index(index)
self[index] = Color.new(r, g, b)
end | Set given pixel identified by + index + to + r + + g + + b + |
Summarize the following code: def [](index)
if index.respond_to?(:to_a)
index.to_a.map do |i|
check_index(i)
Color.from_i(ws2811_led_get(@channel, i))
end
else
check_index(index)
Color.from_i(ws2811_led_get(@channel, index))
end
end | Return + Color + of led located at given index |
Summarize the following code: def format_path(entry)
server_path = entry.path
if base_path && server_path[0,base_path.length] == base_path
if server_path == base_path
return "."
elsif server_path[base_path.length,1] == "/"
return server_path[base_path.length + 1, server_p... | Print the given server path relative to the current directory |
Summarize the following code: def exact_path
return nil if has_double_star || exact_parts.any? { |part| part.nil? }
result = ChefFS::PathUtils::join(*exact_parts)
is_absolute ? ChefFS::PathUtils::join('', result) : result
end | If this pattern represents an exact path returns the exact path . |
Summarize the following code: def []=(x, y, color)
check_coords(x, y)
@pixels[x][y] = color
@hat[map_coords(x, y)] = color
end | Set given pixel identified by + x + + y + to + color + |
Summarize the following code: def set(x, y, r, g, b)
check_coords(x, y)
self[x, y] = Color.new(r, g, b)
end | Set given pixel identified by + x + + y + to + r + + g + + b + |
Summarize the following code: def rotation=(val)
permissible = [0, 90, 180, 270]
fail ArgumentError, "invalid rotation, permissible: #{permissible.join(', ')}" unless permissible.include?(val % 360)
@rotation = val % 360
push_all_pixels
end | Set rotation of the Unicorn HAT to + val + |
Summarize the following code: def check_coords(x, y)
if 0 <= x && x < 8 && 0 <= y && y < 8
true
else
fail ArgumentError, "coord (#{x},#{y}) outside of permitted range ((0..7), (0..7))"
end
end | Verify supplied coords + x + and + y + |
Summarize the following code: def validate!
if self.class.json_schema
self.class.validator.instance_variable_set('@errors', [])
self.class.validator.instance_variable_set('@data', stringify_keys(to_h(persist: true)))
self.class.validator.validate
true
end
end | Validates the object against the schema . |
Summarize the following code: def to_h(persist: false)
{}.tap do |hash|
(persist ? properties - foreign_objects : properties).each do |property|
value = self[property]
if value == false || value.present?
hash[property] = value
end
end
end
end | Returns the object as a hash . |
Summarize the following code: def export_to_file(filename, options={})
content_string = export_to_string(default_options(filename).merge(:filename => filename))
File.open(filename, "w") { |f| f.write(content_string) }
nil
end | Export this map to the given filename in the appropriate format . |
Summarize the following code: def export_to_string(options = {})
hash = self.to_h
# Need to add back all non-tilelayers to hash["layers"]
image_layers = hash.delete(:image_layers)
object_groups = hash.delete(:object_groups)
hash[:layers] += image_layers
hash[:layers] += object_group... | Export this map as a string in the appropriate format . |
Summarize the following code: def dump_scraped_objects(task_name)
counts = Hash.new(0)
@store.pipelined do
send(task_name).each do |object|
counts[object._type] += 1
dump_scraped_object(object)
end
end
counts
end | Dumps scraped objects to disk . |
Summarize the following code: def import
@report[:import] = {}
objects = deduplicate(load_scraped_objects)
object_id_to_database_id = {}
if use_dependency_graph?(objects)
dependency_graph = build_dependency_graph(objects)
# Replace object IDs with database IDs in foreign keys... | Saves scraped objects to a database . |
Summarize the following code: def dump_scraped_object(object)
type = object.class.to_s.demodulize.underscore
name = "#{type}_#{object._id.gsub(File::SEPARATOR, '_')}.json"
if @store.write_unless_exists(name, object.to_h)
info {"save #{type} #{object.to_s} as #{name}"}
else
raise... | Dumps an scraped object to disk . |
Summarize the following code: def load_scraped_objects
{}.tap do |objects|
@store.read_multi(@store.entries).each do |properties|
object = load_scraped_object(properties)
objects[object._id] = object
end
end
end | Loads scraped objects from disk . |
Summarize the following code: def load_scraped_object(properties)
type = properties['_type'] || properties[:_type]
if type
type.camelize.constantize.new(properties)
else
raise Errors::MissingObjectTypeError, "missing _type: #{JSON.dump(properties)}"
end
end | Loads a scraped object from its properties . |
Summarize the following code: def deduplicate(objects)
losers_to_winners = build_losers_to_winners_map(objects)
# Remove all losers.
losers_to_winners.each_key do |key|
objects.delete(key)
end
# Swap the IDs of losers for the IDs of winners.
objects.each do |id,object|
... | Removes all duplicate objects and re - assigns any foreign keys . |
Summarize the following code: def build_losers_to_winners_map(objects)
inverse = {}
objects.each do |id,object|
(inverse[object.to_h.except(:_id)] ||= []) << id
end
{}.tap do |map|
inverse.values.each do |ids|
ids.drop(1).each do |id|
map[id] = ids[0]
... | For each object map its ID to the ID of its duplicate if any . |
Summarize the following code: def use_dependency_graph?(objects)
objects.each do |id,object|
object.foreign_objects.each do |property|
if object[property].present?
return false
end
end
end
true
end | If any objects have unresolved foreign objects we cannot derive an evaluation order using a dependency graph . |
Summarize the following code: def build_dependency_graph(objects)
DependencyGraph.new.tap do |graph|
objects.each do |id,object|
graph[id] = [] # no duplicate IDs
object.foreign_keys.each do |property|
value = object[property]
if value
graph[id] <<... | Builds a dependency graph . |
Summarize the following code: def resolve_foreign_keys(object, map)
object.foreign_keys.each do |property|
value = object[property]
if value
if map.key?(value)
object[property] = map[value]
else
raise Errors::MissingDatabaseIdError, "couldn't resolve for... | Resolves an object s foreign keys from object IDs to database IDs . |
Summarize the following code: def resolve_foreign_objects(object, map)
object.foreign_objects.each do |property|
value = object[property]
if value.present?
foreign_object = ForeignObject.new(value)
resolve_foreign_keys(foreign_object, map)
document = connection.find(f... | Resolves an object s foreign objects to database IDs . |
Summarize the following code: def run(args, overrides = {})
rest = opts.parse!(args)
@options = OpenStruct.new(options.to_h.merge(overrides))
if options.actions.empty?
options.actions = %w(scrape import)
end
if options.tasks.empty?
options.tasks = @processor_class.tasks
... | Runs the action . |
Summarize the following code: def add_group_result(result, group: nil)
data = {result: result}
if group
data[:group] = group
end
if result.present?
@group_results << data
end
end | Adds a group result . |
Summarize the following code: def add_count(option, value, group: nil)
data = {option: option, value: value}
if group
data[:group] = group
end
if option.present? && value.present?
@counts << data
end
end | Adds a count . |
Summarize the following code: def print_artifacts
artifacts = build.artifacts
return if artifacts.empty?
content = "### Jenkins artifacts:\n\n"
content << "<img width='40' align='right' src='#{JENKINS_ICON}'></img>\n"
artifacts.each do |artifact|
content << "* #{artifact_link(art... | Adds a list of artifacts to the danger comment |
Summarize the following code: def delete(pkg)
iterator = case pkg
when Package
pkg[:sigmd5] ? each_match(:sigmd5, pkg[:sigmd5]) : each_match(:label, pkg[:label])
when String
each_match(:label, pkg)
when Dependency
... | Add a delete operation to the transaction |
Summarize the following code: def commit
flags = RPM::C::TransFlags[:none]
callback = proc do |hdr, type, amount, total, key_ptr, data_ignored|
key_id = key_ptr.address
key = @keys.include?(key_id) ? @keys[key_id] : nil
if block_given?
package = hdr.null? ? nil : Package.... | Performs the transaction . |
Summarize the following code: def find(params)
params = { type: params } if params.is_a?(String)
found_objects = find_all do |object|
params.any? {|key,value| object.send(key) == value.to_s }
end.compact
self.class.new found_objects
end | Allows finding by type or a specfied hash of parameters |
Summarize the following code: def next_lfsr25(seed)
i = 1
i = (seed + 1) & MASK
raise ArgumentError, "Seed #{seed} out of bounds" if seed && i == 0
i = (seed + 1) & MASK while i == 0
i = (i >> 1) | ((i[0]^i[1]^i[2]^i[3]) << 0x18)
i = (i >> 1) | ((i[0]^i[1]^i[2]^i[3]) << 0x18) while i... | Fibonacci linear feedback shift register with x^25 + x^24 + x^23 + x^22 + 1 poly |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.