riakrest 0.1.5 → 0.1.6

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/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.6 2009-12-17
2
+ - Add method for specifying data conversion in JiakData and JiakResouce.
3
+ - Add testing and examples for data conversion.
4
+
1
5
  === 0.1.5 2009-12-11
2
6
  - Added POV processing.
3
7
  - Refactored jattr_* to attr_*.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/example_helper.rb'
2
+ require 'date'
3
+
4
+ # JiakData class with a couple of attributes, one of which requires conversion
5
+ class DateData
6
+ include JiakData
7
+ attr_accessor :name, :date
8
+ convert :date => lambda{|value| Date.parse(value)}
9
+ end
10
+
11
+ client = JiakClient.new(SERVER_URI)
12
+ bucket = JiakBucket.new('date data',DateData)
13
+
14
+ # Leap data date is a Data object
15
+ leap_2008 = DateData.new(:name => "Leap 2008",
16
+ :date => Date.new(2008,02,29))
17
+ leap_obj = client.store(JiakObject.new(:bucket => bucket,
18
+ :data => leap_2008),
19
+ :return => :object)
20
+ puts leap_obj.data.date.inspect # => #<Date: 2008-02-29 (etc.)>
21
+
22
+ # Clean-up stored object
23
+ client.delete(bucket,leap_obj.key)
24
+
25
+
26
+ # It is also possible to use Ruby JSON processing to achieve a similar result;
27
+ # however, this is not optimal as the stored Riak data value contains
28
+ # Ruby-secific information which may be undesirable to non-Ruby consumers of
29
+ # that data.
30
+
31
+ # Instrument the Ruby Date class for round-trip JSON processing.
32
+ class Date
33
+ def to_json(*args)
34
+ { 'json_class' => self.class.name,
35
+ 'date' => to_s
36
+ }.to_json(*args)
37
+ end
38
+ def self.json_create(hash)
39
+ parse(hash['date'])
40
+ end
41
+ end
42
+
43
+ class DateData2
44
+ include JiakData
45
+ attr_accessor :name, :date
46
+ end
47
+
48
+ bucket = JiakBucket.new('date data',DateData2)
49
+
50
+ leap_2012 = DateData2.new(:name => "Leap 2012",
51
+ :date => Date.new(2012,02,29))
52
+ leap_obj = client.store(JiakObject.new(:bucket => bucket,
53
+ :data => leap_2012),
54
+ :return => :object)
55
+ puts leap_obj.data.date.inspect # => #<Date: 2012-02-29 (etc.)>
56
+
57
+ # JSON payload:
58
+ # leap_2008 : {"name":"leap","date":"2008-02-29"}
59
+ # leap_2012 : {"name":"leap","date":{"json_class":"Date","date":"2012-02-29"}}
60
+
61
+ # Clean-up stored object
62
+ client.delete(bucket,leap_obj.key)
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/example_helper.rb'
2
+ require 'date'
3
+
4
+ # JiakResource with a couple of attributes, one of which requires conversion
5
+ class Person
6
+ include JiakResource
7
+ server SERVER_URI
8
+ attr_accessor :name, :birthdate
9
+ convert :birthdate => lambda{|value| Date.parse(value)}
10
+ keygen {name.downcase}
11
+
12
+ def age
13
+ now = DateTime.now
14
+ age = now.year - birthdate.year
15
+ age -= 1 if(now.yday < birthdate.yday)
16
+ age
17
+ end
18
+ end
19
+
20
+ # Create and post resource, showing birthdate is a Date before and after post.
21
+ remy = Person.new(:name => 'Remy',:birthdate => Date.new(1999,06,26))
22
+ puts remy.birthdate.inspect # => #<Date: 1999-06-26 (etc.)>
23
+ puts remy.age # => current age
24
+ remy.post
25
+ puts remy.birthdate.inspect # => #<Date: 1999-06-26 (etc.)>
26
+ puts remy.age # => current age
27
+
28
+ remy.delete
29
+
@@ -105,7 +105,7 @@ module RiakRest
105
105
  # <code>delete</code> requests take precendence over the setting maintained
106
106
  # by a JiakClient. Any request parameter not set in JiakClient or on an
107
107
  # individual request will default to the values set in the Riak cluster.
108
- #
108
+ #
109
109
  def initialize(uri, opts={})
110
110
  check_opts(opts,CLIENT_PARAMS,JiakClientException)
111
111
  self.server = uri
@@ -263,7 +263,7 @@ module RiakRest
263
263
  def store(jobj,opts={})
264
264
  check_opts(opts,STORE_PARAMS,JiakClientException)
265
265
  req_params = {
266
- WRITES => opts[:writes] || @params[:writes],
266
+ WRITES => opts[:writes] || @params[:writes],
267
267
  DURABLE_WRITES => opts[:durable_writes] || @params[:durable_writes],
268
268
  COPY => opts[:copy]
269
269
  }
@@ -292,7 +292,7 @@ module RiakRest
292
292
  else
293
293
  resp = RestClient.put(uri,payload,headers)
294
294
  end
295
-
295
+
296
296
  if(req_params[RETURN_BODY])
297
297
  JiakObject.jiak_create(JSON.parse(resp),jobj.bucket.data_class)
298
298
  elsif(key_empty)
@@ -301,12 +301,14 @@ module RiakRest
301
301
  jobj.key
302
302
  end
303
303
  rescue RestClient::ExceptionWithResponse => err
304
- fail_with_response("put", err)
304
+ JiakClient.fail_with_response("store", err)
305
305
  rescue RestClient::Exception => err
306
- fail_with_message("put", err)
306
+ JiakClient.fail_with_message("store", err)
307
+ rescue Errno::ECONNREFUSED => err
308
+ JiakClient.fail_connection("store", err)
307
309
  end
308
310
  end
309
-
311
+
310
312
  # :call-seq:
311
313
  # get(bucket,key,opts={}) -> JiakObject
312
314
  #
@@ -348,9 +350,11 @@ module RiakRest
348
350
  rescue RestClient::ResourceNotFound => err
349
351
  raise JiakResourceNotFound, "failed get: #{err.message}"
350
352
  rescue RestClient::ExceptionWithResponse => err
351
- fail_with_response("get", err)
353
+ JiakClient.fail_with_response("get", err)
352
354
  rescue RestClient::Exception => err
353
- fail_with_message("get",err)
355
+ JiakClient.fail_with_message("get",err)
356
+ rescue Errno::ECONNREFUSED => err
357
+ JiakClient.fail_connection("get", err)
354
358
  end
355
359
  end
356
360
 
@@ -372,9 +376,11 @@ module RiakRest
372
376
  RestClient.delete(uri,:accept => APP_JSON)
373
377
  true
374
378
  rescue RestClient::ExceptionWithResponse => err
375
- fail_with_response("delete", err)
379
+ JiakClient.fail_with_response("delete", err)
376
380
  rescue RestClient::Exception => err
377
- fail_with_message("delete", err)
381
+ JiakClient.fail_with_message("delete", err)
382
+ rescue Errno::ECONNREFUSED => err
383
+ JiakClient.fail_connection("delete", err)
378
384
  end
379
385
  end
380
386
 
@@ -389,8 +395,8 @@ module RiakRest
389
395
  true
390
396
  rescue RestClient::ResourceNotFound
391
397
  false
392
- rescue RestClient::Exception => err
393
- fail_with_message("delete", err)
398
+ rescue Errno::ECONNREFUSED => err
399
+ JiakClient.fail_connection("exist?", err)
394
400
  end
395
401
  end
396
402
 
@@ -425,9 +431,11 @@ module RiakRest
425
431
  JiakObject.jiak_create(jiak,data_class)
426
432
  end
427
433
  rescue RestClient::ExceptionWithResponse => err
428
- fail_with_response("put", err)
434
+ JiakClient.fail_with_response("walk", err)
429
435
  rescue RestClient::Exception => err
430
- fail_with_message("put", err)
436
+ JiakClient.fail_with_message("walk", err)
437
+ rescue Errno::ECONNREFUSED => err
438
+ JiakClient.fail_connection("walk", err)
431
439
  end
432
440
  end
433
441
 
@@ -438,7 +446,7 @@ module RiakRest
438
446
  def ==(other)
439
447
  (@server == other.server) rescue false
440
448
  end
441
-
449
+
442
450
  # :call-seq:
443
451
  # eql?(other) -> true or false
444
452
  #
@@ -453,6 +461,8 @@ module RiakRest
453
461
  @server.hash
454
462
  end
455
463
 
464
+ # :stopdoc:
465
+
456
466
  # Build the URI for accessing the Jiak server.
457
467
  def jiak_uri(bucket,key="")
458
468
  bucket_name = bucket.is_a?(JiakBucket) ? bucket.name : bucket
@@ -472,7 +482,7 @@ module RiakRest
472
482
  qstring
473
483
  end
474
484
  private :jiak_qstring
475
-
485
+
476
486
  # Get either the schema or keys for the bucket.
477
487
  def bucket_info(bucket,info)
478
488
  ignore = (info == SCHEMA) ? KEYS : SCHEMA
@@ -480,23 +490,30 @@ module RiakRest
480
490
  uri = jiak_uri(bucket,"") << jiak_qstring({ignore => false})
481
491
  JSON.parse(RestClient.get(uri, :accept => APP_JSON))[info]
482
492
  rescue RestClient::ExceptionWithResponse => err
483
- fail_with_response("get", err)
493
+ JiakClient.fail_with_response("info", err)
484
494
  rescue RestClient::Exception => err
485
- fail_with_message("get", err)
495
+ JiakClient.fail_with_message("info", err)
496
+ rescue Errno::ECONNREFUSED => err
497
+ JiakClient.fail_connection("info", err)
486
498
  end
487
499
  end
488
500
  private :bucket_info
489
501
 
490
- def fail_with_response(action,err)
491
- raise( JiakResourceException,
492
- "failed #{action}: HTTP code #{err.http_code}: #{err.http_body}")
502
+ def self.fail_with_response(action,err)
503
+ raise(JiakResourceException,
504
+ "failed #{action}: HTTP code #{err.http_code}: #{err.http_body}")
493
505
  end
494
- private :fail_with_response
495
506
 
496
- def fail_with_message(action,err)
507
+ def self.fail_with_message(action,err)
497
508
  raise JiakResourceException, "failed #{action}: #{err.message}"
498
509
  end
499
- private :fail_with_message
510
+
511
+ def self.fail_connection(action,err)
512
+ raise(JiakClientException,
513
+ "failed #{action}: Connection refused for server #{@server}")
514
+ end
515
+
516
+ # :startdoc:
500
517
 
501
518
  end
502
519
 
@@ -47,9 +47,9 @@ module RiakRest
47
47
  # ----------------------------------------------------------------------
48
48
  # Class methods
49
49
  # ----------------------------------------------------------------------
50
-
50
+
51
51
  # Class methods for use in creating a user-defined JiakData. The methods
52
- # <code>allow, require, readable, writable</code> delegate to JiakSchema.
52
+ # <code>allow, require, readable, writable</code> delegate to JiakSchema.
53
53
  # See JiakSchema for discussion on the use of schemas in Riak.
54
54
  module ClassMethods
55
55
 
@@ -148,7 +148,7 @@ module RiakRest
148
148
  added_fields = @schema.send(method,*fields)
149
149
  added_allowed = @schema.allowed_fields - prev_allowed
150
150
  # added_allowed.each {|field| attr_accessor field}
151
- added_allowed.each do |field|
151
+ added_allowed.each do |field|
152
152
  class_eval <<-EOH
153
153
  def #{field}
154
154
  @#{field}
@@ -161,7 +161,7 @@ module RiakRest
161
161
  added_fields
162
162
  end
163
163
  private :expand_schema
164
-
164
+
165
165
  # :call-seq:
166
166
  # JiakData.schema -> JiakSchema
167
167
  #
@@ -173,7 +173,7 @@ module RiakRest
173
173
  # :call-seq:
174
174
  # JiakData.keygen(&block) -> nil
175
175
  #
176
- # Define the key generation for an instance of the created JiakData
176
+ # Specify the key generation for an instance of the created JiakData
177
177
  # class. Key generation will call the specified block in the scope of the
178
178
  # current instance.
179
179
  def keygen(&block)
@@ -181,26 +181,33 @@ module RiakRest
181
181
  end
182
182
 
183
183
  # :call-seq:
184
- # JiakData.jiak_create(jiak) -> JiakData
185
- #
186
- # Create an instance of user-defined data object from the fields read
187
- # by Jiak. These fields are determined by the read mask of the
188
- # structured Jiak interaction. See JiakSchema for read mask discussion.
184
+ # JiakData.convert(hash) -> nil
189
185
  #
190
- # User-defined data classes must either override this method explicitly
191
- # or use the <code>attr_*</code> methods which implicitly override this
192
- # method. The method is automatically called to marshall data from
193
- # Jiak. You do not call this method explicitly.
186
+ # Specify a hash of optional Procs for converting the data values stored
187
+ # in Riak during the process of inflating returned Riak data into Ruby
188
+ # objects. The hash values should be Procs used to convert the data
189
+ # attribute specified by the hash key. The Procs must accept one
190
+ # argument, the data value actually stored in Riak. The converted result
191
+ # will be the actual value of the data field inside the inflated Ruby
192
+ # object.
194
193
  #
195
194
  # ====Example
196
- # def initialize(f1,f2)
197
- # @f1 = f1
198
- # @f2 = f2
199
- # end
200
- # def jiak_create(jiak)
201
- # new(jiak['f1'], jiak['f2'])
202
- # end
203
- def jiak_create(jiak)
195
+ # def PersonData
196
+ # include JiakData
197
+ # attr_accessor :name, :birthdate
198
+ # convert :birthdate => lambda {|val| Date.parse(val)}
199
+ # end
200
+ def convert(hash)
201
+ @converter ||= {}
202
+ hash.each {|k,blk| @converter[k.to_s] = blk}
203
+ end
204
+
205
+ # Use optional converters to convert returned data values before passing
206
+ # to the JiakData constructor.
207
+ def jiak_create(jiak) # :nodoc:
208
+ unless(@converter.nil?)
209
+ @converter.each {|k,blk| jiak[k] = blk.call(jiak[k])}
210
+ end
204
211
  new(jiak)
205
212
  end
206
213
 
@@ -235,7 +242,7 @@ module RiakRest
235
242
  end
236
243
  end
237
244
  end
238
-
245
+
239
246
  # ----------------------------------------------------------------------
240
247
  # Instance methods
241
248
  # ----------------------------------------------------------------------
@@ -244,34 +251,6 @@ module RiakRest
244
251
  hash.each {|k,v| instance_variable_set("@#{k}", v)}
245
252
  end
246
253
 
247
- # :call-seq:
248
- # to_jiak -> hash
249
- #
250
- # Provide a hash structure of the data to write to Jiak. The fields for
251
- # this structure should come from the JiakData write mask. See JiakSchema
252
- # for shema discussion.
253
- #
254
- # User-defined data classes must either override this method explicitly or
255
- # use the <code>attr_*</code> methods which implicitly provide an implicit
256
- # override. The method is automatically called to marshall data to
257
- # Jiak. You do not call this method explicitly.
258
-
259
- # Data classes that do not used the attr_* methods to specify attributes
260
- # must override this method.
261
- #
262
- # ====Example
263
- # def to_jiak
264
- # { :writable_f1 => @writable_f1,
265
- # :writable_f2 => @writable_f2
266
- # }
267
- # end
268
- def to_jiak
269
- self.class.schema.write_mask.inject({}) do |build,field|
270
- build[field] = send("#{field}")
271
- build
272
- end
273
- end
274
-
275
254
  # :call-seq:
276
255
  # keygen -> string
277
256
  #
@@ -125,7 +125,7 @@ module RiakRest
125
125
  private :check_fields
126
126
 
127
127
  # :call-seq:
128
- # keygen(&block)
128
+ # JiakResource.keygen(&block)
129
129
  #
130
130
  # Specify the block for generating keys for a JiakResource instance.
131
131
  def keygen(&block)
@@ -134,6 +134,20 @@ module RiakRest
134
134
  EOS
135
135
  end
136
136
 
137
+ # :call-seq:
138
+ # JiakResource.convert(hash)
139
+ #
140
+ # Specify a hash of optional Procs for converting the data values stored
141
+ # in Riak during the process of inflating returned Riak data into
142
+ # JiakResource objects. The hash values should be Procs used to convert
143
+ # the data attribute specified by the hash key. The Procs must accept one
144
+ # argument, the data value actually stored in Riak. The converted result
145
+ # will be the actual value of the data field inside the inflated
146
+ # JiakResource.
147
+ def convert(hash)
148
+ jiak.data.convert(hash)
149
+ end
150
+
137
151
  # :call-seq:
138
152
  # JiakResource.params(opts={}) -> hash
139
153
  #
@@ -2,12 +2,23 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
3
  class FooBarBaz # :nodoc:
4
4
  include JiakData
5
-
6
5
  attr_accessor :foo, :bar
7
6
  require :foo
8
7
  allow :baz
9
8
  end
10
9
 
10
+ require 'date'
11
+ class DateData
12
+ include JiakData
13
+ attr_accessor :name, :date
14
+ convert :date => lambda { |v| Date.parse(v) }
15
+ end
16
+
17
+ class PersonData
18
+ include JiakData
19
+ attr_accessor :name
20
+ end
21
+
11
22
  describe "JiakClient" do
12
23
  before do
13
24
  @base_uri = SERVER_URI
@@ -67,7 +78,7 @@ describe "JiakClient" do
67
78
 
68
79
  no_no = lambda {JiakClient::KEYS << 'a'}
69
80
  no_no.should raise_error(StandardError,/frozen/)
70
-
81
+
71
82
  no_no = lambda {JiakClient::SCHEMA << 'a'}
72
83
  no_no.should raise_error(StandardError,/frozen/)
73
84
  end
@@ -97,7 +108,7 @@ describe "JiakClient" do
97
108
  client.proxy.should eql 'proxy_uri'
98
109
  client.params.should have_exactly(4).items
99
110
  @params.each {|k,v| client.params[k].should == @params[k]}
100
-
111
+
101
112
  @opts.delete(:proxy)
102
113
  @opts.delete(:writes)
103
114
  client = JiakClient.new(@base_uri,@opts)
@@ -126,13 +137,41 @@ describe "JiakClient" do
126
137
 
127
138
  bad_opts = lambda {@client.set_params(:junk => 'junk')}
128
139
  bad_opts.should raise_error(JiakClientException,/option/)
129
-
140
+
130
141
  @params[:junk] = 'junk'
131
142
  bad_opts = lambda {@client.params = @params}
132
143
  bad_opts.should raise_error(JiakClientException,/option/)
133
144
  end
134
145
  end
135
146
 
147
+ describe "JiakClient connection" do
148
+ before do
149
+ @client = JiakClient.new("http://localhost:9999/jiak/")
150
+ @data = FooBarBaz.new(:foo => 'Foo',:bar => 'Bar')
151
+ @bucket = JiakBucket.new('actions_bucket',FooBarBaz)
152
+ end
153
+
154
+ it "should report refused errors" do
155
+ client = JiakClient.new("http://localhost:9999/jiak/")
156
+ data = FooBarBaz.new(:foo => 'Foo',:bar => 'Bar')
157
+ bucket = JiakBucket.new('actions_bucket',FooBarBaz)
158
+ key = 'key'
159
+ jobj = JiakObject.new(:bucket => bucket, :key => key, :data => data)
160
+ qlink = QueryLink.new(bucket,'tag',nil)
161
+
162
+ [lambda {client.keys(bucket)},
163
+ lambda {client.schema(bucket)},
164
+ lambda {client.store(jobj)},
165
+ lambda {client.get(bucket,key)},
166
+ lambda {client.exist?(bucket,key)},
167
+ lambda {client.delete(bucket,key)},
168
+ lambda {client.walk(bucket,'tag',qlink,FooBarBaz)}
169
+ ].each do |bad_req|
170
+ bad_req.should raise_error(JiakClientException,/Connection refused/)
171
+ end
172
+ end
173
+ end
174
+
136
175
  describe "JiakClient URI handling" do
137
176
  before do
138
177
  @base_uri = SERVER_URI
@@ -174,7 +213,7 @@ describe "JiakClient processing" do
174
213
 
175
214
  it "should set and fetch a bucket schema" do
176
215
  schema = @client.schema(@bucket)
177
-
216
+
178
217
  ['allowed_fields',
179
218
  'required_fields',
180
219
  'read_mask',
@@ -188,7 +227,7 @@ describe "JiakClient processing" do
188
227
  it "should update an existing bucket schema" do
189
228
  FooBarBazBuz = JiakDataFields.create(:foo,:bar,:baz,:buz)
190
229
  @client.set_schema(JiakBucket.new(@bucket_name,FooBarBazBuz))
191
-
230
+
192
231
  resp_schema = @client.schema(@bucket)
193
232
  resp_schema.allowed_fields.should include :buz
194
233
  resp_schema.required_fields.should be_empty
@@ -263,7 +302,7 @@ describe "JiakClient processing" do
263
302
  jobj.local?.should be true
264
303
  resp.local?.should be false
265
304
  end
266
-
305
+
267
306
  it "should handle odd key values" do
268
307
  key = '$ p @ c #'
269
308
  jobj = JiakObject.new(:bucket => @bucket, :key => key, :data => @data)
@@ -276,7 +315,7 @@ describe "JiakClient processing" do
276
315
  it "should check for resource existence" do
277
316
  jobj = JiakObject.new(:bucket => @bucket, :data => @data)
278
317
  key = @client.store(jobj)
279
-
318
+
280
319
  @client.exist?(@bucket,key).should be true
281
320
  @client.exist?(@bucket,'nope').should be false
282
321
  end
@@ -297,10 +336,25 @@ describe "JiakClient processing" do
297
336
  fetched.should be_a JiakObject
298
337
  end
299
338
 
339
+ it "should optionally convert data values" do
340
+ bucket = JiakBucket.new('date data',DateData)
341
+ name = 'leap'
342
+ date = Date.new(2004,02,29)
343
+ jobj = JiakObject.new(:bucket => bucket,
344
+ :data => DateData.new(:name => name,
345
+ :date => date))
346
+ jobj.data.name.should eql name
347
+ jobj.data.date.should eql date
348
+
349
+ jobj = @client.store(jobj, :return => :object)
350
+ jobj.data.name.should eql name
351
+ jobj.data.date.should eql date
352
+ end
353
+
300
354
  it "should accept write and read parameters" do
301
355
  key = 'fetch_key_wr'
302
356
  jobj = JiakObject.new(:bucket => @bucket, :key => key, :data => @data)
303
- jobj = @client.store(jobj,
357
+ jobj = @client.store(jobj,
304
358
  :writes => 3, :reads => 3,
305
359
  :return => :object)
306
360
 
@@ -318,7 +372,7 @@ describe "JiakClient processing" do
318
372
  jobj =
319
373
  @client.store(JiakObject.new(:bucket => @bucket, :data => @data),
320
374
  {:return => :object})
321
-
375
+
322
376
  jobj.data.should eql @data
323
377
  [:vclock,:vtag,:lastmod].each do |field|
324
378
  jobj.riak.should include field
@@ -328,7 +382,7 @@ describe "JiakClient processing" do
328
382
 
329
383
  updated_data = FooBarBaz.new(:foo => 'new val')
330
384
  jobj.data = updated_data
331
- updated_object =
385
+ updated_object =
332
386
  @client.store(jobj,{:return => :object})
333
387
  updated_data = updated_object.data
334
388
  updated_data.should_not eql @data
@@ -353,11 +407,6 @@ describe "JiakClient processing" do
353
407
 
354
408
  end
355
409
 
356
- class PersonData
357
- include JiakData
358
- attr_accessor :name
359
- end
360
-
361
410
  describe "JiakClient links" do
362
411
  before do
363
412
  @base_uri = SERVER_URI
@@ -440,7 +489,7 @@ describe "JiakClient links" do
440
489
  child.links.should include p_link
441
490
  end
442
491
  end
443
-
492
+
444
493
  # p's should include links to their c's
445
494
  c_link = QueryLink.new(@c_bucket,'child',nil)
446
495
  parent_children.each do |p_name,children|
@@ -318,6 +318,31 @@ describe "JiakResource class auto-update" do
318
318
 
319
319
  end
320
320
 
321
+ describe "JiakResource data conversion" do
322
+ require 'date'
323
+ class DogDate # :nodoc:
324
+ include JiakResource
325
+ server SERVER_URI
326
+ group 'dogs'
327
+ attr_accessor :name, :birthdate
328
+ convert :birthdate => lambda{|value| Date.parse(value)}
329
+ keygen { name }
330
+ auto_manage
331
+ end
332
+
333
+ it "should convert date data into a Date" do
334
+ name = 'Adelaide'
335
+ date = Date.new(1993,10,8)
336
+
337
+ addie = DogDate.new(:name => name, :birthdate => date)
338
+ addie.name.should eql name
339
+ addie.birthdate.should eql date
340
+
341
+ addie.delete
342
+ end
343
+
344
+ end
345
+
321
346
  describe "JiakResource simple" do
322
347
  class Dog # :nodoc:
323
348
  include JiakResource
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riakrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Rogers
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-11 00:00:00 -08:00
12
+ date: 2009-12-16 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -96,6 +96,8 @@ files:
96
96
  - examples/buoy.rb
97
97
  - examples/buoy_pov.rb
98
98
  - examples/example_helper.rb
99
+ - examples/jiak_client.data.rb
100
+ - examples/jiak_resource_data.rb
99
101
  - examples/linked_resources.rb
100
102
  - lib/riakrest.rb
101
103
  - lib/riakrest/core/exceptions.rb
@@ -167,4 +169,6 @@ test_files:
167
169
  - examples/buoy.rb
168
170
  - examples/buoy_pov.rb
169
171
  - examples/example_helper.rb
172
+ - examples/jiak_client.data.rb
173
+ - examples/jiak_resource_data.rb
170
174
  - examples/linked_resources.rb