Class: DeepStore::Repository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/deep_store/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Repository

Returns a new instance of Repository.



10
11
12
13
14
15
16
17
# File 'lib/deep_store/repository.rb', line 10

def initialize(data = {})
  @data           = data
  @adapter        = data.fetch(:adapter, DeepStore.adapter)
  @bucket         = data.fetch(:bucket, DeepStore.settings.bucket)
  @codec          = data.fetch(:codec)
  @resource_class = data.fetch(:resource_class)
  @dao            = DAO.new(adapter: @adapter, bucket: @bucket, codec: @codec)
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/deep_store/repository.rb', line 5

def adapter
  @adapter
end

#bucketObject (readonly)

Returns the value of attribute bucket.



6
7
8
# File 'lib/deep_store/repository.rb', line 6

def bucket
  @bucket
end

#codecObject (readonly)

Returns the value of attribute codec.



6
7
8
# File 'lib/deep_store/repository.rb', line 6

def codec
  @codec
end

#daoObject (readonly)

Returns the value of attribute dao.



6
7
8
# File 'lib/deep_store/repository.rb', line 6

def dao
  @dao
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



6
7
8
# File 'lib/deep_store/repository.rb', line 6

def resource_class
  @resource_class
end

Instance Method Details

#destroy(key) ⇒ Object



31
32
33
# File 'lib/deep_store/repository.rb', line 31

def destroy(key)
  Operations::DestroyOperation.new(dao, resource_class, key: key).result
end

#find(key) ⇒ Object



19
20
21
# File 'lib/deep_store/repository.rb', line 19

def find(key)
  Operations::FindQuery.new(dao, resource_class, key: key).result
end

#save(resource) ⇒ Object



27
28
29
# File 'lib/deep_store/repository.rb', line 27

def save(resource)
  Operations::SaveOperation.new(dao, resource_class, resource: resource).result
end

#where(query = {}) ⇒ Object



23
24
25
# File 'lib/deep_store/repository.rb', line 23

def where(query = {})
  Operations::WhereQuery.new(dao, resource_class, query: query).result
end