Module: Asbestos

Defined in:
lib/asbestos.rb,
lib/asbestos/address.rb,
lib/asbestos/service.rb,
lib/asbestos/metadata.rb

Defined Under Namespace

Modules: ClassCollection, Firewall Classes: Address, Host, HostTemplate, RuleSet, Service

Constant Summary collapse

VERSION =
"0.0.9"
HOMEPAGE =
"http://www.github.com/koudelka/asbestos"

Class Method Summary collapse

Class Method Details

.firewallObject



28
29
30
31
32
33
34
35
36
# File 'lib/asbestos.rb', line 28

def self.firewall
  case os
    when :linux
      Asbestos::Firewall::IPTables
    when :darwin
      #FIXME
      Asbestos::Firewall::IPTables
  end
end

.hostnameObject



11
12
13
# File 'lib/asbestos.rb', line 11

def self.hostname
  Socket.gethostname[/[^.]*/]
end

.interfacesObject



15
16
17
# File 'lib/asbestos.rb', line 15

def self.interfaces
  System.get_ifaddrs
end

.osObject



19
20
21
22
23
24
25
26
# File 'lib/asbestos.rb', line 19

def self.os
  case
    when RUBY_PLATFORM[/linux/i]
      :linux
    when RUBY_PLATFORM[/darwin/i]
      :darwin
  end
end

.reset!Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/asbestos.rb', line 38

def self.reset!
  [
    Host.all,
    Host.groups,
    HostTemplate.all,
    Address.all,
    RuleSet.all,
    Service.all,
  ].each do |collection|
    collection.delete_if {|_| true}
  end
end

.with_indifferent_access!(hash) ⇒ Object

Didn’t want to monkeypatch the Hash class.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/asbestos.rb', line 54

def self.with_indifferent_access!(hash)
  class << hash
    def [](key)
      fetch key.to_sym
    rescue KeyError # key not found
      nil
    end

    def []=(key, value)
      store key.to_sym, value
    end
  end
end