Class: ActiveModel::Pusher::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model/pusher/events.rb

Defined Under Namespace

Classes: InvalidEventError

Instance Method Summary collapse

Constructor Details

#initialize(*events) ⇒ Events

Returns a new instance of Events.



17
18
19
# File 'lib/active_model/pusher/events.rb', line 17

def initialize(*events)
  @events = Array(events).flatten
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/active_model/pusher/events.rb', line 32

def any?
  @events.any?
end

#validate(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_model/pusher/events.rb', line 21

def validate(event)
  # Allow strings and symbols only
  # Return true if there are no whitelisted events

  return false unless event.respond_to? :to_sym

  return true unless @events.any?

  @events.include?(event)
end

#validate!(event) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_model/pusher/events.rb', line 36

def validate!(event)
  if validate(event) == false
    raise InvalidEventError.new(event)
  else
    true
  end
end