Sha256: f1b32dba33506eebf3de7469bc9188c4e36a1ce4ebb1b60082d5da3f767422e4

Contents?: true

Size: 870 Bytes

Versions: 7

Compression:

Stored size: 870 Bytes

Contents

require "expressir/express_exp/model_visitor"
require "expressir/model"

module Expressir
  module ExpressExp
    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

        if base_item.is_a? Model::InterfacedItem
          base_item = base_item.base_item
        end

        node.base_path = base_item.path
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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