Class: Enterprisifier::Schema::Loader

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/enterprisifier/schema/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Loader

Returns a new instance of Loader.



8
9
10
11
12
# File 'lib/enterprisifier/schema/loader.rb', line 8

def initialize(path)
  @path = Pathname(path).expand_path
  @root_element = nil
  @current_element = nil
end

Instance Method Details

#build_schemaObject



14
15
16
17
18
# File 'lib/enterprisifier/schema/loader.rb', line 14

def build_schema
  parser = Nokogiri::XML::SAX::Parser.new(self)
  @path.open('r') { |file| parser.parse(file) }
  @root_element
end

#cdata_block(string) ⇒ Object



40
41
42
# File 'lib/enterprisifier/schema/loader.rb', line 40

def cdata_block(string)
  @current_element.add_text(string)
end

#characters(string) ⇒ Object



36
37
38
# File 'lib/enterprisifier/schema/loader.rb', line 36

def characters(string)
  @current_element.add_text(string)
end

#element_factoryObject



44
45
46
# File 'lib/enterprisifier/schema/loader.rb', line 44

def element_factory
  Enterprisifier::Schema::ElementFactory
end

#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object



31
32
33
34
# File 'lib/enterprisifier/schema/loader.rb', line 31

def end_element_namespace(name, prefix = nil, uri = nil)
  return nil unless valid_namespace?(name, uri)
  @current_element = @current_element.parent
end

#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/enterprisifier/schema/loader.rb', line 20

def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = [])
  return nil unless valid_namespace?(name, uri)
  element = element_factory.create_element(name, attrs, ns)
  unless @root_element
    @root_element = element
    @root_element.path = @path
  end
  @current_element.add_child(element) if @current_element
  @current_element = element
end