lib/pupa/models/concerns/sourceable.rb in pupa-0.0.10 vs lib/pupa/models/concerns/sourceable.rb in pupa-0.0.11

- old
+ new

@@ -3,28 +3,35 @@ # Adds the Popolo `sources` property to a model. module Sourceable extend ActiveSupport::Concern included do - attr_accessor :sources + 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 + if url.present? @sources << data end end end end