grape-rabl 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d621405f4d7c383ff47dea4a2db866618aaeff12
4
- data.tar.gz: 3ec7ec4c04e7bd20a390fa55acba8ac84171e6d2
3
+ metadata.gz: c4a8470660f6399543eefa3e7f27972b76b8f0cc
4
+ data.tar.gz: 3493ecbd9a3b87e659ae004a312a2d473f5cdd26
5
5
  SHA512:
6
- metadata.gz: 66582082999fe94194742f88ba1d4644dcce4dd83717403ea0202a45544c114f6a1e47c2358205c7d951509bee9771a43501ae8e7ad5684b39f1eadcd0584a42
7
- data.tar.gz: 399b670fd1ac71cac4b0b4fe40006274dbe58b878ffe95a031f7b172a354fe2013aea1d725c6348e7e589c96c8128b7b677d5d80a6592b169b2ea1e323576e86
6
+ metadata.gz: 6c22e0830abc4a6a8793109f432123b1897a35d4c94c0c863446497ef8cc769373f032f2c32272a73b062c6897960f5fc7b28172cbf2b1da62c8893fa7bbedd9
7
+ data.tar.gz: 9cfd783255db7b1288f30133052c78130d62d8101bff90c15f763ed88d99dd31ee55400551acc141930daa5b53e58fad93b4832a15c019f1a6628eb8af61e711
@@ -1,3 +1,7 @@
1
+ #### v0.4.0
2
+
3
+ * Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella)
4
+
1
5
  #### v0.3.1
2
6
 
3
7
  * The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck)
@@ -1,86 +1,88 @@
1
1
  require 'json'
2
2
 
3
3
  module Grape
4
- module Formatter
5
- module Rabl
4
+ module Rabl
5
+ class Formatter
6
6
  class << self
7
- attr_reader :env
8
- attr_reader :endpoint
7
+ def tilt_cache
8
+ @tilt_cache ||= ::Tilt::Cache.new
9
+ end
10
+ end
9
11
 
10
- def call(object, env)
11
- @env = env
12
- @endpoint = env['api.endpoint']
12
+ attr_reader :env, :endpoint, :object
13
13
 
14
- if rablable?
15
- rabl do |template|
16
- engine = tilt_template(template)
17
- output = engine.render endpoint, locals
18
- if layout_template
19
- layout_template.render(endpoint) { output }
20
- else
21
- output
22
- end
14
+ def initialize(object, env)
15
+ @env = env
16
+ @endpoint = env['api.endpoint']
17
+ @object = object
18
+ end
19
+
20
+ def render
21
+ if rablable?
22
+ rabl do |template|
23
+ engine = tilt_template(template)
24
+ output = engine.render endpoint, locals
25
+ if layout_template
26
+ layout_template.render(endpoint) { output }
27
+ else
28
+ output
23
29
  end
24
- else
25
- Grape::Formatter::Json.call object, env
26
30
  end
31
+ else
32
+ Grape::Formatter::Json.call object, env
27
33
  end
34
+ end
28
35
 
29
- private
30
-
31
- def view_path(template)
32
- if template.split('.')[-1] == 'rabl'
33
- File.join(env['api.tilt.root'], template)
34
- else
35
- File.join(env['api.tilt.root'], (template + '.rabl'))
36
- end
37
- end
36
+ private
38
37
 
39
- def rablable?
40
- !!rabl_template
38
+ def view_path(template)
39
+ if template.split('.')[-1] == 'rabl'
40
+ File.join(env['api.tilt.root'], template)
41
+ else
42
+ File.join(env['api.tilt.root'], (template + '.rabl'))
41
43
  end
44
+ end
42
45
 
43
- def rabl
44
- fail 'missing rabl template' unless rabl_template
45
- set_view_root unless env['api.tilt.root']
46
- yield rabl_template
47
- end
46
+ def rablable?
47
+ !!rabl_template
48
+ end
48
49
 
49
- def locals
50
- env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {}
51
- end
50
+ def rabl
51
+ fail 'missing rabl template' unless rabl_template
52
+ set_view_root unless env['api.tilt.root']
53
+ yield rabl_template
54
+ end
52
55
 
53
- def rabl_template
54
- env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl]
55
- end
56
+ def locals
57
+ env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {}
58
+ end
56
59
 
57
- def set_view_root
58
- fail "Use Rack::Config to set 'api.tilt.root' in config.ru"
59
- end
60
+ def rabl_template
61
+ env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl]
62
+ end
60
63
 
61
- def tilt_template(template)
62
- if Grape::Rabl.configuration.cache_template_loading
63
- tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) }
64
- else
65
- ::Tilt.new(view_path(template), tilt_options)
66
- end
67
- end
64
+ def set_view_root
65
+ fail "Use Rack::Config to set 'api.tilt.root' in config.ru"
66
+ end
68
67
 
69
- def tilt_cache
70
- @tilt_cache ||= ::Tilt::Cache.new
68
+ def tilt_template(template)
69
+ if Grape::Rabl.configuration.cache_template_loading
70
+ Grape::Rabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) }
71
+ else
72
+ ::Tilt.new(view_path(template), tilt_options)
71
73
  end
74
+ end
72
75
 
73
- def tilt_options
74
- { format: env['api.format'], view_path: env['api.tilt.root'] }
75
- end
76
+ def tilt_options
77
+ { format: env['api.format'], view_path: env['api.tilt.root'] }
78
+ end
76
79
 
77
- def layout_template
78
- layout_path = view_path(env['api.tilt.layout'] || 'layouts/application')
79
- if Grape::Rabl.configuration.cache_template_loading
80
- tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) }
81
- else
82
- ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path)
83
- end
80
+ def layout_template
81
+ layout_path = view_path(env['api.tilt.layout'] || 'layouts/application')
82
+ if Grape::Rabl.configuration.cache_template_loading
83
+ Grape::Rabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) }
84
+ else
85
+ ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path)
84
86
  end
85
87
  end
86
88
  end
@@ -1,10 +1,12 @@
1
- module GrapeRabl
2
- module Render
3
- def render(options = {})
4
- env['api.tilt.rabl'] = options[:rabl]
5
- env['api.tilt.rabl_locals'] = options[:locals]
1
+ module Grape
2
+ module Rabl
3
+ module Render
4
+ def render(options = {})
5
+ env['api.tilt.rabl'] = options[:rabl]
6
+ env['api.tilt.rabl_locals'] = options[:locals]
7
+ end
6
8
  end
7
9
  end
8
10
  end
9
11
 
10
- Grape::Endpoint.send(:include, GrapeRabl::Render)
12
+ Grape::Endpoint.send(:include, Grape::Rabl::Render)
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Rabl
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -1 +1,13 @@
1
1
  require 'grape-rabl'
2
+
3
+ module Grape
4
+ module Formatter
5
+ module Rabl
6
+ class << self
7
+ def call(object, env)
8
+ Grape::Rabl::Formatter.new(object, env).render
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Niełacny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: tilt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: i18n
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Use rabl in grape
@@ -73,11 +73,11 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .coveralls.yml
77
- - .gitignore
78
- - .rspec
79
- - .rubocop.yml
80
- - .travis.yml
76
+ - ".coveralls.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
81
  - CHANGELOG.md
82
82
  - Gemfile
83
83
  - LICENSE
@@ -116,17 +116,17 @@ require_paths:
116
116
  - lib
117
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: 1.9.3
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.2.2
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Use rabl in grape