Class: TableStructure::Schema::ContextBuilders

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/schema/context_builders.rb

Instance Method Summary collapse

Constructor Details

#initialize(builders) ⇒ ContextBuilders

Returns a new instance of ContextBuilders.



6
7
8
9
10
# File 'lib/table_structure/schema/context_builders.rb', line 6

def initialize(builders)
  @table_builder = builders[:table]
  @header_builder = builders[:header]
  @row_builder = builders[:row]
end

Instance Method Details

#build_for_table(context) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/table_structure/schema/context_builders.rb', line 12

def build_for_table(context)
  if @table_builder
    @table_builder.call(context)
  else
    context
  end
end

#extend_methods_for(table) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/table_structure/schema/context_builders.rb', line 20

def extend_methods_for(table)
  methods = {}
  methods[:header] = create_method(@header_builder) if @header_builder
  methods[:row] = create_method(@row_builder) if @row_builder

  return if methods.empty?

  table.extend ContextBuilder.new(methods)
end