Class: Gameplan::Application
- Inherits:
-
Object
- Object
- Gameplan::Application
- Includes:
- Describe
- Defined in:
- lib/gameplan/application.rb
Instance Attribute Summary collapse
-
#common_states ⇒ Object
readonly
Returns the value of attribute common_states.
-
#last_state ⇒ Object
readonly
Returns the value of attribute last_state.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#pretty_name ⇒ Object
readonly
Returns the value of attribute pretty_name.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #add_error(str) ⇒ Object
- #add_warning(str) ⇒ Object
- #common_state(name, desc, &blk) ⇒ Object
- #compile ⇒ Object
- #for_user(*capabilities) ⇒ Object
-
#initialize(plan, pretty_name, name, &blk) ⇒ Application
constructor
A new instance of Application.
- #pending_state(name, desc, &blk) ⇒ Object
- #state(name, desc, &blk) ⇒ Object
- #validate ⇒ Object
Methods included from Describe
#desc, #description, #description_list
Constructor Details
#initialize(plan, pretty_name, name, &blk) ⇒ Application
Returns a new instance of Application.
7 8 9 |
# File 'lib/gameplan/application.rb', line 7 def initialize(plan, pretty_name, name, &blk) @plan, @pretty_name, @name, @states, @common_states, @blk = plan, pretty_name, name, {}, {}, blk end |
Instance Attribute Details
#common_states ⇒ Object (readonly)
Returns the value of attribute common_states.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def common_states @common_states end |
#last_state ⇒ Object (readonly)
Returns the value of attribute last_state.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def last_state @last_state end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def name @name end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def plan @plan end |
#pretty_name ⇒ Object (readonly)
Returns the value of attribute pretty_name.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def pretty_name @pretty_name end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
5 6 7 |
# File 'lib/gameplan/application.rb', line 5 def states @states end |
Instance Method Details
#add_error(str) ⇒ Object
45 46 47 |
# File 'lib/gameplan/application.rb', line 45 def add_error(str) @plan.add_error(str) end |
#add_warning(str) ⇒ Object
49 50 51 |
# File 'lib/gameplan/application.rb', line 49 def add_warning(str) @plan.add_warning(str) end |
#common_state(name, desc, &blk) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/gameplan/application.rb', line 33 def common_state(name, desc, &blk) raise "#{name} already exists" if @common_states[name] @last_state = @common_states[name] = CommonState.new(self, name, desc, &blk) @last_state.compile @last_state end |
#compile ⇒ Object
11 12 13 |
# File 'lib/gameplan/application.rb', line 11 def compile instance_eval(&@blk) end |
#for_user(*capabilities) ⇒ Object
15 16 17 |
# File 'lib/gameplan/application.rb', line 15 def for_user(*capabilities) @capabilities = capabilities end |
#pending_state(name, desc, &blk) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/gameplan/application.rb', line 19 def pending_state(name, desc, &blk) raise "#{name} already exists" if @states[name] @last_state = @states[name] = PendingState.new(self, name, desc) @last_state.compile @last_state end |
#state(name, desc, &blk) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/gameplan/application.rb', line 26 def state(name, desc, &blk) raise "#{name} already exists" if @states[name] @last_state = @states[name] = State.new(self, name, desc, &blk) @last_state.compile @last_state end |
#validate ⇒ Object
40 41 42 43 |
# File 'lib/gameplan/application.rb', line 40 def validate add_error "For application #{name}, there are no states" if @states.empty? @states.values.each { |state| state.validate } end |