Class: Textus::Action::List

Inherits:
Base
  • Object
show all
Extended by:
Contract::DSL
Defined in:
lib/textus/action/list.rb

Constant Summary collapse

BURN =
:sync

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Contract::DSL

arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view

Methods inherited from Base

#args, inherited

Constructor Details

#initialize(prefix: nil, lane: nil) ⇒ List

Returns a new instance of List.



19
20
21
22
23
# File 'lib/textus/action/list.rb', line 19

def initialize(prefix: nil, lane: nil)
  super()
  @prefix = prefix
  @lane = lane
end

Class Method Details

.new(*args, **kwargs) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/textus/action/list.rb', line 32

def self.new(*args, **kwargs)
  return super(**kwargs) unless args.any?

  call_spec = instance_method(:initialize).parameters
  required = call_spec.slice(:keyreq).map(&:last)
  optional = call_spec.slice(:key).map(&:last)
  positional = required + optional
  mapped = positional.zip(args).to_h
  super(**mapped.merge(kwargs))
end

Instance Method Details

#call(container:, call: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



25
26
27
28
29
30
# File 'lib/textus/action/list.rb', line 25

def call(container:, call: nil) # rubocop:disable Lint/UnusedMethodArgument
  manifest = container.manifest
  rows = manifest.resolver.enumerate(prefix: @prefix)
  rows = rows.select { |row| row[:manifest_entry].lane == @lane } if @lane
  rows.map { |row| { "key" => row[:key], "lane" => row[:manifest_entry].lane, "path" => row[:path] } }
end