Class: Fabricators::Fabricator

Inherits:
Object
  • Object
show all
Defined in:
lib/fabricators/fabricator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Fabricator

Returns a new instance of Fabricator.



6
7
8
9
10
11
12
# File 'lib/fabricators/fabricator.rb', line 6

def initialize(name, options={}, &block)
  @name = name
  @options = options
  @block = block
  @loaded = false
  Reader.new(name, options, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/fabricators/fabricator.rb', line 4

def options
  @options
end

#proxyObject (readonly)

Returns the value of attribute proxy.



4
5
6
# File 'lib/fabricators/fabricator.rb', line 4

def proxy
  @proxy
end

Instance Method Details

#attributes_for(options = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/fabricators/fabricator.rb', line 22

def attributes_for(options={})
  {}.tap do |hash|
    iterate_attributes(options, proxy) do |name, value|
      hash[name] = value
    end
  end
end

#parentObject



14
15
16
17
18
19
20
# File 'lib/fabricators/fabricator.rb', line 14

def parent
  @parent ||= begin
    if @options[:parent]
      Fabricators.definitions.find(@options[:parent], :fabricator)
    end
  end
end