Module: Mt::Wall::DSL
- Defined in:
- lib/mt/wall/dsl.rb,
lib/mt/wall/dsl/rule_scope.rb,
lib/mt/wall/dsl/validators.rb,
lib/mt/wall/dsl/nat_builder.rb,
lib/mt/wall/dsl/host_builder.rb,
lib/mt/wall/dsl/policy_scope.rb,
lib/mt/wall/dsl/root_builder.rb,
lib/mt/wall/dsl/rule_builder.rb,
lib/mt/wall/dsl/chain_builder.rb,
lib/mt/wall/dsl/group_builder.rb,
lib/mt/wall/dsl/device_builder.rb
Overview
Entry points for turning DSL (a block or files) into a Configuration. The actual verbs live in DSL::RootBuilder.
Defined Under Namespace
Modules: PolicyScope, RuleScope, Validators Classes: ChainBuilder, DeviceBuilder, GroupBuilder, HostBuilder, NatBuilder, RootBuilder, RuleBuilder
Class Method Summary collapse
-
.build(&block) ⇒ Configuration
Build a Configuration from a DSL block.
-
.expand(paths) ⇒ Array<String>
Resolve the given paths into an ordered list of concrete ‘*.rb` files: files pass through untouched; directories expand to their recursive, sorted `*.rb` contents.
-
.load(*paths) ⇒ Configuration
Load and evaluate one or more DSL sources into a SINGLE Configuration (a GitOps repo of config).
Class Method Details
.build(&block) ⇒ Configuration
17 18 19 20 21 |
# File 'lib/mt/wall/dsl.rb', line 17 def build(&block) config = Configuration.new RootBuilder.new(config).instance_eval(&block) if block config end |
.expand(paths) ⇒ Array<String>
Resolve the given paths into an ordered list of concrete ‘*.rb` files: files pass through untouched; directories expand to their recursive, sorted `*.rb` contents. Fails fast on a missing path.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mt/wall/dsl.rb', line 46 def (paths) paths.flat_map do |path| if File.directory?(path) # Dir.glob returns lexicographically sorted results (Ruby 3.0+), # giving a deterministic, repeatable load order across a GitOps repo. Dir.glob(File.join(path, "**", "*.rb")) elsif File.file?(path) [path] else raise ConfigurationError, "no such DSL path #{path.inspect}" end end end |
.load(*paths) ⇒ Configuration
Load and evaluate one or more DSL sources into a SINGLE Configuration (a GitOps repo of config). Each path may be either a ‘*.rb` file or a DIRECTORY; a directory contributes every `*.rb` file found under it RECURSIVELY, in deterministic SORTED (lexicographic) order so the same repo always loads the same way. Files supplied directly are loaded in the order given; the contents of a directory are sorted among themselves. All sources fold into one shared Configuration.
34 35 36 37 38 39 |
# File 'lib/mt/wall/dsl.rb', line 34 def load(*paths) config = Configuration.new builder = RootBuilder.new(config) (paths.flatten).each { |path| builder.instance_eval(File.read(path), path) } config end |