uploadcare-rails 0.4.2 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -3
- data/app/assets/javascripts/{uploadcare-0.6.9.2.js → uploadcare-0.8.js} +1918 -713
- data/app/assets/javascripts/uploadcare.js +1 -1
- data/lib/uploadcare/rails/active_record.rb +12 -15
- data/lib/uploadcare/rails/file.rb +24 -0
- data/lib/uploadcare/rails/settings.rb +1 -1
- data/lib/uploadcare/rails/version.rb +1 -1
- metadata +8 -7
@@ -1 +1 @@
|
|
1
|
-
// = require ./uploadcare-0.
|
1
|
+
// = require ./uploadcare-0.8
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uploadcare/rails/file'
|
2
|
+
|
1
3
|
module Uploadcare
|
2
4
|
module Rails
|
3
5
|
module ActiveRecord
|
@@ -8,24 +10,15 @@ module Uploadcare
|
|
8
10
|
force_autostore: false
|
9
11
|
}.update options
|
10
12
|
|
11
|
-
get_uuid = lambda do |attributes|
|
12
|
-
re = /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i
|
13
|
-
m = re.match(attributes[attribute.to_s])
|
14
|
-
if m.nil?
|
15
|
-
nil
|
16
|
-
else
|
17
|
-
m[0]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
13
|
define_method "#{attribute}" do
|
22
|
-
|
23
|
-
return nil unless
|
14
|
+
cdn_url = attributes[attribute.to_s]
|
15
|
+
return nil unless cdn_url
|
24
16
|
|
25
17
|
if instance_variable_defined?("@#{attribute}_cached")
|
26
18
|
instance_variable_get("@#{attribute}_cached")
|
27
19
|
else
|
28
|
-
|
20
|
+
api = ::Rails.application.config.uploadcare.api
|
21
|
+
file_data = File.new(api, cdn_url)
|
29
22
|
instance_variable_set("@#{attribute}_cached", file_data)
|
30
23
|
file_data
|
31
24
|
end
|
@@ -35,13 +28,17 @@ module Uploadcare
|
|
35
28
|
after_save "store_#{attribute}"
|
36
29
|
|
37
30
|
define_method "store_#{attribute}" do
|
38
|
-
|
31
|
+
re = /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i
|
32
|
+
m = re.match(attributes[attribute.to_s])
|
33
|
+
return unless m && m[0]
|
34
|
+
|
35
|
+
uuid = m[0]
|
39
36
|
stored = ::Rails.cache.exist?(
|
40
37
|
"uploadcare.file.#{uuid}.store",
|
41
38
|
force: opts[:force_autostore]
|
42
39
|
)
|
43
40
|
unless stored
|
44
|
-
send(attribute).store
|
41
|
+
send(attribute).api.store
|
45
42
|
::Rails.cache.write("uploadcare.file.#{uuid}.store", true)
|
46
43
|
end
|
47
44
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Uploadcare
|
2
|
+
module Rails
|
3
|
+
class File
|
4
|
+
|
5
|
+
def initialize(api, cdn_url)
|
6
|
+
@api = api
|
7
|
+
@cdn_url = cdn_url
|
8
|
+
end
|
9
|
+
|
10
|
+
def cdn_url(*operations)
|
11
|
+
@api.cdn_url(@cdn_url, *operations)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :public_url, :cdn_url
|
15
|
+
|
16
|
+
def api
|
17
|
+
@file ||= @api.file(@cdn_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :info, :api
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.1.2
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.1.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: sqlite3
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,11 +98,12 @@ executables: []
|
|
98
98
|
extensions: []
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
|
-
- app/assets/javascripts/uploadcare-0.
|
101
|
+
- app/assets/javascripts/uploadcare-0.8.js
|
102
102
|
- app/assets/javascripts/uploadcare.js
|
103
103
|
- lib/uploadcare/rails/action_view.rb
|
104
104
|
- lib/uploadcare/rails/active_record.rb
|
105
105
|
- lib/uploadcare/rails/engine.rb
|
106
|
+
- lib/uploadcare/rails/file.rb
|
106
107
|
- lib/uploadcare/rails/settings.rb
|
107
108
|
- lib/uploadcare/rails/simple_form.rb
|
108
109
|
- lib/uploadcare/rails/version.rb
|
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: '0'
|
125
126
|
segments:
|
126
127
|
- 0
|
127
|
-
hash:
|
128
|
+
hash: 4094460784775535100
|
128
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
130
|
none: false
|
130
131
|
requirements:
|
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
134
|
version: '0'
|
134
135
|
segments:
|
135
136
|
- 0
|
136
|
-
hash:
|
137
|
+
hash: 4094460784775535100
|
137
138
|
requirements: []
|
138
139
|
rubyforge_project:
|
139
140
|
rubygems_version: 1.8.24
|