Class: Telm::Core::Query
- Inherits:
-
Object
- Object
- Telm::Core::Query
- Defined in:
- lib/telm/core/query.rb
Overview
Safe relation builder. Security invariant: sort/dir are validated against the introspected schema before touching the relation — an unknown value raises InvalidQuery (rendered as a 400), never reaching SQL. Everything is built from an allowlist of relation calls; params are never interpolated. Results are always LIMITed.
Defined Under Namespace
Classes: InvalidQuery, Result
Constant Summary collapse
- PER_PAGE =
25- DIRECTIONS =
%w[asc desc].freeze
Instance Method Summary collapse
-
#initialize(resource, options = {}) ⇒ Query
constructor
Accepts :page, :sort, :dir, :fk, :fk_id as a plain hash.
- #result ⇒ Object
Constructor Details
#initialize(resource, options = {}) ⇒ Query
Accepts :page, :sort, :dir, :fk, :fk_id as a plain hash.
37 38 39 40 41 42 43 |
# File 'lib/telm/core/query.rb', line 37 def initialize(resource, = {}) @resource = resource @page = [[:page].to_i, 1].max @sort = validate_sort([:sort]) @dir = validate_dir([:dir]) @fk, @fk_id = validate_fk([:fk], [:fk_id]) end |