durable_decorator 0.1.2 → 0.2.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.
data/.travis.yml CHANGED
@@ -7,4 +7,3 @@ rvm:
7
7
  - 1.9.2
8
8
  - jruby-19mode # JRuby in 1.9 mode
9
9
  - rbx-19mode
10
- - 1.8.7
data/README.md CHANGED
@@ -24,6 +24,12 @@ And then execute:
24
24
 
25
25
  $ bundle
26
26
 
27
+ ## UPGRADING
28
+
29
+ Prior to Version 0.2.0 original methods would have a suffix of original or SHA. A recent change has been made to
30
+ use prefix rather than suffix in order to be compatible with example! and example? methods. Please review your durably decorated
31
+ methods when upgrading to Version 0.2.0.
32
+
27
33
  ## Usage
28
34
 
29
35
  ```ruby
@@ -35,7 +41,7 @@ end
35
41
 
36
42
  ExampleClass.class_eval do
37
43
  durably_decorate :string_method do
38
- string_method_original + " and new"
44
+ original_string_method + " and new"
39
45
  end
40
46
  end
41
47
 
@@ -65,7 +71,7 @@ DurableDecorator::Base.determine_sha('ExampleClass#no_param_method')
65
71
 
66
72
  ExampleClass.class_eval do
67
73
  durably_decorate :string_method, mode: 'strict', sha: 'WRONG-SHA-123456' do
68
- string_method_original + " and new"
74
+ original_string_method + " and new"
69
75
  end
70
76
  end
71
77
 
@@ -83,7 +89,7 @@ end
83
89
 
84
90
  ExampleClass.class_eval do
85
91
  durably_decorate :string_method, mode: 'strict', sha: 'ba3114b2d46caa684b3f7ba38d6f74b2' do |text|
86
- string_method_original(text) + " and new"
92
+ original_string_method(text) + " and new"
87
93
  end
88
94
  end
89
95
 
@@ -92,7 +98,7 @@ instance.string_method('test')
92
98
  # => "original test and new"
93
99
  ```
94
100
 
95
- DurableDecorator also maintains explicit versions of each method overriden by creating aliases with appended SHAs of the form ```some_method_1234abcd``` so you can always target explicit method versions without relying on ```some_method_original```.
101
+ DurableDecorator also maintains explicit versions of each method overriden by creating aliases with appended SHAs of the form ```some_method_1234abcd``` so you can always target explicit method versions without relying on ```original_some_method```.
96
102
 
97
103
  DurableDecorator maintains 3 versions of aliases to previous method versions, 2 of which are short-SHA versions, akin to Github:
98
104
  ```ruby
@@ -106,14 +112,14 @@ ExampleClass.class_eval do
106
112
  end
107
113
 
108
114
  # 3 explicit aliases preserve access to the original method based on it's original SHA:
109
- # 4-char SHA, 6-char SHA and the full SHA suffix
115
+ # 4-char SHA, 6-char SHA and the full SHA prefix
110
116
 
111
117
  instance = ExampleClass.new
112
- instance.string_method_ba31
118
+ instance._ba31_string_method
113
119
  # => "original"
114
- instance.string_method_ba3114
120
+ instance._ba3114_string_method
115
121
  # => "original"
116
- instance.string_method_ba3114b2d46caa684b3f7ba38d6f74b2
122
+ instance._ba3114b2d46caa684b3f7ba38d6f74b2_string_method
117
123
  # => "original"
118
124
  ```
119
125
 
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '>= 1.9.2'
22
+
21
23
  spec.add_dependency "method_source"
22
24
  spec.add_dependency "logging"
23
25
 
@@ -51,9 +51,9 @@ module DurableDecorator
51
51
 
52
52
  def alias_definitions clazz, method_name, old_sha
53
53
  clazz.class_eval do
54
- alias_method("#{method_name}_#{old_sha}", method_name)
55
- alias_method("#{method_name}_#{old_sha[0..3]}", method_name)
56
- alias_method("#{method_name}_#{old_sha[0..5]}", method_name)
54
+ alias_method("_#{old_sha}_#{method_name}", method_name)
55
+ alias_method("_#{old_sha[0..3]}_#{method_name}", method_name)
56
+ alias_method("_#{old_sha[0..5]}_#{method_name}", method_name)
57
57
  end
58
58
  end
59
59
 
@@ -61,7 +61,7 @@ module DurableDecorator
61
61
  return unless original_redefinition? clazz, method_name
62
62
 
63
63
  clazz.class_eval do
64
- alias_method("#{method_name}_original", method_name)
64
+ alias_method("original_#{method_name}", method_name)
65
65
  end
66
66
  end
67
67
 
@@ -16,7 +16,9 @@ module DurableDecorator
16
16
  provided_sha = chill_meta[:sha]
17
17
 
18
18
  raise InvalidDecorationError, "The :mode provided is invalid. Possible modes are: #{DECORATION_MODES.join(", ")}" unless DECORATION_MODES.include? provided_mode
19
- raise InvalidDecorationError, "The SHA provided appears to be empty" unless provided_sha and !provided_sha.empty?
19
+ if provided_mode == 'strict'
20
+ raise InvalidDecorationError, "The SHA provided appears to be empty" unless provided_sha and !provided_sha.empty?
21
+ end
20
22
  send("handle_#{chill_meta[:mode]}_fault", clazz, method_name, expected_sha, provided_sha) unless expected_sha == provided_sha
21
23
  end
22
24
 
@@ -1,3 +1,3 @@
1
1
  module DurableDecorator
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,10 +5,10 @@ describe DurableDecorator::Base do
5
5
  context 'with classes' do
6
6
  # Spec uses ./example_class.rb
7
7
  context 'for existing instance methods' do
8
- it 'guarantees access to #method_original' do
8
+ it 'guarantees access to #original_method' do
9
9
  ExampleClass.class_eval do
10
10
  durably_decorate :no_param_method do
11
- no_param_method_original + " and a new string"
11
+ original_no_param_method + " and a new string"
12
12
  end
13
13
  end
14
14
 
@@ -27,10 +27,10 @@ describe DurableDecorator::Base do
27
27
  end
28
28
 
29
29
  context 'for methods with parameters' do
30
- it 'guarantees access to #method_original' do
30
+ it 'guarantees access to #original_method' do
31
31
  ExampleClass.class_eval do
32
32
  durably_decorate :one_param_method do |another_string|
33
- "#{one_param_method_original('check')} and #{another_string}"
33
+ "#{original_one_param_method('check')} and #{another_string}"
34
34
  end
35
35
  end
36
36
 
@@ -43,7 +43,7 @@ describe DurableDecorator::Base do
43
43
  before do
44
44
  ExampleClass.class_eval do
45
45
  durably_decorate :one_param_method do |another_string|
46
- "#{one_param_method_935888f04d9e132be458591d5755cb8131fec457('check')} and #{another_string}"
46
+ "#{_935888f04d9e132be458591d5755cb8131fec457_one_param_method('check')} and #{another_string}"
47
47
  end
48
48
  end
49
49
  end
@@ -52,14 +52,9 @@ describe DurableDecorator::Base do
52
52
  ExampleClass.class_eval do
53
53
  durably_decorate :one_param_method do |boolean|
54
54
  if boolean
55
- one_param_method_original("older")
55
+ original_one_param_method("older")
56
56
  else
57
- # ugly hack due to inconsistent method_source behavior on 1.8.7
58
- if /^ruby 1\.8\.7/ =~ RUBY_DESCRIPTION
59
- one_param_method_0ec3("newer")
60
- else
61
- one_param_method_3c39("newer")
62
- end
57
+ _b844_one_param_method("newer")
63
58
  end
64
59
  end
65
60
  end
@@ -71,8 +66,8 @@ describe DurableDecorator::Base do
71
66
 
72
67
  it 'work with short explicit method version invocation' do
73
68
  instance = ExampleClass.new
74
- instance.one_param_method_9358('').should == "original: "
75
- instance.one_param_method_935888('').should == "original: "
69
+ instance._9358_one_param_method('').should == "original: "
70
+ instance._935888_one_param_method('').should == "original: "
76
71
  end
77
72
 
78
73
  it 'maintains history of decorations' do
@@ -89,7 +84,7 @@ describe DurableDecorator::Base do
89
84
  :sha => 'd54f9c7ea2038fac0ae2ff9af49c56f35761725d'
90
85
  }
91
86
  durably_decorate :no_param_method, meta do
92
- no_param_method_original + " and a new string"
87
+ original_no_param_method + " and a new string"
93
88
  end
94
89
  end
95
90
 
@@ -107,7 +102,7 @@ describe DurableDecorator::Base do
107
102
  :sha => '1234wrong'
108
103
  }
109
104
  durably_decorate :no_param_method, meta do
110
- no_param_method_original + " and a new string"
105
+ original_no_param_method + " and a new string"
111
106
  end
112
107
  end
113
108
  }.should raise_error(DurableDecorator::TamperedDefinitionError)
@@ -122,7 +117,7 @@ describe DurableDecorator::Base do
122
117
  :mode => 'strict'
123
118
  }
124
119
  durably_decorate :no_param_method, meta do
125
- no_param_method_original + " and a new string"
120
+ original_no_param_method + " and a new string"
126
121
  end
127
122
  end
128
123
  }.should raise_error(DurableDecorator::InvalidDecorationError)
@@ -132,14 +127,14 @@ describe DurableDecorator::Base do
132
127
 
133
128
  context 'for soft definitions' do
134
129
  context 'with the correct SHA' do
135
- it 'guarantees access to #method_original' do
130
+ it 'guarantees access to #original_method' do
136
131
  ExampleClass.class_eval do
137
132
  meta = {
138
133
  :mode => 'soft',
139
134
  :sha => 'd54f9c7ea2038fac0ae2ff9af49c56f35761725d'
140
135
  }
141
136
  durably_decorate :no_param_method, meta do
142
- no_param_method_original + " and a new string"
137
+ original_no_param_method + " and a new string"
143
138
  end
144
139
  end
145
140
 
@@ -156,7 +151,7 @@ describe DurableDecorator::Base do
156
151
  :sha => '1234wrong'
157
152
  }
158
153
  durably_decorate :no_param_method, meta do
159
- no_param_method_original + " and a new string"
154
+ original_no_param_method + " and a new string"
160
155
  end
161
156
  end
162
157
  @log_output.readline.should match(/invalid SHA/)
@@ -179,10 +174,10 @@ describe DurableDecorator::Base do
179
174
  lambda{
180
175
  ExampleClass.class_eval do
181
176
  meta = {
182
- :mode => 'soft'
177
+ :mode => 'strict'
183
178
  }
184
179
  durably_decorate :no_param_method, meta do
185
- no_param_method_original + " and a new string"
180
+ original_no_param_method + " and a new string"
186
181
  end
187
182
  end
188
183
  }.should raise_error(DurableDecorator::InvalidDecorationError)
@@ -202,10 +197,10 @@ describe DurableDecorator::Base do
202
197
  end
203
198
 
204
199
  context 'for existing class methods' do
205
- it 'guarantees access to ::method_original' do
200
+ it 'guarantees access to ::original_method' do
206
201
  ExampleClass.class_eval do
207
202
  durably_decorate_singleton :clazz_level do
208
- clazz_level_original + " and a new string"
203
+ original_clazz_level + " and a new string"
209
204
  end
210
205
  end
211
206
 
@@ -223,10 +218,10 @@ describe DurableDecorator::Base do
223
218
  end
224
219
 
225
220
  context 'for methods with parameters' do
226
- it 'guarantees access to ::method_original' do
221
+ it 'guarantees access to ::original_method' do
227
222
  ExampleClass.class_eval do
228
223
  durably_decorate_singleton :clazz_level_paramed do |another_string|
229
- "#{clazz_level_paramed_original('check')} and #{another_string}"
224
+ "#{original_clazz_level_paramed('check')} and #{another_string}"
230
225
  end
231
226
  end
232
227
 
@@ -249,10 +244,10 @@ describe DurableDecorator::Base do
249
244
  context 'with modules' do
250
245
  # Spec uses ./sample_module.rb
251
246
  context 'for existing methods' do
252
- it 'guarantees access to #method_original' do
247
+ it 'guarantees access to #original_method' do
253
248
  Sample.class_eval do
254
249
  durably_decorate :module_method do
255
- module_method_original + " and a new string"
250
+ original_module_method + " and a new string"
256
251
  end
257
252
  end
258
253
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: durable_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
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: 2013-08-17 00:00:00.000000000 Z
12
+ date: 2013-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: method_source
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ! '>='
135
135
  - !ruby/object:Gem::Version
136
- version: '0'
136
+ version: 1.9.2
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements: