lib/mongoid/document/touch.rb in mongoid_touch-0.1.0 vs lib/mongoid/document/touch.rb in mongoid_touch-0.2.0

- old
+ new

@@ -2,46 +2,38 @@ module Mongoid module Document module Touch extend ActiveSupport::Concern - - included do - end - - module InstanceMethods - - def touch( at_field = nil ) - unless self.frozen? - to_touch = at_field || :updated_at - if self.fields.include? to_touch.to_s - return true if self.update_attribute(to_touch.to_sym, Time.now.utc) - false - else - return false - end - else + + def touch(at_field = nil) + unless self.frozen? + to_touch = at_field || :updated_at + if self.fields.include? to_touch.to_s + return true if self.update_attribute(to_touch.to_sym, Time.now.utc) false + else + return false end + else + false end - - def touch!( at_field = nil, force_fail = false ) - raise Errors::DocumentNotUpdated.new(self) if force_fail - unless self.frozen? - to_touch = at_field || :updated_at - if self.fields.include? to_touch.to_s - return true if self.update_attribute(to_touch.to_sym, Time.now.utc) - raise Errors::DocumentNotUpdated, self - else - raise Errors::MissingField.new(to_touch, self) - end + end + + def touch!(at_field = nil, force_fail = false) + raise Errors::DocumentNotUpdated.new(self) if force_fail + unless self.frozen? + to_touch = at_field || :updated_at + if self.fields.include? to_touch.to_s + return true if self.update_attribute(to_touch.to_sym, Time.now.utc) + raise Errors::DocumentNotUpdated, self else - raise Errors::FrozenInstance, self + raise Errors::MissingField.new(to_touch, self) end + else + raise Errors::FrozenInstance, self end - end - end end end