Module: Utilrb
- Defined in:
- lib/utilrb/common.rb,
lib/utilrb/yard.rb,
lib/utilrb/spawn.rb,
lib/utilrb/doc/rake.rb,
lib/utilrb/pkgconfig.rb,
lib/utilrb/event_loop.rb,
lib/utilrb/timepoints.rb,
lib/utilrb/rake_common.rb,
lib/utilrb/thread_pool.rb,
lib/utilrb/ruby_object_graph.rb,
lib/utilrb/models/registration.rb,
lib/utilrb/models/inherited_enumerable.rb,
lib/utilrb/configsearch/configuration_finder.rb,
ext/utilrb/utilrb.cc
Overview
Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all the standard class extensions used by www.rock-robotics.org projects.
Defined Under Namespace
Modules: Models, Rake, Timepoints, YARD Classes: ConfigurationFinder, EventLoop, PkgConfig, RubyObjectGraph, SpawnFailed, ThreadPool, WeakRef
Constant Summary collapse
- VERSION =
"2.0.1"
- RUBY_IS_19 =
(RUBY_VERSION >= "1.9.2")
- RUBY_IS_191 =
(RUBY_VERSION >= "1.9") && (RUBY_VERSION < "1.9.2")
- LIB_DIR =
File.(File.dirname(__FILE__))
- UTILRB_EXT_MODE =
nil
- DOC_MODE =
begin require 'yard' require 'yard/rake/yardoc_task' 'yard' rescue LoadError begin require 'rdoc/task' 'rdoc' rescue LoadError end end
Class Method Summary collapse
- .doc(target = 'docs', options = Hash.new) ⇒ Object
- .doc? ⇒ Boolean
-
.if_ext(&block) ⇒ Object
Yields if the extension is present.
-
.require_ext(name) ⇒ Object
Yields if the extension is present, and issue a warning otherwise.
- .spawn(*cmdline) ⇒ Object
-
.unless_ext ⇒ Object
Yields if the extension is not present This is used by Utilrb libraries to provide a Ruby version if the C extension is not loaded.
Class Method Details
.doc(target = 'docs', options = Hash.new) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/utilrb/doc/rake.rb', line 25 def self.doc(target = 'docs', = Hash.new) if target.kind_of?(Hash) target, = 'docs', target end = Kernel. , :include => [File.join('lib', '**', '*.rb'), File.join('ext', '**', '*.cc')], :exclude => [], :target_dir => 'doc', :title => '', :plugins => [], :files => [] case DOC_MODE when 'yard' task = YARD::Rake::YardocTask.new(target) task.files.concat([:include]) task. << '--title' << [:title] << '--output-dir' << [:target_dir] if ![:files].empty? task. << "--files" << [:files].join(",") end [:plugins].each do |plugin_name| require "#{plugin_name}/yard" end task_clobber = ::Rake::Task.define_task "clobber_#{target}" do FileUtils.rm_rf [:target_dir] end task_clobber.add_description "Remove #{target} products" name = ::Rake.application.current_scope.dup if name.respond_to?(:path) name = name.map(&:to_s).reverse end name << task.name task_re = ::Rake::Task.define_task "re#{target}" do FileUtils.rm_rf [:target_dir] ::Rake::Task[name.join(":")].invoke end task_re.add_description "Force a rebuild of #{target}" when "rdoc" task = RDoc::Task.new(target) task.rdoc_files.include(*[:include]) task.rdoc_files.exclude(*[:exclude]) task.title = [:title] task.rdoc_dir = File.([:target_dir]) else [target, "re#{target}"].each do |task_name| t = ::Rake::Task.define_task(task_name) do STDERR.puts "Documentation generation is disabled: install either the yard or rdoc gems" end t.add_description "Disabled on this installation as neither yard nor rdoc are available" end end end |
.doc? ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/utilrb/doc/rake.rb', line 17 def self.doc? if DOC_MODE true else false end end |
.if_ext(&block) ⇒ Object
Yields if the extension is present. This is used for Ruby code which depends on methods in the C extension
43 44 45 |
# File 'lib/utilrb/common.rb', line 43 def self.if_ext(&block) require_ext(nil, &block) end |
.require_ext(name) ⇒ Object
Yields if the extension is present, and issue a warning otherwise. This is used for Ruby code which depends on methods in the C extension
50 51 52 53 54 55 56 |
# File 'lib/utilrb/common.rb', line 50 def self.require_ext(name) if UTILRB_EXT_MODE yield if block_given? elsif name STDERR.puts "Utilrb: not loading #{name} since the C extension is not available" end end |
.spawn(*cmdline) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/utilrb/spawn.rb', line 3 def self.spawn(*cmdline) = if cmdline.last.kind_of?(Hash) cmdline.pop else Hash.new end = Kernel. , :redirect => nil, :working_directory => nil, :nice => nil output = [:redirect] workdir = [:working_directory] read, write = IO.pipe pid = fork do if output if !output.kind_of?(IO) output_file_name = output. gsub('%p', ::Process.pid.to_s) if workdir output_file_name = File.(output_file_name, workdir) end output = File.open(output, 'a') end end if output STDERR.reopen(output) STDOUT.reopen(output) end read.close write.sync = true write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) ::Process.setpgrp if [:nice] Process.setpriority(Process::PRIO_PROCESS, 0, [:nice]) end begin if workdir Dir.chdir(workdir) end exec(*cmdline) rescue Exception => e write.write("FAILED") end end write.close if read.read == "FAILED" raise SpawnFailed, "cannot start #{cmdline.inspect}" end pid end |
.unless_ext ⇒ Object
Yields if the extension is not present This is used by Utilrb libraries to provide a Ruby version if the C extension is not loaded
35 36 37 38 39 |
# File 'lib/utilrb/common.rb', line 35 def self.unless_ext # :yield: unless UTILRB_EXT_MODE return yield if block_given? end end |