lib/ultra_config/namespace.rb in ultra_config-0.9.1 vs lib/ultra_config/namespace.rb in ultra_config-0.10.0
- old
+ new
@@ -2,10 +2,12 @@
module UltraConfig
class Namespace
class ObjectNotFoundError < StandardError; end
+ attr_reader :objects
+
def initialize(&block)
@configuration = [block]
reset
end
@@ -36,19 +38,23 @@
def reset
@objects = {}
@configuration.each { |config| self.instance_eval(&config) }
end
- def to_s
- objs = []
+ def to_h
+ hash = {}
+ @objects.each do |name, object|
+ if object.is_a?(Config)
+ hash[name] = object.value
+ else
+ hash[name] = object.to_h
+ end
+ end
- output = '{ '
- @objects.each { |name, object| objs << "#{name}: #{object.to_s}" }
- output << objs.join(', ')
- output << ' }'
+ hash
end
- def to_h
+ def to_sanitized_h
hash = {}
@objects.each do |name, object|
if object.is_a?(Config)
object.sanitize? ? hash[name] = '*****' : hash[name] = object.value
else
\ No newline at end of file