Class: RgGen::OutputBase::Component
- Inherits:
-
Base::Component
- Object
- Base::Component
- RgGen::OutputBase::Component
- Includes:
- Base::HierarchicalAccessors
- Defined in:
- lib/rggen/output_base/component.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#output_directory ⇒ Object
writeonly
Sets the attribute output_directory.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes inherited from Base::Component
#children, #items, #level, #parent
Instance Method Summary collapse
- #add_item(item) ⇒ Object
- #build ⇒ Object
- #generate_code(kind, mode, buffer = nil) ⇒ Object
-
#initialize(parent, configuration, source) ⇒ Component
constructor
A new instance of Component.
- #write_file(root_directory) ⇒ Object
Methods inherited from Base::Component
Methods included from SingleForwardable
#def_object_delegator, #def_object_delegators, #def_single_delegator
Constructor Details
#initialize(parent, configuration, source) ⇒ Component
Returns a new instance of Component.
6 7 8 9 10 11 12 13 |
# File 'lib/rggen/output_base/component.rb', line 6 def initialize(parent, configuration, source) super(parent) define_hierarchical_accessors @configuration = configuration @source = source @need_children = source.need_children? def_delegators(:source, *source.fields) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/rggen/output_base/component.rb', line 15 def configuration @configuration end |
#output_directory=(value) ⇒ Object
Sets the attribute output_directory
17 18 19 |
# File 'lib/rggen/output_base/component.rb', line 17 def output_directory=(value) @output_directory = value end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
16 17 18 |
# File 'lib/rggen/output_base/component.rb', line 16 def source @source end |
Instance Method Details
#add_item(item) ⇒ Object
19 20 21 22 |
# File 'lib/rggen/output_base/component.rb', line 19 def add_item(item) super(item) def_object_delegators(@items.last, *item.exported_methods) end |
#build ⇒ Object
24 25 26 27 |
# File 'lib/rggen/output_base/component.rb', line 24 def build items.each(&:build) children.each(&:build) end |
#generate_code(kind, mode, buffer = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rggen/output_base/component.rb', line 29 def generate_code(kind, mode, buffer = nil) buffer ||= CodeBlock.new generate_pre_code(kind, buffer) generate_main_code(kind, mode, buffer) generate_post_code(kind, buffer) buffer end |
#write_file(root_directory) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rggen/output_base/component.rb', line 37 def write_file(root_directory) directory = output_directory(root_directory) FileUtils.mkpath(directory) unless Dir.exist?(directory) items.each do |item| item.write_file(directory) end children.each do |child| child.write_file(directory) end end |