Permalink
Browse files

dm-paperclip works with Extlib and ActiveSupport

  • Loading branch information...
1 parent d12fca1 commit 8896bd4f910c1244709e69947e481d3478864b04 @johnny committed Mar 5, 2012
Showing with 29 additions and 14 deletions.
  1. +1 −0 Rakefile
  2. +1 −1 dm-paperclip.gemspec
  3. +21 −7 lib/dm-paperclip.rb
  4. +1 −1 lib/dm-paperclip/interpolations.rb
  5. +5 −5 lib/dm-paperclip/validations.rb
View
@@ -63,6 +63,7 @@ spec = Gem::Specification.new do |s|
s.files = FileList["README.rdoc",
"LICENSE",
"Rakefile",
+ "dm-paperclip.gemspec",
"init.rb",
"{lib,tasks,test}/**/*"].to_a
s.require_path = "lib"
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.date = "2012-03-05"
s.email = "jvadev@gmail.com"
s.extra_rdoc_files = ["README.rdoc"]
- s.files = ["README.rdoc", "LICENSE", "Rakefile", "init.rb", "lib/dm-paperclip.rb", "lib/dm-paperclip", "lib/dm-paperclip/callback_compatability.rb", "lib/dm-paperclip/thumbnail.rb", "lib/dm-paperclip/storage", "lib/dm-paperclip/storage/s3", "lib/dm-paperclip/storage/s3/aws_s3_library.rb", "lib/dm-paperclip/storage/s3/aws_library.rb", "lib/dm-paperclip/storage/filesystem.rb", "lib/dm-paperclip/storage/s3.rb", "lib/dm-paperclip/processor.rb", "lib/dm-paperclip/geometry.rb", "lib/dm-paperclip/validations.rb", "lib/dm-paperclip/storage.rb", "lib/dm-paperclip/iostream.rb", "lib/dm-paperclip/attachment.rb", "lib/dm-paperclip/upfile.rb", "lib/dm-paperclip/interpolations.rb", "tasks/paperclip_tasks.rake", "test/fixtures", "test/fixtures/bad.png", "test/fixtures/5k.png", "test/fixtures/12k.png", "test/fixtures/text.txt", "test/fixtures/50x50.png", "test/fixtures/s3.yml", "test/thumbnail_test.rb", "test/paperclip_test.rb", "test/iostream_test.rb", "test/helper.rb", "test/integration_test.rb", "test/storage_test.rb", "test/geometry_test.rb", "test/attachment_test.rb"]
+ s.files = ["README.rdoc", "LICENSE", "Rakefile", "dm-paperclip.gemspec", "init.rb", "lib/dm-paperclip.rb", "lib/dm-paperclip", "lib/dm-paperclip/callback_compatability.rb", "lib/dm-paperclip/thumbnail.rb", "lib/dm-paperclip/storage", "lib/dm-paperclip/storage/s3", "lib/dm-paperclip/storage/s3/aws_s3_library.rb", "lib/dm-paperclip/storage/s3/aws_library.rb", "lib/dm-paperclip/storage/filesystem.rb", "lib/dm-paperclip/storage/s3.rb", "lib/dm-paperclip/processor.rb", "lib/dm-paperclip/geometry.rb", "lib/dm-paperclip/validations.rb", "lib/dm-paperclip/storage.rb", "lib/dm-paperclip/iostream.rb", "lib/dm-paperclip/attachment.rb", "lib/dm-paperclip/upfile.rb", "lib/dm-paperclip/interpolations.rb", "tasks/paperclip_tasks.rake", "test/fixtures", "test/fixtures/bad.png", "test/fixtures/5k.png", "test/fixtures/12k.png", "test/fixtures/text.txt", "test/fixtures/50x50.png", "test/fixtures/s3.yml", "test/thumbnail_test.rb", "test/paperclip_test.rb", "test/iostream_test.rb", "test/helper.rb", "test/integration_test.rb", "test/storage_test.rb", "test/geometry_test.rb", "test/attachment_test.rb"]
s.homepage = "https://github.com/johnny/dm-paperclip"
s.rdoc_options = ["--line-numbers", "--inline-source"]
s.require_paths = ["lib"]
View
@@ -38,11 +38,21 @@
require 'dm-paperclip/storage'
require 'dm-paperclip/interpolations'
require 'dm-paperclip/attachment'
-require 'active_support/core_ext/object/blank'
-require 'active_support/core_ext/hash/keys'
-require 'active_support/inflector'
-require 'active_support/core_ext/string/inflections'
-require 'active_support/core_ext/class/attribute.rb'
+unless Object.const_defined?(:ActiveSupport) || Object.const_defined?(:Extlib)
+ begin
+ require 'active_support/core_ext/object/blank'
+ require 'active_support/core_ext/hash/keys'
+ require 'active_support/inflector'
+ require 'active_support/core_ext/string/inflections'
+ require 'active_support/core_ext/class/attribute.rb'
+ rescue LoadError
+ begin
+ require 'extlib'
+ rescue LoadError
+ raise "dm-paperclip needs either active_support or extlib"
+ end
+ end
+end
# The base module that gets included in ActiveRecord::Base. See the
# documentation for Paperclip::ClassMethods for more useful information.
@@ -175,7 +185,7 @@ def included base #:nodoc:
end
def processor name #:nodoc:
- name = ActiveSupport::Inflector.classify(name.to_s)
+ name = name.to_s.classify
processor = Paperclip.const_get(name)
unless processor.ancestors.include?(Paperclip::Processor)
raise PaperclipError.new("[paperclip] Processor #{name} was not found")
@@ -213,7 +223,11 @@ class InfiniteInterpolationError < PaperclipError #:nodoc:
module Resource
def self.included(base)
- base.class_attribute :attachment_definitions
+ if Object.const_defined?(:ActiveSupport)
+ base.class_attribute :attachment_definitions
+ else
+ base.class_inheritable_accessor :attachment_definitions
+ end
base.extend Paperclip::ClassMethods
# Done at this time to ensure that the user
@@ -82,7 +82,7 @@ def merb_env attachment, style
# Returns the snake cased, pluralized version of the class name.
# e.g. "users" for the User class.
def class attachment, style
- ActiveSupport::Inflector.underscore(attachment.instance.class.to_s).pluralize
+ attachment.instance.class.to_s.underscore.pluralize
end
# Returns the basename of the file. e.g. "file" for "file.jpg"
@@ -43,9 +43,9 @@ def call(target)
return true if @options[:in].include? field_value.to_i
error_message ||= @options[:message] unless @options[:message].nil?
- error_message ||= sprintf("%s must be less than %s bytes",::ActiveSupport::Inflector.humanize(@field_name), @options[:less_than]) unless @options[:less_than].nil?
- error_message ||= sprintf("%s must be greater than %s bytes",::ActiveSupport::Inflector.humanize(@field_name), @options[:greater_than]) unless @options[:greater_than].nil?
- error_message ||= sprintf("%s must be between %s and %s bytes",::ActiveSupport::Inflector.humanize(@field_name), @options[:in].first, @options[:in].last)
+ error_message ||= sprintf("%s must be less than %s bytes",@field_name.to_s.humanize, @options[:less_than]) unless @options[:less_than].nil?
+ error_message ||= sprintf("%s must be greater than %s bytes",@field_name.to_s.humanize, @options[:greater_than]) unless @options[:greater_than].nil?
+ error_message ||= sprintf("%s must be between %s and %s bytes",@field_name.to_s.humanize, @options[:in].first, @options[:in].last)
add_error(target, error_message , @field_name)
return false
end
@@ -55,7 +55,7 @@ class RequiredFieldValidator < DataMapper::Validate::GenericValidator #:nodoc:
def call(target)
field_value = target.validation_property_value(@field_name)
if field_value.nil? || field_value.original_filename.blank?
- error_message = @options[:message] || sprintf("%s must be set",::ActiveSupport::Inflector.humanize(@field_name))
+ error_message = @options[:message] || sprintf("%s must be set",@field_name.to_s.humanize)
add_error(target, error_message , @field_name)
return false
end
@@ -73,7 +73,7 @@ def call(target)
content_type = target.validation_property_value(:"#{@field_name}_content_type")
unless valid_types.any?{|t| t === content_type }
error_message ||= @options[:message] unless @options[:message].nil?
- error_message ||= sprintf("%s's content type of '%s' is not a valid content type",ActiveSupport::Inflector.humanize(@field_name), content_type)
+ error_message ||= sprintf("%s's content type of '%s' is not a valid content type",@field_name.to_s.humanize, content_type)
add_error(target, error_message , @field_name)
return false
end

0 comments on commit 8896bd4

Please sign in to comment.