cant 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,8 +4,6 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem 'rspec'
8
- gem 'wrong'
9
7
  gem 'guard-rspec'
10
8
  gem 'growl'
11
9
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cant (0.1.0)
4
+ cant (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -65,5 +65,5 @@ DEPENDENCIES
65
65
  cant!
66
66
  growl
67
67
  guard-rspec
68
- rspec
69
- wrong
68
+ rspec (~> 2)
69
+ wrong (>= 0.4)
File without changes
@@ -1,21 +1,15 @@
1
1
  Intent
2
2
  ======
3
-
4
3
  Lightweight authorization library, that let you choose where and how you write your rules
5
4
 
6
- Cant is agnostic : you can use it in any existing or future framework, provided names don't clash
5
+ Cant is simple : you can use it in any existing or future framework (provided names don't clash)
7
6
 
8
- Cant is small and even simple : it is 120 lines of code, has no dependencies but for testing
7
+ Cant is small : around 120 lines of code, has no dependencies but for testing
9
8
 
10
9
  Cant can be configured at class level, and support basic configuration inheritance
11
10
 
12
-
13
11
  What does it look like ?
14
12
  ========================
15
-
16
- Examples
17
- --------
18
-
19
13
  * in an existing model
20
14
 
21
15
  class User
@@ -64,17 +58,15 @@ Examples
64
58
  * in a rack middleware ... I have not experimented yet ...
65
59
 
66
60
  breaking authorization into small independent pieces is valuable, and you do not need a library for that, though using Cant::Editable and Cant::Questionable mixins can help you do that
67
-
68
-
61
+
69
62
 
70
63
  Concepts
71
64
  ========
72
-
73
65
  Cant is simply put a reduce (or [fold](http://learnyousomeerlang.com/higher-order-functions)) on a list of Rules.
74
66
 
75
67
  * __Rule__
76
68
 
77
- a tuple of functions {__predicate__, __die__}.
69
+ a tuple of functions __predicate__, __die__
78
70
 
79
71
  * __rules__
80
72
 
@@ -104,7 +96,6 @@ Cant is simply put a reduce (or [fold](http://learnyousomeerlang.com/higher-orde
104
96
 
105
97
  How do I define rules ?
106
98
  =======================
107
-
108
99
  First, choose where you want to define your list, and what information a Rule will need
109
100
 
110
101
  The point of cant is to define a lists of similar rules together, so that they will require similar informations
@@ -118,16 +109,14 @@ Then there is one list of rules for any instance of this class, and instance eva
118
109
 
119
110
  Note that a list of rules can be shared by many inquirers, either explicitly or by using class instance variable inheritance feature
120
111
 
121
- Default Values
122
- --------------
123
-
112
+ Default Values for module configuration
113
+ ---------------------------------------
124
114
  __Cant__ module has "reasonable" default values for __fold__, __die__, __rules__
125
115
 
126
116
  The Cant::Editable module gather methods to configure a Cant engine (fold, die, rules), and defaults to Cant module values
127
117
 
128
118
  Inheritance
129
119
  -----------
130
-
131
120
  Cant support _basic_ inheritance functionality for configuration with the Cant::Embeddable module ...
132
121
  Ouch what that means ?
133
122
 
@@ -139,7 +128,6 @@ Well, have a look at read documentation and source code embeddable.rb if you are
139
128
 
140
129
  What is the arity of a __predicate__ function ?
141
130
  -----------------------------------------------
142
-
143
131
  You are free to pick one that suit your needs
144
132
 
145
133
  There are a couple of things to drive your choice :
@@ -162,7 +150,6 @@ So pick your own semantic, or grow an existing one
162
150
 
163
151
  How do I verify authorization ?
164
152
  ===============================
165
-
166
153
  Cant very meaning is : you can unless you cant, and you define what you cant
167
154
 
168
155
  Defining _not_ or _negative_ ability require some thinking, and I believe we can do it :)
@@ -171,34 +158,39 @@ Use __cant?__ method to check
171
158
 
172
159
  Use __die\_if\_cant!__ method to check and run __die__ code
173
160
 
174
- When you check, provide the list of parameters you specified in your list of rules
161
+ When you check, provide the list of parameters you specified in the list of rules you want to verify
175
162
 
176
163
  Inspired from
177
164
  =============
178
-
179
165
  * [cancan](https://github.com/ryanb/cancan), as I started with it and saw that it did not functioned in presence of mongoid as of < 1.5 ... so I planned to do something no dependent of a model implementation
180
166
 
181
- * [learn you some erlang?](http://learnyousomeerlang.com/higher-order-functions#maps-filters-folds), for the fold illustrations
167
+ * [learn you some erlang?](http://learnyousomeerlang.com/higher-order-functions#maps-filters-folds), for the fold illustrations had great impact
182
168
 
183
169
  * [Howard](http://rubyquiz.com/quiz67.html) and [Nunemaker](http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/) for inheritable class instance variables
184
170
 
185
-
186
- Does it work ?
187
- ==============
188
-
171
+ Does it work on my interpreter?
172
+ ===============================
173
+ rspec
174
+ -----
189
175
  specs are green on mri : [1.9.2-p0, 1.8.7-p302]
190
176
 
191
- C0 coverage is acceptable under ruby-1.9.2-p0 (100% is acceptable for this kind of code)
192
-
193
- There is few lines of code as concept is simple : fold a list of functions...
177
+ There is few lines of code and concept is simple : fold a list of functions...
194
178
  Though, we can make it better and lesser, cant we ?
195
179
 
180
+ 1.9.2 coverage
181
+ --------------
182
+ can be ran with
183
+
184
+ COVERAGE=true rspec /spec
185
+
186
+ Licence
187
+ =======
188
+ Is MIT, available in source code
196
189
 
197
190
  Help|Contribute
198
191
  ===============
199
-
200
192
  Fill an item in tracker
201
193
 
202
194
  Add a page on wiki
203
195
 
204
- Add a spec, open a pull request on topic branch, commit granted on first accepted patch|pull
196
+ Add a spec, open a pull request on topic branch, commit granted on first accepted patch
@@ -83,19 +83,29 @@ module Cant
83
83
 
84
84
  # questionable interface
85
85
  module Questionable
86
- attr_writer :cantfiguration
87
- def cantfiguration
88
- @cantfiguration ||= Object.new.extend(Editable)
89
- end
90
- # return strategy fold for rules with context (a rule or nil)
86
+ # Public : verify whether you cant
87
+ #
88
+ # *args - list of params to pass to rules
89
+ #
90
+ # Returns : a rule that cant, according rules folding, or nil
91
91
  def cant?(*args)
92
92
  cantfiguration.fold.call(cantfiguration.rules, self, *args)
93
93
  end
94
- # return evaled die function of strategy fold
94
+ # Public : run die code if you cant
95
+ #
96
+ # *args - list of params to pass to rules and die function
97
+ #
98
+ # Returns : die result or nil if it can
95
99
  def die_if_cant!(*args)
96
100
  rule = cant?(*args)
97
101
  rule.die!(*args) if rule
98
102
  end
103
+
104
+ attr_writer :cantfiguration
105
+ protected
106
+ def cantfiguration
107
+ @cantfiguration ||= Object.new.extend(Editable)
108
+ end
99
109
  end
100
110
 
101
111
  # standalone engine
@@ -112,8 +122,9 @@ module Cant
112
122
  # - die(*args), that cant raise if convenient
113
123
  #
114
124
  # this class could have been:
115
- # -spared
116
- # -an Array, with an optional syntactic sugar
125
+ # - spared
126
+ # - an Array, with an optional syntactic sugar
127
+ # - a property list in erlang
117
128
  class Rule
118
129
  # a new rule with a predicate and response function
119
130
  def initialize(predicate=nil, die=Cant.die)
@@ -1,3 +1,3 @@
1
1
  module Cant
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - thierry.henrio
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-04 00:00:00 +01:00
17
+ date: 2011-01-14 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,7 @@ files:
59
59
  - Gemfile
60
60
  - Gemfile.lock
61
61
  - Guardfile
62
- - LICENSE.mit
62
+ - MIT-LICENSE
63
63
  - README.markdown
64
64
  - Rakefile
65
65
  - cant.gemspec