Class: Pageflow::UsedFile

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/models/pageflow/used_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, usage = nil) ⇒ UsedFile

Returns a new instance of UsedFile.



3
4
5
6
7
# File 'app/models/pageflow/used_file.rb', line 3

def initialize(file, usage = nil)
  super(file)
  @file = file
  @usage = usage || file.usages.first
end

Instance Method Details

#cache_keyObject



26
27
28
# File 'app/models/pageflow/used_file.rb', line 26

def cache_key
  [@file.cache_key, @usage.cache_key].join('-')
end

#cache_key_with_versionObject



30
31
32
# File 'app/models/pageflow/used_file.rb', line 30

def cache_key_with_version
  [@file.cache_key_with_version, @usage.cache_key_with_version].join('-')
end

#classObject



41
42
43
# File 'app/models/pageflow/used_file.rb', line 41

def class
  @file.class
end

#configurationObject



9
10
11
# File 'app/models/pageflow/used_file.rb', line 9

def configuration
  @usage.configuration
end

#is_a?(klass) ⇒ Boolean

Not delegated by default. Required to allow using instances in Active Record conditions.

Returns:

  • (Boolean)


37
38
39
# File 'app/models/pageflow/used_file.rb', line 37

def is_a?(klass)
  @file.is_a?(klass)
end

#perma_idObject



22
23
24
# File 'app/models/pageflow/used_file.rb', line 22

def perma_id
  @usage.perma_id
end

#update!(attributes) ⇒ Object



13
14
15
16
# File 'app/models/pageflow/used_file.rb', line 13

def update!(attributes)
  super(attributes.except(:configuration))
  @usage.update!(attributes.slice(:configuration))
end

#usage_idObject



18
19
20
# File 'app/models/pageflow/used_file.rb', line 18

def usage_id
  @usage.id
end