module Swa::CLI::CollectionBehaviour
Public Class Methods
included(target)
click to toggle source
# File lib/swa/cli/collection_behaviour.rb, line 8 def self.included(target) target.default_subcommand = "summary" target.subcommand ["summary", "s"], "One-line summary" do def execute collection.each do |i| puts i.summary end end end target.subcommand ["ids"], "Just print ids" do def execute collection.each do |i| puts i.id end end end target.subcommand ["data", "d"], "Full details" do parameter "[QUERY]", "JMESPath expression" def execute display_data(collection.map(&:data).to_a, query) end end end
Public Instance Methods
execute()
click to toggle source
# File lib/swa/cli/collection_behaviour.rb, line 14 def execute collection.each do |i| puts i.summary end end
query_options()
click to toggle source
# File lib/swa/cli/collection_behaviour.rb, line 46 def query_options context[:query_options] ||= {} end
selector()
click to toggle source
# File lib/swa/cli/collection_behaviour.rb, line 42 def selector context[:selector] ||= Selector.new end