Class: Railjet::ComposedPolicy
- Inherits:
-
Object
- Object
- Railjet::ComposedPolicy
- Defined in:
- lib/railjet/composed_policy.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
Class Method Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(context, object) ⇒ ComposedPolicy
constructor
A new instance of ComposedPolicy.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(context, object) ⇒ ComposedPolicy
Returns a new instance of ComposedPolicy.
20 21 22 23 24 25 26 |
# File 'lib/railjet/composed_policy.rb', line 20 def initialize(context, object) @context, @object = context, object @policies = self.class.policies.map do |policy| policy.new(context, object) end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/railjet/composed_policy.rb', line 5 def context @context end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/railjet/composed_policy.rb', line 5 def object @object end |
#policies ⇒ Object (readonly)
Returns the value of attribute policies.
6 7 8 |
# File 'lib/railjet/composed_policy.rb', line 6 def policies @policies end |
Class Method Details
.add(policy, after: nil, before: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/railjet/composed_policy.rb', line 8 def self.add(policy, after: nil, before: nil) self.policies ||= [] if after self.policies = policies.dup.insert(policies.index(after) + 1, policy) elsif before self.policies = policies.dup.insert(policies.index(before), policy) else self.policies += [policy] end end |
Instance Method Details
#errors ⇒ Object
32 33 34 35 |
# File 'lib/railjet/composed_policy.rb', line 32 def errors valid? policies.map(&:errors).inject(&:<<) end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/railjet/composed_policy.rb', line 28 def valid? policies.map(&:valid?).all? end |
#validate! ⇒ Object
37 38 39 |
# File 'lib/railjet/composed_policy.rb', line 37 def validate! policies.each(&:validate!) end |