Class: Nomen::Migration::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/nomen/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 << "Nomen::Migration::Actions::#{child.name.underscore.classify}".constantize.new(child)
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


15
16
17
# File 'lib/nomen/migration/base.rb', line 15

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number


15
16
17
# File 'lib/nomen/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/nomen/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


29
30
31
# File 'lib/nomen/migration/base.rb', line 29

def each_action(&block)
  @actions.each(&block)
end

#inspectObject


33
34
35
# File 'lib/nomen/migration/base.rb', line 33

def inspect
  "#<#{self.class.name}:#{sprintf('%#x', object_id)} ##{number} #{name.inspect} (#{@actions.size} actions)>"
end