Class: Get::Adapters::ActiveRecord
Instance Attribute Summary
#context
Class Method Summary
collapse
Instance Method Summary
collapse
descendants, #eager_load, #initialize, not_implemented_error
Class Method Details
.context_for_entity(entity) ⇒ Object
9
10
11
|
# File 'lib/get/adapters/active_record.rb', line 9
def context_for_entity(entity)
entity_context_map[entity]
end
|
.entity_context_map ⇒ Object
13
14
15
|
# File 'lib/get/adapters/active_record.rb', line 13
def entity_context_map
@map ||= ::ActiveRecord::Base.descendants.reduce({}) { |hash, (klass)| hash.merge(klass.name.split('::').last.underscore.to_sym => klass) }
end
|
.expected_errors ⇒ Object
5
6
7
|
# File 'lib/get/adapters/active_record.rb', line 5
def expected_errors
[::ActiveRecord::RecordNotFound]
end
|
Instance Method Details
#ancestors(options = {}) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/get/adapters/active_record.rb', line 30
def ancestors(options = {})
get!(options)
walk_family_tree(options)
rescue NoMethodError
raise ::Get::Errors::InvalidAncestry.new('Invalid relation. Ensure that the plurality of your associations is correct.')
end
|
#find_all(options = {}) ⇒ Object
26
27
28
|
# File 'lib/get/adapters/active_record.rb', line 26
def find_all(options = {})
@context = @context.where(options[:conditions]).order('ID DESC')
end
|
#find_first(options = {}) ⇒ Object
22
23
24
|
# File 'lib/get/adapters/active_record.rb', line 22
def find_first(options = {})
@context = find_all(options).limit(1).first!
end
|
#get!(options = {}) ⇒ Object
18
19
20
|
# File 'lib/get/adapters/active_record.rb', line 18
def get!(options = {})
@context = @context.find(options[:id])
end
|
#to_hash ⇒ Object
37
38
39
|
# File 'lib/get/adapters/active_record.rb', line 37
def to_hash
@context.attributes
end
|