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.27 app/queries/workarea/metadata.rb
workarea-core-3.5.26 app/queries/workarea/metadata.rb
workarea-core-3.4.45 app/queries/workarea/metadata.rb
workarea-core-3.5.25 app/queries/workarea/metadata.rb
workarea-core-3.5.23 app/queries/workarea/metadata.rb
workarea-core-3.4.44 app/queries/workarea/metadata.rb
workarea-core-3.5.22 app/queries/workarea/metadata.rb
workarea-core-3.4.43 app/queries/workarea/metadata.rb
workarea-core-3.5.21 app/queries/workarea/metadata.rb
workarea-core-3.4.42 app/queries/workarea/metadata.rb
workarea-core-3.5.20 app/queries/workarea/metadata.rb
workarea-core-3.4.41 app/queries/workarea/metadata.rb
workarea-core-3.5.19 app/queries/workarea/metadata.rb
workarea-core-3.4.40 app/queries/workarea/metadata.rb
workarea-core-3.5.18 app/queries/workarea/metadata.rb
workarea-core-3.4.39 app/queries/workarea/metadata.rb
workarea-core-3.5.17 app/queries/workarea/metadata.rb
workarea-core-3.4.38 app/queries/workarea/metadata.rb
workarea-core-3.5.16 app/queries/workarea/metadata.rb
workarea-core-3.4.37 app/queries/workarea/metadata.rb