friendly 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/friendly.gemspec +10 -10
- data/lib/friendly.rb +0 -1
- data/lib/friendly/translator.rb +5 -3
- data/lib/friendly/uuid.rb +2 -1
- data/spec/integration/basic_object_lifecycle_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/translator_spec.rb +4 -4
- metadata +96 -44
data/Rakefile
CHANGED
@@ -15,9 +15,9 @@ begin
|
|
15
15
|
gem.add_development_dependency "jferris-mocha"
|
16
16
|
gem.add_development_dependency "memcached"
|
17
17
|
gem.add_dependency "sequel", ">= 3.7.0"
|
18
|
-
gem.add_dependency "
|
19
|
-
gem.add_dependency "activesupport"
|
18
|
+
gem.add_dependency "activesupport", "=2.3.5"
|
20
19
|
gem.add_dependency "will_paginate"
|
20
|
+
gem.add_dependency "rufus-json", "=0.2.3"
|
21
21
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
22
|
end
|
23
23
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/friendly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{friendly}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Golick"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-02}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{jamesgolick@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -156,7 +156,7 @@ Gem::Specification.new do |s|
|
|
156
156
|
s.homepage = %q{http://friendlyorm.com}
|
157
157
|
s.rdoc_options = ["--charset=UTF-8"]
|
158
158
|
s.require_paths = ["lib"]
|
159
|
-
s.rubygems_version = %q{1.3.
|
159
|
+
s.rubygems_version = %q{1.3.7}
|
160
160
|
s.summary = %q{NoSQL with MySQL in Ruby}
|
161
161
|
s.test_files = [
|
162
162
|
"spec/fakes/data_store_fake.rb",
|
@@ -207,24 +207,24 @@ Gem::Specification.new do |s|
|
|
207
207
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
208
208
|
s.specification_version = 3
|
209
209
|
|
210
|
-
if Gem::Version.new(Gem::
|
210
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
211
211
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
212
212
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
213
213
|
s.add_development_dependency(%q<jferris-mocha>, [">= 0"])
|
214
214
|
s.add_development_dependency(%q<memcached>, [">= 0"])
|
215
215
|
s.add_runtime_dependency(%q<sequel>, [">= 3.7.0"])
|
216
|
-
s.add_runtime_dependency(%q<
|
217
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
216
|
+
s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
|
218
217
|
s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
|
218
|
+
s.add_runtime_dependency(%q<rufus-json>, ["= 0.2.3"])
|
219
219
|
else
|
220
220
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
221
221
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
222
222
|
s.add_dependency(%q<jferris-mocha>, [">= 0"])
|
223
223
|
s.add_dependency(%q<memcached>, [">= 0"])
|
224
224
|
s.add_dependency(%q<sequel>, [">= 3.7.0"])
|
225
|
-
s.add_dependency(%q<
|
226
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
225
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
227
226
|
s.add_dependency(%q<will_paginate>, [">= 0"])
|
227
|
+
s.add_dependency(%q<rufus-json>, ["= 0.2.3"])
|
228
228
|
end
|
229
229
|
else
|
230
230
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
@@ -232,9 +232,9 @@ Gem::Specification.new do |s|
|
|
232
232
|
s.add_dependency(%q<jferris-mocha>, [">= 0"])
|
233
233
|
s.add_dependency(%q<memcached>, [">= 0"])
|
234
234
|
s.add_dependency(%q<sequel>, [">= 3.7.0"])
|
235
|
-
s.add_dependency(%q<
|
236
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
235
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
237
236
|
s.add_dependency(%q<will_paginate>, [">= 0"])
|
237
|
+
s.add_dependency(%q<rufus-json>, ["= 0.2.3"])
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
data/lib/friendly.rb
CHANGED
data/lib/friendly/translator.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
require "rufus-json"
|
2
|
+
|
1
3
|
module Friendly
|
2
4
|
class Translator
|
3
5
|
RESERVED_ATTRS = [:id, :created_at, :updated_at].freeze
|
4
6
|
|
5
7
|
attr_reader :serializer, :time
|
6
8
|
|
7
|
-
def initialize(serializer =
|
9
|
+
def initialize(serializer = Rufus::Json, time = Time)
|
8
10
|
@serializer = serializer
|
9
11
|
@time = time
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_object(klass, record)
|
13
15
|
record.delete(:added_id)
|
14
|
-
attributes = serializer.
|
16
|
+
attributes = serializer.decode(record.delete(:attributes))
|
15
17
|
attributes.merge!(record).merge!(:new_record => false)
|
16
18
|
klass.new_without_change_tracking attributes
|
17
19
|
end
|
@@ -26,7 +28,7 @@ module Friendly
|
|
26
28
|
protected
|
27
29
|
def serialize(document)
|
28
30
|
attrs = document.to_hash.reject { |k,v| RESERVED_ATTRS.include?(k) }
|
29
|
-
serializer.
|
31
|
+
serializer.encode(attrs)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/friendly/uuid.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'friendly/time'
|
2
2
|
require 'friendly/attribute'
|
3
|
+
require 'rufus-json'
|
3
4
|
|
4
5
|
# This class was extracted from the cassandra gem by Evan Weaver
|
5
6
|
# As such, it is distributed under the terms of the apache license.
|
@@ -85,7 +86,7 @@ module Friendly
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def to_json(*args)
|
88
|
-
|
89
|
+
Rufus::Json.encode(to_guid)
|
89
90
|
end
|
90
91
|
|
91
92
|
def seconds
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
require 'rufus-json'
|
2
3
|
|
3
4
|
describe "Creating and retrieving an object" do
|
4
5
|
before do
|
@@ -39,7 +40,7 @@ describe "Creating and retrieving an object" do
|
|
39
40
|
|
40
41
|
it "doesn't serialize id, created_at, or updated_at in the attributes column" do
|
41
42
|
result = $db.from("users").first(:id => @user.id)
|
42
|
-
attrs =
|
43
|
+
attrs = Rufus::Json.decode(result[:attributes])
|
43
44
|
attrs.keys.should_not include("id")
|
44
45
|
attrs.keys.should_not include("created_at")
|
45
46
|
attrs.keys.should_not include("updated_at")
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ describe "Friendly::Translator" do
|
|
10
10
|
|
11
11
|
describe "translating a row to an object" do
|
12
12
|
before do
|
13
|
-
@serializer.stubs(:
|
13
|
+
@serializer.stubs(:decode).with("THE JSON").returns(:name => "Stewie")
|
14
14
|
@time = Time.new
|
15
15
|
@row = {:added_id => 12345,
|
16
16
|
:created_at => @time,
|
@@ -33,7 +33,7 @@ describe "Friendly::Translator" do
|
|
33
33
|
before do
|
34
34
|
@hash = {:name => "Stewie"}
|
35
35
|
@time.stubs(:new).returns(Time.new)
|
36
|
-
@serializer.stubs(:
|
36
|
+
@serializer.stubs(:encode).with(@hash).returns("SOME JSON")
|
37
37
|
@document = stub(:to_hash => @hash,
|
38
38
|
:new_record? => true,
|
39
39
|
:created_at => nil,
|
@@ -62,7 +62,7 @@ describe "Friendly::Translator" do
|
|
62
62
|
:created_at => @created_at,
|
63
63
|
:updated_at => Time.new}
|
64
64
|
@time.stubs(:new).returns(Time.new + 5000)
|
65
|
-
@serializer.stubs(:
|
65
|
+
@serializer.stubs(:encode).returns("SOME JSON")
|
66
66
|
@document = stub(:to_hash => @hash,
|
67
67
|
:created_at => @created_at,
|
68
68
|
:new_record? => false,
|
@@ -71,7 +71,7 @@ describe "Friendly::Translator" do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it "serializes the attributes" do
|
74
|
-
@serializer.should have_received(:
|
74
|
+
@serializer.should have_received(:encode).with(:name => "Stewie")
|
75
75
|
@record[:attributes].should == "SOME JSON"
|
76
76
|
end
|
77
77
|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 7
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- James Golick
|
@@ -9,89 +15,129 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-07-02 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: cucumber
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
33
48
|
version: "0"
|
34
|
-
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
35
51
|
- !ruby/object:Gem::Dependency
|
36
52
|
name: jferris-mocha
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
40
56
|
requirements:
|
41
57
|
- - ">="
|
42
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
43
62
|
version: "0"
|
44
|
-
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
45
65
|
- !ruby/object:Gem::Dependency
|
46
66
|
name: memcached
|
47
|
-
|
48
|
-
|
49
|
-
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
50
70
|
requirements:
|
51
71
|
- - ">="
|
52
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
53
76
|
version: "0"
|
54
|
-
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
55
79
|
- !ruby/object:Gem::Dependency
|
56
80
|
name: sequel
|
57
|
-
|
58
|
-
|
59
|
-
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
60
84
|
requirements:
|
61
85
|
- - ">="
|
62
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 27
|
88
|
+
segments:
|
89
|
+
- 3
|
90
|
+
- 7
|
91
|
+
- 0
|
63
92
|
version: 3.7.0
|
64
|
-
version:
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: json_pure
|
67
93
|
type: :runtime
|
68
|
-
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: "0"
|
74
|
-
version:
|
94
|
+
version_requirements: *id005
|
75
95
|
- !ruby/object:Gem::Dependency
|
76
96
|
name: activesupport
|
77
|
-
|
78
|
-
|
79
|
-
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
80
100
|
requirements:
|
81
|
-
- - "
|
101
|
+
- - "="
|
82
102
|
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
|
103
|
+
hash: 9
|
104
|
+
segments:
|
105
|
+
- 2
|
106
|
+
- 3
|
107
|
+
- 5
|
108
|
+
version: 2.3.5
|
109
|
+
type: :runtime
|
110
|
+
version_requirements: *id006
|
85
111
|
- !ruby/object:Gem::Dependency
|
86
112
|
name: will_paginate
|
87
|
-
|
88
|
-
|
89
|
-
|
113
|
+
prerelease: false
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
90
116
|
requirements:
|
91
117
|
- - ">="
|
92
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
93
122
|
version: "0"
|
94
|
-
|
123
|
+
type: :runtime
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rufus-json
|
127
|
+
prerelease: false
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - "="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 17
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
- 2
|
137
|
+
- 3
|
138
|
+
version: 0.2.3
|
139
|
+
type: :runtime
|
140
|
+
version_requirements: *id008
|
95
141
|
description: ""
|
96
142
|
email: jamesgolick@gmail.com
|
97
143
|
executables: []
|
@@ -247,21 +293,27 @@ rdoc_options:
|
|
247
293
|
require_paths:
|
248
294
|
- lib
|
249
295
|
required_ruby_version: !ruby/object:Gem::Requirement
|
296
|
+
none: false
|
250
297
|
requirements:
|
251
298
|
- - ">="
|
252
299
|
- !ruby/object:Gem::Version
|
300
|
+
hash: 3
|
301
|
+
segments:
|
302
|
+
- 0
|
253
303
|
version: "0"
|
254
|
-
version:
|
255
304
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
305
|
+
none: false
|
256
306
|
requirements:
|
257
307
|
- - ">="
|
258
308
|
- !ruby/object:Gem::Version
|
309
|
+
hash: 3
|
310
|
+
segments:
|
311
|
+
- 0
|
259
312
|
version: "0"
|
260
|
-
version:
|
261
313
|
requirements: []
|
262
314
|
|
263
315
|
rubyforge_project:
|
264
|
-
rubygems_version: 1.3.
|
316
|
+
rubygems_version: 1.3.7
|
265
317
|
signing_key:
|
266
318
|
specification_version: 3
|
267
319
|
summary: NoSQL with MySQL in Ruby
|