Sha256: 0000199fda720acf171eb586939a0caa0262723dd6d28399aa0c65b012689085

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

# Custom Base Policy

`ActionPolicy::Base` is a combination of all available policy extensions with the default configuration.

It looks like this:


```ruby
class ActionPolicy::Base
  include ActionPolicy::Policy::Core
  include ActionPolicy::Policy::Authorization
  include ActionPolicy::Policy::PreCheck
  include ActionPolicy::Policy::Reasons
  include ActionPolicy::Policy::Aliases
  include ActionPolicy::Policy::Scoping
  include ActionPolicy::Policy::Cache
  include ActionPolicy::Policy::CachedApply
  include ActionPolicy::Policy::Defaults

  # ActionPolicy::Policy::Defaults module adds the following

  authorize :user

  default_rule :manage?
  alias_rule :new?, to: :create?

  def index?
    false
  end

  def create?
    false
  end

  def manage?
    false
  end
end
```



You can write your `ApplicationPolicy` from scratch instead of inheriting from `ActionPolicy::Base`
if the defaults above do not fit your needs. The only required component is `ActionPolicy::Policy::Core`:

```ruby
# minimal ApplicationPolicy
class ApplicationPolicy
  include ActionPolicy::Policy::Core
end
```

The `Core` module provides `apply` and `allowed_to?` methods.

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
action_policy-0.4.4 docs/custom_policy.md
action_policy-0.4.3 docs/custom_policy.md
action_policy-0.4.2 docs/custom_policy.md
action_policy-0.4.1 docs/custom_policy.md
action_policy-0.4.0 docs/custom_policy.md
action_policy-0.3.4 docs/custom_policy.md
action_policy-0.3.3 docs/custom_policy.md
action_policy-0.3.2 docs/custom_policy.md