Module: Toast::ConfigDSL

Defined in:
lib/toast/config_dsl.rb

Defined Under Namespace

Modules: Common, DefaultHandlers Classes: Association, Base, Collection, Expose, Settings, Single, ViaVerb

Class Method Summary collapse

Class Method Details

.get_config(_toast_config, _toast_cfg_name) ⇒ Object

Interprets one config file and stores config info in the @expositions Array using OpenStruct.

Params:

config
String

The configuration file’s content as string

fname
String

The file name of the config file with path relative to Rails.root

Return: nil



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/toast/config_dsl.rb', line 17

def self.get_config _toast_config, _toast_cfg_name

  # using _toast_ prefix for all locals here, because they end up in the
  # handler/allow block scope (closure)
  # also freeze them to prevent accidental changes
  # is there a way to remove closure vars with instance_eval?

  _toast_config.freeze
  _toast_cfg_name.freeze

  @@cfg_name = _toast_cfg_name
  @@stack    = []

  _toast_base = ConfigDSL::Base.new
  _toast_base.freeze
  _toast_base.instance_eval(_toast_config, _toast_cfg_name)

rescue ArgumentError, NameError => _toast_error
  _toast_base.raise_config_error _toast_error.message
end

.get_settings(config, cfg_name) ⇒ Object

Interprets the global settings file and stores data using OpenStruct Params:

config
String

The configuration file’s content as string

fname
String

The file name of the config file with path relative to Rails.root

Return: nil



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

def self.get_settings config, cfg_name
  @@cfg_name = cfg_name
  @@stack    = []

  # defaults
  Toast.settings = OpenStruct.new
  Toast.settings.max_window = 42
  Toast.settings.link_unlink_via_post = false
  Toast.settings.authenticate = lambda{|r| r}

  settings = ConfigDSL::Settings.new
  settings.instance_eval(config, cfg_name)

rescue ArgumentError, NameError => error
  settings.raise_config_error error.message
end