Sha256: a103d9786f881bd3f54c008a8a601f012b37410498d50ca3437a3aec45a67f58

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 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, :cache)

  @database = nil
  @mode = nil
  @reflections = nil
  @anchors = nil
  @fail_fast = nil
  @ignore = nil
  @cache = 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.cache() @cache end

  def self.configure(&block)
    config = Config.new(@database, DEFAULT_MODE, nil, nil, DEFAULT_FAIL_FAST, DEFAULT_IGNORE, nil)
    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?
    @cache = config.cache
    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, cache: cache)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
postspec-0.5.5 lib/postspec/config.rb
postspec-0.5.4 lib/postspec/config.rb
postspec-0.5.3 lib/postspec/config.rb
postspec-0.5.2 lib/postspec/config.rb
postspec-0.5.1 lib/postspec/config.rb
postspec-0.5.0 lib/postspec/config.rb
postspec-0.4.1 lib/postspec/config.rb
postspec-0.4.0 lib/postspec/config.rb