Class: Card::Set::Event

Inherits:
Object
  • Object
show all
Includes:
Callbacks, DelayedEvent, Options
Defined in:
lib/card/set/event.rb,
lib/card/set/event/options.rb,
lib/card/set/event/callbacks.rb,
lib/card/set/event/delayed_event.rb

Overview

Events are the building blocks of the three transformative card actions: create, update, and delete.

(The fourth kind of action, read, does not transform cards, and is associated with views, not events).

Whenever you create, update, or delete a card, the card goes through three phases:

  • validate makes sure all the data is in order
  • store puts the data in the database
  • integrate deals with any ramifications of those changes

Events can be defined on each of these stages

Defined Under Namespace

Modules: Api, Callbacks, DelayedEvent, Options

Constant Summary collapse

CONDITION_OPTIONS =
{
  on: %i[create update delete save read],
  changed: %i[name content db_content type type_id codename key],
  changing: %i[name content db_content type type_id codename key],
  skip: :allowed,
  trigger: :required  # the event is only executed if triggered explicitly with
  # trigger: [event_name]
}.freeze
CONDITIONS =
::Set.new(%i[on changed changing when skip trigger]).freeze

Constants included from DelayedEvent

DelayedEvent::DELAY_STAGES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#set_event_callback, #set_event_callbacks, #valid_event_callback

Methods included from Options

#callback_name, #event_opts, #normalize_opts, #process_action_opts, #process_stage_opts, #valid_values, #validate_condition_name, #validate_condition_value, #validate_conditions, #validate_when_value

Methods included from DelayedEvent

#priority

Constructor Details

#initialize(event, stage_or_opts, opts, set_module, &final) ⇒ Event

Returns a new instance of Event.



40
41
42
43
44
45
# File 'lib/card/set/event.rb', line 40

def initialize event, stage_or_opts, opts, set_module, &final
  @event = event
  @set_module = set_module
  @opts = event_opts stage_or_opts, opts
  @event_block = final
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



38
39
40
# File 'lib/card/set/event.rb', line 38

def opts
  @opts
end

#set_moduleObject (readonly)

Returns the value of attribute set_module.



38
39
40
# File 'lib/card/set/event.rb', line 38

def set_module
  @set_module
end

Instance Method Details

#blockObject



59
60
61
# File 'lib/card/set/event.rb', line 59

def block
  @event_block
end

#delaying_method_nameObject

the name for the method that adds the event to the delayed job queue



71
72
73
# File 'lib/card/set/event.rb', line 71

def delaying_method_name
  "#{@event}_with_delay"
end

#nameObject

Returns the name of the event.

Returns:

  • the name of the event



55
56
57
# File 'lib/card/set/event.rb', line 55

def name
  @event
end

#registerObject



47
48
49
50
51
52
# File 'lib/card/set/event.rb', line 47

def register
  validate_conditions
  Card.define_callbacks @event
  define_event
  set_event_callbacks
end

#simple_method_nameObject

the name for the method that only executes the code defined in the event



65
66
67
# File 'lib/card/set/event.rb', line 65

def simple_method_name
  "#{@event}_without_callbacks"
end