Class: Workarea::Metadata

Inherits:
Object
  • Object
show all
Defined in:
app/queries/workarea/metadata.rb

Direct Known Subclasses

CatalogCategory, ContentPage, HomePage

Defined Under Namespace

Classes: CatalogCategory, ContentPage, HomePage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Metadata

Returns a new instance of Metadata.



23
24
25
26
# File 'app/queries/workarea/metadata.rb', line 23

def initialize(content)
  @content = content
  @model = content.contentable
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'app/queries/workarea/metadata.rb', line 3

def content
  @content
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'app/queries/workarea/metadata.rb', line 3

def model
  @model
end

Class Method Details

.automation_klass(model) ⇒ Object



9
10
11
12
13
# File 'app/queries/workarea/metadata.rb', line 9

def self.automation_klass(model)
  "Workarea::Metadata::#{model_name(model.class).classify}".constantize
rescue NameError
  nil
end

.model_name(klass) ⇒ Object



5
6
7
# File 'app/queries/workarea/metadata.rb', line 5

def self.model_name(klass)
  ActiveModel::Naming.param_key(klass)
end

.update(content) ⇒ Object



15
16
17
18
19
20
21
# File 'app/queries/workarea/metadata.rb', line 15

def self.update(content)
  contentable = content.contentable
  return unless contentable.present?

   = automation_klass(contentable)
  .new(content).update if .present?
end

Instance Method Details

#descriptionObject

Raises:

  • (NotImplementedError)


43
44
45
46
47
48
# File 'app/queries/workarea/metadata.rb', line 43

def description
  raise(
    NotImplementedError,
    "#{self.class.name} must implement the #description method"
  )
end

#titleObject

Raises:

  • (NotImplementedError)


36
37
38
39
40
41
# File 'app/queries/workarea/metadata.rb', line 36

def title
  raise(
    NotImplementedError,
    "#{self.class.name} must implement the #title method"
  )
end

#updateObject



28
29
30
31
32
33
34
# File 'app/queries/workarea/metadata.rb', line 28

def update
  return unless content.automate_metadata?

  content.browser_title = title
  content.meta_description = description
  content.save!
end