Skip to content

Commit

Permalink
Fixed Compatability with Rails 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Jun 16, 2011
1 parent d4a9c94 commit 7f2d376
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Version 5.0.3 2011-06-16
- Fixed Compatability with Rails 2

Version 5.0.2 2011-06-16
- Fixed Compatability with Rails
- Fixed Compatability with Rails 3
- Added support, with deprecation warning, for pre-5.0.0 API.

Version 5.0.0 2011-06-14
Expand Down
6 changes: 3 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Easily create CSVs of any data that can be derived from your models.

CsvPirate is the easy way to create a CSV of essentially anything in Ruby, in full pirate regalia.
It works better if you are wearing a tricorne! Now compatible with Ruby 1.8.7 & 1.9.2, and Rails 3!
It works better if you are wearing a tricorne! Now compatible with Ruby 1.8.7 & 1.9.2, and Rails 2 & 3!

Everything in the source that depended on Rails extensions of Ruby classes has been refactored to work in pure Ruby!

Expand Down Expand Up @@ -65,7 +65,7 @@ Gem Using Git building from source:
git clone git://github.com/pboling/csv_pirate.git
cd csv_pirate
gem build csv_pirate.gemspec
sudo gem install csv_pirate-5.0.2.gem # (Or whatever version gets built)
sudo gem install csv_pirate-5.0.3.gem # (Or whatever version gets built)

== Install as a Plugin

Expand Down Expand Up @@ -460,4 +460,4 @@ Thanks go to:

----------------------------------------------------------------------------------
Author: Peter Boling, peter.boling at gmail dot com
Copyright (c) 2009-2010 Peter H. Boling of 9thBit LLC, released under the MIT license. See LICENSE for details.
Copyright (c) 2009-2011 Peter H. Boling of 9thBit LLC, released under the MIT license. See LICENSE for details.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ It works better if you are wearing a tricorne!}
"spec/spec_helpers/star.rb",
"Rakefile",
"Gemfile",
"init.rb",
"LICENSE.txt",
"CHANGELOG.txt",
"VERSION.yml"]
Expand Down
9 changes: 7 additions & 2 deletions csv_pirate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = %q{csv_pirate}
s.version = "5.0.2"
s.version = "5.0.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Peter Boling"]
Expand All @@ -25,6 +25,7 @@ It works better if you are wearing a tricorne!}
"Rakefile",
"VERSION.yml",
"csv_pirate.gemspec",
"init.rb",
"install.rb",
"lib/csv_pirate.rb",
"lib/csv_pirate/pirate_ship.rb",
Expand All @@ -41,26 +42,30 @@ It works better if you are wearing a tricorne!}
]
s.homepage = %q{http://github.com/pboling/csv_pirate}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.7.2}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Easily create CSVs of any data that can be derived from instance methods on your classes.}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<fastercsv>, [">= 1.4.0"])
s.add_development_dependency(%q<rspec>, ["~> 2.6"])
s.add_development_dependency(%q<shoulda>, [">= 0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
s.add_development_dependency(%q<rcov>, [">= 0"])
else
s.add_dependency(%q<fastercsv>, [">= 1.4.0"])
s.add_dependency(%q<rspec>, ["~> 2.6"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
s.add_dependency(%q<rcov>, [">= 0"])
end
else
s.add_dependency(%q<fastercsv>, [">= 1.4.0"])
s.add_dependency(%q<rspec>, ["~> 2.6"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
Expand Down
7 changes: 5 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#We might have rails (pre version 3)...
if defined?(Rails) && !defined?(Rake) && !defined?(Rails::Railtie) && defined?(config) && config.respond_to?(:gems)
puts "init.rb is loading"
if defined?(ActiveRecord) && !defined?(Rake) && !defined?(Rails::Railtie) && defined?(config) && config.respond_to?(:gems)
puts "init.rb has Rails config!"

require 'csv_pirate'

Expand All @@ -15,7 +17,8 @@
end

#And we might not... (rake needs to come hear to load the gems properly)
else
elsif defined?(ActiveRecord) && !defined?(Rails::Railtie)
puts "init.rb probably in a rake task"

require 'csv_pirate'
ActiveRecord::Base.send(:extend, NinthBit::PirateShip::ActMethods) if defined?(ActiveRecord)
Expand Down
47 changes: 27 additions & 20 deletions lib/csv_pirate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,34 @@
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)
puts "has Rails config!"
config.to_prepare do
ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods)
end
else
puts "probably in a rake task"
ActiveRecord::Base.send(:extend, CsvPirate::PirateShip::ActMethods)
end
end
end
Expand Down

0 comments on commit 7f2d376

Please sign in to comment.