Class: Repository::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/repository/storage.rb

Overview

Storage is an abstract base class for the backing storage area of a Repository. Concrete implementations include Stash (for in-memory storage).

Direct Known Subclasses

StashStorage

Defined Under Namespace

Classes: Unidentified, Unimplemented

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass = nil) ⇒ Storage

Returns a new instance of Storage.



18
19
20
# File 'lib/repository/storage.rb', line 18

def initialize(klass = nil)
  @klass = klass
end

Class Method Details

.for_class(klass) ⇒ Object



14
15
16
# File 'lib/repository/storage.rb', line 14

def self.for_class(klass)
  StashStorage.new(klass)
end

Instance Method Details

#[](key) ⇒ Object

alias for get



46
47
48
# File 'lib/repository/storage.rb', line 46

def [](key)
  get(key)
end

#clearObject

Raises:



26
27
28
# File 'lib/repository/storage.rb', line 26

def clear
  raise Unimplemented
end

#find(arg) ⇒ Object

Finds all stashed objects that match the argument. Argument is either a criterion, an key, or an array of either keys or criteria. Returns an array of objects.



53
54
55
56
57
58
59
60
61
# File 'lib/repository/storage.rb', line 53

def find(arg)
  if arg.is_a? Criterion
    find_by_criterion(arg)
  elsif arg.is_a? Array
    find_by_keys(arg)
  else
    find_by_keys([arg])
  end
end

#get(key) ⇒ Object

get an object by key



41
42
43
# File 'lib/repository/storage.rb', line 41

def get(key)
  find_by_keys([key]).first
end

#sizeObject

Raises:



22
23
24
# File 'lib/repository/storage.rb', line 22

def size
  raise Unimplemented
end