Class: Capsium::Package::Storage
- Inherits:
-
Object
- Object
- Capsium::Package::Storage
- Extended by:
- Forwardable
- Defined in:
- sig/capsium/package/storage.rbs,
lib/capsium/package/storage.rb
Overview
Loads and writes storage.json and instantiates its datasets (ARCHITECTURE.md section 5).
Instance Attribute Summary collapse
-
#config ⇒ StorageConfig
readonly
Returns the value of attribute config.
-
#datasets ⇒ Array[Dataset]
readonly
Returns the value of attribute datasets.
-
#path ⇒ String
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #data_sets ⇒ Hash[String, DatasetConfig]
- #dataset(name) ⇒ Dataset?
- #dataset_names ⇒ Array[String]
- #empty? ⇒ Boolean
-
#initialize(path) ⇒ Storage
constructor
A new instance of Storage.
- #load_datasets ⇒ Array[Dataset]
- #save_to_file(output_path = @path) ⇒ void
- #to_hash ⇒ Hash[String, untyped]
- #to_json ⇒ String
Constructor Details
#initialize(path) ⇒ Storage
Returns a new instance of Storage.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/capsium/package/storage.rb', line 14 def initialize(path) @path = path @dir = File.dirname(path) @config = if File.exist?(path) StorageConfig.from_json(File.read(path)) else StorageConfig.new end @datasets = load_datasets end |
Instance Attribute Details
#config ⇒ StorageConfig (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/capsium/package/storage.rb', line 10 def config @config end |
#datasets ⇒ Array[Dataset] (readonly)
Returns the value of attribute datasets.
10 11 12 |
# File 'lib/capsium/package/storage.rb', line 10 def datasets @datasets end |
#path ⇒ String (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/capsium/package/storage.rb', line 10 def path @path end |
Instance Method Details
#data_sets ⇒ Hash[String, DatasetConfig]
25 26 27 |
# File 'lib/capsium/package/storage.rb', line 25 def data_sets @config.data_sets end |
#dataset(name) ⇒ Dataset?
35 36 37 |
# File 'lib/capsium/package/storage.rb', line 35 def dataset(name) @datasets.find { |dataset| dataset.name == name } end |
#dataset_names ⇒ Array[String]
39 40 41 |
# File 'lib/capsium/package/storage.rb', line 39 def dataset_names data_sets.keys.sort end |
#empty? ⇒ Boolean
43 44 45 |
# File 'lib/capsium/package/storage.rb', line 43 def empty? data_sets.empty? end |
#load_datasets ⇒ Array[Dataset]
29 30 31 32 33 |
# File 'lib/capsium/package/storage.rb', line 29 def load_datasets data_sets.map do |name, dataset_config| dataset_config.to_dataset(name, @dir) end end |
#save_to_file(output_path = @path) ⇒ void
This method returns an undefined value.
47 48 49 |
# File 'lib/capsium/package/storage.rb', line 47 def save_to_file(output_path = @path) File.write(output_path, to_json) end |
#to_hash ⇒ Hash[String, untyped]
25 |
# File 'sig/capsium/package/storage.rbs', line 25
def to_hash: () -> Hash[String, untyped]
|
#to_json ⇒ String
24 |
# File 'sig/capsium/package/storage.rbs', line 24
def to_json: (*untyped args) -> String
|