Class: ActiveRecord::LookML::Block
- Inherits:
-
Object
- Object
- ActiveRecord::LookML::Block
- Defined in:
- lib/active_record/lookml/block.rb
Instance Method Summary collapse
- #<<(new_field) ⇒ Object
-
#initialize(type:, name:) {|_self| ... } ⇒ Block
constructor
A new instance of Block.
- #to_lookml(indent_level: 0) ⇒ Object
Constructor Details
#initialize(type:, name:) {|_self| ... } ⇒ Block
Returns a new instance of Block.
4 5 6 7 8 9 |
# File 'lib/active_record/lookml/block.rb', line 4 def initialize(type:, name:) @type = type @name = name @fields = [] yield(self) if block_given? end |
Instance Method Details
#<<(new_field) ⇒ Object
11 12 13 |
# File 'lib/active_record/lookml/block.rb', line 11 def <<(new_field) @fields << new_field end |
#to_lookml(indent_level: 0) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_record/lookml/block.rb', line 15 def to_lookml(indent_level: 0) indent = ' ' * indent_level lookml = "#{indent}#{@type}:" lookml << " #{@name}" if @name lookml << " {\n" @fields.each_with_index do |field, index| lookml << "\n" if index > 0 && field.is_a?(Block) lookml << field.to_lookml(indent_level: indent_level + 1) end lookml << "#{indent}}\n" lookml end |