lib/apimaster/mapper.rb in apimaster-0.0.3 vs lib/apimaster/mapper.rb in apimaster-0.0.4
- old
+ new
@@ -18,11 +18,15 @@
save_with_hash hash, :patch
end
def save_with_hash hash, method
from_hash hash, method
- save
+ if valid?
+ save
+ else
+ raise InvalidFieldError.new(class_name, errors.keys.first)
+ end
self
end
def from_hash(hash, method = :all)
data = {}
@@ -61,9 +65,13 @@
else
raise "Dataset #{self.class} has no method with the name of #{field}"
end
end
record
+ end
+
+ def class_name
+ @class_name ||= self.class.to_s.split("::").last
end
class << self
OPTION_TYPES = [:accessor, :required, :optional]