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

- old
+ new

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