mongoid-serializer 0.0.3 → 0.0.4

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: c2657c7992af64ad72f4fe27e78596692d0a4d80
4
- data.tar.gz: 30cd54dd1c9a6c1c06b6ebafa50b54fee8521567
3
+ metadata.gz: 17785512c923879da4e67fa785a4dae5aa88e131
4
+ data.tar.gz: c96bb37b19a0c70b068758fa7cdc820098abcd16
5
5
  SHA512:
6
- metadata.gz: 3208f6fe803c491399f8cb16f5b1be59aa60f49f36835ccd2bbeb0966713df06a2a7e854e0f009c65bfe08ce8d5fb4208828cf0f6f1c038465388385b6348ab4
7
- data.tar.gz: 60eb85ebdd6caf5de102d823a9255d5cfd1ae46a4f93ab0a9f9a51cdcc403fe2d7a55c66d26a4dead11912767179e982569659662c0e7804d168bc81b2432bc3
6
+ metadata.gz: 87fbbbdcdb6d35093e53ffaa6c5661a1140f84264e83052df5c457bf12d2ad981b03fe75a58d738d479aa335da4e93d97d581df76e073824c169acbb529947a4
7
+ data.tar.gz: fbd5b1c71e490aeb22f8deedcdfc9b577fdb5ef0bad7a486c6d541e8fdb24f0f772d6db39bebdb086d35420a4ac04df7a2c0bf1511cd00bb4f73be6326bf2500
data/README.md CHANGED
@@ -21,18 +21,16 @@ Or install it yourself as:
21
21
 
22
22
  $ gem install mongoid-serializer
23
23
 
24
- If the gem isn't activated automatically, you can add configuration in an initializer file, f.ex `mongoid_config.rb`
25
24
 
26
- ```ruby
27
- # mongoid_config.rb
28
- Mongoid::Serializer.configure!
29
- ```
25
+ ## Config
26
+
27
+ `Mongoid::Serializer.configure!`
30
28
 
31
29
  ## Usage
32
30
 
33
31
  ```ruby
34
32
  class UserSerializer < ActiveModel::MongoidSerializer
35
- attributes :id, :first_name, :last_name, :quote, :age
33
+ attributes :id, :first_name, :last_name, :quote, :age, http_status
36
34
  end
37
35
  ```
38
36
 
@@ -40,9 +38,9 @@ Additionally this gem includes a `ActiveModel::StateTracking` module. This modul
40
38
 
41
39
  You can either include this module in models of your choice, or include it into `Mongoid::Document` to make it part of every model.
42
40
 
43
- For convenience, a method `Mongoid::Serializer.enable_state_tracking!` is made available to add state tracking to all Documents.
41
+ `ActiveModel::StatusSerializer` is configured to try to hook into the `StateTracking` methods from [active_model-shaz](https://github.com/kristianmandrup/active_model-shaz) and set the JSON `http_status` key to either `201` or `204`, to reflect created or deleted state back to the client.
44
42
 
45
- `ActiveModel::MongoidSerializer` is configured to try to hook into the `StateTracking` methods and set the JSON `status:` key to either `201` or `204`, to reflect created or deleted state back to the client.
43
+ `ActiveModel::MongoidSerializer` extends `ActiveModel::StatusSerializer` and sets the `id` attribute to point to `_id` to better work with what the usual client side APIs expect (f.ex for use with ember-data).
46
44
 
47
45
  ## Contributing
48
46
 
@@ -6,52 +6,27 @@ module Mongoid
6
6
  Mongoid::Document.send(:include, ActiveModel::SerializerSupport)
7
7
  Mongoid::Criteria.delegate(:active_model_serializer, to: :to_a)
8
8
  end
9
-
10
- def self.enable_state_tracking!
11
- require "mongoid/serializer/state_tracking"
12
- end
13
9
  end
14
10
  end
15
11
 
16
- if defined?(Mongoid)
17
- Mongoid::Serializer.configure!
18
- end
19
12
 
20
13
  module ActiveModel
21
- class MongoidSerializer < Serializer
22
- def id
23
- object._id
24
- end
25
-
26
- def status
14
+ class StatusSerializer < Serializer
15
+ def http_status
27
16
  return 204 if object.respond_to?(:destroyed?) && object.destroyed?
28
17
  return 201 if object.respond_to?(:created?) && object.created?
29
18
  end
30
19
  end
31
20
  end
32
21
 
33
- module ActiveModel::StateTracking
34
- extend ActiveSupport::Concern
35
-
36
- included do
37
- after_create do
38
- @created = true
39
- end
40
-
41
- after_update do
42
- @created = false
43
- end
44
-
45
- after_destroy do
46
- @destroyed = true
22
+ module ActiveModel
23
+ class MongoidSerializer < StatusSerializer
24
+ def id
25
+ object._id
47
26
  end
48
27
  end
28
+ end
49
29
 
50
- def created?
51
- @created == true
52
- end
53
-
54
- def destroyed?
55
- @destroyed == true
56
- end
30
+ if defined?(Mongoid)
31
+ Mongoid::Serializer.configure!
57
32
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Serializer
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'mongoid', '>= 3.0'
22
+ spec.add_dependency 'active_model-shaz'
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-serializer
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
  - Kristian Mandrup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_model-shaz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -65,7 +79,6 @@ files:
65
79
  - README.md
66
80
  - Rakefile
67
81
  - lib/mongoid/serializer.rb
68
- - lib/mongoid/serializer/state_tracking.rb
69
82
  - lib/mongoid/serializer/version.rb
70
83
  - mongoid-serializer.gemspec
71
84
  homepage: https://github.com/kristianmandrup/mongoid-serializer
@@ -1,3 +0,0 @@
1
- module Mongoid::Document
2
- include ActiveModel::StateTracking
3
- end