Class: Horza::Adapters::AbstractAdapter

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

Direct Known Subclasses

ActiveRecord

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.



24
25
26
# File 'lib/horza/adapters/abstract_adapter.rb', line 24

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/horza/adapters/abstract_adapter.rb', line 4

def context
  @context
end

Class Method Details

.context_for_entity(entity) ⇒ Object



11
12
13
# File 'lib/horza/adapters/abstract_adapter.rb', line 11

def context_for_entity(entity)
  not_implemented_error
end

.entity_context_mapObject



15
16
17
# File 'lib/horza/adapters/abstract_adapter.rb', line 15

def entity_context_map
  not_implemented_error
end

.expected_errorsObject



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

def expected_errors
  [::Horza::Errors::RecordNotFound, ::Horza::Errors::RecordInvalid]
end

.not_implemented_errorObject



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

def not_implemented_error
  raise ::Horza::Errors::MethodNotImplemented, 'You must implement this method in your adapter.'
end

Instance Method Details

#ancestors(options = {}) ⇒ Object



77
78
79
# File 'lib/horza/adapters/abstract_adapter.rb', line 77

def ancestors(options = {})
  not_implemented_error
end

#create(options = {}) ⇒ Object



50
51
52
53
# File 'lib/horza/adapters/abstract_adapter.rb', line 50

def create(options = {})
  create!(options)
rescue *self.class.expected_errors
end

#create!(options = {}) ⇒ Object



55
56
57
# File 'lib/horza/adapters/abstract_adapter.rb', line 55

def create!(options = {})
  not_implemented_error
end

#delete(id) ⇒ Object



59
60
61
62
# File 'lib/horza/adapters/abstract_adapter.rb', line 59

def delete(id)
  delete!(id)
rescue *self.class.expected_errors
end

#delete!(id) ⇒ Object



64
65
66
# File 'lib/horza/adapters/abstract_adapter.rb', line 64

def delete!(id)
  not_implemented_error
end

#eager_load(options = {}) ⇒ Object



81
82
83
# File 'lib/horza/adapters/abstract_adapter.rb', line 81

def eager_load(options = {})
  not_implemented_error
end

#entity_class(res = @context) ⇒ Object



89
90
91
# File 'lib/horza/adapters/abstract_adapter.rb', line 89

def entity_class(res = @context)
  collection?(res) ? ::Horza::Entities.collection_entity_for(entity_symbol).new(res) : ::Horza::Entities.single_entity_for(entity_symbol).new(res)
end

#find_all(options = {}) ⇒ Object



46
47
48
# File 'lib/horza/adapters/abstract_adapter.rb', line 46

def find_all(options = {})
  not_implemented_error
end

#find_first(options = {}) ⇒ Object



37
38
39
40
# File 'lib/horza/adapters/abstract_adapter.rb', line 37

def find_first(options = {})
  find_first!(options)
rescue *self.class.expected_errors
end

#find_first!(options = {}) ⇒ Object



42
43
44
# File 'lib/horza/adapters/abstract_adapter.rb', line 42

def find_first!(options = {})
  not_implemented_error
end

#get(options = {}) ⇒ Object



28
29
30
31
# File 'lib/horza/adapters/abstract_adapter.rb', line 28

def get(options = {})
  get!(options)
rescue *self.class.expected_errors
end

#get!(options = {}) ⇒ Object



33
34
35
# File 'lib/horza/adapters/abstract_adapter.rb', line 33

def get!(options = {})
  not_implemented_error
end

#to_hashObject



85
86
87
# File 'lib/horza/adapters/abstract_adapter.rb', line 85

def to_hash
  not_implemented_error
end

#update(id, options = {}) ⇒ Object



68
69
70
71
# File 'lib/horza/adapters/abstract_adapter.rb', line 68

def update(id, options = {})
  update!(id, options)
rescue *self.class.expected_errors
end

#update!(id, options = {}) ⇒ Object



73
74
75
# File 'lib/horza/adapters/abstract_adapter.rb', line 73

def update!(id, options = {})
  not_implemented_error
end