Class: Gameplan::CommonState
- Inherits:
-
Object
- Object
- Gameplan::CommonState
show all
- Includes:
- Describe
- Defined in:
- lib/gameplan/common_state.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Describe
#desc, #description, #description_list
Constructor Details
#initialize(app, name, pretty_name, &blk) ⇒ CommonState
Returns a new instance of CommonState.
7
8
9
10
11
12
13
|
# File 'lib/gameplan/common_state.rb', line 7
def initialize(app, name, pretty_name, &blk)
@app = app
@name = name
@pretty_name = pretty_name
@endpoints = []
@blk = blk
end
|
Instance Attribute Details
#endpoints ⇒ Object
Returns the value of attribute endpoints.
5
6
7
|
# File 'lib/gameplan/common_state.rb', line 5
def endpoints
@endpoints
end
|
Instance Method Details
#add_error(str) ⇒ Object
37
38
39
|
# File 'lib/gameplan/common_state.rb', line 37
def add_error(str)
@app.add_error(str)
end
|
#compile ⇒ Object
15
16
17
|
# File 'lib/gameplan/common_state.rb', line 15
def compile
instance_eval(&@blk)
end
|
#endpoint(state, desc) ⇒ Object
19
20
21
|
# File 'lib/gameplan/common_state.rb', line 19
def endpoint(state, desc)
@endpoints << Endpoint.new(@app, state, desc)
end
|
#traverse(user, target_state, count, transitions) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/gameplan/common_state.rb', line 23
def traverse(user, target_state, count, transitions)
return if count.zero?
transitions.emit if @name == target_state
@endpoints.each do |endpoint|
transitions.add(@name, endpoint.change_name) do
@app.states[endpoint.state_name].traverse(user, target_state, count - 1, transitions)
end
end
end
|
#validate ⇒ Object
33
34
35
|
# File 'lib/gameplan/common_state.rb', line 33
def validate
add_error "State #{@name} has no endpoints" if @endpoints.empty?
end
|