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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cb3d508860caa3dc32dc42d5576fc1dc3319d7d
4
- data.tar.gz: a2bf374a731001a116227af14d9e1d06719a0f3c
3
+ metadata.gz: a1fd9b7a915c71f1ac16a5155923c05479686343
4
+ data.tar.gz: 7d5229fb81bc664bc5a038fce4c35d7dd6415a97
5
5
  SHA512:
6
- metadata.gz: 35770de8b7dfec7e9d0d5513034888d124891baffe6a4dfbd978bb1413d903f6351bb2c7703c658131151b55cd399f36207882178214750b429ca094d59efb0c
7
- data.tar.gz: 0b9d7cbf9cc86d5f528c7b75c521afd2fa2b04ff71d170b04c486ba766d14cbb05433c29a7cba6f944484bb50808053f3fb11d78c28b1b4be337eb5ba78adcf1
6
+ metadata.gz: 69837e19a4ea03e13d86b41d8692547ca6130663a84484eeced53aa7a6f10ae21bf0302633d8cf5752fe117117de95507e5ebf3d20368f2567546cc5fda32729
7
+ data.tar.gz: 7a3b832d0df34f00a70676782acb808d368abaf8ab5771e99b87b09af64e150051ba50698609889c479f3f92ced7ae5c4d30989885d5496bed41350943f2f01d
@@ -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 = collection.map do |item|
80
- serializer.new(item, context).as_json
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
@@ -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(nagare_adapter.new(serializer), options)
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: 0.1.0
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-01 00:00:00.000000000 Z
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: