Class: Workarea::Content::Asset

Inherits:
Object
  • Object
show all
Extended by:
Dragonfly::Model
Includes:
Mongoid::Document::Taggable, ApplicationDocument, Workarea::Commentable
Defined in:
app/models/workarea/content/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Workarea::Commentable

#add_subscription, #remove_subscription

Methods included from Mongoid::Document::Taggable

included

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



129
130
131
132
133
134
135
# File 'app/models/workarea/content/asset.rb', line 129

def method_missing(sym, *args, &block)
  if file.respond_to?(sym)
    file.send(sym, *args, &block)
  else
    super
  end
end

Class Method Details

.favicon_placeholderObject



79
80
81
82
83
84
85
86
87
88
# File 'app/models/workarea/content/asset.rb', line 79

def self.favicon_placeholder
  find_by(file_name: Workarea.config.favicon_placeholder_image_name)

rescue Mongoid::Errors::DocumentNotFound
  create!(
    file: FindPipelineAsset.new(
      Workarea.config.favicon_placeholder_image_name
    ).path
  )
end

.favicons(type = nil) ⇒ Object



90
91
92
# File 'app/models/workarea/content/asset.rb', line 90

def self.favicons(type = nil)
  tagged_with(['favicon', type].compact.join('-'))
end

.image_placeholderObject



57
58
59
60
61
62
63
64
65
66
# File 'app/models/workarea/content/asset.rb', line 57

def self.image_placeholder
  find_by(file_name: Workarea.config.image_placeholder_image_name)

rescue Mongoid::Errors::DocumentNotFound
  create!(
    file: FindPipelineAsset.new(
      Workarea.config.image_placeholder_image_name
    ).path
  )
end

.open_graph_placeholderObject



68
69
70
71
72
73
74
75
76
77
# File 'app/models/workarea/content/asset.rb', line 68

def self.open_graph_placeholder
  find_by(file_name: Workarea.config.open_graph_placeholder_image_name)

rescue Mongoid::Errors::DocumentNotFound
  create!(
    file: FindPipelineAsset.new(
      Workarea.config.open_graph_placeholder_image_name
    ).path
  )
end

.placeholderObject

TODO v3.5 remove



49
50
51
52
53
54
55
# File 'app/models/workarea/content/asset.rb', line 49

def self.placeholder
  warn <<~eos
    [DEPRECATION] `Asset.placeholder` is deprecated and will be removed in
    version 3.5.0. Please use `Asset.image_placeholder` instead.
  eos
  self.image_placeholder
end

Instance Method Details

#favicon?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/workarea/content/asset.rb', line 94

def favicon?
  tags.any? { |t| t.starts_with?('favicon') }
end

#favicon_placeholder?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/workarea/content/asset.rb', line 115

def favicon_placeholder?
  file_name == Workarea.config.favicon_placeholder_image_name
end

#image_placeholder?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/workarea/content/asset.rb', line 107

def image_placeholder?
  file_name == Workarea.config.image_placeholder_image_name
end

#open_graph_placeholder?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/workarea/content/asset.rb', line 111

def open_graph_placeholder?
  file_name == Workarea.config.open_graph_placeholder_image_name
end

#placeholder?Boolean

TODO v3.5 remove

Returns:

  • (Boolean)


99
100
101
102
103
104
105
# File 'app/models/workarea/content/asset.rb', line 99

def placeholder?
  warn <<~eos
    [DEPRECATION] `Asset#placeholder?` is deprecated and will be removed in
    version 3.5.0. Please use `Asset#image_placeholder?` instead.
  eos
  image_placeholder?
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'app/models/workarea/content/asset.rb', line 125

def respond_to_missing?(method_name, include_private = false)
  super || file.respond_to?(method_name)
end