Class: RgGen::Core::OutputBase::Feature

Inherits:
Base::Feature show all
Includes:
Base::FeatureLayerExtension, RaiseError
Defined in:
lib/rggen/core/output_base/feature.rb

Class Attribute Summary collapse

Attributes inherited from Base::Feature

#component

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RaiseError

#error

Methods inherited from Base::Feature

#feature_name, #initialize, #inspect

Methods included from Base::SharedContext

#attach_context

Constructor Details

This class inherits a constructor from RgGen::Core::Base::Feature

Class Attribute Details

.buildersObject (readonly)

Returns the value of attribute builders.



12
13
14
# File 'lib/rggen/core/output_base/feature.rb', line 12

def builders
  @builders
end

.file_writerObject (readonly)

Returns the value of attribute file_writer.



23
24
25
# File 'lib/rggen/core/output_base/feature.rb', line 23

def file_writer
  @file_writer
end

.pre_buildersObject (readonly)

Returns the value of attribute pre_builders.



11
12
13
# File 'lib/rggen/core/output_base/feature.rb', line 11

def pre_builders
  @pre_builders
end

Class Method Details

.code_generatorsObject



14
15
16
# File 'lib/rggen/core/output_base/feature.rb', line 14

def code_generators
  @code_generators ||= {}
end

.copy_code_generators(subclass) ⇒ Object



88
89
90
91
92
# File 'lib/rggen/core/output_base/feature.rb', line 88

def copy_code_generators(subclass)
  @code_generators&.each do |phase, generator|
    subclass.code_generators[phase] = generator.copy
  end
end

.exported_methodsObject



25
26
27
# File 'lib/rggen/core/output_base/feature.rb', line 25

def exported_methods
  @exported_methods ||= []
end

.inherited(subclass) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/rggen/core/output_base/feature.rb', line 78

def inherited(subclass)
  super
  export_instance_variable(:@pre_builders, subclass, &:dup)
  export_instance_variable(:@builders, subclass, &:dup)
  export_instance_variable(:@template_engine, subclass)
  export_instance_variable(:@file_writer, subclass)
  export_instance_variable(:@exported_methods, subclass, &:dup)
  copy_code_generators(subclass)
end

.template_engine(engine = nil) ⇒ Object



18
19
20
21
# File 'lib/rggen/core/output_base/feature.rb', line 18

def template_engine(engine = nil)
  @template_engine = engine.instance if engine
  @template_engine
end

Instance Method Details

#buildObject



105
106
107
108
109
# File 'lib/rggen/core/output_base/feature.rb', line 105

def build
  helper
    .builders
    &.each { |body| instance_exec(&body) }
end

#export(*methods) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/rggen/core/output_base/feature.rb', line 111

def export(*methods)
  methods.each do |method|
    unless exported_methods(:class).include?(method) ||
           exported_methods(:object).include?(method)
      exported_methods(:object) << method
    end
  end
end

#exported_methods(scope) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/rggen/core/output_base/feature.rb', line 120

def exported_methods(scope)
  if scope == :class
    self.class.exported_methods
  else
    @exported_methods ||= []
  end
end

#generate_code(code, phase, kind) ⇒ Object



128
129
130
131
# File 'lib/rggen/core/output_base/feature.rb', line 128

def generate_code(code, phase, kind)
  generator = self.class.code_generators[phase]
  generator&.generate(self, code, kind)
end

#post_initializeObject



95
96
97
# File 'lib/rggen/core/output_base/feature.rb', line 95

def post_initialize
  define_layer_methods
end

#pre_buildObject



99
100
101
102
103
# File 'lib/rggen/core/output_base/feature.rb', line 99

def pre_build
  helper
    .pre_builders
    &.each { |body| instance_exec(&body) }
end

#write_file(directory = nil) ⇒ Object



133
134
135
136
# File 'lib/rggen/core/output_base/feature.rb', line 133

def write_file(directory = nil)
  file_writer = self.class.file_writer
  file_writer&.write_file(self, directory)
end