Module: Kerbi::Mixins::Mixer
- Included in:
- Kerbi::Mixer, Utils::Values::ErbWrapper
- Defined in:
- lib/mixins/mixer.rb
Instance Method Summary collapse
-
#b64dec(string) ⇒ String
Encoded string.
-
#b64enc(string) ⇒ String
Encoded string.
-
#b64enc_file(fname) ⇒ String
Encoded string.
-
#embed(dict, indent: 25) ⇒ String
Encoded string.
-
#embed_array(dicts, indent: 25) ⇒ String
Encoded string.
- #http_descriptor_to_url(**opts) ⇒ Object
Instance Method Details
#b64dec(string) ⇒ String
Returns encoded string.
45 46 47 48 49 50 51 |
# File 'lib/mixins/mixer.rb', line 45 def b64dec(string) if string Base64.decode64(string).strip else '' end end |
#b64enc(string) ⇒ String
Returns encoded string.
35 36 37 38 39 40 41 |
# File 'lib/mixins/mixer.rb', line 35 def b64enc(string) if string Base64.strict_encode64(string) else '' end end |
#b64enc_file(fname) ⇒ String
Returns encoded string.
55 56 57 58 |
# File 'lib/mixins/mixer.rb', line 55 def b64enc_file(fname) file_contents = File.read(fname) rescue nil b64enc(file_contents) end |
#embed(dict, indent: 25) ⇒ String
Returns encoded string.
7 8 9 10 11 12 13 14 |
# File 'lib/mixins/mixer.rb', line 7 def (dict, indent: 25) _dict = dict.is_a?(Array) ? dict.first : dict raw = YAML.dump(_dict).sub("---", "") indented_lines = raw.split("\n").map do |line| line.indent(indent) end "\n#{indented_lines.join("\n")}" end |
#embed_array(dicts, indent: 25) ⇒ String
Returns encoded string.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mixins/mixer.rb', line 18 def (dicts, indent: 25) return "[]" unless dicts.present? unless dicts.is_a?(Array) raise "embed_array called with non-array #{dicts.class} #{dicts}" end raw = YAML.dump(dicts).sub("---", "") indented_lines = raw.split("\n").map do |line| line.indent(indent) end "\n#{indented_lines.join("\n")}" end |
#http_descriptor_to_url(**opts) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mixins/mixer.rb', line 66 def http_descriptor_to_url(**opts) return opts[:url] if opts[:url] if opts[:from] == 'github' base = "https://raw.githubusercontent.com" branch = opts[:branch] || 'master' project, file = (opts[:project] || opts[:id]), opts[:file] raise "Project and/or file not found" unless project && file "#{base}/#{project}/#{branch}/#{file}" end end |