amfetamine 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7dff766487153f39f4c3031ea1ac716f296fbdf2
4
+ data.tar.gz: 3a9435fdea9c38bda128504c9e74ecc044b15363
5
+ SHA512:
6
+ metadata.gz: 19d8b378c2ddcc16ad185c32c8f04b043c3b640307dc11c3e460bee9006edf57cff3dabf9bdfd8eba60802dcb3af5af8b51615933c0d0eb5c8f03036fcceea88
7
+ data.tar.gz: b6bb834912b00d0e08a215ebfd0fa5e8aa5a37f37c5ded634bd1b5e821f2d64dc5c0959b0ffcf60595994a77eedd1df3b33e025ae36806667028a9161a771a31
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
- - 1.9.2
5
5
  - rbx-19mode
6
6
  - jruby-19mode
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+
3
+ * Add default cache settings (10 minutes)
4
+
1
5
  ## 0.3.3
2
6
 
3
7
  * fix for double Array error messages bug for remote (server) validations [Issue #6]
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- Amfetamine, A REST object abstractavaganza
2
- ====================================
1
+ # Amfetamine
2
+
3
+ A REST object abstractavaganza
3
4
 
4
5
  > Rest abstraction on steroids that makes shit go boom!
5
6
 
@@ -34,15 +35,13 @@ It is still in beta and under heavy development. Some features:
34
35
  Setup
35
36
  =====
36
37
 
37
- ### 1)
38
- Add it to your gemfile:
38
+ ### 1) Add it to your gemfile:
39
39
 
40
40
  ```ruby
41
41
  gem 'amfetamine'
42
42
  ```
43
43
 
44
- ### 2)
45
- Create an initializer, note that you can also do this on a per object basis:
44
+ ### 2) Create an initializer, note that you can also do this on a per object basis:
46
45
 
47
46
  ```ruby
48
47
  #config/initializers/amfetamine_config.rb
@@ -56,15 +55,14 @@ Amfetamine::Config.configure do |config|
56
55
  end
57
56
  ```
58
57
 
59
- On Heroku your `memcached_instance` variable can look like this (with the memcached addon enabled):
58
+ On Heroku your `memcached_instance` variable can look like this (with the [memcachier](https://addons.heroku.com/memcachier) addon enabled):
60
59
 
61
60
  ```ruby
62
- config.memcached_instance = "memcached://#{ENV['MEMCACHE_USERNAME']}:#{ENV['MEMCACHE_PASSWORD']}@#{ENV['MEMCACHE_SERVERS']}:11211"
61
+ config.memcached_instance = "memcached://#{ENV['MEMCACHIER_USERNAME']}:#{ENV['MEMCACHIER_PASSWORD']}@#{ENV['MEMCACHIER_SERVERS']}"
63
62
  ```
64
63
 
65
64
 
66
- ### 3)
67
- Configure your object:
65
+ ### 3) Configure your object:
68
66
 
69
67
  ```ruby
70
68
  class Banana < Amfetamine::Base
@@ -77,8 +75,7 @@ end
77
75
  ```
78
76
 
79
77
 
80
- ### 4)
81
- Lastly, because I think its more semantic, you need to configure both your service and client to include the root element in JSON. However, Amfetamine will work fine without this.
78
+ ### 4) Lastly, because I think its more semantic, you need to configure both your service and client to include the root element in JSON. However, Amfetamine will work fine without this.
82
79
 
83
80
  ```ruby
84
81
  # config/initializers/wrap_parameters.rb
@@ -143,6 +140,21 @@ object.update_attributes(HASH)
143
140
  Object.create(HASH)
144
141
  ```
145
142
 
143
+
144
+ Caching
145
+ =======
146
+
147
+ By default, all requests are cached. Default expiration time is set to 10 minutes. If you want to change it, you can do so when initializing the memcached client (see #2 above in setting up), like this:
148
+
149
+ ```ruby
150
+ Amfetamine::Config.configure do |config|
151
+ config.memcached_instance = "memcached://user:pass@host:port:weight", { expires_in: 60.minutes }
152
+ end
153
+ ```
154
+
155
+ When Amfetamine is required in a Rails application it disables caching altogether in `test` environment and sets the `expires_in` to 60 seconds in `development` environment.
156
+
157
+
146
158
  Cache Invalidation
147
159
  =================
148
160
 
@@ -221,8 +233,7 @@ Future Features & TODO
221
233
  Licence
222
234
  =======
223
235
 
224
-
225
- Copyright (C) 2012 Exvo.com, Timon Vonk
236
+ Copyright (C) 2012-2013 Exvo.com, Timon Vonk
226
237
 
227
238
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
228
239
 
@@ -230,6 +241,7 @@ The above copyright notice and this permission notice shall be included in all c
230
241
 
231
242
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
232
243
 
244
+
233
245
  Contributing
234
246
  ============
235
247
 
@@ -242,5 +254,6 @@ Contributing
242
254
  Contributors
243
255
  ============
244
256
 
245
- * Timon Vonk
246
- * Matt Bridges
257
+ * [Timon Vonk](https://github.com/timonv)
258
+ * [Matt Bridges](https://github.com/mattdbridges)
259
+ * [Paweł Gościcki](https://github.com/pjg)
@@ -16,8 +16,8 @@ module Amfetamine
16
16
  Amfetamine::Logger.instance
17
17
  end
18
18
 
19
- # If included in Rails, disable caching in dev/test modes
20
- if defined?(Rails) && (Rails.env.development? || Rails.env.test?)
19
+ # Disable chaching in test mode (if included in Rails)
20
+ if defined?(Rails) && Rails.env.test?
21
21
  Amfetamine::Config.disable_caching = true
22
22
  end
23
23
  end
@@ -10,7 +10,8 @@ module Amfetamine
10
10
  end
11
11
 
12
12
  def memcached_instance=(servers, options={})
13
- @memcached_instance ||= Dalli::Client.new(servers, options)
13
+ opts = default_memcached_options.merge(options)
14
+ @memcached_instance ||= Dalli::Client.new(servers, opts)
14
15
  end
15
16
 
16
17
  def rest_client=(value)
@@ -32,6 +33,32 @@ module Amfetamine
32
33
  def disable_caching=(value)
33
34
  @disable_caching = value
34
35
  end
36
+
37
+ private
38
+
39
+ def default_memcached_options
40
+ {
41
+ expires_in: expiration_time
42
+ }
43
+ end
44
+
45
+ def expiration_time
46
+ if defined?(Rails)
47
+ method = "expiration_time_for_#{ Rails.env }"
48
+ return send(method) if defined?(method)
49
+ end
50
+
51
+ default_expiration_time
52
+ end
53
+
54
+ def expiration_time_for_development
55
+ 60.seconds
56
+ end
57
+
58
+ def default_expiration_time
59
+ 10.minutes
60
+ end
61
+
35
62
  end
36
63
  end
37
64
  end
@@ -1,3 +1,3 @@
1
1
  module Amfetamine
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -2,6 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  # Integration tests :)
4
4
  describe Amfetamine::Base do
5
+
6
+ describe 'initialization' do
7
+ let(:memcached_instance) { Amfetamine::Config.memcached_instance }
8
+ let(:options) { memcached_instance.instance_variable_get(:@options) }
9
+
10
+ it 'passes :expires_in option to Dalli::Client' do
11
+ options.should include(:expires_in)
12
+ end
13
+
14
+ specify 'exires_in option is set to an integer value' do
15
+ options[:expires_in].should be_an_integer
16
+ end
17
+ end
18
+
5
19
  describe "Dummy, our ever faitful test subject" do
6
20
  # Some hight level tests, due to the complexity this makes it a lot easier to refactor
7
21
  let(:dummy) { build(:dummy) }
@@ -10,8 +24,8 @@ describe Amfetamine::Base do
10
24
  it { should be_valid }
11
25
  its(:title) { should ==('Dummy')}
12
26
  its(:description) { should ==('Crash me!')}
13
- its(:to_json) { should match(/dummy/) }
14
-
27
+ its(:to_json) { should match(/Dummy/) }
28
+ its(:to_json) { should match(/Crash me\!/) }
15
29
  end
16
30
 
17
31
  describe "Class dummy, setup with Amfetamine::Base" do
@@ -155,22 +169,23 @@ describe Amfetamine::Base do
155
169
  end
156
170
 
157
171
  context "#save" do
158
- let(:dummy2) { dummy.dup}
159
- before(:each) do
172
+ let!(:post_dummy) { dummy.dup }
173
+
174
+ before do
160
175
  dummy.send(:notsaved=, true)
161
- dummy2 = dummy.dup
162
176
  dummy.send(:id=, nil)
163
177
  end
164
178
 
165
179
  it "should update the id if data is received from post" do
166
- old_id = dummy.id
167
- Dummy.prevent_external_connections! do |r|
168
- r.post(code:201) { dummy2 }
180
+ dummy.id.should be_nil
169
181
 
182
+ Dummy.prevent_external_connections! do |r|
183
+ r.post(code:201) { post_dummy }
170
184
  dummy.save
171
185
  end
172
- dummy.id.should == old_id
173
- dummy.attributes[:id].should == old_id
186
+
187
+ dummy.id.should == post_dummy.id
188
+ dummy.attributes[:id].should == post_dummy.id
174
189
  end
175
190
 
176
191
  it "should update attributes if data is received from update" do
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amfetamine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Timon Vonk
@@ -10,262 +9,230 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-09-14 00:00:00.000000000 Z
12
+ date: 2013-06-28 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: guard
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: guard-bundler
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: guard-rspec
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: rb-fsevent
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: rb-inotify
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: httparty
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: fakeweb
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - '>='
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - '>='
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: simplecov
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - '>='
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  - !ruby/object:Gem::Dependency
160
141
  name: simplecov-rcov
161
142
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
143
  requirements:
164
- - - ! '>='
144
+ - - '>='
165
145
  - !ruby/object:Gem::Version
166
146
  version: '0'
167
147
  type: :development
168
148
  prerelease: false
169
149
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
150
  requirements:
172
- - - ! '>='
151
+ - - '>='
173
152
  - !ruby/object:Gem::Version
174
153
  version: '0'
175
154
  - !ruby/object:Gem::Dependency
176
155
  name: pry
177
156
  requirement: !ruby/object:Gem::Requirement
178
- none: false
179
157
  requirements:
180
- - - ! '>='
158
+ - - '>='
181
159
  - !ruby/object:Gem::Version
182
160
  version: '0'
183
161
  type: :development
184
162
  prerelease: false
185
163
  version_requirements: !ruby/object:Gem::Requirement
186
- none: false
187
164
  requirements:
188
- - - ! '>='
165
+ - - '>='
189
166
  - !ruby/object:Gem::Version
190
167
  version: '0'
191
168
  - !ruby/object:Gem::Dependency
192
169
  name: dalli
193
170
  requirement: !ruby/object:Gem::Requirement
194
- none: false
195
171
  requirements:
196
- - - ! '>='
172
+ - - '>='
197
173
  - !ruby/object:Gem::Version
198
174
  version: 2.2.1
199
175
  type: :runtime
200
176
  prerelease: false
201
177
  version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
178
  requirements:
204
- - - ! '>='
179
+ - - '>='
205
180
  - !ruby/object:Gem::Version
206
181
  version: 2.2.1
207
182
  - !ruby/object:Gem::Dependency
208
183
  name: activesupport
209
184
  requirement: !ruby/object:Gem::Requirement
210
- none: false
211
185
  requirements:
212
- - - ! '>='
186
+ - - '>='
213
187
  - !ruby/object:Gem::Version
214
188
  version: '0'
215
189
  type: :runtime
216
190
  prerelease: false
217
191
  version_requirements: !ruby/object:Gem::Requirement
218
- none: false
219
192
  requirements:
220
- - - ! '>='
193
+ - - '>='
221
194
  - !ruby/object:Gem::Version
222
195
  version: '0'
223
196
  - !ruby/object:Gem::Dependency
224
197
  name: activemodel
225
198
  requirement: !ruby/object:Gem::Requirement
226
- none: false
227
199
  requirements:
228
- - - ! '>='
200
+ - - '>='
229
201
  - !ruby/object:Gem::Version
230
202
  version: '0'
231
203
  type: :runtime
232
204
  prerelease: false
233
205
  version_requirements: !ruby/object:Gem::Requirement
234
- none: false
235
206
  requirements:
236
- - - ! '>='
207
+ - - '>='
237
208
  - !ruby/object:Gem::Version
238
209
  version: '0'
239
210
  - !ruby/object:Gem::Dependency
240
211
  name: json
241
212
  requirement: !ruby/object:Gem::Requirement
242
- none: false
243
213
  requirements:
244
- - - ! '>='
214
+ - - '>='
245
215
  - !ruby/object:Gem::Version
246
216
  version: '0'
247
217
  type: :runtime
248
218
  prerelease: false
249
219
  version_requirements: !ruby/object:Gem::Requirement
250
- none: false
251
220
  requirements:
252
- - - ! '>='
221
+ - - '>='
253
222
  - !ruby/object:Gem::Version
254
223
  version: '0'
255
224
  - !ruby/object:Gem::Dependency
256
225
  name: rake
257
226
  requirement: !ruby/object:Gem::Requirement
258
- none: false
259
227
  requirements:
260
- - - ! '>='
228
+ - - '>='
261
229
  - !ruby/object:Gem::Version
262
230
  version: '0'
263
231
  type: :runtime
264
232
  prerelease: false
265
233
  version_requirements: !ruby/object:Gem::Requirement
266
- none: false
267
234
  requirements:
268
- - - ! '>='
235
+ - - '>='
269
236
  - !ruby/object:Gem::Version
270
237
  version: '0'
271
238
  description: Provides an interface to REST apis with objects and a cache. Zero effort!
@@ -277,7 +244,6 @@ extensions: []
277
244
  extra_rdoc_files: []
278
245
  files:
279
246
  - .gitignore
280
- - .rspec
281
247
  - .travis.yml
282
248
  - .vagrant
283
249
  - CHANGELOG.md
@@ -319,53 +285,28 @@ files:
319
285
  - spec/helpers/active_model_lint.rb
320
286
  - spec/helpers/id_pool.rb
321
287
  - spec/spec_helper.rb
288
+ - tmp/rspec_guard_result
322
289
  homepage: http://www.github.com/exvo/amfetamine
323
290
  licenses: []
291
+ metadata: {}
324
292
  post_install_message:
325
293
  rdoc_options: []
326
294
  require_paths:
327
295
  - lib
328
296
  required_ruby_version: !ruby/object:Gem::Requirement
329
- none: false
330
297
  requirements:
331
- - - ! '>='
298
+ - - '>='
332
299
  - !ruby/object:Gem::Version
333
300
  version: '0'
334
- segments:
335
- - 0
336
- hash: 1384160561817165326
337
301
  required_rubygems_version: !ruby/object:Gem::Requirement
338
- none: false
339
302
  requirements:
340
- - - ! '>='
303
+ - - '>='
341
304
  - !ruby/object:Gem::Version
342
305
  version: '0'
343
- segments:
344
- - 0
345
- hash: 1384160561817165326
346
306
  requirements: []
347
307
  rubyforge_project: amfetamine
348
- rubygems_version: 1.8.24
308
+ rubygems_version: 2.0.3
349
309
  signing_key:
350
- specification_version: 3
310
+ specification_version: 4
351
311
  summary: REST object abstraction on steroids the makes shit go boom!
352
- test_files:
353
- - spec/amfetamine/base_spec.rb
354
- - spec/amfetamine/caching_spec.rb
355
- - spec/amfetamine/callbacks_spec.rb
356
- - spec/amfetamine/conditions_spec.rb
357
- - spec/amfetamine/dummy_spec.rb
358
- - spec/amfetamine/dynamic_attributes_spec.rb
359
- - spec/amfetamine/relationships_spec.rb
360
- - spec/amfetamine/rest_helpers_spec.rb
361
- - spec/amfetamine/rspec_matchers_spec.rb
362
- - spec/amfetamine/testing_helpers_spec.rb
363
- - spec/dummy/child.rb
364
- - spec/dummy/dummy.rb
365
- - spec/dummy/dummy_rest_client.rb
366
- - spec/dummy/infant.rb
367
- - spec/dummy/student.rb
368
- - spec/dummy/teacher.rb
369
- - spec/helpers/active_model_lint.rb
370
- - spec/helpers/id_pool.rb
371
- - spec/spec_helper.rb
312
+ test_files: []
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --profile