Module: Assit::Config

Defined in:
lib/assit/config.rb

Overview

Helper module for the configuration Ths is used to load the Assit module. The following configuration options exist:

  • assit_disabled - If set it will completely disable the assertions

  • assit_action - Selects the action that will be executed if the assert fails

The Assit framework can be configured through environment variables or a config file (assit_config.rb) in the current load path.

If environment variables are used, the should have ALL UPPERCASE names, as ASSIT_DISABLED and ASSIT_ACTION.

Environment variables take precedence over the config file.

If no configuration is given, the module is configured automatically:

A Rails installation run in ‘production’ mode will have the assertions disabled.

A Rails installation in the other modes will use :raise as the default action.

Other scripts will use :raise if the $DEBUG flag is set, otherwise :log is used as the default action

Class Method Summary collapse

Class Method Details

.actionObject

Get the action for failed assertions



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/assit/config.rb', line 45

def self.action
  @@assit_action_object ||= begin
    action_name = "#{@assit_action.to_s.downcase}_action"

    # require the action's file
    require File.join('actions', action_name)

    # Get the class of the widget and check, just to be sure
    klass = Assit.const_get(camelize(action_name))
    raise(RuntimeError, "Action class does not exist") unless(klass.is_a?(Class))

    # Create the new widget
    klass.new()
  end
end

.assit_action(action) ⇒ Object

Sets the action for failed assertions. This will create the AssitAction object that can be used by the framework



64
65
66
# File 'lib/assit/config.rb', line 64

def self.assit_action(action)
  @assit_action = action.to_sym
end

.assit_disabled(disable) ⇒ Object

Sets the “disable” flag



34
35
36
37
# File 'lib/assit/config.rb', line 34

def self.assit_disabled(disable)
  @assit_disabled = disable
  @assit_disabled_conf = true
end

.disabled?Boolean

Gets the “disable” flag

Returns:

  • (Boolean)


40
41
42
# File 'lib/assit/config.rb', line 40

def self.disabled?
  @assit_disabled
end

.do_config!Object

Sets up the Assit configuration parameters



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/assit/config.rb', line 69

def self.do_config!
  # Try to load the configuration
  begin
    require 'assit_config'
  rescue LoadError
    # Fail silently, we don't care if there is no config file
  end

  # Check for the environment variables. They can overwrite the 
  # config file variables.
  @assit_disabled ||= ENV['ASSIT_DISABLED'] && (ENV['ASSIT_DISABLED'].downcase == 'true' || ENV['ASSIT_DISABLED'].downcase == 'yes') 
  @assit_disabled_conf ||= (ENV['ASSIT_DISABLED'] != nil)
  @assit_action ||= ENV['ASSIT_ACTION'] ? ENV['ASSIT_ACTION'].downcase.to_sym : nil

  # If still not configured, use the auto-config
  @assit_disabled ||= auto_disable unless(@assit_disabled_conf)
  @assit_action ||= auto_action
  
  # Call the action one time to create and load it
  action
  
  # return true
  true
end