-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathshrine.rb
40 lines (33 loc) · 923 Bytes
/
shrine.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "administrate/field/base"
require "rails"
module Administrate
module Field
class Shrine < Administrate::Field::Base
class Engine < ::Rails::Engine
end
# we should first try the regular data.url because if the versions are generated
# in the background by a worker they won't be available immediately after
# submitting the form
# however, once data[:version].url is available data.url won't work,
# so we're covered in both cases
def url
(regular_url || version_url).to_s
end
def regular_url
data.try(:url)
end
def version_url
data.try(:[], version).try(:url)
end
def url_only?
options.fetch(:url_only, false)
end
def version
options.fetch(:version, nil)
end
def cached_value
resource.send("cached_#{attribute}_data")
end
end
end
end