Class: Gameplan
- Inherits:
-
Object
show all
- Includes:
- Validation
- Defined in:
- lib/gameplan.rb,
lib/gameplan/flow.rb,
lib/gameplan/user.rb,
lib/gameplan/state.rb,
lib/gameplan/version.rb,
lib/gameplan/describe.rb,
lib/gameplan/endpoint.rb,
lib/gameplan/validation.rb,
lib/gameplan/application.rb,
lib/gameplan/transitions.rb,
lib/gameplan/common_state.rb,
lib/gameplan/pending_state.rb,
lib/gameplan/site_generator.rb
Defined Under Namespace
Modules: Describe, Validation
Classes: Application, CommonState, Endpoint, Flow, PendingState, SiteGenerator, State, Transitions, User
Constant Summary
collapse
- VERSION =
'0.0.2'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Validation
#add_error, #add_warning, #errors, #reset_validation!, #valid?, #warnings
Constructor Details
Returns a new instance of Gameplan.
33
34
35
36
37
|
# File 'lib/gameplan.rb', line 33
def initialize
@apps = {}
@flows = {}
@capabilities = []
end
|
Instance Attribute Details
#apps ⇒ Object
Returns the value of attribute apps.
19
20
21
|
# File 'lib/gameplan.rb', line 19
def apps
@apps
end
|
#flows ⇒ Object
Returns the value of attribute flows.
19
20
21
|
# File 'lib/gameplan.rb', line 19
def flows
@flows
end
|
#last_app ⇒ Object
Returns the value of attribute last_app.
19
20
21
|
# File 'lib/gameplan.rb', line 19
def last_app
@last_app
end
|
#last_flow ⇒ Object
Returns the value of attribute last_flow.
19
20
21
|
# File 'lib/gameplan.rb', line 19
def last_flow
@last_flow
end
|
Instance Method Details
#app(name, type, &blk) ⇒ Object
98
99
100
|
# File 'lib/gameplan.rb', line 98
def app(name, type, &blk)
@last_app = @apps[type] = Application.new(self, name, type, &blk)
end
|
#capabilities(*capabilities) ⇒ Object
94
95
96
|
# File 'lib/gameplan.rb', line 94
def capabilities(*capabilities)
@capabilities.concat(capabilities)
end
|
#compile ⇒ Object
29
30
31
|
# File 'lib/gameplan.rb', line 29
def compile
@apps.values.each(&:compile)
end
|
#flow(name, &blk) ⇒ Object
102
103
104
105
106
|
# File 'lib/gameplan.rb', line 102
def flow(name, &blk)
@last_flow = flow = Flow.new(self, name, &blk)
@flows[name] = flow
flow
end
|
#load(dir) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/gameplan.rb', line 21
def load(dir)
Dir[File.join(dir, "*.gplan")].each do |f|
instance_eval File.read(f), f, 1
end
compile
self
end
|
#report ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/gameplan.rb', line 48
def report
puts "RUNNING GAMEPLAN\n"
state_count = @apps.values.inject(0) { |s, a| s += a.states.size }
endpoint_count = @apps.values.inject(0) { |s, a| s += a.states.values.inject(0) {|ss, state| ss += state.endpoints.size } }
puts "You currently have #{@apps.size.to_s.foreground(:yellow)} apps with " <<
"#{state_count.to_s.foreground(:yellow)} states and " <<
"#{endpoint_count.to_s.foreground(:yellow)} endpoints defined."
puts "You currently have #{@flows.size.to_s.foreground(:yellow)} flows defined"
puts "#{@errors.size.to_s.foreground(:red)} errors, #{@warnings.size.to_s.foreground(:red)} warnings"
if valid?
puts "\nValid!".foreground(:green)
else
puts "\nThere were errors present:" unless errors.empty?
errors.each { |error| puts error }
puts "\nThere were warnings present:" unless warnings.empty?
warnings.each { |warning| puts warning }
end
end
|
#test(name, user) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/gameplan.rb', line 117
def test(name, user)
types.each do |type|
@apps.values.select { |app| app.name == user.type }.all? do |app|
paths = @flows[name].traverse(app, user).to_a
add_error "Failed to traverse flow #{name}" if paths.empty?
end
end
end
|
#travel(name, type) ⇒ Object
108
109
110
111
|
# File 'lib/gameplan.rb', line 108
def travel(name, type)
user = User.new(type)
@flows[name].traverse(@apps[type], user)
end
|
#types ⇒ Object
113
114
115
|
# File 'lib/gameplan.rb', line 113
def types
@apps.values.map(&:name)
end
|
#validate ⇒ Object
67
68
69
70
71
|
# File 'lib/gameplan.rb', line 67
def validate
reset_validation!
validate_apps
validate_flows
end
|
#validate_and_report ⇒ Object
39
40
41
42
|
# File 'lib/gameplan.rb', line 39
def validate_and_report
validate
report
end
|
#validate_apps ⇒ Object
90
91
92
|
# File 'lib/gameplan.rb', line 90
def validate_apps
@apps.values.each { |app| app.validate }
end
|
#validate_flow_traversability ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/gameplan.rb', line 81
def validate_flow_traversability
with_all_users do |user|
@flows.keys.each do |name|
puts "VALIDATING #{name.inspect}"
test(name, user) end
end
end
|
#validate_flows ⇒ Object
73
74
75
|
# File 'lib/gameplan.rb', line 73
def validate_flows
validate_flow_traversability
end
|
#validate_states ⇒ Object
77
78
79
|
# File 'lib/gameplan.rb', line 77
def validate_states
validate_state_deadends
end
|