Class: ActiveData::Model::Associations::PersistenceAdapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_data/model/associations/persistence_adapters/base.rb

Direct Known Subclasses

ActiveRecord

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_source, primary_key, scope_proc = nil) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 8

def initialize(data_source, primary_key, scope_proc = nil)
  @data_source = data_source
  @primary_key = primary_key
  @scope_proc = scope_proc
end

Instance Attribute Details

#data_sourceObject (readonly)

Returns the value of attribute data_source.



6
7
8
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 6

def data_source
  @data_source
end

#primary_keyObject (readonly)

Returns the value of attribute primary_key.



6
7
8
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 6

def primary_key
  @primary_key
end

#scope_procObject (readonly)

Returns the value of attribute scope_proc.



6
7
8
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 6

def scope_proc
  @scope_proc
end

Instance Method Details

#build(_attributes) ⇒ Object

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 14

def build(_attributes)
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Build new instance of data object by attributes'
end

#data_typeObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 38

def data_type
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Type of data object for type_check'
end

#find_all(owner, identificators) ⇒ Object



30
31
32
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 30

def find_all(owner, identificators)
  scope(owner, identificators).to_a
end

#find_one(owner, identificator) ⇒ Object



26
27
28
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 26

def find_one(owner, identificator)
  scope(owner, identificator).first
end

#identify(_object) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 34

def identify(_object)
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Field to be used as primary_key for object'
end

#persist(_object) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 18

def persist(_object, *)
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Build new instance of data object by attributes'
end

#primary_key_typeObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 42

def primary_key_type
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Ruby data type'
end

#referenced_proxyObject

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 46

def referenced_proxy
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Object to manage proxying of methods to scope.'
end

#scope(_owner, _source) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/active_data/model/associations/persistence_adapters/base.rb', line 22

def scope(_owner, _source)
  raise NotImplementedError, 'Should be implemented in inhereted adapter. Better to be Enumerable'
end