Class: Dynomite::Migration::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/dynomite/migration/file_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileInfo

Returns a new instance of FileInfo.



4
5
6
# File 'lib/dynomite/migration/file_info.rb', line 4

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/dynomite/migration/file_info.rb', line 3

def path
  @path
end

Class Method Details

.all_filesObject



24
25
26
# File 'lib/dynomite/migration/file_info.rb', line 24

def self.all_files
  Dir.glob("#{Dynomite.root}/dynamodb/migrate/*").to_a.sort
end

Instance Method Details

#migration_classObject



12
13
14
15
16
# File 'lib/dynomite/migration/file_info.rb', line 12

def migration_class
  filename = File.basename(@path, '.rb')
  filename = filename.sub(/\d+[-_]/, '') # strip leading timestsamp
  filename.camelize.constantize
end

#pretty_pathObject



8
9
10
# File 'lib/dynomite/migration/file_info.rb', line 8

def pretty_path
  @path.sub(/^\.\//,'') # remove leading ./
end

#versionObject



18
19
20
21
22
# File 'lib/dynomite/migration/file_info.rb', line 18

def version
  filename = File.basename(@path, '.rb')
  md = filename.match(/(\d+)[-_]/)
  md[1].to_i
end