Sha256: 66ea2f806abe633ed94bfe15e45edcdbd604e3ecf2b8614c03ea1ced9664f7dd

Contents?: true

Size: 1.36 KB

Versions: 46

Compression:

Stored size: 1.36 KB

Contents

module Solr # :nodoc:all
  
  class SchemaGenerator

    attr_reader :types

    # Takes an array of index type configs.
    #
    def initialize configuration
      @types = configuration.types
    end

    #
    #
    def generate
      generate_schema_for bound_field_names
    end

    # Returns a binding with the values needed for the schema xml.
    #
    def bound_field_names
      field_names = combine_field_names
      binding
    end

    # TODO
    #
    def combine_field_names
      field_names = []
      types.each do |type|
        field_names += type.solr_fields.map(&:name)
      end
      field_names.uniq!
      field_names
    end

    #
    #
    def generate_schema_for binding
      template_text = read_template
      result = evaluate_erb template_text, binding
      write result
    end

    #
    #
    def evaluate_erb text, binding
      require 'erb'
      template = ERB.new text
      template.result binding
    end

    #
    #
    def read_template
      template_path = File.join PICKY_ROOT, 'solr', 'conf', 'schema.xml.erb'
      schema = ''
      File.open(template_path, 'r') do |file|
        schema = file.read
      end
      schema
    end

    #
    #
    def write result
      schema_path = File.join PICKY_ROOT, 'solr', 'conf', 'schema.xml'
      File.open(schema_path, 'w') do |file|
        file << result
      end
    end

  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
picky-2.6.0 lib/picky/solr/schema_generator.rb
picky-2.5.2 lib/picky/internals/solr/schema_generator.rb
picky-2.5.1 lib/picky/internals/solr/schema_generator.rb
picky-2.5.0 lib/picky/internals/solr/schema_generator.rb
picky-2.4.3 lib/picky/internals/solr/schema_generator.rb
picky-2.4.2 lib/picky/internals/solr/schema_generator.rb
picky-2.4.1 lib/picky/internals/solr/schema_generator.rb
picky-2.4.0 lib/picky/internals/solr/schema_generator.rb
picky-2.3.0 lib/picky/internals/solr/schema_generator.rb
picky-2.2.1 lib/picky/internals/solr/schema_generator.rb
picky-2.2.0 lib/picky/internals/solr/schema_generator.rb
picky-2.1.2 lib/picky/internals/solr/schema_generator.rb
picky-2.1.1 lib/picky/internals/solr/schema_generator.rb
picky-2.1.0 lib/picky/internals/solr/schema_generator.rb
picky-2.0.0 lib/picky/internals/solr/schema_generator.rb
picky-2.0.0.pre3 lib/picky/internals/solr/schema_generator.rb
picky-2.0.0.pre2 lib/picky/internals/solr/schema_generator.rb
picky-2.0.0.pre1 lib/picky/internals/solr/schema_generator.rb
picky-1.5.4 lib/picky/internals/solr/schema_generator.rb
picky-1.5.3 lib/picky/internals/solr/schema_generator.rb