capped 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/capped.rb +47 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 922a8cc12f8fa9373f80a0b247ae74088ba957fd
4
+ data.tar.gz: 490db2d77076e8c179a7d60da2115d32a7ef0d05
5
+ SHA512:
6
+ metadata.gz: 7d99738a5b5a5bf7717587f835a348d3f8903a69b0c7eb63122c5d79f864afd05e69738673498201d9778a9f30c96b3317aad2544ddfcb252afa5ac0c5c36e72
7
+ data.tar.gz: bd76e768c5804ebefb9b93189c15594eca9cb038194354ca32e17a40d1468d814118657f51cdd150c6911b4c7a853f5bd74515ee17f14e121cabd33658cd35f6
data/lib/capped.rb ADDED
@@ -0,0 +1,47 @@
1
+
2
+ module Capped
3
+
4
+ class LimitExceededError < StandardError
5
+ attr_reader :limit
6
+
7
+ def initialize(msg, limit)
8
+ super(msg)
9
+ @limit = limit
10
+ end
11
+ end
12
+
13
+
14
+ def capped_while(limit, condition_proc)
15
+ countdown = limit
16
+ while condition_proc.call
17
+ countdown -= 1
18
+ if countdown < 0
19
+ raise LimitExceededError.new("Condition not met after #{limit} iterations", limit)
20
+ end
21
+ yield
22
+ end
23
+ end
24
+ module_function :capped_while
25
+
26
+
27
+
28
+ def capped_until(limit, condition_proc)
29
+ countdown = limit
30
+ until condition_proc.call
31
+ countdown -= 1
32
+ if countdown < 0
33
+ raise LimitExceededError.new("Condition not met after #{limit} iterations", limit)
34
+ end
35
+ yield
36
+ end
37
+ end
38
+ module_function :capped_until
39
+
40
+
41
+
42
+ class << self
43
+ alias_method :while, :capped_while
44
+ alias_method :until, :capped_until
45
+ end
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capped
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.alpha.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Lauber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Place a cap on your potentially infinite loops
14
+ email: constructible.truth@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/capped.rb
20
+ homepage: https://github.com/briandamaged/capped
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">"
35
+ - !ruby/object:Gem::Version
36
+ version: 1.3.1
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.2.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Place a cap on your potentially infinite loops
43
+ test_files: []