roar 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.10.2
2
+
3
+ * You can now pass values from outside to the render method (e.g. `#to_json`), they will be available as block parameters inside `#link`.
4
+
1
5
  ## 0.10.1
2
6
 
3
7
  * Adding the Coercion feature.
data/Gemfile CHANGED
@@ -5,8 +5,11 @@ gemspec
5
5
 
6
6
  #gem "representable", :path => "../representable"
7
7
 
8
- gem 'faraday'
9
8
 
10
9
  group :test do
10
+ gem 'faraday'
11
11
  gem 'turn'
12
+ gem 'virtus'
13
+ gem "sinatra", "~> 1.3.2"
14
+ gem "sham_rack", "~> 1.3.0"
12
15
  end
@@ -19,13 +19,22 @@ module Roar
19
19
  # link :rel => :next, :title => "Next, please!" do
20
20
  # "http://orders/#{id}"
21
21
  # end
22
+ #
23
+ # Sometimes you need values from outside when the representation links are rendered. Just pass them
24
+ # to the render method, they will be available as block parameters.
25
+ #
26
+ # link :self do |opts|
27
+ # "http://orders/#{opts[:id]}"
28
+ # end
29
+ #
30
+ # model.to_json(:id => 1)
22
31
  module Hypermedia
23
32
  def self.included(base)
24
33
  base.extend ClassMethods
25
34
  end
26
35
 
27
36
  def before_serialize(options={})
28
- prepare_links! unless options[:links] == false # DISCUSS: doesn't work when links are already setup (e.g. from #deserialize).
37
+ prepare_links!(options) unless options[:links] == false # DISCUSS: doesn't work when links are already setup (e.g. from #deserialize).
29
38
  super # Representer::Base
30
39
  end
31
40
 
@@ -39,19 +48,19 @@ module Roar
39
48
 
40
49
  protected
41
50
  # Setup hypermedia links by invoking their blocks. Usually called by #serialize.
42
- def prepare_links!
51
+ def prepare_links!(*args)
43
52
  links_def = find_links_definition or return
44
53
 
45
54
  links_def.rel2block.each do |config| # config is [{..}, block]
46
55
  options = config.first
47
- options[:href] = run_link_block(config.last) or next
56
+ options[:href] = run_link_block(config.last, *args) or next
48
57
 
49
58
  links.update_link(Feature::Hypermedia::Hyperlink.new(options))
50
59
  end
51
60
  end
52
61
 
53
- def run_link_block(block)
54
- instance_exec(&block)
62
+ def run_link_block(block, *args)
63
+ instance_exec(*args, &block)
55
64
  end
56
65
 
57
66
  def find_links_definition
data/lib/roar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.10.1"
2
+ VERSION = "0.10.2"
3
3
  end
data/roar.gemspec CHANGED
@@ -24,8 +24,4 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "test_xml"
26
26
  s.add_development_dependency "minitest", ">= 2.8.1"
27
- s.add_development_dependency "sinatra", "~> 1.3.2"
28
- s.add_development_dependency "sham_rack", "~> 1.3.0"
29
- s.add_development_dependency "turn"
30
- s.add_development_dependency "virtus"
31
27
  end
@@ -31,6 +31,16 @@ class HypermediaTest
31
31
 
32
32
  assert_equal "{\"links\":[{\"rel\":\"self\",\"href\":\"http://self\",\"title\":\"Hey, @myabc\"}]}", Object.new.extend(@mod).to_json
33
33
  end
34
+
35
+ it "receives options from to_*" do
36
+ @mod.class_eval do
37
+ link :self do |opts|
38
+ "http://self/#{opts[:id]}"
39
+ end
40
+ end
41
+
42
+ assert_equal "{\"links\":[{\"rel\":\"self\",\"href\":\"http://self/1\"}]}", Object.new.extend(@mod).to_json(:id => 1)
43
+ end
34
44
  end
35
45
 
36
46
 
metadata CHANGED
@@ -1,112 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: roar
3
- version: !ruby/object:Gem::Version
4
- version: 0.10.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 51
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 10
9
+ - 2
10
+ version: 0.10.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Nick Sutterer
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-05-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: representable
16
- requirement: &75807040 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 29
29
+ segments:
30
+ - 1
31
+ - 1
32
+ - 7
21
33
  version: 1.1.7
22
34
  type: :runtime
23
- prerelease: false
24
- version_requirements: *75807040
25
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
26
37
  name: rake
27
- requirement: &75805090 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *75805090
36
- - !ruby/object:Gem::Dependency
37
- name: test_xml
38
- requirement: &75802000 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *75802000
47
- - !ruby/object:Gem::Dependency
48
- name: minitest
49
- requirement: &75801380 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: 2.8.1
55
- type: :development
56
- prerelease: false
57
- version_requirements: *75801380
58
- - !ruby/object:Gem::Dependency
59
- name: sinatra
60
- requirement: &75799950 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ~>
64
- - !ruby/object:Gem::Version
65
- version: 1.3.2
66
- type: :development
67
38
  prerelease: false
68
- version_requirements: *75799950
69
- - !ruby/object:Gem::Dependency
70
- name: sham_rack
71
- requirement: &75799310 !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
72
40
  none: false
73
- requirements:
74
- - - ~>
75
- - !ruby/object:Gem::Version
76
- version: 1.3.0
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
77
48
  type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: test_xml
78
52
  prerelease: false
79
- version_requirements: *75799310
80
- - !ruby/object:Gem::Dependency
81
- name: turn
82
- requirement: &75798790 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
83
54
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
88
62
  type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: minitest
89
66
  prerelease: false
90
- version_requirements: *75798790
91
- - !ruby/object:Gem::Dependency
92
- name: virtus
93
- requirement: &75797000 !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
94
68
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 45
73
+ segments:
74
+ - 2
75
+ - 8
76
+ - 1
77
+ version: 2.8.1
99
78
  type: :development
100
- prerelease: false
101
- version_requirements: *75797000
102
- description: Streamlines the development of RESTful, resource-oriented architectures
103
- in Ruby.
104
- email:
79
+ version_requirements: *id004
80
+ description: Streamlines the development of RESTful, resource-oriented architectures in Ruby.
81
+ email:
105
82
  - apotonick@gmail.com
106
83
  executables: []
84
+
107
85
  extensions: []
86
+
108
87
  extra_rdoc_files: []
109
- files:
88
+
89
+ files:
110
90
  - .gitignore
111
91
  - .travis.yml
112
92
  - CHANGES.markdown
@@ -182,26 +162,36 @@ files:
182
162
  - test/xml_representer_test.rb
183
163
  homepage: http://rubygems.org/gems/roar
184
164
  licenses: []
165
+
185
166
  post_install_message:
186
167
  rdoc_options: []
187
- require_paths:
168
+
169
+ require_paths:
188
170
  - lib
189
- required_ruby_version: !ruby/object:Gem::Requirement
171
+ required_ruby_version: !ruby/object:Gem::Requirement
190
172
  none: false
191
- requirements:
192
- - - ! '>='
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
179
+ version: "0"
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
181
  none: false
197
- requirements:
198
- - - ! '>='
199
- - !ruby/object:Gem::Version
200
- version: '0'
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
201
189
  requirements: []
190
+
202
191
  rubyforge_project: roar
203
- rubygems_version: 1.8.10
192
+ rubygems_version: 1.8.15
204
193
  signing_key:
205
194
  specification_version: 3
206
195
  summary: Resource-oriented architectures in Ruby.
207
196
  test_files: []
197
+