Class: Pageflow::UsedFile

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

Overview

rubocop:todo Style/Documentation

Constant Summary collapse

USAGE_ATTRIBUTES =
[:configuration, :display_name, :folder_perma_id].freeze

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



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

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

#cache_key_with_versionObject



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

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

#classObject



51
52
53
# File 'app/models/pageflow/used_file.rb', line 51

def class
  @file.class
end

#configurationObject



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

def configuration
  @usage.configuration
end

#display_nameObject



28
29
30
# File 'app/models/pageflow/used_file.rb', line 28

def display_name
  @usage.display_name
end

#folder_perma_idObject



32
33
34
# File 'app/models/pageflow/used_file.rb', line 32

def folder_perma_id
  @usage.folder_perma_id
end

#is_a?(klass) ⇒ Boolean

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

Returns:

  • (Boolean)


47
48
49
# File 'app/models/pageflow/used_file.rb', line 47

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

#perma_idObject



24
25
26
# File 'app/models/pageflow/used_file.rb', line 24

def perma_id
  @usage.perma_id
end

#update!(attributes) ⇒ Object



15
16
17
18
# File 'app/models/pageflow/used_file.rb', line 15

def update!(attributes)
  super(attributes.except(*USAGE_ATTRIBUTES))
  @usage.update!(attributes.slice(*USAGE_ATTRIBUTES))
end

#usage_idObject



20
21
22
# File 'app/models/pageflow/used_file.rb', line 20

def usage_id
  @usage.id
end