Class: Grape::Util::BaseInheritable

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

Overview

Base for classes which need to operate with own values kept in the hash and inherited values kept in a Hash-like object.

Direct Known Subclasses

InheritableValues, StackableValues

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inherited_values = {}) ⇒ BaseInheritable

Returns a new instance of BaseInheritable.

Parameters:

  • inherited_values (Object) (defaults to: {})

    An object implementing an interface of the Hash class.



13
14
15
16
# File 'lib/grape/util/base_inheritable.rb', line 13

def initialize(inherited_values = {})
  @inherited_values = inherited_values
  @new_values = {}
end

Instance Attribute Details

#inherited_valuesObject

Returns the value of attribute inherited_values.



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

def inherited_values
  @inherited_values
end

#new_valuesObject

Returns the value of attribute new_values.



9
10
11
# File 'lib/grape/util/base_inheritable.rb', line 9

def new_values
  @new_values
end

Instance Method Details

#delete(key) ⇒ Object



18
19
20
# File 'lib/grape/util/base_inheritable.rb', line 18

def delete(key)
  new_values.delete key
end

#initialize_copy(other) ⇒ Object



22
23
24
25
26
# File 'lib/grape/util/base_inheritable.rb', line 22

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

#keysObject



28
29
30
31
32
33
# File 'lib/grape/util/base_inheritable.rb', line 28

def keys
  combined = inherited_values.keys
  combined.concat(new_values.keys)
  combined.uniq!
  combined
end