Sha256: c9c649c8dfbe768a6d66119fcaceb3cf6eb6dc05aac6ed0642df9c33ef56425c

Contents?: true

Size: 761 Bytes

Versions: 10

Compression:

Stored size: 761 Bytes

Contents

module OpenActive
  module Validators
    class EnumValidator < BaseValidator
      def initialize(classname)
        @classname = classname
      end

      # Coerce enum url to the enum instance
      #
      # @param value [mixed] Unum instance or URL
      # @return [int] The coerced enum
      def coerce(value)
        return value if value.is_a?(classname)

        classname.find_by_value(value)
      end

      # Run validation on the given value.
      #
      # @param value [mixed] The value to validate.
      # @return [Boolean] Whether validation passes or not.
      def run(value)
        return true if value.is_a?(classname)

        classname.find_by_value(value)
      end

      private

      attr_accessor :classname
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
openactive-0.5.0 lib/openactive/validators/enum_validator.rb
openactive-0.4.0 lib/openactive/validators/enum_validator.rb
openactive-0.3.0 lib/openactive/validators/enum_validator.rb
openactive-0.2.2 lib/openactive/validators/enum_validator.rb
openactive-0.2.1 lib/openactive/validators/enum_validator.rb
openactive-0.2.0 lib/openactive/validators/enum_validator.rb
openactive-0.1.2 lib/openactive/validators/enum_validator.rb
openactive-0.1.1 lib/openactive/validators/enum_validator.rb
openactive-0.1.0 lib/openactive/validators/enum_validator.rb
openactive-0.1.0.rc1 lib/openactive/validators/enum_validator.rb