Module: Lono::Configset::Strategy::Helpers::Dsl::Syntax

Extended by:
Memoist
Included in:
Lono::Configset::Strategy::Helpers::Dsl
Defined in:
lib/lono/configset/strategy/helpers/dsl/syntax.rb

Instance Method Summary collapse

Instance Method Details

#command(key, props = {}) ⇒ Object

Add extra conveniences to command method



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



56
57
58
59
60
61
# 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) ⇒ Object

Source has a different signature than the other native methods



44
45
46
47
48
49
50
51
52
53
54
# 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