Sha256: fa5b59525fa23896b977016ba204193faa0e2a862f0ee1ffdd9bbcf9c4eac785
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Parametric # Adapt legacy policies to the new policy interface class PolicyAdapter class PolicyRunner def initialize(policy, key, value, payload, context) @policy, @key, @raw_value, @payload, @context = policy, key, value, payload, context end # The PolicyRunner interface # @return [Boolean] def eligible? @policy.eligible?(@raw_value, @key, @payload) end # @return [Boolean] def valid? @policy.valid?(value, @key, @payload) end # @return [Any] def value @value ||= @policy.coerce(@raw_value, @key, @context) end # @return [String] def message @policy.message end end def initialize(policy) @policy = policy end # The PolicyFactory interface # Buld a Policy Runner, which is instantiated # for each field when resolving a schema # @param key [Symbol] # @param value [Any] # @option payload [Hash] # @option context [Parametric::Context] # @return [PolicyRunner] def build(key, value, payload:, context:) PolicyRunner.new(@policy, key, value, payload, context) end def meta_data @policy.meta_data end def key @policy.key end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
parametric-0.2.19 | lib/parametric/policy_adapter.rb |
parametric-0.2.18 | lib/parametric/policy_adapter.rb |