Module: AssitConfig

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/assit_config.rb', line 43

def self.action
  @@assit_action_object ||= begin
    action_name = "#{@assit_action.to_s.downcase}_action"
    
    # require the action's file
    require File.join('assit', '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



62
63
64
# File 'lib/assit_config.rb', line 62

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

.assit_disabled(disable) ⇒ Object

Sets the “disable” flag



32
33
34
35
# File 'lib/assit_config.rb', line 32

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

.disabled?Boolean

Gets the “disable” flag

Returns:

  • (Boolean)


38
39
40
# File 'lib/assit_config.rb', line 38

def self.disabled?
  @assit_disabled
end

.do_config!Object

Sets up the Assit configuration parameters



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

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