pragmatic_serializer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pragmatic_serializer/all.rb +12 -0
- data/lib/pragmatic_serializer/collection_interface.rb +16 -0
- data/lib/pragmatic_serializer/collection_serializer.rb +62 -0
- data/lib/pragmatic_serializer/config_interface.rb +19 -0
- data/lib/pragmatic_serializer/configuration.rb +25 -0
- data/lib/pragmatic_serializer/general_base_json.rb +31 -0
- data/lib/pragmatic_serializer/general_initialization.rb +14 -0
- data/lib/pragmatic_serializer/general_resource_json.rb +19 -0
- data/lib/pragmatic_serializer/pagination_json.rb +40 -0
- data/lib/pragmatic_serializer/prefixes.rb +21 -0
- data/lib/pragmatic_serializer/version.rb +3 -0
- data/lib/pragmatic_serializer.rb +23 -0
- data/pragmatic_serializer.gemspec +27 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f989efdf00a8f3a04142577c76d5190a430287dd
|
4
|
+
data.tar.gz: e5eaca6087d796aab8a7edf1356edf151185c953
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e3221363a8f0aeea292f117efeae5fbd2c716a9f94cc9f521057565b56f1778dc8f876c55f47327393f4dab73f40cba74584a323a0ec9f90fbc656e449e0080
|
7
|
+
data.tar.gz: 683b346ef7875cd0a0129101523a73f3d5961a86b2e6f834ff4812914a08f79f66186ca40d7f502e4fafa5531e482cb8907f8744a738b66e35105ba1d0dd0518
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at equivalent@eq8.eu. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tomas Valent
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Pobble/pragmatic_serializer.svg?branch=master)](https://travis-ci.org/Pobble/pragmatic_serializer)
|
2
|
+
|
3
|
+
# PragmaticSerializer
|
4
|
+
|
5
|
+
Pragmatic Serializer for Ruby & Ruby on Rails JSON API.
|
6
|
+
|
7
|
+
|
8
|
+
## About
|
9
|
+
|
10
|
+
Although we agre that [JSON API standard proposal](http://jsonapi.org/)
|
11
|
+
is great, it may be overkill to implement some of it's features (like the way nesting is done) for smaller
|
12
|
+
API Endpoints.
|
13
|
+
|
14
|
+
Therefore if you feel that implementing
|
15
|
+
[Active Model Serializer](https://github.com/rails-api/active_model_serializers) (JSON API Rails gem)
|
16
|
+
is not the best choice for your situation/app this gem may be useful for you
|
17
|
+
too.
|
18
|
+
|
19
|
+
We were heavily inspired by [Stormpath API talk on JSON API](https://www.youtube.com/watch?v=hdSrT4yjS1g)
|
20
|
+
and the pragmatic way they solve some common issues.
|
21
|
+
|
22
|
+
Also the gem don't extend anything Rails wise (therefore Sinatra can use
|
23
|
+
it too), it just provides a generic
|
24
|
+
way to build Plain Ruby Object Serializers that you can call `as_json`
|
25
|
+
on to produce hash that you can then pass to `render json:
|
26
|
+
DocumentSerializer.new(document: Document.last).as_json`
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'pragmatic_serializer'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Or install it yourself as:
|
41
|
+
|
42
|
+
$ gem install pragmatic_serializer
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
|
47
|
+
#### Collections
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
r1 = Band.first
|
51
|
+
r2 = Band.last
|
52
|
+
|
53
|
+
class BandPolicy
|
54
|
+
attr_reader :current_user
|
55
|
+
|
56
|
+
def initialize(current_user:)
|
57
|
+
@current_user = current_user
|
58
|
+
end
|
59
|
+
|
60
|
+
def can_view_counters?
|
61
|
+
current_user.admin == true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class MySerializer
|
66
|
+
include PragmaticSerializer::All
|
67
|
+
|
68
|
+
attr_accessor :policy
|
69
|
+
|
70
|
+
def main_json
|
71
|
+
hash = { title: band.title }
|
72
|
+
hash.merge!(view_count: band.view_count) if policy.can_view_counters?
|
73
|
+
hash
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
policy = BandPolicy.new(current_user: current_user)
|
78
|
+
|
79
|
+
serializer = MySerializer.collection([r1, r2], resource_options: { :"policy=" => policy })
|
80
|
+
serializer.as_json
|
81
|
+
```
|
82
|
+
|
83
|
+
As regular user:
|
84
|
+
|
85
|
+
```json
|
86
|
+
{
|
87
|
+
"id":"123",
|
88
|
+
"type":"band",
|
89
|
+
"title":"Bring Me The Horizon"
|
90
|
+
}
|
91
|
+
```
|
92
|
+
|
93
|
+
As admin
|
94
|
+
|
95
|
+
```json
|
96
|
+
{
|
97
|
+
"id":"123",
|
98
|
+
"type":"band",
|
99
|
+
"title":"Bring Me The Horizon",
|
100
|
+
"view_count": 2001
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Change ID field
|
105
|
+
|
106
|
+
by default the ID field is models `#id`. To change it
|
107
|
+
|
108
|
+
```
|
109
|
+
# config/initializers/pragmatic_serializer.rb
|
110
|
+
|
111
|
+
PragmaticSerializer.config.default_id_source = :public_uid # if you using https://github.com/equivalent/public_uid
|
112
|
+
|
113
|
+
# ..or
|
114
|
+
PragmaticSerializer.config.default_id_source = :url_slug # custom field
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
## Development
|
119
|
+
|
120
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
121
|
+
|
122
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pragmatic_serializer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
127
|
+
|
128
|
+
|
129
|
+
## License
|
130
|
+
|
131
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
132
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pragmatic_serializer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module All
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:include, PragmaticSerializer::ConfigInterface)
|
5
|
+
base.send(:include, PragmaticSerializer::Prefixes)
|
6
|
+
base.send(:include, PragmaticSerializer::GeneralInitialization)
|
7
|
+
base.send(:include, PragmaticSerializer::GeneralBaseJSON)
|
8
|
+
base.send(:include, PragmaticSerializer::GeneralResourceJSON)
|
9
|
+
base.send(:include, PragmaticSerializer::CollectionInterface)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module CollectionInterface
|
3
|
+
module ClassMethods
|
4
|
+
def collection(resources, resource_options: {})
|
5
|
+
PragmaticSerializer::CollectionSerializer.new
|
6
|
+
.tap { |cs| cs.resource_serializer = self }
|
7
|
+
.tap { |cs| cs.resources = resources }
|
8
|
+
.tap { |cs| cs.resource_options = resource_options }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.send(:extend, ClassMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
class CollectionSerializer
|
3
|
+
OverMaximumLimit = Class.new(StandardError)
|
4
|
+
|
5
|
+
extend Forwardable
|
6
|
+
include PragmaticSerializer::ConfigInterface
|
7
|
+
|
8
|
+
attr_writer :limit, :offset, :serialization_method, :resource_options
|
9
|
+
attr_accessor :resources, :resource_serializer, :pagination_evaluator
|
10
|
+
|
11
|
+
def serialization_method
|
12
|
+
@serialization_method ||= config.default_resource_serialization_method
|
13
|
+
end
|
14
|
+
|
15
|
+
def limit
|
16
|
+
@limit ||= config.default_limit
|
17
|
+
raise OverMaximumLimit if @limit > config.max_limit
|
18
|
+
@limit
|
19
|
+
end
|
20
|
+
|
21
|
+
def offset
|
22
|
+
@offset ||= config.default_offset
|
23
|
+
end
|
24
|
+
|
25
|
+
def as_json
|
26
|
+
hash = { collection_prefix => as_unprefixed_json }
|
27
|
+
hash.merge!(pagination_json.as_json) if pagination_evaluator
|
28
|
+
hash
|
29
|
+
end
|
30
|
+
|
31
|
+
def as_unprefixed_json
|
32
|
+
collection_serializers.map { |rs| rs.send(serialization_method) }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def_delegators :resource_serializer, :resource_prefix, :collection_prefix
|
37
|
+
|
38
|
+
def collection_serializers
|
39
|
+
resources.map do |resource|
|
40
|
+
resource_object = resource_serializer.new(resource_prefix => resource)
|
41
|
+
|
42
|
+
resource_options.each do |method_name, value|
|
43
|
+
resource_object.send(method_name, value)
|
44
|
+
end
|
45
|
+
|
46
|
+
resource_object
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def pagination_json
|
51
|
+
@pagination_json ||= PragmaticSerializer::PaginationJSON.new({
|
52
|
+
limit: limit,
|
53
|
+
offset: offset,
|
54
|
+
pagination_evaluator: pagination_evaluator
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def resource_options
|
59
|
+
@resource_options ||= {}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module ConfigInterface
|
3
|
+
module ClassMethods
|
4
|
+
def config
|
5
|
+
PragmaticSerializer.config
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.send(:extend, ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def config
|
16
|
+
self.class.config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
class Configuration
|
3
|
+
attr_writer :default_id_source
|
4
|
+
|
5
|
+
def default_offset
|
6
|
+
0
|
7
|
+
end
|
8
|
+
|
9
|
+
def default_limit
|
10
|
+
50
|
11
|
+
end
|
12
|
+
|
13
|
+
def max_limit
|
14
|
+
200
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_id_source
|
18
|
+
@default_id_source ||= :id
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_resource_serialization_method
|
22
|
+
:as_unprefixed_json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module GeneralBaseJSON
|
3
|
+
IDHasNoValue = Class.new(StandardError)
|
4
|
+
|
5
|
+
def base_json
|
6
|
+
{
|
7
|
+
"id": (json_id_value).to_s,
|
8
|
+
"type": json_type_value,
|
9
|
+
}
|
10
|
+
.tap do |hash|
|
11
|
+
hash.merge!(href: json_href_value) if json_href_value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def json_id_value
|
18
|
+
send(prefix).send(json_id_source) || raise(IDHasNoValue)
|
19
|
+
end
|
20
|
+
|
21
|
+
def json_id_source
|
22
|
+
config.default_id_source
|
23
|
+
end
|
24
|
+
|
25
|
+
def json_type_value
|
26
|
+
prefix.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def json_href_value;end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module GeneralInitialization
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:attr_reader, base.resource_prefix)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(**options)
|
8
|
+
value = options.fetch(prefix) do |x|
|
9
|
+
raise ArgumentError.new("missing keyword: #{x}")
|
10
|
+
end
|
11
|
+
instance_variable_set("@#{prefix}", value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module GeneralResourceJSON
|
3
|
+
def as_unprefixed_json
|
4
|
+
base_json.merge(main_json)
|
5
|
+
end
|
6
|
+
|
7
|
+
def as_json
|
8
|
+
{
|
9
|
+
prefix.to_sym => as_unprefixed_json
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_base_json
|
14
|
+
{
|
15
|
+
prefix.to_sym => base_json
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
class PaginationJSON
|
3
|
+
attr_reader :limit, :offset, :pagination_evaluator
|
4
|
+
attr_accessor :maximum_offset
|
5
|
+
|
6
|
+
def initialize(limit:, offset:, pagination_evaluator:)
|
7
|
+
@limit = limit
|
8
|
+
@offset = offset
|
9
|
+
@pagination_evaluator = pagination_evaluator
|
10
|
+
@maximum_offset = Float::INFINITY
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_json
|
14
|
+
{
|
15
|
+
limit: limit,
|
16
|
+
offset: offset,
|
17
|
+
href: href,
|
18
|
+
first: first,
|
19
|
+
next: self.next,
|
20
|
+
prev: prev,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def first
|
25
|
+
pagination_evaluator.call(limit: limit, offset: 0)
|
26
|
+
end
|
27
|
+
|
28
|
+
def next
|
29
|
+
pagination_evaluator.call(limit: limit, offset: offset+1) unless offset >= maximum_offset
|
30
|
+
end
|
31
|
+
|
32
|
+
def prev
|
33
|
+
pagination_evaluator.call(limit: limit, offset: offset-1) if offset > 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def href
|
37
|
+
pagination_evaluator.call(limit: limit, offset: offset)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PragmaticSerializer
|
2
|
+
module Prefixes
|
3
|
+
module ClassMethods
|
4
|
+
def collection_prefix
|
5
|
+
name.demodulize.underscore.gsub('_serializer', '').pluralize.to_sym
|
6
|
+
end
|
7
|
+
|
8
|
+
def resource_prefix
|
9
|
+
name.demodulize.underscore.gsub('_serializer', '').singularize.to_sym
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.send(:extend, ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
def prefix
|
18
|
+
self.class.resource_prefix
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
require "pragmatic_serializer/version"
|
5
|
+
require "pragmatic_serializer/configuration"
|
6
|
+
require "pragmatic_serializer/config_interface"
|
7
|
+
|
8
|
+
require "pragmatic_serializer/prefixes"
|
9
|
+
require "pragmatic_serializer/general_initialization"
|
10
|
+
require "pragmatic_serializer/general_base_json"
|
11
|
+
require "pragmatic_serializer/general_resource_json"
|
12
|
+
|
13
|
+
require "pragmatic_serializer/pagination_json"
|
14
|
+
require "pragmatic_serializer/collection_serializer"
|
15
|
+
require "pragmatic_serializer/collection_interface"
|
16
|
+
|
17
|
+
require "pragmatic_serializer/all"
|
18
|
+
|
19
|
+
module PragmaticSerializer
|
20
|
+
def self.config
|
21
|
+
@config ||= Configuration.new
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pragmatic_serializer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pragmatic_serializer"
|
8
|
+
spec.version = PragmaticSerializer::VERSION
|
9
|
+
spec.authors = ["Tomas Valent"]
|
10
|
+
spec.email = ["equivalent@eq8.eu"]
|
11
|
+
|
12
|
+
spec.summary = %q{JSON API serializer following Pragmatic JSON standard}
|
13
|
+
spec.description = %q{JSON API Serializer to produce RESTful serializer using plain Ruby Ojects that follows common sense and heavily inspired by StormpathAPI talks}
|
14
|
+
spec.homepage = "https://github.com/equivalent/pragmatic_serializer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "activerecord", "~> 4.2"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pragmatic_serializer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Valent
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: JSON API Serializer to produce RESTful serializer using plain Ruby Ojects
|
84
|
+
that follows common sense and heavily inspired by StormpathAPI talks
|
85
|
+
email:
|
86
|
+
- equivalent@eq8.eu
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/pragmatic_serializer.rb
|
102
|
+
- lib/pragmatic_serializer/all.rb
|
103
|
+
- lib/pragmatic_serializer/collection_interface.rb
|
104
|
+
- lib/pragmatic_serializer/collection_serializer.rb
|
105
|
+
- lib/pragmatic_serializer/config_interface.rb
|
106
|
+
- lib/pragmatic_serializer/configuration.rb
|
107
|
+
- lib/pragmatic_serializer/general_base_json.rb
|
108
|
+
- lib/pragmatic_serializer/general_initialization.rb
|
109
|
+
- lib/pragmatic_serializer/general_resource_json.rb
|
110
|
+
- lib/pragmatic_serializer/pagination_json.rb
|
111
|
+
- lib/pragmatic_serializer/prefixes.rb
|
112
|
+
- lib/pragmatic_serializer/version.rb
|
113
|
+
- pragmatic_serializer.gemspec
|
114
|
+
homepage: https://github.com/equivalent/pragmatic_serializer
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.8
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: JSON API serializer following Pragmatic JSON standard
|
138
|
+
test_files: []
|