Class: Mongration::File
- Inherits:
-
Object
- Object
- Mongration::File
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/mongration/file.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Class Method Summary collapse
- .all ⇒ Object
- .all_file_names ⇒ Object
- .last ⇒ Object
- .migrated ⇒ Object
- .migrated_file_names ⇒ Object
- .pending ⇒ Object
- .wrap(file_names) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #_load ⇒ Object
- #class_name ⇒ Object
-
#initialize(file_name) ⇒ File
constructor
A new instance of File.
- #klass ⇒ Object
- #load ⇒ Object
- #name ⇒ Object
- #number ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(file_name) ⇒ File
Returns a new instance of File.
42 43 44 |
# File 'lib/mongration/file.rb', line 42 def initialize(file_name) @file_name = file_name end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
40 41 42 |
# File 'lib/mongration/file.rb', line 40 def file_name @file_name end |
Class Method Details
.all ⇒ Object
28 29 30 |
# File 'lib/mongration/file.rb', line 28 def self.all pending + migrated end |
.all_file_names ⇒ Object
10 11 12 13 14 |
# File 'lib/mongration/file.rb', line 10 def self.all_file_names Dir[::File.join(Mongration.configuration.dir, '*.rb')].map do |path| path.pathmap('%f') end end |
.last ⇒ Object
32 33 34 |
# File 'lib/mongration/file.rb', line 32 def self.last all.max end |
.migrated ⇒ Object
20 21 22 |
# File 'lib/mongration/file.rb', line 20 def self.migrated wrap(migrated_file_names).sort end |
.migrated_file_names ⇒ Object
24 25 26 |
# File 'lib/mongration/file.rb', line 24 def self.migrated_file_names Migration.file_names end |
.pending ⇒ Object
16 17 18 |
# File 'lib/mongration/file.rb', line 16 def self.pending wrap(all_file_names - migrated_file_names).sort end |
.wrap(file_names) ⇒ Object
36 37 38 |
# File 'lib/mongration/file.rb', line 36 def self.wrap(file_names) file_names.map { |file_name| new(file_name) } end |
Instance Method Details
#<=>(other) ⇒ Object
62 63 64 |
# File 'lib/mongration/file.rb', line 62 def <=>(other) number <=> other.number end |
#_load ⇒ Object
66 |
# File 'lib/mongration/file.rb', line 66 alias_method :_load, :load |
#class_name ⇒ Object
50 51 52 |
# File 'lib/mongration/file.rb', line 50 def class_name underscored_name.camelize end |
#klass ⇒ Object
71 72 73 |
# File 'lib/mongration/file.rb', line 71 def klass class_name.constantize end |
#load ⇒ Object
67 68 69 |
# File 'lib/mongration/file.rb', line 67 def load _load(::File.join(Mongration.configuration.dir, @file_name)) end |
#name ⇒ Object
46 47 48 |
# File 'lib/mongration/file.rb', line 46 def name underscored_name.gsub('_', ' ') end |
#number ⇒ Object
58 59 60 |
# File 'lib/mongration/file.rb', line 58 def number version.to_i end |
#version ⇒ Object
54 55 56 |
# File 'lib/mongration/file.rb', line 54 def version file_name.split('_').first end |