Class: Horza::Adapters::ActiveRecord
Constant Summary
collapse
- INVALID_ANCESTRY_MSG =
'Invalid relation. Ensure that the plurality of your associations is correct.'
- CONTEXT_NAMESPACE =
::ActiveRecord::Base
Instance Attribute Summary
#context
Class Method Summary
collapse
Instance Method Summary
collapse
#context_for_entity, #expected_errors, #expected_horza_errors, #horza_error_from_orm_error, #lazy_load_model, #not_implemented_error
#create, #delete, #find_first, #get, #initialize, #update
Class Method Details
.entity_context_map ⇒ Object
.expected_errors_map ⇒ Object
Instance Method Details
#association(options = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/horza/adapters/active_record.rb', line 59
def association(options = {})
run_and_convert_exceptions do
options = Options.new(options)
base = @context
base = base.includes(options.eager_args) if options.eager_load?
base = base.find(options.id)
result = walk_family_tree(base, options)
return nil unless result
collection?(result) ? entity_class(query(options, result)) : entity_class(result.attributes)
end
end
|
#create!(options = {}) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/horza/adapters/active_record.rb', line 34
def create!(options = {})
run_and_convert_exceptions do
record = @context.new(options)
record.save!
entity_class(record.attributes)
end
end
|
#delete!(id) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/horza/adapters/active_record.rb', line 51
def delete!(id)
run_and_convert_exceptions do
record = @context.find(id)
record.destroy
true
end
end
|
#find_all(options = {}) ⇒ Object
30
31
32
|
# File 'lib/horza/adapters/active_record.rb', line 30
def find_all(options = {})
run_and_convert_exceptions { entity_class(query(options)) }
end
|
#find_first!(options = {}) ⇒ Object
26
27
28
|
# File 'lib/horza/adapters/active_record.rb', line 26
def find_first!(options = {})
run_and_convert_exceptions { entity_class(query(options).first!.attributes) }
end
|
#get!(id) ⇒ Object
22
23
24
|
# File 'lib/horza/adapters/active_record.rb', line 22
def get!(id)
run_and_convert_exceptions { entity_class(@context.find(id).attributes) }
end
|
#update!(id, options = {}) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/horza/adapters/active_record.rb', line 42
def update!(id, options = {})
run_and_convert_exceptions do
record = @context.find(id)
record.assign_attributes(options)
record.save!
entity_class(record.attributes)
end
end
|