module Lanes::Concerns::ExportScope
@see ClassMethods
Public Instance Methods
export_scope(name, limit: nil)
click to toggle source
Mark scope as query-able by the API
. @param name [Symbol,String] Rails will create a class method with this name @param query [lambda] Arel query. This is passed off to Rail's for setting up the scope. @param limit [Symbol referring to a Class method name, lambda] If given, this will be queried by the API
to determining if a given user may call the scope @return nil
# File lib/lanes/concerns/export_scope.rb, line 38 def export_scope(name, limit: nil) include ExportedLimitEvaluator self.exported_scopes ||= Hash.new self.exported_scopes[name.to_sym] = { name: name, limit: limit } nil end
has_exported_scope?(name, user)
click to toggle source
The api can query this to determine if the scope is safe to be called from the API
by [user] @param name [Symbol,String] name of scope @param user [User] who is performing the request.
This is passed off to the method or lambda that was given as the limit argument in {#export_scope}
# File lib/lanes/concerns/export_scope.rb, line 54 def has_exported_scope?(name, user) if self.exported_scopes && ( scope_options = self.exported_scopes[ name.to_sym ] ) return evaluate_export_limit( user, :scope, name, scope_options[:limit] ) else return false end end
scope(name, body, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/lanes/concerns/export_scope.rb, line 25 def scope(name, body, options = {}, &block) super(name, body, &block) if (export = options[:export]) export_scope(name, limit: (export == true ? nil : export[:limit])) end end