Sha256: 4000ecae1e21672716bef7be3ca7f217e22883ff40c5e4ecd4bfd97b18ca93ff

Contents?: true

Size: 609 Bytes

Versions: 1

Compression:

Stored size: 609 Bytes

Contents

require 'jschematic/element'

module Jschematic
  module Attributes
    class Required
      include Jschematic::Element

      def initialize(required=false)
        case required
        when TrueClass, FalseClass
          @required = required
        else
          raise "Require must be strictly true or false. Truthy and false values are not allowed."
        end
      end

      def required?
        @required
      end

      def accepts?(instance)
        if @required
          instance || fail_validation!(@required, instance)
        else
          true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jschematic-0.1.0 lib/jschematic/attributes/required.rb