Class: OsUp::Migration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, dirname, id, name) ⇒ Migration

Returns a new instance of Migration.



16
17
18
19
20
21
22
# File 'lib/osup/migration.rb', line 16

def initialize(path, dirname, id, name)
  @path = File.join(path, dirname)
  @dirname = dirname
  @id = id
  @name = name
  @spec = load_spec
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/osup/migration.rb', line 5

def description
  @description
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



5
6
7
# File 'lib/osup/migration.rb', line 5

def dirname
  @dirname
end

#export_poolObject (readonly)

Returns the value of attribute export_pool.



5
6
7
# File 'lib/osup/migration.rb', line 5

def export_pool
  @export_pool
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/osup/migration.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/osup/migration.rb', line 5

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/osup/migration.rb', line 5

def path
  @path
end

#snapshotObject (readonly)

Returns the value of attribute snapshot.



5
6
7
# File 'lib/osup/migration.rb', line 5

def snapshot
  @snapshot
end

#stop_containersObject (readonly)

Returns the value of attribute stop_containers.



5
6
7
# File 'lib/osup/migration.rb', line 5

def stop_containers
  @stop_containers
end

#summaryObject (readonly)

Returns the value of attribute summary.



5
6
7
# File 'lib/osup/migration.rb', line 5

def summary
  @summary
end

Class Method Details

.load(path, dirname) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/osup/migration.rb', line 8

def self.load(path, dirname)
  if /^(\d+)-(.+)$/ !~ dirname
    raise "'#{dirname}' is not a valid migration"
  end

  new(path, dirname, ::Regexp.last_match(1).to_i, ::Regexp.last_match(2).gsub('-', ' ').capitalize)
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/osup/migration.rb', line 28

def <=>(other)
  id <=> other.id
end

#action_script(action) ⇒ Object



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

def action_script(action)
  File.join(path, "#{action}.rb")
end

#load_specObject (protected)



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/osup/migration.rb', line 34

def load_spec
  unless File.exist?(spec_path)
    @snapshot = []
    return
  end

  spec = OsCtl::Lib::ConfigFile.load_yaml_file(spec_path)
  @name = spec['name'] || @name
  @description = spec['description']
  @snapshot = spec['snapshot'].map(&:to_sym)
  @export_pool = spec.fetch('export_pool', true)
  @stop_containers = spec.fetch('stop_containers', true)
end

#spec_pathObject (protected)



48
49
50
# File 'lib/osup/migration.rb', line 48

def spec_path
  File.join(path, 'spec.yml')
end