Module: SafetyCone::Configuration
- Included in:
- SafetyCone
- Defined in:
- lib/safety_cone/configuration.rb
Overview
Module for configuring safety measures
Constant Summary collapse
- VALID_OPTION_KEYS =
i[method controller action name].freeze
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#cones ⇒ Object
Returns the value of attribute cones.
-
#options ⇒ Object
Returns the value of attribute options.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
-
#add(options = {}) ⇒ Object
Method add a route or method to be managed by safety cone.
-
#configure {|_self| ... } ⇒ Object
Configuration method for Rails initializer.
-
#make_key ⇒ Object
Method to generate a key from the options.
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
6 7 8 |
# File 'lib/safety_cone/configuration.rb', line 6 def auth @auth end |
#cones ⇒ Object
Returns the value of attribute cones.
6 7 8 |
# File 'lib/safety_cone/configuration.rb', line 6 def cones @cones end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/safety_cone/configuration.rb', line 6 def end |
#redis ⇒ Object
Returns the value of attribute redis.
6 7 8 |
# File 'lib/safety_cone/configuration.rb', line 6 def redis @redis end |
Instance Method Details
#add(options = {}) ⇒ Object
Method add a route or method to be managed by safety cone
9 10 11 12 13 14 15 |
# File 'lib/safety_cone/configuration.rb', line 9 def add( = {}) self. = raise(ArgumentError, 'Mandatory param :name missing') unless [:name] cones[make_key] = end |
#configure {|_self| ... } ⇒ Object
Configuration method for Rails initializer
30 31 32 33 34 35 |
# File 'lib/safety_cone/configuration.rb', line 30 def configure self.cones = {} self.auth = { username: nil, password: nil } yield self end |
#make_key ⇒ Object
Method to generate a key from the options
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/safety_cone/configuration.rb', line 18 def make_key if .key? :method [:method].to_sym elsif .include?(:controller) && .include?(:action) "#{options[:controller]}_#{options[:action]}".to_sym else raise(ArgumentError, 'Options should contain :controller and :action or :method.') end end |