Class: Nuvemshop::BaseModel
- Inherits:
-
Object
- Object
- Nuvemshop::BaseModel
- Includes:
- Extensions::MassAssignment
- Defined in:
- lib/nuvemshop/base_model.rb
Direct Known Subclasses
Customer, Extras::Timestampz, Order, Order::Address, Order::ClientDetails, Order::PaymentDetails, Order::PromotionalDiscount, Product, Product::Image
Class Method Summary collapse
-
.attr_accessor(*vars) ⇒ Object
Intercepts attr_acessor call, and assign it value to a variable named @attributes.
-
.attributes ⇒ Object
Getter to expose @attributes to class object.
Instance Method Summary collapse
-
#attributes ⇒ Object
Getter to expose @attributes to class instance.
-
#pretty_print(pp) ⇒ Object
Overwrite default Ruby pretty_print(q) method to act as ActiveRecord’s output.
Methods included from Extensions::MassAssignment
Class Method Details
.attr_accessor(*vars) ⇒ Object
Intercepts attr_acessor call, and assign it value to a variable named @attributes
7 8 9 10 11 |
# File 'lib/nuvemshop/base_model.rb', line 7 def self.attr_accessor(*vars) @attributes ||= [] @attributes.concat vars super(*vars) end |
.attributes ⇒ Object
Getter to expose @attributes to class object
15 16 17 |
# File 'lib/nuvemshop/base_model.rb', line 15 def self.attributes @attributes end |
Instance Method Details
#attributes ⇒ Object
Getter to expose @attributes to class instance
21 22 23 |
# File 'lib/nuvemshop/base_model.rb', line 21 def attributes self.class.attributes end |
#pretty_print(pp) ⇒ Object
Overwrite default Ruby pretty_print(q) method to act as ActiveRecord’s output
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nuvemshop/base_model.rb', line 27 def pretty_print(pp) pp.object_address_group(self) do variables = self.class.attributes.map do |attribute| attribute.to_s.delete(':') end pp.seplist(variables, proc { pp.text ',' }) do |attr_name| pp.breakable ' ' pp.group(1) do pp.text attr_name pp.text ':' pp.breakable value = send(attr_name.to_sym) || nil pp.pp value end end end end |