Class: OsUp::MigrationList

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/osup/migration_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMigrationList

Returns a new instance of MigrationList.



15
16
17
18
19
20
# File 'lib/osup/migration_list.rb', line 15

def initialize
  @migrations = []
  @index = {}

  load_migrations
end

Instance Attribute Details

#indexObject (readonly, protected)

Returns the value of attribute index.



40
41
42
# File 'lib/osup/migration_list.rb', line 40

def index
  @index
end

#migrationsObject (readonly, protected)

Returns the value of attribute migrations.



40
41
42
# File 'lib/osup/migration_list.rb', line 40

def migrations
  @migrations
end

Instance Method Details

#[](id) ⇒ Object



22
23
24
# File 'lib/osup/migration_list.rb', line 22

def [](id)
  index[id]
end

#countObject



30
31
32
# File 'lib/osup/migration_list.rb', line 30

def count
  migrations.count
end

#eachObject



26
27
28
# File 'lib/osup/migration_list.rb', line 26

def each(&)
  migrations.each(&)
end

#getObject



34
35
36
# File 'lib/osup/migration_list.rb', line 34

def get
  migrations.clone
end

#load_migrationsObject (protected)



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/osup/migration_list.rb', line 42

def load_migrations
  dir = OsUp.migration_dir

  Dir.entries(dir).each do |f|
    next if f.start_with?('.') || !Dir.exist?(File.join(dir, f))

    m = Migration.load(dir, f)
    migrations << m
    index[m.id] = m
  end

  migrations.sort!
end