You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,9 @@
7
7
#### Fixes
8
8
9
9
* Your contribution here.
10
+
*[#1825](https://github.com/ruby-grape/grape/pull/1825): `to_s` on a mounted class now responses with the API name - [@myxoh](https://github.com/myxoh).
Copy file name to clipboardExpand all lines: UPGRADING.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,27 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
### Upgrading to >= 1.2.1
5
+
6
+
#### Obtaining the name of a mounted class
7
+
8
+
In order to make obtaining the name of a mounted class simpler, we've delegated `.to_s` to `base.name`
9
+
10
+
**Deprecated in 1.2.0**
11
+
```ruby
12
+
payload[:endpoint].options[:for].name
13
+
```
14
+
**New**
15
+
```ruby
16
+
payload[:endpoint].options[:for].to_s
17
+
```
18
+
4
19
### Upgrading to >= 1.2.0
5
20
6
21
#### Changes in the Grape::API class
7
22
23
+
##### Patching the class
24
+
8
25
In an effort to make APIs re-mountable, The class `Grape::API` no longer refers to an API instance,
9
26
rather, what used to be `Grape::API` is now `Grape::API::Instance` and `Grape::API` was replaced
10
27
with a class that can contain several instances of `Grape::API`.
@@ -29,6 +46,23 @@ class Grape::API::Instance
29
46
end
30
47
```
31
48
49
+
##### `name` (and other caveats) of the mounted API
50
+
51
+
After the patch, the mounted API is no longer a Named class inheriting from `Grape::API`, it is an anonymous class
52
+
which inherit from `Grape::API::Instance`.
53
+
What this means in practice, is:
54
+
- Generally: you can access the named class from the instance calling the getter `base`.
55
+
- In particular: If you need the `name`, you can use `base`.`name`
56
+
57
+
**Deprecated**
58
+
```ruby
59
+
payload[:endpoint].options[:for].name
60
+
```
61
+
**New**
62
+
```ruby
63
+
payload[:endpoint].options[:for].base.name
64
+
```
65
+
32
66
#### Changes in rescue_from returned object
33
67
34
68
Grape will now check the object returned from `rescue_from` and ensure that it is a `Rack::Response`. That makes sure response is valid and avoids exposing service information. Change any code that invoked `Rack::Response.new(...).finish` in a custom `rescue_from` block to `Rack::Response.new(...)` to comply with the validation.
0 commit comments