Sha256: e0fbba875a957e78893f0e80cd739c153a1656999840d11a35106680ddc7e563

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 KB

Contents

module Yoda
  module Store
    module Query
      class FindSignature < Base
        # @param namespace [Objects::NamespaceObject]
        # @param method_name [String, Regexp]
        # @param visibility [Array<Symbol>, nil]
        # @return [Array<Objects::MethodObject>]
        def select(namespace, method_name, visibility: nil)
          FindMethod.new(registry).select(namespace, method_name, visibility: visibility).map { |el| build(namespace, el) }.flatten
        end

        private

        # @param receiver [Store::Objects::NamespaceObject]
        # @param method_object [Store::Objects::MethodObject]
        # @return [Array<FunctionSignatures::Base>]
        def build(receiver, method_object)
          if constructor = try_to_build_constructor(receiver, method_object)
            [constructor]
          elsif method_object.overloads.empty?
            [Model::FunctionSignatures::Method.new(method_object)]
          else
            method_object.overloads.map { |overload| Model::FunctionSignatures::Overload.new(method_object, overload) }
          end
        end

        # @param receiver [Store::Objects::NamespaceObject]
        # @param method_object [Store::Objects::MethodObject]
        # @return [FunctionSignatures::Constructor, nil]
        def try_to_build_constructor(receiver, method_object)
          if method_object.path == 'Class#new' && receiver.is_a?(Store::Objects::MetaClassObject) && receiver.path != 'Class'
            base_class = registry.find(receiver.base_class_address) || return
            initialize_object = FindMethod.new(registry).find(base_class, 'initialize') || return
            Model::FunctionSignatures::Constructor.new(base_class, initialize_object)
          else
            nil
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yoda-language-server-0.7.2 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.7.1 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.7.0 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.6.2 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.6.1 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.6.0 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.5.0 lib/yoda/store/query/find_signature.rb
yoda-language-server-0.4.0 lib/yoda/store/query/find_signature.rb