194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/riaction/riaction.rb', line 194
def riaction_event(event_name)
events = self.class.class_variable_defined?(:@@riaction_events) ? self.class.class_variable_get(:@@riaction_events) : {}
event = events.fetch(event_name.to_sym)
profile = riaction_event_profile(event[:profile])
unless profile.class.respond_to?(:riaction_profile?) && profile.class.riaction_profile?
raise TypeError.new("Object defined for #{self.class} on event #{event_name} as a profile must itself declare riaction(:profile ...)")
end
params = riaction_event_params(event[:params])
raise TypeError.new("Params defined for #{self.class} on event #{event_name} must be a hash") unless params.kind_of? Hash
{
:key => event_name.to_sym,
:profile => profile,
:params => params
}
rescue KeyError => e
raise NoEventDefined.new("no such event #{event_name} defined on #{self.class}")
end
|