Class: ModestModel::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, ActiveModel::Translation
Includes:
ActiveModel::AttributeMethods, ActiveModel::Conversion, ActiveModel::Serialization, ActiveModel::Validations, Validators
Defined in:
lib/modest_model/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/modest_model/base.rb', line 12

def initialize(attributes = {})
  attributes.each do |attr, value|
    self.send("#{attr}=", value)
  end unless attributes.blank?
end

Class Method Details

.attributes(*names) ⇒ Object



24
25
26
27
28
29
# File 'lib/modest_model/base.rb', line 24

def self.attributes(*names)
  attr_accessor *names
  define_attribute_methods names

  self._attributes += names
end

Instance Method Details

#attributesObject



31
32
33
34
35
36
# File 'lib/modest_model/base.rb', line 31

def attributes
  self._attributes.inject({}) do |hash, attr|
    hash[attr.to_s] = send(attr)
    hash
  end
end

#persisted?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/modest_model/base.rb', line 38

def persisted?
  false
end