Class: Metanorma::Release::ChannelConfig
- Inherits:
-
Object
- Object
- Metanorma::Release::ChannelConfig
- Defined in:
- lib/metanorma/release/channel_config.rb
Instance Attribute Summary collapse
-
#default_channels ⇒ Object
readonly
Returns the value of attribute default_channels.
-
#default_visibility ⇒ Object
readonly
Returns the value of attribute default_visibility.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
- .empty ⇒ Object
- .from_file(path) ⇒ Object
- .from_yaml(yaml_string) ⇒ Object
- .parse_channels(list) ⇒ Object
Instance Method Summary collapse
-
#initialize(registry:, default_visibility:, default_channels:) ⇒ ChannelConfig
constructor
A new instance of ChannelConfig.
Constructor Details
#initialize(registry:, default_visibility:, default_channels:) ⇒ ChannelConfig
Returns a new instance of ChannelConfig.
39 40 41 42 43 44 |
# File 'lib/metanorma/release/channel_config.rb', line 39 def initialize(registry:, default_visibility:, default_channels:) @registry = registry @default_visibility = default_visibility @default_channels = default_channels.freeze freeze end |
Instance Attribute Details
#default_channels ⇒ Object (readonly)
Returns the value of attribute default_channels.
46 47 48 |
# File 'lib/metanorma/release/channel_config.rb', line 46 def default_channels @default_channels end |
#default_visibility ⇒ Object (readonly)
Returns the value of attribute default_visibility.
46 47 48 |
# File 'lib/metanorma/release/channel_config.rb', line 46 def default_visibility @default_visibility end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
46 47 48 |
# File 'lib/metanorma/release/channel_config.rb', line 46 def registry @registry end |
Class Method Details
.empty ⇒ Object
34 35 36 37 |
# File 'lib/metanorma/release/channel_config.rb', line 34 def self.empty new(registry: ChannelRegistry.all_allowed, default_visibility: 'public', default_channels: []) end |
.from_file(path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/metanorma/release/channel_config.rb', line 21 def self.from_file(path) if File.directory?(path) channels_yml = File.join(path, 'channels.yml') raise ArgumentError, "Channel config file not found: #{path}" unless File.exist?(channels_yml) return from_file(channels_yml) end raise ArgumentError, "Channel config 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 15 16 17 18 19 |
# File 'lib/metanorma/release/channel_config.rb', line 8 def self.from_yaml(yaml_string) data = YAML.safe_load(yaml_string, permitted_classes: [Symbol]) raise ArgumentError, 'Invalid channel config YAML' unless data.is_a?(Hash) registry = ChannelRegistry.from_yaml(yaml_string) defaults = data['defaults'] || {} default_visibility = defaults['visibility'] || 'public' default_channels = parse_channels(defaults['channels']) new(registry: registry, default_visibility: default_visibility, default_channels: default_channels) end |