Class: StoresInMongo::MongoStore
- Inherits:
-
Object
- Object
- StoresInMongo::MongoStore
- Defined in:
- lib/stores_in_mongo/mongo_store.rb
Instance Attribute Summary collapse
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #find_or_initialize_for(owner) ⇒ Object
-
#initialize(klass, foreign_key) ⇒ MongoStore
constructor
A new instance of MongoStore.
Constructor Details
#initialize(klass, foreign_key) ⇒ MongoStore
Returns a new instance of MongoStore.
5 6 7 8 |
# File 'lib/stores_in_mongo/mongo_store.rb', line 5 def initialize(klass, foreign_key) @klass = klass @foreign_key = foreign_key end |
Instance Attribute Details
#foreign_key ⇒ Object (readonly)
Returns the value of attribute foreign_key.
3 4 5 |
# File 'lib/stores_in_mongo/mongo_store.rb', line 3 def foreign_key @foreign_key end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/stores_in_mongo/mongo_store.rb', line 3 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/stores_in_mongo/mongo_store.rb', line 3 def name @name end |
Instance Method Details
#find_or_initialize_for(owner) ⇒ Object
10 11 12 |
# 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 |