leadlight 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- leadlight (0.0.7)
4
+ leadlight (0.1.0)
5
5
  addressable (~> 2.2.0)
6
6
  faraday (= 0.8.1)
7
7
  fattr
@@ -32,7 +32,6 @@ GEM
32
32
  guard (>= 0.10.0)
33
33
  hookr (1.1.1)
34
34
  fail-fast (= 1.0.0)
35
- libnotify (0.7.2)
36
35
  linecache19 (0.5.12)
37
36
  ruby_core_source (>= 0.1.4)
38
37
  link_header (0.0.5)
@@ -40,8 +39,6 @@ GEM
40
39
  multi_json (1.0.4)
41
40
  multipart-post (1.1.5)
42
41
  rake (0.9.2.2)
43
- rb-inotify (0.8.8)
44
- ffi (>= 0.5.0)
45
42
  rspec (2.11.0)
46
43
  rspec-core (~> 2.11.0)
47
44
  rspec-expectations (~> 2.11.0)
@@ -71,9 +68,7 @@ DEPENDENCIES
71
68
  guard-bundler
72
69
  guard-rspec
73
70
  leadlight!
74
- libnotify
75
71
  rake
76
- rb-inotify
77
72
  rspec
78
73
  ruby-debug19
79
74
  vcr (~> 2.0)
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'leadlight'
16
- s.version = '0.0.7'
17
- s.date = '2012-08-01'
16
+ s.version = '0.1.0'
17
+ s.date = '2012-12-28'
18
18
  s.rubyforge_project = 'leadlight'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -75,7 +75,6 @@ Gem::Specification.new do |s|
75
75
  Guardfile
76
76
  README.md
77
77
  Rakefile
78
- default.gems
79
78
  leadlight.gemspec
80
79
  lib/leadlight.rb
81
80
  lib/leadlight/basic_converter.rb
@@ -16,7 +16,7 @@ require 'leadlight/basic_converter'
16
16
 
17
17
  module Leadlight
18
18
 
19
- VERSION = '0.0.7'
19
+ VERSION = '0.1.0'
20
20
 
21
21
  def self.build_service(target=Class.new, &block)
22
22
  target.tap do
@@ -29,7 +29,7 @@ module Leadlight
29
29
  self
30
30
  end
31
31
 
32
- def exception(message=exception_message)
32
+ def exception
33
33
  return super if defined?(super)
34
34
  case __response__.status.to_i
35
35
  when 404 then ResourceNotFound
@@ -7,10 +7,11 @@ module Leadlight
7
7
  module Service
8
8
  extend Forwardable
9
9
 
10
- attr_reader :service_options
11
- fattr(:logger) { service_options.fetch(:logger) { ::Logger.new($stderr) } }
12
- fattr(:tints) { self.class.tints }
13
- fattr(:codec) { service_options.fetch(:codec) { Codec.new } }
10
+ attr_reader :service_options
11
+ attr_accessor :error_handler
12
+ fattr(:logger) { service_options.fetch(:logger) { ::Logger.new($stderr) } }
13
+ fattr(:tints) { self.class.tints }
14
+ fattr(:codec) { service_options.fetch(:codec) { Codec.new } }
14
15
  fattr(:type_map) { TypeMap.new }
15
16
 
16
17
  def_delegators :codec, :encode, :decode
@@ -22,6 +23,11 @@ module Leadlight
22
23
  execute_hook(:on_init, self)
23
24
  end
24
25
 
26
+ def on_error(&error_handler)
27
+ self.error_handler = error_handler
28
+ self
29
+ end
30
+
25
31
  def root
26
32
  get('/') do |r|
27
33
  return r
@@ -57,6 +63,7 @@ module Leadlight
57
63
 
58
64
  def perform_request(url, http_method, body=nil, options={}, &representation_handler)
59
65
  req = request_class.new(self, connection, url, http_method, body, options)
66
+ req.on_error(&error_handler) if error_handler
60
67
  if representation_handler
61
68
  req.submit_and_wait(&representation_handler)
62
69
  end
@@ -1,3 +1,5 @@
1
+ require 'addressable/template'
2
+ require 'addressable/uri'
1
3
  require 'delegate'
2
4
  require 'mime/types'
3
5
 
@@ -78,7 +80,7 @@ module Leadlight
78
80
  patterns.inject([]) {|patterns, pattern|
79
81
  case pattern
80
82
  when :any
81
- pattern << (100..599)
83
+ patterns << (100..599)
82
84
  when :user_error
83
85
  patterns << (400..499)
84
86
  when :server_error
@@ -251,10 +251,10 @@ module Leadlight
251
251
 
252
252
  it "yields to the block when response is an error" do
253
253
  called = :not_set
254
- block = proc{ called = true }
254
+ block = proc{ called = :set }
255
255
  faraday_response.should_receive(:success?).and_return(false)
256
256
  submit_and_complete.on_error(&block)
257
- called.should be_true
257
+ called.should eq(:set)
258
258
  end
259
259
 
260
260
  it "does not yield to the block when response is sucess" do
@@ -3,8 +3,8 @@ require 'leadlight/service'
3
3
 
4
4
  module Leadlight
5
5
  describe Service do
6
- subject { klass.new(service_options) }
7
- let(:klass) {
6
+ subject { klass.new(service_options) }
7
+ let(:klass) {
8
8
  Class.new do
9
9
  include Service
10
10
 
@@ -12,14 +12,14 @@ module Leadlight
12
12
  end
13
13
  end
14
14
  }
15
- let(:connection) { stub(:connection, get: response) }
16
- let(:representation) { stub(:representation) }
17
- let(:response) { stub(:response, env: env) }
18
- let(:env) { {leadlight_representation: representation} }
19
- let(:service_options) { {codec: codec} }
20
- let(:codec) { stub(:codec) }
21
- let(:request) { stub(:request).as_null_object }
22
- let(:request_class) { stub(:request_class, new: request) }
15
+ let(:connection) { stub(:connection, get: response) }
16
+ let(:representation) { stub(:representation) }
17
+ let(:response) { stub(:response, env: env) }
18
+ let(:env) { {leadlight_representation: representation} }
19
+ let(:service_options) { {codec: codec} }
20
+ let(:codec) { stub(:codec) }
21
+ let(:request) { stub(:request).as_null_object }
22
+ let(:request_class) { stub(:request_class, new: request) }
23
23
 
24
24
  before do
25
25
  subject.stub(connection: connection,
@@ -130,5 +130,19 @@ module Leadlight
130
130
  should equal(representation)
131
131
  end
132
132
  end
133
+
134
+ describe '#on_error' do
135
+ it 'returns itself' do
136
+ subject.on_error.should eq(subject)
137
+ end
138
+
139
+ it 'adds the handler to requests' do
140
+ called = :not_set
141
+ subject.on_error { called = true }
142
+ request.should_receive(:on_error).with(no_args).and_yield
143
+ subject.get '/'
144
+ called.should eq(true)
145
+ end
146
+ end
133
147
  end
134
148
  end
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper_lite'
2
+ require 'addressable/template'
3
+ require 'addressable/uri'
2
4
  require 'leadlight/tint_helper'
3
5
 
4
6
  module Leadlight
@@ -134,6 +136,14 @@ module Leadlight
134
136
  baz
135
137
  end
136
138
  end
139
+
140
+ it 'accepts pattern shortcuts' do
141
+ object.should_receive(:baz)
142
+ subject.exec_tint do
143
+ match_status(:any)
144
+ baz
145
+ end
146
+ end
137
147
  end
138
148
 
139
149
  describe '#match' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leadlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &76999980 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76999980
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.2.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: faraday
27
- requirement: &76999610 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - =
35
+ - - '='
31
36
  - !ruby/object:Gem::Version
32
37
  version: 0.8.1
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *76999610
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.1
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fattr
38
- requirement: &76999300 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *76999300
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: link_header
49
- requirement: &76998910 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *76998910
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: multi_json
60
- requirement: &76998510 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: 1.0.4
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *76998510
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.4
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: mime-types
71
- requirement: &76998210 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :runtime
78
103
  prerelease: false
79
- version_requirements: *76998210
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: hookr
82
- requirement: &76997950 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :runtime
89
119
  prerelease: false
90
- version_requirements: *76997950
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: rake
93
- requirement: &76997690 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *76997690
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: rspec
104
- requirement: &76997450 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *76997450
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: vcr
115
- requirement: &76997150 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ~>
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '2.0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *76997150
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: guard
126
- requirement: &76996930 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ! '>='
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: '0'
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *76996930
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: guard-rspec
137
- requirement: &76996580 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,10 +197,15 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *76996580
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  - !ruby/object:Gem::Dependency
147
207
  name: guard-bundler
148
- requirement: &76996130 !ruby/object:Gem::Requirement
208
+ requirement: !ruby/object:Gem::Requirement
149
209
  none: false
150
210
  requirements:
151
211
  - - ! '>='
@@ -153,10 +213,15 @@ dependencies:
153
213
  version: '0'
154
214
  type: :development
155
215
  prerelease: false
156
- version_requirements: *76996130
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
157
222
  - !ruby/object:Gem::Dependency
158
223
  name: ruby-debug19
159
- requirement: &76995700 !ruby/object:Gem::Requirement
224
+ requirement: !ruby/object:Gem::Requirement
160
225
  none: false
161
226
  requirements:
162
227
  - - ! '>='
@@ -164,7 +229,12 @@ dependencies:
164
229
  version: '0'
165
230
  type: :development
166
231
  prerelease: false
167
- version_requirements: *76995700
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
168
238
  description: Rose colored stained glass windows for HTTP.
169
239
  email: avdi@avdi.org
170
240
  executables: []
@@ -176,7 +246,6 @@ files:
176
246
  - Guardfile
177
247
  - README.md
178
248
  - Rakefile
179
- - default.gems
180
249
  - leadlight.gemspec
181
250
  - lib/leadlight.rb
182
251
  - lib/leadlight/basic_converter.rb
@@ -260,6 +329,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
329
  - - ! '>='
261
330
  - !ruby/object:Gem::Version
262
331
  version: '0'
332
+ segments:
333
+ - 0
334
+ hash: -65573010957843514
263
335
  required_rubygems_version: !ruby/object:Gem::Requirement
264
336
  none: false
265
337
  requirements:
@@ -268,7 +340,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
340
  version: '0'
269
341
  requirements: []
270
342
  rubyforge_project: leadlight
271
- rubygems_version: 1.8.15
343
+ rubygems_version: 1.8.23
272
344
  signing_key:
273
345
  specification_version: 2
274
346
  summary: Rose colored stained glass windows for HTTP.
@@ -1 +0,0 @@
1
- bundler -v1.1.3