lib/shogun/presenter.rb in shogun-3.0.0 vs lib/shogun/presenter.rb in shogun-3.1.0

- old
+ new

@@ -1,9 +1,10 @@ module Shogun module Presenter - def initialize(resource:, meta: {}, links: {}, linked: {}) + def initialize(resource:, includes: [], meta: {}, links: {}, linked: {}) @source = resource + @includes = includes @meta = meta @links = links @linked = linked end @@ -19,11 +20,11 @@ @linked end def links @links.tap do |hash| - associations.each do |name| + includes.each do |name| case association(name).macro when :has_many hash.store(name, source.public_send(name).pluck(:id)) when :belongs_to hash.store(name, source.public_send(association(name).foreign_key)) @@ -36,22 +37,22 @@ private def host ENV["API_HOST"] end - private def associations - self.class.const_get("ASSOCIATIONS") - end - private def namespace self.class.const_get("NAMESPACE") end private def association(name) source.class.reflections[name.to_sym] end private def source @source + end + + private def includes + @includes end end end