Class: Pickle::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/pickle/adapter.rb

Overview

Abstract Factory adapter class, if you have a factory type setup, you can easily create an adaptor to make it work with Pickle.

The factory adaptor must have a #factories class method that returns its instances, and each instance must respond to:

#name : identifies the factory by name (default is attr_reader)
#klass : returns the associated model class for this factory (default is attr_reader)
#create(attrs = {}) : returns a newly created object

Direct Known Subclasses

FactoryGirl, Machinist, Orm

Defined Under Namespace

Modules: Base Classes: FactoryGirl, Machinist, Orm

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



14
15
16
# File 'lib/pickle/adapter.rb', line 14

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/pickle/adapter.rb', line 14

def name
  @name
end

Class Method Details

.column_names(klass) ⇒ Object

Returns the column names for the given ORM model class.



58
59
60
# File 'lib/pickle/adapter.rb', line 58

def column_names(klass)
  klass.const_get(:PickleAdapter).column_names(klass)
end

.create_model(klass, attributes) ⇒ Object



74
75
76
# File 'lib/pickle/adapter.rb', line 74

def create_model(klass, attributes)
  klass.const_get(:PickleAdapter).create_model(klass, attributes)
end

.factoriesObject

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/pickle/adapter.rb', line 49

def factories
  raise NotImplementedError, "return an array of factory adapter objects"
end

.find_all_models(klass, conditions) ⇒ Object



70
71
72
# File 'lib/pickle/adapter.rb', line 70

def find_all_models(klass, conditions)
  klass.const_get(:PickleAdapter).find_all_models(klass, conditions)
end

.find_first_model(klass, conditions) ⇒ Object



66
67
68
# File 'lib/pickle/adapter.rb', line 66

def find_first_model(klass, conditions)
  klass.const_get(:PickleAdapter).find_first_model(klass, conditions)
end

.get_model(klass, id) ⇒ Object



62
63
64
# File 'lib/pickle/adapter.rb', line 62

def get_model(klass, id)
  klass.const_get(:PickleAdapter).get_model(klass, id)
end

.model_classesObject



53
54
55
# File 'lib/pickle/adapter.rb', line 53

def model_classes
  @@model_classes ||= self::Base.adapters.map{ |a| a.model_classes }.flatten
end

Instance Method Details

#create(attrs = {}) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/pickle/adapter.rb', line 16

def create(attrs = {})
  raise NotImplementedError, "create and return an object with the given attributes"
end