Module: Hatt::DSL

Includes:
Configuration, Log
Included in:
Mixin
Defined in:
lib/hatt/dsl.rb

Constant Summary

Constants included from Log

Log::HattFormatter

Constants included from Configuration

Configuration::DEFAULT_CONFIG_FILE, Configuration::DEFAULT_HATT_GLOBS

Instance Method Summary collapse

Methods included from Log

#add_logger, #level=, #log, #logger, #loggers

Methods included from Configuration

#hatt_config_file=, #hatt_configuration

Instance Method Details

#hatt_load_hatt_file(filename) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hatt/dsl.rb', line 34

def hatt_load_hatt_file(filename)
  Log.debug "Loading hatt file '#{filename}'"

  unless File.exist? filename
    raise HattNoSuchHattFile, "No such hatt file '#{filename}'"
  end

  # by evaling in a anonymous module, we protect this class's namespace
  anon_mod = Module.new
  with_local_load_path File.dirname(filename) do
    anon_mod.class_eval(IO.read(filename), filename, 1)
  end
  extend anon_mod
end

#hatt_load_hatt_glob(glob) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/hatt/dsl.rb', line 26

def hatt_load_hatt_glob(glob)
  globbed_files = Dir[glob]
  Log.debug "Found '#{globbed_files.length}' hatt files using hatt glob '#{glob}'"
  Dir[glob].each do |filename|
    hatt_load_hatt_file filename
  end
end

#load_hatts_using_configurationObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hatt/dsl.rb', line 9

def load_hatts_using_configuration
  hatt_globs = hatt_configuration['hatt_globs']
  if hatt_configuration['hatt_config_file']
    debug "Using HATT configuration file: #{hatt_configuration['hatt_config_file']}"
    glob_home_dir = File.dirname hatt_configuration['hatt_config_file']
    hatt_globs.map! { |g| File.join glob_home_dir, g }
  else
    debug 'Not using a hatt configuration file (none defined).'
  end
  if hatt_globs.is_a? Array
    hatt_globs.each do |gg|
      hatt_load_hatt_glob gg
    end
  end
  nil
end