Sha256: ed66a73d396ede1ee2d6625284add81559ec856f1ba02f0c3e280714a143c376

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

module Yoda
  module Store
    module Objects
      class ClassObject < NamespaceObject
        class Connected < NamespaceObject::Connected
          delegate_to_object :superclass_path

          # @return [NamespaceObject::Connected]
          def superclass
            ancestor_tree.superclass.with_connection(**connection_options)
          end
        end

        # @return [Path, nil]
        attr_reader :superclass_path

        # @return [Array<Symbol>]
        def self.attr_names
          super + %i(superclass_path)
        end

        # @param path [String]
        # @param superclass_path [String, nil]
        def initialize(superclass_path: nil, **kwargs)
          super(**kwargs)

          @superclass_path = Model::Path.new(superclass_path) if superclass_path
        end

        def kind
          :class
        end

        def to_h
          super.merge(superclass_path: superclass_path&.to_s)
        end

        private

        # @param another [self]
        # @return [Hash]
        def merge_attributes(another)
          super.merge(
            superclass_path: select_superclass(another.superclass_path)&.to_s,
          )
        end

        # @param another [ScopedPath]
        # @return [Path]
        def select_superclass(another)
          if %w(Object Exception).include?(another&.to_s)
            superclass_path || another
          else
            another || superclass_path
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/store/objects/class_object.rb
yoda-language-server-0.10.0 lib/yoda/store/objects/class_object.rb
yoda-language-server-0.9.0 lib/yoda/store/objects/class_object.rb
yoda-language-server-0.8.0 lib/yoda/store/objects/class_object.rb