Sha256: 09a7839042d0be29cdc26be9cbc29dd023ab7769a40f33469ca84ee2924eaaf0

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 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.blank?
          "#{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

12 entries across 12 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/parsing/singleton_method_context.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/parsing/singleton_method_context.rb
excellent-1.5.4 lib/simplabs/excellent/parsing/singleton_method_context.rb