Module: SimpleActiveStorage::Url

Extended by:
ActiveSupport::Concern
Defined in:
lib/simple_active_storage/url.rb

Defined Under Namespace

Classes: UnknowObjectError

Instance Method Summary collapse

Instance Method Details

#path(key = nil) ⇒ Object



26
27
28
# File 'lib/simple_active_storage/url.rb', line 26

def path(key = nil)
  url(key,only_path: true)
end

#url(key = nil, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_active_storage/url.rb', line 10

def url(key = nil,options = {})
  options.reverse_merge! only_path: false
  options.reverse_merge! SimpleActiveStorage.default_url_options
  helpers = SimpleActiveStorage.url_helpers
  case self.class.name
    when "ActiveStorage::Blob"
      helpers.rails_blob_url(self,options)
    when "ActiveStorage::Attachment","ActiveStorage::Attached::One"
      helpers.rails_blob_url(self.blob,options)
    when "ActiveStorage::Variant","ActiveStorage::Preview"
      helpers.rails_representation_url(self,options)
    else
      raise UnknowObjectError.new("unknow object #{self}")
  end
end