Class: Metanorma::Release::ChannelManifest
- Inherits:
-
Object
- Object
- Metanorma::Release::ChannelManifest
- Defined in:
- lib/metanorma/release/channel_manifest.rb
Instance Attribute Summary collapse
-
#config_source ⇒ Object
readonly
Returns the value of attribute config_source.
Class Method Summary collapse
- .all_private ⇒ Object
- .all_public ⇒ Object
- .from_file(path) ⇒ Object
- .from_yaml(yaml_string) ⇒ Object
- .parse(yaml_hash) ⇒ Object
- .parse_channels(channel_list) ⇒ Object
- .parse_entries(documents) ⇒ Object
- .validate_entry!(doc) ⇒ Object
Instance Method Summary collapse
- #all_channels ⇒ Object
- #explicit? ⇒ Boolean
-
#initialize(entries:, default_visibility:, default_channels:, explicit:, config_source: nil) ⇒ ChannelManifest
constructor
A new instance of ChannelManifest.
- #list_all ⇒ Object
- #resolve(document) ⇒ Object
Constructor Details
#initialize(entries:, default_visibility:, default_channels:, explicit:, config_source: nil) ⇒ ChannelManifest
Returns a new instance of ChannelManifest.
108 109 110 111 112 113 114 115 |
# File 'lib/metanorma/release/channel_manifest.rb', line 108 def initialize(entries:, default_visibility:, default_channels:, explicit:, config_source: nil) @entries = entries @default_visibility = default_visibility @default_channels = default_channels.freeze @explicit = explicit @config_source = config_source freeze end |
Instance Attribute Details
#config_source ⇒ Object (readonly)
Returns the value of attribute config_source.
138 139 140 |
# File 'lib/metanorma/release/channel_manifest.rb', line 138 def config_source @config_source end |
Class Method Details
.all_private ⇒ Object
103 104 105 106 |
# File 'lib/metanorma/release/channel_manifest.rb', line 103 def self.all_private new(entries: [], default_visibility: 'private', default_channels: [], explicit: false, config_source: nil) end |
.all_public ⇒ Object
98 99 100 101 |
# File 'lib/metanorma/release/channel_manifest.rb', line 98 def self.all_public new(entries: [], default_visibility: 'public', default_channels: [Channel.public('default')], explicit: false, config_source: nil) end |
.from_file(path) ⇒ Object
92 93 94 95 96 |
# File 'lib/metanorma/release/channel_manifest.rb', line 92 def self.from_file(path) raise ArgumentError, "Manifest file not found: #{path}" unless File.exist?(path) from_yaml(File.read(path)) end |
.from_yaml(yaml_string) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/metanorma/release/channel_manifest.rb', line 85 def self.from_yaml(yaml_string) yaml = YAML.safe_load(yaml_string, permitted_classes: [Symbol]) raise ArgumentError, 'Manifest YAML is empty' unless yaml.is_a?(Hash) parse(yaml) end |
.parse(yaml_hash) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/metanorma/release/channel_manifest.rb', line 74 def self.parse(yaml_hash) defaults = yaml_hash['defaults'] || {} default_visibility = defaults['visibility'] || 'public' default_channels = parse_channels(defaults['channels']) entries = parse_entries(yaml_hash['documents'] || []) config_source = yaml_hash['config'] new(entries: entries, default_visibility: default_visibility, default_channels: default_channels, explicit: true, config_source: config_source) end |
.parse_channels(channel_list) ⇒ Object
166 167 168 169 170 |
# File 'lib/metanorma/release/channel_manifest.rb', line 166 def self.parse_channels(channel_list) return [] unless channel_list channel_list.map { |c| Channel.parse(c.to_s) } end |
.parse_entries(documents) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/metanorma/release/channel_manifest.rb', line 172 def self.parse_entries(documents) documents.map do |doc| validate_entry!(doc) ManifestEntry.new( source: doc['source'], pattern: doc['pattern'], visibility: doc['visibility'], channels: parse_channels(doc['channels']), stages: doc['stages'] ) end end |
.validate_entry!(doc) ⇒ Object
185 186 187 188 189 |
# File 'lib/metanorma/release/channel_manifest.rb', line 185 def self.validate_entry!(doc) return unless doc['source']&.include?('..') raise ArgumentError, "Path traversal detected in manifest source: #{doc['source']}" end |
Instance Method Details
#all_channels ⇒ Object
130 131 132 |
# File 'lib/metanorma/release/channel_manifest.rb', line 130 def all_channels (@default_channels + @entries.flat_map(&:channels)).uniq end |
#explicit? ⇒ Boolean
134 135 136 |
# File 'lib/metanorma/release/channel_manifest.rb', line 134 def explicit? @explicit end |
#list_all ⇒ Object
126 127 128 |
# File 'lib/metanorma/release/channel_manifest.rb', line 126 def list_all @entries end |
#resolve(document) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/release/channel_manifest.rb', line 117 def resolve(document) return default_policy unless @explicit entry = find_best_match(document) return DocumentReleasePolicy.from_defaults(@default_visibility, @default_channels) unless entry DocumentReleasePolicy.from_entry(entry) end |