Module: TypeConstraints

Defined in:
lib/type_constraints.rb,
lib/type_constraints/meta.rb,
lib/type_constraints/errors.rb,
lib/type_constraints/version.rb,
lib/type_constraints/registry.rb,
lib/type_constraints/type/default.rb

Defined Under Namespace

Modules: Type Classes: InvalidError, Meta, MissingMetaError, Registry

Constant Summary collapse

VERSION =
"0.1.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.registryObject

Returns the value of attribute registry.



8
9
10
# File 'lib/type_constraints.rb', line 8

def registry
  @registry
end

Class Method Details

.check!(name, val, level = 1) ⇒ Object

Raises:



20
21
22
23
# File 'lib/type_constraints.rb', line 20

def check!(name, val, level=1)
  raise MissingMetaError, nil, caller(level) if registry.metas[name].nil?
  registry.metas[name].check!(val, level+1)
end

.check?(name, val) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/type_constraints.rb', line 15

def check?(name, val)
  return false if registry.metas[name].nil?
  registry.metas[name].check?(val)
end

.setup(&code) ⇒ Object



9
10
11
12
13
# File 'lib/type_constraints.rb', line 9

def setup(&code)
  @registry ||= Registry.new
  @registry.instance_eval(&code)
  @registry
end