cloudinary 1.0.50 → 1.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ require "ostruct"
3
3
  require "pathname"
4
4
  require "yaml"
5
5
  require "uri"
6
+ require "erb"
6
7
  require "cloudinary/version"
7
8
  require "cloudinary/exceptions"
8
9
  require "cloudinary/missing"
@@ -37,7 +38,7 @@ module Cloudinary
37
38
 
38
39
  def self.config(new_config=nil)
39
40
  first_time = @@config.nil?
40
- @@config ||= OpenStruct.new((YAML.load_file(config_dir.join("cloudinary.yml"))[config_env] rescue {}))
41
+ @@config ||= OpenStruct.new((YAML.load(ERB.new(IO.read(config_dir.join("cloudinary.yml"))).result)[config_env] rescue {}))
41
42
 
42
43
  # Heroku support
43
44
  if first_time && ENV["CLOUDINARY_CLOUD_NAME"]
@@ -81,7 +81,7 @@ module Cloudinary::CarrierWave
81
81
  @public_id ||= Cloudinary::Utils.random_public_id
82
82
  end
83
83
 
84
- def rename(to_public_id = nil)
84
+ def rename(to_public_id = nil, overwrite=false)
85
85
  to_public_id ||= self.public_id
86
86
  if self.public_id && to_public_id != self.public_id
87
87
  raise CloudinaryException, "The public_id method was overridden and returns #{self.public_id} - can't rename to #{to_public_id}"
@@ -98,8 +98,8 @@ module Cloudinary::CarrierWave
98
98
  from_public_id = [from_public_id, self.format].join(".")
99
99
  to_public_id = [to_public_id, self.format].join(".")
100
100
  end
101
- Cloudinary::Uploader.rename(from_public_id, to_public_id, :type=>self.storage_type, :resource_type=>resource_type)
102
- storage.store_cloudinary_version(@stored_version)
101
+ Cloudinary::Uploader.rename(from_public_id, to_public_id, :type=>self.storage_type, :resource_type=>resource_type, :overwrite=>overwrite)
102
+ storage.store_cloudinary_identifier(@stored_version, [@public_id, self.format].join("."))
103
103
  end
104
104
 
105
105
  def recreate_versions!
@@ -7,9 +7,9 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
7
7
  when Cloudinary::CarrierWave::PreloadedCloudinaryFile
8
8
  if uploader.public_id && uploader.auto_rename_preloaded?
9
9
  @stored_version = file.version
10
- uploader.rename
10
+ uploader.rename(nil, true)
11
11
  else
12
- store_cloudinary_version(file.version)
12
+ store_cloudinary_identifier(file.version, file.filename)
13
13
  end
14
14
  return
15
15
  when Cloudinary::CarrierWave::CloudinaryFile
@@ -39,7 +39,10 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
39
39
  raise Cloudinary::CarrierWave::UploadError.new(uploader.metadata["error"]["message"], uploader.metadata["error"]["http_code"])
40
40
  end
41
41
 
42
- store_cloudinary_version(uploader.metadata["version"]) if uploader.metadata["version"]
42
+ if uploader.metadata["version"]
43
+ filename = [uploader.metadata["public_id"], uploader.metadata["format"]].reject(&:blank?).join(".")
44
+ store_cloudinary_identifier(uploader.metadata["version"], filename)
45
+ end
43
46
  # Will throw an exception on error
44
47
  else
45
48
  raise CloudinaryException, "nested versions are not allowed." if (uploader.class.version_names.length > 1)
@@ -48,8 +51,19 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
48
51
  nil
49
52
  end
50
53
 
54
+ # @deprecated For backward compatibility
51
55
  def store_cloudinary_version(version)
52
- name = "v#{version}/#{identifier.split("/", 2).last}"
56
+ if identifier.match(%r(^(v[0-9]+)/(.*)))
57
+ filename = $2
58
+ else
59
+ filename = identifier
60
+ end
61
+
62
+ store_cloudinary_identifier(version, filename)
63
+ end
64
+
65
+ def store_cloudinary_identifier(version, filename)
66
+ name = "v#{version}/#{filename}"
53
67
  model_class = uploader.model.class
54
68
  column = uploader.model.send(:_mounter, uploader.mounted_as).send(:serialization_column)
55
69
  if defined?(ActiveRecord::Base) && uploader.model.is_a?(ActiveRecord::Base)
@@ -65,6 +65,7 @@ class Cloudinary::Uploader
65
65
  {
66
66
  :timestamp=>Time.now.to_i,
67
67
  :type=>options[:type],
68
+ :overwrite=>options[:overwrite],
68
69
  :from_public_id=>from_public_id,
69
70
  :to_public_id=>to_public_id,
70
71
  }
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.0.50"
3
+ VERSION = "1.0.51"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.50
4
+ version: 1.0.51
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-03-24 00:00:00.000000000 Z
14
+ date: 2013-03-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client