Class: RailsDoctor::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_doctor/adapters/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, config:, runner:, profile:, changed_files: []) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
# File 'lib/rails_doctor/adapters/base.rb', line 10

def initialize(project:, config:, runner:, profile:, changed_files: [])
  @project = project
  @config = config
  @runner = runner
  @profile = profile
  @changed_files = changed_files
end

Instance Attribute Details

#changed_filesObject (readonly)

Returns the value of attribute changed_files.



8
9
10
# File 'lib/rails_doctor/adapters/base.rb', line 8

def changed_files
  @changed_files
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/rails_doctor/adapters/base.rb', line 8

def config
  @config
end

#profileObject (readonly)

Returns the value of attribute profile.



8
9
10
# File 'lib/rails_doctor/adapters/base.rb', line 8

def profile
  @profile
end

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'lib/rails_doctor/adapters/base.rb', line 8

def project
  @project
end

#runnerObject (readonly)

Returns the value of attribute runner.



8
9
10
# File 'lib/rails_doctor/adapters/base.rb', line 8

def runner
  @runner
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/rails_doctor/adapters/base.rb', line 26

def available?
  return false if command.to_s.strip.empty?

  declared_gems.any? { |gem| project.gem_declared?(gem) } || executable_names.any? { |exe| project.command_available?(exe) }
end

#commandObject



22
23
24
# File 'lib/rails_doctor/adapters/base.rb', line 22

def command
  config.command(name)
end

#install_guidanceObject



36
37
38
# File 'lib/rails_doctor/adapters/base.rb', line 36

def install_guidance
  "Run rails-doctor init to add #{declared_gems.first || name} to the appropriate development/test group."
end

#nameObject



18
19
20
# File 'lib/rails_doctor/adapters/base.rb', line 18

def name
  self.class::NAME
end

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rails_doctor/adapters/base.rb', line 40

def run
  command_result = runner.run(command, timeout_seconds: timeout_seconds)
  {
    tool_run: ToolRun.new(
      name: name,
      available: true,
      skipped: false,
      command: command,
      exit_status: command_result.exit_status,
      duration_ms: command_result.duration_ms,
      stdout: command_result.stdout,
      stderr: command_result.stderr,
      metadata: (command_result)
    ),
    findings: parse(command_result)
  }
end

#unavailable_reasonObject



32
33
34
# File 'lib/rails_doctor/adapters/base.rb', line 32

def unavailable_reason
  "#{name} is not installed or available in this project."
end