Sha256: 352a4f92c54d203875ee07b31556c7ff073b0a3c75899035535ef18b30ea096b

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

# Used to initialize postspec from spec/spec_helper.rb or spec/postspec_helper.rb
#
module Postspec
  Config = Struct.new(:database, :mode, :reflections, :anchors, :fail_fast, :ignore)

  @database = nil
  @mode = nil
  @reflections = nil
  @anchors = nil
  @fail_fast = nil
  @ignore = nil

  DEFAULT_MODE = :empty
  DEFAULT_FAIL_FAST = true
  DEFAULT_IGNORE = []

  def self.database() @database end
  def self.mode() @mode end
  def self.reflections() @reflections end
  def self.anchors() @anchors end
  def self.fail_fast() @fail_fast end
  def self.ignore() @ignore end

  def self.configure(&block)
    config = Config.new(@database, DEFAULT_MODE, nil, nil, DEFAULT_FAIL_FAST, DEFAULT_IGNORE)
    yield(config)
    @database = config.database
    @mode = config.mode || DEFAULT_MODE
    @reflections = config.reflections
    @anchors = config.anchors
    @fail_fast = config.fail_fast || DEFAULT_FAIL_FAST
    @ignore = config.ignore || DEFAULT_IGNORE # FIXME: Why not rely on Config defaults?
    self
  end

  def self.postspec()
    !@database.nil? or raise Error, "Database unspecified"
    @postspec ||= Postspec.new(
        PgConn.new(@database), 
        mode: mode, reflector: @reflections, anchors: @anchors, fail: @fail_fast, ignore: @ignore)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
postspec-0.2.5 lib/postspec/config.rb
postspec-0.2.4 lib/postspec/config.rb
postspec-0.2.3 lib/postspec/config.rb
postspec-0.2.2 lib/postspec/config.rb
postspec-0.2.1 lib/postspec/config.rb
postspec-0.2.0 lib/postspec/config.rb
postspec-0.1.2 lib/postspec/config.rb