must_be 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md ADDED
@@ -0,0 +1,7 @@
1
+ # dynamic_variable 1.0.2 2010-09-29
2
+
3
+ * Update for compatibility with Ruby 1.8.6.
4
+
5
+ # must_be 1.0.1 2010-09-27
6
+
7
+ * Update for compatibility with Ruby 1.9.2.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
data/lib/must_be/basic.rb CHANGED
@@ -6,14 +6,14 @@ module MustBe
6
6
 
7
7
  def must_be(*cases)
8
8
  unless cases.empty? ? self : MustBe.match_any_case?(self, cases)
9
- must_notify(self, __method__, cases, nil, ", but matches #{self.class}")
9
+ must_notify(self, :must_be, cases, nil, ", but matches #{self.class}")
10
10
  end
11
11
  self
12
12
  end
13
13
 
14
14
  def must_not_be(*cases)
15
15
  if cases.empty? ? self : MustBe.match_any_case?(self, cases)
16
- must_notify(self, __method__, cases, nil, ", but matches #{self.class}")
16
+ must_notify(self, :must_not_be, cases, nil, ", but matches #{self.class}")
17
17
  end
18
18
  self
19
19
  end
@@ -41,17 +41,17 @@ private
41
41
  public
42
42
 
43
43
  def must_be_a(*modules)
44
- must_be_a__body(modules, :none?, __method__)
44
+ must_be_a__body(modules, :none?, :must_be_a)
45
45
  end
46
46
 
47
47
  def must_not_be_a(*modules)
48
- must_be_a__body(modules, :any?, __method__)
48
+ must_be_a__body(modules, :any?, :must_not_be_a)
49
49
  end
50
50
 
51
51
  def must_be_in(*collection)
52
52
  cs = collection.size == 1 ? collection[0] : collection
53
53
  unless cs.include? self
54
- must_notify(self, __method__, collection)
54
+ must_notify(self, :must_be_in, collection)
55
55
  end
56
56
  self
57
57
  end
@@ -59,34 +59,34 @@ public
59
59
  def must_not_be_in(*collection)
60
60
  cs = collection.size == 1 ? collection[0] : collection
61
61
  if cs.include? self
62
- must_notify(self, __method__, collection)
62
+ must_notify(self, :must_not_be_in, collection)
63
63
  end
64
64
  self
65
65
  end
66
66
 
67
67
  def must_be_nil
68
- must_notify(self, __method__) unless nil?
68
+ must_notify(self, :must_be_nil) unless nil?
69
69
  self
70
70
  end
71
71
 
72
72
  def must_not_be_nil
73
- must_notify(self, __method__) if nil?
73
+ must_notify(self, :must_not_be_nil) if nil?
74
74
  self
75
75
  end
76
76
 
77
77
  def must_be_true
78
- must_notify(self, __method__) unless self == true
78
+ must_notify(self, :must_be_true) unless self == true
79
79
  self
80
80
  end
81
81
 
82
82
  def must_be_false
83
- must_notify(self, __method__) unless self == false
83
+ must_notify(self, :must_be_false) unless self == false
84
84
  self
85
85
  end
86
86
 
87
87
  def must_be_boolean
88
88
  unless self == true or self == false
89
- must_notify(self, __method__)
89
+ must_notify(self, :must_be_boolean)
90
90
  end
91
91
  self
92
92
  end
@@ -94,7 +94,7 @@ public
94
94
  def must_be_close(expected, delta = 0.1)
95
95
  difference = (self - expected).abs
96
96
  unless difference < delta
97
- must_notify(self, __method__, [expected, delta], nil,
97
+ must_notify(self, :must_be_close, [expected, delta], nil,
98
98
  ", difference is #{difference}")
99
99
  end
100
100
  self
@@ -102,7 +102,7 @@ public
102
102
 
103
103
  def must_not_be_close(expected, delta = 0.1)
104
104
  if (self - expected).abs < delta
105
- must_notify(self, __method__, [expected, delta])
105
+ must_notify(self, :must_not_be_close, [expected, delta])
106
106
  end
107
107
  self
108
108
  end
@@ -152,13 +152,15 @@ module MustBe
152
152
  module ClassMethods
153
153
  def must_check_contents_after(*methods)
154
154
  methods.each do |method|
155
- define_method(method) do |*args, &block|
156
- begin
157
- super(*args, &block)
158
- ensure
159
- must_check_contents
155
+ module_eval %Q{
156
+ def #{method}(*args)
157
+ begin
158
+ super
159
+ ensure
160
+ must_check_contents
161
+ end
160
162
  end
161
- end
163
+ }
162
164
  end
163
165
  end
164
166
  end
@@ -231,15 +233,18 @@ module MustBe
231
233
 
232
234
  mutator_advice = Module.new
233
235
  mod.instance_methods(false).each do |method_name|
234
- mutator_advice.send(:define_method, method_name) do |*args, &block|
235
- must_check(lambda { super(*args, &block) }) do |note|
236
- note.prefix = nil
237
- call_s = Note.new(self.class, method_name, args, block).message
238
- call_s.sub!(".", "#")
239
- note.prefix = "#{must_only_ever_contain_prefix}#{call_s}: "
240
- note
236
+ mutator_advice.module_eval %Q{
237
+ def #{method_name}(*args, &block)
238
+ must_check(lambda { super(*args, &block) }) do |note|
239
+ note.prefix = nil
240
+ call_s = Note.new(self.class, #{method_name.inspect}, args,
241
+ block).message
242
+ call_s.sub!(".", "#")
243
+ note.prefix = "\#{must_only_ever_contain_prefix}\#{call_s}: "
244
+ note
245
+ end
241
246
  end
242
- end
247
+ }
243
248
  end
244
249
  mod.const_set(:MutatorAdvice, mutator_advice)
245
250
  mod.instance_eval do
data/lib/must_be/proxy.rb CHANGED
@@ -36,7 +36,7 @@ module MustBe
36
36
  if message
37
37
  must_notify(message)
38
38
  else
39
- must_notify(self, __method__, nil, block)
39
+ must_notify(self, :must, nil, block)
40
40
  end
41
41
  end
42
42
  self
@@ -51,7 +51,7 @@ module MustBe
51
51
  if message
52
52
  must_notify(message)
53
53
  else
54
- must_notify(self, __method__, nil, block)
54
+ must_notify(self, :must_not, nil, block)
55
55
  end
56
56
  end
57
57
  self
data/lib/must_be.rb CHANGED
@@ -1,5 +1,55 @@
1
1
  here = File.expand_path(File.dirname(__FILE__))
2
2
 
3
+ if RUBY_VERSION < "1.8.7"
4
+ unless :symbol.respond_to? :to_proc
5
+ class Symbol
6
+ def to_proc
7
+ Proc.new {|*args| args.shift.__send__ self, *args}
8
+ end
9
+ end
10
+ end
11
+
12
+ unless "string".respond_to? :bytesize
13
+ class String
14
+ alias bytesize size
15
+ end
16
+ end
17
+
18
+ unless [].respond_to? :none?
19
+ class Array
20
+ def none?(&block)
21
+ not any?(&block)
22
+ end
23
+ end
24
+ end
25
+
26
+ unless [].respond_to? :drop_while
27
+ class Array
28
+ def drop_while
29
+ index = 0
30
+ index += 1 while yield(self[index])
31
+ self[index..-1]
32
+ end
33
+ end
34
+ end
35
+
36
+ unless 3.respond_to? :odd?
37
+ class Fixnum
38
+ def odd?
39
+ self % 2 == 1
40
+ end
41
+ end
42
+ end
43
+
44
+ unless 3.respond_to? :even?
45
+ class Fixnum
46
+ def even?
47
+ self % 2 == 0
48
+ end
49
+ end
50
+ end
51
+ end
52
+
3
53
  require here+'/must_be/core'
4
54
  require here+'/must_be/basic'
5
55
  require here+'/must_be/proxy'
data/must_be.gemspec CHANGED
@@ -5,18 +5,20 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{must_be}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["William Taysom"]
12
- s.date = %q{2010-09-27}
12
+ s.date = %q{2010-09-29}
13
13
  s.description = %q{must_be provides runtime assertions which can easily be disabled in production environments. Likewise, the notifier can be customized to raise errors, log failure, enter the debugger, or anything else.}
14
14
  s.email = %q{wtaysom@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "README.md"
16
+ "ChangeLog.md",
17
+ "README.md"
17
18
  ]
18
19
  s.files = [
19
20
  ".gitignore",
21
+ "ChangeLog.md",
20
22
  "README.md",
21
23
  "Rakefile",
22
24
  "VERSION",
@@ -607,9 +607,7 @@ describe MustBe do
607
607
  it "should notify if inserting a non-matching key" do
608
608
  subject["six"] = 6
609
609
  subject["six"].should == 6
610
- should notify("must_only_ever_contain: Hash#[]=(\"six\", 6):"\
611
- " pair {\"six\"=>6} does not match"\
612
- " [{Symbol=>Integer, Integer=>Symbol}] in container {\"six\"=>6}")
610
+ should notify
613
611
  end
614
612
 
615
613
  it "should notify if inserting a matching value" do
@@ -634,9 +632,7 @@ describe MustBe do
634
632
 
635
633
  it "should notify if merged with an unacceptable hash" do
636
634
  subject.merge!({3 => 1})
637
- should notify("must_only_ever_contain: Hash#merge!({3=>1}):"\
638
- " pair {3=>1} does not match"\
639
- " [{Symbol=>Integer, Integer=>Symbol}] in container {3=>1}")
635
+ should notify
640
636
  end
641
637
 
642
638
  it "should not notify if updated with an acceptable hash" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: must_be
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - William Taysom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-27 00:00:00 +08:00
18
+ date: 2010-09-29 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -26,9 +26,11 @@ executables: []
26
26
  extensions: []
27
27
 
28
28
  extra_rdoc_files:
29
+ - ChangeLog.md
29
30
  - README.md
30
31
  files:
31
32
  - .gitignore
33
+ - ChangeLog.md
32
34
  - README.md
33
35
  - Rakefile
34
36
  - VERSION