Sha256: 58b68f3bb2f0f7a804d27ddde15ee4eeace49666c23dd77f4aec5f28fb73c3ee

Contents?: true

Size: 1.17 KB

Versions: 62

Compression:

Stored size: 1.17 KB

Contents

module Workarea
  class Metadata
    attr_reader :content, :model

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

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

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

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

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

    def update
      return unless content.automate_metadata?

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

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

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

    private

    def max_words
      Workarea.config.meta_description_max_words
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/queries/workarea/metadata.rb
workarea-core-3.4.36 app/queries/workarea/metadata.rb
workarea-core-3.5.14 app/queries/workarea/metadata.rb
workarea-core-3.4.35 app/queries/workarea/metadata.rb
workarea-core-3.5.13 app/queries/workarea/metadata.rb
workarea-core-3.4.34 app/queries/workarea/metadata.rb
workarea-core-3.5.12 app/queries/workarea/metadata.rb
workarea-core-3.4.33 app/queries/workarea/metadata.rb
workarea-core-3.5.11 app/queries/workarea/metadata.rb
workarea-core-3.5.10 app/queries/workarea/metadata.rb
workarea-core-3.4.32 app/queries/workarea/metadata.rb
workarea-core-3.5.9 app/queries/workarea/metadata.rb
workarea-core-3.4.31 app/queries/workarea/metadata.rb
workarea-core-3.5.8 app/queries/workarea/metadata.rb
workarea-core-3.4.30 app/queries/workarea/metadata.rb
workarea-core-3.5.7 app/queries/workarea/metadata.rb
workarea-core-3.4.29 app/queries/workarea/metadata.rb
workarea-core-3.5.6 app/queries/workarea/metadata.rb
workarea-core-3.4.28 app/queries/workarea/metadata.rb
workarea-core-3.5.5 app/queries/workarea/metadata.rb