Class: Codebreaker::StorageInterceptor
- Inherits:
-
Object
- Object
- Codebreaker::StorageInterceptor
- Defined in:
- lib/codebreaker/storage/storage_interceptor.rb
Constant Summary collapse
- DEFAULT_PATH_TO_FILE =
"./lib/codebreaker/data/stat.yml".freeze
Instance Method Summary collapse
-
#initialize(path_to_file = DEFAULT_PATH_TO_FILE) ⇒ StorageInterceptor
constructor
A new instance of StorageInterceptor.
- #read_database ⇒ Object
- #write_database(data) ⇒ Object
Constructor Details
#initialize(path_to_file = DEFAULT_PATH_TO_FILE) ⇒ StorageInterceptor
5 6 7 |
# File 'lib/codebreaker/storage/storage_interceptor.rb', line 5 def initialize(path_to_file = DEFAULT_PATH_TO_FILE) @path_to_file = path_to_file.empty? ? DEFAULT_PATH_TO_FILE : path_to_file end |
Instance Method Details
#read_database ⇒ Object
9 10 11 |
# File 'lib/codebreaker/storage/storage_interceptor.rb', line 9 def read_database YAML.load_file(@path_to_file) if File.exist?(@path_to_file) end |
#write_database(data) ⇒ Object
13 14 15 |
# File 'lib/codebreaker/storage/storage_interceptor.rb', line 13 def write_database(data) File.open(@path_to_file, 'w') { |file| file.write(data.to_yaml) } end |