Class: DiverDown::Web::Metadata
- Inherits:
-
Object
- Object
- DiverDown::Web::Metadata
- Defined in:
- lib/diver_down/web/metadata.rb,
lib/diver_down/web/metadata/source_alias.rb,
lib/diver_down/web/metadata/source_metadata.rb
Defined Under Namespace
Classes: SourceAlias, SourceMetadata
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source_alias ⇒ Object
readonly
Returns the value of attribute source_alias.
Instance Method Summary collapse
-
#flush ⇒ void
Write store to file.
-
#initialize(path) ⇒ Metadata
constructor
A new instance of Metadata.
-
#reload ⇒ void
Reload metadata from file.
- #source(source_name) ⇒ DiverDown::Web::Metadata::SourceMetadata
- #to_h ⇒ Hash
Constructor Details
#initialize(path) ⇒ Metadata
Returns a new instance of Metadata.
12 13 14 15 |
# File 'lib/diver_down/web/metadata.rb', line 12 def initialize(path) @path = path reload end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/diver_down/web/metadata.rb', line 9 def path @path end |
#source_alias ⇒ Object (readonly)
Returns the value of attribute source_alias.
9 10 11 |
# File 'lib/diver_down/web/metadata.rb', line 9 def source_alias @source_alias end |
Instance Method Details
#flush ⇒ void
This method returns an undefined value.
Write store to file
40 41 42 |
# File 'lib/diver_down/web/metadata.rb', line 40 def flush File.write(@path, to_h.to_yaml) end |
#reload ⇒ void
This method returns an undefined value.
Reload metadata from file
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/diver_down/web/metadata.rb', line 46 def reload @source_map = Hash.new { |h, source_name| h[source_name] = DiverDown::Web::Metadata::SourceMetadata.new } @source_alias = DiverDown::Web::Metadata::SourceAlias.new loaded = YAML.load_file(@path) if File.exist?(@path) return if loaded.nil? loaded[:sources]&.each do |source_name, source_hash| source(source_name).memo = source_hash[:memo] if source_hash[:memo] source(source_name).module = source_hash[:module] if source_hash[:module] source(source_name).dependency_types = source_hash[:dependency_types] if source_hash[:dependency_types] end loaded[:source_alias]&.each do |alias_name, source_names| @source_alias.update_alias(alias_name, source_names) end end |
#source(source_name) ⇒ DiverDown::Web::Metadata::SourceMetadata
19 20 21 |
# File 'lib/diver_down/web/metadata.rb', line 19 def source(source_name) @source_map[source_name] end |
#to_h ⇒ Hash
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/diver_down/web/metadata.rb', line 24 def to_h source_names = @source_map.keys.sort sources = source_names.filter_map { h = source(_1).to_h [_1, h] unless h.empty? }.to_h { sources:, source_alias: @source_alias.to_h, } end |