Class: Flagship::Context

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/flagship/context.rb

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



5
6
7
# File 'lib/flagship/context.rb', line 5

def initialize
  @values = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, args = [], &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flagship/context.rb', line 13

def method_missing(name, args = [], &block)
  if @values.key?(name)
    value = @values[name]

    if value.respond_to?(:call)
      value.call
    else
      value
    end
  else
    super
  end
end

Instance Method Details

#__set(key, value) ⇒ Object



9
10
11
# File 'lib/flagship/context.rb', line 9

def __set(key, value)
  @values[key.to_sym] = value
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/flagship/context.rb', line 27

def respond_to_missing?(name, include_private = false)
  @values.key?(name) or super
end

#with_values(values, &block) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/flagship/context.rb', line 31

def with_values(values, &block)
  original_values = @values
  @values = @values.dup.merge(values)
  block.call
ensure
  @values = original_values
end