Class: Grape::Util::InheritableValues

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/util/inheritable_values.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inherited_values = {}) ⇒ InheritableValues



7
8
9
10
# File 'lib/grape/util/inheritable_values.rb', line 7

def initialize(inherited_values = {})
  self.inherited_values = inherited_values
  self.new_values = {}
end

Instance Attribute Details

#inherited_valuesObject

Returns the value of attribute inherited_values



4
5
6
# File 'lib/grape/util/inheritable_values.rb', line 4

def inherited_values
  @inherited_values
end

#new_valuesObject

Returns the value of attribute new_values



5
6
7
# File 'lib/grape/util/inheritable_values.rb', line 5

def new_values
  @new_values
end

Instance Method Details

#[](name) ⇒ Object



12
13
14
# File 'lib/grape/util/inheritable_values.rb', line 12

def [](name)
  values[name]
end

#[]=(name, value) ⇒ Object



16
17
18
# File 'lib/grape/util/inheritable_values.rb', line 16

def []=(name, value)
  new_values[name] = value
end

#delete(key) ⇒ Object



20
21
22
# File 'lib/grape/util/inheritable_values.rb', line 20

def delete(key)
  new_values.delete key
end

#initialize_copy(other) ⇒ Object



36
37
38
39
40
# File 'lib/grape/util/inheritable_values.rb', line 36

def initialize_copy(other)
  super
  self.inherited_values = other.inherited_values
  self.new_values = other.new_values.deep_dup
end

#keysObject



28
29
30
# File 'lib/grape/util/inheritable_values.rb', line 28

def keys
  (new_values.keys + inherited_values.keys).sort.uniq
end

#merge(new_hash) ⇒ Object



24
25
26
# File 'lib/grape/util/inheritable_values.rb', line 24

def merge(new_hash)
  values.merge(new_hash)
end

#to_hashObject



32
33
34
# File 'lib/grape/util/inheritable_values.rb', line 32

def to_hash
  values.clone
end