lib/rasti/form.rb in rasti-form-1.0.0 vs lib/rasti/form.rb in rasti-form-1.0.1

- old
+ new

@@ -7,10 +7,12 @@ extend MultiRequire require_relative_pattern 'form/*' require_relative_pattern 'form/types/*' + include Validable + class << self def [](attributes) Class.new(self) do attributes.each do |name, type, options={}| @@ -83,11 +85,11 @@ attrs.each do |name, value| begin if self.class.attributes.key? name write_attribute name, value else - errors[name] << 'Unexpected attribute' + errors[name] << 'unexpected attribute' end rescue CastError => error errors[name] << error.message @@ -133,28 +135,9 @@ def fetch(attribute) attribute.to_s.split('.').inject(self) do |target, attr_name| target.nil? ? nil : target.public_send(attr_name) end - end - - def validate! - validate - raise ValidationError.new(errors) unless errors.empty? - end - - def validate - end - - def errors - @errors ||= Hash.new { |hash, key| hash[key] = [] } - end - - def assert(key, condition, message) - return true if condition - - errors[key] << message - false end def assert_present(attribute) assert attribute, !fetch(attribute).nil?, 'not present' end \ No newline at end of file