Class: Dao::Entity::State

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Dirty
Defined in:
lib/dao/entity/state.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ State

Returns a new instance of State.



24
25
26
27
# File 'lib/dao/entity/state.rb', line 24

def initialize(params={})
  assign_attributes(params)
  changes_applied
end

Class Method Details

.build_with_attrs(attrs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dao/entity/state.rb', line 6

def self.build_with_attrs(attrs)
  state = Class.new(self)

  state.define_attribute_methods(*attrs)

  state.send(:attr_accessor, *attrs)
  attrs.each do |attr|
    state.send(:define_method, "#{ attr }=") do |val|
      if public_send(attr) != val
        attribute_will_change!(attr)
        instance_variable_set("@#{ attr}", val)
      end
    end
  end

  state
end

Instance Method Details

#assign_attributes(params) ⇒ Object



29
30
31
32
33
# File 'lib/dao/entity/state.rb', line 29

def assign_attributes(params)
  params.each do |attr, value|
    self.public_send("#{attr}=", value)
  end
end

#reload!Object



35
36
37
# File 'lib/dao/entity/state.rb', line 35

def reload!
  clear_changes_information
end

#rollback!Object



39
40
41
# File 'lib/dao/entity/state.rb', line 39

def rollback!
  restore_attributes
end