Class: Granite::Form::Model::Associations::PersistenceAdapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/granite/form/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.



9
10
11
12
13
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 9

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.



7
8
9
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 7

def data_source
  @data_source
end

#primary_keyObject (readonly)

Returns the value of attribute primary_key.



7
8
9
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 7

def primary_key
  @primary_key
end

#scope_procObject (readonly)

Returns the value of attribute scope_proc.



7
8
9
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 7

def scope_proc
  @scope_proc
end

Instance Method Details

#build(_attributes) ⇒ Object

Raises:

  • (NotImplementedError)


15
16
17
18
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 15

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

#data_typeObject

Raises:

  • (NotImplementedError)


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

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

#find_all(owner, identificators) ⇒ Object



28
29
30
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 28

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

#find_one(owner, identificator) ⇒ Object



24
25
26
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 24

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

#identify(_object) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
35
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 32

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

#primary_key_typeObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/granite/form/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
49
# File 'lib/granite/form/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)


20
21
22
# File 'lib/granite/form/model/associations/persistence_adapters/base.rb', line 20

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