Class: Journeyman::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/journeyman/builder.rb

Overview

Internal: Builds and creates objects, using the configuration provided.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, config) ⇒ Builder

Returns a new instance of Builder.



12
13
14
# File 'lib/journeyman/builder.rb', line 12

def initialize(name, options, config)
  @config = Configuration.new(name, options, config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/journeyman/builder.rb', line 9

def config
  @config
end

Instance Method Details

#build(attrs = {}) ⇒ Object

Internal: Builds a new instance, using the configuration specified in the factory.

attrs - The attributes used to build the object

Returns a new instance of the object.



27
28
29
30
31
32
# File 'lib/journeyman/builder.rb', line 27

def build(attrs={})
  check_build_arguments(attrs)
  attrs = merge_defaults(attrs)
  attrs = Journeyman.execute(processor, attrs) if processor
  config.builder.call(attrs)
end

#create(attrs = {}) ⇒ Object

Internal: Create a new instance, using the configuration specified in the factory.

attrs - The attributes used to build the object

Returns a new instance of the object.



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

def create(attrs={})
  build(attrs).tap { |instance|
    instance.save!
    Journeyman.execute(after_create_callback, instance, attrs)
  }
end

#find(id) ⇒ Object

Internal: Executes the finder.



17
18
19
# File 'lib/journeyman/builder.rb', line 17

def find(id)
  config.finder.call(id)
end