Sha256: 965da000870b26fe21a6f4dac4f5052279d045b30b0cf996380f624535cd7718

Contents?: true

Size: 1.87 KB

Versions: 34

Compression:

Stored size: 1.87 KB

Contents

module Inch
  module CodeObject
    # CodeObject::Proxy object represent code objects in the analaysed
    # codebase.
    #
    class Proxy
      # Returns a Proxy object for the given +code_object+
      #
      # @param language [String,Symbol]
      # @param code_object [YARD::Object::Base]
      # @param object_lookup [Codebase::Objects]
      # @return [CodeObject::Proxy]
      def self.for(language, code_object, object_lookup)
        attributes = Converter.to_hash(code_object)
        class_for(language, code_object).new(attributes, object_lookup)
      end

      extend Forwardable

      # @return [#find]
      #  an object that responds to #find to look up objects by their
      #  full name
      attr_accessor :object_lookup

      # @param object_lookup [Codebase::Objects]
      def initialize(attributes = {}, object_lookup = nil)
        @attributes = attributes
        @object_lookup = object_lookup
      end

      # Returns the attribute for the given +key+
      #
      # @param key [Symbol]
      def [](key)
        @attributes[key]
      end

      # @return [Symbol] the programming language of the code object
      def language
        fail NotImplementedError
      end

      # Used to persist the code object
      def marshal_dump
        @attributes
      end

      # Used to load a persisted code object
      def marshal_load(attributes)
        @attributes = attributes
      end

      def inspect
        "#<#{self.class}: #{fullname}>"
      end

      # Returns a Proxy class for the given +code_object+
      #
      # @param language [String,Symbol]
      # @param code_object [YARD::CodeObject]
      # @return [Class]
      def self.class_for(language, code_object)
        class_name = code_object.class.to_s.split('::').last
        Config.namespace(language, :CodeObject).const_get(class_name)
      end
      private_class_method :class_for
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 lib/inch/code_object/proxy.rb
inch-0.8.0 lib/inch/code_object/proxy.rb
inch-0.8.0.rc2 lib/inch/code_object/proxy.rb
inch-0.8.0.rc1 lib/inch/code_object/proxy.rb
inch-0.7.1 lib/inch/code_object/proxy.rb
inch-0.7.0 lib/inch/code_object/proxy.rb
inch-0.6.4 lib/inch/code_object/proxy.rb
inch-0.6.3 lib/inch/code_object/proxy.rb
inch-0.6.2 lib/inch/code_object/proxy.rb
inch-0.6.1 lib/inch/code_object/proxy.rb
inch-0.6.0 lib/inch/code_object/proxy.rb
inch-0.6.0.rc6 lib/inch/code_object/proxy.rb
inch-0.6.0.rc5 lib/inch/code_object/proxy.rb
inch-0.6.0.rc4 lib/inch/code_object/proxy.rb
inch-0.6.0.rc3 lib/inch/code_object/proxy.rb
inch-0.6.0.rc2 lib/inch/code_object/proxy.rb
inch-0.6.0.rc1 lib/inch/code_object/proxy.rb
inch-0.5.10 lib/inch/code_object/proxy.rb
inch-0.5.9 lib/inch/code_object/proxy.rb
inch-0.5.8 lib/inch/code_object/proxy.rb