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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac8702d88c5f2db7d4777025f5c2b30c114742b1
4
- data.tar.gz: fe42df1b4394704eb074ff68f1aef27f5e3fe9fd
3
+ metadata.gz: 2296947bedbdc7b81cac15053a92a8d59ecdb276
4
+ data.tar.gz: aeece846c1d8717ee920294da0e63f33834ffa93
5
5
  SHA512:
6
- metadata.gz: 0ee9e39e7bc75d8160751a015978cabad1eb5e5bb99b70106655aab1d2e068f0a06496d85096625c72410275e67720235361bd5558edd79012c53b3ae6f83c9a
7
- data.tar.gz: 05d5f0a2f798f2001e31a854ddacc7f5b353d4b91179e51633ed7af48b8362ea9d0f4de44c93bd641f1d92ac7eac04995ed56c137d8cd022b7b75c922db1a536
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
- All documentation is in the [doc](https://github.com/pragmarb/pragma-rails/tree/master/doc)
33
- folder.
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
 
@@ -46,7 +46,8 @@ module Pragma
46
46
  def class_exists?(klass)
47
47
  Object.const_get(klass)
48
48
  true
49
- rescue NameError
49
+ rescue NameError => e
50
+ raise e unless e.message.include?("uninitialized constant #{klass}")
50
51
  false
51
52
  end
52
53
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Pragma
3
3
  module Rails
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
6
6
  end
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.2
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: 2016-12-30 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pragma