preconditions 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,7 +32,7 @@ To use the fluent DSL API use the `check(arg).is {}` form like so:
32
32
 
33
33
  class MyMath
34
34
  def sqrt(num)
35
- Preconditions.check(num) { is_not_nil and has_type(Integer) and satisfies(">= 0") { arg >= 0 } }
35
+ Preconditions.check(num) { is_not_nil and has_type(Integer) and satisfies(">= 0") { num >= 0 } }
36
36
  num.sqrt
37
37
  end
38
38
  end
@@ -42,7 +42,7 @@ be supplied to add the argument name to any raised errors, or one can use the `#
42
42
 
43
43
  class MyMath
44
44
  def sqrt(num)
45
- Preconditions.check(num).named('num') { is_not_nil and has_type(Integer) and satisfies(">= 0") { arg >= 0 } }
45
+ Preconditions.check(num).named('num') { is_not_nil and has_type(Integer) and satisfies(">= 0") { num >= 0 } }
46
46
  num.sqrt
47
47
  end
48
48
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -58,6 +58,16 @@ class ConditionChecker
58
58
  true
59
59
  end
60
60
 
61
+ # DSL call. Establishes that the checked argument matches the given regular expression
62
+ # @raises [ArgumentError] if the argument does not match the supplied regex
63
+ # @return true
64
+ def matches(regex)
65
+ if arg !~ regex
66
+ raise ArgumentError, format_message("must match the regex /#{regex.to_s}/")
67
+ end
68
+ true
69
+ end
70
+
61
71
  # DSL call. Establishes that the checked argument satisfies an arbitrary condition specified in a block. If the
62
72
  # block evaluates to true the argument passes; if it evaluates to false it fails and an [ArgumentError] is raised.
63
73
  # An optional message may be supplied to describe what the block is checking.
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{preconditions}
8
- s.version = "0.2.1"
7
+ s.name = "preconditions"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{tucker}]
12
- s.date = %q{2011-05-25}
13
- s.description = %q{The Preconditions library provides a simple set of methods for checking arguments being passed into a method. Instead of writing custom checks and raising exceptions directly in your code you can use Preconditions to verify basic properties of your arguments (not-nil, satisfying a boolean expression, being of a certain type/duck-type) and raise the appropriate exception for you.
14
- }
15
- s.email = %q{tucker+rubygems@glyde.com}
11
+ s.authors = ["tucker"]
12
+ s.date = "2012-07-31"
13
+ s.description = "The Preconditions library provides a simple set of methods for checking arguments being passed into a method. Instead of writing custom checks and raising exceptions directly in your code you can use Preconditions to verify basic properties of your arguments (not-nil, satisfying a boolean expression, being of a certain type/duck-type) and raise the appropriate exception for you.\n"
14
+ s.email = "tucker+rubygems@glyde.com"
16
15
  s.extra_rdoc_files = [
17
16
  "LICENSE.txt",
18
17
  "README.md"
@@ -31,11 +30,11 @@ Gem::Specification.new do |s|
31
30
  "spec/preconditions_spec.rb",
32
31
  "spec/spec_helper.rb"
33
32
  ]
34
- s.homepage = %q{http://github.com/ctucker/preconditions}
35
- s.licenses = [%q{MIT}]
36
- s.require_paths = [%q{lib}]
37
- s.rubygems_version = %q{1.8.3}
38
- s.summary = %q{Preconditions checking support inspired by Guava}
33
+ s.homepage = "http://github.com/ctucker/preconditions"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.22"
37
+ s.summary = "Preconditions checking support inspired by Guava"
39
38
  s.test_files = [
40
39
  "spec/preconditions_dsl_spec.rb",
41
40
  "spec/preconditions_spec.rb",
@@ -1,4 +1,4 @@
1
- require "rspec"
1
+ require 'rspec'
2
2
  require 'preconditions'
3
3
 
4
4
  describe "dsl expression" do
@@ -35,6 +35,19 @@ describe "dsl expression" do
35
35
  res.should == arg
36
36
  end
37
37
 
38
+ it 'should raise on a matches check if the regex does not match' do
39
+ arg = 'some string'
40
+ expect {
41
+ Preconditions.check(arg) { matches(/other thing/) }
42
+ }.to raise_exception(ArgumentError)
43
+ end
44
+
45
+ it 'should return true on a matches check if the regex does match' do
46
+ arg = 'some string'
47
+ res = Preconditions.check(arg) { matches(/me/) }
48
+ res.should == arg
49
+ end
50
+
38
51
  it "should evaluate a satisfies block using the instance-local arg value" do
39
52
  x = 1
40
53
  expect {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preconditions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - tucker
@@ -15,9 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-25 00:00:00 Z
18
+ date: 2012-07-31 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
+ name: yard
21
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
22
23
  none: false
23
24
  requirements:
@@ -30,10 +31,10 @@ dependencies:
30
31
  - 0
31
32
  version: 0.6.0
32
33
  type: :development
33
- requirement: *id001
34
34
  prerelease: false
35
- name: yard
35
+ requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
+ name: bluecloth
37
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
@@ -44,10 +45,10 @@ dependencies:
44
45
  - 0
45
46
  version: "0"
46
47
  type: :development
47
- requirement: *id002
48
48
  prerelease: false
49
- name: bluecloth
49
+ requirement: *id002
50
50
  - !ruby/object:Gem::Dependency
51
+ name: bundler
51
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
52
53
  none: false
53
54
  requirements:
@@ -60,10 +61,10 @@ dependencies:
60
61
  - 0
61
62
  version: 1.0.0
62
63
  type: :development
63
- requirement: *id003
64
64
  prerelease: false
65
- name: bundler
65
+ requirement: *id003
66
66
  - !ruby/object:Gem::Dependency
67
+ name: jeweler
67
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
69
  none: false
69
70
  requirements:
@@ -76,10 +77,10 @@ dependencies:
76
77
  - 2
77
78
  version: 1.5.2
78
79
  type: :development
79
- requirement: *id004
80
80
  prerelease: false
81
- name: jeweler
81
+ requirement: *id004
82
82
  - !ruby/object:Gem::Dependency
83
+ name: rcov
83
84
  version_requirements: &id005 !ruby/object:Gem::Requirement
84
85
  none: false
85
86
  requirements:
@@ -90,10 +91,10 @@ dependencies:
90
91
  - 0
91
92
  version: "0"
92
93
  type: :development
93
- requirement: *id005
94
94
  prerelease: false
95
- name: rcov
95
+ requirement: *id005
96
96
  - !ruby/object:Gem::Dependency
97
+ name: rspec
97
98
  version_requirements: &id006 !ruby/object:Gem::Requirement
98
99
  none: false
99
100
  requirements:
@@ -106,10 +107,10 @@ dependencies:
106
107
  - 0
107
108
  version: 2.6.0
108
109
  type: :development
109
- requirement: *id006
110
110
  prerelease: false
111
- name: rspec
111
+ requirement: *id006
112
112
  - !ruby/object:Gem::Dependency
113
+ name: ci_reporter
113
114
  version_requirements: &id007 !ruby/object:Gem::Requirement
114
115
  none: false
115
116
  requirements:
@@ -120,9 +121,8 @@ dependencies:
120
121
  - 0
121
122
  version: "0"
122
123
  type: :development
123
- requirement: *id007
124
124
  prerelease: false
125
- name: ci_reporter
125
+ requirement: *id007
126
126
  description: |
127
127
  The Preconditions library provides a simple set of methods for checking arguments being passed into a method. Instead of writing custom checks and raising exceptions directly in your code you can use Preconditions to verify basic properties of your arguments (not-nil, satisfying a boolean expression, being of a certain type/duck-type) and raise the appropriate exception for you.
128
128
 
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  requirements: []
177
177
 
178
178
  rubyforge_project:
179
- rubygems_version: 1.8.3
179
+ rubygems_version: 1.8.22
180
180
  signing_key:
181
181
  specification_version: 3
182
182
  summary: Preconditions checking support inspired by Guava