Class: Huginn::Datatable::AllowedPaths
- Inherits:
-
Object
- Object
- Huginn::Datatable::AllowedPaths
- Defined in:
- lib/huginn/datatable/allowed_paths.rb
Overview
Expands the allowed_paths: allowlist into its canonical association
chains and answers whether a given chain is authorized.
Accepts the same shapes Rails knows: a Symbol, a String, a Hash of nested associations, or an Array mixing those — e.g.
allowed_paths: [:company, { company: :people }, "products"]
Every path is canonicalized through the reflection so that table names and public aliases map to the association name the querier actually walks.
Class Method Summary collapse
Instance Method Summary collapse
- #allow(reference_or_spec) ⇒ Object
- #any? ⇒ Boolean
-
#include?(path) ⇒ Boolean
Canonical association-name path for a Validator/association Path.
-
#include_path(path) ⇒ Object
Authorizes an association chain produced by a huginn_attributes alias (canonicalized), even when the raw allowlist does not mention it.
-
#initialize(model, spec) ⇒ AllowedPaths
constructor
A new instance of AllowedPaths.
- #to_a ⇒ Object
Constructor Details
#initialize(model, spec) ⇒ AllowedPaths
Returns a new instance of AllowedPaths.
21 22 23 24 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 21 def initialize(model, spec) @model = model @allowed = (spec) end |
Class Method Details
.call(model, spec) ⇒ Object
17 18 19 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 17 def self.call(model, spec) new(model, spec) end |
Instance Method Details
#allow(reference_or_spec) ⇒ Object
26 27 28 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 26 def allow(reference_or_spec) self.class.call(@model, reference_or_spec) end |
#any? ⇒ Boolean
44 45 46 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 44 def any? @allowed.any? end |
#include?(path) ⇒ Boolean
Canonical association-name path for a Validator/association Path.
37 38 39 40 41 42 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 37 def include?(path) return false if path.blank? canonical = canonicalize_path(path) @allowed.include?(canonical) end |
#include_path(path) ⇒ Object
Authorizes an association chain produced by a huginn_attributes alias (canonicalized), even when the raw allowlist does not mention it.
32 33 34 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 32 def include_path(path) @allowed << canonicalize_path(path) end |
#to_a ⇒ Object
48 49 50 |
# File 'lib/huginn/datatable/allowed_paths.rb', line 48 def to_a @allowed.dup end |