Class: ArchivePublic

Inherits:
Archive show all
Defined in:
lib/archive_public.rb

Constant Summary collapse

FILE_NAME =
'public'

Constants inherited from Archive

Archive::EXTENSION_FILE, Archive::FILE_PATH_KEYS, Archive::MODE_WRITE, Archive::ROOT_PATH_FILE

Instance Attribute Summary

Attributes inherited from Archive

#name, #path

Instance Method Summary collapse

Methods inherited from Archive

#decode, #encode, #full_name, #set_name

Constructor Details

#initializeArchivePublic

Returns a new instance of ArchivePublic.



5
6
7
# File 'lib/archive_public.rb', line 5

def initialize
  set_name(FILE_NAME)
end

Instance Method Details

#readObject



9
10
11
12
# File 'lib/archive_public.rb', line 9

def read
  file = File.open full_name
  JSON.parse(decode(file.read), symbolize_names: true)
end

#write(text) ⇒ Object



14
15
16
17
18
# File 'lib/archive_public.rb', line 14

def write(text)
  file = File.open(full_name, Archive::MODE_WRITE)
  file.puts encode JSON.generate text
  file.close
end