Class: Jdepp::CLI::Feedback
- Inherits:
-
Object
- Object
- Jdepp::CLI::Feedback
- Defined in:
- lib/jdepp/cli/feedback.rb
Instance Attribute Summary collapse
-
#enabled_tags ⇒ Object
readonly
Returns the value of attribute enabled_tags.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #action ⇒ Object
- #action? ⇒ Boolean
- #add_tag(tag) ⇒ Object
- #delete_tag(tag) ⇒ Object
- #dry_run ⇒ Object
- #dry_run? ⇒ Boolean
-
#initialize(enabled_tags = [], output = $stderr) ⇒ Feedback
constructor
A new instance of Feedback.
- #puts_if(relevant_tags, &msg) ⇒ Object
- #quiet ⇒ Object
- #system(cmds) ⇒ Object
- #verbose ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize(enabled_tags = [], output = $stderr) ⇒ Feedback
Returns a new instance of Feedback.
11 12 13 14 |
# File 'lib/jdepp/cli/feedback.rb', line 11 def initialize(=[], output=$stderr) @enabled_tags = Set.new([:error]) | @output = output end |
Instance Attribute Details
#enabled_tags ⇒ Object (readonly)
Returns the value of attribute enabled_tags.
8 9 10 |
# File 'lib/jdepp/cli/feedback.rb', line 8 def @enabled_tags end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
9 10 11 |
# File 'lib/jdepp/cli/feedback.rb', line 9 def output @output end |
Instance Method Details
#action ⇒ Object
44 45 46 |
# File 'lib/jdepp/cli/feedback.rb', line 44 def action add_tag(:action) end |
#action? ⇒ Boolean
40 41 42 |
# File 'lib/jdepp/cli/feedback.rb', line 40 def action? @enabled_tags.member?(:action) end |
#add_tag(tag) ⇒ Object
16 17 18 |
# File 'lib/jdepp/cli/feedback.rb', line 16 def add_tag(tag) @enabled_tags.add(tag) end |
#delete_tag(tag) ⇒ Object
20 21 22 |
# File 'lib/jdepp/cli/feedback.rb', line 20 def delete_tag(tag) @enabled_tags.delete(tag) end |
#dry_run ⇒ Object
28 29 30 |
# File 'lib/jdepp/cli/feedback.rb', line 28 def dry_run add_tag(:dry_run) end |
#dry_run? ⇒ Boolean
24 25 26 |
# File 'lib/jdepp/cli/feedback.rb', line 24 def dry_run? @enabled_tags.member?(:dry_run) end |
#puts_if(relevant_tags, &msg) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jdepp/cli/feedback.rb', line 56 def puts_if(, &msg) if .is_a?(Array) then = Set.new() elsif not .is_a?(Set) then = Set.new([]) end = .intersection(@enabled_tags) if .length > 0 then @output.puts("#{prefix }#{msg.call()}") end nil end |
#quiet ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/jdepp/cli/feedback.rb', line 48 def quiet preserve_dry = dry_run @enabled_tags = Set.new([:error]) if preserve_dry then dry_run end end |
#system(cmds) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/jdepp/cli/feedback.rb', line 69 def system(cmds) puts_if([:dry_run, :verbose, :action]) { cmds } if not self.dry_run? then Kernel::system(cmds) else nil end end |
#verbose ⇒ Object
36 37 38 |
# File 'lib/jdepp/cli/feedback.rb', line 36 def verbose add_tag(:verbose) end |
#verbose? ⇒ Boolean
32 33 34 |
# File 'lib/jdepp/cli/feedback.rb', line 32 def verbose? @enabled_tags.member?(:verbose) end |