Module: BlueprintsBoy::Helper

Defined in:
lib/blueprints_boy/helper.rb

Instance Method Summary collapse

Instance Method Details

#autoset(name, value) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/blueprints_boy/helper.rb', line 11

def autoset(name, value)
  if respond_to?(name)
    @_blueprint_data[name] ||= value
  else
    set(name, value)
  end
  value
end

#blueprint_data(name = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/blueprints_boy/helper.rb', line 20

def blueprint_data(name = nil)
  if name
    @_blueprint_data[name]
  else
    @_blueprint_data
  end
end

#build(*names) ⇒ Object



28
29
30
# File 'lib/blueprints_boy/helper.rb', line 28

def build(*names)
  build_with nil, *names
end

#build!(*names) ⇒ Object



32
33
34
# File 'lib/blueprints_boy/helper.rb', line 32

def build!(*names)
  build_with :create, *names
end

#build_attributes(*names) ⇒ Object



40
41
42
# File 'lib/blueprints_boy/helper.rb', line 40

def build_attributes(*names)
  build_with :attributes, *names
end

#build_new(*names) ⇒ Object



36
37
38
# File 'lib/blueprints_boy/helper.rb', line 36

def build_new(*names)
  build_with :new, *names
end

#build_with(strategy, *names) ⇒ Object



44
45
46
# File 'lib/blueprints_boy/helper.rb', line 44

def build_with(strategy, *names)
  BlueprintsBoy.manager.build(self, names, strategy: strategy)
end

#set(name, value) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/blueprints_boy/helper.rb', line 2

def set(name, value)
  instance_eval <<-RUBY, __FILE__, __LINE__ + 1
    def self.#{name}
      @_blueprint_data[:#{name}]
    end
  RUBY
  @_blueprint_data[name] = value
end