Class: Textus::CLI::Verb::Hooks
- Inherits:
-
Textus::CLI::Verb
- Object
- Textus::CLI::Verb
- Textus::CLI::Verb::Hooks
- Defined in:
- lib/textus/cli/verb/hooks.rb
Instance Attribute Summary
Attributes inherited from Textus::CLI::Verb
Instance Method Summary collapse
-
#call(store) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity.
Methods inherited from Textus::CLI::Verb
#emit, inherited, #initialize, needs_store?, option, options, #parse
Constructor Details
This class inherits a constructor from Textus::CLI::Verb
Instance Method Details
#call(store) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/textus/cli/verb/hooks.rb', line 7 def call(store) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity subcommand = positional.first if subcommand raise UsageError.new("hook requires 'list'") unless subcommand == "list" positional.shift end rows = [] Textus::Hooks::Registry::EVENTS.each do |event, spec| mode = spec[:mode].to_s case spec[:mode] when :rpc store.registry.rpc_names(event).each do |name| rows << { "event" => event.to_s, "mode" => mode, "name" => name.to_s } end when :pubsub store.registry.pubsub_handlers(event).each do |h| row = { "event" => event.to_s, "mode" => mode, "name" => h[:name].to_s } row["keys"] = Array(h[:keys]) if h[:keys] rows << row end end end store.manifest.entries.each do |e| e.events.each do |evt, defs| Array(defs).each do |defn| next unless defn["exec"] rows << { "event" => evt.to_s, "mode" => "manifest", "exec" => defn["exec"], "key" => e.key, "as" => defn["as"] || "script" } end end end rows.select! { |r| r["event"] == event_filter } if event_filter emit({ "hooks" => rows }) end |