Class: Grape::Util::InheritableSetting
- Defined in:
- lib/grape/util/inheritable_setting.rb
Instance Attribute Summary collapse
-
#api_class ⇒ Object
Returns the value of attribute api_class.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#namespace_inheritable ⇒ Object
Returns the value of attribute namespace_inheritable.
-
#namespace_stackable ⇒ Object
Returns the value of attribute namespace_stackable.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#point_in_time_copies ⇒ Object
Returns the value of attribute point_in_time_copies.
-
#route ⇒ Object
Returns the value of attribute route.
Class Method Summary collapse
- .global ⇒ Object
-
.reset_global! ⇒ Object
only for testing.
Instance Method Summary collapse
- #global ⇒ Object
- #inherit_from(parent) ⇒ Object
-
#initialize ⇒ InheritableSetting
constructor
A new instance of InheritableSetting.
- #point_in_time_copy ⇒ Object
- #route_end ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ InheritableSetting
Returns a new instance of InheritableSetting.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grape/util/inheritable_setting.rb', line 15 def initialize self.route = {} self.api_class = {} self.namespace = InheritableValues.new # only inheritable from a parent when # used with a mount, or should every API::Class be a seperate namespace by default? self.namespace_inheritable = InheritableValues.new self.namespace_stackable = StackableValues.new self.point_in_time_copies = [] self.parent = nil end |
Instance Attribute Details
#api_class ⇒ Object
Returns the value of attribute api_class.
4 5 6 |
# File 'lib/grape/util/inheritable_setting.rb', line 4 def api_class @api_class end |
#namespace ⇒ Object
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/grape/util/inheritable_setting.rb', line 4 def namespace @namespace end |
#namespace_inheritable ⇒ Object
Returns the value of attribute namespace_inheritable.
4 5 6 |
# File 'lib/grape/util/inheritable_setting.rb', line 4 def namespace_inheritable @namespace_inheritable end |
#namespace_stackable ⇒ Object
Returns the value of attribute namespace_stackable.
4 5 6 |
# File 'lib/grape/util/inheritable_setting.rb', line 4 def namespace_stackable @namespace_stackable end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/grape/util/inheritable_setting.rb', line 5 def parent @parent end |
#point_in_time_copies ⇒ Object
Returns the value of attribute point_in_time_copies.
5 6 7 |
# File 'lib/grape/util/inheritable_setting.rb', line 5 def point_in_time_copies @point_in_time_copies end |
#route ⇒ Object
Returns the value of attribute route.
4 5 6 |
# File 'lib/grape/util/inheritable_setting.rb', line 4 def route @route end |
Class Method Details
.global ⇒ Object
7 8 9 |
# File 'lib/grape/util/inheritable_setting.rb', line 7 def self.global @global ||= {} end |
.reset_global! ⇒ Object
only for testing
11 12 13 |
# File 'lib/grape/util/inheritable_setting.rb', line 11 def self.reset_global! # only for testing @global = {} end |
Instance Method Details
#global ⇒ Object
28 29 30 |
# File 'lib/grape/util/inheritable_setting.rb', line 28 def global self.class.global end |
#inherit_from(parent) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grape/util/inheritable_setting.rb', line 32 def inherit_from(parent) return if parent.nil? self.parent = parent namespace_inheritable.inherited_values = parent.namespace_inheritable namespace_stackable.inherited_values = parent.namespace_stackable self.route = parent.route.merge(route) point_in_time_copies.map { |cloned_one| cloned_one.inherit_from parent } end |
#point_in_time_copy ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/grape/util/inheritable_setting.rb', line 44 def point_in_time_copy self.class.new.tap do |new_setting| point_in_time_copies << new_setting new_setting.point_in_time_copies = [] new_setting.namespace = namespace.clone new_setting.namespace_inheritable = namespace_inheritable.clone new_setting.namespace_stackable = namespace_stackable.clone new_setting.route = route.clone new_setting.api_class = api_class new_setting.inherit_from(parent) end end |
#route_end ⇒ Object
59 60 61 |
# File 'lib/grape/util/inheritable_setting.rb', line 59 def route_end @route = {} end |
#to_hash ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/grape/util/inheritable_setting.rb', line 63 def to_hash { global: global.clone, route: route.clone, namespace: namespace.to_hash, namespace_inheritable: namespace_inheritable.to_hash, namespace_stackable: namespace_stackable.to_hash } end |