Class: OptionsModel::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Concerns::AttributeAssignment, Concerns::Attributes, Concerns::Serialization
Defined in:
lib/options_model/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::AttributeAssignment

#[], #[]=, #attributes, #fetch, #initialize, #initialize_dup, #nested_attributes, #replace, #unused_attributes

Methods included from Concerns::Serialization

#to_h

Class Method Details

.derive(name = "AnonymousRecord") ⇒ Object



41
42
43
44
45
46
# File 'lib/options_model/base.rb', line 41

def self.derive(name = "AnonymousRecord")
  Class.new(self) do
    include OptionsModel::Concerns::NameHacking
    self.name = name
  end
end

.inspectObject



33
34
35
# File 'lib/options_model/base.rb', line 33

def self.inspect
  "#<#{name}:OptionsModel [#{attribute_names.map(&:inspect).join(', ')}]>"
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



17
18
19
20
21
22
# File 'lib/options_model/base.rb', line 17

def ==(other)
  other.instance_of?(self.class) &&
    attributes == other.attributes &&
    nested_attributes == other.nested_attributes &&
    unused_attributes == other.unused_attributes
end

#hashObject



25
26
27
# File 'lib/options_model/base.rb', line 25

def hash
  [attributes, nested_attributes, unused_attributes].hash
end

#inspectObject



29
30
31
# File 'lib/options_model/base.rb', line 29

def inspect
  "#<#{self.class.name}:OptionsModel #{to_h}>"
end

#persisted?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/options_model/base.rb', line 37

def persisted?
  true
end