predicates 0.1.4 → 0.1.5

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.
@@ -44,8 +44,14 @@ module Predicates
44
44
 
45
45
  attr_writer attribute unless method_defined? attribute
46
46
 
47
- define_method method do
48
- !!instance_variable_get(:"@#{attribute}")
47
+ if method_defined? attribute
48
+ define_method method do
49
+ !!send(attribute)
50
+ end
51
+ else
52
+ define_method method do
53
+ !!instance_variable_get(:"@#{attribute}")
54
+ end
49
55
  end
50
56
  end
51
57
  end
@@ -1,3 +1,3 @@
1
1
  module Predicates
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -59,6 +59,23 @@ class PredicatesTest < MiniTest::Unit::TestCase
59
59
  assert object.attribute?
60
60
  end
61
61
 
62
+ def test_define_a_predicate_with_only_a_predefined_attribute_method
63
+ klass = Class.new WithPredicates do
64
+ def attribute
65
+ 1
66
+ end
67
+
68
+ predicate :attribute?
69
+ end
70
+
71
+ object = klass.new
72
+
73
+ assert object.respond_to?(:attribute?)
74
+ refute object.respond_to?(:attribute=)
75
+
76
+ assert object.attribute?
77
+ end
78
+
62
79
  def test_define_a_predicate_with_only_a_predefined_attribute_writer
63
80
  klass = Class.new WithPredicates do
64
81
  attr_writer :attribute
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: predicates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Truth accessors for Ruby classes and models.
15
15
  email: