simplecheck 0.9 → 1.0rc1

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: 2b4972b81b875d8ee3c78f8cf807c36aeffb5f5d
4
- data.tar.gz: 8a5397331cdce47a1dc42f8eb696d0cbc718b18d
3
+ metadata.gz: a928fd88137669a29e16e814e1d21af7e6403f3f
4
+ data.tar.gz: 547b3655c4efdbf9ab4e1ef019f51fcc224c537f
5
5
  SHA512:
6
- metadata.gz: 99c1b54c9c1f3b319835e271ead32230fe82ac592896760841afe812fef13ec5a2f8c93397c1ed44ef78969eac362de415267778c6f89c23b39e0be0ea50445e
7
- data.tar.gz: ef92f00f785240a4279a6888780a5426fa2b76424a35b8a7c7f4354c321349da3ba7e7453934b380cca20e2d5ea34a021a7e042529b81b0daf25b74558ce780f
6
+ metadata.gz: c77b199bbbc3308e07b0348f6f7c013cc473376b62930a715ba31b249cff9a55f291cfcb658d8c756c5f929abf0a63bd453f1524a85397619b20535ab98f9ea8
7
+ data.tar.gz: 1cb867dc97e7dba604956d0432198304990be0d0a024deca114350a47c263a75c41d1a38260ab3e663a133d2fdebcd0c9e00b84ef08eb548df6d8907b247bf3e
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  Simplecheck
2
2
  ===========
3
3
 
4
- Simplecheck is a property checking API for Ruby designed for quickly checking arguments. Once included into a class it provides the `check` instance method which takes a list of arguments and a condition to check them against.
4
+ 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
5
 
6
- If a check fails an exception of type `Simplecheck::CheckFailed` is raised.
6
+ If a check fails a `Simplecheck::CheckFailed` exception is raised.
7
7
 
8
8
  Usage
9
9
  -----
@@ -37,15 +37,24 @@ Simplecheck currently supports three different check methods:
37
37
 
38
38
  ### Expression Check
39
39
 
40
- In the simplest case `check` takes an expression as an argument. If the expression evaluates to `nil` or `false` it will fail.
40
+ In the simplest case `check` takes an expression as an argument. If the expression evaluates to `nil` or `false` it will fail.
41
41
 
42
- check( a > 2 )
42
+ def calculate_percentage( score, total )
43
+ check( total > 0 )
44
+ 100.0 * score / total
45
+ end
43
46
 
44
47
  ### Case Equality (===) Check
45
48
 
46
49
  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.
47
50
 
48
- 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. If a class does not alias or implement it's own version of `===` it has the same functionality as `==`.
51
+ def greatest_common_divisor( a, b )
52
+ check( a, b, Numeric )
53
+ # GCD Algorithm
54
+ end
55
+
56
+ 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.
57
+
49
58
 
50
59
  #### Class
51
60
 
@@ -69,7 +78,7 @@ If a class does not alias or implement it's own version of `===` it has the same
69
78
 
70
79
  `===` is aliased to `call`:
71
80
 
72
- check( password, password_confirmation, lambda{ |pwd| !Dictionary.check( pwd )})
81
+ check( password, password_confirmation , ->(p){ !Dict.lookup( p )})
73
82
 
74
83
  #### Custom Check Object
75
84
 
@@ -84,7 +93,7 @@ For example to check whether a set of points is inside a given polygon we would
84
93
  A block can be passed to `check`, with the arguments passed to `check` then passed individually to the block:
85
94
 
86
95
  check( a, b, c ) do |n|
87
- n.modulo?(2).zero?
96
+ n.odd?
88
97
  end
89
98
 
90
99
  This is syntactic sugar for the Proc Case Equality check.
@@ -94,6 +103,11 @@ Multiple Arguments
94
103
 
95
104
  Case Equality and Block checks can be called with multiple arguments, with each argument being checked individually against the condition:
96
105
 
106
+ check( i, j, k, Integer )
107
+ check( a, b, c ) do |n|
108
+ n.even?
109
+ end
110
+
97
111
  License
98
112
  -------
99
113
  Simplecheck is released under the BSD License.
@@ -1,4 +1,5 @@
1
1
  require 'simplecheck'
2
+
2
3
  include Simplecheck
3
4
 
4
5
  check( 1.odd? )
@@ -1,4 +1,5 @@
1
1
  require 'simplecheck'
2
+
2
3
  include Simplecheck
3
4
 
4
5
  # Block passed implicitly to check
@@ -1,4 +1,5 @@
1
1
  require 'simplecheck'
2
+
2
3
  include Simplecheck
3
4
 
4
5
  # Class#=== -> Class#kind_of?
data/lib/simplecheck.rb CHANGED
@@ -4,55 +4,40 @@ require 'simplecheck/check_failed'
4
4
  module Simplecheck
5
5
  def check( *arguments, &block )
6
6
  error_message = if block_given?
7
- __check_arguments_with_block( arguments, block )
7
+ Simplecheck.check_arguments_with_block( arguments, block )
8
8
  else
9
- __check_arguments( arguments )
9
+ Simplecheck.check_arguments( arguments )
10
10
  end
11
11
 
12
- if error_message
13
- __handle_failure( error_message )
14
- else
15
- __handle_return_arguments( arguments )
16
- end
12
+ error_message ? Simplecheck.handle_failure( error_message ) : true
17
13
  end
18
14
 
19
-
20
- private
21
- def __check_arguments( arguments )
15
+ def Simplecheck.check_arguments( arguments )
22
16
  case arguments.size
23
17
  when 1
24
- __check_expression( arguments[ 0 ])
18
+ Simplecheck.check_expression( arguments[ 0 ])
25
19
  else
26
- __check_case_equality( *arguments )
20
+ Simplecheck.check_case_equality( *arguments )
27
21
  end
28
22
  end
29
23
 
30
- def __check_arguments_with_block( arguments, block )
31
- __check_arguments(( arguments + [ block ]))
24
+ def Simplecheck.check_arguments_with_block( arguments, block )
25
+ Simplecheck.check_arguments(( arguments + [ block ]))
32
26
  end
33
27
 
34
- def __check_expression( expression )
28
+ def Simplecheck.check_expression( expression )
35
29
  if !expression
36
- 'Condition is not true'
30
+ 'Condition is not satisfied'
37
31
  end
38
32
  end
39
33
 
40
- def __check_case_equality( *arguments, receiver )
41
- if invalid_argument = arguments.find{ |argument| !( receiver === argument )}
42
- "#{ invalid_argument } does not satisfy #{ receiver }"
34
+ def Simplecheck.check_case_equality( *arguments, check_argument )
35
+ if invalid_argument = arguments.find{ |argument| !( check_argument === argument )}
36
+ "#{ invalid_argument } does not satisfy #{ check_argument }"
43
37
  end
44
38
  end
45
39
 
46
- def __handle_failure( message )
40
+ def Simplecheck.handle_failure( message )
47
41
  raise Simplecheck::CheckFailed.new( message )
48
42
  end
49
-
50
- def __handle_return_arguments( arguments )
51
- case arguments.size
52
- when 1
53
- arguments[0]
54
- else
55
- arguments
56
- end
57
- end
58
43
  end
@@ -1,3 +1,3 @@
1
1
  module Simplecheck
2
- VERSION = '0.9'
2
+ VERSION = '1.0rc1'
3
3
  end
data/simplecheck.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['Farrel Lifson']
10
10
  s.email = ['farrel.lifson@aimred.com']
11
- s.homepage = 'http://www.aimred.com/projects/simplecheck'
11
+ s.homepage = 'http://github.com/farrel/simplecheck'
12
12
  s.summary = 'Simple property checking for Ruby'
13
13
  s.description = 'Simple property checking for Ruby'
14
14
 
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: '0.9'
4
+ version: 1.0rc1
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-04 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple property checking for Ruby
14
14
  email:
@@ -33,7 +33,7 @@ files:
33
33
  - simplecheck.gemspec
34
34
  - test/simplecheck_test.rb
35
35
  - test/test_helper.rb
36
- homepage: http://www.aimred.com/projects/simplecheck
36
+ homepage: http://github.com/farrel/simplecheck
37
37
  licenses: []
38
38
  metadata: {}
39
39
  post_install_message:
@@ -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: '0'
52
+ version: 1.3.1
53
53
  requirements: []
54
54
  rubyforge_project: rcap
55
55
  rubygems_version: 2.0.3