Class: Missions::EventHandlers::MissionEventHandler

Inherits:
Omega::Server::EventHandler show all
Defined in:
lib/missions/event_handler.rb

Overview

Missions Event Handler, allows clients to match MissionEvents via custom filters

Constant Summary collapse

FILTERS =

Filters which user may limit processed missions by

['mission_id', 'user_id']

Instance Attribute Summary collapse

Attributes inherited from Omega::Server::EventHandler

#endpoint_id, #event_id, #event_type, #handlers, #persist

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Omega::Server::EventHandler

#exec, #handlers_json, #invoke, json_create, #to_json

Constructor Details

#initialize(args = {}) ⇒ MissionEventHandler


62
63
64
65
66
# File 'lib/missions/event_handler.rb', line 62

def initialize(args = {})
  attr_from_args args, :mission_id => nil,
                       :user_id    => nil
  super(args)
end

Instance Attribute Details

#mission_idObject

Mission id to match


57
58
59
# File 'lib/missions/event_handler.rb', line 57

def mission_id
  @mission_id
end

#user_idObject

Mission assigned to user to match


60
61
62
# File 'lib/missions/event_handler.rb', line 60

def user_id
  @user_id
end

Class Method Details

.valid_filters?(filters) ⇒ Boolean

Return bool inidicating if specified filters are valid


52
53
54
# File 'lib/missions/event_handler.rb', line 52

def self.valid_filters?(filters)
  filters.all? { |f| FILTERS.include?(f) }
end

Instance Method Details

#json_dataObject


75
76
77
78
# File 'lib/missions/event_handler.rb', line 75

def json_data
  super.merge({ :mission_id => mission_id,
                :user_id    => user_id })
end

#matches?(mission_event) ⇒ Boolean


68
69
70
71
72
73
# File 'lib/missions/event_handler.rb', line 68

def matches?(mission_event)
   mission_event.kind_of?(Missions::Events::MissionEvent) &&
  (mission_id.nil? || mission_event.mission.id == mission_id ) &&
  (user_id.nil?    || mission_event.mission.assigned_to_id == user_id ) &&
  super(mission_event)
end