Class: Portage::Ucp::Capability

Inherits:
Object
  • Object
show all
Defined in:
lib/portage/ucp/capability.rb

Overview

A named, versioned UCP capability (e.g. "dev.ucp.shopping.catalog") mapping UCP action names to the Adapter methods that back them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version:, actions:, predicate: nil) ⇒ Capability

predicate: is for extension capabilities like dev.ucp.shopping.discount and dev.ucp.shopping.fulfillment that add a param to an existing action rather than an action of their own — there's no dedicated method whose override signals support, so the adapter exposes a boolean method instead and the capability asks it directly rather than inspecting actions.



14
15
16
17
18
19
# File 'lib/portage/ucp/capability.rb', line 14

def initialize(name:, version:, actions:, predicate: nil)
  @name = name
  @version = version
  @actions = actions
  @predicate = predicate
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/portage/ucp/capability.rb', line 6

def actions
  @actions
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/portage/ucp/capability.rb', line 6

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/portage/ucp/capability.rb', line 6

def version
  @version
end

Instance Method Details

#advertised_for?(adapter) ⇒ Boolean

Advertised if the predicate says so, or (for ordinary action-based capabilities) if at least one backing Adapter method is overridden — see Portage::Ucp::Adapter for why (contract can grow without breaking adapters).

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/portage/ucp/capability.rb', line 24

def advertised_for?(adapter)
  return adapter.public_send(@predicate) if @predicate

  actions.values.any? { |method_name| overridden?(adapter, method_name) }
end