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.
6 7 8 |
# File 'lib/guard/migrate/migration.rb', line 6 def initialize(_path) @path = _path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/guard/migrate/migration.rb', line 4 def path @path end |
Instance Method Details
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 22 |
# File 'lib/guard/migrate/migration.rb', line 14 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
10 11 12 |
# File 'lib/guard/migrate/migration.rb', line 10 def version path.scan(%r{^db/migrate/(\d+).+\.rb}).flatten.first end |