Class: Gameplan::Application

Inherits:
Object
  • Object
show all
Includes:
Describe
Defined in:
lib/gameplan/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_statesObject (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_stateObject (readonly)

Returns the value of attribute last_state.



5
6
7
# File 'lib/gameplan/application.rb', line 5

def last_state
  @last_state
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gameplan/application.rb', line 5

def name
  @name
end

#planObject (readonly)

Returns the value of attribute plan.



5
6
7
# File 'lib/gameplan/application.rb', line 5

def plan
  @plan
end

#pretty_nameObject (readonly)

Returns the value of attribute pretty_name.



5
6
7
# File 'lib/gameplan/application.rb', line 5

def pretty_name
  @pretty_name
end

#statesObject (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

#compileObject



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

#validateObject



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