Module: MongoPersist::ClassMethods

Defined in:
lib/mongo_persist/base.rb

Instance Method Summary collapse

Instance Method Details

#default_collection_nameObject



71
72
73
# File 'lib/mongo_persist/base.rb', line 71

def default_collection_name
  to_s.downcase.pluralize
end

#from_mongo_hash(h) ⇒ Object



79
80
81
82
83
# File 'lib/mongo_persist/base.rb', line 79

def from_mongo_hash(h)
  res = new_with_nil_args.tap { |x| x.from_mongo_hash(h) }
  res.after_mongo_load if res.respond_to?(:after_mongo_load)
  res
end

#mongo_connection(ops) ⇒ Object



84
85
86
# File 'lib/mongo_persist/base.rb', line 84

def mongo_connection(ops)
  ops.each { |k,v| send("#{k}=",v) }
end

#new_with_nil_argsObject



75
76
77
78
# File 'lib/mongo_persist/base.rb', line 75

def new_with_nil_args
  args = (1..(instance_method(:initialize).arity)).map { |x| nil }
  new(*args)
end