Skip to content

Instantly share code, notes, and snippets.

@brandonhilkert
Created April 3, 2015 17:39
Show Gist options
  • Select an option

  • Save brandonhilkert/a83f2bf7b231f03079f8 to your computer and use it in GitHub Desktop.

Select an option

Save brandonhilkert/a83f2bf7b231f03079f8 to your computer and use it in GitHub Desktop.
class Handler
def self.receive(model, action, message)
begin
"#{model.classify}::#{action.classify}".constantize.new(message).perform
rescue NameError
Rails.logger.info("No map for #{model.classify}::#{action.classify}")
return
end
end
end
@gdpelican
Copy link

I use Temping for testing stuff like this, although it might not match this use case exactly.

  module Model; end
  Model::Action = Temping.create :action do
    def initialize(message)
      @message = message
    end
    def perform
      "Message: #{@message}"
    end
  end
  expect(Handler.receive "Model", "Action", "foo").to eq "Message: foo"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment