playdough 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3103a35ae4c7b5b73d38ce6f9b70c451ae2cb4bd
4
+ data.tar.gz: dbd330027d673e4bf5b40272d3174d139ece30a4
5
+ SHA512:
6
+ metadata.gz: 80f383bd51676c39a7bb1749475446e502d40ca1c43f1610afa92e9182d2b2f6b5600ba45bb84c99eb81e31d671dcbd7b3574e73d7a2dcf3212a724073a7e092
7
+ data.tar.gz: 62a5316272bf5579cfbfceab1371b5068ecf10ad7cfd37c2a1944c0edb7a6aa690dff19db1bc4fd3cfc70b8dc19733a1dfc2649d28fa9e5fd0f65f1c291b988c
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 VTS
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Playdough
2
+
3
+ API versioning that promotes convention over configuration.
4
+
5
+ The premise of this gem is that consumers of your API need versioning and different shapes of your resources. Without proper thought into versioning and shaping, your codebase can quickly resolve into a redundant and confusing state. This gem tries to solve that problem by allowing the API owner to use simple conventions -- Accept headers and ActiveModelSerializer namespacing -- to achieve controller reuse by controllers delegating resource versioning and shaping to the serializer level.
6
+
7
+
8
+ ## example
9
+
10
+
11
+
12
+ Let's say we have a resource of type `Foo` and `foos_controller.rb` that includes our gem and has a `show` action:
13
+
14
+ ``` Ruby
15
+ class FoosController < ActionController::Base
16
+ versioner Serializers::Foo
17
+
18
+ def show
19
+ render json: Foo.new(first_name: 'Shawn'), serializer: versioner_serializer
20
+ end
21
+
22
+ end
23
+ ```
24
+
25
+ A client on v1 would like a list of `foos` in short form:
26
+
27
+ `curl http://localhost:3000/foos -H 'Accept: application/javascript; version=1 shape=short'`
28
+
29
+ A client on v2 would like a list of `foos` in short form:
30
+
31
+ `curl http://localhost:3000/foos -H 'Accept: application/javascript; version=2 shape=short'`
32
+
33
+ A client on v1 would like a list of `foos` in full form:
34
+
35
+ `curl http://localhost:3000/foos -H 'Accept: application/javascript; version=1 shape=full'`
36
+
37
+ A client on v2 would like a list of `foos` in default form:
38
+
39
+ `curl http://localhost:3000/foos -H 'Accept: application/javascript; version=2`
40
+
41
+ Assuming we have the following ActiveModelSerializer directory structure, we wouldn't have to change the above controller at all to fulfill these requests:
42
+ ```
43
+ app
44
+ serializers
45
+ foo
46
+ v1
47
+ foo_short_serializer.rb
48
+ foo_full_serializer.rb
49
+ v2
50
+ foo_full_serializer.rb
51
+ foo_serializer.rb
52
+ ```
53
+
54
+ To specify that the versioner should be applied to or excluded from given controller actions, use the :only and :except parameters.
55
+ ```
56
+ versioner Serializers::Foo, :except => [:index, :show]
57
+ versioner Serializers::Foo, :only => :delete
58
+ ```
59
+
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.3
data/lib/playdough.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'playdough/version'
2
+
3
+ module Playdough
4
+
5
+ def versioner mod, **opts
6
+ normalize_options(opts)
7
+ self.prepend_before_filter opts do
8
+ if request.accept
9
+ version = request.accept[/version\s?=\s?(\d+)/, 1]
10
+ shape = request.accept[/shape\s?=\s?(\w+)/, 1]
11
+ mod_version = mod.const_get("V#{version}")
12
+ resource_name = mod.name.split('::').last
13
+ if shape
14
+ @versioner_serializer = mod_version.const_get("#{resource_name}#{shape.camelize}Serializer")
15
+ else
16
+ @versioner_serializer = mod_version.const_get("#{resource_name}Serializer")
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def normalize_options(opts)
25
+ opts.keep_if do |k, _v|
26
+ [:except, :only].include?(k)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ if defined? ActionController::Base
33
+ ActionController::Base.class_eval do
34
+ attr_accessor :versioner_serializer
35
+ extend Playdough
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Playdough
2
+ VERSION = '1.0.0'
3
+ end
data/playdough.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'playdough/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'playdough'
8
+ spec.version = Playdough::VERSION
9
+ spec.authors = ['Shawn O\'Mara', 'Dean Nasseri']
10
+ spec.email = ['shaw3257@gmail.com']
11
+
12
+ spec.summary = 'API versioning that promotes convention over configuration'
13
+
14
+ spec.description = 'The premise of this gem is that consumers of your API need versioning
15
+ and different shapes of your resources. Without proper thought into versioning
16
+ and shaping, your codebase can quickly resolve into a redundant and confusing state.
17
+ This gem tries to solve that problem by allowing the API owner to use simple
18
+ conventions -- Accept headers and ActiveModelSerializer namespacing -- to achieve
19
+ controller reuse by controllers delegating resource versioning and shaping
20
+ to the serializer level.'
21
+
22
+ spec.homepage = 'https://github.com/viewthespace/playdough'
23
+ spec.license = 'MIT'
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'actionpack'
29
+ spec.add_dependency 'activesupport'
30
+ spec.add_dependency 'active_model_serializers'
31
+
32
+ spec.add_development_dependency 'rspec-rails'
33
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: playdough
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Shawn O'Mara
8
+ - Dean Nasseri
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: active_model_serializers
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: |-
71
+ The premise of this gem is that consumers of your API need versioning
72
+ and different shapes of your resources. Without proper thought into versioning
73
+ and shaping, your codebase can quickly resolve into a redundant and confusing state.
74
+ This gem tries to solve that problem by allowing the API owner to use simple
75
+ conventions -- Accept headers and ActiveModelSerializer namespacing -- to achieve
76
+ controller reuse by controllers delegating resource versioning and shaping
77
+ to the serializer level.
78
+ email:
79
+ - shaw3257@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - Gemfile
86
+ - LICENSE.md
87
+ - README.md
88
+ - circle.yml
89
+ - lib/playdough.rb
90
+ - lib/playdough/version.rb
91
+ - playdough.gemspec
92
+ homepage: https://github.com/viewthespace/playdough
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: API versioning that promotes convention over configuration
116
+ test_files: []