ardb 0.29.1 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.l.yml +8 -0
  3. data/.rubocop.yml +3 -0
  4. data/.t.yml +6 -0
  5. data/Gemfile +4 -2
  6. data/ardb.gemspec +9 -6
  7. data/bin/ardb +2 -0
  8. data/lib/ardb.rb +75 -61
  9. data/lib/ardb/adapter/base.rb +40 -19
  10. data/lib/ardb/adapter/mysql.rb +2 -0
  11. data/lib/ardb/adapter/postgresql.rb +36 -25
  12. data/lib/ardb/adapter/sqlite.rb +7 -7
  13. data/lib/ardb/adapter_spy.rb +16 -14
  14. data/lib/ardb/cli.rb +23 -18
  15. data/lib/ardb/cli/clirb.rb +5 -0
  16. data/lib/ardb/cli/commands.rb +184 -95
  17. data/lib/ardb/db_tests.rb +2 -0
  18. data/lib/ardb/default_order_by.rb +13 -11
  19. data/lib/ardb/migration.rb +7 -4
  20. data/lib/ardb/record_spy.rb +42 -38
  21. data/lib/ardb/relation_spy.rb +27 -25
  22. data/lib/ardb/require_autoloaded_active_record_files.rb +3 -1
  23. data/lib/ardb/test_helpers.rb +11 -9
  24. data/lib/ardb/use_db_default.rb +9 -7
  25. data/lib/ardb/version.rb +3 -1
  26. data/script/determine_autoloaded_active_record_files.rb +22 -20
  27. data/test/helper.rb +2 -0
  28. data/test/support/factory.rb +2 -1
  29. data/test/support/fake_schema.rb +3 -1
  30. data/test/support/postgresql/schema.rb +3 -1
  31. data/test/support/postgresql/setup_test_db.rb +3 -1
  32. data/test/support/relative_require_test_db_file.rb +1 -0
  33. data/test/support/require_test_db_file.rb +1 -0
  34. data/test/unit/adapter/base_tests.rb +9 -5
  35. data/test/unit/adapter/mysql_tests.rb +2 -0
  36. data/test/unit/adapter/postgresql_tests.rb +14 -14
  37. data/test/unit/adapter/sqlite_tests.rb +2 -0
  38. data/test/unit/adapter_spy_tests.rb +4 -1
  39. data/test/unit/ardb_tests.rb +28 -13
  40. data/test/unit/cli_tests.rb +47 -34
  41. data/test/unit/db_tests_tests.rb +4 -1
  42. data/test/unit/default_order_by_tests.rb +18 -13
  43. data/test/unit/migration_tests.rb +8 -5
  44. data/test/unit/record_spy_tests.rb +21 -14
  45. data/test/unit/relation_spy_tests.rb +28 -22
  46. data/test/unit/test_helpers_tests.rb +4 -1
  47. data/test/unit/use_db_default_tests.rb +16 -7
  48. metadata +27 -11
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "ardb"
3
5
  require "ardb/adapter/base"
@@ -5,23 +7,21 @@ require "ardb/adapter/base"
5
7
  module Ardb::Adapter
6
8
  class Sqlite < Ardb::Adapter::Base
7
9
  def db_file_path
8
- File.expand_path(self.database, self.config.root_path)
10
+ File.expand_path(database, config.root_path)
9
11
  end
10
12
 
11
13
  def validate!
12
- if File.exist?(self.db_file_path)
13
- raise RuntimeError, "`#{self.database}` already exists"
14
- end
14
+ raise "`#{database}` already exists" if File.exist?(db_file_path)
15
15
  end
16
16
 
17
17
  def create_db
18
18
  validate!
19
- FileUtils.mkdir_p File.dirname(self.db_file_path)
20
- ActiveRecord::Base.establish_connection(self.connect_hash)
19
+ FileUtils.mkdir_p File.dirname(db_file_path)
20
+ ActiveRecord::Base.establish_connection(connect_hash)
21
21
  end
22
22
 
23
23
  def drop_db
24
- FileUtils.rm(self.db_file_path) if File.exist?(self.db_file_path)
24
+ FileUtils.rm(db_file_path) if File.exist?(db_file_path)
25
25
  end
26
26
  end
27
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ardb"
2
4
  require "ardb/adapter/base"
3
5
 
@@ -20,60 +22,60 @@ module Ardb
20
22
  end
21
23
 
22
24
  def create_db_called?
23
- self.create_db_called_count > 0
25
+ create_db_called_count > 0
24
26
  end
25
27
 
26
28
  def drop_db_called?
27
- self.drop_db_called_count > 0
29
+ drop_db_called_count > 0
28
30
  end
29
31
 
30
32
  def drop_tables_called?
31
- self.drop_tables_called_count > 0
33
+ drop_tables_called_count > 0
32
34
  end
33
35
 
34
36
  def connect_db_called?
35
- self.connect_db_called_count > 0
37
+ connect_db_called_count > 0
36
38
  end
37
39
 
38
40
  def migrate_db_called?
39
- self.migrate_db_called_count > 0
41
+ migrate_db_called_count > 0
40
42
  end
41
43
 
42
44
  def load_schema_called?
43
- self.load_schema_called_count > 0
45
+ load_schema_called_count > 0
44
46
  end
45
47
 
46
48
  def dump_schema_called?
47
- self.dump_schema_called_count > 0
49
+ dump_schema_called_count > 0
48
50
  end
49
51
 
50
52
  # Overwritten `Adapter::Base` methods
51
53
 
52
- def create_db(*args, &block)
54
+ def create_db(*_args)
53
55
  self.create_db_called_count += 1
54
56
  end
55
57
 
56
- def drop_db(*args, &block)
58
+ def drop_db(*_args)
57
59
  self.drop_db_called_count += 1
58
60
  end
59
61
 
60
- def drop_tables(*args, &block)
62
+ def drop_tables(*_args)
61
63
  self.drop_tables_called_count += 1
62
64
  end
63
65
 
64
- def connect_db(*args, &block)
66
+ def connect_db(*_args)
65
67
  self.connect_db_called_count += 1
66
68
  end
67
69
 
68
- def migrate_db(*args, &block)
70
+ def migrate_db(*_args)
69
71
  self.migrate_db_called_count += 1
70
72
  end
71
73
 
72
- def load_schema(*args, &block)
74
+ def load_schema(*_args)
73
75
  self.load_schema_called_count += 1
74
76
  end
75
77
 
76
- def dump_schema(*args, &block)
78
+ def dump_schema(*_args)
77
79
  self.dump_schema_called_count += 1
78
80
  end
79
81
  end
@@ -1,23 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ardb/cli/clirb"
2
4
  require "ardb/cli/commands"
3
5
  require "ardb/version"
4
6
 
5
7
  module Ardb
6
8
  class CLI
7
- COMMANDS = CommandSet.new{ |unknown| InvalidCommand.new(unknown) }.tap do |c|
8
- c.add(ConnectCommand)
9
- c.add(CreateCommand)
10
- c.add(DropCommand)
11
- c.add(GenerateMigrationCommand)
12
- c.add(MigrateCommand)
13
- c.add(MigrateUpCommand)
14
- c.add(MigrateDownCommand)
15
- c.add(MigrateForwardCommand)
16
- c.add(MigrateBackwardCommand)
17
- end
9
+ COMMANDS =
10
+ CommandSet.new{ |unknown|
11
+ InvalidCommand.new(unknown)
12
+ }.tap do |c|
13
+ c.add(ConnectCommand)
14
+ c.add(CreateCommand)
15
+ c.add(DropCommand)
16
+ c.add(GenerateMigrationCommand)
17
+ c.add(MigrateCommand)
18
+ c.add(MigrateUpCommand)
19
+ c.add(MigrateDownCommand)
20
+ c.add(MigrateForwardCommand)
21
+ c.add(MigrateBackwardCommand)
22
+ end
18
23
 
19
24
  def self.run(args)
20
- self.new.run(args)
25
+ new.run(args)
21
26
  end
22
27
 
23
28
  def initialize(kernel = nil, stdout = nil, stderr = nil)
@@ -37,16 +42,16 @@ module Ardb
37
42
  @stdout.puts cmd.command_help
38
43
  rescue CLIRB::VersionExit
39
44
  @stdout.puts Ardb::VERSION
40
- rescue CLIRB::Error, ArgumentError, InvalidCommandError => exception
41
- display_debug(exception)
42
- @stderr.puts "#{exception.message}\n\n"
45
+ rescue CLIRB::Error, ArgumentError, InvalidCommandError => ex
46
+ display_debug(ex)
47
+ @stderr.puts "#{ex.message}\n\n"
43
48
  @stdout.puts cmd.command_help
44
49
  @kernel.exit 1
45
50
  rescue CommandExitError
46
51
  @kernel.exit 1
47
- rescue StandardError => exception
48
- @stderr.puts "#{exception.class}: #{exception.message}"
49
- @stderr.puts exception.backtrace.join("\n")
52
+ rescue => ex
53
+ @stderr.puts "#{ex.class}: #{ex.message}"
54
+ @stderr.puts ex.backtrace.join("\n")
50
55
  @kernel.exit 1
51
56
  end
52
57
  @kernel.exit 0
@@ -1,4 +1,5 @@
1
1
  module Ardb; end
2
+
2
3
  class Ardb::CLI
3
4
  class CLIRB # Version 1.1.0, https://github.com/redding/cli.rb
4
5
  Error = Class.new(RuntimeError);
@@ -18,13 +19,16 @@ class Ardb::CLI
18
19
  end
19
20
 
20
21
  def option(*args); @options << Option.new(*args); end
22
+
21
23
  def parse!(argv)
22
24
  @args = (argv || []).dup.tap do |args_list|
23
25
  begin; @parser.parse!(args_list)
24
26
  rescue OptionParser::ParseError => err; raise Error, err.message; end
25
27
  end; @data = @args + [@opts]
26
28
  end
29
+
27
30
  def to_s; @parser.to_s; end
31
+
28
32
  def inspect
29
33
  "#<#{self.class}:#{"0x0%x" % (object_id << 1)} @data=#{@data.inspect}>"
30
34
  end
@@ -50,6 +54,7 @@ class Ardb::CLI
50
54
  custom_abbrev || processed_name.gsub(/[^a-z]/, "").chars.first || "a"
51
55
  ]
52
56
  end
57
+
53
58
  def gvalinfo(v); v.kind_of?(Class) ? [nil,v] : [v,v.class]; end
54
59
  end
55
60
  end
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ardb"
2
4
  require "ardb/cli/clirb"
3
- require "much-plugin"
5
+ require "much-mixin"
4
6
 
5
7
  module Ardb; end
8
+
6
9
  class Ardb::CLI
7
10
  InvalidCommandError = Class.new(ArgumentError)
8
11
  CommandExitError = Class.new(RuntimeError)
@@ -15,12 +18,14 @@ class Ardb::CLI
15
18
  @clirb = CLIRB.new
16
19
  end
17
20
 
18
- def new; self; end
21
+ def new
22
+ self
23
+ end
19
24
 
20
25
  def run(argv)
21
26
  @clirb.parse!([@name, argv].flatten.compact)
22
27
  raise CLIRB::HelpExit if @name.to_s.empty?
23
- raise InvalidCommandError, "\"#{self.name}\" is not a command."
28
+ raise InvalidCommandError, "\"#{name}\" is not a command."
24
29
  end
25
30
 
26
31
  def command_help
@@ -32,19 +37,26 @@ class Ardb::CLI
32
37
  end
33
38
 
34
39
  module ValidCommand
35
- include MuchPlugin
40
+ include MuchMixin
36
41
 
37
- plugin_class_methods do
38
- def command_name; raise NotImplementedError; end
39
- def command_summary; ""; end
42
+ mixin_class_methods do
43
+ def command_name
44
+ raise NotImplementedError
45
+ end
46
+
47
+ def command_summary
48
+ ""
49
+ end
40
50
  end
41
51
 
42
- plugin_instance_methods do
52
+ mixin_instance_methods do
43
53
  def initialize(&clirb_build)
44
54
  @clirb = CLIRB.new(&clirb_build)
45
55
  end
46
56
 
47
- def clirb; @clirb; end
57
+ def clirb
58
+ @clirb
59
+ end
48
60
 
49
61
  def run(argv, stdout = nil, stderr = nil)
50
62
  @clirb.parse!(argv)
@@ -52,14 +64,19 @@ class Ardb::CLI
52
64
  @stderr = stderr || $stderr
53
65
  end
54
66
 
55
- def command_name; self.class.command_name; end
56
- def command_summary; self.class.command_summary; end
67
+ def command_name
68
+ self.class.command_name
69
+ end
70
+
71
+ def command_summary
72
+ self.class.command_summary
73
+ end
57
74
 
58
75
  def command_help
59
- "Usage: ardb #{self.command_name} [options]\n\n" \
60
- "Options: #{self.clirb}\n" \
76
+ "Usage: ardb #{command_name} [options]\n\n" \
77
+ "Options: #{clirb}\n" \
61
78
  "Description:\n" \
62
- " #{self.command_summary}"
79
+ " #{command_summary}"
63
80
  end
64
81
  end
65
82
  end
@@ -67,8 +84,13 @@ class Ardb::CLI
67
84
  class ConnectCommand
68
85
  include ValidCommand
69
86
 
70
- def self.command_name; "connect"; end
71
- def self.command_summary; "Connect to the configured DB"; end
87
+ def self.command_name
88
+ "connect"
89
+ end
90
+
91
+ def self.command_summary
92
+ "Connect to the configured DB"
93
+ end
72
94
 
73
95
  def run(argv, *args)
74
96
  super
@@ -76,15 +98,21 @@ class Ardb::CLI
76
98
  begin
77
99
  Ardb.init(false)
78
100
  Ardb.adapter.connect_db
79
- @stdout.puts "connected to #{Ardb.config.adapter} db #{Ardb.config.database.inspect}"
80
- rescue ActiveRecord::NoDatabaseError => e
81
- @stderr.puts "error: database #{Ardb.config.database.inspect} "\
82
- "does not exist"
83
- rescue StandardError => e
84
- @stderr.puts e
85
- @stderr.puts e.backtrace.join("\n")
86
- @stderr.puts "error connecting to #{Ardb.config.database.inspect} database " \
87
- "with #{Ardb.config.activerecord_connect_hash.inspect}"
101
+ @stdout.puts(
102
+ "connected to #{Ardb.config.adapter} "\
103
+ "db #{Ardb.config.database.inspect}",
104
+ )
105
+ rescue ActiveRecord::NoDatabaseError
106
+ @stderr.puts(
107
+ "error: database #{Ardb.config.database.inspect} does not exist",
108
+ )
109
+ rescue => ex
110
+ @stderr.puts ex
111
+ @stderr.puts ex.backtrace.join("\n")
112
+ @stderr.puts(
113
+ "error connecting to #{Ardb.config.database.inspect} database " \
114
+ "with #{Ardb.config.activerecord_connect_hash.inspect}",
115
+ )
88
116
  raise CommandExitError
89
117
  end
90
118
  end
@@ -93,8 +121,13 @@ class Ardb::CLI
93
121
  class CreateCommand
94
122
  include ValidCommand
95
123
 
96
- def self.command_name; "create"; end
97
- def self.command_summary; "Create the configured DB"; end
124
+ def self.command_name
125
+ "create"
126
+ end
127
+
128
+ def self.command_summary
129
+ "Create the configured DB"
130
+ end
98
131
 
99
132
  def run(argv, *args)
100
133
  super
@@ -102,12 +135,15 @@ class Ardb::CLI
102
135
  begin
103
136
  Ardb.init(false)
104
137
  Ardb.adapter.create_db
105
- @stdout.puts "created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}"
106
- rescue ActiveRecord::StatementInvalid => e
107
- @stderr.puts "error: database #{Ardb.config.database.inspect} "\
108
- "already exists"
109
- rescue StandardError => e
110
- @stderr.puts e
138
+ @stdout.puts(
139
+ "created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}",
140
+ )
141
+ rescue ActiveRecord::StatementInvalid
142
+ @stderr.puts(
143
+ "error: database #{Ardb.config.database.inspect} already exists",
144
+ )
145
+ rescue => ex
146
+ @stderr.puts ex
111
147
  @stderr.puts "error creating #{Ardb.config.database.inspect} database"
112
148
  raise CommandExitError
113
149
  end
@@ -117,8 +153,13 @@ class Ardb::CLI
117
153
  class DropCommand
118
154
  include ValidCommand
119
155
 
120
- def self.command_name; "drop"; end
121
- def self.command_summary; "Drop the configured DB"; end
156
+ def self.command_name
157
+ "drop"
158
+ end
159
+
160
+ def self.command_summary
161
+ "Drop the configured DB"
162
+ end
122
163
 
123
164
  def run(argv, *args)
124
165
  super
@@ -126,12 +167,15 @@ class Ardb::CLI
126
167
  begin
127
168
  Ardb.init(true)
128
169
  Ardb.adapter.drop_db
129
- @stdout.puts "dropped #{Ardb.config.adapter} db #{Ardb.config.database.inspect}"
130
- rescue ActiveRecord::NoDatabaseError => e
131
- @stderr.puts "error: database #{Ardb.config.database.inspect} "\
132
- "does not exist"
133
- rescue StandardError => e
134
- @stderr.puts e
170
+ @stdout.puts(
171
+ "dropped #{Ardb.config.adapter} db #{Ardb.config.database.inspect}",
172
+ )
173
+ rescue ActiveRecord::NoDatabaseError
174
+ @stderr.puts(
175
+ "error: database #{Ardb.config.database.inspect} does not exist",
176
+ )
177
+ rescue => ex
178
+ @stderr.puts ex
135
179
  @stderr.puts "error dropping #{Ardb.config.database.inspect} database"
136
180
  raise CommandExitError
137
181
  end
@@ -141,8 +185,13 @@ class Ardb::CLI
141
185
  class GenerateMigrationCommand
142
186
  include ValidCommand
143
187
 
144
- def self.command_name; "generate-migration"; end
145
- def self.command_summary; "Generate a MIGRATION-NAME migration file"; end
188
+ def self.command_name
189
+ "generate-migration"
190
+ end
191
+
192
+ def self.command_summary
193
+ "Generate a MIGRATION-NAME migration file"
194
+ end
146
195
 
147
196
  def run(argv, *args)
148
197
  super
@@ -154,50 +203,55 @@ class Ardb::CLI
154
203
  migration = Ardb::Migration.new(Ardb.config, @clirb.args.first)
155
204
  migration.save!
156
205
  @stdout.puts "generated #{migration.file_path}"
157
- rescue Ardb::Migration::NoIdentifierError => exception
206
+ rescue Ardb::Migration::NoIdentifierError => ex
158
207
  error = ArgumentError.new("MIGRATION-NAME must be provided")
159
- error.set_backtrace(exception.backtrace)
208
+ error.set_backtrace(ex.backtrace)
160
209
  raise error
161
- rescue StandardError => e
162
- @stderr.puts e
163
- @stderr.puts e.backtrace.join("\n")
210
+ rescue => ex
211
+ @stderr.puts ex
212
+ @stderr.puts ex.backtrace.join("\n")
164
213
  @stderr.puts "error generating migration"
165
214
  raise CommandExitError
166
215
  end
167
216
  end
168
217
 
169
218
  def command_help
170
- "Usage: ardb #{self.command_name} MIGRATION-NAME [options]\n\n" \
171
- "Options: #{self.clirb}\n" \
219
+ "Usage: ardb #{command_name} MIGRATION-NAME [options]\n\n" \
220
+ "Options: #{clirb}\n" \
172
221
  "Description:\n" \
173
- " #{self.command_summary}"
222
+ " #{command_summary}"
174
223
  end
175
224
  end
176
225
 
177
226
  module MigrateCommandBehaviors
178
- include MuchPlugin
227
+ include MuchMixin
179
228
 
180
- plugin_included do
229
+ mixin_included do
181
230
  include ValidCommand
182
231
  end
183
232
 
184
- plugin_instance_methods do
185
- def migrate; raise NotImplementedError; end
233
+ mixin_instance_methods do
234
+ def migrate
235
+ raise NotImplementedError
236
+ end
186
237
 
187
238
  def run(argv, *args)
188
239
  super
189
240
 
190
241
  begin
191
242
  Ardb.init(true)
192
- self.migrate
243
+ migrate
193
244
  Ardb.adapter.dump_schema unless ENV["ARDB_MIGRATE_NO_SCHEMA"]
194
- rescue ActiveRecord::NoDatabaseError => e
195
- @stderr.puts "error: database #{Ardb.config.database.inspect} "\
196
- "does not exist"
197
- rescue StandardError => e
198
- @stderr.puts e
199
- @stderr.puts e.backtrace.join("\n")
200
- @stderr.puts "error migrating #{Ardb.config.database.inspect} database"
245
+ rescue ActiveRecord::NoDatabaseError
246
+ @stderr.puts(
247
+ "error: database #{Ardb.config.database.inspect} does not exist",
248
+ )
249
+ rescue => ex
250
+ @stderr.puts ex
251
+ @stderr.puts ex.backtrace.join("\n")
252
+ @stderr.puts(
253
+ "error migrating #{Ardb.config.database.inspect} database",
254
+ )
201
255
  raise CommandExitError
202
256
  end
203
257
  end
@@ -207,8 +261,13 @@ class Ardb::CLI
207
261
  class MigrateCommand
208
262
  include MigrateCommandBehaviors
209
263
 
210
- def self.command_name; "migrate"; end
211
- def self.command_summary; "Migrate the configured DB"; end
264
+ def self.command_name
265
+ "migrate"
266
+ end
267
+
268
+ def self.command_summary
269
+ "Migrate the configured DB"
270
+ end
212
271
 
213
272
  def migrate
214
273
  Ardb.adapter.migrate_db
@@ -216,43 +275,60 @@ class Ardb::CLI
216
275
  end
217
276
 
218
277
  module MigrateStyleBehaviors
219
- include MuchPlugin
278
+ include MuchMixin
220
279
 
221
- plugin_included do
280
+ mixin_included do
222
281
  include MigrateCommandBehaviors
223
282
  end
224
283
 
225
- plugin_class_methods do
226
- def command_style; raise NotImplementedError; end
284
+ mixin_class_methods do
285
+ def command_style
286
+ raise NotImplementedError
287
+ end
227
288
 
228
- def command_name; "migrate-#{self.command_style}"; end
229
- def command_summary; "Migrate the configured DB #{self.command_style}"; end
289
+ def command_name
290
+ "migrate-#{command_style}"
291
+ end
292
+
293
+ def command_summary
294
+ "Migrate the configured DB #{command_style}"
295
+ end
230
296
  end
231
297
 
232
- plugin_instance_methods do
298
+ mixin_instance_methods do
233
299
  def migrate
234
- Ardb.adapter.send("migrate_db_#{self.class.command_style}", *migrate_args)
300
+ Ardb.adapter.send(
301
+ "migrate_db_#{self.class.command_style}",
302
+ *migrate_args,
303
+ )
235
304
  end
236
305
 
237
306
  private
238
307
 
239
- def migrate_args; raise NotImplementedError; end
308
+ def migrate_args
309
+ raise NotImplementedError
310
+ end
240
311
  end
241
312
  end
242
313
 
243
314
  module MigrateDirectionBehaviors
244
- include MuchPlugin
315
+ include MuchMixin
245
316
 
246
- plugin_included do
317
+ mixin_included do
247
318
  include MigrateStyleBehaviors
248
319
  end
249
320
 
250
- plugin_class_methods do
251
- def command_style; self.command_direction; end
252
- def command_direction; raise NotImplementedError; end
321
+ mixin_class_methods do
322
+ def command_style
323
+ command_direction
324
+ end
325
+
326
+ def command_direction
327
+ raise NotImplementedError
328
+ end
253
329
  end
254
330
 
255
- plugin_instance_methods do
331
+ mixin_instance_methods do
256
332
  def initialize
257
333
  super do
258
334
  option(:target_version, "version to migrate to", value: String)
@@ -268,18 +344,23 @@ class Ardb::CLI
268
344
  end
269
345
 
270
346
  module MigrateStepDirectionBehaviors
271
- include MuchPlugin
347
+ include MuchMixin
272
348
 
273
- plugin_included do
349
+ mixin_included do
274
350
  include MigrateStyleBehaviors
275
351
  end
276
352
 
277
- plugin_class_methods do
278
- def command_style; self.command_direction; end
279
- def command_direction; raise NotImplementedError; end
353
+ mixin_class_methods do
354
+ def command_style
355
+ command_direction
356
+ end
357
+
358
+ def command_direction
359
+ raise NotImplementedError
360
+ end
280
361
  end
281
362
 
282
- plugin_instance_methods do
363
+ mixin_instance_methods do
283
364
  def initialize
284
365
  super do
285
366
  option(:steps, "number of migrations to migrate", value: 1)
@@ -297,30 +378,38 @@ class Ardb::CLI
297
378
  class MigrateUpCommand
298
379
  include MigrateDirectionBehaviors
299
380
 
300
- def self.command_direction; "up"; end
381
+ def self.command_direction
382
+ "up"
383
+ end
301
384
  end
302
385
 
303
386
  class MigrateDownCommand
304
387
  include MigrateDirectionBehaviors
305
388
 
306
- def self.command_direction; "down"; end
389
+ def self.command_direction
390
+ "down"
391
+ end
307
392
  end
308
393
 
309
394
  class MigrateForwardCommand
310
395
  include MigrateStepDirectionBehaviors
311
396
 
312
- def self.command_direction; "forward"; end
397
+ def self.command_direction
398
+ "forward"
399
+ end
313
400
  end
314
401
 
315
402
  class MigrateBackwardCommand
316
403
  include MigrateStepDirectionBehaviors
317
404
 
318
- def self.command_direction; "backward"; end
405
+ def self.command_direction
406
+ "backward"
407
+ end
319
408
  end
320
409
 
321
410
  class CommandSet
322
411
  def initialize(&unknown_cmd_block)
323
- @lookup = Hash.new{ |h,k| unknown_cmd_block.call(k) }
412
+ @lookup = Hash.new{ |_h, k| unknown_cmd_block.call(k) }
324
413
  @names = []
325
414
  @aliases = {}
326
415
  @summaries = {}
@@ -329,7 +418,7 @@ class Ardb::CLI
329
418
  def add(klass)
330
419
  begin
331
420
  cmd = klass.new
332
- rescue StandardError
421
+ rescue
333
422
  # don"t add any commands you can"t initialize
334
423
  else
335
424
  @lookup[cmd.command_name] = cmd
@@ -355,11 +444,11 @@ class Ardb::CLI
355
444
  end
356
445
 
357
446
  def to_s
358
- max_name_size = @names.map{ |n| n.size }.max || 0
447
+ max_name_size = @names.map(&:size).max || 0
359
448
 
360
- @to_s ||= @names.map do |n|
449
+ @to_s ||= @names.map{ |n|
361
450
  "#{n.ljust(max_name_size)} #{@summaries[n]}"
362
- end.join("\n")
451
+ }.join("\n")
363
452
  end
364
453
  end
365
454
  end