Class: QED::Settings

Inherits:
Object show all
Defined in:
lib/qed/settings.rb

Overview

Settings ecapsulates setup configuration for running QED.

Constant Summary collapse

DEFAULT_FILES =

If files are not specified than these directories will be searched.

['qed', 'demo', 'spec']
OMIT_PATHS =

Directory names to omit from automatic selection.

%w{applique helpers support sample samples fixture fixtures}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Settings

Initialize new Settings instance.


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/qed/settings.rb', line 23

def initialize(options={}, &block)
  initialize_defaults

  @profile = (options.delete(:profile) || default_profile).to_s

  load_profile(&block)

  options.each do |key, val|
    send("#{key}=", val) if val
  end
end

Instance Attribute Details

#formatObject

Output format.


77
78
79
# File 'lib/qed/settings.rb', line 77

def format
  @format
end

#loadpathObject

Paths to be added to $LOAD_PATH.


86
87
88
# File 'lib/qed/settings.rb', line 86

def loadpath
  @loadpath
end

#modeObject

Parse mode.


83
84
85
# File 'lib/qed/settings.rb', line 83

def mode
  @mode
end

#omitObject

File patterns to omit.


74
75
76
# File 'lib/qed/settings.rb', line 74

def omit
  @omit
end

#requiresObject

Libraries to be required.


89
90
91
# File 'lib/qed/settings.rb', line 89

def requires
  @requires
end

#rootedObject

Operate from project root?


92
93
94
# File 'lib/qed/settings.rb', line 92

def rooted
  @rooted
end

#rootlessObject

Operate from system temporary directory?


95
96
97
# File 'lib/qed/settings.rb', line 95

def rootless
  @rootless
end

#traceObject

Trace execution?


80
81
82
# File 'lib/qed/settings.rb', line 80

def trace
  @trace
end

Instance Method Details

#clear_directoryObject

Remove and recreate temporary working directory.


158
159
160
161
# File 'lib/qed/settings.rb', line 158

def clear_directory
  FileUtils.rm_r(tmpdir) if File.exist?(tmpdir)
  FileUtils.mkdir_p(tmpdir)
end

#default_profileObject

Profile name can come from `profile` or `p` environment variables.


51
52
53
# File 'lib/qed/settings.rb', line 51

def default_profile
  ENV['profile'] || ENV['p'] || 'default'
end

#filesObject

Demonstration files (or globs).


56
57
58
59
60
# File 'lib/qed/settings.rb', line 56

def files
  @files ||= (
    [DEFAULT_FILES.find{ |d| File.directory?(d) }].compact
  )
end

#files=(files) ⇒ Object


63
64
65
66
67
68
69
70
71
# File 'lib/qed/settings.rb', line 63

def files=(files)
  @files = (
    if files.nil? or files.empty?
      nil
    else
      Array(files).flatten.compact
    end
  )
end

#initialize_defaultsObject

Initialize default settings.


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/qed/settings.rb', line 38

def initialize_defaults
  @files    = nil #DEFAULT_FILES
  @format   = :dot
  @trace    = false
  @mode     = nil  # ?
  @loadpath = ['lib']
  @omit     = OMIT_PATHS
  @rootless = false
  @requires = []  #@profile  = :default

end

#load_profile(&block) ⇒ Object

Load QED configuration profile. The load procedure is stored as a Proc object in a hash b/c different configuration systems can be used.


102
103
104
105
# File 'lib/qed/settings.rb', line 102

def load_profile(&block)
  config = QED.profiles[@profile]
  config.call(self) if config
end

#profilesObject

Profiles are collected from the RC library, unless RC is deactivated via the override file.


111
112
113
# File 'lib/qed/settings.rb', line 111

def profiles
  QED.profiles.keys
end

#rootObject Also known as: root_directory

Project's root directory.


125
126
127
# File 'lib/qed/settings.rb', line 125

def root
  Utils.root
end

#rootless?Boolean

Operate relative to project root directory, or use system's location.

Returns:

  • (Boolean)

118
119
120
# File 'lib/qed/settings.rb', line 118

def rootless?
  @rootless
end

#temporary_directoryObject Also known as: tmpdir

Temporary directory. If `#rootless?` return true then this will be a system's temporary directory (e.g. `/tmp/qed/foo/20111117242323/`). Otherwise, it will local to the project's root int `tmp/qed/`.


139
140
141
142
143
144
145
146
147
148
# File 'lib/qed/settings.rb', line 139

def temporary_directory
  @temporary_directory ||= (
    if rootless?
      Utils.system_tmpdir
    else
      File.join(root_directory, 'tmp', 'qed')
    end    #FileUtils.mkdir_p(dir) unless File.directory?(dir)

  )
end