Class: ConditionalMessages::ContextHolder

Inherits:
BasicObject
Defined in:
lib/conditional_messages/context_holder.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ContextHolder

Returns a new instance of ContextHolder.



7
8
9
10
11
12
# File 'lib/conditional_messages/context_holder.rb', line 7

def initialize(context)
  @context = {}
  context.each_pair do |key, value|
    @context[key.to_s] = value
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



14
15
16
17
18
# File 'lib/conditional_messages/context_holder.rb', line 14

def method_missing(method, *)
  @context.fetch(method.to_s) {
    ::Kernel.raise UnknownContextKey, "Couldn't find the key `#{method}` in the context you provided:\n\n#{@context.inspect}"
  }
end