Sha256: 0cedfc986f3790392f413f80809a89983c7ede1a9ec8e6c4a8043f8f736a3918
Contents?: true
Size: 1.03 KB
Versions: 19
Compression:
Stored size: 1.03 KB
Contents
module Fiona7 module AttributeWriters module Helpers class LinkSerializer def initialize(obj, klass) self.obj = obj self.klass = klass end def call(link) link = link.symbolize_keys new_link = {} if link[:url] # handle www.example.com new_link[:url] = "external:#{link[:url]}" unless link[:url] =~ /\A[a-zA-Z][a-zA-Z0-9+.-]:/ elsif obj_id = link[:obj_id] # FIXME: use a repository here to speed up the lookup new_link[:url] = self.klass.find(obj_id).path end new_link[:url] ||= link[:url] new_link[:title] = link[:title] if link[:title] new_link[:target] = link[:target] if link[:target] new_link[:url] = "#{new_link[:url]}?#{link[:query]}" if link[:query] new_link[:url] = "#{new_link[:url]}##{link[:fragment]}" if link[:fragment] new_link end protected attr_accessor :obj, :klass end end end end
Version data entries
19 entries across 19 versions & 1 rubygems