Class: Goodcheck::Commands::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/commands/init.rb

Constant Summary collapse

CONFIG =
<<-EOC
rules:
  - id: com.example.1
    pattern: Github
    message: Do you want to write GitHub?
    glob: 
- "**/*.rb"
- "**/*.yaml"
- "**/*.yml"
- "**/*.html"
    fail:
- Signup via Github
    pass:
- Signup via GitHub
EOC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, path:, force:) ⇒ Init

Returns a new instance of Init.



25
26
27
28
29
30
# File 'lib/goodcheck/commands/init.rb', line 25

def initialize(stdout:, stderr:, path:, force:)
  @stdout = stdout
  @stderr = stderr
  @path = path
  @force = force
end

Instance Attribute Details

#forceObject (readonly)

Returns the value of attribute force.



23
24
25
# File 'lib/goodcheck/commands/init.rb', line 23

def force
  @force
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/goodcheck/commands/init.rb', line 22

def path
  @path
end

#stderrObject (readonly)

Returns the value of attribute stderr.



21
22
23
# File 'lib/goodcheck/commands/init.rb', line 21

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



20
21
22
# File 'lib/goodcheck/commands/init.rb', line 20

def stdout
  @stdout
end

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/goodcheck/commands/init.rb', line 32

def run
  if path.file? && !force
    stderr.puts "#{path} already exists. Try --force option to overwrite the file."
    return 1
  end

  path.open("w") do |io|
    io.print(CONFIG)
  end

  stdout.puts "Wrote #{path}. ✍️"

  0
end