Class: Ripgrep::Client
- Inherits:
-
Object
- Object
- Ripgrep::Client
- Extended by:
- Forwardable
- Defined in:
- lib/ripgrep/client.rb
Instance Method Summary collapse
- #exec(*args, opts) ⇒ Object
-
#initialize(verbose: false) ⇒ Client
constructor
A new instance of Client.
- #run(&block) ⇒ Object
Constructor Details
#initialize(verbose: false) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/ripgrep/client.rb', line 9 def initialize(verbose: false) @verbose = verbose end |
Instance Method Details
#exec(*args, opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ripgrep/client.rb', line 13 def exec(*args, opts) unless opts.is_a? Hash args << opts opts = {} end verbose = opts[:verbose].nil? ? @verbose : !!opts[:verbose] = opts[:options]&.map do |key, val| next unless val val = '' if val.is_a? TrueClass val = val.join if val.is_a? Array key = key.to_s.tr('_', '-') "--#{key} #{val}".strip end&.compact || [] puts "cli_options: #{cli_options}" if verbose cli_arguments = + args cli_arguments << (opts[:path] || '.') puts "cli_arguments: #{cli_arguments}" if verbose Core.exec(*cli_arguments, verbose: verbose) end |
#run(&block) ⇒ Object
33 34 35 |
# File 'lib/ripgrep/client.rb', line 33 def run(&block) instance_eval(&block) end |