Module: Skr::Concerns::ExportScope::ClassMethods
- Defined in:
- lib/skr/concerns/export_scope.rb
Overview
### Mark a scope as “exportable”
An exported scope is safe for querying by external clients over the API. The scope should always:
* Safely escape data *(should __ALWAYS__ do this anyway, but it bears mentioning again)*
* Be relatively simple and complete quickly.
* Provide value to the client that it cannot obtain by using normal query methods
Instance Method Summary collapse
-
#export_scope(name, query, limit: nil) ⇒ Object
Mark scope as query-able by the API.
-
#has_exported_scope?(name, user) ⇒ Boolean
The api can query this to determine if the scope is safe to be called from the API by [user].
- #scope(name, body, options = {}, &block) ⇒ Object
Instance Method Details
#export_scope(name, query, limit: nil) ⇒ Object
Mark scope as query-able by the API. If given, this will be queried by the API to determining if a given user may call the scope
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/skr/concerns/export_scope.rb', line 38 def export_scope(name, query, limit: nil) include ExportedLimitEvaluator self.exported_scopes ||= Hash.new self.exported_scopes[name.to_sym] = { scope: scope(name, query), name: name, limit: limit } nil end |
#has_exported_scope?(name, user) ⇒ Boolean
The api can query this to determine if the scope is safe to be called from the API by [user]
56 57 58 59 60 61 62 |
# File 'lib/skr/concerns/export_scope.rb', line 56 def has_exported_scope?(name, user) if self.exported_scopes && ( = self.exported_scopes[ name.to_sym ] ) return evaluate_export_limit( user, :scope, name, [:limit] ) else return false end end |
#scope(name, body, options = {}, &block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/skr/concerns/export_scope.rb', line 25 def scope(name, body, = {}, &block) super(name, body, &block) if (export = [:export]) export_scope(name, body, limit: (export == true ? nil : export[:limit])) end end |