Class: CC::EngineRegistry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cc/engine_registry.rb

Defined Under Namespace

Classes: EngineDetails

Constant Summary collapse

DEFAULT_MEMORY_LIMIT =
1_024_000_000
DEFAULT_COMMAND =
nil
DEFAULT_MANIFEST_PATH =
File.expand_path("../../../config/engines.yml", __FILE__)
EngineDetailsNotFoundError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(path = DEFAULT_MANIFEST_PATH, prefix = nil) ⇒ EngineRegistry

Returns a new instance of EngineRegistry.



12
13
14
15
# File 'lib/cc/engine_registry.rb', line 12

def initialize(path = DEFAULT_MANIFEST_PATH, prefix = nil)
  @yaml = YAML.safe_load(File.read(path))
  @prefix = prefix || ENV["CODECLIMATE_PREFIX"] || ""
end

Instance Method Details

#eachObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cc/engine_registry.rb', line 17

def each
  yaml.each do |name, |
    engine = Config::Engine.new(
      name,
      channel: .fetch("channels").keys.first,
    )
    engine_details = fetch_engine_details(engine)

    yield(engine, engine_details)
  end
end

#fetch_engine_details(engine, development: false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cc/engine_registry.rb', line 29

def fetch_engine_details(engine, development: false)
  if development
    EngineDetails.new("codeclimate/codeclimate-#{engine.name}", nil, "")
  else
     = yaml.fetch(engine.name)
    channels = .fetch("channels")

    EngineDetails.new(
      [prefix, channels.fetch(engine.channel)].join,
      .fetch("command", DEFAULT_COMMAND),
      .fetch("description", "(No description available)"),
      memory_limit(["minimum_memory_limit"]),
      .fetch("source-library", {}),
      .fetch("channel-versions", {}),
      .fetch("plugin", {}),
    )
  end
rescue KeyError
  raise EngineDetailsNotFoundError, not_found_message(engine, channels)
end