Class: Trains::Scanner

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/trains/scanner.rb

Overview

Scanner parses all the code and stores metadata about the repo

Instance Method Summary collapse

Constructor Details

#initialize(folder, options = {}) ⇒ Scanner

Returns a new instance of Scanner.



6
7
8
9
10
11
12
13
# File 'lib/trains/scanner.rb', line 6

def initialize(folder, options = {})
  @root_folder = folder
  @models = {}
  @controllers = {}
  @helpers = {}
  @dir = File.expand_path(folder)
  @options = options
end

Instance Method Details

#scanObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trains/scanner.rb', line 15

def scan
  # Check if @folder is a Rails directory before beginning analysis
  rails_dir_result = RailsDir.check @dir
  case rails_dir_result
  in Result[data: true, error: nil]
    # Do nothing
  else
    return(
      Result.new(
        data: nil,
        error: ArgumentError.new('Not a Rails directory')
      )
    )
  end

  @models = generate_models unless @options[:models] == false
  @controllers = get_controllers unless @options[:controllers] == false
  @routes = get_routes.to_set unless @options[:routes] == false
  # TODO: @helpers = get_helpers

  # Create instance of Trains::DTO::App
  DTO::App.new(
    name: nil,
    controllers: @controllers,
    models: @models,
    helpers: @helpers,
    routes: @routes
  )
end