Module: Tram::Policy::DSL
- Included in:
- Tram::Policy
- Defined in:
- lib/tram/policy/dsl.rb
Overview
Class-level DSL for policy objects
Instance Method Summary collapse
-
#[](*args) ⇒ Tram::Policy
Policy constructor/validator (alias for [.new]).
-
#local_validators ⇒ Array<Proc>
List of validators defined by a policy per se.
-
#root_scope(*value) ⇒ self
Sets the root scope of the policy and its subclasses.
-
#scope ⇒ Array<String>
Translation scope for a policy.
-
#validate(name, opts) ⇒ self
Registers a validator.
-
#validators ⇒ Array<Proc>
List of all applicable validators from both the policy and its parent.
Instance Method Details
#[](*args) ⇒ Tram::Policy
Policy constructor/validator (alias for [.new])
21 22 23 |
# File 'lib/tram/policy/dsl.rb', line 21 def [](*args) new(*args) end |
#local_validators ⇒ Array<Proc>
List of validators defined by a policy per se
46 47 48 |
# File 'lib/tram/policy/dsl.rb', line 46 def local_validators @local_validators ||= [] end |
#root_scope(*value) ⇒ self
Sets the root scope of the policy and its subclasses
30 31 32 |
# File 'lib/tram/policy/dsl.rb', line 30 def root_scope(*value) tap { @root_scope = value.flatten.map(&:to_s).reject(&:empty?) } end |
#scope ⇒ Array<String>
Translation scope for a policy
38 39 40 |
# File 'lib/tram/policy/dsl.rb', line 38 def scope @scope ||= Array(@root_scope) + [Inflector.underscore(name)] end |
#validate(name, opts) ⇒ self
Registers a validator
11 12 13 14 |
# File 'lib/tram/policy/dsl.rb', line 11 def validate(name = nil, **opts, &block) local_validators << Validator.new(name, block, opts) self end |