Class: Igniter::Extensions::Contracts::ContentAddressing::Declaration
- Inherits:
-
Object
- Object
- Igniter::Extensions::Contracts::ContentAddressing::Declaration
- Defined in:
- lib/igniter/extensions/contracts/content_addressing/declaration.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#callable ⇒ Object
readonly
Returns the value of attribute callable.
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
Instance Method Summary collapse
- #call(**kwargs) ⇒ Object
- #content_fingerprint ⇒ Object
- #content_key(inputs) ⇒ Object
- #declared_capabilities ⇒ Object
-
#initialize(callable:, fingerprint:, cache:, capabilities:) ⇒ Declaration
constructor
A new instance of Declaration.
- #pure? ⇒ Boolean
Constructor Details
#initialize(callable:, fingerprint:, cache:, capabilities:) ⇒ Declaration
Returns a new instance of Declaration.
10 11 12 13 14 15 16 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 10 def initialize(callable:, fingerprint:, cache:, capabilities:) @callable = callable @fingerprint = fingerprint.to_s.freeze @cache = cache @capabilities = Array(capabilities).map(&:to_sym).uniq.freeze freeze end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 8 def cache @cache end |
#callable ⇒ Object (readonly)
Returns the value of attribute callable.
8 9 10 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 8 def callable @callable end |
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
8 9 10 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 8 def capabilities @capabilities end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
8 9 10 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 8 def fingerprint @fingerprint end |
Instance Method Details
#call(**kwargs) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 18 def call(**kwargs) key = content_key(kwargs) cached = cache.fetch(key) return cached unless cached.nil? value = callable.call(**kwargs) cache.store(key, value) value end |
#content_fingerprint ⇒ Object
36 37 38 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 36 def content_fingerprint fingerprint end |
#content_key(inputs) ⇒ Object
40 41 42 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 40 def content_key(inputs) ContentKey.compute(fingerprint: fingerprint, inputs: inputs) end |
#declared_capabilities ⇒ Object
28 29 30 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 28 def declared_capabilities capabilities end |
#pure? ⇒ Boolean
32 33 34 |
# File 'lib/igniter/extensions/contracts/content_addressing/declaration.rb', line 32 def pure? capabilities.include?(:pure) end |