Class: Evil::Client::Policy
- Inherits:
-
Tram::Policy
- Object
- Tram::Policy
- Evil::Client::Policy
- Defined in:
- lib/evil/client/policy.rb
Overview
Base class for policies that validate settings
Class Attribute Summary collapse
-
.model ⇒ Class?
readonly
Reference to the model whose instances are validated by the policy.
Class Method Summary collapse
-
.for(model) ⇒ Class
Subclasses itself for a model class.
-
.name ⇒ String?
(also: to_s, to_sym, inspect)
Delegates the name of the policy to the name of checked model.
-
.scope ⇒ Object
Redefines translation scope for the policy.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object (private)
54 55 56 |
# File 'lib/evil/client/policy.rb', line 54 def method_missing(*args) respond_to_missing?(*args) ? model.__send__(*args) : super end |
Class Attribute Details
.model ⇒ Class? (readonly)
Reference to the model whose instances are validated by the policy
22 23 24 |
# File 'lib/evil/client/policy.rb', line 22 def model @model end |
Class Method Details
.for(model) ⇒ Class
Subclasses itself for a model class
12 13 14 15 16 |
# File 'lib/evil/client/policy.rb', line 12 def for(model) Class.new(self).tap do |klass| klass.send :instance_variable_set, :@model, model end end |
.name ⇒ String? Also known as: to_s, to_sym, inspect
Delegates the name of the policy to the name of checked model
28 29 30 |
# File 'lib/evil/client/policy.rb', line 28 def name "#{model}.policy" end |
.scope ⇒ Object
Redefines translation scope for the policy
39 40 41 42 |
# File 'lib/evil/client/policy.rb', line 39 def scope @scope ||= i[evil client errors] << \ Tram::Policy::Inflector.underscore(model.to_s).to_sym end |