Top Level Namespace
Defined Under Namespace
Modules: ArrayExt, FileExt, HashExt, IAM, IOExt, IPv4NetExt, IamExt, ObjectExt, OpenSSLExt, Processes, QueryParamsMixin, StringExt, URI
Classes: CaseInsensitiveHash, GithubClient, Glob
Instance Method Summary
collapse
Instance Method Details
#error(msg, pref = '[!] ') ⇒ Object
22
23
24
|
# File 'lib/w-stdlib/prelude.rb', line 22
def error(msg, pref='[!] ')
STDERR.puts pref + msg
end
|
#fatal(msg, code = 1, pref = '[!] ') ⇒ Object
13
14
15
16
|
# File 'lib/w-stdlib/prelude.rb', line 13
def fatal(msg, code=1, pref='[!] ')
STDERR.puts pref + msg
exit code
end
|
#get_json(url) ⇒ Object
39
40
41
|
# File 'lib/w-stdlib/prelude.rb', line 39
def get_json(url)
HTTP.get(url).to_s.from_json
end
|
#home_join(*paths) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/w-stdlib/prelude.rb', line 59
def home_join(*paths)
home = ENV['HOME']
if paths.empty?
home
else
File.join home, *paths
end
end
|
#info(msg, pref = '[+] ') ⇒ Object
18
19
20
|
# File 'lib/w-stdlib/prelude.rb', line 18
def info(msg, pref='[+] ')
STDERR.puts pref + msg
end
|
#json_file(name) ⇒ Object
26
27
28
|
# File 'lib/w-stdlib/prelude.rb', line 26
def json_file(name)
JSON.parse File.read(name)
end
|
#read_json(path) ⇒ Object
30
31
32
|
# File 'lib/w-stdlib/prelude.rb', line 30
def read_json(path)
json_file(path)
end
|
#read_lines(path) ⇒ Object
43
44
45
|
# File 'lib/w-stdlib/prelude.rb', line 43
def read_lines(path)
File.readlines(path).map(&:strip).reject(&:empty?)
end
|
#stdin_json ⇒ Object
51
52
53
|
# File 'lib/w-stdlib/prelude.rb', line 51
def stdin_json
$stdin.read.from_json
end
|
#stdin_lines ⇒ Object
47
48
49
|
# File 'lib/w-stdlib/prelude.rb', line 47
def stdin_lines
$stdin.lines.map(&:strip).reject(&:empty?)
end
|
#write_json(path, o, pretty = false) ⇒ Object
34
35
36
37
|
# File 'lib/w-stdlib/prelude.rb', line 34
def write_json(path, o, pretty=false)
json = pretty ? JSON.pretty_generate(o) : o.to_json
File.write(path, json)
end
|
#write_lines(path, lines) ⇒ Object
55
56
57
|
# File 'lib/w-stdlib/prelude.rb', line 55
def write_lines(path, lines)
File.write(path, lines.join("\n"))
end
|