Class: Cliqr::Config::EventBased Private

Inherits:
Base
  • Object
show all
Defined in:
lib/cliqr/config/event_based.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The configuration that enabled events for another configuration

Direct Known Subclasses

Named

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#skip_validation?

Methods included from Validation

#errors, included, #read_attributes, #valid?, #validate, #validations

Methods included from DSL

included

Constructor Details

#initializeEventBased

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

New instance of event based config



17
18
19
# File 'lib/cliqr/config/event_based.rb', line 17

def initialize
  @events = {}
end

Instance Attribute Details

#eventsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Events to listen for

Returns:

  • (Hash)

    A hash of String => Cliqr::Config::Event



12
13
14
# File 'lib/cliqr/config/event_based.rb', line 12

def events
  @events
end

Instance Method Details

#event(name) ⇒ Cliqr::Config::Event

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a event handler config by name



47
48
49
# File 'lib/cliqr/config/event_based.rb', line 47

def event(name)
  @events[name.to_s]
end

#handle?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if a event can be handled in this context

Returns:

  • (Boolean)


40
41
42
# File 'lib/cliqr/config/event_based.rb', line 40

def handle?(name)
  @events.key?(name.to_s)
end

#set_config(name, event_name, *args, &block) ⇒ Cliqr::Config::Event

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a event

Parameters:

  • name (Symbol)

    Name of the attribute

  • event_name (String)

    Event’s name

  • args (Array)

    Event handler

  • block (Proc)

    Event handler function

Returns:



29
30
31
32
33
34
35
36
37
# File 'lib/cliqr/config/event_based.rb', line 29

def set_config(name, event_name, *args, &block)
  case name
  when :on
    # if defined, args[0] will be the custom event handler class
    handle_event(event_name, args[0], &block)
  else
    super
  end
end