Class: Browsable::Policy
- Inherits:
-
Object
- Object
- Browsable::Policy
- Defined in:
- lib/browsable/policy.rb
Overview
The effective ‘allow_browser` policy for a specific controller#action.
Policy is what runtime mode produces per response — distinct from PolicyScanner::Policy, which is a discovery record for one callsite. A Policy carries enough information to (a) build a Target against which the endpoint’s assets are audited, and (b) explain why this is the policy in play, when the TestReport renders findings.
Instance Attribute Summary collapse
-
#except ⇒ Object
readonly
Returns the value of attribute except.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#only ⇒ Object
readonly
Returns the value of attribute only.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#default? ⇒ Boolean
True when this Policy is the application-wide fallback rather than a specific allow_browser call.
-
#initialize(versions:, note: nil, scope: nil, only: nil, except: nil, source: :controller) ⇒ Policy
constructor
A new instance of Policy.
-
#label ⇒ Object
A short human label, e.g.
-
#target ⇒ Object
The Browsable::Target this policy implies.
Constructor Details
#initialize(versions:, note: nil, scope: nil, only: nil, except: nil, source: :controller) ⇒ Policy
Returns a new instance of Policy.
20 21 22 23 24 25 26 27 |
# File 'lib/browsable/policy.rb', line 20 def initialize(versions:, note: nil, scope: nil, only: nil, except: nil, source: :controller) @versions = versions @note = note @scope = scope @only = only @except = except @source = source end |
Instance Attribute Details
#except ⇒ Object (readonly)
Returns the value of attribute except.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def except @except end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def note @note end |
#only ⇒ Object (readonly)
Returns the value of attribute only.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def only @only end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def scope @scope end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def source @source end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
12 13 14 |
# File 'lib/browsable/policy.rb', line 12 def versions @versions end |
Instance Method Details
#as_json ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/browsable/policy.rb', line 52 def as_json { versions: versions, note: note, scope: scope, only: only, except: except, source: source.to_s } end |
#default? ⇒ Boolean
True when this Policy is the application-wide fallback rather than a specific allow_browser call. Distinguished so reports can say “no controller policy — audited against the project default”.
50 |
# File 'lib/browsable/policy.rb', line 50 def default? = source == :default |
#label ⇒ Object
A short human label, e.g. “:modern” or “{ chrome: 120, … }” — used by the TestReport when it wants to print which policy applied.
39 40 41 42 43 44 45 |
# File 'lib/browsable/policy.rb', line 39 def label case versions when Symbol then ":#{versions}" when Hash then "{ #{versions.map { |k, v| "#{k}: #{v}" }.join(', ')} }" else "(unresolved)" end end |
#target ⇒ Object
The Browsable::Target this policy implies. Falls back to the browserslist ‘defaults` query when no allow_browser versions could be resolved.
31 32 33 34 35 |
# File 'lib/browsable/policy.rb', line 31 def target return Target.from_rails_policy(versions) if versions Target.new("defaults") end |