Sha256: 1c78bcdee839e95d1ee330340cbdac21587fb30610bb00d32d9ba583cdc817e6

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

require 'simplabs/excellent/parsing/cyclomatic_complexity_measure'
require 'simplabs/excellent/parsing/abc_measure'

module Simplabs

  module Excellent

    module Parsing

      class SingletonMethodContext < MethodContext #:nodoc:

        include CyclomaticComplexityMeasure
        include AbcMeasure

        attr_reader :parameters
        attr_reader :calls

        def initialize(exp, parent)
          super
          @name = exp[2].to_s
          @full_name = get_full_name
          @calls = Hash.new(0)
        end

        def full_name
          return @full_name if @full_name
          parent = @parent.is_a?(BlockContext) ? @parent.parent : @parent
          return @name if !parent
          "#{parent.full_name}.#{@name}"
        end

        def record_call_to(exp)
          @calls[exp] += 1
        end

        private

          def get_full_name
            if @exp[1].is_a?(Sexp)
              if @exp[1].node_type == :call
                return "#{@exp[1][2]}.#{@name}"
              elsif @exp[1].node_type == :const
                return "#{@exp[1][1]}.#{@name}"
              end
            end
            nil
          end

      end

    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
excellent-2.1.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-2.1.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-2.0.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-2.0.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-1.7.2 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-1.7.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-1.7.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-1.6.0 lib/simplabs/excellent/parsing/singleton_method_context.rb