tire-am_serializers 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19507b2069ef8fe4d96ef988a4ff56a45b99024d
4
+ data.tar.gz: b4064dbe20e841d18816b6881c2e2723780e47f6
5
+ SHA512:
6
+ metadata.gz: b7fb13113679b491869b5a83dbacbae2cce894143ecff0f353ed8a35eb25f16b17f5f95fd9e6e221e8c7618e9b62367892d29a7f87ceb812fa87ed6bc0cb6c0a
7
+ data.tar.gz: abf971f17cd8cc63dae8ab24c2770c451f5d855a5046c87f5e5aadc57d299a539c098dad05947286eed1f79fc30397a283df1ea98af2208cc4b7991a7c5b679b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tire-am_serializers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sergey Efremov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Active Model Serializers + Tire
2
+
3
+ The easy way to add [Active Model Serializers](https://github.com/rails-api/active_model_serializers) to your [Tire](https://github.com/karmi/tire/) results.
4
+
5
+ ## Installation
6
+
7
+ Drop this line to your application's Gemfile:
8
+ ```ruby
9
+ gem 'tire-am_serializers'
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Do nothing, it should works as expected:
15
+ ```ruby
16
+ render json: User.search(...).results
17
+ ```
18
+
19
+ If you want to get old behaviour from Tire:
20
+ ```ruby
21
+ render json: Vacancy.search("*").map(&:tire_as_json)
22
+ ```
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ module Tire
2
+ module ActiveModel
3
+ module Serializer
4
+
5
+ def serializer_to_json(options = {})
6
+ serialization :to_json, options
7
+ end
8
+
9
+ def serializer_as_json(options = {})
10
+ serialization :as_json, options
11
+ end
12
+
13
+ private
14
+
15
+ def serializer_defined?
16
+ !active_model_serializer.nil?
17
+ end
18
+
19
+ def serialization(method, options)
20
+ if serializer_defined?
21
+ active_model_serializer.new(self).send(method, options)
22
+ else
23
+ send("tire_#{method}", options)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require "tire/version"
2
+ require "tire/active_model/serializer"
3
+
4
+ Tire::Results::Collection.send(:include, ActiveModel::ArraySerializerSupport)
5
+
6
+ Tire::Results::Item.send(:include, ActiveModel::SerializerSupport)
7
+ Tire::Results::Item.send(:include, Tire::ActiveModel::Serializer)
8
+
9
+ Tire::Results::Item.send(:alias_method, :tire_as_json, :as_json)
10
+
11
+ Tire::Results::Item.send :define_method, :to_json do |options|
12
+ tire_as_json.to_json(options)
13
+ end
14
+
15
+ Tire::Results::Item.send(:alias_method, :tire_to_json, :to_json)
16
+
17
+ Tire::Results::Item.send(:alias_method, :to_json, :serializer_to_json)
18
+ Tire::Results::Item.send(:alias_method, :as_json, :serializer_as_json)
@@ -0,0 +1,5 @@
1
+ module Tire
2
+ module AmSerializers
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tire/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tire-am_serializers"
8
+ spec.version = Tire::AmSerializers::VERSION
9
+ spec.authors = ["Sergey Efremov", "Ilya Zayats"]
10
+ spec.email = ["efremov.sergey@gmail.com", "somebody32@gmail.com"]
11
+ spec.description = %q{The easy way to add active model serializers to your tire results}
12
+ spec.summary = %q{The easy way to add active model serializers to your tire results}
13
+ spec.homepage = "https://github.com/ResumUP/tire_am_serializers/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "tire"
22
+ spec.add_dependency "active_model_serializers"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tire-am_serializers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Efremov
8
+ - Ilya Zayats
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tire
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: active_model_serializers
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: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
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: The easy way to add active model serializers to your tire results
71
+ email:
72
+ - efremov.sergey@gmail.com
73
+ - somebody32@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/tire/active_model/serializer.rb
84
+ - lib/tire/am_serializers.rb
85
+ - lib/tire/version.rb
86
+ - tire-am_serializers.gemspec
87
+ homepage: https://github.com/ResumUP/tire_am_serializers/
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: The easy way to add active model serializers to your tire results
111
+ test_files: []