interchangeable 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cda8cd912331c11bd0ae9b3d202e2a5f351c89a4
4
- data.tar.gz: 92d11defc20ae888d9752fc2a0c9d6c84d5af735
3
+ metadata.gz: 5df0ea6a13cdf08bf9339d7933cb1a6765a4f383
4
+ data.tar.gz: 9835d7d3a325ea760ccb587486a77bd1bb8e1713
5
5
  SHA512:
6
- metadata.gz: 91252026af2d9053a4b3afedb6c059ed9e978f4e30787c2fcb7b826bdec6bbb88ca64152c7f2441b0c27da9adc8cec9c2e957b81ed6138a5ccc02c7b715882a5
7
- data.tar.gz: 49bfa7e108b444af8b4849dbfa36b17ed7cff4f4b65df58a47482d245e3833cf9effdd43c81426e82625a9b2ee77f2d9c443b6a92b991a1fe7b8058079ed682c
6
+ metadata.gz: 7e3ac3cfd0390ef4900a94ead1bf8f5b696a9ee12237de563f78e0ac21d9093023d1805b98741bc8554740fda20903940c3b268cb4a5de43eac4e1fa2d0b97aa
7
+ data.tar.gz: d231000374e534a5b5f773e357a184ae1ddce695f91c4a3ea4d6035270707e996691bad2789569cfd3f670132b8dd9e871ee89fe42515b556afe7bea580c7a8b
@@ -1,3 +1,3 @@
1
1
  module Interchangeable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,10 +1,21 @@
1
1
  require "interchangeable/version"
2
2
 
3
3
  class Class
4
- def interchangeable_instance_method *args, &block
5
- Interchangeable.entries << Struct.new(:method_name, :target, :level)
6
- .new(args[0], self, :instance)
7
- Interchangeable.define(self, args[0], &block) if block
4
+
5
+ def interchangeable_describe description
6
+ @interchangeable_description = description
7
+ end
8
+
9
+ def interchangeable_method *args, &block
10
+ description = @interchangeable_description
11
+ @interchangeable_description = nil
12
+ entry = Struct.new(:method_name, :target, :implemented, :default, :description)
13
+ .new(args[0], self, false, false, description)
14
+ Interchangeable.entries << entry
15
+ if block
16
+ Interchangeable.define self, args[0], &block
17
+ entry.default = true
18
+ end
8
19
  end
9
20
  end
10
21
 
@@ -21,6 +32,9 @@ module Interchangeable
21
32
  the_class.instance_eval do
22
33
  define_method method_name, &block
23
34
  end
35
+ entry = Interchangeable.entries.select { |x| x.target == the_class && x.method_name && method_name }.first
36
+ entry.implemented = true
37
+ entry.default = false
24
38
  end
25
39
  end
26
40
 
@@ -6,18 +6,19 @@ describe Interchangeable do
6
6
  Interchangeable.instance_eval { @settings = nil }
7
7
  end
8
8
 
9
- describe "defining an instance-level method on a class" do
9
+ describe "defining a method on a class" do
10
10
 
11
11
  [
12
- ["Blah", "something"],
13
- ["Yawn", "applesauce"],
14
- ].map { |x| Struct.new(:class_name, :method_name).new(*x) }.each do |example|
12
+ ["Blah", "something", "this is a special method"],
13
+ ["Yawn", "applesauce", "make sure this works"],
14
+ ].map { |x| Struct.new(:class_name, :method_name, :description).new(*x) }.each do |example|
15
15
 
16
16
  describe "noting the method on a class" do
17
17
 
18
18
  before do
19
19
  eval("class #{example.class_name}
20
- interchangeable_instance_method :#{example.method_name}
20
+ interchangeable_describe \"#{example.description}\"
21
+ interchangeable_method :#{example.method_name}
21
22
  end")
22
23
  end
23
24
 
@@ -35,8 +36,16 @@ describe Interchangeable do
35
36
  Interchangeable.entries.first.target.must_equal eval(example.class_name)
36
37
  end
37
38
 
38
- it "should say that it's an instance method" do
39
- Interchangeable.entries.first.level.must_equal :instance
39
+ it "should say that it is not implemented" do
40
+ Interchangeable.entries.first.implemented.must_equal false
41
+ end
42
+
43
+ it "should say that it is not using the default implementation" do
44
+ Interchangeable.entries.first.default.must_equal false
45
+ end
46
+
47
+ it "should include the description" do
48
+ Interchangeable.entries.first.description.must_equal example.description
40
49
  end
41
50
 
42
51
  end
@@ -55,6 +64,14 @@ describe Interchangeable do
55
64
  instance.send(example.method_name.to_sym).must_be_same_as the_return_value
56
65
  end
57
66
 
67
+ it "should say that it is not implemented" do
68
+ Interchangeable.entries.first.implemented.must_equal true
69
+ end
70
+
71
+ it "should say that it is not using the default implementation" do
72
+ Interchangeable.entries.first.default.must_equal false
73
+ end
74
+
58
75
  end
59
76
 
60
77
  describe "accessing private members of the class" do
@@ -101,7 +118,7 @@ describe Interchangeable do
101
118
 
102
119
  before do
103
120
  eval("class #{example.class_name}
104
- interchangeable_instance_method(:#{example.method_name}) { \"#{default_value}\" }
121
+ interchangeable_method(:#{example.method_name}) { \"#{default_value}\" }
105
122
  end")
106
123
  end
107
124
 
@@ -112,6 +129,37 @@ describe Interchangeable do
112
129
  result.must_equal default_value
113
130
  end
114
131
 
132
+ it "should say that it is implemented" do
133
+ Interchangeable.entries.first.implemented.must_equal true
134
+ end
135
+
136
+ it "should say that it is using the default implementation" do
137
+ Interchangeable.entries.first.default.must_equal true
138
+ end
139
+
140
+ describe "and a new implementation is define elsewhere" do
141
+
142
+ let(:new_value) { Object.new }
143
+
144
+ before do
145
+ nv = new_value
146
+ Interchangeable.define(eval(example.class_name), example.method_name.to_sym) do
147
+ nv
148
+ end
149
+ end
150
+
151
+ it "should return the new value" do
152
+ instance = eval(example.class_name).new
153
+ result = instance.send(example.method_name.to_sym)
154
+ result.must_be_same_as new_value
155
+ end
156
+
157
+ it "should reset the default flag to false" do
158
+ Interchangeable.entries.first.default.must_equal false
159
+ end
160
+
161
+ end
162
+
115
163
  end
116
164
 
117
165
  end
@@ -122,4 +170,19 @@ describe Interchangeable do
122
170
 
123
171
  end
124
172
 
173
+ describe "one description, then two methods" do
174
+ before do
175
+ eval("class SomethingElse
176
+ interchangeable_describe \"That's a banana\"
177
+ interchangeable_method :banana
178
+ interchangeable_method :kiwi
179
+ end")
180
+ end
181
+
182
+ it "should put the description on the first, but not the second" do
183
+ Interchangeable.entries[0].description.must_equal "That's a banana"
184
+ Interchangeable.entries[1].description.nil?.must_equal true
185
+ end
186
+ end
187
+
125
188
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interchangeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon