Class: Onoma::Migrator::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/onoma/migrator/reference.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReference

Returns a new instance of Reference.



14
15
16
17
18
19
20
# File 'lib/onoma/migrator/reference.rb', line 14

def initialize
  @set = if Onoma.reference_path.exist?
           Onoma::NomenclatureSet.load_file(Onoma.reference_path)
         else
           Onoma::NomenclatureSet.new
         end
end

Class Method Details

.run(migration) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/onoma/migrator/reference.rb', line 4

def self.run(migration)
  ref = new
  migration.each_action do |action|
    ref.send(action.action_name, action)
  end
  ref.version = migration.number
  puts "Write DB in #{Onoma.reference_path.relative_path_from(Onoma.root)}"
  ref.write
end

Instance Method Details

#item_change(action) ⇒ Object



58
59
60
# File 'lib/onoma/migrator/reference.rb', line 58

def item_change(action)
  @set.change_item(action.nomenclature, action.name, action.changes)
end

#item_creation(action) ⇒ Object



54
55
56
# File 'lib/onoma/migrator/reference.rb', line 54

def item_creation(action)
  @set.add_item(action.nomenclature, action.name, action.options)
end

#item_merging(action) ⇒ Object



62
63
64
# File 'lib/onoma/migrator/reference.rb', line 62

def item_merging(action)
  @set.merge_item(action.nomenclature, action.name, action.into)
end

#item_removal(action) ⇒ Object



66
67
68
# File 'lib/onoma/migrator/reference.rb', line 66

def item_removal(action)
  @set.remove_item(action.nomenclature, action.name)
end

#nomenclature_change(action) ⇒ Object



38
39
40
# File 'lib/onoma/migrator/reference.rb', line 38

def nomenclature_change(action)
  @set.change_nomenclature(action.nomenclature, action.changes)
end

#nomenclature_creation(action) ⇒ Object



34
35
36
# File 'lib/onoma/migrator/reference.rb', line 34

def nomenclature_creation(action)
  @set.add_nomenclature(action.name, action.options)
end

#nomenclature_removal(action) ⇒ Object



42
43
44
# File 'lib/onoma/migrator/reference.rb', line 42

def nomenclature_removal(action)
  @set.remove_nomenclature(action.nomenclature)
end

#property_change(action) ⇒ Object



50
51
52
# File 'lib/onoma/migrator/reference.rb', line 50

def property_change(action)
  @set.change_property(action.nomenclature, action.name, action.changes)
end

#property_creation(action) ⇒ Object



46
47
48
# File 'lib/onoma/migrator/reference.rb', line 46

def property_creation(action)
  @set.add_property(action.nomenclature, action.name, action.type, action.options)
end

#versionObject



22
23
24
# File 'lib/onoma/migrator/reference.rb', line 22

def version
  @set.version
end

#version=(number) ⇒ Object



26
27
28
# File 'lib/onoma/migrator/reference.rb', line 26

def version=(number)
  @set.version = number
end

#writeObject



30
31
32
# File 'lib/onoma/migrator/reference.rb', line 30

def write
  File.write(Onoma.reference_path, @set.to_xml)
end