arcane 1.0.0.pre → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +88 -29
- data/lib/arcane/version.rb +1 -1
- data/lib/generators/arcane/install/USAGE +2 -0
- data/lib/generators/arcane/install/install_generator.rb +13 -0
- data/lib/generators/arcane/install/templates/application_refinery.rb +5 -0
- data/lib/generators/arcane/refinery/USAGE +8 -0
- data/lib/generators/arcane/refinery/refinery_generator.rb +13 -0
- data/lib/generators/arcane/refinery/templates/refinery.rb +11 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a862bb0fc096981789134db824772a2dab9355f8
|
4
|
+
data.tar.gz: e7e02551cda7792cc50bdfb18db771ec49d438a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a929d3ac3a2fdea27cc51fe56056fa5280bdc8c83a938a5ae6743202680f7ca269f3cb9b0c53eedf13ab0f727bdeff7d48488e0c4bae942eb2306c369d26b50d
|
7
|
+
data.tar.gz: 9a069440ffd9a1f4daf7450d33e7e704dd2c0d0171e5210d60093f94bc9a7cde7298b37a9ff1d34244548e8f2848ca077969a08ac598ce393d354e8b65291228
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,11 @@
|
|
8
8
|
refine your parameters. Look in `README.md` for
|
9
9
|
detailed information.
|
10
10
|
|
11
|
+
* **[feature]** Introducing most rails generators
|
12
|
+
to easily create generators for your class in the
|
13
|
+
command line. Read Look in `README.md` for
|
14
|
+
detailed information.
|
15
|
+
|
11
16
|
* **[bugfix]** You can now properly specify
|
12
17
|
`refinery_class` in your model.
|
13
18
|
|
data/README.md
CHANGED
@@ -11,6 +11,30 @@ in Rails 3 and 4.
|
|
11
11
|
Arcane magic is real and reliable, no cheap tricks.
|
12
12
|
Inspired by [Pundit](https://github.com/elabs/pundit)
|
13
13
|
|
14
|
+
#### Breaking Changes - Check [CHANGELOG.md](https://github.com/cloudsdaleapp/arcane/blob/master/CHANGELOG.md)
|
15
|
+
|
16
|
+
**This branch is showing a pre-release of Arcane, to install the this release, do this:**
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem "arcane", "~> 1.0.0"
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ bundle
|
30
|
+
```
|
31
|
+
|
32
|
+
To install arcane, execute:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
rails g arcane:install
|
36
|
+
```
|
37
|
+
|
14
38
|
## Usage
|
15
39
|
|
16
40
|
This is how easy it is to use:
|
@@ -48,6 +72,11 @@ end
|
|
48
72
|
Before you can use the parameter methods, you need a Refinery for the model you want to pass parameters to.
|
49
73
|
Simply create the directory `/app/refineries` in your Rails project. Create a Refinery your model, in this
|
50
74
|
case Article. `/app/refineries/article_refinery.rb`. Create a class in that file called `ArticleRefinery`.
|
75
|
+
You can also use the rails generator below:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
rails g arcane:refinery article
|
79
|
+
```
|
51
80
|
|
52
81
|
Methods defined in the refinery should reflect the controller method for clarity, but can be anything you
|
53
82
|
want it to be. These methods must return an array containing the same parameters you would otherwise send
|
@@ -100,8 +129,8 @@ class GameController < ApplicationController
|
|
100
129
|
end
|
101
130
|
|
102
131
|
def update
|
103
|
-
@
|
104
|
-
@
|
132
|
+
@game.find(params[:id])
|
133
|
+
@game.update_attributes params.for(@game).as(current_user).refine
|
105
134
|
end
|
106
135
|
|
107
136
|
def update_many
|
@@ -127,13 +156,29 @@ the arcane methods. This is good if you have some other way of getting data in t
|
|
127
156
|
the context of a controller.
|
128
157
|
|
129
158
|
```ruby
|
130
|
-
|
159
|
+
@user, @post = User.find(1), Post.find(24)
|
160
|
+
|
161
|
+
my_params = ActionController::Parameters.new({ post: { content: "Hello" } })
|
162
|
+
my_params.for(@post).as(@user).on(:create)
|
163
|
+
```
|
164
|
+
|
165
|
+
If you want to delegate some behaviour to your model, you can always create your own constructor.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
class Post < ActiveRecord::Base
|
169
|
+
def self.refined_create(params)
|
170
|
+
create(params.for(self).refine)
|
171
|
+
end
|
172
|
+
end
|
131
173
|
|
132
|
-
|
133
|
-
|
174
|
+
class PostsController
|
175
|
+
def create
|
176
|
+
@post = Post.refined_create(params)
|
177
|
+
end
|
178
|
+
end
|
134
179
|
```
|
135
180
|
|
136
|
-
### Automatic
|
181
|
+
### Automatic method detection.
|
137
182
|
If you have specified no refinery action in your chain to params, Arcane tries to find out for itself
|
138
183
|
what method to use. Arcane uses the action key in the rails parameters to determine the refinery method.
|
139
184
|
|
@@ -152,7 +197,22 @@ class CommentRefinery < Arcane::Refinery
|
|
152
197
|
end
|
153
198
|
```
|
154
199
|
|
155
|
-
###
|
200
|
+
### Easily manage conditional parameters
|
201
|
+
As an application grows larger, you usually want to filter what parameters based on some rules, usually
|
202
|
+
by checking the role of your current user or the state of the object you want to set the parameters on.
|
203
|
+
Arcane easily helps you do this.
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
class UserRefinery < Arcane::Refinery
|
207
|
+
def update
|
208
|
+
params = [ { abuse_reports: AbuseReportRefinery.new(AbuseReport.new,user).create } ]
|
209
|
+
params += [:suspended] if user.admin?
|
210
|
+
params += [:name,:email] if user.admin? or user == object
|
211
|
+
end
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
### Default parameters.
|
156
216
|
You are able to specify a `default` method in your refinery which will be prioritized if no the method
|
157
217
|
you call does not exist. If default is not specified it will be as the refinery returned an empty array.
|
158
218
|
|
@@ -164,7 +224,7 @@ class AmbiguityRefinery < Arcane::Refinery
|
|
164
224
|
end
|
165
225
|
```
|
166
226
|
|
167
|
-
### Custom root
|
227
|
+
### Custom root requirement.
|
168
228
|
You are able to disable or change the root requirement. Let's say you have a sessions endpoint where
|
169
229
|
you don't have your username and password parameters wrapped in a root. Now you can use the root class
|
170
230
|
method and set it to nil or false and it will automatically not require it.
|
@@ -189,7 +249,7 @@ class MeRefinery < UserRefinery
|
|
189
249
|
end
|
190
250
|
```
|
191
251
|
|
192
|
-
### Refinery
|
252
|
+
### Refinery inheritence.
|
193
253
|
Say you have quite similar needs between two different models, one of them might even have inherited
|
194
254
|
from the other. As arcane's refineries are just regular ruby models you can easily inherit from one
|
195
255
|
to another and it will just work.
|
@@ -216,6 +276,19 @@ class CubeRefinery
|
|
216
276
|
end
|
217
277
|
```
|
218
278
|
|
279
|
+
### Building HATEOAS API templates
|
280
|
+
As your refinery is a class that accepts an object and a user you can invoke it on it's own. This is
|
281
|
+
really good if you want your application to generate endpoints under different scenarios dynamically.
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
|
285
|
+
track_params = TrackRefinery.new(Track.new,User.new).create
|
286
|
+
# => [:title,:description,:duration]
|
287
|
+
|
288
|
+
track_url("{track}") + "?" + "{#{track_params.join(",")}}"
|
289
|
+
# => "http://www.music.com/tracks/{track}?{title,desc,duration}"
|
290
|
+
```
|
291
|
+
|
219
292
|
## Requirements
|
220
293
|
|
221
294
|
Currently this gem is only supported for Rails and with any of these ruby versions:
|
@@ -226,30 +299,16 @@ Currently this gem is only supported for Rails and with any of these ruby versio
|
|
226
299
|
* jruby-19
|
227
300
|
* rbx-19
|
228
301
|
|
229
|
-
## Installation
|
230
|
-
|
231
|
-
Add this line to your application's Gemfile:
|
232
|
-
|
233
|
-
```ruby
|
234
|
-
gem 'arcane'
|
235
|
-
```
|
236
|
-
|
237
|
-
And then execute:
|
238
|
-
|
239
|
-
```bash
|
240
|
-
$ bundle
|
241
|
-
```
|
242
|
-
|
243
302
|
## To-do
|
244
303
|
|
245
|
-
- [
|
246
|
-
- [
|
304
|
+
- [x] Explain Arcane::Refinery
|
305
|
+
- [x] Write rails generators
|
247
306
|
- [x] List features
|
248
307
|
- [x] Add Documentation
|
249
|
-
- [
|
250
|
-
- [
|
251
|
-
- [
|
252
|
-
- [
|
308
|
+
- [x] Add documentation for HATEOAS
|
309
|
+
- [x] Automatic method detection
|
310
|
+
- [-] RSpec helpers to test Arcane
|
311
|
+
- [-] Configuration
|
253
312
|
|
254
313
|
## Contributing
|
255
314
|
|
data/lib/arcane/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Arcane
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
6
|
+
|
7
|
+
def copy_application_refinery
|
8
|
+
template 'application_refinery.rb', 'app/refineries/application_refinery.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Arcane
|
2
|
+
module Generators
|
3
|
+
class RefineryGenerator < ::Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
6
|
+
|
7
|
+
def create_policy
|
8
|
+
template 'refinery.rb', File.join('app/refineries', class_path, "#{file_name}_refinery.rb")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arcane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Vieira
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -116,6 +116,12 @@ files:
|
|
116
116
|
- lib/arcane/parameters.rb
|
117
117
|
- lib/arcane/refinery.rb
|
118
118
|
- lib/arcane/version.rb
|
119
|
+
- lib/generators/arcane/install/USAGE
|
120
|
+
- lib/generators/arcane/install/install_generator.rb
|
121
|
+
- lib/generators/arcane/install/templates/application_refinery.rb
|
122
|
+
- lib/generators/arcane/refinery/USAGE
|
123
|
+
- lib/generators/arcane/refinery/refinery_generator.rb
|
124
|
+
- lib/generators/arcane/refinery/templates/refinery.rb
|
119
125
|
- spec/arcane/finder_spec.rb
|
120
126
|
- spec/arcane/parameters_spec.rb
|
121
127
|
- spec/arcane/refinery_spec.rb
|
@@ -136,9 +142,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
142
|
version: '0'
|
137
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
144
|
requirements:
|
139
|
-
- - '
|
145
|
+
- - '>='
|
140
146
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
147
|
+
version: '0'
|
142
148
|
requirements: []
|
143
149
|
rubyforge_project:
|
144
150
|
rubygems_version: 2.0.3
|