Class: Skeevy::Instance
- Inherits:
-
Object
- Object
- Skeevy::Instance
- Defined in:
- lib/skeevy/instance.rb
Instance Attribute Summary collapse
-
#cutter ⇒ Object
readonly
Returns the value of attribute cutter.
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
- #container_key(hash:, ns:) ⇒ Object
- #delete!(key:) ⇒ Object
- #exist?(key:) ⇒ Boolean
-
#initialize(identifier:, engine: nil, cutter: nil) ⇒ Instance
constructor
A new instance of Instance.
- #object_key(hash:, ns:, object:) ⇒ Object
- #read(key:) ⇒ Object
- #to_s ⇒ Object
- #write!(key:, content:) ⇒ Object
Constructor Details
#initialize(identifier:, engine: nil, cutter: nil) ⇒ Instance
Returns a new instance of Instance.
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
#cutter ⇒ Object (readonly)
Returns the value of attribute cutter.
4 5 6 |
# File 'lib/skeevy/instance.rb', line 4 def cutter @cutter end |
#engine ⇒ Object (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
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_s ⇒ Object
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 |