Module: Swa::CLI::CollectionBehaviour

Defined in:
lib/swa/cli/collection_behaviour.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(target) ⇒ Object



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
# 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

Instance Method Details

#query_optionsObject



46
47
48
# File 'lib/swa/cli/collection_behaviour.rb', line 46

def query_options
  context[:query_options] ||= {}
end

#selectorObject



42
43
44
# File 'lib/swa/cli/collection_behaviour.rb', line 42

def selector
  context[:selector] ||= Selector.new
end