Class: Xapit::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/xapit/adapters/abstract_adapter.rb

Overview

Adapters are used to support multiple ORMs (ActiveRecord, Datamapper, Sequel, etc.). It abstracts out all find calls so they can be handled differently for each ORM. To create your own adapter, subclass AbstractAdapter and override the placeholder methods. See ActiveRecordAdapter for an example.

Direct Known Subclasses

ActiveRecordAdapter, DataMapperAdapter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ AbstractAdapter

Sets the @target instance, this is the class the adapter needs to forward its messages to.



19
20
21
# File 'lib/xapit/adapters/abstract_adapter.rb', line 19

def initialize(target)
  @target = target
end

Class Method Details

.for_class?(member_class) ⇒ Boolean

Used to determine if the given adapter should be used for the passed in class. Usually one will see if it inherits from another class (ActiveRecord::Base)

Returns:

  • (Boolean)


25
26
27
# File 'lib/xapit/adapters/abstract_adapter.rb', line 25

def self.for_class?(member_class)
  raise "To be implemented in subclass"
end

.inherited(subclass) ⇒ Object



7
8
9
10
# File 'lib/xapit/adapters/abstract_adapter.rb', line 7

def self.inherited(subclass)
  @subclasses ||= []
  @subclasses << subclass
end

.subclassesObject

Returns all adapter classes.



13
14
15
# File 'lib/xapit/adapters/abstract_adapter.rb', line 13

def self.subclasses
  @subclasses
end

Instance Method Details

#find_each(*args, &block) ⇒ Object

Iiterate through all records using the given parameters. It should yield to the block and pass in each record individually. The args are the same as those passed from the XapitMember#xapit call.



43
44
45
# File 'lib/xapit/adapters/abstract_adapter.rb', line 43

def find_each(*args, &block)
  raise "To be implemented in subclass"
end

#find_multiple(ids) ⇒ Object

Fetch multiple records from the passed in array of ids.



36
37
38
# File 'lib/xapit/adapters/abstract_adapter.rb', line 36

def find_multiple(ids)
  raise "To be implemented in subclass"
end

#find_single(id, *args) ⇒ Object

Fetch a single record by the given id. The args are the same as those passed from the XapitMember#xapit call.



31
32
33
# File 'lib/xapit/adapters/abstract_adapter.rb', line 31

def find_single(id, *args)
  raise "To be implemented in subclass"
end