lib/appfuel/validation.rb in appfuel-0.5.16 vs lib/appfuel/validation.rb in appfuel-0.6.1
- old
+ new
@@ -1,11 +1,13 @@
require_relative 'validation/validator'
require_relative 'validation/validator_pipe'
module Appfuel
module Validation
+ extend Appfuel::Application::FeatureHelper
class << self
+
# Dsl used create and register validators in the app container. The key
# needs to be the fully qualified feature or global.
#
#
# @example define 'global.foo' do
@@ -26,9 +28,23 @@
def define(name, opts = {}, &block)
key, basename = build_validator_key(name)
container = Appfuel.app_container
validator = build_validator(basename, opts, &block)
container.register(key, validator)
+ end
+
+ def load_schema(key)
+ feature = extract_feature_name(key)
+ container = Appfuel.app_container
+ key, _basename = build_validator_key(key)
+ unless feature_initialized?(feature)
+ initialize_feature(feature)
+ end
+
+ unless container.key?(key)
+ fail "Could not load validator key #{key}"
+ end
+ container[key]
end
# Turns the block of code given into a Dry::Validation schema or formi
# which is then used to create our validator.
#