lib/dry/schema/messages/namespaced.rb in dry-schema-0.1.1 vs lib/dry/schema/messages/namespaced.rb in dry-schema-0.2.0
- old
+ new
@@ -13,15 +13,19 @@
# @api private
attr_reader :root
# @api private
+ attr_reader :call_opts
+
+ # @api private
def initialize(namespace, messages)
super()
@namespace = namespace
@messages = messages
@root = messages.root
+ @call_opts = { namespace: namespace }.freeze
end
# Get a message for the given key and its options
#
# @param [Symbol] key
@@ -32,10 +36,16 @@
# @api public
def get(key, options = {})
messages.get(key, options)
end
+ # @api public
+ def call(key, options = {})
+ super(key, options.empty? ? call_opts : options.merge(call_opts))
+ end
+ alias_method :[], :call
+
# Check if given key is defined
#
# @return [Boolean]
#
# @api public
@@ -43,10 +53,15 @@
messages.key?(key, *args)
end
# @api private
def lookup_paths(tokens)
- super(tokens.merge(root: "#{root}.rules.#{namespace}")) + super
+ super(tokens.merge(root: "#{tokens[:root]}.#{namespace}")) + super
+ end
+
+ def rule_lookup_paths(tokens)
+ base_paths = messages.rule_lookup_paths(tokens)
+ base_paths.map { |key| key.gsub("dry_schema", "dry_schema.#{namespace}") } + base_paths
end
end
end
end
end