Class: Aspera::Cli::MountSpec
- Inherits:
-
Struct
- Object
- Struct
- Aspera::Cli::MountSpec
- Defined in:
- lib/aspera/cli/command_spec.rb
Overview
Declares that a command node exposes a sub-tree of another plugin class. The mounted children appear in the host registry (dispatch, --help, completion) as if they were declared by the host; host children with the same id take precedence.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Arguments read by the host after the mounted command, before its own arguments; resolved values are passed to
instance(e.g.packages ls <package_id> <path>). -
#at ⇒ Object
readonly
Path in the target registry whose children are mounted ([] = root).
-
#except ⇒ Object
readonly
Exclude these ids from mounted children.
-
#only ⇒ Object
readonly
Restrict mounted children to these ids.
Instance Method Summary collapse
-
#accepts?(id) ⇒ Boolean
True if this child is exposed by the mount.
-
#initialize(**kwargs) ⇒ MountSpec
constructor
A new instance of MountSpec.
-
#instance(value) ⇒ Object
Host instance method called with **ctx, returning the target plugin instance, or [instance, ctx] where ctx seeds the target dispatch (it replaces what the setups of
atand its ancestors would provide). -
#plugin(value) ⇒ Object
Target plugin class (subclass of Plugins::Base).
-
#registry ⇒ CommandRegistry
Registry of the target plugin class.
Constructor Details
#initialize(**kwargs) ⇒ MountSpec
Returns a new instance of MountSpec.
149 150 151 152 153 |
# File 'lib/aspera/cli/command_spec.rb', line 149 def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Arguments read by the host after the mounted command, before its own
arguments; resolved values are passed to instance
(e.g. packages ls <package_id> <path>)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
#at ⇒ Object (readonly)
Path in the target registry whose children are mounted ([] = root)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
#except ⇒ Object (readonly)
Exclude these ids from mounted children
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
#only ⇒ Object (readonly)
Restrict mounted children to these ids
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
Instance Method Details
#accepts?(id) ⇒ Boolean
Returns true if this child is exposed by the mount.
162 163 164 |
# File 'lib/aspera/cli/command_spec.rb', line 162 def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end |
#instance=(value) ⇒ Object
Host instance method called with **ctx, returning the target plugin
instance, or [instance, ctx] where ctx seeds the target dispatch
(it replaces what the setups of at and its ancestors would provide)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
#plugin=(value) ⇒ Object
Target plugin class (subclass of Plugins::Base)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aspera/cli/command_spec.rb', line 140 MountSpec = Struct.new( :plugin, :at, :instance, :only, :except, :arguments, keyword_init: true ) do def initialize(**kwargs) kwargs[:at] = Array(kwargs[:at]).freeze kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze super end # @return [CommandRegistry] registry of the target plugin class def registry plugin.command_registry end # @param id [Symbol] id of a child of `at` in the target registry # @return [Boolean] true if this child is exposed by the mount def accepts?(id) (only.nil? || only.include?(id)) && !except&.include?(id) end end |
#registry ⇒ CommandRegistry
Returns registry of the target plugin class.
156 157 158 |
# File 'lib/aspera/cli/command_spec.rb', line 156 def registry plugin.command_registry end |