Class: Statusboard::DSL::DSLBase

Inherits:
Object
  • Object
show all
Defined in:
lib/statusboard/dsl/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DSLBase

Default constructor. Executes the given block within its own context, so the block contents behave as a DSL.



35
36
37
# File 'lib/statusboard/dsl/base.rb', line 35

def initialize(&block)
	instance_eval &block
end

Class Method Details

.setter(*method_names) ⇒ Object

Automatically creates DSL-like setters for the specified fields. Fields must be specified as symbols.



7
8
9
10
11
12
13
# File 'lib/statusboard/dsl/base.rb', line 7

def self.setter(*method_names)
	method_names.each do |name|
		send :define_method, name do |data|
			instance_variable_set "@#{name}".to_sym, data 
		end
	end
end

.setter_with_default_value(method_name, default_value) ⇒ Object

Automatically creates a DSL-like setter for a specified field. If the setter is called by the *user without an argument*, the specified default value will be used as the value.

The method will NOT use the specified value as a default value for the field. If a default value is needed, the field should be set in the constructor.

Attributes

  • method_name - Name of the field for which a setter should be created

  • default_value - Default value of the argument which is used if the method is called without an argument



27
28
29
30
31
# File 'lib/statusboard/dsl/base.rb', line 27

def self.setter_with_default_value(method_name, default_value)
	send :define_method, method_name do |data = default_value|
		instance_variable_set "@#{method_name}".to_sym, data 
	end
end