Class: Schash::Schema::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/schash/schema/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.evaluate(&block) ⇒ Object



4
5
6
# File 'lib/schash/schema/dsl.rb', line 4

def self.evaluate(&block)
  self.new.instance_eval(&block)
end

Instance Method Details

#arrayObject



44
45
46
# File 'lib/schash/schema/dsl.rb', line 44

def array
  type(Array)
end

#array_of(schema) ⇒ Object



8
9
10
# File 'lib/schash/schema/dsl.rb', line 8

def array_of(schema)
  Rule::ArrayOf.new(schema)
end

#booleanObject



48
49
50
# File 'lib/schash/schema/dsl.rb', line 48

def boolean
  one_of_types(TrueClass, FalseClass)
end

#floatObject



36
37
38
# File 'lib/schash/schema/dsl.rb', line 36

def float
  type(Float)
end

#integerObject



32
33
34
# File 'lib/schash/schema/dsl.rb', line 32

def integer
  type(Integer)
end

#match(pattern) ⇒ Object



52
53
54
# File 'lib/schash/schema/dsl.rb', line 52

def match(pattern)
  Rule::Match.new(pattern)
end

#numericObject



28
29
30
# File 'lib/schash/schema/dsl.rb', line 28

def numeric
  type(Numeric)
end

#one_of_types(*schemas) ⇒ Object



12
13
14
# File 'lib/schash/schema/dsl.rb', line 12

def one_of_types(*schemas)
  Rule::OneOfTypes.new(*schemas)
end

#optional(rule) ⇒ Object



20
21
22
# File 'lib/schash/schema/dsl.rb', line 20

def optional(rule)
  Rule::Optional.new(rule)
end

#stringObject



24
25
26
# File 'lib/schash/schema/dsl.rb', line 24

def string
  type(String)
end

#symbolObject



40
41
42
# File 'lib/schash/schema/dsl.rb', line 40

def symbol
  type(Symbol)
end

#type(klass) ⇒ Object



16
17
18
# File 'lib/schash/schema/dsl.rb', line 16

def type(klass)
  Rule::Type.new(klass)
end