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:

  • validation makes sure all the data is in order
  • storage puts the data in the database
  • integration deals with any ramifications of those changes

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],
  skip: :allowed,
  trigger: :required,  # the event is only executed if triggered explicitly with
                       # trigger: [event_name]
}.freeze
CONDITIONS =
::Set.new(%i[on changed 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

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

Constructor Details

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

Returns a new instance of Event.



34
35
36
37
38
39
# File 'lib/card/set/event.rb', line 34

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.



32
33
34
# File 'lib/card/set/event.rb', line 32

def opts
  @opts
end

#set_moduleObject (readonly)

Returns the value of attribute set_module.



32
33
34
# File 'lib/card/set/event.rb', line 32

def set_module
  @set_module
end

Instance Method Details

#blockObject



53
54
55
# File 'lib/card/set/event.rb', line 53

def block
  @event_block
end

#delaying_method_nameObject

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



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

def delaying_method_name
  "#{@event}_with_delay"
end

#nameObject

Returns the name of the event.

Returns:

  • the name of the event



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

def name
  @event
end

#registerObject



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

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



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

def simple_method_name
  "#{@event}_without_callbacks"
end