Class: Pgai::Encryption::ReferenceStore

Inherits:
Object
  • Object
show all
Defined in:
lib/pgai/encryption/reference_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil) ⇒ ReferenceStore

Returns a new instance of ReferenceStore.



6
7
8
9
# File 'lib/pgai/encryption/reference_store.rb', line 6

def initialize(path: nil)
  path ||= Pgai.config_dir.join("op_ref")
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/pgai/encryption/reference_store.rb', line 26

def path
  @path
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pgai/encryption/reference_store.rb', line 22

def exists?
  File.exist?(@path) && !read.empty?
end

#readObject



16
17
18
19
20
# File 'lib/pgai/encryption/reference_store.rb', line 16

def read
  return nil unless File.exist?(@path)

  File.read(@path).strip
end

#write(reference) ⇒ Object



11
12
13
14
# File 'lib/pgai/encryption/reference_store.rb', line 11

def write(reference)
  ensure_directory_exists
  File.write(@path, reference)
end