Class: Nomen::Migrator::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/nomen/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/nomen/migrator/reference.rb', line 14

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

Class Method Details

.run(migration) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'lib/nomen/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 #{Nomen.reference_path.relative_path_from(Rails.root)}".yellow
  ref.write
end

Instance Method Details

#item_change(action) ⇒ Object


58
59
60
# File 'lib/nomen/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/nomen/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/nomen/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/nomen/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/nomen/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/nomen/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/nomen/migrator/reference.rb', line 42

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

#property_change(action) ⇒ Object


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

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

#property_creation(action) ⇒ Object


46
47
48
# File 'lib/nomen/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/nomen/migrator/reference.rb', line 22

def version
  @set.version
end

#version=(number) ⇒ Object


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

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

#writeObject


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

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