Class: FlossFunding::ActivationEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/floss_funding/activation_event.rb

Overview

Represents a single funding-related activation event for a Library.
Tracks mutable state across: “activated”, “unactivated”, and “invalid”.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(library, activation_key, state, silent) ⇒ ActivationEvent

Returns a new instance of ActivationEvent.

Parameters:

  • library (FlossFunding::Library)
  • activation_key (String)
  • state (Symbol, String)

    initial state (defaults to :unactivated)

  • silent (Object, nil)

    optional silence flag or callable captured at event creation



22
23
24
25
26
27
28
29
30
31
# File 'lib/floss_funding/activation_event.rb', line 22

def initialize(library, activation_key, state, silent)
  @library = library
  @activation_key = activation_key
  @state = state # has already been normalized by FlossFunding::Inclusion
  # Always use the deterministic time source from FlossFunding
  @occurred_at = ::FlossFunding.loaded_at
  @silent = silent
  validate!
  freeze
end

Instance Attribute Details

#activation_keyString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/floss_funding/activation_event.rb', line 10

def activation_key
  @activation_key
end

#libraryFlossFunding::Library (readonly)



8
9
10
# File 'lib/floss_funding/activation_event.rb', line 8

def library
  @library
end

#occurred_atTime (readonly)

Returns:

  • (Time)


14
15
16
# File 'lib/floss_funding/activation_event.rb', line 14

def occurred_at
  @occurred_at
end

#silentObject? (readonly)

Returns flag or callable indicating silent preference.

Returns:

  • (Object, nil)

    flag or callable indicating silent preference



16
17
18
# File 'lib/floss_funding/activation_event.rb', line 16

def silent
  @silent
end

#stateString

Returns one of STATE_VALUES.

Returns:

  • (String)

    one of STATE_VALUES



12
13
14
# File 'lib/floss_funding/activation_event.rb', line 12

def state
  @state
end

Instance Method Details

#validate!Object



33
34
35
36
# File 'lib/floss_funding/activation_event.rb', line 33

def validate!
  raise FlossFunding::Error, "#{@state.inspect} (#{@state.class}) must be one of #{STATE_VALUES}" unless STATE_VALUES.include?(@state)
  raise FlossFunding::Error, "silent must be nil or respond to call (silent=true short circuits)" unless @silent.nil? || @silent.respond_to?(:call)
end