Sha256: f4a8294eb004e57e1e72aeaa02f980a3b1091910fcd5ce62a4ae9e6d73ac898f

Contents?: true

Size: 608 Bytes

Versions: 1

Compression:

Stored size: 608 Bytes

Contents

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

      included do
        attr_accessor :links
        dump :links
      end

      def initialize(*args)
        @links = []
        super
      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
          @links << data
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupa-0.0.10 lib/pupa/models/concerns/linkable.rb