Class: SchemaDev::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_dev/config.rb

Defined Under Namespace

Classes: Tuple

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

once we no longer support ruby 1.9.3, can switch to native keyword args



40
41
42
43
44
45
46
47
48
# File 'lib/schema_dev/config.rb', line 40

def initialize(opts={}) # once we no longer support ruby 1.9.3, can switch to native keyword args
  opts = opts.keyword_args(ruby: :required, rails: :required, db: nil, exclude: nil, notify: nil, quick: nil)
  @ruby = Array.wrap(opts.ruby)
  @rails = Array.wrap(opts.rails)
  @db = Array.wrap(opts.db)
  @exclude = Array.wrap(opts.exclude).map(&:symbolize_keys).map {|tuple| Tuple.new(tuple)}
  @notify = Array.wrap(opts.notify)
  @quick = Array.wrap(opts.quick || {ruby: @ruby.last, rails: @rails.last, db: @db.andand.last})
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



15
16
17
# File 'lib/schema_dev/config.rb', line 15

def db
  @db
end

#quickObject

Returns the value of attribute quick.



15
16
17
# File 'lib/schema_dev/config.rb', line 15

def quick
  @quick
end

Class Method Details

._resetObject

for use by rspec



17
# File 'lib/schema_dev/config.rb', line 17

def self._reset ; @@config = nil end

.loadObject



19
20
21
# File 'lib/schema_dev/config.rb', line 19

def self.load
  @@config ||= new((YAML.load Pathname.new(CONFIG_FILE).read).symbolize_keys)
end

Instance Method Details

#db?Boolean



50
51
52
# File 'lib/schema_dev/config.rb', line 50

def db?
  @db.any?
end

#matrix(opts = {}) ⇒ Object

once we no longer support ruby 1.9.3, can switch to native keyword args



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/schema_dev/config.rb', line 54

def matrix(opts={}) # once we no longer support ruby 1.9.3, can switch to native keyword args
  opts = opts.keyword_args(quick: false, ruby: nil, rails: nil, db: nil)
  use_ruby = @ruby
  use_rails = @rails
  use_db = @db
  if opts.quick
    use_ruby = @quick.map{|q| q[:ruby]}
    use_rails = @quick.map{|q| q[:rails]}
    use_db = @quick.map{|q| q[:db]}
  end
  use_ruby = Array.wrap(opts.ruby) if opts.ruby
  use_rails = Array.wrap(opts.rails) if opts.rails
  use_db = Array.wrap(opts.db) if opts.db

  @matrix ||= begin
                m = use_ruby.product(use_rails)
                m = m.product(use_db).map(&:flatten) if db?
                m = m.map { |_ruby, _rails, _db| Tuple.new(ruby: _ruby, rails: _rails, db: _db) }
                m.reject(&it.match_any?(@exclude)).map(&:to_hash)
              end
end