Module: StoreModel::Model
- Defined in:
- lib/store_model/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json(options = {}) ⇒ Object
-
#blank? ⇒ Boolean
Allows to call :presence validation on the association itself.
- #inspect ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/store_model/model.rb', line 7 def self.included(base) base.include ActiveModel::Model base.include ActiveModel::Attributes base.extend(Module.new do def to_type Types::JsonType.new(self) end def to_array_type Types::ArrayType.new(self) end end) end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 |
# File 'lib/store_model/model.rb', line 26 def ==(other) return super unless other.is_a?(self.class) attributes.all? { |name, value| value == other.send(name) } end |
#as_json(options = {}) ⇒ Object
22 23 24 |
# File 'lib/store_model/model.rb', line 22 def as_json( = {}) attributes.with_indifferent_access.as_json() end |
#blank? ⇒ Boolean
Allows to call :presence validation on the association itself
33 34 35 |
# File 'lib/store_model/model.rb', line 33 def blank? attributes.values.all?(&:blank?) end |
#inspect ⇒ Object
37 38 39 40 |
# File 'lib/store_model/model.rb', line 37 def inspect attribute_string = attributes.map { |name, value| "#{name}: #{value || 'nil'}" }.join(", ") "#<#{self.class.name} #{attribute_string}>" end |