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

Fabrication, FactoryBot, Machinist, Orm

Defined Under Namespace

Modules: Base Classes: Fabrication, FactoryBot, 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.



12
13
14
# File 'lib/pickle/adapter.rb', line 12

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/pickle/adapter.rb', line 12

def name
  @name
end

Class Method Details

.column_names(klass) ⇒ Object

Returns the column names for the given ORM model class.



56
57
58
# File 'lib/pickle/adapter.rb', line 56

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

.create_model(klass, attributes) ⇒ Object



72
73
74
# File 'lib/pickle/adapter.rb', line 72

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

.factoriesObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/pickle/adapter.rb', line 47

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

.find_all_models(klass, conditions) ⇒ Object



68
69
70
# File 'lib/pickle/adapter.rb', line 68

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

.find_first_model(klass, conditions) ⇒ Object



64
65
66
# File 'lib/pickle/adapter.rb', line 64

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

.get_model(klass, id) ⇒ Object



60
61
62
# File 'lib/pickle/adapter.rb', line 60

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

.model_classesObject



51
52
53
# File 'lib/pickle/adapter.rb', line 51

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

Instance Method Details

#create(attrs = {}) ⇒ Object

Raises:

  • (NotImplementedError)


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

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