Sha256: 2f7c66fe0ed058ef70f035ecb585b29d88cd65ec4d89efba8506e86cde150b35

Contents?: true

Size: 766 Bytes

Versions: 20

Compression:

Stored size: 766 Bytes

Contents

module Pupa
  module Concerns
    # Adds the Popolo `links` property to a model.
    module Linkable
      extend ActiveSupport::Concern

      included do
        attr_reader :links
        dump :links
      end

      def initialize(*args)
        @links = []
        super
      end

      # Sets the links.
      #
      # @param [Array] links a list of links
      def links=(links)
        @links = symbolize_keys(links)
      end

      # Adds a URL.
      #
      # @param [String] url a URL
      # @param [String] note a note, e.g. "Wikipedia page"
      def add_link(url, note: nil)
        data = {url: url}
        if note
          data[:note] = note
        end
        if url.present?
          @links << data
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
pupa-0.2.4 lib/pupa/models/concerns/linkable.rb
pupa-0.2.3 lib/pupa/models/concerns/linkable.rb
pupa-0.2.2 lib/pupa/models/concerns/linkable.rb
pupa-0.2.1 lib/pupa/models/concerns/linkable.rb
pupa-0.2.0 lib/pupa/models/concerns/linkable.rb
pupa-0.1.11 lib/pupa/models/concerns/linkable.rb
pupa-0.1.10 lib/pupa/models/concerns/linkable.rb
pupa-0.1.9 lib/pupa/models/concerns/linkable.rb
pupa-0.1.8 lib/pupa/models/concerns/linkable.rb
pupa-0.1.7 lib/pupa/models/concerns/linkable.rb
pupa-0.1.6 lib/pupa/models/concerns/linkable.rb
pupa-0.1.5 lib/pupa/models/concerns/linkable.rb
pupa-0.1.4 lib/pupa/models/concerns/linkable.rb
pupa-0.1.3 lib/pupa/models/concerns/linkable.rb
pupa-0.1.2 lib/pupa/models/concerns/linkable.rb
pupa-0.1.1 lib/pupa/models/concerns/linkable.rb
pupa-0.1.0 lib/pupa/models/concerns/linkable.rb
pupa-0.0.13 lib/pupa/models/concerns/linkable.rb
pupa-0.0.12 lib/pupa/models/concerns/linkable.rb
pupa-0.0.11 lib/pupa/models/concerns/linkable.rb