Class: Saxxy::EventRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/saxxy/event_registry.rb

Overview

The Event Registry is in charge of registering new events and firing the event callback whenever a specific event gets deactivated.

The registry has an @actions instance variable that holds

Author:

  • rubymaniac

Instance Method Summary collapse

Constructor Details

#initializeEventRegistry

Initializes an empty Event Registry


20
21
22
# File 'lib/saxxy/event_registry.rb', line 20

def initialize
  clear
end

Instance Method Details

#activate_events_on(element_name, attributes) ⇒ Object

Activate the active events on a specific node. This is done in order to increase the events' internal counter.


78
79
80
# File 'lib/saxxy/event_registry.rb', line 78

def activate_events_on(element_name, attributes)
  send_on_each_event(:activate_on, element_name, attributes)
end

#clearObject

Clears all registered actions


96
97
98
# File 'lib/saxxy/event_registry.rb', line 96

def clear
  @actions = {}
end

#deactivate_events_on(element_name) ⇒ Object

Deactivate the active events on a specific node


66
67
68
# File 'lib/saxxy/event_registry.rb', line 66

def deactivate_events_on(element_name)
  send_on_each_event(:deactivate_on, element_name)
end

#eventsObject

Loops through the active actions (those registered) and takes the last, i.e. active, event.


46
47
48
# File 'lib/saxxy/event_registry.rb', line 46

def events
  @actions.values.map(&:last)
end

#push_text(text) ⇒ Object

Appends the text on every active event


56
57
58
# File 'lib/saxxy/event_registry.rb', line 56

def push_text(text)
  send_on_each_event(:append_text, text)
end

#register_event_from_action(action, name = nil, attributes = {}) ⇒ Object

Registers an event into the registry by initializing it and setting its element_name and attributes accordingly.


33
34
35
36
37
38
39
# File 'lib/saxxy/event_registry.rb', line 33

def register_event_from_action(action, name = nil, attributes = {})
  new_event_for(action).tap do |e|
    e.set_element_name(name)
    e.merge_attributes(attributes)
    self[action] << e
  end
end

#remove_actions!(*actions) ⇒ Object

Deletes the provided actions from the @actions without firing any callbacks.


89
90
91
92
# File 'lib/saxxy/event_registry.rb', line 89

def remove_actions!(*actions)
  actions.each { |a| @actions.delete(a) }
  @actions
end