Class: SchemaDev::Config
- Inherits:
-
Object
- Object
- SchemaDev::Config
- Defined in:
- lib/schema_dev/config.rb
Defined Under Namespace
Classes: Tuple
Instance Attribute Summary collapse
-
#activerecord ⇒ Object
Returns the value of attribute activerecord.
-
#db ⇒ Object
Returns the value of attribute db.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#notify ⇒ Object
Returns the value of attribute notify.
-
#quick ⇒ Object
Returns the value of attribute quick.
-
#ruby ⇒ Object
Returns the value of attribute ruby.
Class Method Summary collapse
-
._reset ⇒ Object
for use by rspec.
- .load ⇒ Object
- .read ⇒ Object
Instance Method Summary collapse
- #dbms ⇒ Object
-
#initialize(opts = {}) ⇒ Config
constructor
once we no longer support ruby 1.9.3, can switch to native keyword args.
-
#matrix(opts = {}) ⇒ Object
once we no longer support ruby 1.9.3, can switch to native keyword args.
Constructor Details
#initialize(opts = {}) ⇒ Config
once we no longer support ruby 1.9.3, can switch to native keyword args
27 28 29 30 31 32 33 34 35 |
# File 'lib/schema_dev/config.rb', line 27 def initialize(opts={}) # once we no longer support ruby 1.9.3, can switch to native keyword args opts = opts.keyword_args(ruby: :required, activerecord: :required, db: :required, exclude: nil, notify: nil, quick: nil) @ruby = Array.wrap(opts.ruby) @activerecord = Array.wrap(opts.activerecord) @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, activerecord: @activerecord.last, db: @db.last}) end |
Instance Attribute Details
#activerecord ⇒ Object
Returns the value of attribute activerecord.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def activerecord @activerecord end |
#db ⇒ Object
Returns the value of attribute db.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def db @db end |
#exclude ⇒ Object
Returns the value of attribute exclude.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def exclude @exclude end |
#notify ⇒ Object
Returns the value of attribute notify.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def notify @notify end |
#quick ⇒ Object
Returns the value of attribute quick.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def quick @quick end |
#ruby ⇒ Object
Returns the value of attribute ruby.
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def ruby @ruby end |
Class Method Details
._reset ⇒ Object
for use by rspec
17 |
# File 'lib/schema_dev/config.rb', line 17 def self._reset ; @@config = nil end |
.load ⇒ Object
23 24 25 |
# File 'lib/schema_dev/config.rb', line 23 def self.load @@config ||= read end |
.read ⇒ Object
19 20 21 |
# File 'lib/schema_dev/config.rb', line 19 def self.read new((YAML.load Pathname.new(CONFIG_FILE).read).symbolize_keys) end |
Instance Method Details
#dbms ⇒ Object
37 38 39 |
# File 'lib/schema_dev/config.rb', line 37 def dbms @dbms ||= [:postgresql, :mysql].select{|dbm| @db.grep(/^#{dbm}/).any?} end |
#matrix(opts = {}) ⇒ Object
once we no longer support ruby 1.9.3, can switch to native keyword args
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/schema_dev/config.rb', line 41 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, activerecord: nil, db: nil, excluded: nil) use_ruby = @ruby use_activerecord = @activerecord use_db = @db if opts.quick use_ruby = @quick.map{|q| q[:ruby]} use_activerecord = @quick.map{|q| q[:activerecord]} use_db = @quick.map{|q| q[:db]} end use_ruby = Array.wrap(opts.ruby) if opts.ruby use_activerecord = Array.wrap(opts.activerecord) if opts.activerecord use_db = Array.wrap(opts.db) if opts.db use_ruby = [nil] unless use_ruby.any? use_activerecord = [nil] unless use_activerecord.any? use_db = [nil] unless use_db.any? m = use_ruby.product(use_activerecord, use_db) m = m.map { |_ruby, _activerecord, _db| Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db) }.compact m = m.reject(&it.match_any?(@exclude)) unless opts.excluded == :none m = m.map(&:to_hash) if opts.excluded == :only return matrix(opts.merge(excluded: :none)) - m else return m end end |