Sha256: 9fef508542d4866cd79e5a6c2f1627db72cc900246e99d10d5439189ce25f625

Contents?: true

Size: 403 Bytes

Versions: 6

Compression:

Stored size: 403 Bytes

Contents

require 'jschematic/element'

module Jschematic
  module Attributes
    class Enum
      include Jschematic::Element

      def initialize(enum)
        raise "Enum requires an Array of possible values" unless Array === enum
        @enum = enum
      end

      def accepts?(instance)
        @enum.any?{ |e| e == instance } || fail_validation!("one of #{@enum}", instance)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jschematic-0.1.0 lib/jschematic/attributes/enum.rb
jschematic-0.0.9 lib/jschematic/attributes/enum.rb
jschematic-0.0.6 lib/jschematic/attributes/enum.rb
jschematic-0.0.5 lib/jschematic/attributes/enum.rb
jschematic-0.0.2 lib/jschematic/attributes/enum.rb
jschematic-0.0.1 lib/jschematic/attributes/enum.rb