Sha256: 5aefe90b13c188476ea7b6b70eee0f338cbf7c3d6dc5d2db0e8cd523babf7070

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

module LetsencryptWebfaction
  class ArgsParser
    class Field
      attr_reader :identifier, :description, :validators

      def initialize(identifier, description, validators = [])
        @identifier = identifier
        @description = description
        @validators = validators
      end

      def sanitize(val)
        val
      end

      def valid?(val)
        validators.reject { |validator| validator.valid?(val) }.empty?
      end

      def value?
        true
      end

      class IntegerField < Field
        def sanitize(val)
          val.to_i
        end
      end

      class ListField < Field
        def sanitize(val)
          val.split(',').map(&:strip).compact
        end
      end

      class BooleanField < Field
        def sanitize(val)
          val || false
        end

        def value?
          false
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
letsencrypt_webfaction-2.2.0 lib/letsencrypt_webfaction/args_parser/field.rb