Class: RubyUIConverter::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ui_converter/converter.rb

Overview

Orchestrates the conversion of an entire directory (or single file).

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(path, config: Configuration.new) ⇒ Converter

Returns a new instance of Converter.



10
11
12
13
# File 'lib/ruby_ui_converter/converter.rb', line 10

def initialize(path, config: Configuration.new)
  @path = path
  @config = config
end

Instance Method Details

#rootObject

The namespace root. Precedence: explicit config.root, then the nearest ‘app/views` ancestor (Rails convention — keeps generated constants matching the Zeitwerk path mapping no matter which subfolder was converted), then the directory the user pointed at.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_ui_converter/converter.rb', line 19

def root
  @root ||=
    if @config.root
      File.expand_path(@config.root)
    else
      base =
        if File.directory?(@path)
          File.expand_path(@path)
        else
          File.dirname(File.expand_path(@path))
        end
      conventional_root(base) || base
    end
end

#runObject



34
35
36
# File 'lib/ruby_ui_converter/converter.rb', line 34

def run
  FileWalker.new(@path).erb_files.map { |file| convert_file(file) }
end