Browse files

Remove the explicit requires in models; explicitly require lib/ in pr…

…od mode in the scraper task
  • Loading branch information...
1 parent 1f80083 commit 8bed1c449587ba34b2727235048a48934e87a003 @mcmire committed Apr 28, 2011
View
2 app/models/category.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Category
include MongoMapper::Document
include Hardwarepedia::ModelMixins::RequiresFields
View
2 app/models/image.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Image
include MongoMapper::EmbeddedDocument
include MongoMapper::Plugins::Timestamps
View
2 app/models/manufacturer.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Manufacturer
include MongoMapper::Document
include MongoMapper::Plugins::IdentityMap
View
2 app/models/price.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Price
include MongoMapper::EmbeddedDocument
include MongoMapper::Plugins::Timestamps
View
2 app/models/product.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Product
include MongoMapper::Document
include MongoMapper::Plugins::IdentityMap
View
2 app/models/rating.rb
@@ -1,5 +1,3 @@
-require 'hardwarepedia/model_mixins/requires_fields'
-
class Rating
include MongoMapper::EmbeddedDocument
include MongoMapper::Plugins::Timestamps
View
1 app/models/url.rb
@@ -1,5 +1,4 @@
require 'digest/md5'
-require 'hardwarepedia/model_mixins/requires_fields'
class Url
def self.md5(content)
View
2 config/application.rb
@@ -21,7 +21,7 @@ class Application < Rails::Application
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{config.root}/extras )
- config.autoload_paths << Rails.root.join("lib")
+ config.autoload_paths << "#{config.root}/lib"
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
View
20 lib/tasks/scrape.rake
@@ -1,14 +1,18 @@
namespace :scrape do
- task :init do
- Rake::Task['environment'].invoke
+ task :init => :environment do
$stdout.sync = true # disable buffering
- # Load all the models since we're getting an error accessing the Product
- # model when screenscraping product pages:
- # "LoadError: Expected app/models/product.rb to define Product"
- Dir[ Rails.root.join("app/models/**/*.rb") ].each {|fn| require fn }
-
- require 'hardwarepedia/scraper'
+ if Rails.env.production?
+ # Load all the eager load paths since Rails does not do this when running
+ # Rake tasks, even in production mode
+ Dir[ Rails.root.join("lib/hardwarepedia/**/*.rb") ].each {|fn| require_dependency fn }
+ Dir[ Rails.root.join("app/models/**/*.rb") ].each {|fn| require_dependency fn }
+ else
+ # Load all the models since we're getting an error accessing the Product
+ # model when screenscraping product pages:
+ # "LoadError: Expected app/models/product.rb to define Product"
+ Dir[ Rails.root.join("app/models/**/*.rb") ].each {|fn| require_dependency fn }
+ end
end
task :products => :init do

0 comments on commit 8bed1c4

Please sign in to comment.