Class: Flatito::Finder

Inherits:
Object
  • Object
show all
Includes:
RegexFromSearch
Defined in:
lib/flatito/finder.rb

Constant Summary collapse

DEFAULT_EXTENSIONS =
%w[json yml yaml].freeze
FORK_THRESHOLD =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RegexFromSearch

#regex, #value_regex

Constructor Details

#initialize(paths, options = {}) ⇒ Finder

Returns a new instance of Finder.



16
17
18
19
20
21
22
23
24
# File 'lib/flatito/finder.rb', line 16

def initialize(paths, options = {})
  @paths = paths
  @search = options[:search]
  @search_value = options[:search_value]
  @case_sensitive = options[:case_sensitive]
  @extensions = prepare_extensions(options[:extensions] || DEFAULT_EXTENSIONS)
  @options = options
  @print_items = PrintItems.new(search, search_value, case_sensitive: case_sensitive)
end

Instance Attribute Details

#case_sensitiveObject (readonly)

Returns the value of attribute case_sensitive.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def case_sensitive
  @case_sensitive
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def extensions
  @extensions
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def options
  @options
end

#pathsObject (readonly)

Returns the value of attribute paths.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def paths
  @paths
end

Returns the value of attribute print_items.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def print_items
  @print_items
end

#searchObject (readonly)

Returns the value of attribute search.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def search
  @search
end

#search_valueObject (readonly)

Returns the value of attribute search_value.



14
15
16
# File 'lib/flatito/finder.rb', line 14

def search_value
  @search_value
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flatito/finder.rb', line 28

def call
  @matched = false
  renderer.prepare

  files = collect_candidate_files

  if files.size >= FORK_THRESHOLD && Process.respond_to?(:fork)
    process_with_forks(files)
  else
    files.each { |pathname| flat_and_filter(pathname) }
  end

  @matched
ensure
  renderer.ending
end