Module: BuildingBlocks::Builders::BuilderBuilder::InstanceMethods

Defined in:
lib/building_blocks/builders/builder_builder.rb

Overview

Methods available to instances of a generated builder class.

Instance Method Summary collapse

Instance Method Details

#example_builder_attr(existing_object = nil, &block) ⇒ Object

Reference for instance methods defined via ClassInstanceMethods#builder.

This method is not actually defined, but serves as a reference for the instance method defined when an attribute is defined on the parent builder class using ClassInstanceMethods#builder.

Invokes the receiver_method of receiver with the provided existing_object or a new object generated by invoking the build method of the derived builder_class with the given block.

Parameters:

  • existing_object (Object) (defaults to: nil)

    An existing object to use as the argument to receiver_method. Cannot be used in conjunction with a block.

  • block (Proc)

    A block to be given to the build method of the derived builder_class to generate a new object. Cannot be used in conjunction with a provided existing_object.

Returns:

  • (Object)

    The provided existing_object or the object generated by invoking the build method of the builder_class with the given block.

Raises:

  • (ArgumentError)

    Raised if both an existing_object and block are given or neither an existing_object nor block are provided.

See Also:



# File 'lib/building_blocks/builders/builder_builder.rb', line 313

#initialize(instance) ⇒ Object

Initializes a new instance of the generated builder class. Requires the resource class instance that the builder will populate to be provided.

Parameters:

  • instance (Object)

    The object that should be populated by the builder instance.



301
302
303
# File 'lib/building_blocks/builders/builder_builder.rb', line 301

def initialize(instance)
  @instance = instance
end

#instanceObject

Returns the object instance being built by the builder instance.

Returns:



309
310
311
# File 'lib/building_blocks/builders/builder_builder.rb', line 309

def instance
  return @instance
end