Class: Hosum::Dsl
- Inherits:
-
Object
- Object
- Hosum::Dsl
- Defined in:
- lib/hosum/dsl.rb
Instance Attribute Summary collapse
-
#containers ⇒ Object
Returns the value of attribute containers.
-
#context ⇒ Object
Returns the value of attribute context.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#ips_list_scopes ⇒ Object
Returns the value of attribute ips_list_scopes.
Instance Method Summary collapse
- #containers_eval(object, &block) ⇒ Object
- #group(name, &block) ⇒ Object
- #hosts(*args, &block) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Dsl
constructor
A new instance of Dsl.
- #ip(*args, &block) ⇒ Object
- #subject(name, &block) ⇒ Object
- #to_dnsmasq(options = {}) ⇒ Object
- #to_hosts(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Dsl
Returns a new instance of Dsl.
9 10 11 12 13 14 15 16 |
# File 'lib/hosum/dsl.rb', line 9 def initialize( = {}, &block) self.groups = [] self.containers = [] self.ips_list_scopes = [] self.context = [:context] || [] instance_eval(&block) if block end |
Instance Attribute Details
#containers ⇒ Object
Returns the value of attribute containers.
5 6 7 |
# File 'lib/hosum/dsl.rb', line 5 def containers @containers end |
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/hosum/dsl.rb', line 6 def context @context end |
#groups ⇒ Object
Returns the value of attribute groups.
7 8 9 |
# File 'lib/hosum/dsl.rb', line 7 def groups @groups end |
#ips_list_scopes ⇒ Object
Returns the value of attribute ips_list_scopes.
5 6 7 |
# File 'lib/hosum/dsl.rb', line 5 def ips_list_scopes @ips_list_scopes end |
Instance Method Details
#containers_eval(object, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/hosum/dsl.rb', line 18 def containers_eval(object, &block) self.containers.push(object) instance_eval(&block) self.containers.pop end |
#group(name, &block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/hosum/dsl.rb', line 24 def group(name, &block) group = Group.new group.name = name self.groups << group containers_eval(group, &block) if block end |
#hosts(*args, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hosum/dsl.rb', line 59 def hosts(*args, &block) = args. container = self.containers.last hosts = Hosts.new hosts. = hosts.domains = [ args ].flatten hosts.parent = container container.children << hosts if !self.ips_list_scopes.empty? ips_list = self.ips_list_scopes.last hosts.ips_list = ips_list end containers_eval(hosts, &block) if block end |
#ip(*args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hosum/dsl.rb', line 32 def ip(*args, &block) = args. ips = Ips.new ips. = ips.addresses = [ args ].flatten if block self.ips_list_scopes << [ ips ] instance_eval(&block) self.ips_list_scopes.pop else self.containers.last.ips_list << ips end end |
#subject(name, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hosum/dsl.rb', line 48 def subject(name, &block) subject = Subject.new subject.name = name parent = self.containers.last parent.children << subject subject.parent = parent containers_eval(subject, &block) if block end |
#to_dnsmasq(options = {}) ⇒ Object
83 84 85 86 87 |
# File 'lib/hosum/dsl.rb', line 83 def to_dnsmasq( = {}) self.groups.map do |group| group.to_dnsmasq() end.join("\n\n") end |
#to_hosts(options = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/hosum/dsl.rb', line 77 def to_hosts( = {}) self.groups.map do |group| group.to_hosts() end.join("\n\n") end |