Class: Igniter::Contracts::Assembly::HookSpec
- Inherits:
-
Object
- Object
- Igniter::Contracts::Assembly::HookSpec
- Defined in:
- lib/igniter/contracts/assembly/hook_spec.rb
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#required_keywords ⇒ Object
readonly
Returns the value of attribute required_keywords.
-
#return_policy ⇒ Object
readonly
Returns the value of attribute return_policy.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
-
#initialize(registry:, method_name:, required_keywords:, role:, return_policy: :opaque, result_validator: nil) ⇒ HookSpec
constructor
A new instance of HookSpec.
- #validate!(key, implementation) ⇒ Object
- #validate_result!(key, result) ⇒ Object
Constructor Details
#initialize(registry:, method_name:, required_keywords:, role:, return_policy: :opaque, result_validator: nil) ⇒ HookSpec
Returns a new instance of HookSpec.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 9 def initialize(registry:, method_name:, required_keywords:, role:, return_policy: :opaque, result_validator: nil) @registry = registry.to_sym @method_name = method_name.to_sym @required_keywords = required_keywords.map(&:to_sym).freeze @role = role.to_sym @return_policy = return_policy.to_sym @result_validator = result_validator freeze end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
7 8 9 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 7 def method_name @method_name end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
7 8 9 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 7 def registry @registry end |
#required_keywords ⇒ Object (readonly)
Returns the value of attribute required_keywords.
7 8 9 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 7 def required_keywords @required_keywords end |
#return_policy ⇒ Object (readonly)
Returns the value of attribute return_policy.
7 8 9 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 7 def return_policy @return_policy end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
7 8 9 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 7 def role @role end |
Instance Method Details
#validate!(key, implementation) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 20 def validate!(key, implementation) unless implementation.respond_to?(method_name) raise InvalidHookImplementationError, "#{registry} entry #{key} must respond to ##{method_name}" end parameters = parameters_for(implementation) return if accepts_required_keywords?(parameters) missing = missing_keywords(parameters) expected_keywords = required_keywords.map { |name| "#{name}:" }.join(", ") missing_labels = missing.map { |name| "#{name}:" }.join(", ") raise InvalidHookImplementationError, "#{registry} entry #{key} must accept keywords #{expected_keywords}; missing #{missing_labels}" end |
#validate_result!(key, result) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/igniter/contracts/assembly/hook_spec.rb', line 37 def validate_result!(key, result) return result unless @result_validator = @result_validator.call(result) return result unless raise InvalidHookResultError, "#{registry} entry #{key} (#{role}) #{}" end |