class StoresInMongo::MongoStore

Attributes

foreign_key[R]
klass[R]
name[R]

Public Class Methods

new(klass, foreign_key) click to toggle source
# File lib/stores_in_mongo/mongo_store.rb, line 5
def initialize(klass, foreign_key)
  @klass = klass
  @foreign_key = foreign_key      
end

Public Instance Methods

find_or_initialize_for(owner) click to toggle source
# File lib/stores_in_mongo/mongo_store.rb, line 10
def find_or_initialize_for(owner)
  owner[@foreign_key].present? && @klass.where(id: owner[@foreign_key]).first || @klass.new
end