Class: Clickwrap::AnonymousActor

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

Overview

An actor who is not a persisted record: someone completing a checkout, an applicant, a visitor acting before any account exists.

The identifier is host-owned and opaque, and the host owns any later account linking and every identity or capacity question that goes with it.

An IP address is explicitly not acceptable here. It is not stable, it is not unique to a person, it is shared by households and offices and whole networks, and using one as an actor identifier would put a claim in the evidence that the evidence cannot support. The constructor refuses one rather than letting it become a hard-to-notice mistake.

Constant Summary collapse

IP_ADDRESS_PATTERN =
/\A(\d{1,3}\.){3}\d{1,3}\z|\A[0-9a-f:]+:[0-9a-f:]*\z/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ AnonymousActor

Returns a new instance of AnonymousActor.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/clickwrap/anonymous_actor.rb', line 20

def initialize(identifier)
  @identifier = identifier.to_s

  if @identifier.strip.empty?
    raise ArgumentError,
          "An anonymous actor needs a stable identifier your application owns, for example " \
          "\"checkout_#{signed_checkout_id}\"."
  end

  if IP_ADDRESS_PATTERN.match?(@identifier)
    raise ArgumentError,
          "#{@identifier.inspect} looks like an IP address. An IP address is not an actor: " \
          "it is shared, reassigned, and proxied, so evidence attributed to one would claim " \
          "more than it can support. Use a stable identifier your application controls."
  end

  freeze
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



18
19
20
# File 'lib/clickwrap/anonymous_actor.rb', line 18

def identifier
  @identifier
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



43
# File 'lib/clickwrap/anonymous_actor.rb', line 43

def ==(other) = other.is_a?(self.class) && other.identifier == identifier

#clickwrap_actor_referenceObject



39
# File 'lib/clickwrap/anonymous_actor.rb', line 39

def clickwrap_actor_reference = "anonymous/#{identifier}"

#hashObject



45
# File 'lib/clickwrap/anonymous_actor.rb', line 45

def hash = [self.class, identifier].hash

#idObject



40
# File 'lib/clickwrap/anonymous_actor.rb', line 40

def id = identifier

#persisted?Boolean

Returns:

  • (Boolean)


42
# File 'lib/clickwrap/anonymous_actor.rb', line 42

def persisted? = false

#to_sObject



41
# File 'lib/clickwrap/anonymous_actor.rb', line 41

def to_s = clickwrap_actor_reference