Skip to content

Commit

Permalink
Fix potential ArgumentError in development
Browse files Browse the repository at this point in the history
When operating in a development environment, changing
Griddler.configuration.processor_class can raise an

    ArgumentError: A copy of EmailProcessor has been removed from the module tree but is still active!

To prevent this, change our reference to the class to a string and
reload it when the class is reloaded (as it is in
Rails.env.development?) and constantize that string when needed.
  • Loading branch information
mpospelov authored and calebhearth committed Nov 20, 2014
1 parent 2ef2ffb commit c49cff4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/griddler/configuration.rb
Expand Up @@ -22,7 +22,7 @@ def processor_class
@processor_class ||=
begin
if Kernel.const_defined?(:EmailProcessor)
EmailProcessor
"EmailProcessor"
else
raise NameError.new(<<-ERROR.strip_heredoc, 'EmailProcessor')
To use Griddler, you must either define `EmailProcessor` or configure a
Expand All @@ -31,6 +31,12 @@ def processor_class
ERROR
end
end

@processor_class.constantize
end

def processor_class=(klass)
@processor_class = klass.to_s
end

def processor_method
Expand Down
7 changes: 4 additions & 3 deletions spec/griddler/configuration_spec.rb
Expand Up @@ -26,13 +26,14 @@
end

it 'stores a processor_class' do
dummy_processor = Class.new
class DummyProcessor
end

Griddler.configure do |config|
config.processor_class = dummy_processor
config.processor_class = DummyProcessor
end

expect(Griddler.configuration.processor_class).to eq dummy_processor
expect(Griddler.configuration.processor_class).to eq DummyProcessor
end

it 'stores a processor_method' do
Expand Down

0 comments on commit c49cff4

Please sign in to comment.