multi_ar 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e703260ff0896138cefe607320db98e5c020bbe0233117a518e833ae5afb0408
4
- data.tar.gz: 2a2d097579ffb99fd8735b4fe5c53aef110d5edabc47761375b0edcbc4f59174
3
+ metadata.gz: c2d35c65ac586a681d1ae51f3a61a6f98e79f47a467dbdd097d20f427a9b51f8
4
+ data.tar.gz: a169328e8a669ba95a69fd36fe0fc52c33a5f10f99fdb5186572bc8019fee43f
5
5
  SHA512:
6
- metadata.gz: 1c8c633fbdc59cd7d7bf4e01429956a602776f26bb726d2b26ef55985786c98e8cebfd960040dd540e5255d4405a227b805a5ed20859c10723d29cbaf81095d0
7
- data.tar.gz: 665b59f332f12c9c6ee82629fb07a7e06fb3e56dc3425433c1e6801672ad1db8b178465450c446168a4e6f8ad639f4717ccf620efa2c6a7383f5338c5cc8cd87
6
+ metadata.gz: 19a8273f4ba5bdb663f8b961eabc38bb19e90d2701b2573348350497c5d10637e58c226654279d8565dd36448ca6d97140b8526ae68e2c0e313cfaef7e3586a2
7
+ data.tar.gz: 3a93f3563be70937ba18b40056bc89e1969945b87915fcd4bf2dfe5e771dfd280bc99beb1c244271198613682db218cc5b74e893704334347aa06a6c4c695a34
checksums.yaml.gz.sig CHANGED
Binary file
@@ -140,11 +140,11 @@ module MultiAR
140
140
  opts[:databases] = parse_databases_input(@opts["databases"])
141
141
  opts[:environment] = @opts["environment"]
142
142
  opts[:verbose] = @opts["verbose"]
143
- opts[:migration_framework] = @migration_framework
144
143
  @multi_ar = MultiAR.new opts
145
144
  end
146
145
 
147
146
  def parse_databases_input databases
147
+ return if databases.nil?
148
148
  raise "You did not give proper databases. Please see --help for instructions." unless databases.respond_to? :each
149
149
 
150
150
  out = {}
@@ -1,4 +1,4 @@
1
1
 
2
2
  module MultiAR
3
- VERSION = "5.0.0"
3
+ VERSION = "5.1.0"
4
4
  end
data/lib/multi_ar.rb CHANGED
@@ -27,7 +27,7 @@ module MultiAR
27
27
 
28
28
  # @param databases array of available databases
29
29
  # @todo config file is overriding parameters passed here... I think it should be other way around, but need more custom logic for that :/
30
- def initialize databases:, environment: "development", config: "config/settings.yaml", db_config: "config/database.yaml", verbose: false, migration_framework: true
30
+ def initialize databases: nil, environment: "development", config: "config/settings.yaml", db_config: "config/database.yaml", verbose: false
31
31
 
32
32
  # first load config
33
33
  if not config.nil? and File.exist? config
@@ -35,27 +35,22 @@ module MultiAR
35
35
  config = Psych.load_file config
36
36
  b = binding
37
37
  config.each do |key, value|
38
- if key == "databases"
39
- out = {}
40
- value.each do |database|
41
- out[database["database"]] = database["migration_path"]
42
- end
43
- value = out
38
+ # If databases have been passed, we don’t have much reason to override it from config
39
+ if key != "databases" || databases.nil?
40
+ b.local_variable_set key.to_sym, value
44
41
  end
45
- b.local_variable_set key.to_sym, value
46
42
  end
47
43
  end
48
44
 
49
45
  # then check that we have data in format we want it to be
50
46
  raise "#{db_config} is not valid path to a file. Try specifying --db-config <path> or configuring it in the configuration file." if db_config.nil? or !File.exist?(db_config)
51
- raise "databases is not responding to :each. Try passing passing --databases <database> or configuring it in the configuration file." unless databases.respond_to? :each
47
+ #raise "databases is not responding to :each. Try passing passing --databases <database> or configuring it in the configuration file." unless databases.respond_to? :each
52
48
 
53
- parse_databases_input databases
49
+ parse_databases_input databases unless databases.nil?
54
50
 
55
51
  #@databases = databases
56
52
  @db_config = db_config
57
53
  @environment = environment
58
- @migration_framework = migration_framework
59
54
  #@@migration_dirs = migration_dirs unless migration_dirs.empty? # This takes care of that it will only be overridden if there is any given values, making default configs work
60
55
  #ActiveRecord::Tasks::DatabaseTasks.migrations_paths = migration_dirs
61
56
 
@@ -120,9 +115,11 @@ module MultiAR
120
115
  #
121
116
  # @note often you want to add full path to this dir, `__dir__` is useful for this.
122
117
  def self.add_database database_name, migration_path
123
- if @migration_framework
124
- raise "Migration dir #{migration_path} does not exist." unless Dir.exist? migration_path
118
+ raise "Migration dir #{migration_path} does not exist." unless Dir.exist? migration_path
119
+ begin
125
120
  ActiveRecord::Tasks::DatabaseTasks.migrations_paths << migration_path
121
+ rescue NameError
122
+ # multi_ar can be used without migration support, so adding a database to migration paths is only necessary when actually running migrations.
126
123
  end
127
124
  @@__databases[database_name] = migration_path
128
125
  end
@@ -144,12 +141,30 @@ module MultiAR
144
141
  @@__databases
145
142
  end
146
143
 
144
+ # TODO: remember to remove these if not needed...
145
+ # Helper to resolve a path to database
146
+ #def self.resolve_database_path
147
+
148
+ #end
149
+
150
+ #def self.resolve_databases_paths
151
+ #end
152
+
147
153
  private
148
154
 
155
+ # Supports three different input formats:
156
+ #
157
+ # 1. Array with strings of database names
158
+ # 2. Array with hashes of { "database" => "db_name", "migration_path" => "/path/to/migrations" }
159
+ # 3. Hash with key as database name and value as migration path
149
160
  def parse_databases_input dbs
150
161
  if dbs.kind_of? Array
151
162
  dbs.each do |database|
152
- ::MultiAR::MultiAR::add_database database, "db/migrate/#{database}"
163
+ if database.kind_of? Hash
164
+ ::MultiAR::MultiAR::add_database database["database"], database["migration_path"]
165
+ else
166
+ ::MultiAR::MultiAR::add_database database, "db/migrate/#{database}"
167
+ end
153
168
  end
154
169
  return
155
170
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samu Voutilainen
@@ -29,7 +29,7 @@ cert_chain:
29
29
  w7Q+3AEK9ifd9ywHO2Ott0JdJEadxhU4N0cI6bQg+uJiSYmdBK0vEJN4lhNg1w37
30
30
  C6hgCMQL3/D3kq732F4KGypqykYwx1wRDGHLxDTBHY26sy/TXfHcj4zPuKA=
31
31
  -----END CERTIFICATE-----
32
- date: 2018-07-04 00:00:00.000000000 Z
32
+ date: 2018-09-06 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: trollop
@@ -161,12 +161,10 @@ description: |-
161
161
  Core library for multi database support in any Ruby project for ActiveRecord.
162
162
  Migrations are supported by optional gem multi_ar_migrations.
163
163
  email: smar@smar.fi
164
- executables:
165
- - multi_ar
164
+ executables: []
166
165
  extensions: []
167
166
  extra_rdoc_files: []
168
167
  files:
169
- - bin/multi_ar
170
168
  - lib/multi_ar.rb
171
169
  - lib/multi_ar/database.rb
172
170
  - lib/multi_ar/interface.rb
metadata.gz.sig CHANGED
Binary file
data/bin/multi_ar DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative "../lib/multi_ar/interface"
4
-
5
- require_relative "../lib/multi_ar/version"
6
-
7
- interface = MultiAR::Interface.new
8
- interface.version = "multi_ar-#{MultiAR::VERSION}"
9
- interface.description = "Multi database migration tools utilizing ActiveRecord"
10
- interface.migration_framework = true
11
- opts = interface.cli do |parser|
12
- # Nya.
13
- end