Class: Tamiyo::DataStore
Instance Method Summary
collapse
Methods included from YamlHelper
#emit_block_mapping, #emit_block_sequence, #emit_end_of_one_document, #emit_flow_sequence, #emit_literal, #emit_pair, #emit_pair_with_literal_value, #emit_pair_with_optional_sequence_value, #emit_pair_with_sequence_value, #emit_plain, #emit_start_of_one_document, #setup_yaml_emitter_for, #yaml_event_stream_for, #yaml_from, #yaml_of
Constructor Details
Returns a new instance of DataStore.
8
9
10
11
|
# File 'lib/tamiyo/data_store.rb', line 8
def initialize
@data_dir = ensure_tamiyo_data_dir
@custom_sets_path = path_for 'custom_sets.yaml'
end
|
Instance Method Details
#ensure_tamiyo_data_dir ⇒ Object
13
14
15
16
17
|
# File 'lib/tamiyo/data_store.rb', line 13
def ensure_tamiyo_data_dir
data_dir = File.join Dir.home, '.tamiyo'
FileUtils.mkpath data_dir
data_dir
end
|
#load_custom_sets ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/tamiyo/data_store.rb', line 23
def load_custom_sets
File.exists?(@custom_sets_path) ? begin
File.open(@custom_sets_path, 'r') do |f|
yaml_from f.read
end
end : {}
end
|
#path_for(file_name) ⇒ Object
19
20
21
|
# File 'lib/tamiyo/data_store.rb', line 19
def path_for(file_name)
File.join @data_dir, file_name
end
|
#persist_custom_sets(data) ⇒ Object
31
32
33
34
35
|
# File 'lib/tamiyo/data_store.rb', line 31
def persist_custom_sets(data)
File.open(@custom_sets_path, 'w') do |f|
f.write yaml_of data
end
end
|