Class: Pigtail::Configs
- Inherits:
-
Object
- Object
- Pigtail::Configs
- Defined in:
- lib/pigtail/configs.rb
Instance Method Summary collapse
- #config_type(name, template) ⇒ Object
- #generate_configs_output ⇒ Object
-
#initialize(options) ⇒ Configs
constructor
A new instance of Configs.
- #set(variable, value) ⇒ Object
- #to(path, options = {}) ⇒ Object
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() @configs, @set_variables, @pre_set_variables = {}, {}, {}, {} if .is_a? String = { :string => } end pre_set([:set]) # setup_file = File.expand_path('../setup.rb', __FILE__) # setup = File.read(setup_file) pigtail_config = if [:string] [:string] elsif [:file] File.read([:file]) end # instance_eval(setup, setup_file) instance_eval(pigtail_config, [: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| = { :task => task, :template => template } .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()) end end end |
#generate_configs_output ⇒ Object
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, = {}) @current_path_scope = path @options = yield end |