Class: Tenon::ProxyAttachment

Inherits:
Object
  • Object
show all
Defined in:
lib/tenon/proxy_attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, klass, asset_name) ⇒ ProxyAttachment

Returns a new instance of ProxyAttachment.



5
6
7
8
9
# File 'lib/tenon/proxy_attachment.rb', line 5

def initialize(attachment, klass, asset_name)
  @attachment = attachment.try(:attachment) || attachment
  @asset = attachment if attachment.is_a?(Tenon::Asset)
  @style_prefix = "#{klass.to_s.underscore.gsub('/', '_')}_#{asset_name}"
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



3
4
5
# File 'lib/tenon/proxy_attachment.rb', line 3

def asset
  @asset
end

#attachmentObject (readonly)

Returns the value of attribute attachment.



3
4
5
# File 'lib/tenon/proxy_attachment.rb', line 3

def attachment
  @attachment
end

#style_prefixObject (readonly)

Returns the value of attribute style_prefix.



3
4
5
# File 'lib/tenon/proxy_attachment.rb', line 3

def style_prefix
  @style_prefix
end

Instance Method Details

#display_nameObject



15
16
17
# File 'lib/tenon/proxy_attachment.rb', line 15

def display_name
  Tenon::AssetDecorator.new(@attachment.instance).display_name
end

#original_filenameObject



11
12
13
# File 'lib/tenon/proxy_attachment.rb', line 11

def original_filename
  @attachment.original_filename
end

#url(style = :original, *args) ⇒ Object

Prefix with an underscore to use base Asset styles



20
21
22
23
24
25
26
# File 'lib/tenon/proxy_attachment.rb', line 20

def url(style = :original, *args)
  if style.to_sym == :original
    original_url(*args)
  else
    named_url(style, *args)
  end
end