Module: Rbcli::Configurate::Config
- Includes:
- Rbcli::Configurable
- Defined in:
- lib/rbcli/components/config/component.rb
Overview
Rbcli – A framework for developing command line applications in Ruby #
Copyright (C) 2024 Andrew Khoury <[email protected]> #
Class Method Summary collapse
- .banner(text) ⇒ Object
- .create_if_not_exists(cne) ⇒ Object
- .defaults(hash) ⇒ Object
- .file(location) ⇒ Object
- .save_on_exit(soe) ⇒ Object
- .schema_file(path) ⇒ Object
- .schema_hash(hash) ⇒ Object
- .skeleton(text) ⇒ Object
- .suppress_errors(suppress) ⇒ Object
- .type(type) ⇒ Object
Methods included from Rbcli::Configurable
Class Method Details
.banner(text) ⇒ Object
54 55 56 57 |
# File 'lib/rbcli/components/config/component.rb', line 54 def self. text raise Rbcli::ConfigurateError.new "The banner must be set to a string." unless text.is_a?(String) @params[:banner] = text end |
.create_if_not_exists(cne) ⇒ Object
44 45 46 47 |
# File 'lib/rbcli/components/config/component.rb', line 44 def self.create_if_not_exists cne raise Rbcli::ConfigurateError.new "Config 'create_if_not_exists' must be true or false" unless cne.is_a?(TrueClass) || cne.is_a?(FalseClass) @params[:create_if_not_exists] = cne end |
.defaults(hash) ⇒ Object
59 60 61 62 |
# File 'lib/rbcli/components/config/component.rb', line 59 def self.defaults hash raise Rbcli::ConfigurateError.new "The default configuration must be a hash." unless hash.is_a?(Hash) @params[:defaults] = hash end |
.file(location) ⇒ Object
18 19 20 21 |
# File 'lib/rbcli/components/config/component.rb', line 18 def self.file location raise Rbcli::ConfigurateError.new "Config file location must either be a path or an array of paths" unless location.nil? || location.is_a?(String) || (location.is_a?(Array) && location.all? { |loc| loc.is_a?(String) }) @params[:location] = location end |
.save_on_exit(soe) ⇒ Object
40 41 42 |
# File 'lib/rbcli/components/config/component.rb', line 40 def self.save_on_exit soe Rbcli::Engine.register_operation Proc.new { Rbcli::Warehouse.get(:config, :parsedopts).save! }, name: :save_config, priority: 160 if soe end |
.schema_file(path) ⇒ Object
28 29 30 31 32 |
# File 'lib/rbcli/components/config/component.rb', line 28 def self.schema_file path raise Rbcli::ConfigurateError.new "Config schema file location must be a path" unless path.nil? || path.is_a?(String) raise Rbcli::ConfigurateError.new "May not define both a schema_hash and schema_file together." if @params[:schema_hash] && !path.nil? @params[:schema_file] = path end |
.schema_hash(hash) ⇒ Object
34 35 36 37 38 |
# File 'lib/rbcli/components/config/component.rb', line 34 def self.schema_hash hash raise Rbcli::ConfigurateError.new "Config schema hash must be a hash" unless hash.nil? || hash.is_a?(Hash) raise Rbcli::ConfigurateError.new "May not define both a schema_hash and schema_file together." if @params[:schema_file] && !hash.nil? @params[:schema_hash] = hash end |
.skeleton(text) ⇒ Object
64 65 66 67 |
# File 'lib/rbcli/components/config/component.rb', line 64 def self.skeleton text raise Rbcli::ConfigurateError.new "The skeleton data must be set to a string." unless text.is_a?(String) @params[:skeleton] = text end |
.suppress_errors(suppress) ⇒ Object
49 50 51 52 |
# File 'lib/rbcli/components/config/component.rb', line 49 def self.suppress_errors suppress raise Rbcli::ConfigurateError.new "Config 'suppress_errors' must be true or false" unless suppress.is_a?(TrueClass) || suppress.is_a?(FalseClass) @params[:suppress_errors] = suppress end |
.type(type) ⇒ Object
23 24 25 26 |
# File 'lib/rbcli/components/config/component.rb', line 23 def self.type type raise Rbcli::ConfigurateError.new "Config type must be one of the following: #{Rbcli::UserConf::Backend.types.keys.join(', ')}" unless (type.is_a?(String) || type.is_a?(Symbol)) && Rbcli::UserConf::Backend.types.key?(type.downcase.to_sym) @params[:type] = type end |