lib/monitoring_protocols/data_struct.rb
##
# Merge new data in the structure.
#
# @param [Object,Hash] opts_or_obj Source
# @param [Array] only_fields an array of symbol
#   specifying which fields to copy
# @param [Boolean] allow_nil If false nil values from
#   the source will not be copied in object
#
Merge new data in the structure.
Merge new data in the structure .
def merge_data_from!(opts_or_obj = {}, only_fields = nil, allow_nil = false)
      keys_left = list_keys(opts_or_obj)
      self.class.attributes.select{|attr_name| selected_field?(attr_name, only_fields) }.each do |attr_name|
        v = opts_or_obj.is_a?(Hash) ? (opts_or_obj[attr_name.to_s] || opts_or_obj[attr_name]) : opts_or_obj.send(attr_name)
        if allow_nil || !v.nil?
          send("#{attr_name}=", v)
        end
        keys_left.delete(attr_name)
      end
      unless keys_left.empty?
        raise ArgumentError, "unknown keys: #{keys_left}"
      end
    end
def merge_data_from! ( opts_or_obj = { } , only_fields = nil , allow_nil = false ) keys_left = list_keys ( opts_or_obj ) self . class . attributes . select { | attr_name | selected_field? ( attr_name , only_fields ) } . each do | attr_name | v = opts_or_obj . is_a? ( Hash ) ? ( opts_or_obj [ attr_name . to_s ] || opts_or_obj [ attr_name ] ) : opts_or_obj . send ( attr_name ) if allow_nil || ! v . nil? send ( "#{attr_name}=" , v ) end keys_left . delete ( attr_name ) end unless keys_left . empty? raise ArgumentError , "unknown keys: #{keys_left}" end end
Merge new data in the structure.
Merge new data in the structure .
opts_or_obj
<not_specific>
only_fields
<not_specific>
allow_nil
<not_specific>
<not_specific>
allow_nil If false nil values from the source will not be copied in object
allow_nil If false nil values from the source will not be copied in object