Skip to content

Commit 9387170

Browse files
authored
Merge pull request #9 from aktsk/update-dependencies
CI: fix matrix spec / fix broken bin/benchmark.sh
2 parents ff48af6 + 213a821 commit 9387170

File tree

14 files changed

+65
-74
lines changed

14 files changed

+65
-74
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,18 @@ jobs:
66
build:
77
strategy:
88
matrix:
9-
ruby_version: ['3.0', '2.7', '2.6']
10-
11-
gemfile:
12-
- gemfiles/rails_61.gemfile
13-
- gemfiles/rails_60.gemfile
14-
15-
include:
16-
- ruby_version: ruby-head
17-
gemfile: gemfiles/rails_edge.gemfile
18-
allow_failures: 'true'
19-
- ruby_version: '3.0'
20-
gemfile: gemfiles/rails_edge.gemfile
21-
allow_failures: 'true'
22-
23-
- ruby_version: '2.7'
24-
gemfile: gemfiles/rails_edge.gemfile
25-
allow_failures: 'true'
26-
27-
- ruby_version: '2.6'
28-
gemfile: gemfiles/rails_52.gemfile
29-
- ruby_version: '2.6'
30-
gemfile: gemfiles/rails_51.gemfile
31-
- ruby_version: '2.6'
32-
gemfile: gemfiles/rails_50.gemfile
33-
- ruby_version: '2.6'
34-
gemfile: gemfiles/rails_42.gemfile
35-
bundler_version: '1'
36-
37-
- ruby_version: '2.5'
38-
gemfile: gemfiles/rails_52.gemfile
39-
- ruby_version: '2.5'
40-
gemfile: gemfiles/rails_42.gemfile
41-
bundler_version: '1'
9+
ruby: ['3.2', '3.3', '3.4']
10+
rails: ["7.1", "7.2", "8.0"]
4211

4312
runs-on: ubuntu-latest
4413

4514
env:
46-
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
15+
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
4716

4817
steps:
49-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
5019
- uses: ruby/setup-ruby@v1
5120
with:
52-
ruby-version: ${{ matrix.ruby_version }}
53-
bundler: ${{ matrix.bundler_version }}
21+
ruby-version: ${{ matrix.ruby }}
5422
bundler-cache: true
55-
continue-on-error: ${{ matrix.allow_failures == 'true' }}
5623
- run: bundle exec rake
57-
continue-on-error: ${{ matrix.allow_failures == 'true' }}

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# SimpleJson
2+
23
A simple & fast solution for Rails JSON rendering.
34

45
## Get started
6+
57
In Gemfile
8+
69
```ruby
710
gem 'simple_json'
811
```
912

1013
In controller
14+
1115
```ruby
1216
class ApplicationController < ActionController::Base
1317
include SimpleJson::SimpleJsonRenderable
@@ -44,18 +48,23 @@ That's all!
4448
Have fun!
4549

4650
## Special thanks
51+
4752
This project is built on work of [jb](https://github.com/amatsuda/jb).
4853

4954
## Template Syntax
55+
5056
SimpleJson templates are simply lambda objects that return data(Hashes or Arrays) for json.
57+
5158
```ruby
5259
-> {
5360
{
5461
key: @value,
5562
}
5663
}
5764
```
65+
5866
When no parameters specified, `-> {` and `}` can be omitted.
67+
5968
```ruby
6069
{
6170
key: @value,
@@ -83,62 +92,75 @@ Use `partial!` method to call another template in template. Note that path is al
8392
```
8493

8594
Cache helpers of simple_json is similar to jbuilder.
95+
8696
```ruby
8797
cache! key, options do
8898
data_to_cache
8999
end
90100
```
91101

92102
Cache helpers uses `Rails.cache` to cache, so array keys, expirations are available. Make sure `perform_caching` is enabled.
103+
93104
```ruby
94105
cache! [key1, key2], expires_in: 10.minutes do
95106
data_to_cache
96107
end
97108
```
98109

99110
`cache_if!` is also available
111+
100112
```ruby
101113
cache_if! boolean, key1, options do
102114
data_to_cache
103115
end
104116
```
105117

106118
You can set key_prefix for caching like this
119+
107120
```ruby
108121
SimpleJson.cache_key_prefix = "MY_PREFIX"
109122
```
110123

111124
## Configurations
125+
112126
Load all templates on boot. (For production)
113127
Templates loaded will not load again, so it is not recommended in development environment.
128+
114129
```ruby
115130
# config/environments/production.rb
116131
SimpleJson.enable_template_cache
117132
```
118133

119134
The default path for templates is `app/views`, you can change it by
135+
120136
```ruby
121137
SimpleJson.template_paths.append("app/simple_jsons")
122138
# or
123139
SimpleJson.template_paths=["app/views", "app/simple_jsons"]
124140
```
141+
125142
Note that these paths should not be eager loaded cause using .rb as suffix.
126143

127144
SimpleJson uses Oj as json serializer by default. Modules with `#encode` and `#decode` method can be used here.
145+
128146
```ruby
129147
SimpleJson.json_module = ActiveSupport::JSON
130148
```
131149

132150
## The Generator
151+
133152
SimpleJson extends the default Rails scaffold generator and adds some simple_json templates. If you don't need them, please configure like so.
153+
134154
```rb
135155
Rails.application.config.generators.simple_json false
136156
```
137157

138158
## Benchmarks
159+
139160
Here're the results of a benchmark (which you can find [here](https://github.com/aktsk/simple_json/blob/master/test/dummy_app/app/controllers/benchmarks_controller.rb) in this repo) rendering a collection to JSON.
140161

141162
### RAILS_ENV=development
163+
142164
```
143165
% ./bin/benchmark.sh
144166
@@ -189,7 +211,9 @@ Comparison:
189211
jb: 106.1 i/s - 2.56x (± 0.00) slower
190212
jbuilder: 13.0 i/s - 20.88x (± 0.00) slower
191213
```
214+
192215
### RAILS_ENV=production
216+
193217
```
194218
% RAILS_ENV=production ./bin/benchmark.sh
195219
@@ -242,13 +266,16 @@ Comparison:
242266
```
243267

244268
## Migrating from Jbuilder
269+
245270
When migrating from Jbuilder, you can include `Migratable` in controller for migrating mode.
271+
246272
```
247273
include SimpleJson::SimpleJsonRenderable
248274
include SimpleJson::Migratable
249275
```
250276

251277
In migrating mode
278+
252279
- Comparision will be performed for simple_json and ActionView render(Jbuilder) result.
253280
- simple_json partials not found will use Jbuilder partial as an alternative.
254281

gemfiles/rails_42.gemfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

gemfiles/rails_50.gemfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

gemfiles/rails_52.gemfile

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ source 'https://rubygems.org'
55
gemspec path: '../'
66

77
gem 'jbuilder'
8-
gem 'rails', '~> 6.0.0'
8+
gem 'rails', '~> 7.1.0'
99
gem 'selenium-webdriver'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ source 'https://rubygems.org'
55
gemspec path: '../'
66

77
gem 'jbuilder'
8-
gem 'rails', '~> 6.1.0'
8+
gem 'rails', '~> 7.2.0'
99
gem 'selenium-webdriver'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ source 'https://rubygems.org'
55
gemspec path: '../'
66

77
gem 'jbuilder'
8-
gem 'rails', '~> 5.1.0'
8+
gem 'rails', '~> 8.0.0'
9+
gem 'selenium-webdriver'

simple_json.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ Gem::Specification.new do |spec|
2424

2525
spec.add_development_dependency 'action_args'
2626
spec.add_development_dependency 'bundler'
27-
spec.add_development_dependency 'byebug'
28-
spec.add_development_dependency 'rails'
27+
spec.add_development_dependency 'debug'
28+
spec.add_development_dependency 'rails', '~> 8.0'
2929
spec.add_development_dependency 'rake'
3030
spec.add_development_dependency 'selenium-webdriver'
3131
spec.add_development_dependency 'test-unit-rails'
32+
spec.add_development_dependency 'mutex_m'
3233

33-
spec.required_ruby_version = '>= 2.5.0'
34+
spec.required_ruby_version = '>= 3.2.0'
3435
end

test/dummy_app/app/controllers/benchmarks_controller.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ def index(n = '100')
88

99
jb = render_to_string 'index_jb'
1010
jbuilder = render_to_string 'index_jbuilder'
11-
simple_json = render_to_string 'index_simple_json'
11+
12+
SimpleJson.json_module = SimpleJson::Json::Oj
13+
simple_json = render_to_string 'index'
14+
15+
SimpleJson.json_module = ActiveSupport::JSON
16+
simple_json_active_support_json = render_to_string 'index'
17+
1218
raise 'jb != jbuilder' unless jb == jbuilder
1319
raise 'simple_json != jbuilder' unless simple_json == jbuilder
20+
raise 'simple_json_active_support_json != jbuilder' unless simple_json_active_support_json == jbuilder
1421

1522
result = Benchmark.ips do |x|
1623
x.report('jb') { render_to_string 'index_jb' }
1724
x.report('jbuilder') { render_to_string 'index_jbuilder' }
18-
x.report('simple_json') { render_to_string 'index_simple_json' }
25+
x.report('simple_json(oj)') {
26+
SimpleJson.json_module = SimpleJson::Json::Oj
27+
render_to_string 'index'
28+
}
29+
x.report('simple_json(AS::json)') {
30+
SimpleJson.json_module = ActiveSupport::JSON
31+
render_to_string 'index'
32+
}
1933
x.compare!
2034
end
2135
render plain: result.data.to_s

0 commit comments

Comments
 (0)