Module: Rails::Mongomatic::Support

Included in:
Mongomatic::Base
Defined in:
lib/rails/mongomatic/support.rb

Defined Under Namespace

Modules: ClassMethods, Errors

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
# File 'lib/rails/mongomatic/support.rb', line 4

def self.included(base)
  base.extend ClassMethods
  ::Mongomatic::Errors.send(:include, Errors)
end

Instance Method Details

#merge!(hash) ⇒ Object



9
10
11
12
13
# File 'lib/rails/mongomatic/support.rb', line 9

def merge!(hash)
  return true unless hash
  merge(hash)
  update
end

#upsertObject



15
16
17
18
19
20
21
# File 'lib/rails/mongomatic/support.rb', line 15

def upsert
  if new?
    insert
  else
    update
  end
end

#upsert!Object



23
24
25
26
27
28
29
# File 'lib/rails/mongomatic/support.rb', line 23

def upsert!
  if new?
    insert!
  else
    update!
  end
end