Class: Clickwrap::Statement
- Inherits:
-
Object
- Object
- Clickwrap::Statement
- Defined in:
- lib/clickwrap/statement.rb
Overview
One act inside a policy: a single thing the person is asked to do, with the lifecycle its kind actually needs.
A policy can contain several statements — "agree to the Terms" and "acknowledge the Privacy Notice" typically appear on the same screen. They produce one event and one receipt, but they never collapse into one meaning: each statement keeps its own kind, documents, assertion, answer, and lifecycle. That distinction is the whole point of the six kinds, and flattening it is exactly the mistake this gem exists to stop.
Instance Attribute Summary collapse
-
#assertion ⇒ Object
readonly
Returns the value of attribute assertion.
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#document_keys ⇒ Object
readonly
Returns the value of attribute document_keys.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#link_labels ⇒ Object
readonly
Returns the value of attribute link_labels.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#ordinal ⇒ Object
readonly
Returns the value of attribute ordinal.
-
#protected_outcome_version ⇒ Object
readonly
Returns the value of attribute protected_outcome_version.
-
#purpose_key ⇒ Object
readonly
Returns the value of attribute purpose_key.
-
#record_protected_outcome_with ⇒ Object
readonly
Returns the value of attribute record_protected_outcome_with.
-
#requires ⇒ Object
readonly
Returns the value of attribute requires.
-
#subject_fingerprint_version ⇒ Object
readonly
Returns the value of attribute subject_fingerprint_version.
-
#subject_fingerprint_with ⇒ Object
readonly
Returns the value of attribute subject_fingerprint_with.
-
#valid_for ⇒ Object
readonly
Returns the value of attribute valid_for.
-
#withdrawal_path ⇒ Object
readonly
Returns the value of attribute withdrawal_path.
Instance Method Summary collapse
- #correctable? ⇒ Boolean
- #expirable? ⇒ Boolean
- #expires_after(from) ⇒ Object
- #initial_action ⇒ Object
-
#initialize(key:, kind:, ordinal:, options: {}) ⇒ Statement
constructor
A new instance of Statement.
- #one_time? ⇒ Boolean
-
#optional? ⇒ Boolean
Optional statements are offered but never required.
- #required? ⇒ Boolean
-
#requires_an_explicit_choice? ⇒ Boolean
A statement that must be answered one way or the other, with real unselected controls for each choice.
-
#requires_current_version? ⇒ Boolean
When true, evidence against an older published version no longer satisfies this statement.
-
#resolve_copy(locale:) ⇒ Object
Resolves every human-facing string for one locale.
- #subject_bound? ⇒ Boolean
- #to_snapshot ⇒ Object
- #withdrawable? ⇒ Boolean
Constructor Details
#initialize(key:, kind:, ordinal:, options: {}) ⇒ Statement
Returns a new instance of Statement.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clickwrap/statement.rb', line 20 def initialize(key:, kind:, ordinal:, options: {}) @key = key.to_s @kind = kind.to_s @ordinal = ordinal @options = @document_keys = Array([:document]).map(&:to_s) @assertion = LocalizedText.new([:statement]) @label = LocalizedText.new([:label]) @link_labels = build_link_labels([:link_label]) @choices = normalize_choices([:choices]) @purpose_key = ([:purpose] || key).to_s @withdrawal_path = [:withdrawal_path] @valid_for = [:valid_for] @requires = Array([:requires]).map(&:to_s) @subject_fingerprint_with = [:subject_fingerprint_with] @subject_fingerprint_version = [:subject_fingerprint_version]&.to_s @record_protected_outcome_with = [:record_protected_outcome_with] @protected_outcome_version = [:protected_outcome_version]&.to_s validate! freeze end |
Instance Attribute Details
#assertion ⇒ Object (readonly)
Returns the value of attribute assertion.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def assertion @assertion end |
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def choices @choices end |
#document_keys ⇒ Object (readonly)
Returns the value of attribute document_keys.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def document_keys @document_keys end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def key @key end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def kind @kind end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def label @label end |
#link_labels ⇒ Object (readonly)
Returns the value of attribute link_labels.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def link_labels @link_labels end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def @options end |
#ordinal ⇒ Object (readonly)
Returns the value of attribute ordinal.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def ordinal @ordinal end |
#protected_outcome_version ⇒ Object (readonly)
Returns the value of attribute protected_outcome_version.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def protected_outcome_version @protected_outcome_version end |
#purpose_key ⇒ Object (readonly)
Returns the value of attribute purpose_key.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def purpose_key @purpose_key end |
#record_protected_outcome_with ⇒ Object (readonly)
Returns the value of attribute record_protected_outcome_with.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def record_protected_outcome_with @record_protected_outcome_with end |
#requires ⇒ Object (readonly)
Returns the value of attribute requires.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def requires @requires end |
#subject_fingerprint_version ⇒ Object (readonly)
Returns the value of attribute subject_fingerprint_version.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def subject_fingerprint_version @subject_fingerprint_version end |
#subject_fingerprint_with ⇒ Object (readonly)
Returns the value of attribute subject_fingerprint_with.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def subject_fingerprint_with @subject_fingerprint_with end |
#valid_for ⇒ Object (readonly)
Returns the value of attribute valid_for.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def valid_for @valid_for end |
#withdrawal_path ⇒ Object (readonly)
Returns the value of attribute withdrawal_path.
14 15 16 |
# File 'lib/clickwrap/statement.rb', line 14 def withdrawal_path @withdrawal_path end |
Instance Method Details
#correctable? ⇒ Boolean
67 |
# File 'lib/clickwrap/statement.rb', line 67 def correctable? = Vocabulary.correctable?(kind) |
#expirable? ⇒ Boolean
66 |
# File 'lib/clickwrap/statement.rb', line 66 def expirable? = Vocabulary.expirable?(kind) |
#expires_after(from) ⇒ Object
69 70 71 72 73 |
# File 'lib/clickwrap/statement.rb', line 69 def expires_after(from) return nil unless valid_for from + valid_for end |
#initial_action ⇒ Object
64 |
# File 'lib/clickwrap/statement.rb', line 64 def initial_action = Vocabulary.initial_action_for(kind) |
#one_time? ⇒ Boolean
56 |
# File 'lib/clickwrap/statement.rb', line 56 def one_time? = .fetch(:one_time, false) == true |
#optional? ⇒ Boolean
Optional statements are offered but never required. Leaving an optional consent control unselected creates no grant at all — silence is not a refusal, and the receipt says the option was offered and not taken rather than recording a decision the person did not make.
48 |
# File 'lib/clickwrap/statement.rb', line 48 def optional? = .fetch(:optional, false) == true |
#required? ⇒ Boolean
49 |
# File 'lib/clickwrap/statement.rb', line 49 def required? = !optional? |
#requires_an_explicit_choice? ⇒ Boolean
A statement that must be answered one way or the other, with real unselected controls for each choice. Use it when the application needs a recorded decision rather than the absence of one.
54 |
# File 'lib/clickwrap/statement.rb', line 54 def requires_an_explicit_choice? = .fetch(:require_an_explicit_choice, false) == true |
#requires_current_version? ⇒ Boolean
When true, evidence against an older published version no longer satisfies this statement. The application decides which change is material; Clickwrap only enforces the rule it is given.
61 |
# File 'lib/clickwrap/statement.rb', line 61 def requires_current_version? = .fetch(:require_current_version, false) == true |
#resolve_copy(locale:) ⇒ Object
Resolves every human-facing string for one locale. Called when the presentation is built; the resolved text is what gets stored.
77 78 79 80 81 82 83 |
# File 'lib/clickwrap/statement.rb', line 77 def resolve_copy(locale:) { "assertion" => assertion.resolve(locale:).first, "label" => label.resolve(locale:).first, "link_labels" => link_labels.transform_values { |text| text.resolve(locale:).first } } end |
#subject_bound? ⇒ Boolean
63 |
# File 'lib/clickwrap/statement.rb', line 63 def subject_bound? = !subject_fingerprint_with.nil? |
#to_snapshot ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/clickwrap/statement.rb', line 85 def to_snapshot { "key" => key, "kind" => kind, "ordinal" => ordinal, "documents" => document_keys, "assertion" => assertion.to_snapshot, "label" => label.to_snapshot, "link_labels" => link_labels.transform_values(&:to_snapshot), "choices" => choices, "required" => required?, "optional" => optional?, "requires_an_explicit_choice" => requires_an_explicit_choice?, "requires_current_version" => requires_current_version?, "one_time" => one_time?, "purpose_key" => purpose_key, "withdrawal_path" => withdrawal_path, "valid_for_seconds" => valid_for&.to_i, "requires" => requires, "subject_fingerprint_with" => subject_fingerprint_with ? "configured" : nil, "subject_fingerprint_version" => subject_fingerprint_version, "record_protected_outcome_with" => record_protected_outcome_with ? "configured" : nil, "protected_outcome_version" => protected_outcome_version }.compact end |
#withdrawable? ⇒ Boolean
65 |
# File 'lib/clickwrap/statement.rb', line 65 def withdrawable? = Vocabulary.withdrawable?(kind) |