Class: Landable::Asset

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Librarian, TableName
Defined in:
app/models/landable/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Librarian

#deactivate, #nuke!, #reactivate

Class Method Details

.url_generatorObject

This bit of indirection allows us to generate predictable URLs in the test environment.



17
18
19
# File 'app/models/landable/asset.rb', line 17

def self.url_generator
  @url_generator ||= proc { |asset| asset.data.try(:url) }
end

Instance Method Details

#associated_pagesObject



43
44
45
46
47
48
49
# File 'app/models/landable/asset.rb', line 43

def associated_pages
  paths = []
  Page.where('body like ?', "%#{name}%").each do |page|
    paths.push(page.path)
  end
  paths
end

#duplicate_ofObject



38
39
40
41
# File 'app/models/landable/asset.rb', line 38

def duplicate_of
  return unless data.present?
  self.class.where(md5sum: calculate_md5sum).first
end

#public_urlObject



34
35
36
# File 'app/models/landable/asset.rb', line 34

def public_url
  self.class.url_generator.call(self)
end