Sha256: 3620ec8a5ce4b9c6df66ebdb08a8af2fbf565d3d20bc034bc4a281cd48917f63

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

$:.unshift(File.expand_path('../../lib', __FILE__))

require 'dynflow'

class ExampleHelper
  class << self
    def world
      @world ||= create_world
    end

    def create_world
      config = Dynflow::Config.new
      config.persistence_adapter = persistence_adapter
      config.logger_adapter      = logger_adapter
      config.auto_rescue         = false
      yield config if block_given?
      Dynflow::World.new(config).tap do |world|
        puts "World #{world.id} started..."
      end
    end

    def persistence_conn_string
      ENV['DB_CONN_STRING'] || 'sqlite:/'
    end

    def persistence_adapter
      Dynflow::PersistenceAdapters::Sequel.new persistence_conn_string
    end

    def logger_adapter
      Dynflow::LoggerAdapters::Simple.new $stderr, 4
    end


    def run_web_console(world = ExampleHelper.world)
      require 'dynflow/web'
      dynflow_console = Dynflow::Web.setup do
        set :world, world
      end
      Rack::Server.new(:app => dynflow_console, :Port => 4567).start
    end

    # for simulation of the execution failing for the first time
    def something_should_fail!
      @should_fail = true
    end

    # for simulation of the execution failing for the first time
    def something_should_fail?
      @should_fail
    end

    def nothing_should_fail!
      @should_fail = false
    end

    def terminate
      @world.terminate.wait if @world
    end
  end
end

at_exit { ExampleHelper.terminate }

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dynflow-0.8.9 examples/example_helper.rb
dynflow-0.8.8 examples/example_helper.rb
dynflow-0.8.7 examples/example_helper.rb
dynflow-0.8.6 examples/example_helper.rb
dynflow-0.8.5 examples/example_helper.rb
dynflow-0.8.4 examples/example_helper.rb
dynflow-0.8.3 examples/example_helper.rb
dynflow-0.8.2 examples/example_helper.rb
dynflow-0.8.1 examples/example_helper.rb
dynflow-0.8.0 examples/example_helper.rb