Class: Railscope::Storage::Base

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

Direct Known Subclasses

Database, RedisBuffer

Instance Method Summary collapse

Instance Method Details

#all(filters: {}, page: 1, per_page: 25, displayable_only: true) ⇒ Array<EntryData>

List entries with optional filters

Parameters:

  • filters (Hash) (defaults to: {}) —

    optional filters (:type, :tag, :batch_id, :family_hash)

  • page (Integer) (defaults to: 1) —

    page number (1-indexed)

  • per_page (Integer) (defaults to: 25) —

    entries per page

  • displayable_only (Boolean) (defaults to: true) —

    only return displayable entries

Returns:

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/railscope/storage/base.rb', line 34

def all(filters: {}, page: 1, per_page: 25, displayable_only: true)
  raise NotImplementedError, "#{self.class}#all must be implemented"
end

#count(filters: {}, displayable_only: true) ⇒ Integer

Count entries with optional filters

Parameters:

  • filters (Hash) (defaults to: {}) —

    optional filters

  • displayable_only (Boolean) (defaults to: true) —

    only count displayable entries

Returns:

  • (Integer) —

    count of entries

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/railscope/storage/base.rb', line 42

def count(filters: {}, displayable_only: true)
  raise NotImplementedError, "#{self.class}#count must be implemented"
end

#destroy_all! ⇒ Integer

Delete all entries

Returns:

  • (Integer) —

    number of deleted entries

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/railscope/storage/base.rb', line 71

def destroy_all!
  raise NotImplementedError, "#{self.class}#destroy_all! must be implemented"
end

#destroy_expired! ⇒ Integer

Delete expired entries (older than retention_days)

Returns:

  • (Integer) —

    number of deleted entries

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/railscope/storage/base.rb', line 77

def destroy_expired!
  raise NotImplementedError, "#{self.class}#destroy_expired! must be implemented"
end

#family_count(family_hash) ⇒ Integer

Count entries with the same family hash

Parameters:

  • family_hash (String) —

    the family hash

Returns:

  • (Integer) —

    count of entries

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/railscope/storage/base.rb', line 65

def family_count(family_hash)
  raise NotImplementedError, "#{self.class}#family_count must be implemented"
end

#find(uuid) ⇒ EntryData?

Find an entry by UUID

Parameters:

  • uuid (String) —

    the entry UUID

Returns:

  • (EntryData, nil) —

    the entry or nil if not found

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/railscope/storage/base.rb', line 16

def find(uuid)
  raise NotImplementedError, "#{self.class}#find must be implemented"
end

#find!(uuid) ⇒ EntryData

Find an entry by UUID, raising if not found

Parameters:

  • uuid (String) —

    the entry UUID

Returns:

Raises:



24
25
26
# File 'lib/railscope/storage/base.rb', line 24

def find!(uuid)
  find(uuid) || raise(RecordNotFound, "Entry not found: #{uuid}")
end

#for_batch(batch_id) ⇒ Array<EntryData>

Get all entries in a batch

Parameters:

  • batch_id (String) —

    the batch UUID

Returns:

  • (Array<EntryData>) —

    list of entries in the batch

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/railscope/storage/base.rb', line 49

def for_batch(batch_id)
  raise NotImplementedError, "#{self.class}#for_batch must be implemented"
end

#for_family(family_hash, page: 1, per_page: 25) ⇒ Array<EntryData>

Get all entries with the same family hash

Parameters:

  • family_hash (String) —

    the family hash

  • page (Integer) (defaults to: 1) —

    page number

  • per_page (Integer) (defaults to: 25) —

    entries per page

Returns:

  • (Array<EntryData>) —

    list of entries with same family

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/railscope/storage/base.rb', line 58

def for_family(family_hash, page: 1, per_page: 25)
  raise NotImplementedError, "#{self.class}#for_family must be implemented"
end

#ready? ⇒ Boolean

Check if storage is available and ready

Returns:

  • (Boolean) —

    true if ready

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/railscope/storage/base.rb', line 83

def ready?
  raise NotImplementedError, "#{self.class}#ready? must be implemented"
end

#write(attributes) ⇒ EntryData

Write a new entry

Parameters:

  • attributes (Hash) —

    entry attributes

Returns:

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/railscope/storage/base.rb', line 9

def write(attributes)
  raise NotImplementedError, "#{self.class}#write must be implemented"
end