-
Notifications
You must be signed in to change notification settings - Fork 2
Registry
Jamie English edited this page Jul 21, 2017
·
4 revisions
Speculation allows you to store your specs in a global registry. The following demonstrates adding a spec named :"MyApp/id" to the registry:
S.def :"MyApp/id", S.or(:i => Integer, :s => String)Now we've registered our spec we're free to use it anywhere in our application:
S.valid?(:"MyApp/id", "123") # => true
S.valid?(:"MyApp/id", 123) # => true
S.valid?(:"MyApp/id", 123.0) # => false
S.valid?(:"MyApp/id", nil) # => falseWe can also refer to this spec by name when defining other specs:
S.def :"MyApp/maybe_id", S.nilable(:"MyApp/id")
S.def :"MyApp/ids", S.coll_of(:"MyApp/id")If you're wondering "why the weird symbols?", see Namespaced Symbols for an explanation.