Class: Phronomy::Agent::ContextPolicyDescriptor
- Inherits:
-
Data
- Object
- Data
- Phronomy::Agent::ContextPolicyDescriptor
- Defined in:
- lib/phronomy/agent/context_policy_descriptor.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #config_digest ⇒ Object
-
#initialize(id:, version:, config: {}) ⇒ ContextPolicyDescriptor
constructor
A new instance of ContextPolicyDescriptor.
- #to_h ⇒ Object
Constructor Details
#initialize(id:, version:, config: {}) ⇒ ContextPolicyDescriptor
Returns a new instance of ContextPolicyDescriptor.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 8 def initialize(id:, version:, config: {}) normalized_config = Immutable.copy(config || {}) Immutable.validate_canonical_json!(normalized_config, label: "Context Policy config") super( id: id.to_s.freeze, version: Integer(version), config: normalized_config ) raise ArgumentError, "Context Policy id must not be empty" if id.empty? raise ArgumentError, "Context Policy version must be positive" unless version.positive? freeze end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config
7 8 9 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 7 def config @config end |
#id ⇒ Object (readonly)
Returns the value of attribute id
7 8 9 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 7 def id @id end |
#version ⇒ Object (readonly)
Returns the value of attribute version
7 8 9 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 7 def version @version end |
Class Method Details
.from_h(hash) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 21 def self.from_h(hash) descriptor = new( id: hash.fetch("id") { hash.fetch(:id) }, version: hash.fetch("version") { hash.fetch(:version) }, config: hash["config"] || hash[:config] || {} ) expected_digest = hash["config_digest"] || hash[:config_digest] if expected_digest && expected_digest.to_s != descriptor.config_digest raise Phronomy::ConfigurationError, "Context Policy config digest mismatch for #{descriptor.id}@#{descriptor.version}" end descriptor end |
Instance Method Details
#config_digest ⇒ Object
35 36 37 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 35 def config_digest "sha256:#{Digest::SHA256.hexdigest(Phronomy::CanonicalJSON.dump(config))}" end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/phronomy/agent/context_policy_descriptor.rb', line 39 def to_h { "id" => id, "version" => version, "config" => config, "config_digest" => config_digest } end |