mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
Removed unused code, add missing activesupport dependency
This commit is contained in:
@@ -42,12 +42,21 @@ require 'paperclip/matchers'
|
||||
require 'paperclip/callback_compatability'
|
||||
require 'paperclip/railtie' if defined?(Rails)
|
||||
|
||||
require 'active_support/concern'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
|
||||
# The base module that gets included in ActiveRecord::Base. See the
|
||||
# documentation for Paperclip::ClassMethods for more useful information.
|
||||
module Paperclip
|
||||
|
||||
VERSION = "2.2.9.2"
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class_attribute :attachment_definitions
|
||||
Paperclip::CallbackCompatability.install_to(self)
|
||||
end
|
||||
|
||||
class << self
|
||||
# Provides configurability to Paperclip. There are a number of options available, such as:
|
||||
# * whiny: Will raise an error if Paperclip cannot process thumbnails of
|
||||
@@ -109,17 +118,6 @@ module Paperclip
|
||||
File.exist?("/dev/null") ? "/dev/null" : "NUL"
|
||||
end
|
||||
|
||||
def included base #:nodoc:
|
||||
base.extend ClassMethods
|
||||
base.class_attribute :attachment_definitions
|
||||
|
||||
if base.respond_to?(:set_callback)
|
||||
base.send :include, Paperclip::CallbackCompatability::Rails3
|
||||
else
|
||||
base.send :include, Paperclip::CallbackCompatability::Rails21
|
||||
end
|
||||
end
|
||||
|
||||
def processor name #:nodoc:
|
||||
name = name.to_s.camelize
|
||||
processor = Paperclip.const_get(name)
|
||||
@@ -217,11 +215,7 @@ module Paperclip
|
||||
def has_attached_file name, options = {}
|
||||
include InstanceMethods
|
||||
|
||||
if attachment_definitions.nil?
|
||||
self.attachment_definitions = {}
|
||||
else
|
||||
self.attachment_definitions = self.attachment_definitions.dup
|
||||
end
|
||||
self.attachment_definitions = self.attachment_definitions&.dup || {}
|
||||
attachment_definitions[name] = {:validations => []}.merge(options)
|
||||
|
||||
after_save :save_attached_files
|
||||
@@ -305,10 +299,6 @@ module Paperclip
|
||||
:if => options[:if],
|
||||
:unless => options[:unless]}]
|
||||
end
|
||||
|
||||
def attachment_definitions
|
||||
self.attachment_definitions
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods #:nodoc:
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
module Paperclip
|
||||
module CallbackCompatability
|
||||
module Rails21
|
||||
def self.included(base)
|
||||
base.extend(Defining)
|
||||
base.send(:include, Running)
|
||||
end
|
||||
module_function
|
||||
|
||||
def install_to(base)
|
||||
mod = base.respond_to?(:set_callback) ? Rails3 : Rails21
|
||||
base.extend(mod::Defining)
|
||||
base.send(:include, mod::Running)
|
||||
end
|
||||
|
||||
module Rails21
|
||||
module Defining
|
||||
def define_paperclip_callbacks(*args)
|
||||
args.each do |callback|
|
||||
@@ -28,29 +31,24 @@ module Paperclip
|
||||
end
|
||||
|
||||
module Rails3
|
||||
def self.included(base)
|
||||
base.extend(Defining)
|
||||
base.send(:include, Running)
|
||||
end
|
||||
|
||||
module Defining
|
||||
TERMINATOR =
|
||||
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('4.1')
|
||||
->(target, result) { result == false }
|
||||
else
|
||||
'result == false'
|
||||
end
|
||||
|
||||
def define_paperclip_callbacks(*callbacks)
|
||||
terminator =
|
||||
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('4.1')
|
||||
->(target, result) { result == false }
|
||||
else
|
||||
'result == false'
|
||||
define_callbacks *[callbacks, {terminator: TERMINATOR}].flatten
|
||||
callbacks.map(&:to_sym).each do |callback|
|
||||
define_singleton_method "before_#{callback}" do |*args, &blk|
|
||||
set_callback(callback, :before, *args, &blk)
|
||||
end
|
||||
|
||||
define_singleton_method "after_#{callback}" do |*args, &blk|
|
||||
set_callback(callback, :after, *args, &blk)
|
||||
end
|
||||
define_callbacks *[callbacks, {terminator: terminator}].flatten
|
||||
callbacks.each do |callback|
|
||||
eval <<-end_callbacks
|
||||
def before_#{callback}(*args, &blk)
|
||||
set_callback(:#{callback}, :before, *args, &blk)
|
||||
end
|
||||
def after_#{callback}(*args, &blk)
|
||||
set_callback(:#{callback}, :after, *args, &blk)
|
||||
end
|
||||
end_callbacks
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -60,9 +58,7 @@ module Paperclip
|
||||
run_callbacks(callback, &block)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,5 +17,6 @@ Gem::Specification.new do |s|
|
||||
s.rubygems_version = %q{1.3.1}
|
||||
s.summary = %q{File attachments as attributes for ActiveRecord}
|
||||
|
||||
s.add_dependency 'activesupport'
|
||||
s.add_dependency 'fastimage'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user