Class: Grepfruit::Search
- Inherits:
-
Object
- Object
- Grepfruit::Search
- Includes:
- Decorator
- Defined in:
- lib/grepfruit/search.rb
Constant Summary
Constants included from Decorator
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#excluded_lines ⇒ Object
readonly
Returns the value of attribute excluded_lines.
-
#excluded_paths ⇒ Object
readonly
Returns the value of attribute excluded_paths.
-
#included_paths ⇒ Object
readonly
Returns the value of attribute included_paths.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#json_output ⇒ Object
readonly
Returns the value of attribute json_output.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#search_hidden ⇒ Object
readonly
Returns the value of attribute search_hidden.
-
#truncate ⇒ Object
readonly
Returns the value of attribute truncate.
Instance Method Summary collapse
-
#initialize(dir:, regex:, exclude:, include:, truncate:, search_hidden:, jobs:, json_output: false) ⇒ Search
constructor
A new instance of Search.
- #run ⇒ Object
Constructor Details
#initialize(dir:, regex:, exclude:, include:, truncate:, search_hidden:, jobs:, json_output: false) ⇒ Search
Returns a new instance of Search.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/grepfruit/search.rb', line 12 def initialize(dir:, regex:, exclude:, include:, truncate:, search_hidden:, jobs:, json_output: false) @dir = File.(dir) @regex = regex @excluded_lines, @excluded_paths = exclude.map { _1.split("/") }.partition { _1.last.include?(":") } @included_paths = include.map { _1.split("/") } @truncate = truncate @search_hidden = search_hidden @jobs = jobs || Etc.nprocessors @json_output = json_output end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def dir @dir end |
#excluded_lines ⇒ Object (readonly)
Returns the value of attribute excluded_lines.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def excluded_lines @excluded_lines end |
#excluded_paths ⇒ Object (readonly)
Returns the value of attribute excluded_paths.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def excluded_paths @excluded_paths end |
#included_paths ⇒ Object (readonly)
Returns the value of attribute included_paths.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def included_paths @included_paths end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def jobs @jobs end |
#json_output ⇒ Object (readonly)
Returns the value of attribute json_output.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def json_output @json_output end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def regex @regex end |
#search_hidden ⇒ Object (readonly)
Returns the value of attribute search_hidden.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def search_hidden @search_hidden end |
#truncate ⇒ Object (readonly)
Returns the value of attribute truncate.
10 11 12 |
# File 'lib/grepfruit/search.rb', line 10 def truncate @truncate end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 |
# File 'lib/grepfruit/search.rb', line 23 def run puts "Searching for #{regex.inspect} in #{dir.inspect}...\n\n" unless json_output display_final_results(execute_search) end |