Module: Rego
- Defined in:
- lib/rego.rb,
lib/rego/_lib.rb,
lib/rego/utils.rb
Constant Summary collapse
- Version =
'2.1.0'
- ANSI =
{ :clear => "\e[0m", :reset => "\e[0m", :erase_line => "\e[K", :erase_char => "\e[P", :bold => "\e[1m", :dark => "\e[2m", :underline => "\e[4m", :underscore => "\e[4m", :blink => "\e[5m", :reverse => "\e[7m", :concealed => "\e[8m", :black => "\e[30m", :red => "\e[31m", :green => "\e[32m", :yellow => "\e[33m", :blue => "\e[34m", :magenta => "\e[35m", :cyan => "\e[36m", :white => "\e[37m", :on_black => "\e[40m", :on_red => "\e[41m", :on_green => "\e[42m", :on_yellow => "\e[43m", :on_blue => "\e[44m", :on_magenta => "\e[45m", :on_cyan => "\e[46m", :on_white => "\e[47m" }
Class Method Summary collapse
- .dependencies ⇒ Object
- .libdir(*args, &block) ⇒ Object
- .load(*libs) ⇒ Object
- .realpath(path) ⇒ Object
- .say(phrase, *args) ⇒ Object
- .tmpdir(&block) ⇒ Object
- .version ⇒ Object
Class Method Details
.dependencies ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/rego/_lib.rb', line 8 def Rego.dependencies { 'main' => [ 'main' , ' ~> 6.0' ] , 'map' => [ 'map' , ' ~> 6.6' ] , 'rb-fsevent' => [ 'rb-fsevent' , ' ~> 0.10' ] , } end |
.libdir(*args, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rego/_lib.rb', line 16 def Rego.libdir(*args, &block) @libdir ||= File.(__FILE__).sub(/\.rb$/,'') args.empty? ? @libdir : File.join(@libdir, *args) ensure if block begin $LOAD_PATH.unshift(@libdir) block.call() ensure $LOAD_PATH.shift() end end end |
.load(*libs) ⇒ Object
30 31 32 33 |
# File 'lib/rego/_lib.rb', line 30 def Rego.load(*libs) libs = libs.join(' ').scan(/[^\s+]+/) Rego.libdir{ libs.each{|lib| Kernel.load(lib) } } end |
.realpath(path) ⇒ Object
2 3 4 |
# File 'lib/rego/utils.rb', line 2 def Rego.realpath(path) Pathname.new(path).realpath.to_s end |
.say(phrase, *args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rego/utils.rb', line 23 def Rego.say(phrase, *args) = args.last.is_a?(Hash) ? args.pop : {} [:color] = args.shift.to_s.to_sym unless args.empty? keys = .keys keys.each{|key| [key.to_s.to_sym] = .delete(key)} color = [:color] bold = .has_key?(:bold) parts = [phrase] if STDOUT.tty? parts.unshift(ANSI[color]) if color parts.unshift(ANSI[:bold]) if bold parts.push(ANSI[:clear]) if parts.size > 1 end method = [:method] || :puts send(method, parts.join) end |
.tmpdir(&block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rego/utils.rb', line 6 def Rego.tmpdir(&block) tmpdir = File.join(Dir.tmpdir, ['rego', Process.ppid.to_s, Process.pid.to_s, Thread.current.object_id.to_s].join('-') + '.d') FileUtils.mkdir_p(tmpdir) if block begin Dir.chdir(tmpdir, &block) ensure FileUtils.rm_rf(tmpdir) at_exit{ `rm -rf #{ tmpdir }` } end else tmpdir end end |