class NoradCli::UiSeedGenerator
Constants
- ALLOWED_ATTRIBUTES
- OPTIONAL_ATTRIBUTES
- REQUIRED_ATTRIBUTES
Public Class Methods
new(manifest_paths)
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 11 def initialize(manifest_paths) @manifest_paths = if manifest_paths.empty? Dir.glob('./**/manifest.yml') else manifest_paths end end
Public Instance Methods
process!()
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 19 def process! configurations = [] @manifest_paths.each { |manifest_path| configurations << configuration_from_manifest(manifest_path) } save_seed_file!(configurations) rescue ManifestError => e puts e.message end
Private Instance Methods
configuration_from_manifest(manifest_path)
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 37 def configuration_from_manifest(manifest_path) raise ManifestNotFoundError, manifest_path unless File.exist?(manifest_path) seed = YAML.safe_load(File.read(manifest_path)) validate_seed(manifest_path, seed) seed['name'] = seed['version'] ? "#{seed['name']}:#{seed['version']}" : seed['name'] sanitize_seed(seed) end
sanitize_seed(seed)
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 47 def sanitize_seed(seed) seed.each_key { |key| seed.delete(key) unless ALLOWED_ATTRIBUTES.include?(key) } end
save_seed_file!(configurations)
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 33 def save_seed_file!(configurations) File.open(seed_path, 'w') { |f| f.write YAML.dump(configurations) } end
seed_path()
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 29 def seed_path "#{Dir.pwd}/seed.yml" end
validate_seed(manifest_path, seed)
click to toggle source
# File lib/norad_cli/support/ui_seed_generator.rb, line 51 def validate_seed(manifest_path, seed) raise InvalidManifestError, manifest_path unless seed.is_a?(Hash) return if REQUIRED_ATTRIBUTES & seed.keys == REQUIRED_ATTRIBUTES raise ManifestMissingAttributesError.new(manifest_path, REQUIRED_ATTRIBUTES - seed.keys) end