Class: Skeevy::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/skeevy/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, engine: nil, cutter: nil) ⇒ Instance

Returns a new instance of Instance.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/skeevy/instance.rb', line 6

def initialize(identifier:,
               engine: nil,
               cutter: nil)
  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?
  @cutter = cutter || Skeevy::Cutters::StandardKey.new(instance: self)
  @engine = engine || Skeevy::Engines::SymbolicHash.new(instance: self)
  @cutter.instance ||= self
  @engine.instance ||= self
  @identifier = identifier
end

Instance Attribute Details

#cutterObject (readonly)

Returns the value of attribute cutter.



4
5
6
# File 'lib/skeevy/instance.rb', line 4

def cutter
  @cutter
end

#engineObject (readonly)

Returns the value of attribute engine.



4
5
6
# File 'lib/skeevy/instance.rb', line 4

def engine
  @engine
end

Instance Method Details

#container_key(hash:, ns:) ⇒ Object



23
24
25
# File 'lib/skeevy/instance.rb', line 23

def container_key(hash:, ns:)
  @cutter.cut(hash: hash, ns: ns, object: nil)
end

#delete!(key:) ⇒ Object



39
40
41
# File 'lib/skeevy/instance.rb', line 39

def delete!(key:)
  @engine.delete!(key: key)
end

#exist?(key:) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/skeevy/instance.rb', line 35

def exist?(key:)
  @engine.exist?(key: key)
end

#object_key(hash:, ns:, object:) ⇒ Object



19
20
21
# File 'lib/skeevy/instance.rb', line 19

def object_key(hash:, ns:, object:)
  @cutter.cut(hash: hash, ns: ns, object: object)
end

#read(key:) ⇒ Object



27
28
29
# File 'lib/skeevy/instance.rb', line 27

def read(key:)
  @engine.read(key: key)
end

#to_sObject



43
44
45
# File 'lib/skeevy/instance.rb', line 43

def to_s
  { identifier: @identifier, engine: @engine, cutter: @cutter}.to_s
end

#write!(key:, content:) ⇒ Object



31
32
33
# File 'lib/skeevy/instance.rb', line 31

def write!(key:, content:)
  @engine.write!(key: key, content: content)
end