Class: ActiveRecord::Bixformer::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-bixformer/compiler.rb

Direct Known Subclasses

From::Csv, To::Csv

Instance Method Summary collapse

Constructor Details

#initialize(format, plan) ⇒ Compiler

Returns a new instance of Compiler.



4
5
6
7
8
9
# File 'lib/activerecord-bixformer/compiler.rb', line 4

def initialize(format, plan)
  plan.__bixformer_format = format.to_s

  @model_name = plan.class.__bixformer_model
  @plan       = ActiveRecord::Bixformer::PlanAccessor.new(plan)
end

Instance Method Details

#clearObject



11
12
13
# File 'lib/activerecord-bixformer/compiler.rb', line 11

def clear
  @model = nil
end

#compileObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/activerecord-bixformer/compiler.rb', line 15

def compile
  @model ||= -> do
    model_type, model_options = @plan.parse_to_type_and_options(@plan.value_of(:entry)[:type])

    model = @plan.new_module_instance(:model, model_type, @model_name, model_options)

    compile_model(model)

    model
  end.call
end

#should_be_includedObject



27
28
29
# File 'lib/activerecord-bixformer/compiler.rb', line 27

def should_be_included
  compile.should_be_included
end