Class: CC::CLI::ConfigGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/cli/config_generator.rb

Direct Known Subclasses

UpgradeConfigGenerator

Constant Summary collapse

CODECLIMATE_YAML =
Command::CODECLIMATE_YAML
AUTO_EXCLUDE_PATHS =
%w(config/ db/ dist/ features/ node_modules/ script/ spec/ test/ tests/ vendor/).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filesystem, engine_registry) ⇒ ConfigGenerator

Returns a new instance of ConfigGenerator.



15
16
17
18
# File 'lib/cc/cli/config_generator.rb', line 15

def initialize(filesystem, engine_registry)
  @filesystem = filesystem
  @engine_registry = engine_registry
end

Class Method Details

.for(filesystem, engine_registry, upgrade_requested) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/cc/cli/config_generator.rb', line 7

def self.for(filesystem, engine_registry, upgrade_requested)
  if upgrade_requested && upgrade_needed?(filesystem)
    UpgradeConfigGenerator.new(filesystem, engine_registry)
  else
    ConfigGenerator.new(filesystem, engine_registry)
  end
end

.upgrade_needed?(filesystem) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/cc/cli/config_generator.rb', line 51

def self.upgrade_needed?(filesystem)
  if filesystem.exist?(CODECLIMATE_YAML)
    YAML.safe_load(File.read(CODECLIMATE_YAML))["languages"].present?
  end
end

Instance Method Details

#can_generate?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cc/cli/config_generator.rb', line 20

def can_generate?
  true
end

#eligible_enginesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/cc/cli/config_generator.rb', line 24

def eligible_engines
  return @eligible_engines if @eligible_engines

  engines = engine_registry.list
  @eligible_engines = engines.each_with_object({}) do |(name, config), result|
    if engine_eligible?(config)
      result[name] = config
    end
  end
end

#errorsObject



35
36
37
# File 'lib/cc/cli/config_generator.rb', line 35

def errors
  []
end

#exclude_pathsObject



39
40
41
# File 'lib/cc/cli/config_generator.rb', line 39

def exclude_paths
  AUTO_EXCLUDE_PATHS.select { |path| filesystem.exist?(path) }
end

#post_generation_verbObject



43
44
45
# File 'lib/cc/cli/config_generator.rb', line 43

def post_generation_verb
  "generated"
end