lib/secros.rb in secros-0.1.8 vs lib/secros.rb in secros-0.2.0
- old
+ new
@@ -5,23 +5,31 @@
def initialize(path)
@root_path = path
end
- def value(key)
- secrets[:values][normalized_key(key)]
+ def values
+ @values ||= secrets[:values]
end
- def file(key)
- File.join(secret_files_path, secrets[:files][normalized_key(key)])
+ def files
+ @files ||= deep_apply_block(secrets[:files]) do |file|
+ File.join(secret_files_path, file)
+ end
end
private
def secrets
@secrets ||= YAML.load(File.read(secrets_path)).deep_symbolize_keys
end
- def normalized_key(key)
- key.to_s.to_sym
+ def deep_apply_block(obj, &block)
+ if obj.is_a?(Array)
+ obj.map { |x| block.call(x) }
+ elsif obj.is_a?(Hash)
+ Hash[obj.map { |k, v| [k, block.call(v)] }]
+ else
+ block.call(obj)
+ end
end
end