muesli 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d88c7b5ea190a21c2f434d660fc6a096fc7fb1b
4
- data.tar.gz: 61c0ebb207d165d27354cdbd67951e5a0eacd879
3
+ metadata.gz: d7f19a08f4b26660bcdacf136c51d3dcf633cff6
4
+ data.tar.gz: dd88ad4e223ab62f9eabd3dd7c2150c316031c37
5
5
  SHA512:
6
- metadata.gz: 3ba343f8c5e11e8487a4c19f7b118af386c0377b846c5af686d000329c064f3e124c00f44a53987f92cdf7e3abdee64a2d1321f479d352d3bdf9760d3d3de5aa
7
- data.tar.gz: aeebe4cd258a35f88e83455bd14e6e3bb49926eba518373a96bec862dee76a8838f751968fe6c88a1d9e803017a12d16a808f4c254f5ffb9af07929904cfa7ae
6
+ metadata.gz: 48204ca4d266fc21d197a3d30a357f969604ca68e2e118daacb015752d38b5539fde97831bb78ec57e9eb8976c83ea8e41f1a6bc401a750c888a58502e581177
7
+ data.tar.gz: 1f7416429b01b0522218a4e617a61dc0b7e2727595b01f22d99415d40f980d93c24dafc8858efcbe2438ce2a70937c2e10f3b1eadd056f7d06fd9d2e2a17c52e
@@ -0,0 +1,13 @@
1
+ module Muesli
2
+ module Adapters
3
+ module CanCan
4
+ attr_accessor :ability
5
+
6
+ protected
7
+
8
+ def cache_key
9
+ "#{model.class.to_s.underscore}-#{model.id}-#{model.updated_at}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -22,9 +22,18 @@ module Muesli
22
22
  end
23
23
 
24
24
  def serialize_attributes(attribute_source, attribute_list)
25
- return attribute_list.reduce({}) do |memo, attr|
26
- memo[attr] = serialize_value( attribute_source.send(attr) )
27
- memo
25
+ return attribute_list.map do |attr|
26
+ map_from_source(attribute_source, attr)
27
+ end.compact.to_h
28
+ end
29
+
30
+ def map_from_source(attribute_source, attr)
31
+ if attribute_source.respond_to?(attr)
32
+ begin
33
+ [ attr, serialize_value( attribute_source.send(attr) ) ]
34
+ rescue ActiveModel::MissingAttributeError
35
+ nil
36
+ end
28
37
  end
29
38
  end
30
39
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muesli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Connor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Provides serialization of models into hashes with attribute whitelisting
14
- and authorization for passing to views or as an API response.
13
+ description: Provides class-based recursive serialization of models into hashes with
14
+ attribute whitelisting and conditionals for passing to views or as an API response.
15
15
  email: danconn@danconnor.com
16
16
  executables: []
17
17
  extensions: []
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - lib/muesli.rb
21
21
  - lib/muesli/adapters/cancan.rb
22
+ - lib/muesli/adapters/rack_cache.rb
22
23
  - lib/muesli/attribute_serializers/base.rb
23
24
  - lib/muesli/attribute_serializers/bson_objectid.rb
24
25
  - lib/muesli/attribute_serializers/date.rb
@@ -49,6 +50,6 @@ rubyforge_project:
49
50
  rubygems_version: 2.2.2
50
51
  signing_key:
51
52
  specification_version: 4
52
- summary: Provides serialization of models into hashes with attribute whitelisting
53
- and authorization for passing to views or as an API response.
53
+ summary: Provides class-based recursive serialization of models into hashes with attribute
54
+ whitelisting and conditionals for passing to views or as an API response.
54
55
  test_files: []