Sha256: 6eb8aa3315b41d728108236c1dd71e52a313c21d73c6ff2d2c07fbb0f4128d8d

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 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, :iasgn
        @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

10 entries across 10 versions & 2 rubygems

Version Path
kevinrutherford-reek-1.1.3.11 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.12 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.13 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.14 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.15 lib/reek/block_context.rb
kevinrutherford-reek-1.1.3.16 lib/reek/block_context.rb
kevinrutherford-reek-1.2.0 lib/reek/block_context.rb
reek-1.2.2 lib/reek/block_context.rb
reek-1.2.1 lib/reek/block_context.rb
reek-1.2.0 lib/reek/block_context.rb