simplecheck 1.0rc1 → 1.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
  SHA1:
3
- metadata.gz: a928fd88137669a29e16e814e1d21af7e6403f3f
4
- data.tar.gz: 547b3655c4efdbf9ab4e1ef019f51fcc224c537f
3
+ metadata.gz: fc468c54a4b799857823419a0492b16f088f011a
4
+ data.tar.gz: 66bb8cfc8196b4dbdfd00ef2a6eca8b336c10dbb
5
5
  SHA512:
6
- metadata.gz: c77b199bbbc3308e07b0348f6f7c013cc473376b62930a715ba31b249cff9a55f291cfcb658d8c756c5f929abf0a63bd453f1524a85397619b20535ab98f9ea8
7
- data.tar.gz: 1cb867dc97e7dba604956d0432198304990be0d0a024deca114350a47c263a75c41d1a38260ab3e663a133d2fdebcd0c9e00b84ef08eb548df6d8907b247bf3e
6
+ metadata.gz: 7a9ab02843cee5155e667f91f83b0f16942eff1f94becc5e5449ca6eebb654a05fcb28ec9f2a4ec304e29011557cafef28f04fd95e703f79b8c68e60cd63b68b
7
+ data.tar.gz: 22207c8cccd871e1dd158f520172cd5dfcedfa658a7059476d0ba3b110736b71ff65a6feb6dd1f521cfb181b9b7d13c17262de4d34ea67e770e7cbcbf28b8ee4
data/README.md CHANGED
@@ -1,33 +1,37 @@
1
- Simplecheck
2
- ===========
1
+ # Simplecheck
3
2
 
4
3
  Simplecheck is a lightweight property checking API for Ruby designed to quickly check arguments. Once included into a class it provides the `check` instance method which takes arguments and a condition to check them against.
5
4
 
6
5
  If a check fails a `Simplecheck::CheckFailed` exception is raised.
7
6
 
8
- Usage
9
- -----
7
+ ## Installation
8
+
9
+ Simplecheck is available as a Rubygem installable via [gem install simplecheck](http://rubygems.org/gems/simplecheck).
10
+
11
+ A git repository is also available at [http://github.com/farrel/simplecheck](http://github.com/farrel/simplecheck).
12
+
13
+ ## Usage
10
14
 
11
15
  require 'simplecheck'
12
16
 
13
- class Person
17
+ class Customer
14
18
  include Simplecheck
19
+
20
+ attr_accessor( :name, :age )
15
21
 
16
22
  def initialize( name, age )
17
- check( name ) # Check name is not nil
18
- check( age, 18..75 ) # Check age is within range
23
+ check( name, String ) # Check name is String
24
+ check( age, 18..75 ) # Check age is within Range
19
25
 
20
- @name = name
21
- @age = age
26
+ @name, @age = name, age
22
27
  end
23
28
  end
24
29
 
25
- Person.new( "Joe", 25 ) # No error
26
- Person.new( nil, 25 ) rescue puts "Name can not be nil"
27
- Person.new( "Joe", 15 ) rescue puts "Age is out of range"
30
+ Customer.new( "Joe", 25 ) # No error
31
+ Customer.new( nil, 25 ) rescue puts "Name can not be nil"
32
+ Customer.new( "Joe", 15 ) rescue puts "Age is out of range"
28
33
 
29
- Check Methods
30
- -------------
34
+ ## Check Methods
31
35
 
32
36
  Simplecheck currently supports three different check methods:
33
37
 
@@ -49,8 +53,8 @@ In the simplest case `check` takes an expression as an argument. If the expressi
49
53
  If two or more arguments are given without a block, then the last argument becomes the condition against which the previous arguments are checked. To accomplish this the condition argument should implement the case equality operator (`===` or threequal) in a logical manner.
50
54
 
51
55
  def greatest_common_divisor( a, b )
52
- check( a, b, Numeric )
53
- # GCD Algorithm
56
+ check( a, b, Integer )
57
+ # GCD Algorithm...
54
58
  end
55
59
 
56
60
  If a class does not alias or implement it's own version of `===` it has the same functionality as `==`. The following Ruby Core classes already alias `===` to various instance methods.
@@ -98,8 +102,7 @@ A block can be passed to `check`, with the arguments passed to `check` then pass
98
102
 
99
103
  This is syntactic sugar for the Proc Case Equality check.
100
104
 
101
- Multiple Arguments
102
- ------------------
105
+ ## Multiple Arguments
103
106
 
104
107
  Case Equality and Block checks can be called with multiple arguments, with each argument being checked individually against the condition:
105
108
 
@@ -108,8 +111,12 @@ Case Equality and Block checks can be called with multiple arguments, with each
108
111
  n.even?
109
112
  end
110
113
 
111
- License
112
- -------
114
+ ## Resources
115
+
116
+ * Git repository - [http://github.com/farrel/simplecheck](http://github.com/farrel/simplecheck)
117
+ * Rubygem page - [http://rubygems.org/gems/simplecheck](http://rubygems.org/gems/simplecheck)
118
+
119
+ ## License
113
120
  Simplecheck is released under the BSD License.
114
121
 
115
122
  Copyright 2013 AIMRED CC. All rights reserved.
@@ -12,6 +12,6 @@ check( 'aaabbb', /^aaa/ )
12
12
  check( 1, 1..10 )
13
13
 
14
14
  # Proc#=== -> Proc#call
15
- check( 1, lambda{ |n| n.odd? })
15
+ check( 1, ->(n){ n.odd? })
16
16
 
17
17
  puts "All passed"
@@ -51,3 +51,5 @@ bob.date_of_birth = nil
51
51
 
52
52
  # date_of_birth is not present
53
53
  try{ joe > bob }
54
+
55
+ puts "Finished"
@@ -1,3 +1,3 @@
1
1
  module Simplecheck
2
- VERSION = '1.0rc1'
2
+ VERSION = '1.0'
3
3
  end
@@ -1,98 +1,61 @@
1
1
  require 'test_helper'
2
2
 
3
- class Foo
4
- include Simplecheck
5
-
6
- def expression_check( a )
7
- check( a )
8
- end
9
-
10
- def case_equality_check( a )
11
- check( a, Integer )
12
- end
13
-
14
- def case_equality_check_multiple_arguments( *arguments )
15
- check( *arguments, Integer )
16
- end
17
-
18
- def block_check( a )
19
- check( a ){ |x| x.modulo( 2 ).zero? }
20
- end
21
-
22
- def block_check_multiple_arguments( a, b, c )
23
- check( a, b, c ){ |x| x.even? }
24
- end
25
-
26
- def lambda_argument_check( a )
27
- check_lambda = lambda{ |x| x.even? }
28
- check( a, check_lambda )
29
- end
30
-
31
- def lambda_block_check( a )
32
- check_lambda = lambda{ |x| x.even? }
33
- check( a, &check_lambda )
34
- end
35
- end
36
-
37
3
  class TestSimplecheck < MiniTest::Test
38
-
39
- def setup
40
- @foo = Foo.new
41
- end
4
+ include Simplecheck
42
5
 
43
6
  def test_expression_check_true
44
- assert( @foo.expression_check( 1 ))
7
+ assert( check( 1 ))
45
8
  end
46
9
 
47
10
  def test_expression_check_raises_exception
48
- assert_raises( Simplecheck::CheckFailed ){ @foo.expression_check( nil )}
11
+ assert_raises( Simplecheck::CheckFailed ){ check( nil )}
49
12
  end
50
13
 
51
14
  def test_case_equality_check_true
52
- assert( @foo.case_equality_check( 1 ))
15
+ assert( check( 1, Integer ))
53
16
  end
54
17
 
55
18
  def test_case_equality_check_raises_exception
56
- assert_raises( Simplecheck::CheckFailed ){ @foo.case_equality_check( '1' )}
19
+ assert_raises( Simplecheck::CheckFailed ){ check( '1', Integer )}
57
20
  end
58
21
 
59
22
  def test_case_equality_check_multiple_arguments
60
- assert( @foo.case_equality_check_multiple_arguments( 1, 2 ))
23
+ assert( check( 1, 2, Integer ))
61
24
  end
62
25
 
63
26
  def test_case_equality_check_multiple_arguments_raises_exception
64
- assert_raises( Simplecheck::CheckFailed ){ @foo.case_equality_check_multiple_arguments( 1, '2' )}
27
+ assert_raises( Simplecheck::CheckFailed ){ check( 1, '2', Integer )}
65
28
  end
66
29
 
67
30
  def test_block_check_true
68
- assert( @foo.block_check( 2 ))
31
+ assert( check( 1 ){ |n| n.odd? })
69
32
  end
70
33
 
71
34
  def test_block_check_raises_exception
72
- assert_raises( Simplecheck::CheckFailed ){ @foo.block_check( 1 )}
35
+ assert_raises( Simplecheck::CheckFailed ){ check( 1 ){ |n| n.even? }}
73
36
  end
74
37
 
75
38
  def test_block_check_multiple_arguments_true
76
- assert( @foo.block_check_multiple_arguments( 2, 2, 2 ))
39
+ assert( check( 1, 1, 1 ){ |n| n.odd? })
77
40
  end
78
41
 
79
42
  def test_block_check_multiple_arguments_exception
80
- assert_raises( Simplecheck::CheckFailed ){ @foo.block_check_multiple_arguments( 2, 2, 1 )}
43
+ assert_raises( Simplecheck::CheckFailed ){ check( 1, 1, 2 ){ |n| n.odd? }}
81
44
  end
82
45
 
83
46
  def test_lambda_argument_check_true
84
- assert( @foo.lambda_argument_check( 2 ))
47
+ assert( check( 1, ->(n){ n.odd? }))
85
48
  end
86
49
 
87
50
  def test_lambda_argument_check_raises_exception
88
- assert_raises( Simplecheck::CheckFailed ){ @foo.lambda_argument_check( 1 )}
51
+ assert_raises( Simplecheck::CheckFailed ){ check( 2, ->(n){ n.odd? })}
89
52
  end
90
53
 
91
54
  def test_lambda_block_check_true
92
- assert( @foo.lambda_block_check( 2 ))
55
+ assert( check( 1, &->(n){ n.odd? }))
93
56
  end
94
57
 
95
58
  def test_lambda_block_check_raises_exception
96
- assert_raises( Simplecheck::CheckFailed ){ @foo.lambda_block_check( 1 )}
59
+ assert_raises( Simplecheck::CheckFailed ){ check( 2, &->(n){ n.odd? })}
97
60
  end
98
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0rc1
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Farrel Lifson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple property checking for Ruby
14
14
  email:
@@ -47,9 +47,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>'
50
+ - - '>='
51
51
  - !ruby/object:Gem::Version
52
- version: 1.3.1
52
+ version: '0'
53
53
  requirements: []
54
54
  rubyforge_project: rcap
55
55
  rubygems_version: 2.0.3