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 |
# 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 JsonModelType.new(self) end end) end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 26 |
# File 'lib/store_model/model.rb', line 22 def ==(other) return super unless other.is_a?(self.class) attributes.all? { |name, value| value == other.send(name) } end |
#as_json(options = {}) ⇒ Object
18 19 20 |
# File 'lib/store_model/model.rb', line 18 def as_json( = {}) attributes.with_indifferent_access.as_json() end |
#blank? ⇒ Boolean
Allows to call :presence validation on the association itself
29 30 31 |
# File 'lib/store_model/model.rb', line 29 def blank? attributes.values.all?(&:blank?) end |
#inspect ⇒ Object
33 34 35 36 |
# File 'lib/store_model/model.rb', line 33 def inspect attribute_string = attributes.map { |name, value| "#{name}: #{value || 'nil'}" }.join(", ") "#<#{self.class.name} #{attribute_string}>" end |