latest_migration 0.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 792e6fd9e2242e833f766eef2f4a90ee606033b8
4
- data.tar.gz: 640e3f31d966dc8a7f9d4d8da147a9675056b825
3
+ metadata.gz: 867c900a2a79606c355eb0d568b55103a4d11dbb
4
+ data.tar.gz: b5b8edb6bc56498eef6b6b7d1eb1a74298d22f9b
5
5
  SHA512:
6
- metadata.gz: 52b685812e7870c45e000dc5812071aa2280f85e3682a1448268029d23203599ba1bd62b50aadfa7c63c72a23617f4dc512b1462c9fb9027aac5cd33593a69e1
7
- data.tar.gz: c36693c2207f6d575d0de392ee13f0af93928ebe5bd3d82c9b7c3d0582ba6ab156156d227ad458da1ee6600d4d5dce29672ed83b23694950d8b9b791a82a1e34
6
+ metadata.gz: a8b37003fec74d8316f2fdf89011c7ab88900e70e6822dcfb812fa27a120558041bcddc266ab48cfefce2603f8e6d54c1bcfa951467dbd85b022a4178cd135c1
7
+ data.tar.gz: 916bdae822957e8475ef67b39ff40c07f4432a5ba3d021bf98042a82ecd21f71c8313a7c1822bcc6160a7c0a8a00683c380e2c57f56eab9efa7d3724fe6ce937
data/README.md CHANGED
@@ -3,13 +3,13 @@
3
3
  # latest_migration
4
4
 
5
5
  `latest_migration` is a Ruby on Rails gem that allows you to open your latest
6
- migration file in text editor. It saves the time of selecting, copying
6
+ migration file in text editor. It saves the time of selecting, copying
7
7
  and opening the file in your editor.
8
8
 
9
9
  ## Installation
10
10
  * Add `latest_migration` to your Gemfile:
11
11
  ```ruby
12
- gem 'latest_migration', group: development
12
+ gem 'latest_migration', group: :development
13
13
  ```
14
14
 
15
15
  * Install with: bundle install
@@ -1,5 +1,5 @@
1
1
  module LatestMigration
2
- require "latest_migration/railtie" if defined?(Rails)
3
2
  require "latest_migration/base"
4
3
  require "latest_migration/errors"
4
+ require "latest_migration/railtie" if defined?(Rails) or fail LatestMigration::Errors::RailsNotFound
5
5
  end
@@ -4,12 +4,13 @@ module LatestMigration
4
4
  def open_latest_migration
5
5
  puts "Opening #{latest_migration_filename}"
6
6
  system editor_command
7
- rescue LatestMigration::Errors::MigrationsNotFoundError
8
- puts "Could not find any migration in this Rails application"
7
+ rescue LatestMigration::Errors::MigrationsNotFoundError => e
8
+ puts e
9
9
  end
10
10
 
11
11
  def latest_migration_path
12
- migrations_filenames.sort.last or fail LatestMigration::Errors::MigrationsNotFoundError
12
+ filename = latest_migration_filename
13
+ File.join(Rails.root, filename)
13
14
  end
14
15
 
15
16
  def editor
@@ -20,25 +21,13 @@ module LatestMigration
20
21
 
21
22
  private
22
23
 
23
- def latest_migration_filename
24
- File.basename(latest_migration_path)
25
- end
26
-
27
24
  def editor_command
28
25
  "#{editor} #{latest_migration_path}"
29
26
  end
30
27
 
31
- def migrations_filenames
32
- Dir.glob(migrations_filename_pattern)
33
- end
34
-
35
- def migrations_filename_pattern
36
- File.join(migrations_dir_path, "*.rb")
37
- end
38
-
39
- def migrations_dir_path
40
- dir_path = Rails.root.join("db", "migrate") if defined?(Rails) or fail LatestMigration::Errors::RailsNotFound
41
- dir_path if Dir.exist?(dir_path) or fail LatestMigration::Errors::MigrationsDirNotFoundError
28
+ def latest_migration_filename
29
+ filename = ActiveRecord::Migrator.migrations(ActiveRecord::Migrator.migrations_path).last.try(:filename)
30
+ filename or fail LatestMigration::Errors::MigrationsNotFoundError
42
31
  end
43
32
  end
44
33
  end
@@ -1,20 +1,14 @@
1
1
  module LatestMigration
2
2
  module Errors
3
3
  class MigrationsNotFoundError < StandardError
4
- def message
5
- "Could not find any migration in this Rails application"
6
- end
7
- end
8
-
9
- class MigrationsDirNotFoundError < StandardError
10
- def message
11
- "Could not find migrations directory in this Rails application"
4
+ def initialize
5
+ super("Could not find any migration in this Rails application")
12
6
  end
13
7
  end
14
8
 
15
9
  class RailsNotFound < StandardError
16
- def message
17
- "Could not load Rails environment"
10
+ def initialize
11
+ super("Could not load Rails environment")
18
12
  end
19
13
  end
20
14
  end
@@ -1,3 +1,3 @@
1
1
  module LatestMigration
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latest_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiusz Fal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-01 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails