Class: Onoma::Migration
- Inherits:
-
Object
- Object
- Onoma::Migration
- Defined in:
- lib/onoma/migration.rb,
lib/onoma/migration/actions/base.rb,
lib/onoma/migration/actions/item_change.rb,
lib/onoma/migration/actions/item_merging.rb,
lib/onoma/migration/actions/item_removal.rb,
lib/onoma/migration/actions/item_creation.rb,
lib/onoma/migration/actions/property_creation.rb,
lib/onoma/migration/actions/nomenclature_change.rb,
lib/onoma/migration/actions/nomenclature_removal.rb,
lib/onoma/migration/actions/nomenclature_creation.rb
Overview
Migration instance represents a migration file
Defined Under Namespace
Modules: Actions
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Class Method Summary collapse
-
.parse(file) ⇒ Object
Parse en XML migration to a Onoma::Migration object.
Instance Method Summary collapse
- #add(action) ⇒ Object
- #each_action(&block) ⇒ Object
-
#initialize(number, name) {|_self| ... } ⇒ Migration
constructor
A new instance of Migration.
- #inspect ⇒ Object
- #label ⇒ Object
- #migrate(conn) ⇒ Object
Constructor Details
#initialize(number, name) {|_self| ... } ⇒ Migration
Returns a new instance of Migration.
36 37 38 39 40 41 |
# File 'lib/onoma/migration.rb', line 36 def initialize(number, name) @number = number @name = name @actions = [] yield self if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/onoma/migration.rb', line 34 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
34 35 36 |
# File 'lib/onoma/migration.rb', line 34 def number @number end |
Class Method Details
.parse(file) ⇒ Object
Parse en XML migration to a Onoma::Migration object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/onoma/migration.rb', line 16 def parse(file) # puts "Parse #{file}" f = File.open(file, 'rb') document = Nokogiri::XML(f) do |config| config.strict.nonet.noblanks.noent end f.close root = document.root number = file.basename.to_s.split('_').first.to_i new(number, root['name']) do |m| root.children.each do |child| next unless child.is_a? Nokogiri::XML::Element m.add "Onoma::Migration::Actions::#{child.name.underscore.classify}".constantize.new(child) end end end |
Instance Method Details
#add(action) ⇒ Object
47 48 49 |
# File 'lib/onoma/migration.rb', line 47 def add(action) @actions << action end |
#each_action(&block) ⇒ Object
51 52 53 |
# File 'lib/onoma/migration.rb', line 51 def each_action(&block) @actions.each(&block) end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/onoma/migration.rb', line 55 def inspect "#<#{self.class.name}:#{format('%#x', object_id)} ##{number} #{name.inspect} (#{@actions.size} actions)>" end |
#label ⇒ Object
43 44 45 |
# File 'lib/onoma/migration.rb', line 43 def label "#{number} #{name}" end |
#migrate(conn) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/onoma/migration.rb', line 59 def migrate(conn) puts '' puts "== #{label}: migrating ".ljust(80, '=') duration = Benchmark.measure do each_action do |action| puts "-- #{action.label}" conn.exec_action(action) end conn.version = number end puts "== #{label}: migrated (#{duration.real.round(4)}s)".ljust(80, '=') # puts "Write DB in #{Onoma.reference_path.relative_path_from(Onoma.root)}".yellow if @steps versions_dir = Onoma.root.join('tmp', 'versions') FileUtils.mkdir_p(versions_dir) conn.copy(versions_dir.join("#{number}.xml")) end end |