Class: DigitalOceanInventory::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/digital_ocean_inventory/group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, hosts = []) ⇒ Group

Returns a new instance of Group.



13
14
15
16
17
# File 'lib/digital_ocean_inventory/group.rb', line 13

def initialize(name, config, hosts = [])
  @name   = name
  @config = config
  @hosts  = hosts
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/digital_ocean_inventory/group.rb', line 3

def config
  @config
end

#hostsObject (readonly)

Returns the value of attribute hosts.



3
4
5
# File 'lib/digital_ocean_inventory/group.rb', line 3

def hosts
  @hosts
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/digital_ocean_inventory/group.rb', line 3

def name
  @name
end

Class Method Details

.build(opts = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/digital_ocean_inventory/group.rb', line 5

def self.build(opts = {})
  name   = opts[:name]
  config = opts[:config]
  hosts  = opts[:hosts] || []

  new name, config, hosts
end

Instance Method Details

#<<(host) ⇒ Object



19
20
21
22
23
# File 'lib/digital_ocean_inventory/group.rb', line 19

def <<(host)
  return host if hosts.include? host.name

  @hosts << host
end