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



16
17
18
# File 'lib/w-stdlib/prelude.rb', line 16

def error(msg, pref='[!] ')
  STDERR.puts pref + msg
end

#fatal(msg, code = 1, pref = '[!] ') ⇒ Object



7
8
9
10
# File 'lib/w-stdlib/prelude.rb', line 7

def fatal(msg, code=1, pref='[!] ')
  STDERR.puts pref + msg
  exit code
end

#get_json(url) ⇒ Object



33
34
35
# File 'lib/w-stdlib/prelude.rb', line 33

def get_json(url)
  HTTP.get(url).to_s.from_json
end

#home_join(*paths) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/w-stdlib/prelude.rb', line 53

def home_join(*paths)
  home = ENV['HOME']
  if paths.empty?
    home
  else
    File.join home, *paths
  end
end

#info(msg, pref = '[+] ') ⇒ Object



12
13
14
# File 'lib/w-stdlib/prelude.rb', line 12

def info(msg, pref='[+] ')
  STDERR.puts pref + msg
end

#json_file(name) ⇒ Object



20
21
22
# File 'lib/w-stdlib/prelude.rb', line 20

def json_file(name)
  JSON.parse File.read(name)
end

#read_json(path) ⇒ Object



24
25
26
# File 'lib/w-stdlib/prelude.rb', line 24

def read_json(path)
  json_file(path)
end

#read_lines(path) ⇒ Object



37
38
39
# File 'lib/w-stdlib/prelude.rb', line 37

def read_lines(path)
  File.readlines(path).map(&:strip).reject(&:empty?)
end

#stdin_jsonObject



45
46
47
# File 'lib/w-stdlib/prelude.rb', line 45

def stdin_json
  $stdin.read.from_json
end

#stdin_linesObject



41
42
43
# File 'lib/w-stdlib/prelude.rb', line 41

def stdin_lines
  $stdin.lines.map(&:strip).reject(&:empty?)
end

#write_json(path, o, pretty = false) ⇒ Object



28
29
30
31
# File 'lib/w-stdlib/prelude.rb', line 28

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



49
50
51
# File 'lib/w-stdlib/prelude.rb', line 49

def write_lines(path, lines)
  File.write(path, lines.join("\n"))
end