Class: Ngenie::Builder::BaseBuilder
Constant Summary
collapse
- DEFAULT_BIND =
'127.0.0.1'
- DEFAULT_PORT =
'80'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseBuilder.
8
9
10
11
12
|
# File 'lib/ngenie/builder/base_builder.rb', line 8
def initialize(name)
@name = name
@bind = DEFAULT_BIND
@port = DEFAULT_PORT
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/ngenie/builder/base_builder.rb', line 36
def method_missing(meth, *args, &blk)
name = meth.to_s
klass = class << self; self; end
klass.class_eval do
define_method(name) do |*args|
if !args.empty?
self.instance_variable_set(:"@#{name}", args.first)
else
self.instance_variable_get(:"@#{name}")
end
end
end
send(meth, *args, &blk)
end
|
Instance Attribute Details
#blueprint(template) ⇒ Object
Returns the value of attribute blueprint.
6
7
8
|
# File 'lib/ngenie/builder/base_builder.rb', line 6
def blueprint
@blueprint
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/ngenie/builder/base_builder.rb', line 6
def name
@name
end
|
Instance Method Details
#build(template = '') ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/ngenie/builder/base_builder.rb', line 18
def build(template='')
set_template(template)
File.open(File.join(Ngenie::CONFD_PATH, "#{name}.conf"), "w") do |f|
f.write("# GENERATED BY Ngenie. DO NOT EDIT\n#{render}\n".chomp)
f.close
end
end
|
#get_template(template) ⇒ Object
28
29
30
|
# File 'lib/ngenie/builder/base_builder.rb', line 28
def get_template(template)
File.read(File.join(Ngenie::TEMPLATE_PATH, "#{template}.#{self.template_extension}"))
end
|
#respond_to?(meth) ⇒ Boolean
54
55
56
|
# File 'lib/ngenie/builder/base_builder.rb', line 54
def respond_to?(meth)
meth != :has_key? ? true : super(meth)
end
|
#set_template(template) ⇒ Object
32
33
34
|
# File 'lib/ngenie/builder/base_builder.rb', line 32
def set_template(template)
self.template = @blueprint || get_template(template)
end
|