Class: QED::Settings
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
-
#format ⇒ Object
Output format.
-
#loadpath ⇒ Object
Paths to be added to $LOAD_PATH.
-
#mode ⇒ Object
Parse mode.
-
#omit ⇒ Object
File patterns to omit.
-
#requires ⇒ Object
Libraries to be required.
-
#rooted ⇒ Object
Operate from project root?.
-
#rootless ⇒ Object
Operate from system temporary directory?.
-
#trace ⇒ Object
Trace execution?.
Instance Method Summary collapse
-
#clear_directory ⇒ Object
Remove and recreate temporary working directory.
-
#default_profile ⇒ Object
Profile name can come from
profileorpenvironment variables. -
#files ⇒ Object
Demonstration files (or globs).
- #files=(files) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Settings
constructor
Initialize new Settings instance.
-
#initialize_defaults ⇒ Object
Initialize default settings.
-
#load_profile(&block) ⇒ Object
Load QED configuration profile.
-
#profiles ⇒ Object
Profiles are collected from the RC library, unless RC is deactivated via the override file.
-
#root ⇒ Object
(also: #root_directory)
Project’s root directory.
-
#rootless? ⇒ Boolean
Operate relative to project root directory, or use system’s location.
-
#temporary_directory ⇒ Object
(also: #tmpdir)
Temporary directory.
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(={}, &block) initialize_defaults @profile = (.delete(:profile) || default_profile).to_s load_profile(&block) .each do |key, val| send("#{key}=", val) if val end end |
Instance Attribute Details
#format ⇒ Object
Output format.
77 78 79 |
# File 'lib/qed/settings.rb', line 77 def format @format end |
#loadpath ⇒ Object
Paths to be added to $LOAD_PATH.
86 87 88 |
# File 'lib/qed/settings.rb', line 86 def loadpath @loadpath end |
#omit ⇒ Object
File patterns to omit.
74 75 76 |
# File 'lib/qed/settings.rb', line 74 def omit @omit end |
#requires ⇒ Object
Libraries to be required.
89 90 91 |
# File 'lib/qed/settings.rb', line 89 def requires @requires end |
#rooted ⇒ Object
Operate from project root?
92 93 94 |
# File 'lib/qed/settings.rb', line 92 def rooted @rooted end |
#rootless ⇒ Object
Operate from system temporary directory?
95 96 97 |
# File 'lib/qed/settings.rb', line 95 def rootless @rootless end |
#trace ⇒ Object
Trace execution?
80 81 82 |
# File 'lib/qed/settings.rb', line 80 def trace @trace end |
Instance Method Details
#clear_directory ⇒ Object
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_profile ⇒ Object
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 |
#files ⇒ Object
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_defaults ⇒ Object
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 |
#profiles ⇒ Object
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 |
#root ⇒ Object 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.
118 119 120 |
# File 'lib/qed/settings.rb', line 118 def rootless? @rootless end |
#temporary_directory ⇒ Object 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 |