Module: Popo::Utils
- Includes:
- Constants
- Defined in:
- lib/popo/utils.rb
Constant Summary
Constants included
from Constants
Constants::COLOR_GREEN, Constants::COLOR_NONE, Constants::COLOR_RED, Constants::COLOR_YELLOW, Constants::DEFAULT_CONFIG_FILE, Constants::DEFAULT_POPO_TARGET, Constants::POPORC, Constants::POPO_COMMANDS, Constants::POPO_CONFIG, Constants::POPO_DIR_KEY, Constants::POPO_KEY_VALUES, Constants::POPO_WORK_PATH, Constants::POPO_YML_FILE, Constants::POST_INSTALL_NOTE, Constants::REQUIRED_COMMANDS
Class Method Summary
collapse
Class Method Details
.colorize ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/popo/utils.rb', line 7
def self.colorize
String.class_eval do
include Popo::Constants
constants.grep(/^COLOR/).each do |c|
color = c.to_s.gsub('COLOR_','').downcase.to_sym
define_method color do
if !ENV['popo_no_color']
"#{Popo::Constants.const_get(c)}#{self}#{COLOR_NONE}"
else
self
end
end
end
end
end
|
.git_say(action, message, subitem = false) ⇒ Object
38
39
40
|
# File 'lib/popo/utils.rb', line 38
def self.git_say(action, message, subitem = false)
puts "#{subitem ? "\r->" : "\[#{action}\]"} #{message}"
end
|
.git_say_with_time(action, message) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/popo/utils.rb', line 42
def self.git_say_with_time(action, message)
git_say(action, message)
result = nil
time = Benchmark.measure { result = yield }
say "%.4fs" % time.real, :subitem
say("#{result} rows", :subitem) if result.is_a?(Integer)
result
end
|
.has_popo_config?(root_path) ⇒ Boolean
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/popo/utils.rb', line 60
def self.has_popo_config?(root_path)
popo_work_path = File.join(root_path, POPO_WORK_PATH)
popo_yml = File.join(popo_work_path, POPO_YML_FILE)
if File.exists?(popo_yml)
popo_config = YAML.load_file(popo_yml)
if popo_config.is_a?(Hash)
POPO_CONFIG.update(popo_config)
else
Error.say "#{POPO_YML_FILE} seems to be wrong."
end
else
false
end
true
end
|
.in_popo?(root_path) ⇒ Boolean
52
53
54
55
56
57
58
|
# File 'lib/popo/utils.rb', line 52
def self.in_popo?(root_path)
if !ENV.include?('popo_path')
Error.say "You must be inside popo!"
end
true
end
|
.say(message, subitem = false) ⇒ Object
25
26
27
|
# File 'lib/popo/utils.rb', line 25
def self.say(message, subitem = false)
puts "#{subitem ? " \->" : "--"} #{message}"
end
|
.say_with_time(message) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/popo/utils.rb', line 29
def self.say_with_time(message)
say(message)
result = nil
time = Benchmark.measure { result = yield }
say "%.4fs" % time.real, :subitem
say("#{result} rows", :subitem) if result.is_a?(Integer)
result
end
|