Sha256: 423910544d64ccf9e98ade9650e1716fdb261fb14215ceb11be7ec619a23d639

Contents?: true

Size: 1.44 KB

Versions: 14

Compression:

Stored size: 1.44 KB

Contents

module Inch
  module CodeObject
    # CodeObject::Proxy object represent code objects in the analaysed
    # codebase.
    #
    module Proxy
      class << self
        # Returns a Proxy object for the given +code_object+
        #
        # @param code_object [YARD::Object::Base]
        # @return [CodeObject::Proxy::Base]
        def for(code_object)
          @cache ||= {}
          if proxy_object = @cache[cache_key(code_object)]
            proxy_object
          else
            attributes = Converter.to_hash(code_object)
            proxy_object = class_for(code_object).new(attributes)
            @cache[cache_key(code_object)] = proxy_object
          end
        end

        private

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

        # Returns a cache key for the given +code_object+
        #
        # @return [String]
        def cache_key(code_object)
          code_object.fullname
        end
      end
    end
  end
end

require_relative 'proxy/base'
require_relative 'proxy/namespace_object'
require_relative 'proxy/class_object'
require_relative 'proxy/constant_object'
require_relative 'proxy/method_object'
require_relative 'proxy/method_parameter_object'
require_relative 'proxy/module_object'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
inch-0.3.3 lib/inch/code_object/proxy.rb
inch-0.3.3.rc1 lib/inch/code_object/proxy.rb
inch-0.3.2 lib/inch/code_object/proxy.rb
inch-0.3.2.rc2 lib/inch/code_object/proxy.rb
inch-0.3.2.rc1 lib/inch/code_object/proxy.rb
inch-0.3.1 lib/inch/code_object/proxy.rb
inch-0.3.1.rc6 lib/inch/code_object/proxy.rb
inch-0.3.1.rc5 lib/inch/code_object/proxy.rb
inch-0.3.1.rc4 lib/inch/code_object/proxy.rb
inch-0.3.1.rc3 lib/inch/code_object/proxy.rb
inch-0.3.1.rc2 lib/inch/code_object/proxy.rb
inch-0.3.1.rc1 lib/inch/code_object/proxy.rb
inch-0.3.0 lib/inch/code_object/proxy.rb
inch-0.3.0.rc3 lib/inch/code_object/proxy.rb