Permalink
Browse files

Cleanup and Ruby 1.9 compatibility

  • Loading branch information...
onsitedev committed Nov 9, 2010
1 parent e9e6639 commit dfa08ff9e8bf30ebf539754227b63ee5ebb53ffa
Showing with 32 additions and 28 deletions.
  1. +1 −0 Rakefile
  2. +1 −1 VERSION
  3. +7 −4 attachment_on_the_fly.gemspec
  4. +23 −23 lib/attachment_on_the_fly.rb
View
@@ -7,6 +7,7 @@ begin
gemspec.email = "jefferey.sutherland@gmail.com"
gemspec.homepage = "http://github.com/drpentode/Attachment-on-the-Fly"
gemspec.authors = ["Jeff Sutherland"]
+ gemspec.add_dependency "paperclip"
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
View
@@ -1 +1 @@
-0.0.6
+0.0.7
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{attachment_on_the_fly}
- s.version = "0.0.6"
+ s.version = "0.0.7"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeff Sutherland"]
- s.date = %q{2009-11-25}
+ s.date = %q{2010-11-08}
s.description = %q{A Paperclip mix-in to allow auto-generation of resized images}
s.email = %q{jefferey.sutherland@gmail.com}
s.extra_rdoc_files = [
@@ -28,17 +28,20 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/drpentode/Attachment-on-the-Fly}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.5}
+ s.rubygems_version = %q{1.3.7}
s.summary = %q{A Paperclip mix-in to allow auto-generation of resized images}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<paperclip>, [">= 0"])
else
+ s.add_dependency(%q<paperclip>, [">= 0"])
end
else
+ s.add_dependency(%q<paperclip>, [">= 0"])
end
end
@@ -3,25 +3,25 @@
# the paperclip attachment attribute should be called "attachment" on the model
#
Paperclip::Attachment.class_eval do
- require 'ftools'
+ require 'ftools' if RUBY_VERSION < "1.9"
require 'fileutils'
require 'tempfile'
-
+
# we respond to s_ and cls_
def respond_to?(method,*args, &block)
if method.to_s.match(/^s_[0-9]+_[0-9]+/) || method.to_s.match(/^s_[0-9]+_[a-z]+/) || method.to_s.match(/^s[0-9]+/) ||
- method.to_s.match(/^cls_[0-9]+_[0-9]+/) || method.to_s.match(/^cls_[0-9]+_[a-z]+/) || method.to_s.match(/^cls[0-9]+/)
+ method.to_s.match(/^cls_[0-9]+_[0-9]+/) || method.to_s.match(/^cls_[0-9]+_[a-z]+/) || method.to_s.match(/^cls[0-9]+/)
return true
end
super
end
-
+
def method_missing(symbol , *args, &block )
# We are looking for methods with S_[number]_[number]_(height | width | proportion)
# Height and width
# Check to see if file exist if so return string
# if not generate image and return string to file Fiel is in format S_Height_x_Width_FILE_NAME
- image_name = nil
+ image_name = nil
if symbol.to_s.match(/^s_[0-9]+_[0-9]+/) || symbol.to_s.match(/^cls_[0-9]+_[0-9]+/)
values = symbol.to_s.split("_")
height = values[1]
@@ -37,43 +37,43 @@ def method_missing(symbol , *args, &block )
size = values[1]
who = "width"
image_name = generate_image(who, size.to_i)
- else
- # if our method string does not match, we kick things back up to super ... this keeps ActiveRecord chugging along happily
- super
- end
-
- return image_name
- end
-
- def generate_image(kind, height = 0, width = 0)
+ else
+ # if our method string does not match, we kick things back up to super ... this keeps ActiveRecord chugging along happily
+ super
+ end
+
+ return image_name
+ end
+
+ def generate_image(kind, height = 0, width = 0)
prefix = ""
-
+
if kind == "height"
- prefix = "S_" + height.to_s + "_HEIGHT_"
+ prefix = "S_" + height.to_s + "_HEIGHT_"
elsif kind == "width"
width = height
prefix = "S_" + height.to_s + "_WIDTH_"
elsif kind == "both"
prefix = "S_" + height.to_s + "_" + height.to_s + "_"
end
-
+
path = instance.attachment.path
url = instance.attachment.url
-
+
path_arr = path.split("/")
file_name = path_arr.pop
path = path_arr.join("/")
-
+
url_arr = url.split("/")
url_file_name = url_arr.pop
url_path = url_arr.join("/")
-
+
original = path + "/" + instance.attachment.original_filename
newfilename = path + "/" + prefix + file_name
new_path = url_path + "/" + prefix + file_name
-
+
return new_path if File.exist?(newfilename)
-
+
if !File.exist?(original)
return new_path
end
@@ -91,4 +91,4 @@ def generate_image(kind, height = 0, width = 0)
return new_path
end
-end
+end

0 comments on commit dfa08ff

Please sign in to comment.