Sha256: 7dad20ab2246bf59abfdcfe973857f1b3da15afe1db9de6fe0a35c7f31aa0765
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
# encoding: UTF-8 # frozen_string_literal: true # Refinements # ======================================================================= using NRSER using NRSER::Types # Definitions # ======================================================================= # Helpful and not so helpful things. # module NRSER::Rash::Helpers include SemanticLogger::Loggable class << self def quote(value) double_quote(value) end alias_method :q, :quote # single-quote a string for bash # reaplces `'` with `'\''` def single_quote(string) "'" + string.gsub(/'/, {"'" => "'\\''"}) + "'" end alias_method :sq, :single_quote # double-quote a string for bash # replaces `"` with `\"` and `\` with `\\` def double_quote(string) '"' + string.gsub(/["\\]/, {'"' => '\"', '\\' => '\\\\'}) + '"' end alias_method :dq, :double_quote def block(start, finish, &body) $stdout.block start, finish, &body end def user name = nil, &body # if no name is provided, it just means 'not root' if name.nil? body.() if ENV['USER'] != 'root' else body.() if ENV['USER'] == name end end end # class << self end # module NRSER::Rash::Helpers
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nrser-rash-0.2.3 | lib/nrser/rash/helpers.rb |
nrser-rash-0.2.2 | lib/nrser/rash/helpers.rb |
nrser-rash-0.2.1 | lib/nrser/rash/helpers.rb |
nrser-rash-0.2.0 | lib/nrser/rash/helpers.rb |