Class: Pigtail::Configs

Inherits:
Object
  • Object
show all
Defined in:
lib/pigtail/configs.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configs

Returns a new instance of Configs.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pigtail/configs.rb', line 4

def initialize(options)
  @configs, @set_variables, @pre_set_variables = {}, {}, {}, {}

  if options.is_a? String
    options = { :string => options }
  end

  pre_set(options[:set])

  # setup_file     = File.expand_path('../setup.rb', __FILE__)
  # setup          = File.read(setup_file)
  pigtail_config =
    if options[:string]
      options[:string]
    elsif options[:file]
      File.read(options[:file])
    end

  # instance_eval(setup, setup_file)
  instance_eval(pigtail_config, options[:file] || '<eval>')
end

Instance Method Details

#config_type(name, template) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pigtail/configs.rb', line 41

def config_type(name, template)
  singleton_class_shim.class_eval do
    define_method(name) do |task, *args|
      options = { :task => task, :template => template }
      options.merge!(args[0]) if args[0].is_a? Hash

      @configs[@current_path_scope] ||= []
      @configs[@current_path_scope] << Pigtail::Config.new(@options.merge(@set_variables).merge(options))
    end
  end
end

#generate_configs_outputObject



53
54
55
# File 'lib/pigtail/configs.rb', line 53

def generate_configs_output
  output_configs
end

#set(variable, value) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/pigtail/configs.rb', line 26

def set(variable, value)
  variable = variable.to_sym
  return if @pre_set_variables[variable]

  instance_variable_set("@#{variable}".to_sym, value)
  self.class.send(:attr_reader, variable.to_sym)
  @set_variables[variable] = value
end

#to(path, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/pigtail/configs.rb', line 35

def to(path, options = {})
  @current_path_scope = path
  @options = options
  yield
end