Class: Clickwrap::ActorProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/clickwrap/actor_proxy.rb

Overview

user.clickwraps — the everyday API.

Each predicate reads as the question it answers, and each one asks about the specific act it names. agreed_to?(:terms) is not the same question as consented_to?(:marketing), and neither is answered by a generic accepted_at timestamp. That is the whole point of having six kinds.

Two things these predicates deliberately never do. They never treat a system exemption as a human action — an exemption answers exempted_from? and nothing else. And they never infer a "yes" from missing data: no evidence means no, every time.

Defined Under Namespace

Classes: ReceiptCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor) ⇒ ActorProxy

Returns a new instance of ActorProxy.



16
17
18
# File 'lib/clickwrap/actor_proxy.rb', line 16

def initialize(actor)
  @actor = actor
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



20
21
22
# File 'lib/clickwrap/actor_proxy.rb', line 20

def actor
  @actor
end

Instance Method Details

#acknowledged?(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/clickwrap/actor_proxy.rb', line 37

def acknowledged?(statement_key, subject: nil, tenant: nil, acting_for: nil)
  satisfied?("acknowledgment", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#agreed_to?(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/clickwrap/actor_proxy.rb', line 33

def agreed_to?(statement_key, subject: nil, tenant: nil, acting_for: nil)
  satisfied?("agreement", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#attested?(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/clickwrap/actor_proxy.rb', line 50

def attested?(statement_key, subject: nil, tenant: nil, acting_for: nil)
  satisfied?("attestation", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#authorization(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Object



78
79
80
# File 'lib/clickwrap/actor_proxy.rb', line 78

def authorization(statement_key, subject: nil, tenant: nil, acting_for: nil)
  state_for("authorization", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#authorized?(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/clickwrap/actor_proxy.rb', line 54

def authorized?(statement_key, subject: nil, tenant: nil, acting_for: nil)
  satisfied?("authorization", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end


74
75
76
# File 'lib/clickwrap/actor_proxy.rb', line 74

def consent(purpose_key, subject: nil, tenant: nil, acting_for: nil)
  state_for_purpose(purpose_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#consented_to?(purpose_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/clickwrap/actor_proxy.rb', line 41

def consented_to?(purpose_key, subject: nil, tenant: nil, acting_for: nil)
  state = state_for_purpose(purpose_key, subject: subject, tenant: tenant, acting_for: acting_for)
  !state.nil? && state.satisfies?
end

#current_for?(policy_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

--- Predicates -----------------------------------------------------------

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/clickwrap/actor_proxy.rb', line 24

def current_for?(policy_key, subject: nil, tenant: nil, acting_for: nil)
  Clickwrap.current?(policy_key, actor: actor, subject: subject, tenant: tenant,
                                 acting_for: acting_for)
end

#declaration(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Object

--- Records --------------------------------------------------------------



70
71
72
# File 'lib/clickwrap/actor_proxy.rb', line 70

def declaration(statement_key, subject: nil, tenant: nil, acting_for: nil)
  state_for("declaration", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#declared?(statement_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/clickwrap/actor_proxy.rb', line 46

def declared?(statement_key, subject: nil, tenant: nil, acting_for: nil)
  satisfied?("declaration", statement_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#eventsObject



82
83
84
# File 'lib/clickwrap/actor_proxy.rb', line 82

def events
  Event.for_actor(actor_reference).chronological
end

#exempted_from?(policy_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Deliberately a separate question. An exemption records that no human action occurred, so it can never answer agreed_to? — the whole reason to record one is that the difference matters.

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/clickwrap/actor_proxy.rb', line 61

def exempted_from?(policy_key, subject: nil, tenant: nil, acting_for: nil)
  states(subject: subject, tenant: tenant, acting_for: acting_for)
    .for_policy(policy_key)
    .where(state: "exempted")
    .exists?
end

#receiptsObject



86
87
88
# File 'lib/clickwrap/actor_proxy.rb', line 86

def receipts
  ReceiptCollection.new(events.where(event_type: Vocabulary::ACTOR_RECEIPT_EVENT_TYPES))
end

#required_for?(policy_key, subject: nil, tenant: nil, acting_for: nil) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/clickwrap/actor_proxy.rb', line 29

def required_for?(policy_key, subject: nil, tenant: nil, acting_for: nil)
  !current_for?(policy_key, subject: subject, tenant: tenant, acting_for: acting_for)
end

#statement_statesObject



90
# File 'lib/clickwrap/actor_proxy.rb', line 90

def statement_states = StatementState.for_actor(actor_reference)

#to_sObject



92
# File 'lib/clickwrap/actor_proxy.rb', line 92

def to_s = "clickwraps for #{actor_reference}"