Class: EditInPlace::ExtendedBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/edit_in_place/extended_builder.rb

Overview

A base class that allows one to easily and safely extend the Builder class with additional functionality. Every ExtendedBuilder contains a base builder to which it delegates all missing method calls. In this way, builder instances can be extended multiple times, like so:

base = Builder.new({...})
base.respond_to? :field # => true

hello_builder = HelloBuilder.new(base_builder, {...}) # a sub-class of ExtendedBuilder
hello_builder.respond_to? :hello # => true
hello_builder.respond_to? :field # => true

world_builder = WorldBuilder.new(hello_builder, {...}) # a sub-class of ExtendedBuilder
world_builder.respond_to? :world # => true
world_builder.respond_to? :hello # => true
world_builder.respond_to? :field # => true

A word of caution is in order, however! An ExtendedBuilder should never override a method on the base builder. While this may seem like a convenient way to add new methods to Builder, it can cause problems, since other methods further along in the chain will not call the overriden one. ExtendedBuilder is intended only for adding new methods, not mdifying existing ones.

Author:

  • Jacob Lockard

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ ExtendedBuilder

Creates a new EditInPlace::ExtendedBuilder with the given base builder.

Parameters:

  • base (Object)

    the base builder to extend. It should quack like a Builder.

Since:

  • 0.1.0



36
37
38
# File 'lib/edit_in_place/extended_builder.rb', line 36

def initialize(base)
  @base = base
end

Instance Attribute Details

#baseObject (readonly)

Returns the base builder instance which this EditInPlace::ExtendedBuilder extends. It should quack like a Builder.

Returns:

Since:

  • 0.1.0



30
31
32
# File 'lib/edit_in_place/extended_builder.rb', line 30

def base
  @base
end