Class: Gameplan::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/gameplan/flow.rb

Instance Method Summary collapse

Constructor Details

#initialize(plan, name, &blk) ⇒ Flow

Returns a new instance of Flow.



3
4
5
6
7
# File 'lib/gameplan/flow.rb', line 3

def initialize(plan, name, &blk)
  @plan = plan
  @name = name
  instance_eval(&blk) if blk
end

Instance Method Details

#apps(*apps) ⇒ Object Also known as: app



9
10
11
# File 'lib/gameplan/flow.rb', line 9

def apps(*apps)
  @apps = apps
end

#from(name) ⇒ Object



14
15
16
# File 'lib/gameplan/flow.rb', line 14

def from(name)
  @from = name
end

#steps(count) ⇒ Object



22
23
24
# File 'lib/gameplan/flow.rb', line 22

def steps(count)
  @step_count = count
end

#to(name) ⇒ Object



18
19
20
# File 'lib/gameplan/flow.rb', line 18

def to(name)
  @to = name
end

#traversable?(user) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gameplan/flow.rb', line 35

def traversable?(user)
  !traverse(user).empty?
end

#traverse(app, user) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/gameplan/flow.rb', line 26

def traverse(app, user)
  Enumerator.new do |yielder|
    @plan.apps.each do |app_name, app|
      initial_state = app.states[@from]
      initial_state.traverse(user, @to, @step_count, Transitions.new(yielder))
    end
  end
end