Sha256: eeb6ab8e576d5a4af5a2d72be8c5ddf3df6240fe39531a509d726cbb7cf2d0bd

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module SyncFiles
  module Config
    class Validation
      class Invalid < Exception; end

      def initialize(config:)
        @config = config
      end

      def valid?
        validate!
        true
      rescue SyncFiles::Config::Validation::Invalid => e
        puts e.message
        false
      end

      def validate!
        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

      def validate_settings
        groups.all? { |group| !group["settings"].nil? && !group["settings"]["destination"].nil? }
      end

      def validate_fixtures
        groups.all? { |group| !group["fixtures"].nil? && !group["fixtures"].empty? }
      end

      def validate_groups
        !(@config["groups"].nil?)
      end

      def groups
        @config["groups"]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sync_files-0.1.0 lib/sync_files/config/validation.rb