pragma-rails 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +77 -2
- data/lib/pragma/rails/resource_controller.rb +2 -1
- data/lib/pragma/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2296947bedbdc7b81cac15053a92a8d59ecdb276
|
4
|
+
data.tar.gz: aeece846c1d8717ee920294da0e63f33834ffa93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3ae5a6057b1da3c878db167f310661ec9fcc919427c96036378a2fcec58b8a9a82d5f0e78eac38dd631235056d981b3d2b775b0ef2f0f22156ae7480bf7cce
|
7
|
+
data.tar.gz: 6348bd9002b966c8b604deffdd4aa6ed41f27d3f036105fc1bae4a9c70f1e58661f3503921c7acafa377c066b00a427506b3d77de2ff2a60282406474724291a
|
data/README.md
CHANGED
@@ -29,8 +29,83 @@ $ gem install pragma-rails
|
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
The gem provides two modules which you can include in your controllers to integrate with Pragma.
|
33
|
+
|
34
|
+
### Basic controllers
|
35
|
+
|
36
|
+
The first module is `Pragma::Rails::Controller`. It gives you a `#run` method which you can call in
|
37
|
+
your controller to run the provided Pragma operation:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
module API
|
41
|
+
module V1
|
42
|
+
class PostsController < ApplicationController
|
43
|
+
include Pragma::Rails::Controller
|
44
|
+
|
45
|
+
def create
|
46
|
+
run API::V1::Post::Operation::Create
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
In the example above, `PostsController#create` will run the `API::V1::Post::Operation::Create`
|
54
|
+
operation and respond with the status code, headers and resource output by the operation.
|
55
|
+
|
56
|
+
By default, the `#params` method will be used as the operation's parameters and `#current_user`, if
|
57
|
+
available, will be used as the operation's user. You can override these defaults by overriding the
|
58
|
+
`#operation_params` and `#operation_user` methods in your controller:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
module API
|
62
|
+
module V1
|
63
|
+
class PostsController < ApplicationController
|
64
|
+
include Pragma::Rails::Controller
|
65
|
+
|
66
|
+
def create
|
67
|
+
run API::V1::Post::Operation::Create
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def operation_params
|
73
|
+
params.merge(my_additional: 'param')
|
74
|
+
end
|
75
|
+
|
76
|
+
def operation_user
|
77
|
+
User.authenticate_from params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
### Resource controllers
|
85
|
+
|
86
|
+
Resource controllers abstract even more of the logic behind your controllers by inferring the
|
87
|
+
operations supported by a resource and automagically providing controller actions that run them.
|
88
|
+
|
89
|
+
Provided that the name of the controller and the name of the operation stay the same, the example
|
90
|
+
above could be rewritten as:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
module API
|
94
|
+
module V1
|
95
|
+
class PostsController < ApplicationController
|
96
|
+
include Pragma::Rails::ResourceController
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
You will still have to define a route to your `#create` action, of course, but you don't have to
|
103
|
+
write the action anymore! This works with any actions, not only the default CRUD actions defined
|
104
|
+
by Rails. So, for instance, if you have an `API::V1::Post::Operation::Publish` operation, a
|
105
|
+
`#publish` action will be accessible in the `API::V1::PostsController` controller.
|
106
|
+
|
107
|
+
Note that `Pragma::Rails::Controller` is included automatically when including
|
108
|
+
`Pragma::Rails::ResourceController`.
|
34
109
|
|
35
110
|
## Contributing
|
36
111
|
|
data/lib/pragma/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragma-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pragma
|