Module: Colloquy::FlowParser::InstanceMethods
- Includes:
- Helpers
- Defined in:
- lib/colloquy/flow_parser.rb
Constant Summary collapse
- STATE_DEFAULT =
{ node: :index, flow_state: :init, previous: {} }
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #_(message_emergent) ⇒ Object
- #apply(input = nil) ⇒ Object
- #flow_name ⇒ Object
-
#initialize(flow_name = nil, options = {}) ⇒ Object
Initializes the flow.
- #node_add(identifier, options = {}, &payload) ⇒ Object
- #notify(message) ⇒ Object
- #pass ⇒ Object
- #reset!(include_messages = false) ⇒ Object
- #reset_nodes! ⇒ Object
-
#state=(state) ⇒ Object
Do not set @state directly, because it has many checks to ensure that @state is never inconsistent.
- #switch(node, options = {}) ⇒ Object
Methods included from Helpers::Settings
Methods included from Helpers::Scribe
Methods included from Helpers::Redis
Methods included from Helpers::MySQL
Methods included from Helpers::Url
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
19 20 21 |
# File 'lib/colloquy/flow_parser.rb', line 19 def headers @headers end |
#logger ⇒ Object
Returns the value of attribute logger.
19 20 21 |
# File 'lib/colloquy/flow_parser.rb', line 19 def logger @logger end |
#messages ⇒ Object
Returns the value of attribute messages.
19 20 21 |
# File 'lib/colloquy/flow_parser.rb', line 19 def @messages end |
#nodes ⇒ Object
Returns the value of attribute nodes.
18 19 20 |
# File 'lib/colloquy/flow_parser.rb', line 18 def nodes @nodes end |
#session ⇒ Object
Returns the value of attribute session.
19 20 21 |
# File 'lib/colloquy/flow_parser.rb', line 19 def session @session end |
Instance Method Details
#_(message_emergent) ⇒ Object
100 101 102 |
# File 'lib/colloquy/flow_parser.rb', line 100 def _() Colloquy::MessageBuilder.(, :flow => self) end |
#apply(input = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/colloquy/flow_parser.rb', line 57 def apply(input = nil) reset_nodes! input = sanitize_input(input) store_previous_state! case state[:flow_state].to_sym when :init store_back_state! apply_request(input) when :request apply_process(input) else raise Colloquy::FlowStateInconsistent, "An unexpected flow state: #{state[:flow_state]} was found" end rescue Colloquy::NotifyJump => e notify! e.payload rescue Colloquy::SwitchJump => e switch! e.payload rescue Colloquy::SwitchBackJump => e switch_back! rescue Colloquy::PassJump => e pass! input end |
#flow_name ⇒ Object
38 39 40 |
# File 'lib/colloquy/flow_parser.rb', line 38 def flow_name @flow_name ||= "#{self.class}".underscore.gsub(/_flow/, '').split('/').last.to_sym end |
#initialize(flow_name = nil, options = {}) ⇒ Object
Initializes the flow
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/colloquy/flow_parser.rb', line 23 def initialize(flow_name = nil, = {}) @flow_name = flow_name.to_sym if flow_name @logger = [:logger] || Logger.new(STDOUT) @session = HashWithIndifferentAccess.new([:session] || {}) @messages = [:messages] || {} @headers = {} self.state = [:state] @nodes = [:nodes] || [] setup if self.class.method_defined?(:setup) create_nodes_from_definitions! if @nodes.empty? end |
#node_add(identifier, options = {}, &payload) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/colloquy/flow_parser.rb', line 47 def node_add(identifier, = {}, &payload) if node_by_id(identifier) raise Colloquy::DuplicateNodeException, "A node named #{identifier} is already present in the flow" end .merge!(flow: self) @nodes << Colloquy::Node.new(identifier, , &payload) end |
#notify(message) ⇒ Object
104 105 106 |
# File 'lib/colloquy/flow_parser.rb', line 104 def notify() raise_jump_exception(Colloquy::NotifyJump, ) end |
#pass ⇒ Object
120 121 122 |
# File 'lib/colloquy/flow_parser.rb', line 120 def pass raise_jump_exception(Colloquy::PassJump) end |
#reset!(include_messages = false) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/colloquy/flow_parser.rb', line 83 def reset!( = false) @session = HashWithIndifferentAccess.new @state = {} self.state = {} @headers = {} @messages = {} if reset_nodes! end |
#reset_nodes! ⇒ Object
94 95 96 97 98 |
# File 'lib/colloquy/flow_parser.rb', line 94 def reset_nodes! @nodes.each do |node| node.reset! end end |
#state=(state) ⇒ Object
Do not set @state directly, because it has many checks to ensure that @state is never inconsistent
43 44 45 |
# File 'lib/colloquy/flow_parser.rb', line 43 def state=(state) @state = STATE_DEFAULT.merge(flow_name: flow_name).merge(state || {}) end |
#switch(node, options = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/colloquy/flow_parser.rb', line 108 def switch(node, = {}) if node == :back raise_jump_exception(Colloquy::SwitchBackJump) end if [:flow] raise_jump_exception(Colloquy::SwitchFlowJump, { :node => node, :flow => [:flow] }) end raise_jump_exception(Colloquy::SwitchJump, node) end |