Module: ClassGen

Included in:
IndexManager
Defined in:
app/models/class_gen.rb

Class Method Summary collapse

Class Method Details

.gen_class(class_name, dataspec) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/class_gen.rb', line 2

def self.gen_class(class_name, dataspec)
  new_class = Class.new(Object) do
    # Set name for class
    @class_name = class_name
    def self.model_name
      ActiveModel::Name.new(self, nil, @class_name)
    end

    # Import needed methods
    require 'elasticsearch/model'
    include Elasticsearch::Persistence::Model
    include Elasticsearch::Model
    include ENAnalyzer
    extend ModelGen

    # Load dataspec
    dataspec
    index_name dataspec.index_name

    # Gen settings and mapping
    settings = ENAnalyzer::analyzerSettings
    genMapping(settings, dataspec)
  end

  # Set constant and return class
  const_set(class_name, new_class)
  return new_class
end