indulgence 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ things:
10
10
 
11
11
  It was apparent to me that if 'something' was one of the CRUD actions, it would
12
12
  cover most of the use cases I could think of. So permissions were sub-divided
13
- into the 'abilities': create, read, update, and delete.
13
+ into the 'actions': create, read, update, and delete.
14
14
 
15
15
  The other requirement was that the permission for an object could be defined
16
16
  succinctly within a single file.
@@ -101,7 +101,7 @@ give Emperors the right to see and do anything by first creating an emperor
101
101
  caesar = User.create(
102
102
  :first_name => 'Julius',
103
103
  :last_name => 'Ceasar',
104
- :role_id => emporor.id
104
+ :role_id => emperor.id
105
105
  )
106
106
 
107
107
  And then defining what they can do by adding these two methods to ThingPermission:
@@ -243,6 +243,40 @@ With that done:
243
243
  Thing.indulgence(cicero, :update) == [thing]
244
244
  Thing.indulgence(cicero, :delete) --> raises ActiveRecord::RecordNotFound
245
245
 
246
+ === Defining your own actions
247
+
248
+ The default actions on which indulgence is based are the CRUD operations:
249
+ _create_, _read_, _update_ and _delete_. You can add your own actions, or
250
+ define a completely different action set if you prefer.
251
+
252
+ So for example when showing information about a thing, we could
253
+ display a warning that only emperors should see.
254
+
255
+ First update ThingPermissions like this:
256
+
257
+ def default
258
+ {
259
+ create: none,
260
+ read: all,
261
+ update: none,
262
+ delete: none,
263
+ prophecy: none,
264
+ }
265
+ end
266
+
267
+ def emperor
268
+ {
269
+ create: all,
270
+ update: all,
271
+ delete: all,
272
+ prophecy: all
273
+ }
274
+ end
275
+
276
+ And then in views/things/show.html.erb add:
277
+
278
+ <%= "Beware the Ides of March" if @thing.indulge?(current_user, :prophecy) %>
279
+
246
280
  === Alternative Permission Class
247
281
 
248
282
  As stated above, the default behaviour is for a Thing class to expect its
@@ -71,12 +71,6 @@ module Indulgence
71
71
  def define_ability(args)
72
72
  self.class.define_ability(args)
73
73
  end
74
-
75
- # Ensure passing an unknown key behaves as one would expect for a hash
76
- def [](key)
77
- return {}[key] unless keys.include? key
78
- super
79
- end
80
74
 
81
75
  def role_name
82
76
  @role_name ||= entity_role_name
@@ -1,10 +1,16 @@
1
1
  module Indulgence
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
4
4
 
5
5
  # History
6
6
  # =======
7
7
  #
8
+ # 0.0.3 Updated to use latest version of standalone_migrations
9
+ #
10
+ # standalone_migrations main has been updated to use branch this app
11
+ # has been using. So config in .standalone_migrations now works without
12
+ # using a specific clone branch.
13
+ #
8
14
  # 0.0.2 Rebuild with lessons learnt from first usage in host app
9
15
  #
10
16
  # Adds automatic caching of abilites. Required a reworking of ability
@@ -1,8 +1,10 @@
1
1
  require 'active_record'
2
2
  class CreateRoles < ActiveRecord::Migration
3
- create_table :roles do |t|
4
- t.string :name
3
+ def change
4
+ create_table :roles do |t|
5
+ t.string :name
5
6
 
6
- t.timestamps
7
+ t.timestamps
8
+ end
7
9
  end
8
10
  end
@@ -1,7 +1,10 @@
1
1
  class CreateThings < ActiveRecord::Migration
2
- create_table :things do |t|
3
- t.string :name
4
- t.integer :owner_id
5
- t.timestamps
2
+
3
+ def change
4
+ create_table :things do |t|
5
+ t.string :name
6
+ t.integer :owner_id
7
+ t.timestamps
8
+ end
6
9
  end
7
10
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indulgence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: standalone_migrations
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.1
46
62
  description: Packages permission functionality into a set of permission objects.
47
63
  email:
48
64
  - rob@undervale.co.uk