lib/prezzo/context.rb in prezzo-0.5.1 vs lib/prezzo/context.rb in prezzo-1.0.0.pre.rc
- old
+ new
@@ -1,37 +1,23 @@
-require "hanami-validations"
-
module Prezzo
- module Context
- def self.included(base)
- base.class_eval do
- base.include(Hanami::Validations)
- end
- end
+ class Context
+ include ParamsDSL
- def valid?
- validation.success?
+ def initialize(attributes)
+ @attributes = attributes
end
- def errors
- validation.errors
- end
-
def fetch(key, default = nil)
- if default.nil?
- attributes.fetch(key)
+ value = @attributes.fetch(key, default)
+
+ if value.is_a?(Hash)
+ Class.new(Context).new(value)
else
- attributes.fetch(key, default) || default
+ value
end
end
- def attributes
- validation.output
- end
-
- private
-
- def validation
- @_validation ||= validate
+ def context
+ self
end
end
end