Sha256: 1aca86a9183c3a206b80848d9cb64159409b3eb07bd64616b76b1619b4227e44

Contents?: true

Size: 759 Bytes

Versions: 7

Compression:

Stored size: 759 Bytes

Contents

require "expressir/express/model_visitor"
require "expressir/model"

module Expressir
  module Express
    class ResolveReferencesModelVisitor < ModelVisitor
      def visit(node)
        if node.is_a? Model::Expressions::SimpleReference
          visit_expressions_simple_reference(node)
        end

        super
      end

      def visit_expressions_simple_reference(node)
        return if node.parent.is_a? Model::Expressions::AttributeReference

        if node.parent.is_a? Model::InterfaceItem
          base_item = node.find("#{node.parent.parent.schema.id}.#{node.parent.ref.id}")
        else
          base_item = node.find(node.id)
        end
        return unless base_item

        node.base_path = base_item.path
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
expressir-1.0.0 lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-x86_64-linux lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-x86_64-darwin lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-x86-mingw32 lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-x86-linux lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-x64-mingw32 lib/expressir/express/resolve_references_model_visitor.rb
expressir-1.0.0-arm64-darwin lib/expressir/express/resolve_references_model_visitor.rb