mongoid-nested-serialization 0.0.4 → 0.0.5
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/lib/mongoid-nested-serialization.rb +1 -11
- data/lib/mongoid/nested_serialization.rb +1 -0
- data/lib/mongoid/nested_serialization/core_ext.rb +10 -0
- data/lib/mongoid/nested_serialization/finder.rb +16 -15
- data/lib/mongoid/nested_serialization/version.rb +1 -1
- data/spec/spec_helper.rb +2 -5
- metadata +4 -3
@@ -1,12 +1,2 @@
|
|
1
|
-
require "mongoid"
|
2
|
-
require "mongoid/nested_serialization/version"
|
3
1
|
require "mongoid/nested_serialization"
|
4
|
-
|
5
|
-
module Mongoid
|
6
|
-
module Document
|
7
|
-
def self.included(base)
|
8
|
-
super
|
9
|
-
base.send(:include, Mongoid::NestedSerialization)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
2
|
+
require "mongoid/nested_serialization/version"
|
@@ -3,21 +3,6 @@ require "multi_json"
|
|
3
3
|
module Mongoid
|
4
4
|
module NestedSerialization
|
5
5
|
class Finder
|
6
|
-
# parse the raw JSON data into a hash
|
7
|
-
def self.parse_input(json)
|
8
|
-
MultiJson.load(json)
|
9
|
-
end
|
10
|
-
|
11
|
-
# load the top level object directly with the collection
|
12
|
-
def self.top_level_object(data)
|
13
|
-
data["class_name"].constantize.find(data["id"])
|
14
|
-
end
|
15
|
-
|
16
|
-
# load an object nested within another, using the data
|
17
|
-
def self.nested_object(object, data)
|
18
|
-
object.send(data["association"]).find(data["id"])
|
19
|
-
end
|
20
|
-
|
21
6
|
def self.find(json)
|
22
7
|
data = parse_input(json)
|
23
8
|
# load the top level object
|
@@ -32,6 +17,22 @@ module Mongoid
|
|
32
17
|
# once at the bottom, return the object
|
33
18
|
object
|
34
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
# parse the raw JSON data into a hash
|
23
|
+
def self.parse_input(json)
|
24
|
+
MultiJson.load(json)
|
25
|
+
end
|
26
|
+
|
27
|
+
# load the top level object directly with the collection
|
28
|
+
def self.top_level_object(data)
|
29
|
+
data["class_name"].constantize.find(data["id"])
|
30
|
+
end
|
31
|
+
|
32
|
+
# load an object nested within another, using the data
|
33
|
+
def self.nested_object(object, data)
|
34
|
+
object.send(data["association"]).find(data["id"])
|
35
|
+
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,7 @@ SimpleCov.start do
|
|
3
3
|
add_filter "/spec/"
|
4
4
|
end
|
5
5
|
|
6
|
-
require "
|
7
|
-
require
|
8
|
-
|
9
|
-
lib = File.expand_path("../../lib", __FILE__)
|
10
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require "bundler"
|
7
|
+
Bundler.require
|
11
8
|
|
12
9
|
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-nested-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- lib/mongoid-nested-serialization.rb
|
126
126
|
- lib/mongoid/nested_serialization.rb
|
127
|
+
- lib/mongoid/nested_serialization/core_ext.rb
|
127
128
|
- lib/mongoid/nested_serialization/finder.rb
|
128
129
|
- lib/mongoid/nested_serialization/serializer.rb
|
129
130
|
- lib/mongoid/nested_serialization/version.rb
|
@@ -151,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
segments:
|
153
154
|
- 0
|
154
|
-
hash: -
|
155
|
+
hash: -98816556624355443
|
155
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
157
|
none: false
|
157
158
|
requirements:
|
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
version: '0'
|
161
162
|
segments:
|
162
163
|
- 0
|
163
|
-
hash: -
|
164
|
+
hash: -98816556624355443
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
167
|
rubygems_version: 1.8.24
|