Module: SafetyCone::Configuration

Included in:
SafetyCone
Defined in:
lib/safety_cone/configuration.rb

Overview

Module for configuring safety measures

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authObject

Returns the value of attribute auth.



4
5
6
# File 'lib/safety_cone/configuration.rb', line 4

def auth
  @auth
end

#featuresObject

Returns the value of attribute features.



4
5
6
# File 'lib/safety_cone/configuration.rb', line 4

def features
  @features
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/safety_cone/configuration.rb', line 4

def options
  @options
end

#pathsObject

Returns the value of attribute paths.



4
5
6
# File 'lib/safety_cone/configuration.rb', line 4

def paths
  @paths
end

#redisObject

Returns the value of attribute redis.



4
5
6
# File 'lib/safety_cone/configuration.rb', line 4

def redis
  @redis
end

Instance Method Details

#add(options = {}) ⇒ Object

Method add a route or method to be managed by safety cone

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/safety_cone/configuration.rb', line 7

def add(options = {})
  self.options = options

  raise(ArgumentError, 'Mandatory param :name missing') unless options[:name]

  if options[:feature]
    features << options
    SafetyCone::ViewHelpers.add_method(options[:feature])
  else
    paths[make_key] = options
  end
end

#configure {|_self| ... } ⇒ Object

Configuration method for Rails initializer

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
38
39
# File 'lib/safety_cone/configuration.rb', line 33

def configure
  self.paths = {}
  self.features = []
  self.auth = { username: nil, password: nil }

  yield self
end

#make_keyObject

Method to generate a key from the options



21
22
23
24
25
26
27
28
29
30
# File 'lib/safety_cone/configuration.rb', line 21

def make_key
  if options.key? :method
    options[:method].to_sym
  elsif options.include?(:controller) && options.include?(:action)
    "#{options[:controller]}_#{options[:action]}".to_sym
  else
    raise(ArgumentError,
          'Options should contain :controller and :action or :method.')
  end
end