Sha256: c27c7ef72f97ad749a47e4730b686e415074e54b71db558c7e8907029009a744
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jsonapi-resources-0.11.0.beta2 | lib/jsonapi/path.rb |