Class: Setup::Configuration
- Inherits:
-
Object
- Object
- Setup::Configuration
- Defined in:
- lib/setup/configuration.rb
Overview
Stores platform information and general install settings.
Constant Summary collapse
- RBCONFIG =
Ruby System Configuration
::RbConfig::CONFIG
- META_CONFIG_FILE =
Custom configuration file.
META_EXTENSION_DIR + '/metaconfig.rb'
Instance Attribute Summary collapse
-
#reset ⇒ Object
def initialize_configfile begin File.foreach(CONFIG_FILE) do |line| k, v = *line.split(/=/, 2) k.gsub!(‘-’,‘_’) __send__(“#k=”,v.strip) #self = v.strip end rescue Errno::ENOENT raise Error, $!.message + “n#File.basename($0) config first” end end.
Class Method Summary collapse
-
.option(name, *args) ⇒ Object
TODO: better methods for path type.
- .options ⇒ Object
Instance Method Summary collapse
-
#base_bindir ⇒ Object
Base bin directory.
- #base_datadir ⇒ Object
-
#base_docdir ⇒ Object
NOTE: This removed the trailing
$(PACKAGE). -
#base_libdir ⇒ Object
Base libdir.
-
#base_localstatedir ⇒ Object
Base directory for local state data.
- #base_mandir ⇒ Object
- #base_rubyarchdir ⇒ Object
- #base_rubylibdir ⇒ Object
-
#base_sysconfdir ⇒ Object
Base directory for system configuration files.
-
#bindir ⇒ Object
Directory for commands.
-
#bindir=(path) ⇒ Object
Set directory for commands.
-
#compile? ⇒ Boolean
Compile native extensions?.
-
#datadir ⇒ Object
Directory for shared data.
-
#datadir=(path) ⇒ Object
Set directory for shared data.
-
#doc? ⇒ Boolean
Install doc directory?.
-
#docdir ⇒ Object
Directory for documentation.
-
#docdir=(path) ⇒ Object
Set directory for documentation.
-
#exist? ⇒ Boolean
Does the configuration file exist?.
- #extconfopt ⇒ Object
- #extconfopt=(string) ⇒ Object
-
#initialize(values = {}) {|_self| ... } ⇒ Configuration
constructor
New ConfigTable.
-
#initialize_configfile ⇒ Object
Load configuration.
-
#initialize_defaults ⇒ Object
By default installation is to site locations, tests will not be run, ri documentation will not be generated, but the
doc/directory will be installed. -
#initialize_environment ⇒ Object
Get configuration from environment.
- #initialize_metaconfig ⇒ Object
-
#libdir ⇒ Object
Directory for libraries.
-
#libdir=(path) ⇒ Object
Set directory for libraries.
-
#libruby ⇒ Object
Directory for ruby libraries.
-
#libruby=(path) ⇒ Object
Set directory for ruby libraries.
-
#librubyver ⇒ Object
Directory for standard ruby libraries.
-
#librubyver=(path) ⇒ Object
Set directory for standard ruby libraries.
-
#librubyverarch ⇒ Object
Directory for standard ruby extensions.
-
#librubyverarch=(path) ⇒ Object
Set directory for standard ruby extensions.
-
#localstatedir ⇒ Object
Directory for local state data TODO: Can this be prefixed?.
-
#localstatedir=(path) ⇒ Object
Set directory for local state data.
-
#makeprog ⇒ Object
TODO: Does this handle ‘nmake’ on windows?.
- #makeprog=(command) ⇒ Object
-
#mandir ⇒ Object
Directory for man pages.
-
#mandir=(path) ⇒ Object
Set directory for man pages.
- #no_doc ⇒ Object
- #no_doc=(val) ⇒ Object
- #no_ext ⇒ Object
- #no_ext=(val) ⇒ Object
-
#no_ri ⇒ Object
deprecated
Deprecated.
Will be remove in future version. Currently ignored.
-
#no_ri=(val) ⇒ Object
deprecated
Deprecated.
Will be remove in future version. Currently ignored.
- #no_test ⇒ Object
- #no_test=(val) ⇒ Object
- #options ⇒ Object
-
#prefix ⇒ Object
Path prefix of target environment.
-
#prefix=(path) ⇒ Object
Set path prefix of target environment.
-
#rbdir ⇒ Object
Directory for ruby scripts.
- #rubypath ⇒ Object
- #rubypath=(path) ⇒ Object
- #rubyprog ⇒ Object
- #rubyprog=(command) ⇒ Object
-
#save_config ⇒ Object
Save configuration.
-
#shebang ⇒ Object
Default is
ruby. -
#shebang=(val) ⇒ Object
There are three options:
all,ruby,never. -
#siteruby ⇒ Object
Directory for version-independent aux ruby libraries.
-
#siteruby=(path) ⇒ Object
Set directory for version-independent aux ruby libraries.
-
#siterubyver ⇒ Object
Directory for aux ruby libraries.
-
#siterubyver=(path) ⇒ Object
Set directory for aux ruby libraries.
-
#siterubyverarch ⇒ Object
Directory for aux ruby binary libraries.
-
#siterubyverarch=(path) ⇒ Object
Set directory for aux arch ruby binaries.
-
#sodir ⇒ Object
Directory for ruby extentions.
-
#sysconfdir ⇒ Object
Directory for system configuration files TODO: Can this be prefixed?.
-
#sysconfdir=(path) ⇒ Object
Set directory for system configuration files.
-
#test? ⇒ Boolean
Run unit tests?.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #to_yaml(*args) ⇒ Object
- #type ⇒ Object (also: #installdirs)
- #type=(val) ⇒ Object (also: #installdirs=)
Constructor Details
#initialize(values = {}) {|_self| ... } ⇒ Configuration
New ConfigTable
112 113 114 115 116 117 118 119 120 |
# File 'lib/setup/configuration.rb', line 112 def initialize(values={}) initialize_defaults initialize_environment initialize_configfile unless values[:reset] values.each{ |k,v| __send__("#{k}=", v) } yield(self) if block_given? end |
Instance Attribute Details
#reset ⇒ Object
def initialize_configfile begin
File.foreach(CONFIG_FILE) do |line|
k, v = *line.split(/=/, 2)
k.gsub!('-','_')
__send__("#{k}=",v.strip) #self[k] = v.strip
end
rescue Errno::ENOENT
raise Error, $!. + "\n#{File.basename($0)} config first"
end
end
188 189 190 |
# File 'lib/setup/configuration.rb', line 188 def reset @reset end |
Class Method Details
.option(name, *args) ⇒ Object
TODO: better methods for path type
32 33 34 35 |
# File 'lib/setup/configuration.rb', line 32 def self.option(name, *args) #type, description) << [name.to_s, *args] #type, description] attr_accessor(name) end |
.options ⇒ Object
25 26 27 |
# File 'lib/setup/configuration.rb', line 25 def self. ||= [] end |
Instance Method Details
#base_bindir ⇒ Object
Base bin directory
198 199 200 |
# File 'lib/setup/configuration.rb', line 198 def base_bindir @base_bindir ||= subprefix('bindir') end |
#base_datadir ⇒ Object
208 209 210 |
# File 'lib/setup/configuration.rb', line 208 def base_datadir @base_datadir ||= subprefix('datadir') end |
#base_docdir ⇒ Object
NOTE: This removed the trailing $(PACKAGE).
218 219 220 |
# File 'lib/setup/configuration.rb', line 218 def base_docdir @base_docdir || File.dirname(subprefix('docdir')) end |
#base_libdir ⇒ Object
Base libdir
203 204 205 |
# File 'lib/setup/configuration.rb', line 203 def base_libdir @base_libdir ||= subprefix('libdir') end |
#base_localstatedir ⇒ Object
Base directory for local state data
238 239 240 |
# File 'lib/setup/configuration.rb', line 238 def base_localstatedir @base_localstatedir ||= subprefix('localstatedir') end |
#base_mandir ⇒ Object
213 214 215 |
# File 'lib/setup/configuration.rb', line 213 def base_mandir @base_mandir ||= subprefix('mandir') end |
#base_rubyarchdir ⇒ Object
228 229 230 |
# File 'lib/setup/configuration.rb', line 228 def base_rubyarchdir @base_rubyarchdir ||= subprefix('archdir') end |
#base_rubylibdir ⇒ Object
223 224 225 |
# File 'lib/setup/configuration.rb', line 223 def base_rubylibdir @rubylibdir ||= subprefix('rubylibdir') end |
#base_sysconfdir ⇒ Object
Base directory for system configuration files
233 234 235 |
# File 'lib/setup/configuration.rb', line 233 def base_sysconfdir @base_sysconfdir ||= subprefix('sysconfdir') end |
#bindir ⇒ Object
Directory for commands
365 366 367 |
# File 'lib/setup/configuration.rb', line 365 def bindir @bindir || File.join(prefix, base_bindir) end |
#bindir=(path) ⇒ Object
Set directory for commands
370 371 372 |
# File 'lib/setup/configuration.rb', line 370 def bindir=(path) @bindir = pathname(path) end |
#compile? ⇒ Boolean
Compile native extensions?
554 555 556 |
# File 'lib/setup/configuration.rb', line 554 def compile? !no_ext end |
#datadir ⇒ Object
Directory for shared data
385 386 387 |
# File 'lib/setup/configuration.rb', line 385 def datadir @datadir || File.join(prefix, base_datadir) end |
#datadir=(path) ⇒ Object
Set directory for shared data
390 391 392 |
# File 'lib/setup/configuration.rb', line 390 def datadir=(path) @datadir = pathname(path) end |
#doc? ⇒ Boolean
Install doc directory?
569 570 571 |
# File 'lib/setup/configuration.rb', line 569 def doc? !no_doc end |
#docdir ⇒ Object
Directory for documentation
405 406 407 |
# File 'lib/setup/configuration.rb', line 405 def docdir @docdir || File.join(prefix, base_docdir) end |
#docdir=(path) ⇒ Object
Set directory for documentation
410 411 412 |
# File 'lib/setup/configuration.rb', line 410 def docdir=(path) @docdir = pathname(path) end |
#exist? ⇒ Boolean
Does the configuration file exist?
611 612 613 |
# File 'lib/setup/configuration.rb', line 611 def exist? File.exist?(CONFIG_FILE) end |
#extconfopt ⇒ Object
484 485 486 |
# File 'lib/setup/configuration.rb', line 484 def extconfopt @extconfopt ||= '' end |
#extconfopt=(string) ⇒ Object
489 490 491 |
# File 'lib/setup/configuration.rb', line 489 def extconfopt=(string) @extconfopt = string end |
#initialize_configfile ⇒ Object
Load configuration.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/setup/configuration.rb', line 153 def initialize_configfile if exist? erb = ERB.new(File.read(CONFIG_FILE)) txt = erb.result(binding) dat = YAML.load(txt) dat.each do |k, v| next if 'type' == k next if 'installdirs' == k k = k.gsub('-','_') __send__("#{k}=", v) end # do these last if dat['type'] self.type = dat['type'] end if dat['installdirs'] self.installdirs = dat['installdirs'] end #else # raise Error, $!.message + "\n#{File.basename($0)} config first" end end |
#initialize_defaults ⇒ Object
By default installation is to site locations, tests will not be run, ri documentation will not be generated, but the doc/ directory will be installed.
133 134 135 136 137 138 139 140 141 |
# File 'lib/setup/configuration.rb', line 133 def initialize_defaults self.type = 'site' self.no_ri = true self.no_test = true self.no_doc = true self.no_ext = false #@rbdir = siterubyver #'$siterubyver' #@sodir = siterubyverarch #'$siterubyverarch' end |
#initialize_environment ⇒ Object
Get configuration from environment.
144 145 146 147 148 149 150 |
# File 'lib/setup/configuration.rb', line 144 def initialize_environment .each do |name, *args| if value = ENV["RUBYSETUP_#{name.to_s.upcase}"] __send__("#{name}=", value) end end end |
#initialize_metaconfig ⇒ Object
123 124 125 126 127 128 |
# File 'lib/setup/configuration.rb', line 123 def if File.exist?(META_CONFIG_FILE) script = File.read(META_CONFIG_FILE) (class << self; self; end).class_eval(script) end end |
#libdir ⇒ Object
Directory for libraries
375 376 377 |
# File 'lib/setup/configuration.rb', line 375 def libdir @libdir || File.join(prefix, base_libdir) end |
#libdir=(path) ⇒ Object
Set directory for libraries
380 381 382 |
# File 'lib/setup/configuration.rb', line 380 def libdir=(path) @libdir = pathname(path) end |
#libruby ⇒ Object
Directory for ruby libraries
299 300 301 |
# File 'lib/setup/configuration.rb', line 299 def libruby @libruby ||= RBCONFIG['prefix'] + "/lib/ruby" end |
#libruby=(path) ⇒ Object
Set directory for ruby libraries
304 305 306 307 308 309 |
# File 'lib/setup/configuration.rb', line 304 def libruby=(path) path = pathname(path) @librubyver = librubyver.sub(libruby, path) @librubyverarch = librubyverarch.sub(libruby, path) @libruby = path end |
#librubyver ⇒ Object
Directory for standard ruby libraries
312 313 314 |
# File 'lib/setup/configuration.rb', line 312 def librubyver @librubyver ||= RBCONFIG['rubylibdir'] end |
#librubyver=(path) ⇒ Object
Set directory for standard ruby libraries
317 318 319 |
# File 'lib/setup/configuration.rb', line 317 def librubyver=(path) @librubyver = pathname(path) end |
#librubyverarch ⇒ Object
Directory for standard ruby extensions
322 323 324 |
# File 'lib/setup/configuration.rb', line 322 def librubyverarch @librubyverarch ||= RBCONFIG['archdir'] end |
#librubyverarch=(path) ⇒ Object
Set directory for standard ruby extensions
327 328 329 |
# File 'lib/setup/configuration.rb', line 327 def librubyverarch=(path) @librubyverarch = pathname(path) end |
#localstatedir ⇒ Object
Directory for local state data TODO: Can this be prefixed?
437 438 439 |
# File 'lib/setup/configuration.rb', line 437 def localstatedir @localstatedir ||= base_localstatedir end |
#localstatedir=(path) ⇒ Object
Set directory for local state data
442 443 444 |
# File 'lib/setup/configuration.rb', line 442 def localstatedir=(path) @localstatedir = pathname(path) end |
#makeprog ⇒ Object
TODO: Does this handle ‘nmake’ on windows?
468 469 470 471 472 473 474 475 476 |
# File 'lib/setup/configuration.rb', line 468 def makeprog @makeprog ||= ( if arg = RBCONFIG['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg } arg.sub(/'/, '').split(/=/, 2)[1] else 'make' end ) end |
#makeprog=(command) ⇒ Object
479 480 481 |
# File 'lib/setup/configuration.rb', line 479 def makeprog=(command) @makeprog = command end |
#mandir ⇒ Object
Directory for man pages
395 396 397 |
# File 'lib/setup/configuration.rb', line 395 def mandir @mandir || File.join(prefix, base_mandir) end |
#mandir=(path) ⇒ Object
Set directory for man pages
400 401 402 |
# File 'lib/setup/configuration.rb', line 400 def mandir=(path) @mandir = pathname(path) end |
#no_doc ⇒ Object
528 529 530 |
# File 'lib/setup/configuration.rb', line 528 def no_doc @no_doc end |
#no_doc=(val) ⇒ Object
533 534 535 |
# File 'lib/setup/configuration.rb', line 533 def no_doc=(val) @no_doc = boolean(val) end |
#no_ext ⇒ Object
508 509 510 |
# File 'lib/setup/configuration.rb', line 508 def no_ext @no_ext end |
#no_ext=(val) ⇒ Object
513 514 515 |
# File 'lib/setup/configuration.rb', line 513 def no_ext=(val) @no_ext = boolean(val) end |
#no_ri ⇒ Object
Will be remove in future version. Currently ignored.
539 540 541 |
# File 'lib/setup/configuration.rb', line 539 def no_ri @no_ri end |
#no_ri=(val) ⇒ Object
Will be remove in future version. Currently ignored.
544 545 546 |
# File 'lib/setup/configuration.rb', line 544 def no_ri=(val) @no_ri = boolean(val) end |
#no_test ⇒ Object
518 519 520 |
# File 'lib/setup/configuration.rb', line 518 def no_test @no_test end |
#no_test=(val) ⇒ Object
523 524 525 |
# File 'lib/setup/configuration.rb', line 523 def no_test=(val) @no_test = boolean(val) end |
#options ⇒ Object
104 105 106 107 |
# File 'lib/setup/configuration.rb', line 104 def #(class << self ; self ; end).options self.class. end |
#prefix ⇒ Object
Path prefix of target environment
289 290 291 |
# File 'lib/setup/configuration.rb', line 289 def prefix @prefix ||= RBCONFIG['prefix'] end |
#prefix=(path) ⇒ Object
Set path prefix of target environment
294 295 296 |
# File 'lib/setup/configuration.rb', line 294 def prefix=(path) @prefix = pathname(path) end |
#rbdir ⇒ Object
Directory for ruby scripts
415 416 417 |
# File 'lib/setup/configuration.rb', line 415 def rbdir @rbdir || File.join(prefix, base_rubylibdir) end |
#rubypath ⇒ Object
447 448 449 450 |
# File 'lib/setup/configuration.rb', line 447 def rubypath #@rubypath ||= RBCONFIG['libexecdir'] @rubypath ||= File.join(RBCONFIG['bindir'], RBCONFIG['ruby_install_name'] + RBCONFIG['EXEEXT']) end |
#rubypath=(path) ⇒ Object
453 454 455 |
# File 'lib/setup/configuration.rb', line 453 def rubypath=(path) @rubypath = pathname(path) end |
#rubyprog ⇒ Object
458 459 460 |
# File 'lib/setup/configuration.rb', line 458 def rubyprog @rubyprog || rubypath end |
#rubyprog=(command) ⇒ Object
463 464 465 |
# File 'lib/setup/configuration.rb', line 463 def rubyprog=(command) @rubyprog = command end |
#save_config ⇒ Object
Save configuration.
596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/setup/configuration.rb', line 596 def save_config out = to_yaml dir = File.dirname(CONFIG_FILE) unless File.exist?(dir) FileUtils.mkdir_p(dir) end if File.exist?(CONFIG_FILE) txt = File.read(CONFIG_FILE) return nil if txt == out end File.open(CONFIG_FILE, 'w'){ |f| f << out } true end |
#shebang ⇒ Object
Default is ruby.
494 495 496 |
# File 'lib/setup/configuration.rb', line 494 def shebang @shebang ||= 'ruby' end |
#shebang=(val) ⇒ Object
There are three options: all, ruby, never.
499 500 501 502 503 504 505 |
# File 'lib/setup/configuration.rb', line 499 def shebang=(val) if %w(all ruby never).include?(val) @shebang = val else raise Error, "bad config: use SHEBANG=(all|ruby|never) [#{val}]" end end |
#siteruby ⇒ Object
Directory for version-independent aux ruby libraries
332 333 334 |
# File 'lib/setup/configuration.rb', line 332 def siteruby @siteruby ||= RBCONFIG['sitedir'] end |
#siteruby=(path) ⇒ Object
Set directory for version-independent aux ruby libraries
337 338 339 340 341 342 |
# File 'lib/setup/configuration.rb', line 337 def siteruby=(path) path = pathname(path) @siterubyver = siterubyver.sub(siteruby, path) @siterubyverarch = siterubyverarch.sub(siteruby, path) @siteruby = path end |
#siterubyver ⇒ Object
Directory for aux ruby libraries
345 346 347 |
# File 'lib/setup/configuration.rb', line 345 def siterubyver @siterubyver ||= RBCONFIG['sitelibdir'] end |
#siterubyver=(path) ⇒ Object
Set directory for aux ruby libraries
350 351 352 |
# File 'lib/setup/configuration.rb', line 350 def siterubyver=(path) @siterubyver = pathname(path) end |
#siterubyverarch ⇒ Object
Directory for aux ruby binary libraries
355 356 357 |
# File 'lib/setup/configuration.rb', line 355 def siterubyverarch @siterubyverarch ||= RBCONFIG['sitearchdir'] end |
#siterubyverarch=(path) ⇒ Object
Set directory for aux arch ruby binaries
360 361 362 |
# File 'lib/setup/configuration.rb', line 360 def siterubyverarch=(path) @siterubyverarch = pathname(path) end |
#sodir ⇒ Object
Directory for ruby extentions
420 421 422 |
# File 'lib/setup/configuration.rb', line 420 def sodir @sodir || File.join(prefix, base_rubyarchdir) end |
#sysconfdir ⇒ Object
Directory for system configuration files TODO: Can this be prefixed?
426 427 428 |
# File 'lib/setup/configuration.rb', line 426 def sysconfdir @sysconfdir ||= base_sysconfdir end |
#sysconfdir=(path) ⇒ Object
Set directory for system configuration files
431 432 433 |
# File 'lib/setup/configuration.rb', line 431 def sysconfdir=(path) @sysconfdir = pathname(path) end |
#test? ⇒ Boolean
Run unit tests?
559 560 561 |
# File 'lib/setup/configuration.rb', line 559 def test? !no_test end |
#to_h ⇒ Object
577 578 579 580 581 582 583 |
# File 'lib/setup/configuration.rb', line 577 def to_h h = {} .each do |name, *args| h[name.to_s] = __send__(name) end h end |
#to_s ⇒ Object
586 587 588 |
# File 'lib/setup/configuration.rb', line 586 def to_s to_yaml.sub(/\A---\s*\n/,'') end |
#to_yaml(*args) ⇒ Object
591 592 593 |
# File 'lib/setup/configuration.rb', line 591 def to_yaml(*args) to_h.to_yaml(*args) end |
#type ⇒ Object Also known as: installdirs
246 247 248 |
# File 'lib/setup/configuration.rb', line 246 def type @type ||= 'site' end |
#type=(val) ⇒ Object Also known as: installdirs=
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/setup/configuration.rb', line 251 def type=(val) @type = val case val.to_s when 'std', 'ruby' @rbdir = librubyver #'$librubyver' @sodir = librubyverarch #'$librubyverarch' when 'site' @rbdir = siterubyver #'$siterubyver' @sodir = siterubyverarch #'$siterubyverarch' when 'home' self.prefix = File.join(home, '.local') # TODO: Use XDG @rbdir = nil #'$libdir/ruby' @sodir = nil #'$libdir/ruby' #when 'local' # rbdir = subprefix(librubyver, '') # sodir = subprefix(librubyverarch, '') # self.prefix = '/usr/local' # FIXME: how? # self.rbdir = File.join(prefix, rbdir) #'$libdir/ruby' # self.sodir = File.join(prefix, sodir) #'$libdir/ruby' else raise Error, "bad config: use type=(std|site|home) [#{val}]" end end |