Class: Noraneko::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/noraneko/project.rb

Constant Summary collapse

RESERVED_METHODS =
%i[initialize self].freeze

Instance Method Summary collapse

Constructor Details

#initialize(registry, view_registry) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
# File 'lib/noraneko/project.rb', line 7

def initialize(registry, view_registry)
  @registry = registry
  @nconsts = registry.to_a
  @view_registry = view_registry
  @views = view_registry.to_a
end

Instance Method Details

#all_unusedsObject



40
41
42
# File 'lib/noraneko/project.rb', line 40

def all_unuseds
  unused_methods + unused_modules + unused_views
end

#unused_methodsObject



14
15
16
17
18
# File 'lib/noraneko/project.rb', line 14

def unused_methods
  (unused_private_methods + unused_public_methods).reject do |method|
    RESERVED_METHODS.include?(method.name)
  end
end

#unused_modulesObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/noraneko/project.rb', line 20

def unused_modules
  @nconsts.each_with_object([]) do |nconst, candidates|
    nconst.all_used_modules.each do |m_name|
      cmodule = @registry.find(m_name)
      next unless cmodule
      if cmodule.all_methods.all? { |method| unused_public_method?(method) }
        candidates << cmodule
      end
    end
  end
end

#unused_viewsObject



32
33
34
35
36
37
38
# File 'lib/noraneko/project.rb', line 32

def unused_views
  controllers = @nconsts.select { |n| n.controller? }
  @views.reject { |v| v.name == 'layouts/application' }.select do |view|
    controllers.none? { |con| con.used_view?(view.name) } &&
      @views.none? { |v| v.called?(view.name) }
  end
end