README.md in consul-0.7.0 vs README.md in consul-0.8.0
- old
+ new
@@ -147,10 +147,32 @@
end
end
+Powers that require context (arguments)
+---------------------------------------
+
+Sometimes it can be useful to define powers that require context. To do so, just take an argument in your `power` block:
+
+ class Power
+ ...
+
+ power :assignable_story_states do |story|
+ if story.finished?
+ %w[delivered archived]
+ else
+ %w[committed started finished]
+ end
+ end
+
+When querying such a power, you always need to provide the context, e.g.:
+
+ story = ...
+ Power.current_assignable_story_state?(story, 'finished')
+
+
Role-based permissions
----------------------
Consul has no built-in support for role-based permissions, but you can easily implement it yourself. Let's say your `User` model has a string column `role` which can be `"author"` or `"admin"`:
@@ -414,10 +436,10 @@
`Power.current` or, if it is not set, just assume that everything is accessible:
class UserReport
def data
- Power.for_model(user).collect do |user|
+ Power.for_model(User).collect do |user|
[user.name, user.email, user.income]
end
end
end