Class: Dnif::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/dnif/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Schema

Returns a new instance of Schema.



4
5
6
# File 'lib/dnif/schema.rb', line 4

def initialize(klass)
  @klass = klass
end

Instance Method Details

#generateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dnif/schema.rb', line 8

def generate
  xml = Builder::XmlMarkup.new(:indent => 2)
  xml.sphinx(:schema) do
    fields = []
    @klass.indexes.values.each do |index|
      (index.fields - fields).each do |name|
        xml.sphinx(:field, :name => name)
        fields << name
      end
    end

    xml.sphinx(:attr, :name => "class_id", :type => "int")
    xml.sphinx(:attr, :name => "class_name", :type => "multi")

    attributes = []
    @klass.indexes.values.each do |index|
      index.attributes.each do |name, type|
        if not attributes.include?(name)
          xml.sphinx(:attr, :name => name, :type => attribute_type(type))
          attributes << name
        end
      end
    end
  end
  xml.target!
end