Sha256: 6aa57018d27f2811ee28dd8f7917f7769be6c33c5bcb59722414a529800884f2

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Seam
  class Flow

    attr_accessor :stamp_data_history

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

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

    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:            ActiveSupport::HashWithIndifferentAccess.new(self.to_hash),
                             data:            ActiveSupport::HashWithIndifferentAccess.new(data)
                           } )
    end

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

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

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seam-0.0.17 lib/seam/flow.rb
seam-0.0.16 lib/seam/flow.rb
seam-0.0.15 lib/seam/flow.rb