Class: Bricks::BuilderSet

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/bricks/builder_set.rb

Instance Method Summary collapse

Methods included from DSL

#build?, #builder, #create?

Constructor Details

#initialize(klass) ⇒ BuilderSet

Returns a new instance of BuilderSet.



27
28
29
30
# File 'lib/bricks/builder_set.rb', line 27

def initialize(klass)
  @class    = klass
  @builders = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



32
33
34
# File 'lib/bricks/builder_set.rb', line 32

def method_missing(name, *args)
  build(@class).send(name, *args)
end

Instance Method Details

#build(klass = @class) ⇒ Object



7
8
9
# File 'lib/bricks/builder_set.rb', line 7

def build(klass = @class)
  (@builders << super).last
end

#build!(klass = @class) ⇒ Object



11
12
13
# File 'lib/bricks/builder_set.rb', line 11

def build!(klass = @class)
  (@builders << super).last
end

#clearObject



15
16
17
# File 'lib/bricks/builder_set.rb', line 15

def clear
  @builders.clear
end

#create(klass = @class) ⇒ Object



19
20
21
# File 'lib/bricks/builder_set.rb', line 19

def create(klass = @class)
  (@builders << super).last
end

#create!(klass = @class) ⇒ Object



23
24
25
# File 'lib/bricks/builder_set.rb', line 23

def create!(klass = @class)
  (@builders << super).last
end

#generate(parent = nil) ⇒ Object



36
37
38
# File 'lib/bricks/builder_set.rb', line 36

def generate(parent = nil)
  @builders.map { |b| b.generate(parent) }
end