Class: PipeLineDealer::Model::Base
- Inherits:
-
Object
- Object
- PipeLineDealer::Model::Base
- Includes:
- Concern::Persistance
- Defined in:
- lib/pipe_line_dealer/model/base.rb,
lib/pipe_line_dealer/model/base/concern/persistance.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Concern
Constant Summary
Constants included from Concern::Persistance
Concern::Persistance::IGNORE_ATTRIBUTES_WHEN_SAVING
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#attributes_for_saving(attributes) ⇒ Object
TODO : remove check of methode bestaat.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #to_json ⇒ Object
- #to_s ⇒ Object
Methods included from Concern::Persistance
#destroy, #new_record?, #persisted?, #save
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 |
# File 'lib/pipe_line_dealer/model/base.rb', line 11 def initialize = {} @options = @persisted = !!@options[:persisted] @collection = @options[:collection] import_attributes! @options[:attributes] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/pipe_line_dealer/model/base.rb', line 8 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/pipe_line_dealer/model/base.rb', line 9 def id @id end |
Class Method Details
.attrs(*attrs) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pipe_line_dealer/model/base.rb', line 37 def self.attrs *attrs if attrs.last.kind_of?(Hash) = attrs.pop else = {} end attrs.each do |attr| pld_attr attr, end end |
.inherited(subklass) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/pipe_line_dealer/model/base.rb', line 49 def self.inherited(subklass) @attributes ||= {} # Copy all attributes to the children. @attributes.each do |attr, | subklass.pld_attr attr, end end |
.pld_attr(attr, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pipe_line_dealer/model/base.rb', line 58 def self.pld_attr attr, = {} @attributes ||= {} @attributes[attr] = # Getter define_method attr do @attributes[attr.to_s] end # Setter define_method "#{attr}=".to_sym do |value| @attributes[attr.to_s] = value end end |
Instance Method Details
#==(other) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/pipe_line_dealer/model/base.rb', line 25 def ==(other) if other.kind_of?(self.class) other.attributes == self.attributes else super(other) end end |
#attributes_for_saving(attributes) ⇒ Object
TODO : remove check of methode bestaat
20 21 22 |
# File 'lib/pipe_line_dealer/model/base.rb', line 20 def attributes_for_saving(attributes) attributes end |
#to_json ⇒ Object
33 34 35 |
# File 'lib/pipe_line_dealer/model/base.rb', line 33 def to_json JSON.dump(@attributes) end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/pipe_line_dealer/model/base.rb', line 73 def to_s "<PipeLineDealer::Model:#{__id__} klass=#{self.class.name} id=#{@id} attributes=#{@attributes.inspect}>" end |