README.md in permission_settings-1.0.2 vs README.md in permission_settings-1.0.4
- old
+ new
@@ -22,11 +22,11 @@
Generate and run the migration to create the settings table that is used to store the permissions:
```shell
rails g rails_settings:migration
-rake db:migrate
+rails db:migrate
```
## Usage
### Configuration
@@ -34,11 +34,11 @@
You can configure the gem by calling `PermissionSettings.configure` method in an initializer:
```ruby
# config/initializers/permission_settings.rb
-PermissionSettings.configure do |_config|
+PermissionSettings.configure do |config|
config.permissions_dir_path = 'config/permissions'
config.role_access_method = :role
end
```
* `permissions_dir_path` - configuration option for setting path to permissions directory
@@ -96,11 +96,11 @@
end
```
In order to check permissions of the resource instance you need to pass it as a named argument `resource` to the `#can?` method.
-Take into account that the resource model should have a `role` filed or method that returns a role name of the calling instance or you can configure the gem to use another method name by setting `role_access_method` configuration option.
+Take into account that the resource model should have a `role` field or method that returns a role name of the calling instance or you can configure the gem to use another method name by setting `role_access_method` configuration option.
### Checking permissions
You can check permissions of the resource instance by calling `#can?` method:
@@ -109,20 +109,20 @@
person = Person.last # => #<Person id: 2, name: "Jane", role: "client">
user.can?(:read, :notifications, resource: person) # => true
```
Method `can?` accepts 2 arguments:
-* `*permission_keys` - this keys will be used to find permissions in the settings. It can be a string or an array of strings. Required argument.
-* `*resource` - Named argument resource. Instance towards which the permissions will be checked. Required argument.
+* `*permission_keys` - this keys will be used to find permissions in the settings. It can be a string or an array of strings. `Required argument`.
+* `*resource` - Named argument resource. Instance towards which the permissions will be checked. `Required argument`.
### Accessing permissions
You can also access permissions of the resource or calling instance by calling `#settings` method:
```ruby
person = Person.last # => #<Person id: 2, name: "Jane", role: "client">
-person.settings[PermissionSettings.configuration.scope_name].admin.notifications.read # => false
+person.permissions[:admin][:notifications][:read] # => false
```
More about settings you can read in [Rails Settings](https://github.com/ledermann/rails-settings) gem documentation.
### Dynamic settings
@@ -165,10 +165,11 @@
}
admin = User.first # => #<User id: 1, name: "John", role: "admin">
person = Person.last # => #<User id: 2, name: "Jane", role: "client">
-person.settings(PermissionSettings.configuration.scope_name).update(custom_permissions)
+policy_scope = PermissionSettings.configuration.scope_name(User)
+person.settings(policy_scope).update(custom_permissions)
admin.can?(:read, :notifications, resource: person) # => false
person.settings(policy_scope).update({ admin: { notifications: nil } })