Sha256: 8a83ce313ff3ac2211ff6d9812325f8e6f12f99b7e0c1426c054f8905be8056e

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

require 'set'
require 'reek/code_context'

module Reek

  module ParameterSet
    def names
      return @names if @names
      return (@names = []) if empty?
      arg = slice(1)
      case slice(0)
      when :masgn
        @names = arg[1..-1].map {|lasgn| Name.new(lasgn[1]) }
      when :lasgn
        @names = [Name.new(arg)]
      end
    end

    def include?(name)
      names.include?(name)
    end
  end

  class BlockContext < CodeContext

    def initialize(outer, exp)
      super
      @name = Name.new('block')
      @parameters = exp[0] if exp
      @parameters ||= []
      @parameters.extend(ParameterSet)
      @local_variables = Set.new
    end

    def inside_a_block?
      true
    end

    def has_parameter(name)
      @parameters.include?(name) or @outer.has_parameter(name)
    end

    def nested_block?
      @outer.inside_a_block?
    end
    
    def record_local_variable(sym)
      @local_variables << Name.new(sym)
    end

    def outer_name
      "#{@outer.outer_name}#{@name}/"
    end
    
    def variable_names
      @parameters.names + @local_variables.to_a
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
kevinrutherford-reek-1.1.1 lib/reek/block_context.rb
kevinrutherford-reek-1.1.2.1 lib/reek/block_context.rb
kevinrutherford-reek-1.1.2 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.1 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.10 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.2 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.3 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.4 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.5 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.6 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.7 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.8 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.9 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3 lib/reek/block_context.rb
teksymmetry-reek-1.1.3.1 lib/reek/block_context.rb
teksymmetry-reek-1.1.3.2 lib/reek/block_context.rb
reek-1.1.3 lib/reek/block_context.rb