Skip to content

Commit

Permalink
Let Ruby raise an error if the models are not defined.
Browse files Browse the repository at this point in the history
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
cmer committed Jul 4, 2012
1 parent 2bc0ce6 commit 91f2b05
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions lib/socialization/config/config.rb
@@ -1,20 +1,10 @@
module Socialization module Socialization
class << self 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 def follow_model
if @follow_model if @follow_model
@follow_model @follow_model
elsif defined?(::Follow)
::Follow
else else
raise RuntimeError.new("No Follow model has been defined.") ::Follow
end end
end end


Expand All @@ -25,10 +15,8 @@ def follow_model=(klass)
def like_model def like_model
if @like_model if @like_model
@like_model @like_model
elsif defined?(::Like)
::Like
else else
raise RuntimeError.new("No Like model has been defined.") ::Like
end end
end end


Expand All @@ -39,10 +27,8 @@ def like_model=(klass)
def mention_model def mention_model
if @mention_model if @mention_model
@mention_model @mention_model
elsif defined?(::Mention)
::Mention
else else
raise RuntimeError.new("No Mention model has been defined.") ::Mention
end end
end end


Expand Down

0 comments on commit 91f2b05

Please sign in to comment.