Class: DispatchPolicy::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch_policy/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Context

Returns a new instance of Context.



17
18
19
# File 'lib/dispatch_policy/context.rb', line 17

def initialize(hash)
  @data = deep_stringify(hash).freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/dispatch_policy/context.rb', line 15

def data
  @data
end

Class Method Details

.wrap(value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/dispatch_policy/context.rb', line 5

def self.wrap(value)
  case value
  when Context then value
  when Hash    then new(value)
  when nil     then new({})
  else
    raise InvalidPolicy, "context must be a Hash, got #{value.class}"
  end
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/dispatch_policy/context.rb', line 21

def [](key)
  @data[key.to_s]
end

#fetch(key, *args, &block) ⇒ Object



33
34
35
# File 'lib/dispatch_policy/context.rb', line 33

def fetch(key, *args, &block)
  @data.fetch(key.to_s, *args, &block)
end

#to_hObject



25
26
27
# File 'lib/dispatch_policy/context.rb', line 25

def to_h
  @data
end

#to_jsonbObject



29
30
31
# File 'lib/dispatch_policy/context.rb', line 29

def to_jsonb
  @data
end