class EntityEvents::EventFinder

Public Class Methods

find(hint) click to toggle source
# File lib/entity_events/event_finder.rb, line 6
def find(hint)
  #get the entity's custom EntityEvent
  begin
    entity = from_hint(hint)
    entity = entity.constantize
  rescue NameError
    #if not found then use the default EntityEvent
    EntityEvents::EntityEvent
  end
end

Private Class Methods

from_hint(hint) click to toggle source
# File lib/entity_events/event_finder.rb, line 20
def from_hint(hint)
  if hint.respond_to?(:event_class)
    hint.event_class
  elsif hint.class.respond_to?(:event_class)
    hint.class.event_class
  else
    entity = if hint.respond_to?(:model_name)
      hint.model_name
    elsif hint.class.respond_to?(:model_name)
      hint.class.model_name
    elsif hint.is_a?(Class)
      hint
    elsif hint.is_a?(Symbol)
      hint.to_s.classify
    elsif hint.is_a?(String)
      hint.classify
    else
      hint.class
    end
    "#{entity}Event"
  end
end