cerializable 0.0.2 → 0.1.0
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 +4 -4
- data/lib/cerializable/acts_as_cerializable.rb +5 -7
- data/lib/cerializable/version.rb +1 -1
- data/test/acts_as_cerializable_test.rb +19 -21
- data/test/dummy/config/application.rb +1 -2
- data/test/dummy/log/test.log +3288 -0
- metadata +5 -6
- data/README.rdoc +0 -48
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cerializable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Arnold
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
19
|
+
version: 4.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0
|
26
|
+
version: 4.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +46,6 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- MIT-LICENSE
|
49
|
-
- README.rdoc
|
50
49
|
- Rakefile
|
51
50
|
- lib/cerializable.rb
|
52
51
|
- lib/cerializable/acts_as_cerializable.rb
|
@@ -117,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
116
|
requirements:
|
118
117
|
- - ">="
|
119
118
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
119
|
+
version: 2.2.2
|
121
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
121
|
requirements:
|
123
122
|
- - ">="
|
data/README.rdoc
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
= Cerializable
|
2
|
-
|
3
|
-
Cerializable provides flexible custom serialization for Rails models.
|
4
|
-
|
5
|
-
HOW TO USE
|
6
|
-
|
7
|
-
Add Cerializable to your Gemfile
|
8
|
-
|
9
|
-
gem 'cerializable', git: 'git://github.com/nativestranger/cerializable.git', branch: 'master'
|
10
|
-
|
11
|
-
Call 'acts_as_cerializable' in the models you wish to use Cerializable with.
|
12
|
-
|
13
|
-
class Comment < ApplicationRecord
|
14
|
-
acts_as_cerializable
|
15
|
-
end
|
16
|
-
|
17
|
-
Define corresponding serializer modules.
|
18
|
-
|
19
|
-
module CommentSerializer
|
20
|
-
|
21
|
-
include ActionView::Helpers::DateHelper
|
22
|
-
|
23
|
-
def run(comment, options)
|
24
|
-
{ id: comment.id,
|
25
|
-
user: { id: comment.user.id,
|
26
|
-
name: comment.user.name },
|
27
|
-
body: comment.body,
|
28
|
-
ancestorCount: comment.ancestor_count,
|
29
|
-
childComments: options[:children] || comment.child_comments.order(id: :desc).map { |c| c.serializable_hash },
|
30
|
-
createdAtInWords: "#{ time_ago_in_words(comment.created_at) } ago" }
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
The only requirement is that the 'run' method accepts two arguments and returns a hash which details how any given instance of your model is to be represented in JSON.
|
36
|
-
|
37
|
-
Pass custom options to #as_json, #to_json, or #serializable_hash and your models will use the #run method of their serializers to produce the result.
|
38
|
-
|
39
|
-
If you wish, you can specify the serializer module to use:
|
40
|
-
|
41
|
-
class Comment < ApplicationRecord
|
42
|
-
acts_as_cerializable serialize_with: SomeSerializerModule
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
TODO:
|
47
|
-
|
48
|
-
* Support #to_xml
|