class Skeevy::Instance

Attributes

cutter[R]
engine[R]

Public Class Methods

new(identifier:, engine: nil, cutter: nil, filters: [] ) click to toggle source
# File lib/skeevy/instance.rb, line 6
def initialize(identifier:,
               engine: nil,
               cutter: nil,
               filters: []
)
  raise(ArgumentError, "identifier must be a Symbol") unless identifier.is_a?(Symbol)
  raise(ArgumentError, "engine #{engine} is not a Skeevy Engine!") unless engine.is_a?(Skeevy::Engine) || engine.nil?
  raise(ArgumentError, "cutter #{cutter} is not a Skeevy Cutter!") unless cutter.is_a?(Skeevy::Cutter) || cutter.nil?
  raise(ArgumentError, "filters must be an array") unless filters.is_a?(Array)
  @cutter = cutter || Skeevy::Cutters::StandardKey.new(instance: self)
  @engine = engine || Skeevy::Engines::SymbolicHash.new(instance: self)
  @filters = filters
  @cutter.instance ||= self
  @engine.instance ||= self
  @identifier = identifier
end

Public Instance Methods

add_filter(filter:) click to toggle source
# File lib/skeevy/instance.rb, line 58
def add_filter(filter:)
  @filters << filter
end
container_key(hash:, ns:) click to toggle source
# File lib/skeevy/instance.rb, line 27
def container_key(hash:, ns:)
  @cutter.cut(hash: hash, ns: ns, object: nil)
end
delete!(key:) click to toggle source
# File lib/skeevy/instance.rb, line 50
def delete!(key:)
  @engine.delete!(key: key)
end
exist?(key:) click to toggle source
# File lib/skeevy/instance.rb, line 46
def exist?(key:)
  @engine.exist?(key: key)
end
object_key(hash:, ns:, object:) click to toggle source
# File lib/skeevy/instance.rb, line 23
def object_key(hash:, ns:, object:)
  @cutter.cut(hash: hash, ns: ns, object: object)
end
read(key:) click to toggle source
# File lib/skeevy/instance.rb, line 31
def read(key:)
  content = @engine.read(key: key)
  @filters.reverse.each do |f|
    content = f.filter_read(content: content)
  end
  content
end
to_s() click to toggle source
# File lib/skeevy/instance.rb, line 54
def to_s
  { identifier: @identifier, engine: @engine, cutter: @cutter}.to_s
end
write!(key:, content:) click to toggle source
# File lib/skeevy/instance.rb, line 39
def write!(key:, content:)
  @filters.each do |f|
    content = f.filter_write(content: content)
  end
  @engine.write!(key: key, content: content)
end