Class: StateFu::Persistence::Attribute

Inherits:
Base show all
Defined in:
lib/persistence/attribute.rb

Instance Attribute Summary

Attributes inherited from Base

#binding, #current_state, #field_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#find_current_state, #initialize, #klass, #machine, #object, #persist!, #reload, #value

Constructor Details

This class inherits a constructor from StateFu::Persistence::Base

Class Method Details

.prepare_field(klass, field_name) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/persistence/attribute.rb', line 5

def self.prepare_field( klass, field_name )
  # ensure getter exists
  unless klass.instance_methods.map(&:to_sym).include?( field_name.to_sym )
    Logging.debug "Adding attr_reader :#{field_name} for #{klass}"
    _field_name = field_name
    klass.class_eval do
      private
      attr_reader _field_name
    end
  end

  # ensure setter exists
  unless klass.instance_methods.map(&:to_sym).include?( :"#{field_name}=" )
    Logging.debug "Adding attr_writer :#{field_name}= for #{klass}"
    _field_name = field_name
    klass.class_eval do
      private
      attr_writer _field_name
    end
  end
end

Instance Method Details

#bObject


27
# File 'lib/persistence/attribute.rb', line 27

def b; binding; end