nagare 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nagare.rb +7 -4
- data/lib/nagare/railtie.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1fd9b7a915c71f1ac16a5155923c05479686343
|
4
|
+
data.tar.gz: 7d5229fb81bc664bc5a038fce4c35d7dd6415a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69837e19a4ea03e13d86b41d8692547ca6130663a84484eeced53aa7a6f10ae21bf0302633d8cf5752fe117117de95507e5ebf3d20368f2567546cc5fda32729
|
7
|
+
data.tar.gz: 7a3b832d0df34f00a70676782acb808d368abaf8ab5771e99b87b09af64e150051ba50698609889c479f3f92ced7ae5c4d30989885d5496bed41350943f2f01d
|
data/lib/nagare.rb
CHANGED
@@ -14,6 +14,8 @@ module Nagare
|
|
14
14
|
define_method(attribute) do
|
15
15
|
if object.respond_to?(attribute)
|
16
16
|
object.send(attribute)
|
17
|
+
elsif context.respond_to?(attribute)
|
18
|
+
context.send(attribute)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -76,8 +78,8 @@ module Nagare
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def as_json(options = nil)
|
79
|
-
items =
|
80
|
-
|
81
|
+
items = map do |item|
|
82
|
+
item.as_json
|
81
83
|
end
|
82
84
|
|
83
85
|
attributes.merge({
|
@@ -92,8 +94,9 @@ module Nagare
|
|
92
94
|
end
|
93
95
|
|
94
96
|
class Adapter
|
95
|
-
def initialize(serializer)
|
97
|
+
def initialize(serializer, collection: false)
|
96
98
|
@serializer = serializer
|
99
|
+
@collection = collection
|
97
100
|
end
|
98
101
|
|
99
102
|
def as_json(options = nil)
|
@@ -102,7 +105,7 @@ module Nagare
|
|
102
105
|
|
103
106
|
private
|
104
107
|
|
105
|
-
attr_reader :serializer
|
108
|
+
attr_reader :serializer, :collection
|
106
109
|
end
|
107
110
|
|
108
111
|
class Context
|
data/lib/nagare/railtie.rb
CHANGED
@@ -23,13 +23,15 @@ module Nagare
|
|
23
23
|
|
24
24
|
serializer = collection_serializer.
|
25
25
|
new(resource, nagare_context.extend(options.fetch(:context, {})), serializer: item_serializer)
|
26
|
+
adapter = nagare_adapter.new(serializer, collection: true)
|
26
27
|
else
|
27
28
|
item_serializer = serializers.fetch(:item)
|
28
29
|
|
29
30
|
serializer = item_serializer.new(resource, nagare_context.extend(options.fetch(:context, {})))
|
31
|
+
adapter = nagare_adapter.new(serializer, collection: false)
|
30
32
|
end
|
31
33
|
|
32
|
-
super(
|
34
|
+
super(adapter, options)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Oestrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -72,3 +72,4 @@ signing_key:
|
|
72
72
|
specification_version: 4
|
73
73
|
summary: Serialize your ruby objects
|
74
74
|
test_files: []
|
75
|
+
has_rdoc:
|