Class: Horza::Adapters::AbstractAdapter
- Inherits:
-
Object
- Object
- Horza::Adapters::AbstractAdapter
- Defined in:
- lib/horza/adapters/abstract_adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
- .context_for_entity(entity) ⇒ Object
- .entity_context_map ⇒ Object
- .expected_errors ⇒ Object
- .not_implemented_error ⇒ Object
Instance Method Summary collapse
- #ancestors(options = {}) ⇒ Object
- #create(options = {}) ⇒ Object
- #create!(options = {}) ⇒ Object
- #delete(id) ⇒ Object
- #delete!(id) ⇒ Object
- #eager_load(options = {}) ⇒ Object
- #entity_class(res = @context) ⇒ Object
- #find_all(options = {}) ⇒ Object
- #find_first(options = {}) ⇒ Object
- #find_first!(options = {}) ⇒ Object
- #get(options = {}) ⇒ Object
- #get!(options = {}) ⇒ Object
-
#initialize(context) ⇒ AbstractAdapter
constructor
A new instance of AbstractAdapter.
- #to_hash ⇒ Object
- #update(id, options = {}) ⇒ Object
- #update!(id, options = {}) ⇒ Object
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
#context ⇒ Object (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_map ⇒ Object
15 16 17 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 15 def entity_context_map not_implemented_error end |
.expected_errors ⇒ Object
7 8 9 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 7 def expected_errors [::Horza::Errors::RecordNotFound, ::Horza::Errors::RecordInvalid] end |
.not_implemented_error ⇒ Object
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( = {}) not_implemented_error end |
#create(options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 50 def create( = {}) create!() rescue *self.class.expected_errors end |
#create!(options = {}) ⇒ Object
55 56 57 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 55 def create!( = {}) 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( = {}) 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( = {}) not_implemented_error end |
#find_first(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 37 def find_first( = {}) find_first!() 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!( = {}) not_implemented_error end |
#get(options = {}) ⇒ Object
28 29 30 31 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 28 def get( = {}) get!() rescue *self.class.expected_errors end |
#get!(options = {}) ⇒ Object
33 34 35 |
# File 'lib/horza/adapters/abstract_adapter.rb', line 33 def get!( = {}) not_implemented_error end |
#to_hash ⇒ Object
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, = {}) update!(id, ) 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, = {}) not_implemented_error end |