Class: Mongration::File

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/mongration/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject (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

.allObject



28
29
30
# File 'lib/mongration/file.rb', line 28

def self.all
  pending + migrated
end

.all_file_namesObject



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

.lastObject



32
33
34
# File 'lib/mongration/file.rb', line 32

def self.last
  all.max
end

.migratedObject



20
21
22
# File 'lib/mongration/file.rb', line 20

def self.migrated
  wrap(migrated_file_names).sort
end

.migrated_file_namesObject



24
25
26
# File 'lib/mongration/file.rb', line 24

def self.migrated_file_names
  Migration.file_names
end

.pendingObject



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

#_loadObject



66
# File 'lib/mongration/file.rb', line 66

alias_method :_load, :load

#class_nameObject



50
51
52
# File 'lib/mongration/file.rb', line 50

def class_name
  underscored_name.camelize
end

#klassObject



71
72
73
# File 'lib/mongration/file.rb', line 71

def klass
  class_name.constantize
end

#loadObject



67
68
69
# File 'lib/mongration/file.rb', line 67

def load
  _load(::File.join(Mongration.configuration.dir, @file_name))
end

#nameObject



46
47
48
# File 'lib/mongration/file.rb', line 46

def name
  underscored_name.gsub('_', ' ')
end

#numberObject



58
59
60
# File 'lib/mongration/file.rb', line 58

def number
  version.to_i
end

#versionObject



54
55
56
# File 'lib/mongration/file.rb', line 54

def version
  file_name.split('_').first
end