Commit e59d0b53 by Prem Sichanugrist

Move Schema includes into Paperclip::Glue

parent ec1aa8be
require 'paperclip/callbacks' require 'paperclip/callbacks'
require 'paperclip/validators'
require 'paperclip/schema'
module Paperclip module Paperclip
module Glue module Glue
...@@ -8,6 +10,12 @@ module Paperclip ...@@ -8,6 +10,12 @@ module Paperclip
base.send :include, Validators base.send :include, Validators
base.class_attribute :attachment_definitions base.class_attribute :attachment_definitions
if defined?(ActiveRecord)
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
end
locale_path = Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}") locale_path = Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}")
I18n.load_path += locale_path unless I18n.load_path.include?(locale_path) I18n.load_path += locale_path unless I18n.load_path.include?(locale_path)
end end
......
...@@ -3,27 +3,24 @@ require 'paperclip/schema' ...@@ -3,27 +3,24 @@ require 'paperclip/schema'
module Paperclip module Paperclip
require 'rails' require 'rails'
class Railtie < Rails::Railtie class Railtie < Rails::Railtie
initializer 'paperclip.insert_into_active_record' do initializer 'paperclip.insert_into_active_record' do
ActiveSupport.on_load :active_record do ActiveSupport.on_load :active_record do
Paperclip::Railtie.insert Paperclip::Railtie.insert
end end
end end
rake_tasks do
load "tasks/paperclip.rake" rake_tasks { load "tasks/paperclip.rake" }
end
end end
class Railtie class Railtie
def self.insert def self.insert
Paperclip.options[:logger] = Rails.logger if defined?(Rails) Paperclip.options[:logger] = Rails.logger
if defined?(ActiveRecord) if defined?(ActiveRecord)
Paperclip.options[:logger] = ActiveRecord::Base.logger Paperclip.options[:logger] = ActiveRecord::Base.logger
ActiveRecord::Base.send(:include, Paperclip::Glue) ActiveRecord::Base.send(:include, Paperclip::Glue)
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment