Class: Trestle::Toolbar::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/toolbar/context.rb

Overview

The toolbar Context is the object that is yielded to a toolbar block and handles the delegation of builder methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, enumerator, *args) ⇒ Context

Returns a new instance of Context.



7
8
9
10
# File 'lib/trestle/toolbar/context.rb', line 7

def initialize(builder, enumerator, *args)
  @builder, @enumerator = builder, enumerator
  @args = args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



24
25
26
27
28
29
30
31
32
# File 'lib/trestle/toolbar/context.rb', line 24

def method_missing(name, *args, &block)
  result = builder.send(name, *args, &block)

  if builder.builder_methods.include?(name)
    group { @current_group << result }
  else
    result
  end
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



5
6
7
# File 'lib/trestle/toolbar/context.rb', line 5

def builder
  @builder
end

Instance Method Details

#groupObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/trestle/toolbar/context.rb', line 12

def group
  if @current_group
    yield
  else
    @current_group = []
    yield
    @enumerator << @current_group
    @current_group = nil
  end
end