Sha256: 1e304c1c3ec035b37a7685c36cde15319f54874d9117fb38c491e85a0b5126de

Contents?: true

Size: 788 Bytes

Versions: 20

Compression:

Stored size: 788 Bytes

Contents

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

      included do
        attr_reader :sources
        dump :sources
      end

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

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

      # Adds a source to the object.
      #
      # @param [String] url a URL
      # @param [String] note a note
      def add_source(url, note: nil)
        data = {url: url}
        if note
          data[:note] = note
        end
        if url.present?
          @sources << 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/sourceable.rb
pupa-0.2.3 lib/pupa/models/concerns/sourceable.rb
pupa-0.2.2 lib/pupa/models/concerns/sourceable.rb
pupa-0.2.1 lib/pupa/models/concerns/sourceable.rb
pupa-0.2.0 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.11 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.10 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.9 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.8 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.7 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.6 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.5 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.4 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.3 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.2 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.1 lib/pupa/models/concerns/sourceable.rb
pupa-0.1.0 lib/pupa/models/concerns/sourceable.rb
pupa-0.0.13 lib/pupa/models/concerns/sourceable.rb
pupa-0.0.12 lib/pupa/models/concerns/sourceable.rb
pupa-0.0.11 lib/pupa/models/concerns/sourceable.rb