Class: Guard::Migrate::Migration
- Inherits:
-
Object
- Object
- Guard::Migrate::Migration
- Defined in:
- lib/guard/migrate/migration.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(_path) ⇒ Migration
constructor
A new instance of Migration.
- #valid? ⇒ Boolean
- #version ⇒ Object
Constructor Details
#initialize(_path) ⇒ Migration
Returns a new instance of Migration.
7 8 9 |
# File 'lib/guard/migrate/migration.rb', line 7 def initialize(_path) @path = _path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/guard/migrate/migration.rb', line 5 def path @path end |
Instance Method Details
#valid? ⇒ Boolean
15 16 17 18 19 20 21 22 23 |
# File 'lib/guard/migrate/migration.rb', line 15 def valid? file = File.open(path, 'r') content = file.read.gsub(/\s+/, '') !content.empty? && content.match(/def(up|down|change)end/).nil? rescue Errno::ENOENT false ensure begin; file.close; rescue; end end |
#version ⇒ Object
11 12 13 |
# File 'lib/guard/migrate/migration.rb', line 11 def version path.scan(%r{^db/migrate/(\d+).+\.rb}).flatten.first end |