module JSONAPI::Realizer::Adapter::ActiveRecord
Public Instance Methods
filtering(scope, filters)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 13 def filtering(scope, filters) scope.where(filters.slice(*scope.column_names)) end
find_many(scope)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 5 def find_many(scope) scope.all end
find_one(scope, id)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 9 def find_one(scope, id) scope.find(id) end
include_relationships(scope, includes)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 44 def include_relationships(scope, includes) scope.eager_load(*includes.map(&method(:arel_chain))) end
paginate(scope, per, offset)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 32 def paginate(scope, per, offset) scope.page(offset).per(per) end
sorting(scope, sorts)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 17 def sorting(scope, sorts) scope.order( *sorts. map do |(keychain, direction)| [keychain, if direction == "-" then :DESC else :ASC end] end. map do |(keychain, direction)| [keychain.map {|key| key.inspect}.join("."), direction] end. map do |pair| Arel.sql(pair.join(" ")) end ) end
write_attributes(model, attributes)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 36 def write_attributes(model, attributes) model.assign_attributes(attributes) end
write_relationships(model, relationships)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 40 def write_relationships(model, relationships) model.assign_attributes(relationships) end
Private Instance Methods
arel_chain(chains)
click to toggle source
# File lib/jsonapi/realizer/adapter/active_record.rb, line 48 def arel_chain(chains) if chains.size == 1 chains.first else {chains.first => arel_chain(chains.drop(1))} end end