Class: RC::DSL

Inherits:
Module
  • Object
show all
Defined in:
lib/rc/dsl.rb

Overview

Configuration’s DSL

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ DSL

Returns a new instance of DSL.



10
11
12
13
# File 'lib/rc/dsl.rb', line 10

def initialize(configuration)
  @configuration = configuration
  @_options = {}
end

Instance Method Details

#config(command = nil, options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
# File 'lib/rc/dsl.rb', line 49

def config(command=nil, options={}, &block)
  nested_keys = @_options.keys & options.keys.map{|k| k.to_sym}
  raise ArgumentError, "nested #{nested_keys.join(', ')}" unless nested_keys.empty?

  options = @_options.merge(options)

  @configuration.config(command, options, &block)
end

#import(glob, opts = {}) ⇒ Object



16
17
18
# File 'lib/rc/dsl.rb', line 16

def import(glob, opts={})
  @configuration.import(glob, *opts)
end

#onload(feature, options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
68
# File 'lib/rc/dsl.rb', line 60

def onload(feature, options={}, &block)
  nested_keys = @_options.keys & options.keys.map{|k| k.to_sym}
  raise ArgumentError, "nested #{nested_keys.join(', ')}" unless nested_keys.empty?

  options = @_options.merge(options)
  options[:onload] = true

  @configuration.config(feature, options, &block)
end

#profile(name, state = {}, &block) ⇒ Object

Profile block.

Parameters:

  • name (String, Symbol)

    A profile name.

Raises:

  • (SyntaxError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/rc/dsl.rb', line 36

def profile(name, state={}, &block)
  raise SyntaxError, "nested profile sections" if @_options[:profile]
  original_state = @_options.dup
  @_options.update(state)
  @_options[:profile] = name.to_s

  instance_eval(&block)

  @_options = original_state
end