Sha256: 6311ca06c5904e982544f4c47db2a81c7f07b7cb4144c5dd37e30a554d330a8e
Contents?: true
Size: 1.33 KB
Versions: 16
Compression:
Stored size: 1.33 KB
Contents
module JSONAPI class Path attr_reader :segments, :resource_klass def initialize(resource_klass:, path_string:, ensure_default_field: true, parse_fields: true) @resource_klass = resource_klass current_resource_klass = resource_klass @segments = path_string.to_s.split('.').collect do |segment_string| segment = PathSegment.parse(source_resource_klass: current_resource_klass, segment_string: segment_string, parse_fields: parse_fields) current_resource_klass = segment.resource_klass segment end if ensure_default_field && parse_fields && @segments.last.is_a?(PathSegment::Relationship) last = @segments.last @segments << PathSegment::Field.new(resource_klass: last.resource_klass, field_name: last.resource_klass._primary_key) end end def relationship_segments @segments.select {|p| p.is_a?(PathSegment::Relationship)} end def relationship_path_string relationship_segments.collect(&:to_s).join('.') end def last_relationship if @segments.last.is_a?(PathSegment::Relationship) @segments.last else @segments[-2] end end end end
Version data entries
16 entries across 16 versions & 1 rubygems