Class: Clickwrap::Statement

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = options

  @document_keys = Array(options[:document]).map(&:to_s)
  @assertion = LocalizedText.new(options[:statement])
  @label = LocalizedText.new(options[:label])
  @link_labels = build_link_labels(options[:link_label])
  @choices = normalize_choices(options[:choices])
  @purpose_key = (options[:purpose] || key).to_s
  @withdrawal_path = options[:withdrawal_path]
  @valid_for = options[:valid_for]
  @requires = Array(options[:requires]).map(&:to_s)
  @subject_fingerprint_with = options[:subject_fingerprint_with]
  @subject_fingerprint_version = options[:subject_fingerprint_version]&.to_s
  @record_protected_outcome_with = options[:record_protected_outcome_with]
  @protected_outcome_version = options[:protected_outcome_version]&.to_s

  validate!
  freeze
end

Instance Attribute Details

#assertionObject (readonly)

Returns the value of attribute assertion.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def assertion
  @assertion
end

#choicesObject (readonly)

Returns the value of attribute choices.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def choices
  @choices
end

#document_keysObject (readonly)

Returns the value of attribute document_keys.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def document_keys
  @document_keys
end

#keyObject (readonly)

Returns the value of attribute key.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def key
  @key
end

#kindObject (readonly)

Returns the value of attribute kind.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def kind
  @kind
end

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def label
  @label
end

Returns the value of attribute link_labels.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def link_labels
  @link_labels
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def options
  @options
end

#ordinalObject (readonly)

Returns the value of attribute ordinal.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def ordinal
  @ordinal
end

#protected_outcome_versionObject (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_keyObject (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_withObject (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

#requiresObject (readonly)

Returns the value of attribute requires.



14
15
16
# File 'lib/clickwrap/statement.rb', line 14

def requires
  @requires
end

#subject_fingerprint_versionObject (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_withObject (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_forObject (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_pathObject (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

Returns:

  • (Boolean)


67
# File 'lib/clickwrap/statement.rb', line 67

def correctable? = Vocabulary.correctable?(kind)

#expirable?Boolean

Returns:

  • (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_actionObject



64
# File 'lib/clickwrap/statement.rb', line 64

def initial_action = Vocabulary.initial_action_for(kind)

#one_time?Boolean

Returns:

  • (Boolean)


56
# File 'lib/clickwrap/statement.rb', line 56

def one_time? = options.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.

Returns:

  • (Boolean)


48
# File 'lib/clickwrap/statement.rb', line 48

def optional? = options.fetch(:optional, false) == true

#required?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


54
# File 'lib/clickwrap/statement.rb', line 54

def requires_an_explicit_choice? = options.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.

Returns:

  • (Boolean)


61
# File 'lib/clickwrap/statement.rb', line 61

def requires_current_version? = options.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

Returns:

  • (Boolean)


63
# File 'lib/clickwrap/statement.rb', line 63

def subject_bound? = !subject_fingerprint_with.nil?

#to_snapshotObject



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

Returns:

  • (Boolean)


65
# File 'lib/clickwrap/statement.rb', line 65

def withdrawable? = Vocabulary.withdrawable?(kind)