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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RegexFromSearch

#regex

Constructor Details

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

Returns a new instance of Finder.



13
14
15
16
17
18
19
# File 'lib/flatito/finder.rb', line 13

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

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



11
12
13
# File 'lib/flatito/finder.rb', line 11

def extensions
  @extensions
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/flatito/finder.rb', line 11

def options
  @options
end

#pathsObject (readonly)

Returns the value of attribute paths.



11
12
13
# File 'lib/flatito/finder.rb', line 11

def paths
  @paths
end

Returns the value of attribute print_items.



11
12
13
# File 'lib/flatito/finder.rb', line 11

def print_items
  @print_items
end

#searchObject (readonly)

Returns the value of attribute search.



11
12
13
# File 'lib/flatito/finder.rb', line 11

def search
  @search
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flatito/finder.rb', line 21

def call
  renderer.prepare

  paths.each do |path|
    TreeIterator.new(path, options).each do |pathname|
      renderer.print_file_progress(pathname)

      if extensions.include?(pathname.extname)
        flat_and_filter(pathname)
      end
    end
  end
ensure
  renderer.ending
end