Class: Brakeman::SexpProcessor::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_parser/bm_sexp_processor.rb

Overview

I really hate this here, but I hate subdirs in my lib dir more… I guess it is kinda like shaving… I'll split this out when it itches too much…

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.


155
156
157
158
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 155

def initialize
  @env = []
  @env.unshift({})
end

Instance Method Details

#[](name) ⇒ Object

TODO: depth_of


170
171
172
173
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 170

def [] name
  hash = @env.find { |closure| closure.has_key? name }
  hash[name] if hash
end

#[]=(name, val) ⇒ Object


175
176
177
178
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 175

def []= name, val
  hash = @env.find { |closure| closure.has_key? name } || @env.first
  hash[name] = val
end

#allObject


160
161
162
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 160

def all
  @env.reverse.inject { |env, scope| env.merge scope }
end

#depthObject


164
165
166
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 164

def depth
  @env.length
end

#scopeObject


180
181
182
183
184
185
186
187
188
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 180

def scope
  @env.unshift({})
  begin
    yield
  ensure
    @env.shift
    raise "You went too far unextending env" if @env.empty?
  end
end