lib/csv_pirate.rb in csv_pirate-5.0.2 vs lib/csv_pirate.rb in csv_pirate-5.0.4
- old
+ new
@@ -14,30 +14,37 @@
else
require 'faster_csv'
end
module CsvPirate
- if defined?(Rails::Railtie)
- # namespace our plugin and inherit from Rails::Railtie
- # to get our plugin into the initialization process
- class Railtie < Rails::Railtie
+ # If you are using this on a vanilla Ruby class (no rails or active record) then extend your class like this:
+ # MyClass.send(:extend, NinthBit::PirateShip::ActMethods) if defined?(MyClass)
+ # Alternatively you can do this inside your class definition:
+ # class MyClass
+ # extend NinthBit::PirateShip::ActMethods
+ # end
+ # If you are using ActiveRecord then it is done for you :)
- # configure our plugin on boot. other extension points such
- # as configuration, rake tasks, etc, are also available
- #initializer "csv_pirate.initialize" do |app|
- #end
-
- # Add a to_prepare block which is executed once in production
- # and before each request in development
- config.to_prepare do
- # If you are using this on a vanilla Ruby class (no rails or active record) then extend your class like this:
- # MyClass.send(:extend, CsvPirate::PirateShip::ActMethods) if defined?(MyClass)
- # Alternatively you can do this inside your class definition:
- # class MyClass
- # extend CsvPirate::PirateShip::ActMethods
- # end
- # If you are using ActiveRecord then it is done for you :)
- ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods) if defined?(ActiveRecord)
+ if defined?(Rails) && defined?(ActiveRecord)
+ if defined?(Rails::Railtie)
+ # namespace our plugin and inherit from Rails::Railtie
+ # to get our plugin into the initialization process
+ class Railtie < Rails::Railtie
+ # Add a to_prepare block which is executed once in production
+ # and before each request in development
+ config.to_prepare do
+ ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods)
+ end
+ end
+ else
+ if !defined?(Rake) && defined?(config) && config.respond_to?(:gems)
+ #Not sure if this is ever executed...
+ config.to_prepare do
+ ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods)
+ end
+ else
+ #This one cleans up that mess...
+ ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods)
end
end
end
end