Class: AssemblyLine::Constructor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/assembly_line/constructor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, code_block) ⇒ Constructor

Returns a new instance of Constructor.



9
10
11
12
# File 'lib/assembly_line/constructor.rb', line 9

def initialize(name, code_block)
  @name = name
  @code_block = code_block
end

Instance Attribute Details

#code_blockObject (readonly)

Returns the value of attribute code_block.



7
8
9
# File 'lib/assembly_line/constructor.rb', line 7

def code_block
  @code_block
end

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/assembly_line/constructor.rb', line 7

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/assembly_line/constructor.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/assembly_line/constructor.rb', line 7

def options
  @options
end

Instance Method Details

#assemble(context, options) ⇒ Object



14
15
16
17
18
19
# File 'lib/assembly_line/constructor.rb', line 14

def assemble(context, options)
  @options = options
  @context = context
  instance_eval(&code_block)
  self
end

#depends_on(*constructors) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/assembly_line/constructor.rb', line 29

def depends_on(*constructors)
  if options[:depends_on]
    constructors = Array(options[:depends_on])
  end
  constructors.each do |name|
    AssemblyLine.assemble(name, context)
  end
end

#invoke(*methods) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/assembly_line/constructor.rb', line 21

def invoke(*methods)
  if methods.any?
    invoke_in_setup *methods
  else
    invoke_in_setup name
  end
end