Sha256: bbfb80a232e5f3adc73e463dc40791b292140ba4f589c3004c591ab8941dab65

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 KB

Contents

module Solr
  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

24 entries across 24 versions & 1 rubygems

Version Path
picky-0.12.3 lib/picky/solr/schema_generator.rb
picky-0.12.2 lib/picky/solr/schema_generator.rb
picky-0.12.1 lib/picky/solr/schema_generator.rb
picky-0.12.0 lib/picky/solr/schema_generator.rb
picky-0.11.2 lib/picky/solr/schema_generator.rb
picky-0.11.1 lib/picky/solr/schema_generator.rb
picky-0.11.0 lib/picky/solr/schema_generator.rb
picky-0.10.5 lib/picky/solr/schema_generator.rb
picky-0.10.4 lib/picky/solr/schema_generator.rb
picky-0.10.2 lib/picky/solr/schema_generator.rb
picky-0.10.1 lib/picky/solr/schema_generator.rb
picky-0.10.0 lib/picky/solr/schema_generator.rb
picky-0.9.4 lib/picky/solr/schema_generator.rb
picky-0.9.3 lib/picky/solr/schema_generator.rb
picky-0.9.2 lib/picky/solr/schema_generator.rb
picky-0.9.1 lib/picky/solr/schema_generator.rb
picky-0.9.0 lib/picky/solr/schema_generator.rb
picky-0.3.0 lib/picky/solr/schema_generator.rb
picky-0.2.4 lib/picky/solr/schema_generator.rb
picky-0.2.3 lib/picky/solr/schema_generator.rb