constrain 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48a0683db5a9b95baaf0ca8ee0f59322ffadbfe9f8b524a9e6e3d53cf7d1f06c
4
- data.tar.gz: 3d07bc32462abdd359a85130301a29680f108dfe30f9af43ae1cda10f2a21d7d
3
+ metadata.gz: e58649bbac9af8f3464dedd63c6c76e72c6f37440da629a10b5aba3319972214
4
+ data.tar.gz: c82c606c419af6c2af55aaca6a57bf03d2229917241bf800d32dba8d8a6a512c
5
5
  SHA512:
6
- metadata.gz: fd9457aab6e64780ade38a804b914a3519a5c5f6cabf62cd35f94a5823eced188e2e9e89deb0980319ce6c6d565ebd97456f67b6a0657648226396b7476a0be2
7
- data.tar.gz: 4f4fcedad8e23c7dcf7a1c52cc69c9f9361fbb95cd3e889c7295c6d0dbc85d67a547a0b9b9e4368d632a122ce1b6b3532a2ef89b00a92ea448a772360a47815a
6
+ metadata.gz: 6e0b90a537bea77af54c907ccb7fb1ea0a501623ba42c793c94ac446cfcbee615cac3d2937ec86741af883698ef3558ba4a3bc34030e3d1be68c36730e159097
7
+ data.tar.gz: 3d0212bdafd1a03d9058b8ad94bc423f346ec6b36752c1dbbc11b2f3b319d77493754cb68be712ce7dc7ab02986eab1329b7fa42ec116b770a0e31517c9c7124
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.7.1
1
+ ruby-3.1.2
data/README.md CHANGED
@@ -47,16 +47,17 @@ have it available in all child classes
47
47
 
48
48
  ## Methods
49
49
 
50
- #### constrain(value, \*expressions, message = nil, unwind: 0)
50
+ #### constrain(value, \*expressions, message: nil, unwind: 0)
51
51
 
52
52
  Return the given value if it matches at least one of the expressions and raise a
53
53
  Constrain::TypeError if not. The value is matched against the expressions using
54
54
  the #=== operator so anything you can put into the 'when' clause of a 'case'
55
55
  statement can be used. #constrain raise a Constrain::MatchError if the value
56
- doesn't match any expression
56
+ doesn't match any expression and an ArgumentError if there is a syntax error in
57
+ the expression
57
58
 
58
- The error message can be customized by added the message argument and a number
59
- of backtrace leves can be skipped by setting :unwind option. By default the
59
+ The error message can be customized by adding the message option and a number
60
+ of backtrace leves can be skipped using the :unwind option. By default the
60
61
  backtrace will refer to the point of the call of \#constrain. \#constrain
61
62
  raises a Constrain::Error exception if there is an error in the syntax of the
62
63
  class expression
@@ -65,9 +66,8 @@ class expression
65
66
  want an exception if the parameters doesn't match the expected, but because it
66
67
  returns the value if successful it can be used to check the validity of
67
68
  variables in expressions too, eg. `return constrain(result_of_complex_computation, Integer)`
68
- to check the return value of a method
69
69
 
70
- #### Constrain.constrain(value, \*expressions, message = nil, unwind: 0)
70
+ #### Constrain.constrain(value, \*expressions, message: nil, unwind: 0)
71
71
 
72
72
  Class method version of #constrain. It is automatically added to classes that
73
73
  include Constrain
@@ -77,8 +77,8 @@ include Constrain
77
77
 
78
78
  It matches value against the class expressions like #constrain but returns true
79
79
  or false as result. It is automatically added to classes that include
80
- Constrain. Constrain.constrain? raises a Constrain::Error exception if there
81
- is an error in the syntax of the class expression
80
+ Constrain. Constrain.constrain? raises a ArgumentError exception if there
81
+ is an error in the syntax of the expression
82
82
 
83
83
 
84
84
  ## Expressions
data/TODO CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ o Allow 'constrain SomeClass < SomeOtherClass'
3
+ o Match ranges and regular expressions
2
4
  o A tuple method: "Symbol => constrain.tuple(String, Integer)"
3
5
  o An array and hash method: "Symbol => constrain.array(Integer), String => constrain.hash(Symbol, Integer)"
4
6
  o Class | Class syntax
data/constrain.gemspec CHANGED
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  Constrain works with ruby-2 (and maybe ruby-3)
28
28
  }
29
29
  spec.homepage = "https://github.com/clrgit/constrain/"
30
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
31
30
 
32
31
  spec.metadata["homepage_uri"] = spec.homepage
33
32
 
@@ -1,3 +1,3 @@
1
1
  module Constrain
2
- VERSION = "0.5.0"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/constrain.rb CHANGED
@@ -65,9 +65,12 @@ module Constrain
65
65
  end
66
66
 
67
67
  begin
68
- !exprs.empty? or raise ArgumentError, "Empty constraint"
69
- exprs.any? { |expr| Constrain.do_constrain_value?(value, expr) } or
70
- raise MatchError.new(value, exprs, message: message, unwind: unwind)
68
+ if exprs.empty?
69
+ value or raise MatchError.new(value, [], message: message, unwind: unwind)
70
+ else
71
+ exprs.any? { |expr| Constrain.do_constrain_value?(value, expr) } or
72
+ raise MatchError.new(value, exprs, message: message, unwind: unwind)
73
+ end
71
74
  rescue ArgumentError, Constrain::MatchError => ex
72
75
  ex.set_backtrace(caller[1 + unwind..-1])
73
76
  raise
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-06 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -56,7 +56,7 @@ homepage: https://github.com/clrgit/constrain/
56
56
  licenses: []
57
57
  metadata:
58
58
  homepage_uri: https://github.com/clrgit/constrain/
59
- post_install_message:
59
+ post_install_message:
60
60
  rdoc_options: []
61
61
  require_paths:
62
62
  - lib
@@ -64,15 +64,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 2.3.0
67
+ version: '0'
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.1.4
75
- signing_key:
74
+ rubygems_version: 3.3.18
75
+ signing_key:
76
76
  specification_version: 4
77
77
  summary: Dynamic in-file type checking
78
78
  test_files: []