Class: Foxy::Repository
Instance Attribute Summary collapse
-
#class_key ⇒ Object
readonly
Returns the value of attribute class_key.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#pk ⇒ Object
readonly
Returns the value of attribute pk.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #all ⇒ Object
- #create(entity) ⇒ Object
- #destroy(entity) ⇒ Object
- #destroy_all ⇒ Object
- #find(id) ⇒ Object
- #find_or_create(entity) ⇒ Object
-
#initialize(collection: nil, pk: :id, storage: Foxy::Storages::Yaml, model: true, class_key: :class) ⇒ Repository
constructor
A new instance of Repository.
- #save(entity) ⇒ Object
- #update(entity, attrs) ⇒ Object
- #where(query = {}) ⇒ Object
Constructor Details
#initialize(collection: nil, pk: :id, storage: Foxy::Storages::Yaml, model: true, class_key: :class) ⇒ Repository
Returns a new instance of Repository.
9 10 11 12 13 14 15 |
# File 'lib/foxy/repository.rb', line 9 def initialize(collection: nil, pk: :id, storage: Foxy::Storages::Yaml, model: true, class_key: :class) @collection = collection || class_name.downcase @pk = pk @storage = storage @model = model == true ? find_model : model @class_key = class_key end |
Instance Attribute Details
#class_key ⇒ Object (readonly)
Returns the value of attribute class_key.
7 8 9 |
# File 'lib/foxy/repository.rb', line 7 def class_key @class_key end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
7 8 9 |
# File 'lib/foxy/repository.rb', line 7 def collection @collection end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/foxy/repository.rb', line 7 def model @model end |
#pk ⇒ Object (readonly)
Returns the value of attribute pk.
7 8 9 |
# File 'lib/foxy/repository.rb', line 7 def pk @pk end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
7 8 9 |
# File 'lib/foxy/repository.rb', line 7 def storage @storage end |
Instance Method Details
#all ⇒ Object
25 26 27 |
# File 'lib/foxy/repository.rb', line 25 def all deserialize_collection store.all end |
#create(entity) ⇒ Object
33 34 35 |
# File 'lib/foxy/repository.rb', line 33 def create(entity) deserialize create! serialize entity end |
#destroy(entity) ⇒ Object
45 46 47 |
# File 'lib/foxy/repository.rb', line 45 def destroy(entity) destroy! serialize entity end |
#destroy_all ⇒ Object
49 50 51 |
# File 'lib/foxy/repository.rb', line 49 def destroy_all store.destroy_all end |
#find(id) ⇒ Object
21 22 23 |
# File 'lib/foxy/repository.rb', line 21 def find(id) deserialize find! id end |
#find_or_create(entity) ⇒ Object
17 18 19 |
# File 'lib/foxy/repository.rb', line 17 def find_or_create(entity) deserialize find_or_create! serialize entity end |
#save(entity) ⇒ Object
41 42 43 |
# File 'lib/foxy/repository.rb', line 41 def save(entity) deserialize save! serialize entity end |
#update(entity, attrs) ⇒ Object
37 38 39 |
# File 'lib/foxy/repository.rb', line 37 def update(entity, attrs) deserialize update! (serialize entity), attrs end |
#where(query = {}) ⇒ Object
29 30 31 |
# File 'lib/foxy/repository.rb', line 29 def where(query={}) deserialize_collection where!(query) end |