Class: Manufactory::Adapter

Inherits:
Object show all
Defined in:
lib/manufactory.rb

Overview

Adapter.new(User, :admin, age: 24)

Direct Known Subclasses

GenericModelAdapter, ObjectAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, name, callables) ⇒ Adapter



40
41
42
43
44
# File 'lib/manufactory.rb', line 40

def initialize(klass, name, callables)
  @klass     = klass
  @name      = name
  @callables = callables
end

Instance Attribute Details

#callablesObject (readonly)

Returns the value of attribute callables.



39
40
41
# File 'lib/manufactory.rb', line 39

def callables
  @callables
end

#klassObject (readonly)

Returns the value of attribute klass.



39
40
41
# File 'lib/manufactory.rb', line 39

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/manufactory.rb', line 39

def name
  @name
end

Instance Method Details

#has_association?(object, attribute) ⇒ Boolean



57
58
59
# File 'lib/manufactory.rb', line 57

def has_association?(object, attribute)
  false
end

#run(attributes = Hash.new) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/manufactory.rb', line 46

def run(attributes = Hash.new)
  blueprint = klass.blueprints[name.to_sym]
  raise "No blueprint #{name} for class #{klass}" if blueprint.nil?
  default_attributes = Hash.new
  object = klass.new(default_attributes) # will be discarded at the end
  self.callables.each do |callable|
    default_attributes.merge!(DSL.new(self, object, callable).run)
  end
  self.initialize_object(klass, default_attributes, attributes)
end