Class: Pickle::Adapter::Machinist

Inherits:
Pickle::Adapter show all
Defined in:
lib/pickle/adapter.rb

Overview

machinist adapter

Instance Attribute Summary

Attributes inherited from Pickle::Adapter

#klass, #name

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Pickle::Adapter

column_names, create_model, find_all_models, find_first_model, get_model, model_classes

Constructor Details

- (Machinist) initialize(klass, blueprint)



91
92
93
94
95
# File 'lib/pickle/adapter.rb', line 91

def initialize(klass, blueprint)
  @klass, @blueprint = klass, blueprint
  @name = @klass.name.underscore.gsub('/','_')
  @name = "#{@blueprint}_#{@name}" unless @blueprint == :master
end

Class Method Details

+ (Object) factories



81
82
83
84
85
86
87
88
89
# File 'lib/pickle/adapter.rb', line 81

def self.factories
  factories = []
  model_classes.each do |klass|
    if blueprints = klass.instance_variable_get('@blueprints')
      blueprints.keys.each {|blueprint| factories << new(klass, blueprint)}
    end
  end
  factories
end

Instance Method Details

- (Object) create(attrs = {})



97
98
99
100
101
102
103
# File 'lib/pickle/adapter.rb', line 97

def create(attrs = {})
  if @klass.respond_to?('make!')
    @klass.send(:make!, @blueprint, attrs)
  else
    @klass.send(:make, @blueprint, attrs)
  end
end