Sha256: 668839d9dffc527d99889af5c1173eb5540e1fd89a63d52c65e27729078f6551

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

class StrongJSON
  module Types
    def object(fields = {})
      Type::Object.new(fields)
    end

    def array(type = any)
      Type::Array.new(type)
    end

    def optional(type = any)
      Type::Optional.new(type)
    end

    def string
      StrongJSON::Type::Base.new(:string)
    end

    def numeric
      StrongJSON::Type::Base.new(:numeric)
    end

    def number
      StrongJSON::Type::Base.new(:number)
    end

    def boolean
      StrongJSON::Type::Base.new(:boolean)
    end

    def any
      StrongJSON::Type::Base.new(:any)
    end

    def prohibited
      StrongJSON::Type::Base.new(:prohibited)
    end

    def symbol
      StrongJSON::Type::Base.new(:symbol)
    end

    def literal(value)
      StrongJSON::Type::Literal.new(value)
    end

    def enum(*types)
      StrongJSON::Type::Enum.new(types)
    end

    def string?
      optional(string)
    end

    def numeric?
      optional(numeric)
    end

    def number?
      optional(number)
    end

    def boolean?
      optional(boolean)
    end

    def symbol?
      optional(symbol)
    end

    def ignored
      StrongJSON::Type::Base.new(:ignored)
    end

    def array?(ty)
      optional(array(ty))
    end

    def object?(fields)
      optional(object(fields))
    end

    def literal?(value)
      optional(literal(value))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strong_json-0.4.0 lib/strong_json/types.rb
strong_json-0.3.0 lib/strong_json/types.rb
strong_json-0.2.0 lib/strong_json/types.rb