Class: Onoma::Migration::Base
- Inherits:
-
Object
- Object
- Onoma::Migration::Base
- Defined in:
- lib/onoma/migration/base.rb
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
Instance Method Summary collapse
- #each_action(&block) ⇒ Object
-
#initialize(number, name, element = nil) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
Constructor Details
#initialize(number, name, element = nil) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/onoma/migration/base.rb', line 17 def initialize(number, name, element = nil) @number = number @name = name @actions = [] if element element.children.each do |child| next unless child.is_a? Nokogiri::XML::Element @actions << "Onoma::Migration::Actions::#{child.name.underscore.classify}".constantize.new(child) end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/onoma/migration/base.rb', line 15 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
15 16 17 |
# File 'lib/onoma/migration/base.rb', line 15 def number @number end |
Class Method Details
.parse(file) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/onoma/migration/base.rb', line 4 def self.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'], root) end |
Instance Method Details
#each_action(&block) ⇒ Object
30 31 32 |
# File 'lib/onoma/migration/base.rb', line 30 def each_action(&block) @actions.each(&block) end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/onoma/migration/base.rb', line 34 def inspect "#<#{self.class.name}:#{format('%#x', object_id)} ##{number} #{name.inspect} (#{@actions.size} actions)>" end |