Class: Swagcov::Command::GenerateDotfile

Inherits:
Object
  • Object
show all
Defined in:
lib/swagcov/command/generate_dotfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basename: ::Swagcov::DOTFILE) ⇒ GenerateDotfile

Returns a new instance of GenerateDotfile.



8
9
10
# File 'lib/swagcov/command/generate_dotfile.rb', line 8

def initialize basename: ::Swagcov::DOTFILE
  @dotfile = ::Swagcov.project_root.join(basename)
end

Instance Attribute Details

#dotfileObject (readonly)

Returns the value of attribute dotfile.



6
7
8
# File 'lib/swagcov/command/generate_dotfile.rb', line 6

def dotfile
  @dotfile
end

Instance Method Details

#runObject



12
13
14
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
44
45
46
47
# File 'lib/swagcov/command/generate_dotfile.rb', line 12

def run
  if ::File.exist?(@dotfile)
    $stdout.puts "#{@dotfile.basename} already exists at #{@dotfile.dirname}"
    return ::Swagcov::STATUS_ERROR
  end

  ::File.write(
    dotfile,
    <<~YAML
      ## Required field:
      # List your OpenAPI documentation file(s) (accepts json or yaml)
      docs:
        paths:
          - swagger.yaml
          - swagger.json

      ## Optional fields:
      # routes:
      #   paths:
      #     only:
      #       - ^/v2 # only track v2 endpoints
      #     ignore:
      #       - /: # root
      #         - GET
      #       - /up: # health check
      #         - GET
      #       - /v2/users # do not track certain endpoints
      #       - /v2/users/:id: # ignore only certain actions (verbs)
      #         - PUT
    YAML
  )

  $stdout.puts "created #{@dotfile.basename} at #{@dotfile.dirname}"

  ::Swagcov::STATUS_SUCCESS
end