Module: Rego
- Defined in:
- lib/rego.rb,
lib/rego/_lib.rb,
lib/rego/utils.rb
Constant Summary collapse
- Version =
'3.2.1'
- 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
- .relative_path(path, options = {}) ⇒ 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 self.dependencies { 'main' => ['main', ' ~> 6.3.0'], 'map' => ['map', ' ~> 6.6.0'], 'listen' => ['listen', ' ~> 3.8.0'] } 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 self.libdir(*args, &block) @libdir ||= File.basename(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 self.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 self.realpath(path) Pathname.new(path).realpath.to_s end |
.relative_path(path, options = {}) ⇒ Object
6 7 8 9 10 |
# File 'lib/rego/utils.rb', line 6 def self.relative_path(path, = {}) path = File.(String(path)) relative = File.(String([:from])) Pathname.new(path).relative_path_from(Pathname.new(relative)).to_s end |
.say(phrase, *args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rego/utils.rb', line 30 def self.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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rego/utils.rb', line 12 def self.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 |