Class: ModestModel::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, ActiveModel::Translation
Includes:
ActiveModel::AttributeMethods, ActiveModel::Conversion, 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.



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

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

Class Method Details

.attributes(*names) ⇒ Object



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

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

  self._attributes += names
end

Instance Method Details

#attributesObject



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

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

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  false
end