Class: Setup::Base
- Inherits:
-
Object
- Object
- Setup::Base
- Defined in:
- lib/setup/base.rb
Overview
Common base class for all Setup build classes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#force ⇒ Object
Returns the value of attribute force.
-
#io ⇒ Object
Returns the value of attribute io.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#trace ⇒ Object
Returns the value of attribute trace.
-
#trial ⇒ Object
Returns the value of attribute trial.
Instance Method Summary collapse
-
#bash(*args) ⇒ Object
(also: #command)
Shellout executation.
- #force? ⇒ Boolean
- #force_remove_file(path) ⇒ Object
-
#initialize(project, configuration, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#initialize_hooks ⇒ Object
Hooking into the setup process, use extension scripts according to the name of the class.
- #quiet? ⇒ Boolean
- #remove_file(path) ⇒ Object
- #rm_f(path) ⇒ Object
- #rmdir(path) ⇒ Object
- #rootdir ⇒ Object
-
#ruby(*args) ⇒ Object
Shellout a ruby command.
- #trace? ⇒ Boolean
-
#trace_off ⇒ Object
:yield:.
- #trial? ⇒ Boolean
Constructor Details
#initialize(project, configuration, options = {}) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/setup/base.rb', line 32 def initialize(project, configuration, ={}) @project = project @config = configuration initialize_hooks .each do |k,v| __send__("#{k}=", v) if respond_to?("#{k}=") end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/setup/base.rb', line 14 def config @config end |
#force ⇒ Object
Returns the value of attribute force.
26 27 28 |
# File 'lib/setup/base.rb', line 26 def force @force end |
#io ⇒ Object
Returns the value of attribute io.
29 30 31 |
# File 'lib/setup/base.rb', line 29 def io @io end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
11 12 13 |
# File 'lib/setup/base.rb', line 11 def project @project end |
#quiet ⇒ Object
Returns the value of attribute quiet.
23 24 25 |
# File 'lib/setup/base.rb', line 23 def quiet @quiet end |
#trace ⇒ Object
Returns the value of attribute trace.
20 21 22 |
# File 'lib/setup/base.rb', line 20 def trace @trace end |
#trial ⇒ Object
Returns the value of attribute trial.
17 18 19 |
# File 'lib/setup/base.rb', line 17 def trial @trial end |
Instance Method Details
#bash(*args) ⇒ Object Also known as: command
Shellout executation.
75 76 77 78 |
# File 'lib/setup/base.rb', line 75 def bash(*args) $stderr.puts args.join(' ') if trace? system(*args) or raise RuntimeError, "system(#{args.map{|a| a.inspect }.join(' ')}) failed" end |
#force? ⇒ Boolean
67 |
# File 'lib/setup/base.rb', line 67 def force? ; @force ; end |
#force_remove_file(path) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/setup/base.rb', line 116 def force_remove_file(path) begin remove_file(path) rescue end end |
#initialize_hooks ⇒ Object
Hooking into the setup process, use extension scripts according to the name of the class. For instance to augment the behavior of the Installer, use:
.setup/installer.rb
49 50 51 52 53 54 55 |
# File 'lib/setup/base.rb', line 49 def initialize_hooks file = META_EXTENSION_DIR + "/#{self.class.name.downcase}.rb" if File.exist?(file) script = File.read(file) (class << self; self; end).class_eval(script) end end |
#quiet? ⇒ Boolean
64 |
# File 'lib/setup/base.rb', line 64 def quiet? ; @quiet ; end |
#remove_file(path) ⇒ Object
124 125 126 127 |
# File 'lib/setup/base.rb', line 124 def remove_file(path) File.chmod 0777, path File.unlink(path) end |
#rm_f(path) ⇒ Object
109 110 111 112 113 |
# File 'lib/setup/base.rb', line 109 def rm_f(path) io.puts "rm -f #{path}" if trace? or trial? return if trial? force_remove_file(path) end |
#rmdir(path) ⇒ Object
130 131 132 133 134 |
# File 'lib/setup/base.rb', line 130 def rmdir(path) io.puts "rmdir #{path}" if trace? or trial? return if trial? Dir.rmdir(path) end |
#rootdir ⇒ Object
70 71 72 |
# File 'lib/setup/base.rb', line 70 def rootdir project.rootdir end |
#ruby(*args) ⇒ Object
Shellout a ruby command.
84 85 86 |
# File 'lib/setup/base.rb', line 84 def ruby(*args) bash(config.rubyprog, *args) end |
#trace? ⇒ Boolean
61 |
# File 'lib/setup/base.rb', line 61 def trace? ; @trace ; end |
#trace_off ⇒ Object
:yield:
97 98 99 100 101 102 103 104 |
# File 'lib/setup/base.rb', line 97 def trace_off #:yield: begin save, @trace = trace?, false yield ensure @trace = save end end |
#trial? ⇒ Boolean
58 |
# File 'lib/setup/base.rb', line 58 def trial? ; @trial ; end |