Sha256: 05ccd6badfd4ed3412e4d5961ef06f58bfc4043006e7c0ab6b4af09fc9c41d36

Contents?: true

Size: 927 Bytes

Versions: 14

Compression:

Stored size: 927 Bytes

Contents

module Trestle
  class Toolbar
    # The toolbar Context is the object that is yielded to a toolbar block and handles the delegation of builder methods.
    class Context
      attr_reader :builder

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

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

    private
      def respond_to_missing?(name, include_all=false)
        builder.respond_to?(name) || super
      end

      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trestle-0.10.0.pre lib/trestle/toolbar/context.rb
trestle-0.9.8 lib/trestle/toolbar/context.rb
trestle-0.9.7 lib/trestle/toolbar/context.rb
trestle-0.9.6 lib/trestle/toolbar/context.rb
trestle-0.9.5 lib/trestle/toolbar/context.rb
trestle-0.9.4 lib/trestle/toolbar/context.rb
trestle-0.9.3 lib/trestle/toolbar/context.rb
trestle-0.9.2 lib/trestle/toolbar/context.rb
trestle-0.9.1 lib/trestle/toolbar/context.rb
trestle-0.9.0 lib/trestle/toolbar/context.rb
trestle-0.8.13 lib/trestle/toolbar/context.rb
trestle-0.8.12 lib/trestle/toolbar/context.rb
trestle-0.8.11 lib/trestle/toolbar/context.rb
trestle-0.8.10 lib/trestle/toolbar/context.rb