Module: Einhorn::AbstractState

Included in:
State, TransientState
Defined in:
lib/einhorn.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/einhorn.rb', line 28

def method_missing(name, *args)
  if (name.to_s =~ /(.*)=$/) && state.has_key?($1.to_sym)
    state.send(:[]=, $1.to_sym, *args)
  elsif state.has_key?(name)
    state[name]
  else
    ds = default_state
    if ds.has_key?(name)
      ds[name]
    else
      super
    end
  end
end

Instance Method Details

#default_stateObject

Raises:

  • (NotImplementedError)


23
# File 'lib/einhorn.rb', line 23

def default_state; raise NotImplementedError.new('Override in extended modules'); end

#dumpable_stateObject



26
# File 'lib/einhorn.rb', line 26

def dumpable_state; state; end

#stateObject



24
# File 'lib/einhorn.rb', line 24

def state; @state ||= default_state; end

#state=(v) ⇒ Object



25
# File 'lib/einhorn.rb', line 25

def state=(v); @state = v; end