Class: Ordit::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/ordit/results.rb

Instance Method Summary collapse

Constructor Details

#initializeResults

Returns a new instance of Results.



5
6
# File 'lib/ordit/results.rb', line 5

def initialize
end

Instance Method Details

#active_controllersObject



16
# File 'lib/ordit/results.rb', line 16

def active_controllers = to_h[:active_controllers].sort

#definitionsObject



12
13
14
# File 'lib/ordit/results.rb', line 12

def definitions
  Definitions.all
end

#filesObject



8
9
10
# File 'lib/ordit/results.rb', line 8

def files
  Files.all
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ordit/results.rb', line 20

def to_h
  @to_h ||= begin
    base_object = {
      active_controllers: [],
      undefined_controllers: {},
      unused_controllers: files.dup || []
    }


    definitions.each_with_object(base_object) do |(definition, file), result|
      # Convert definition pattern to match file pattern
      file_pattern = definition_to_file_pattern(definition)

      # Find matching file
      matching_file = files.find { |f| file_pattern == file_pattern_from_path(f) }

      if matching_file
        result[:active_controllers] << matching_file
        result[:unused_controllers].delete(matching_file)
        result[:active_controllers].sort!
      else
        result[:undefined_controllers][definition] ||= []
        result[:undefined_controllers][definition] |= file
      end
    end
  end
end

#undefined_controllersObject



17
# File 'lib/ordit/results.rb', line 17

def undefined_controllers = to_h[:undefined_controllers]

#unused_controllersObject



18
# File 'lib/ordit/results.rb', line 18

def unused_controllers = to_h[:unused_controllers].sort