transit-rails 0.8.0.beta

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: d699027a2b416a7235950d3dba40abc58b31299a
4
+ data.tar.gz: d696f53e7e5ceb2c23d2391f6717cfbb527ce829
5
+ SHA512:
6
+ metadata.gz: 35ce5135b5ed7e1897224f87f8e7f71eb9471d347d3c3180859c583508c034c2fc82a5952a86a74c6b4490b30d09e064151e715ff1f1b7435e021be717a37bc9
7
+ data.tar.gz: d5e514282eab988728a9705ed32f01b0a74148a82b2b40cc9ca98da7385a314e069a44b1b10424f748f931ee00ec0239cd4d641659b644fd0973f21305d6f51e
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.1
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'rspec'
5
+
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joshua Davey
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,42 @@
1
+ # transit-rails
2
+
3
+ Use [transit format](https://github.com/cognitect/transit-format) in
4
+ your Rails application, with minimal friction.
5
+
6
+ Currently only works with C-based Ruby implementations.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'transit-rails'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install transit-rails
21
+
22
+ ## Usage
23
+
24
+ In your controller:
25
+
26
+ ```ruby
27
+ def index
28
+ @posts = Post.all
29
+ respond_to do |format|
30
+ format.html
31
+ format.transit { render transit: @posts }
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/jgdavey/transit-rails/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1 @@
1
+ require 'transit/rails'
@@ -0,0 +1,6 @@
1
+ require 'transit/rails/railtie'
2
+
3
+ module Transit
4
+ module Rails
5
+ end
6
+ end
@@ -0,0 +1,43 @@
1
+ module Transit
2
+ module Rails
3
+ class TimeWithZoneHandler
4
+ def initialize
5
+ @h = Transit::WriteHandlers::TimeHandler.new
6
+ end
7
+
8
+ def tag(o)
9
+ @h.tag(o)
10
+ end
11
+
12
+ def rep(o)
13
+ @h.rep(o)
14
+ end
15
+
16
+ def string_rep(o)
17
+ @h.string_rep(o.to_time)
18
+ end
19
+
20
+ def verbose_handler() VerboseTimeWithZoneHandler.new end
21
+ end
22
+
23
+ class VerboseTimeWithZoneHandler
24
+ def initialize
25
+ @h = Transit::WriteHandlers::VerboseTimeHandler.new
26
+ end
27
+
28
+ def tag(o)
29
+ @h.tag(o)
30
+ end
31
+
32
+ def rep(o)
33
+ @h.rep(o)
34
+ end
35
+
36
+ def string_rep(o)
37
+ @h.string_rep(o.to_time)
38
+ end
39
+ end
40
+
41
+ TRANSIT_HANDLERS = { ActiveSupport::TimeWithZone => TimeWithZoneHandler.new }
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/railtie'
2
+
3
+ module Transit
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ config.after_initialize do
7
+ require 'transit/rails/renderer'
8
+ require 'action_controller/metal/renderers'
9
+
10
+ Mime::Type.register "application/transit+json", :transit
11
+ Mime::Type.register_alias "application/transit+json", :transit_verbose
12
+ Mime::Type.register "application/transit+msgpack", :transit_msgpack
13
+
14
+ ActionController.add_renderer :transit do |obj, options|
15
+ Transit::Rails::Renderer.new(obj, options).render
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ require 'transit'
2
+ require 'transit/writer'
3
+ require 'transit/rails/handlers'
4
+
5
+ module Transit
6
+ module Rails
7
+ class Renderer
8
+ attr_reader :io
9
+
10
+ def initialize(obj, options={}, io=StringIO.new)
11
+ @object = obj
12
+ @format = options[:verbose] ? :json_verbose : :json
13
+ @handlers = TRANSIT_HANDLERS.merge(options[:handlers] || {})
14
+ @io = io
15
+ end
16
+
17
+ def write
18
+ serialized = serialize_for_transit(@object)
19
+ Transit::Writer.new(@format, @io, handlers: @handlers).write(serialized)
20
+ end
21
+
22
+ def render
23
+ return @rendered if defined?(@rendered)
24
+ write
25
+ @io.rewind
26
+ @rendered = @io.read
27
+ end
28
+
29
+ def to_s
30
+ render
31
+ end
32
+ alias to_str to_s
33
+
34
+ private
35
+ def serialize_for_transit(obj)
36
+ return obj if String === obj
37
+ if obj.respond_to?(:to_transit)
38
+ obj.to_transit
39
+ elsif obj.respond_to?(:serializable_hash)
40
+ obj.serializable_hash
41
+ elsif obj.respond_to?(:to_ary)
42
+ obj.to_ary.map {|o| serialize_for_transit(o)}
43
+ else
44
+ obj
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Transit
2
+ module Rails
3
+ VERSION = "0.8.0.beta"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'transit/rails'
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'transit/rails/version'
3
+
4
+ describe Transit::Rails do
5
+ it 'has a version number' do
6
+ expect(Transit::Rails::VERSION).not_to be nil
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transit/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "transit-rails"
8
+ spec.version = Transit::Rails::VERSION
9
+ spec.authors = ["Joshua Davey"]
10
+ spec.email = ["josh@joshuadavey.com"]
11
+ spec.summary = %q{Transit format helpers for Rails}
12
+ spec.description = %q{Transit format helpers for Rails. See Cognitect's transit-format for more info.}
13
+ spec.homepage = "https://github.com/jgdavey/transit-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 "transit-ruby", "~> 0.8", ">= 0.8.467"
22
+ spec.add_dependency "rails", "~> 4.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transit-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Davey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: transit-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.467
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.467
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.6'
61
+ description: Transit format helpers for Rails. See Cognitect's transit-format for
62
+ more info.
63
+ email:
64
+ - josh@joshuadavey.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - ".rspec"
71
+ - ".ruby-version"
72
+ - ".travis.yml"
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - lib/transit-rails.rb
78
+ - lib/transit/rails.rb
79
+ - lib/transit/rails/handlers.rb
80
+ - lib/transit/rails/railtie.rb
81
+ - lib/transit/rails/renderer.rb
82
+ - lib/transit/rails/version.rb
83
+ - spec/spec_helper.rb
84
+ - spec/transit/rails_spec.rb
85
+ - transit-rails.gemspec
86
+ homepage: https://github.com/jgdavey/transit-rails
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.1
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Transit format helpers for Rails
110
+ test_files:
111
+ - spec/spec_helper.rb
112
+ - spec/transit/rails_spec.rb