Class: Dashbeautiful::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/dashbeautiful/network.rb

Overview

description TODO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organization, **attributes) ⇒ Network

Returns a new instance of Network.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/dashbeautiful/network.rb', line 36

def initialize(organization, **attributes)
  @organization = organization
  @id = attributes[:id]
  @name = attributes[:name]
  @tags = attributes[:tags]

  raise ArgumentError if @id.nil? || @name.nil? || @tags.nil?

  @tags = @tags.split.uniq
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/dashbeautiful/network.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/dashbeautiful/network.rb', line 4

def name
  @name
end

#organizationObject (readonly)

Returns the value of attribute organization.



4
5
6
# File 'lib/dashbeautiful/network.rb', line 4

def organization
  @organization
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/dashbeautiful/network.rb', line 4

def tags
  @tags
end

Class Method Details

.all(organization) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/dashbeautiful/network.rb', line 18

def self.all(organization)
  raise ArgumentError, 'must pass an Organization' if organization.nil?

  organization.networks
end

.create(*args, **kwargs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dashbeautiful/network.rb', line 6

def self.create(*args, **kwargs)
  type = case kwargs[:type]
         when 'camera' then CameraNetwork
         when 'switch' then SwitchNetwork
         when 'wireless' then WirelessNetwork
         when 'appliance' then ApplianceNetwork
         when 'combined' then CombinedNetwork
         else Network
         end
  type.new(*args, **kwargs)
end

.find(organization, &block) ⇒ Object



24
25
26
# File 'lib/dashbeautiful/network.rb', line 24

def self.find(organization, &block)
  all(organization).find(&block)
end

.find_by_id(id, organization) ⇒ Object



28
29
30
# File 'lib/dashbeautiful/network.rb', line 28

def self.find_by_id(id, organization)
  find(organization) { |network| network.id == id }
end

.find_by_name(name, organization) ⇒ Object



32
33
34
# File 'lib/dashbeautiful/network.rb', line 32

def self.find_by_name(name, organization)
  find(organization) { |network| network.name == name }
end

Instance Method Details

#devicesObject



47
48
49
# File 'lib/dashbeautiful/network.rb', line 47

def devices
  @devices ||= organization.api.devices(id).map { |device| Device.create(self, **device) }
end

#devices!Object



51
52
53
54
# File 'lib/dashbeautiful/network.rb', line 51

def devices!
  @devices = nil
  devices
end