Skip to content

Rewrite the GDK::Config DSL

Toon Claes requested to merge tc-re-dsl into master

What does this Merge Request do?

There was too much Ruby magic going on, so to make it easier to make some future changes, change the DSL to something more straight-forward.

When you define a setting you need to specify a type. So there is a limited set of keywords used to create a setting.

This makes validation easier and also should make it easier to deprecate settings in the future.

Let's compare the two...

Old DSL:

class Config < ConfigSettings
  hostname { read!('hostname') || read!('host') || '127.0.0.1' }

  gdk do |g|
    g.debug false
    g.ignore_foreman { read!('.ignore-foreman') || false }
    g.overwrite_changes false
  end

  port do
    next 443 if config.auto_devops.enabled

    read!('port') || 3000
  end
end

New DSL:

class Config < ConfigSettings
  string(:hostname) { read!('hostname') || read!('host') || '127.0.0.1' }

  settings :gdk do
    bool(:debug) { false }
    bool(:ignore_foreman) { read!('.ignore-foreman') || false }
    bool(:overwrite_changes) { false }
  end

  integer :port do
    next 443 if config.auto_devops.enabled

    read!('port') || 3000
  end
end

Closes #686 (closed), #650 (closed)

Merge Request checklist

  • Tests added for new functionality. If not, please raise Issue to follow-up.
  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Documentation added/updated, if needed.
  • gdk doctor test added, if needed.
Edited by Toon Claes

Merge request reports

Loading