class Terrestrial::Record
Attributes
attributes[R]
mapping[R]
Public Class Methods
new(mapping, attributes)
click to toggle source
# File lib/terrestrial/record.rb, line 8 def initialize(mapping, attributes) @mapping = mapping @attributes = attributes end
Public Instance Methods
==(other)
click to toggle source
# File lib/terrestrial/record.rb, line 81 def ==(other) other.is_a?(self.class) && [other.mapping, other.attributes] == [mapping, attributes] end
deep_clone()
click to toggle source
# File lib/terrestrial/record.rb, line 77 def deep_clone new_with_attributes(Marshal.load(Marshal.dump(attributes))) end
empty?()
click to toggle source
# File lib/terrestrial/record.rb, line 68 def empty? updatable_attributes.empty? end
identity()
click to toggle source
# File lib/terrestrial/record.rb, line 44 def identity attributes.select { |k,_v| identity_fields.include?(k) } end
identity_fields()
click to toggle source
# File lib/terrestrial/record.rb, line 48 def identity_fields mapping.primary_key end
identity_values()
click to toggle source
# File lib/terrestrial/record.rb, line 40 def identity_values identity.values end
if_delete(&block)
click to toggle source
# File lib/terrestrial/record.rb, line 24 def if_delete(&block) self end
if_upsert(&block)
click to toggle source
# File lib/terrestrial/record.rb, line 20 def if_upsert(&block) self end
keys()
click to toggle source
# File lib/terrestrial/record.rb, line 36 def keys attributes.keys end
merge(more_attributes)
click to toggle source
# File lib/terrestrial/record.rb, line 52 def merge(more_attributes) new_with_attributes(attributes.merge(more_attributes)) end
merge!(more_attributes)
click to toggle source
# File lib/terrestrial/record.rb, line 56 def merge!(more_attributes) attributes.merge!(more_attributes) end
namespace()
click to toggle source
# File lib/terrestrial/record.rb, line 16 def namespace mapping.namespace end
reject(&block)
click to toggle source
# File lib/terrestrial/record.rb, line 60 def reject(&block) new_with_attributes(updatable_attributes.reject(&block).merge(identity)) end
subset?(other_record)
click to toggle source
# File lib/terrestrial/record.rb, line 72 def subset?(other_record) mapping == other_record.mapping && to_set.subset?(other_record.to_set) end
to_h()
click to toggle source
# File lib/terrestrial/record.rb, line 64 def to_h attributes.to_h end
updatable?()
click to toggle source
# File lib/terrestrial/record.rb, line 28 def updatable? updatable_attributes.any? end
updatable_attributes()
click to toggle source
# File lib/terrestrial/record.rb, line 32 def updatable_attributes attributes.reject { |k, _v| non_updatable_fields.include?(k) } end
Protected Instance Methods
to_set()
click to toggle source
# File lib/terrestrial/record.rb, line 88 def to_set Set.new(attributes.to_a) end
Private Instance Methods
new_with_attributes(new_attributes)
click to toggle source
# File lib/terrestrial/record.rb, line 102 def new_with_attributes(new_attributes) self.class.new(mapping, new_attributes) end
nil_fields_expecting_default_value()
click to toggle source
# File lib/terrestrial/record.rb, line 98 def nil_fields_expecting_default_value mapping.database_default_fields.select { |k| attributes[k].nil? } end
non_updatable_fields()
click to toggle source
# File lib/terrestrial/record.rb, line 94 def non_updatable_fields identity_fields + mapping.database_owned_fields + nil_fields_expecting_default_value end