module Lono::Configset::Strategy::Helpers::Dsl::Syntax

Public Instance Methods

command(key, props={}) click to toggle source

Add extra conveniences to command method

# File lib/lono/configset/strategy/helpers/dsl/syntax.rb, line 14
def command(key, props={})
  init_empty(@current, "commands")

  # order commands automatically
  if key !~ /^\d+_/
    c = @command_counts[@current] += 1 # IE: @command_counts["main"]
    padded_c = "%03d" % c
    key = "#{padded_c}_#{key}"
  end

  # if syntax support
  if props.key?(:if)
    if_clause = props.delete(:if)
    props[:test] = "if #{if_clause} ; then true ; else false ; fi"
    # returns true  - will run command
    # returns false - will not run command
  end

  # unless syntax support
  if props.key?(:unless)
    unless_clause = props.delete(:unless)
    props[:test] = "if #{unless_clause} ; then false ; else true ; fi"
    # returns true  - will run command
    # returns false - will not run command
  end

  current_structure(@current)["commands"].deep_merge!(key => props)
end
configset(current) { || ... } click to toggle source
# File lib/lono/configset/strategy/helpers/dsl/syntax.rb, line 56
def configset(current)
  @tracked << current
  previous, @current = @current, current
  yield
  @current = previous
end
source(*args) click to toggle source

Source has a different signature than the other native methods

# File lib/lono/configset/strategy/helpers/dsl/syntax.rb, line 44
def source(*args)
  if args.first.is_a?(Hash)
    item = args.first
  else # 2 args form: first element is k, second is
    k, v, _ = args
    item = {k => v}
  end

  init_empty(@current, "sources")
  current_structure(@current)["sources"].deep_merge!(item)
end

Private Instance Methods

current_structure(configset) click to toggle source
# File lib/lono/configset/strategy/helpers/dsl/syntax.rb, line 64
def current_structure(configset)
  @structure[configset] ||= {}
end
init_empty(configset, section) click to toggle source
# File lib/lono/configset/strategy/helpers/dsl/syntax.rb, line 69
def init_empty(configset, section)
  current = current_structure(configset)
  current[section] ||= {}
end