Sha256: 4ececf65b23da03d462914f4cd11e1dd59cf9adaffa7ca35401eb25550af2788
Contents?: true
Size: 1.1 KB
Versions: 10
Compression:
Stored size: 1.1 KB
Contents
module JSONAPIonify::Api module Resource::Builders class RelationshipsBuilder < FieldsBuilder delegate :relationships, to: :resource, prefix: true delegate :includes, to: :context private def build_default resource_relationships.each_with_object(Objects::Relationships.new) do |relationship, attrs| if !relationship.hidden_for_action?(action_name) || includes.keys.include?(relationship.name.to_s) attrs[relationship.name] = build_relationship(relationship) end end end def build_sparce (resource_fields + includes.keys).each_with_object(Objects::Relationships.new) do |field, attrs| field = field.to_sym relationship = resource_relationships.find { |rel| rel.name == field } attrs[field] = build_relationship(relationship) if relationship end end def build_relationship(relationship) RelationshipBuilder.build( resource, relationship: relationship, context: context, instance: instance ) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems