Class: Metanorma::Release::ChannelRegistry
- Inherits:
-
Object
- Object
- Metanorma::Release::ChannelRegistry
- Defined in:
- lib/metanorma/release/channel_registry.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
Class Method Summary collapse
- .all_allowed ⇒ Object
- .from_file(path) ⇒ Object
- .from_yaml(yaml_string) ⇒ Object
- .parse_channel_list(list) ⇒ Object
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #include?(channel_or_string) ⇒ Boolean
-
#initialize(channels:) ⇒ ChannelRegistry
constructor
A new instance of ChannelRegistry.
- #valid?(channel) ⇒ Boolean
Constructor Details
#initialize(channels:) ⇒ ChannelRegistry
Returns a new instance of ChannelRegistry.
26 27 28 29 30 |
# File 'lib/metanorma/release/channel_registry.rb', line 26 def initialize(channels:) @channels = channels.freeze @channel_set = channels.to_set freeze end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
42 43 44 |
# File 'lib/metanorma/release/channel_registry.rb', line 42 def channels @channels end |
Class Method Details
.all_allowed ⇒ Object
22 23 24 |
# File 'lib/metanorma/release/channel_registry.rb', line 22 def self.all_allowed new(channels: []) end |
.from_file(path) ⇒ Object
16 17 18 19 20 |
# File 'lib/metanorma/release/channel_registry.rb', line 16 def self.from_file(path) raise ArgumentError, "Channel registry file not found: #{path}" unless File.exist?(path) from_yaml(File.read(path)) end |
.from_yaml(yaml_string) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/metanorma/release/channel_registry.rb', line 8 def self.from_yaml(yaml_string) data = YAML.safe_load(yaml_string, permitted_classes: [Symbol]) raise ArgumentError, 'Invalid channel registry YAML' unless data.is_a?(Hash) channels = parse_channel_list(data['channels']) new(channels: channels) end |
.parse_channel_list(list) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/release/channel_registry.rb', line 48 def self.parse_channel_list(list) return [] unless list list.filter_map do |entry| case entry when Hash then Channel.parse(entry['name'].to_s) when String then Channel.parse(entry) end end end |
Instance Method Details
#empty? ⇒ Boolean
44 45 46 |
# File 'lib/metanorma/release/channel_registry.rb', line 44 def empty? @channels.empty? end |
#include?(channel_or_string) ⇒ Boolean
38 39 40 |
# File 'lib/metanorma/release/channel_registry.rb', line 38 def include?(channel_or_string) valid?(Channel.parse(channel_or_string.to_s)) end |
#valid?(channel) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/metanorma/release/channel_registry.rb', line 32 def valid?(channel) return true if @channels.empty? @channel_set.include?(channel) end |