Class: SyncFiles::Config::Validation
- Inherits:
-
Object
- Object
- SyncFiles::Config::Validation
- Defined in:
- lib/sync_files/config/validation.rb
Defined Under Namespace
Classes: Invalid
Instance Method Summary collapse
- #groups ⇒ Object
-
#initialize(config:) ⇒ Validation
constructor
A new instance of Validation.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
- #validate_fixtures ⇒ Object
- #validate_groups ⇒ Object
- #validate_settings ⇒ Object
Constructor Details
#initialize(config:) ⇒ Validation
Returns a new instance of Validation.
6 7 8 |
# File 'lib/sync_files/config/validation.rb', line 6 def initialize(config:) @config = config end |
Instance Method Details
#groups ⇒ Object
37 38 39 |
# File 'lib/sync_files/config/validation.rb', line 37 def groups @config["groups"] end |
#valid? ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/sync_files/config/validation.rb', line 10 def valid? validate! true rescue SyncFiles::Config::Validation::Invalid => e puts e. false end |
#validate! ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sync_files/config/validation.rb', line 18 def validate! raise Invalid.new("ERROR: No config file found. Please create one of the following files: #{CONFIG_FILENAMES.join(", ")}") unless @config raise Invalid.new("ERROR: No groups specified in the config file.") unless validate_groups raise Invalid.new("ERROR: No files specified in the config file.") unless validate_fixtures raise Invalid.new("ERROR: No destination specified in the config file.") unless validate_settings end |
#validate_fixtures ⇒ Object
29 30 31 |
# File 'lib/sync_files/config/validation.rb', line 29 def validate_fixtures groups.all? { |group| !group["fixtures"].nil? && !group["fixtures"].empty? } end |
#validate_groups ⇒ Object
33 34 35 |
# File 'lib/sync_files/config/validation.rb', line 33 def validate_groups !(@config["groups"].nil?) end |
#validate_settings ⇒ Object
25 26 27 |
# File 'lib/sync_files/config/validation.rb', line 25 def validate_settings groups.all? { |group| !group["settings"].nil? && !group["settings"]["destination"].nil? } end |