Class: RapidApi::ModelAdapters::ActiveRecordAdapter

Inherits:
Abstract
  • Object
show all
Defined in:
lib/rapid_api/model_adapters/active_record_adapter.rb

Instance Attribute Summary

Attributes inherited from Abstract

#klass

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from RapidApi::ModelAdapters::Abstract

Instance Method Details

#create(params, scope = {}) ⇒ Object



16
17
18
19
20
# File 'lib/rapid_api/model_adapters/active_record_adapter.rb', line 16

def create(params, scope={})
  create_params = params.merge scope
  member = klass.create create_params
  _query_result_for_member member
end

#destroy(id, scope = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rapid_api/model_adapters/active_record_adapter.rb', line 30

def destroy(id, scope=nil)
  member = _find_member_with_scope(id, scope)
  if member.present?
    member.destroy
  end
  _query_result_for_member member
end

#find(id, scope = nil) ⇒ Object



5
6
7
8
# File 'lib/rapid_api/model_adapters/active_record_adapter.rb', line 5

def find(id, scope=nil)
  member = _find_member_with_scope(id, scope)
  QueryResult.new data: member
end

#find_all(params = {}, scope = {}) ⇒ Object



10
11
12
13
14
# File 'lib/rapid_api/model_adapters/active_record_adapter.rb', line 10

def find_all(params={}, scope={})
  scoped_params = params.merge scope
  collection = klass.where(scoped_params)
  QueryResult.new data: collection
end

#update(id, params, scope = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rapid_api/model_adapters/active_record_adapter.rb', line 22

def update(id, params, scope=nil)
  member = _find_member_with_scope(id, scope)
  if member.present?
    member.update_attributes params
  end
  _query_result_for_member member
end