Class: Seam::Flow

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFlow

Returns a new instance of Flow.



6
7
8
9
# File 'lib/seam/flow.rb', line 6

def initialize
  @steps = []
  @stamp_data_history = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



11
12
13
14
15
# File 'lib/seam/flow.rb', line 11

def method_missing(meth, *args, &blk)
  meth = meth.to_s
  @steps << { name: meth, arguments: args }
  true
end

Instance Attribute Details

#stamp_data_historyObject

Returns the value of attribute stamp_data_history.



4
5
6
# File 'lib/seam/flow.rb', line 4

def stamp_data_history
  @stamp_data_history
end

Instance Method Details

#start(data = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/seam/flow.rb', line 17

def start(data = {})
  Seam::Effort.create( {
                         id:              SecureRandom.uuid.to_s,
                         created_at:      Time.parse(Time.now.to_s),
                         next_execute_at: Time.parse(Time.now.to_s),
                         next_step:       self.steps.first.name.to_s,
                         flow:            the_flow_from,
                         data:            ActiveSupport::HashWithIndifferentAccess.new(data)
                       } )
end

#stepsObject



44
45
46
47
48
49
50
51
# File 'lib/seam/flow.rb', line 44

def steps
  @steps.each.map do |step|
    Seam::Step.new( { name:      step[:name],
                      type:      'do',
                      arguments: step[:arguments] } )

  end
end

#the_flow_fromObject



28
29
30
31
32
33
34
35
# File 'lib/seam/flow.rb', line 28

def the_flow_from
  hash = self.to_hash
  flow = ActiveSupport::HashWithIndifferentAccess.new hash
  flow['steps'].each do |step|
    step['id'] = SecureRandom.uuid.to_s
  end
  flow
end

#to_hashObject



37
38
39
40
41
42
# File 'lib/seam/flow.rb', line 37

def to_hash
  { 
    steps: self.steps.map { |x| x.to_hash },
    stamp_data_history: @stamp_data_history
  }
end