typestrict 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/typestrict.rb +11 -5
  2. metadata +3 -3
data/lib/typestrict.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Strict
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
 
4
4
  class TypeError < Exception
5
5
  attr :errors
@@ -27,7 +27,7 @@ module Strict
27
27
  end
28
28
 
29
29
  def setmode_catch!
30
- @@errors = []
30
+ @@errors = [] unless @@errors.is_a? Array
31
31
  @@raise_exception = false
32
32
  end
33
33
 
@@ -43,8 +43,8 @@ module Strict
43
43
  end
44
44
 
45
45
  def register_supertype(supertype, handler)
46
- enforce_primitive!(Symbol, supertype)
47
- enforce_primitive!(Proc, handler)
46
+ enforce_primitive!(Symbol, supertype, "typestrict/register_supertype")
47
+ enforce_primitive!(Proc, handler, "typestrict/register_supertype")
48
48
 
49
49
  @@dynamic_handlers[supertype] = handler
50
50
  puts "registered a dynamic handler for supertype: #{supertype}"
@@ -71,7 +71,10 @@ module Strict
71
71
  def enforce_weak_primitives!(types, data, context="Value")
72
72
  enforce_primitive!(Array, types, 'lib/typestrict')
73
73
  types.each {|type| enforce_primitive!(Object, type, 'lib/typestrict')}
74
-
74
+
75
+ raise_set_before = @@raise_exception
76
+ setmode_catch!
77
+
75
78
  match_found = false
76
79
  types.each do |type|
77
80
  begin
@@ -82,6 +85,9 @@ module Strict
82
85
  next
83
86
  end
84
87
  end
88
+
89
+ setmode_raise! if raise_set_before
90
+
85
91
  catch_error "#{header(context, data)} must be of one of the types of #{types.inspect}" unless match_found
86
92
  return data
87
93
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typestrict
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Raeez Lorgat