Permalink
Browse files

Let Ruby raise an error if the models are not defined.

This way, the lazy-loaded classes will be loaded automatically if they're not already loaded. Otherwise, defined? returned false when the class wasn't already loaded, even though the class file existed.
  • Loading branch information...
1 parent 2bc0ce6 commit 91f2b058e65cb46630c8eccf3fc819b9add06644 @cmer committed Jul 4, 2012
Showing with 3 additions and 17 deletions.
  1. +3 −17 lib/socialization/config/config.rb
@@ -1,20 +1,10 @@
module Socialization
class << self
- if defined?(Rails)
- %w{follow mention like}.each do |model|
- Dir[Rails.root + "app/models/**/#{model}.rb"].each do |path|
- require path
- end
- end
- end
-
def follow_model
if @follow_model
@follow_model
- elsif defined?(::Follow)
- ::Follow
else
- raise RuntimeError.new("No Follow model has been defined.")
+ ::Follow
end
end
@@ -25,10 +15,8 @@ def follow_model=(klass)
def like_model
if @like_model
@like_model
- elsif defined?(::Like)
- ::Like
else
- raise RuntimeError.new("No Like model has been defined.")
+ ::Like
end
end
@@ -39,10 +27,8 @@ def like_model=(klass)
def mention_model
if @mention_model
@mention_model
- elsif defined?(::Mention)
- ::Mention
else
- raise RuntimeError.new("No Mention model has been defined.")
+ ::Mention
end
end

0 comments on commit 91f2b05

Please sign in to comment.