Class: Dashbeautiful::Network
- Inherits:
-
Object
- Object
- Dashbeautiful::Network
- Defined in:
- lib/dashbeautiful/network.rb
Overview
description TODO
Direct Known Subclasses
ApplianceNetwork, CameraNetwork, CombinedNetwork, SwitchNetwork, WirelessNetwork
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
- .all(organization) ⇒ Object
- .create(*args, **kwargs) ⇒ Object
- .find(organization, &block) ⇒ Object
- .find_by_id(id, organization) ⇒ Object
- .find_by_name(name, organization) ⇒ Object
Instance Method Summary collapse
- #devices ⇒ Object
- #devices! ⇒ Object
-
#initialize(organization, **attributes) ⇒ Network
constructor
A new instance of Network.
Constructor Details
#initialize(organization, **attributes) ⇒ Network
Returns a new instance of Network.
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/dashbeautiful/network.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/dashbeautiful/network.rb', line 4 def name @name end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
4 5 6 |
# File 'lib/dashbeautiful/network.rb', line 4 def organization @organization end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
4 5 6 |
# File 'lib/dashbeautiful/network.rb', line 4 def @tags end |
Class Method Details
.all(organization) ⇒ Object
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
#devices ⇒ Object
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 |