lib/conglomerate/serializer.rb in conglomerate-0.5.1 vs lib/conglomerate/serializer.rb in conglomerate-0.6.0

- old
+ new

@@ -90,10 +90,11 @@ attributes = self.class._attributes item = apply_data(item, :data => attributes, :object => object) links = self.class._attributes .select { |attr| attr[:block] } + links += self.class._item_links if links.empty? item.empty? ? nil : item else apply_links(item, :links => links, :object => object) @@ -126,11 +127,11 @@ end def apply_links(collection, links: self.class._links, object: nil) if object && !links.empty? links = links.map do |link| - if present?(object.send(link[:name])) + if !link.has_key?(:name) || present?(object.send(link[:name])) build_item_link( link[:rel], :proc => link[:block], :object => object ) else nil @@ -229,18 +230,24 @@ self._links = self._links << { :rel => rel, :block => block } end + def item_link(rel, &block) + self._item_links = self._item_links << { + :rel => rel, :block => block + } + end + def template(name, type: :value, prompt: nil) self._templates = self._templates << { :name => name, :type => type, :prompt => prompt, :template => true } end attr_writer :_href, :_item_href, :_queries, :_attributes, :_links, - :_templates + :_item_links, :_templates def _href @_href || nil end @@ -256,9 +263,13 @@ @_attributes || [] end def _links @_links || [] + end + + def _item_links + @_item_links || [] end def _templates @_templates || [] end