Class: SchemaDev::Config
- Inherits:
-
Object
- Object
- SchemaDev::Config
- Defined in:
- lib/schema_dev/config.rb
Defined Under Namespace
Classes: Tuple
Constant Summary collapse
- DB_VERSION_DEFAULTS =
{ postgresql: ['9.6'] }.freeze
Instance Attribute Summary collapse
-
#activerecord ⇒ Object
Returns the value of attribute activerecord.
-
#db ⇒ Object
Returns the value of attribute db.
-
#dbversions ⇒ Object
Returns the value of attribute dbversions.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#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
- #db_versions_for(db) ⇒ Object
- #dbms ⇒ Object
-
#initialize(ruby:, activerecord:, db:, dbversions: nil, exclude: nil, notify: nil, quick: nil) ⇒ Config
constructor
A new instance of Config.
- #matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil, with_dbversion: false) ⇒ Object
Constructor Details
#initialize(ruby:, activerecord:, db:, dbversions: nil, exclude: nil, notify: nil, quick: nil) ⇒ Config
Returns a new instance of Config.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/schema_dev/config.rb', line 27 def initialize(ruby:, activerecord:, db:, dbversions: nil, exclude: nil, notify: nil, quick: nil) @ruby = Array.wrap(ruby).map(&:to_s) @activerecord = Array.wrap(activerecord).map(&:to_s) @db = Array.wrap(db) @dbversions = (dbversions || {}).symbolize_keys @exclude = Array.wrap(exclude).map(&:symbolize_keys).map { |tuple| Tuple.new(**tuple.transform_values(&:to_s)) } if @activerecord.include?('5.2') ruby3 = ::Gem::Version.new('3.0') @ruby.select { |e| ::Gem::Version.new(e) >= ruby3 }.each do |v| @exclude << Tuple.new(ruby: v, activerecord: '5.2') end end unless notify.nil? warn 'Notify is no longer supported' end @quick = Array.wrap(quick || { ruby: @ruby.last, activerecord: @activerecord.last, db: @db.last }) end |
Instance Attribute Details
#activerecord ⇒ Object
Returns the value of attribute activerecord.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def activerecord @activerecord end |
#db ⇒ Object
Returns the value of attribute db.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def db @db end |
#dbversions ⇒ Object
Returns the value of attribute dbversions.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def dbversions @dbversions end |
#exclude ⇒ Object
Returns the value of attribute exclude.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def exclude @exclude end |
#quick ⇒ Object
Returns the value of attribute quick.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def quick @quick end |
#ruby ⇒ Object
Returns the value of attribute ruby.
12 13 14 |
# File 'lib/schema_dev/config.rb', line 12 def ruby @ruby end |
Class Method Details
._reset ⇒ Object
for use by rspec
15 16 17 |
# File 'lib/schema_dev/config.rb', line 15 def self._reset @load = nil end |
.load ⇒ Object
23 24 25 |
# File 'lib/schema_dev/config.rb', line 23 def self.load @load ||= read end |
.read ⇒ Object
19 20 21 |
# File 'lib/schema_dev/config.rb', line 19 def self.read new(**YAML.safe_load(Pathname.new(CONFIG_FILE).read, [Symbol]).symbolize_keys) end |
Instance Method Details
#db_versions_for(db) ⇒ Object
54 55 56 |
# File 'lib/schema_dev/config.rb', line 54 def db_versions_for(db) @dbversions.fetch(db.to_sym, DB_VERSION_DEFAULTS.fetch(db.to_sym, [])).map(&:to_s) end |
#dbms ⇒ Object
46 47 48 |
# File 'lib/schema_dev/config.rb', line 46 def dbms @dbms ||= i[postgresql mysql].select { |dbm| @db.grep(/^#{dbm}/).any? } end |
#matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil, with_dbversion: false) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/schema_dev/config.rb', line 58 def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil, with_dbversion: false) use_ruby = @ruby use_activerecord = @activerecord use_db = @db if 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(ruby) if ruby use_activerecord = Array.wrap(activerecord) if activerecord use_db = Array.wrap(db) if 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.flat_map do |loop_ruby, loop_activerecord, loop_db| if with_dbversion && !(dbversions = db_versions_for(loop_db)).empty? dbversions.map { |v| Tuple.new(ruby: loop_ruby, activerecord: loop_activerecord, db: loop_db, dbversion: v) } else [Tuple.new(ruby: loop_ruby, activerecord: loop_activerecord, db: loop_db)] end end.compact m = m.reject { |r| r.match_any?(@exclude) } unless excluded == :none m = m.map(&:to_hash) if excluded == :only matrix(quick: quick, ruby: ruby, activerecord: activerecord, db: db, with_dbversion: with_dbversion, excluded: :none) - m else m end end |