Class: ModestModel::Base

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

Direct Known Subclasses

Resource

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CombinedAttr

attribute

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ Base

Returns a new instance of Base.



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

def initialize(attributes = {}, options={})
  self.assign_attributes(attributes, options)
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

#[](attr) ⇒ Object



41
42
43
# File 'lib/modest_model/base.rb', line 41

def [] attr
  attributes[attr.to_s]
end

#[]=(attr, val) ⇒ Object



45
46
47
# File 'lib/modest_model/base.rb', line 45

def []= attr, val
  self.send "#{attr}=", val
end

#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

#attributes=(attributes, options = {}) ⇒ Object



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

def attributes= attributes, options = {}
  assign_attributes attributes, options = {}
end

#persisted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/modest_model/base.rb', line 49

def persisted?
  false
end