Module: Dogviz::Flowable

Included in:
Thing
Defined in:
lib/dogviz/flowable.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dogviz/flowable.rb', line 28

def method_missing(m, *args, &block)
  if requests.has_key?(m)
    @flow ||= nil

    request_def = requests[m]
    if request_def.is_a?(String)
      label = request_def
      return_label = nil
    else
      request_def = request_def.call(*args) if request_def.is_a?(Proc)
      label = request_def.keys.first
      return_label = request_def.values.first
    end
    
    @flow.next_call self, label
    block.call if block_given?
    @flow.end_call(return_label)
  else
    raise "this flowable does not know about receiving '#{m}', only know about: #{requests.keys}"
  end
end

Instance Method Details

#does(action) ⇒ Object



5
6
7
# File 'lib/dogviz/flowable.rb', line 5

def does(action)
  Process.new(self, action)
end

#note(where, what) ⇒ Object



16
17
18
# File 'lib/dogviz/flowable.rb', line 16

def note(where, what)
  @flow.add_note(self, where, what)
end

#receives(requests, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/dogviz/flowable.rb', line 9

def receives(requests, &block)
  
  @requests = self.requests.merge requests if requests.is_a?(Hash)
  self.requests[requests] = block if requests.is_a?(Symbol)

end

#request_handlersObject



54
55
56
# File 'lib/dogviz/flowable.rb', line 54

def request_handlers
  @request_handlers ||= {}
end

#requestsObject



50
51
52
# File 'lib/dogviz/flowable.rb', line 50

def requests
  @requests ||= {}
end

#start_flow(flow) ⇒ Object



20
21
22
# File 'lib/dogviz/flowable.rb', line 20

def start_flow(flow)
  @flow = flow
end

#stop_flowObject



24
25
26
# File 'lib/dogviz/flowable.rb', line 24

def stop_flow
  @flow = nil
end