activeldap 4.0.5 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +3 -1
  3. data/doc/text/development.md +26 -0
  4. data/doc/text/{news.textile → news.md} +451 -241
  5. data/doc/text/{rails.textile → rails.md} +44 -33
  6. data/doc/text/{tutorial.textile → tutorial.md} +177 -185
  7. data/lib/active_ldap/adapter/base.rb +40 -17
  8. data/lib/active_ldap/adapter/jndi.rb +21 -9
  9. data/lib/active_ldap/adapter/jndi_connection.rb +83 -20
  10. data/lib/active_ldap/adapter/ldap.rb +50 -28
  11. data/lib/active_ldap/adapter/ldap_ext.rb +32 -13
  12. data/lib/active_ldap/adapter/net_ldap.rb +26 -24
  13. data/lib/active_ldap/associations.rb +5 -5
  14. data/lib/active_ldap/attribute_methods/before_type_cast.rb +1 -1
  15. data/lib/active_ldap/attribute_methods/dirty.rb +4 -7
  16. data/lib/active_ldap/attribute_methods/query.rb +1 -1
  17. data/lib/active_ldap/attribute_methods/read.rb +5 -1
  18. data/lib/active_ldap/attribute_methods/write.rb +1 -1
  19. data/lib/active_ldap/attribute_methods.rb +1 -2
  20. data/lib/active_ldap/base.rb +61 -14
  21. data/lib/active_ldap/callbacks.rb +7 -8
  22. data/lib/active_ldap/configuration.rb +27 -3
  23. data/lib/active_ldap/connection.rb +4 -22
  24. data/lib/active_ldap/distinguished_name.rb +1 -1
  25. data/lib/active_ldap/human_readable.rb +5 -4
  26. data/lib/active_ldap/operations.rb +24 -4
  27. data/lib/active_ldap/persistence.rb +3 -2
  28. data/lib/active_ldap/populate.rb +5 -3
  29. data/lib/active_ldap/railties/controller_runtime.rb +1 -2
  30. data/lib/active_ldap/schema/syntaxes.rb +8 -4
  31. data/lib/active_ldap/validations.rb +12 -4
  32. data/lib/active_ldap/version.rb +1 -1
  33. data/lib/active_ldap.rb +0 -7
  34. data/po/en/active-ldap.po +2 -2
  35. data/po/ja/active-ldap.po +3 -3
  36. data/test/add-phonetic-attribute-options-to-slapd.ldif +3 -3
  37. data/test/al-test-utils.rb +125 -38
  38. data/test/command.rb +13 -16
  39. data/test/enable-dynamic-groups.ldif +22 -0
  40. data/test/enable-start-tls.ldif +27 -0
  41. data/test/run-test.rb +0 -4
  42. data/test/test_base.rb +223 -22
  43. data/test/test_base_per_instance.rb +33 -1
  44. data/test/test_callback.rb +10 -8
  45. data/test/test_connection.rb +4 -0
  46. data/test/test_connection_per_class.rb +34 -0
  47. data/test/test_dn.rb +7 -0
  48. data/test/test_entry.rb +1 -0
  49. data/test/test_find.rb +14 -3
  50. data/test/test_supported_control.rb +1 -1
  51. data/test/test_syntax.rb +5 -0
  52. data/test/test_validation.rb +28 -15
  53. metadata +23 -24
  54. data/README.textile +0 -141
  55. data/doc/text/development.textile +0 -54
  56. data/lib/active_ldap/timeout.rb +0 -75
  57. data/lib/active_ldap/timeout_stub.rb +0 -17
@@ -37,6 +37,15 @@ class TestValidation < Test::Unit::TestCase
37
37
  priority :must
38
38
 
39
39
  priority :normal
40
+ def test_validate_false
41
+ make_temporary_user(:simple => true) do |user,|
42
+ user.sn = nil
43
+ assert_raise(ActiveLdap::RequiredAttributeMissed) do
44
+ user.save(validate: false)
45
+ end
46
+ end
47
+ end
48
+
40
49
  def test_octet_string
41
50
  make_temporary_user(:simple => true) do |user,|
42
51
  utf8_encoded_binary_value = "\xff".force_encoding("UTF-8")
@@ -52,8 +61,8 @@ class TestValidation < Test::Unit::TestCase
52
61
  user1.id = user2.id
53
62
  assert_false(user1.save)
54
63
 
55
- format = la_('distinguishedName').humanize
56
- format << ' ' << _("is duplicated: %s")
64
+ format = human_attribute_name("distinguishedName")
65
+ format << " " << _("is duplicated: %s")
57
66
  assert_equal([format % [user2.dn.to_s]],
58
67
  user1.errors.full_messages)
59
68
  end
@@ -66,8 +75,8 @@ class TestValidation < Test::Unit::TestCase
66
75
  user.jpeg_photo = "XXX"
67
76
  assert_not_predicate(user, :save)
68
77
 
69
- format = la_('jpegPhoto').humanize
70
- format << ' ' << _("has invalid format: %s: required syntax: %s: %s")
78
+ format = human_attribute_name('jpegPhoto')
79
+ format << " " << _("has invalid format: %s: required syntax: %s: %s")
71
80
  arguments = [_("<binary-value>"),
72
81
  lsd_("1.3.6.1.4.1.1466.115.121.1.28"),
73
82
  _("invalid JPEG format")]
@@ -112,8 +121,8 @@ class TestValidation < Test::Unit::TestCase
112
121
  reason = _("attribute value is missing")
113
122
  invalid_format = _("%s is invalid distinguished name (DN): %s")
114
123
  invalid_message = invalid_format % ["uid==,#{user.class.base}", reason]
115
- format = la_('distinguishedName').humanize
116
- format << ' ' << _("is invalid: %s")
124
+ format = human_attribute_name("distinguishedName")
125
+ format << " " << _("is invalid: %s")
117
126
  message = format % invalid_message
118
127
  assert_equal([message],
119
128
  user.errors.full_messages.find_all {|m| /DN/ =~ m})
@@ -126,8 +135,8 @@ class TestValidation < Test::Unit::TestCase
126
135
  reason = _("attribute value is missing")
127
136
  invalid_format = _("%s is invalid distinguished name (DN): %s")
128
137
  invalid_message = invalid_format % ["uid==,#{user.class.base}", reason]
129
- format = la_('distinguishedName').humanize
130
- format << ' ' << _("is invalid: %s")
138
+ format = human_attribute_name("distinguishedName")
139
+ format << " " << _("is invalid: %s")
131
140
  message = format % invalid_message
132
141
  assert_equal([message], user.errors.full_messages)
133
142
  end
@@ -138,8 +147,8 @@ class TestValidation < Test::Unit::TestCase
138
147
  assert(user.valid?)
139
148
  user.uid_number = ""
140
149
  assert(!user.valid?)
141
- format = la_('uidNumber').humanize
142
- format << ' ' << _("is required attribute by objectClass '%s'")
150
+ format = human_attribute_name("uidNumber")
151
+ format << " " << _("is required attribute by objectClass '%s'")
143
152
  blank_message = format % loc_("posixAccount")
144
153
  assert_equal([blank_message], user.errors.full_messages)
145
154
  end
@@ -150,8 +159,8 @@ class TestValidation < Test::Unit::TestCase
150
159
  assert(user.save)
151
160
  user.class.excluded_classes = ['person']
152
161
  assert(!user.save)
153
- format = la_("objectClass").humanize
154
- format << ' ' << n_("has excluded value: %s",
162
+ format = human_attribute_name("objectClass")
163
+ format << " " << n_("has excluded value: %s",
155
164
  "has excluded values: %s",
156
165
  1)
157
166
  message = format % loc_("person")
@@ -222,8 +231,8 @@ class TestValidation < Test::Unit::TestCase
222
231
  assert(ou_class.new("YYY").save)
223
232
  ou = ou_class.new("YYY")
224
233
  assert(!ou.save)
225
- format = la_("distinguishedName").humanize
226
- format << ' ' << _("is duplicated: %s")
234
+ format = human_attribute_name("distinguishedName")
235
+ format << " " << _("is duplicated: %s")
227
236
  message = format % ou.dn
228
237
  assert_equal([message], ou.errors.full_messages)
229
238
  end
@@ -259,12 +268,16 @@ class TestValidation < Test::Unit::TestCase
259
268
  end
260
269
 
261
270
  private
271
+ def human_attribute_name(name)
272
+ la_(name).dup
273
+ end
274
+
262
275
  def assert_invalid_value(name, formatted_value, syntax, reason, model, option)
263
276
  syntax_description = lsd_(syntax)
264
277
  assert_not_nil(syntax_description)
265
278
  params = [formatted_value, syntax_description, reason]
266
279
  params.unshift(option) if option
267
- localized_name = la_(name).humanize
280
+ localized_name = human_attribute_name(name)
268
281
  format = localized_name << ' '
269
282
  if option
270
283
  format << _("(%s) has invalid format: %s: required syntax: %s: %s")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Drewry
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-20 00:00:00.000000000 Z
12
+ date: 2020-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.0.0
20
+ version: '5.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 4.0.0
27
+ version: '5.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: locale
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -68,13 +68,13 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: bundler
71
+ name: builder
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
- type: :development
77
+ type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rake
85
+ name: bundler
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: test-unit
99
+ name: kramdown
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -110,7 +110,7 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: test-unit-notify
113
+ name: packnga
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: yard
127
+ name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - ">="
@@ -138,7 +138,7 @@ dependencies:
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
- name: RedCloth
141
+ name: test-unit
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - ">="
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: packnga
155
+ name: yard
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
@@ -182,16 +182,15 @@ files:
182
182
  - COPYING
183
183
  - Gemfile
184
184
  - LICENSE
185
- - README.textile
186
185
  - TODO
187
186
  - benchmark/README.md
188
187
  - benchmark/bench-backend.rb
189
188
  - benchmark/bench-instantiate.rb
190
189
  - benchmark/config.yaml.sample
191
- - doc/text/development.textile
192
- - doc/text/news.textile
193
- - doc/text/rails.textile
194
- - doc/text/tutorial.textile
190
+ - doc/text/development.md
191
+ - doc/text/news.md
192
+ - doc/text/rails.md
193
+ - doc/text/tutorial.md
195
194
  - examples/config.yaml.example
196
195
  - examples/example.der
197
196
  - examples/example.jpg
@@ -265,8 +264,6 @@ files:
265
264
  - lib/active_ldap/schema.rb
266
265
  - lib/active_ldap/schema/syntaxes.rb
267
266
  - lib/active_ldap/supported_control.rb
268
- - lib/active_ldap/timeout.rb
269
- - lib/active_ldap/timeout_stub.rb
270
267
  - lib/active_ldap/user_password.rb
271
268
  - lib/active_ldap/validations.rb
272
269
  - lib/active_ldap/version.rb
@@ -282,6 +279,8 @@ files:
282
279
  - test/al-test-utils.rb
283
280
  - test/command.rb
284
281
  - test/config.yaml.sample
282
+ - test/enable-dynamic-groups.ldif
283
+ - test/enable-start-tls.ldif
285
284
  - test/fixtures/lower_case_object_class_schema.rb
286
285
  - test/run-test.rb
287
286
  - test/test_acts_as_tree.rb
@@ -346,8 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
346
345
  - !ruby/object:Gem::Version
347
346
  version: '0'
348
347
  requirements: []
349
- rubyforge_project: ruby-activeldap
350
- rubygems_version: 2.4.5.1
348
+ rubygems_version: 3.2.0.rc.2
351
349
  signing_key:
352
350
  specification_version: 4
353
351
  summary: ActiveLdap is a object-oriented API to LDAP
@@ -356,6 +354,8 @@ test_files:
356
354
  - test/al-test-utils.rb
357
355
  - test/command.rb
358
356
  - test/config.yaml.sample
357
+ - test/enable-dynamic-groups.ldif
358
+ - test/enable-start-tls.ldif
359
359
  - test/fixtures/lower_case_object_class_schema.rb
360
360
  - test/run-test.rb
361
361
  - test/test_acts_as_tree.rb
@@ -400,4 +400,3 @@ test_files:
400
400
  - test/test_usermod-lang-add.rb
401
401
  - test/test_usermod.rb
402
402
  - test/test_validation.rb
403
- has_rdoc:
data/README.textile DELETED
@@ -1,141 +0,0 @@
1
- h1. ActiveLdap
2
-
3
- A ruby library for object-oriented LDAP interface.
4
-
5
- * Copyright (C) 2004-2006 Will Drewry _<will@alum.bu.edu>_
6
- * Copyright (C) 2006-2013 Kouhei Sutou _<kou@clear-code.com>_
7
-
8
- h2. Description
9
-
10
- 'ActiveLdap' is a ruby library which provides a clean
11
- objected oriented interface to LDAP library. It was
12
- inspired by ActiveRecord. This is not nearly as clean or as
13
- flexible as ActiveRecord, but it is still trivial to define
14
- new objects and manipulate them with minimal difficulty.
15
-
16
- For example and usage - read the
17
- "document":http://activeldap.github.io/.
18
-
19
- h2. Prerequisites
20
-
21
- - Ruby intepreter :=
22
- One of them:
23
- * "Ruby":http://www.ruby-lang.org (1.9.3 or 2.0.x)
24
- * "JRuby":http://www.jruby.org/
25
-
26
- See the above links for installation.
27
- =:
28
- - LDAP client :=
29
- JRuby doesn't need to install new library because JRuby
30
- has builtin LDAP support. Ruby users need one of them:
31
-
32
- * "Ruby/LDAP":http://ruby-ldap.sourceforge.net/
33
- * "Net::LDAP":http://rubyldap.com/
34
-
35
- See the above links for installation.
36
- =:
37
- - ActiveModel :=
38
- A toolkit for building modeling frameworks like Active
39
- Record and Active Resource.
40
- =:
41
-
42
- h2. Notes
43
-
44
- * Only GSSAPI SASL support exists due to Ruby/LDAP limitations
45
-
46
- h2. Rails
47
-
48
- See "Rails":file.rails.html ("doc/text/rails.textile":doc/text/rails.textile
49
- in the repository and on GitHub) page for Rails integration.
50
-
51
- h2. Licence
52
-
53
- This program is free software; you can redistribute it and/or modify it. It is
54
- dual licensed under Ruby's license and under the terms of the GNU General
55
- Public License as published by the Free Software Foundation; either version 2,
56
- or (at your option) any later version.
57
-
58
- Please see the file LICENSE for the terms of the licence.
59
-
60
- h2. Thanks
61
-
62
- This list may not be correct. If you notice mistakes of this
63
- list, please point out.
64
-
65
- * Dick Davies
66
- * Nathan Kinder
67
- * Patrick Cole
68
- * Google Inc.
69
- * Nobody: Bug reports and API improveent ideas.
70
- * James Hughes: Bug reports and advices and documentations.
71
- * Buzz Chopra: Documentations.
72
- * Christoph Lipp:
73
- ** Bug reports.
74
- ** Tell us character escape syntax.
75
- * Jeff Hall: Bug reports.
76
- * Ernie Miller: Bug reports and advices.
77
- * Daniel Pfile: Patches.
78
- * Jacob Wilkins: Bug reports.
79
- * Ace Suares:
80
- ** Bug reports.
81
- ** Nederlands translations.
82
- * Iain Pople: Bug reports and API improvement ideas.
83
- * Kevin McCarthy: Patches.
84
- * Perry Smith: Patches, bug reports and indications.
85
- * Marc Dequènes: API suggestions.
86
- * Jeremy Pruitt: Bug reports.
87
- * Bodaniel Jeanes:
88
- ** A suggestion for behavior on simple bind with empty password.
89
- ** Bug reports.
90
- * Naoto Morishima: Bug reports.
91
- * David Morton:
92
- ** An API improvement idea.
93
- ** Bug reports.
94
- * Lennon Day-Reynolds: Bug reports.
95
- * Tilo: A bug report.
96
- * Matt Mencel: Bug reports.
97
- * CultureSpy:
98
- ** Bug reports.
99
- ** Bug fixes.
100
- * gwarf12: A bug report.
101
- * Baptiste Grenier: API improvement ideas.
102
- * Richard 3 Nicholas: API improvement ideas.
103
- * Kazuhiro NISHIYAMA: A bug report.
104
- * Grzegorz Marszałek: A bug report.
105
- * しまさわらさん: A suggesetion.
106
- * Ted Lepich: A suggestion.
107
- * danger1986: A suggestion.
108
- * michael.j.konopka: Bug reports.
109
- * ingersoll: A suggestion.
110
- * Alexey.Chebotar: Bug reports.
111
- * ery.lee: A bug report.
112
- * id:dicdak: A bug report.
113
- * Raiko Mitsu: A bug report.
114
- * Kazuaki Takase: Documents in Japanese.
115
- * Tim Hermans: A bug report.
116
- * Joe Francis: A suggestion.
117
- * Tiago Fernandes: Bug reports.
118
- * achemze: A suggestion.
119
- * George Montana Harkin: A suggestion.
120
- * Marc Dequènes: Bug reports.
121
- * brad@lucky-dip.net: A bug report.
122
- * Hideyuki Yasuda: Bug reports.
123
- * zachwily: A bug report.
124
- * syrius.ml@no-log.org: A bug report.
125
- * Tim Hermans: A bug report.
126
- * Anthony M. Martinez: Helped SASL options support
127
- * ilusi0n.x: A bug report.
128
- * projekttabla: A suggestion.
129
- * christian.pennaforte: A bug report.
130
- * planetmcd: A bug report.
131
- * spoidar: Rails 3 support.
132
- * Kris Wehner: Rails 2.3.8 support.
133
- * Ryan Tandy:
134
- ** A test bug fix.
135
- ** Rails 3 support.
136
- * rbq: A bug report.
137
- * Narihiro Nakamura: Rails 3 support.
138
- * Hidetoshi Yoshimoto: Rails 3 support.
139
- * warden: A bug report.
140
- * bklier: A bug fix.
141
- * Craig White: Bug reports.
@@ -1,54 +0,0 @@
1
- h1. Development
2
-
3
- Here is information for developers.
4
-
5
- h2. Repository
6
-
7
- ActiveLdap uses ["git repository on
8
- GitHub":https://github.com/activeldap]. Here is a
9
- list to get each source code.
10
-
11
- - "activeldap":https://github.com/activeldap/activeldap :=
12
- <pre class="command">
13
- % git clone https://github.com/activeldap/activeldap.git
14
- </pre>
15
- =:
16
- - "al-admin":https://github.com/activeldap/al-admin :=
17
- <pre class="command">
18
- % git clone https://github.com/activeldap/al-admin.git
19
- </pre>
20
- =:
21
-
22
- h2. Issues
23
-
24
- ActiveLdap uses "Issues on
25
- GitHub":https://github.com/activeldap/activeldap/issues for
26
- issue tracking. Please submit a issue when you find an
27
- issue.
28
-
29
- h2. Rails 3 support
30
-
31
- Here is design about Rails 3 support.
32
-
33
- h3. must
34
-
35
- * We add active_ldap/test_help.rb to support ActiveLdap fixture.
36
- We don't write same codes into test_helper.rb like
37
- http://ruby-activeldap.rubyforge.org/activeldap-fabrication/en/#Install
38
-
39
- h3. may
40
-
41
- * We support Warden.
42
- * We support Devise
43
- * We support OmniAuth. (instead of Warden)
44
-
45
- h3. DONE
46
-
47
- * We don't support Rails 3.0.x.
48
- * We provide active_ldap/railtie to initialize ActiveLdap.
49
- * We remove ActiveRecord dependency.
50
- * We depend on ActiveModel instead of ActiveRecord.
51
- * We target to Rails 3.1.0. (Yes, it's not released yet
52
- but it will be released before we support Rails 3.x.)
53
- * We update the documentation and ensure that the procedure
54
- for including ActiveLdap in a Rails 3 project is correct.
@@ -1,75 +0,0 @@
1
- require 'timeout'
2
-
3
- module Timeout
4
-
5
- # A forking timeout implementation that relies on
6
- # signals to interrupt blocking I/O instead of passing
7
- # that code to run in a separate process.
8
- #
9
- # A process is fork()ed, sleeps for _sec_,
10
- # then sends a ALRM signal to the Process.ppid
11
- # process. ALRM is used to avoid conflicts with sleep()
12
- #
13
- # This overwrites any signal
14
- def Timeout.alarm(sec, exception=Timeout::Error, &block)
15
- return block.call if sec == nil or sec.zero?
16
-
17
-
18
- # Trap an alarm in case it comes before we're ready
19
- orig_alrm = trap(:ALRM, 'IGNORE')
20
-
21
- # Setup a fallback in case of a race condition of an
22
- # alarm before we set the other trap
23
- trap(:ALRM) do
24
- # Don't leave zombies
25
- Process.wait2()
26
- # Restore the original handler
27
- trap('ALRM', orig_alrm)
28
- # Now raise an exception!
29
- raise exception, 'execution expired'
30
- end
31
-
32
- # Spawn the sleeper
33
- pid = Process.fork {
34
- begin
35
- # Sleep x seconds then send SIGALRM
36
- sleep(sec)
37
- # Send alarm!
38
- Process.kill(:ALRM, Process.ppid)
39
- end
40
- exit! 0
41
- }
42
-
43
- # Setup the real handler
44
- trap(:ALRM) do
45
- # Make sure we clean up any zombies
46
- Process.waitpid(pid)
47
- # Restore the original handler
48
- trap(:ALRM, orig_alrm)
49
- # Now raise an exception!
50
- raise exception, 'execution expired'
51
- end
52
-
53
- begin
54
- # Run the code!
55
- return block.call
56
- ensure
57
- # Restore old alarm handler since we're done
58
- trap(:ALRM, orig_alrm)
59
- # Make sure the process is dead
60
- # This may be run twice (trap occurs during execution) so ignore ESRCH
61
- Process.kill(:TERM, pid) rescue Errno::ESRCH
62
- # Don't leave zombies
63
- Process.waitpid(pid) rescue Errno::ECHILD
64
- end
65
- end
66
- end # Timeout
67
-
68
- if __FILE__ == $0
69
- require 'time'
70
- Timeout.alarm(2) do
71
- loop do
72
- p Time.now
73
- end
74
- end
75
- end
@@ -1,17 +0,0 @@
1
- require 'timeout'
2
-
3
- module Timeout
4
- # STUB
5
- def Timeout.alarm(sec, exception=Timeout::Error, &block)
6
- timeout(sec, exception, &block)
7
- end
8
- end # Timeout
9
-
10
- if __FILE__ == $0
11
- require 'time'
12
- Timeout.alarm(2) do
13
- loop do
14
- p Time.now
15
- end
16
- end
17
- end