Module: Gricer::Mongoid::Touch

Extended by:
ActiveSupport::Concern
Included in:
Session
Defined in:
lib/gricer/mongoid/touch.rb

Instance Method Summary collapse

Instance Method Details

#touch(at_field = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gricer/mongoid/touch.rb', line 6

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
end

#touch!(at_field = nil, force_fail = false) ⇒ Object

Raises:

  • (Errors::DocumentNotUpdated)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gricer/mongoid/touch.rb', line 20

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
  else
    raise Errors::FrozenInstance, self
  end
end