Class: Spec::Rails::Example::AssignsHashProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/example/assigns_hash_proxy.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(example_group, &block) ⇒ AssignsHashProxy

Returns a new instance of AssignsHashProxy.



5
6
7
8
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 5

def initialize(example_group, &block)
  @target = block.call
  @example_group = example_group
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 10

def [](key)
  return false if false == assigns[key] || false == assigns[key.to_s]
  assigns[key] || assigns[key.to_s] || @target.instance_variable_get("@#{key}")
end

#[]=(key, val) ⇒ Object



15
16
17
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 15

def []=(key, val)
  @target.instance_variable_set("@#{key}", val)
end

#delete(key) ⇒ Object



19
20
21
22
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 19

def delete(key)
  assigns.delete(key.to_s)
  @target.instance_variable_set("@#{key}", nil)
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 24

def each(&block)
  assigns.each &block
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/spec/rails/example/assigns_hash_proxy.rb', line 28

def has_key?(key)
  assigns.key?(key.to_s)
end