Module: Grape::DSL::Settings

Extended by:
ActiveSupport::Concern
Included in:
Configuration::ClassMethods, InsideRoute, Endpoint
Defined in:
lib/grape/dsl/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inheritable_settingObject

Returns the value of attribute inheritable_setting



8
9
10
# File 'lib/grape/dsl/settings.rb', line 8

def inheritable_setting
  @inheritable_setting
end

#top_level_settingObject

Returns the value of attribute top_level_setting



8
9
10
# File 'lib/grape/dsl/settings.rb', line 8

def top_level_setting
  @top_level_setting
end

Instance Method Details

#api_class_setting(key, value = nil) ⇒ Object



76
77
78
# File 'lib/grape/dsl/settings.rb', line 76

def api_class_setting(key, value = nil)
  get_or_set :api_class, key, value
end

#get_or_set(type, key, value) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/grape/dsl/settings.rb', line 23

def get_or_set(type, key, value)
  setting = inheritable_setting.send(type)
  if value.nil?
    setting[key]
  else
    setting[key] = value
  end
end

#global_setting(key, value = nil) ⇒ Object



32
33
34
# File 'lib/grape/dsl/settings.rb', line 32

def global_setting(key, value = nil)
  get_or_set :global, key, value
end

#namespace_endObject



88
89
90
91
# File 'lib/grape/dsl/settings.rb', line 88

def namespace_end
  route_end
  @inheritable_setting = inheritable_setting.parent
end

#namespace_inheritable(key, value = nil) ⇒ Object



56
57
58
# File 'lib/grape/dsl/settings.rb', line 56

def namespace_inheritable(key, value = nil)
  get_or_set :namespace_inheritable, key, value
end

#namespace_inheritable_to_nil(key) ⇒ Object



64
65
66
# File 'lib/grape/dsl/settings.rb', line 64

def namespace_inheritable_to_nil(key)
  inheritable_setting.namespace_inheritable[key] = nil
end

#namespace_setting(key, value = nil) ⇒ Object



48
49
50
# File 'lib/grape/dsl/settings.rb', line 48

def namespace_setting(key, value = nil)
  get_or_set :namespace, key, value
end

#namespace_stackable(key, value = nil) ⇒ Object



68
69
70
# File 'lib/grape/dsl/settings.rb', line 68

def namespace_stackable(key, value = nil)
  get_or_set :namespace_stackable, key, value
end

#namespace_startObject



84
85
86
# File 'lib/grape/dsl/settings.rb', line 84

def namespace_start
  @inheritable_setting = Grape::Util::InheritableSetting.new.tap { |new_settings| new_settings.inherit_from inheritable_setting }
end

#route_endObject



93
94
95
96
# File 'lib/grape/dsl/settings.rb', line 93

def route_end
  inheritable_setting.route_end
  reset_validations!
end

#route_setting(key, value = nil) ⇒ Object



40
41
42
# File 'lib/grape/dsl/settings.rb', line 40

def route_setting(key, value = nil)
  get_or_set :route, key, value
end

#unset(type, key) ⇒ Object



18
19
20
21
# File 'lib/grape/dsl/settings.rb', line 18

def unset(type, key)
  setting = inheritable_setting.send(type)
  setting.delete key
end

#unset_api_class_setting(key) ⇒ Object



80
81
82
# File 'lib/grape/dsl/settings.rb', line 80

def unset_api_class_setting(key)
  unset :api_class_setting, key
end

#unset_global_setting(key) ⇒ Object



36
37
38
# File 'lib/grape/dsl/settings.rb', line 36

def unset_global_setting(key)
  unset :global, key
end

#unset_namespace_inheritable(key) ⇒ Object



60
61
62
# File 'lib/grape/dsl/settings.rb', line 60

def unset_namespace_inheritable(key)
  unset :namespace_inheritable, key
end

#unset_namespace_setting(key) ⇒ Object



52
53
54
# File 'lib/grape/dsl/settings.rb', line 52

def unset_namespace_setting(key)
  unset :namespace_setting, key
end

#unset_namespace_stackable(key) ⇒ Object



72
73
74
# File 'lib/grape/dsl/settings.rb', line 72

def unset_namespace_stackable(key)
  unset :namespace_stackable, key
end

#unset_route_setting(key) ⇒ Object



44
45
46
# File 'lib/grape/dsl/settings.rb', line 44

def unset_route_setting(key)
  unset :route, key
end

#within_namespace(&block) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/grape/dsl/settings.rb', line 98

def within_namespace(&block)
  namespace_start

  result = yield if block_given?

  namespace_end
  reset_validations!

  result
end