module Ymlenv
Constants
- VERSION
Public Class Methods
convert_body()
click to toggle source
# File lib/ymlenv.rb, line 11 def convert_body @options[:body] = File.read(@options[:file]) if define_file? ENV.each_pair do |ek, ev| @options[:body] = @options[:body].gsub(/\$[{]?#{ek}[}]?/, ev) end end
debug()
click to toggle source
# File lib/ymlenv.rb, line 69 def debug @options[:debug] end
define_file?()
click to toggle source
# File lib/ymlenv.rb, line 57 def define_file? !@options[:file].nil? end
enable_symborize()
click to toggle source
# File lib/ymlenv.rb, line 65 def enable_symborize @options[:symborize] end
exec_with_format()
click to toggle source
# File lib/ymlenv.rb, line 41 def exec_with_format convert_body if @options[:json] require 'json' load_yaml.to_json else if write_to_file? File.write @options[:file], @options[:body] "You yaml file #{@options[:file]} has been overwritten." else @options[:body] end end end
load_yaml()
click to toggle source
# File lib/ymlenv.rb, line 18 def load_yaml require "yaml" symbolize_all_keys YAML.load(@options[:body]) end
options()
click to toggle source
# File lib/ymlenv.rb, line 7 def options @options end
symbolize_all_keys(obj)
click to toggle source
# File lib/ymlenv.rb, line 23 def symbolize_all_keys(obj) return obj unless enable_symborize case obj.class.to_s when 'Hash' obj.keys.each do |key| obj[(key.to_sym rescue key) || key] = symbolize_all_keys(obj.delete(key)) end obj when 'Array' obj.map! do |elem| symbolize_all_keys elem end obj else obj end end
write_to_file?()
click to toggle source
# File lib/ymlenv.rb, line 61 def write_to_file? define_file? && @options[:overwrite] end