Module: Chatwerk::Api

Defined in:
lib/chatwerk/api.rb

Class Method Summary collapse

Class Method Details

.package(package_path:) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/chatwerk/api.rb', line 34

def package(package_path:)
  package = Helpers.find_package(package_path)

  Views::PackageView.render(package:)
rescue StandardError => e
  raise Chatwerk::Error.new(e, package_path:)
end

.package_todos(package_path:, constant_name: '') ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chatwerk/api.rb', line 42

def package_todos(package_path:, constant_name: '')
  package = Helpers.find_package(package_path)
  constant_name = Helpers.normalize_constant_name(constant_name)
  violations = package.todos

  if constant_name.empty?
    Views::ViolationsListView.render(package:, violations:)
  else
    Views::ViolationsDetailsView.render(package:, violations:, constant_name:)
  end
rescue StandardError => e
  raise Chatwerk::Error.new(e, package_path:, constant_name:)
end

.package_violations(package_path:, constant_name: '') ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chatwerk/api.rb', line 56

def package_violations(package_path:, constant_name: '')
  package = Helpers.find_package(package_path)
  constant_name = Helpers.normalize_constant_name(constant_name)
  violations = package.violations

  if constant_name.empty?
    Views::ViolationsListView.render(package:, violations:)
  else
    Views::ViolationsDetailsView.render(package:, violations:, constant_name:)
  end
rescue StandardError => e
  raise Chatwerk::Error.new(e, package_path:, constant_name:)
end

.packages(package_path: '') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chatwerk/api.rb', line 21

def packages(package_path: '')
  packages = Helpers.all_packages(package_path)

  if packages.empty?
    has_packwerk_yml = File.exist?('packwerk.yml')
    Views::NoPackagesView.render(has_packwerk_yml:)
  else
    Views::PackagesView.render(packages:)
  end
rescue StandardError => e
  raise Chatwerk::Error.new(e, package_path:)
end


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/chatwerk/api.rb', line 9

def print_env
  msg = <<~MESSAGE
    PWD: #{Dir.pwd}
    PWD from ENV: #{ENV.fetch('PWD', nil)}
  MESSAGE
  Helpers.chdir do
    msg << "Chdir'd to #{Helpers.pwd}\n"
  end
  msg << ENV.to_h.map { |key, value| "#{key}=#{value}" }.join("\n")
  msg
end