Class: Tubular::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/tubular/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, &block) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
14
15
16
17
18
19
# File 'lib/tubular/builder.rb', line 10

def initialize(attributes, &block)
  @context    = attributes.fetch(:context)
  @collection = attributes.fetch(:collection, []) 
  @table_html = attributes.fetch(:table_html, {})
  @columns    = []

  if block_given?
    instance_eval(&block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tubular/builder.rb', line 31

def method_missing(m, *args, &block)
  if context.respond_to?(m)
    context.send(m, *args, &block)
  else
    super
  end
end

Class Method Details

.render(*args, &block) ⇒ Object



6
7
8
# File 'lib/tubular/builder.rb', line 6

def self.render(*args, &block)
  new(*args, &block).render
end

Instance Method Details

#column(*args, &block) ⇒ Object



27
28
29
# File 'lib/tubular/builder.rb', line 27

def column(*args, &block)
  columns << build_column(*args, &block) 
end

#renderObject



21
22
23
24
25
# File 'lib/tubular/builder.rb', line 21

def render
  (:table, table_html) do
    (render_table_head + render_table_body) if columns.size > 0
  end
end

#respond_to?(m) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/tubular/builder.rb', line 39

def respond_to?(m)
  if context.respond_to?(m)
    true
  else
    super
  end
end