Removed unused code, add missing activesupport dependency

This commit is contained in:
Max Melentiev
2018-11-14 16:26:04 +03:00
parent d7827e6f69
commit 9dd2736365
3 changed files with 23 additions and 35 deletions

View File

@@ -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:

View File

@@ -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,11 +31,6 @@ module Paperclip
end
module Rails3
def self.included(base)
base.extend(Defining)
base.send(:include, Running)
end
module Defining
def define_paperclip_callbacks(*callbacks)
terminator =
@@ -43,14 +41,15 @@ module Paperclip
end
define_callbacks *[callbacks, {terminator: terminator}].flatten
callbacks.each do |callback|
eval <<-end_callbacks
class_eval <<~RUBY, __FILE__, __LINE__ + 1
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
RUBY
end
end
end
@@ -60,9 +59,7 @@ module Paperclip
run_callbacks(callback, &block)
end
end
end
end
end

View File

@@ -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