Class: ActionMessage::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/action_message/interceptor.rb

Class Method Summary collapse

Class Method Details

.register(conditions = {}) ⇒ Object

Raises:

  • (TypeError)


7
8
9
10
11
12
13
14
# File 'lib/action_message/interceptor.rb', line 7

def register(conditions={})
  raise TypeError, 'Invalid type. Please provide a hash object' unless conditions.methods.include?(:key)

  conditions.each do |attribute, condition|
    @@blacklist[attribute.to_sym] ||= []
    @@blacklist[attribute.to_sym].push(condition)
  end
end

.registered_for?(message) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/action_message/interceptor.rb', line 17

def registered_for?(message)
  @@blacklist.each do |attribute, conditions|
    value = message.send(attribute.to_sym)

    conditions.each do |condition|
      return true if value.send(match_method_for(condition), condition)
    end
  end

  return false
end