Class: Dashbeautiful::Organization
- Inherits:
-
Object
- Object
- Dashbeautiful::Organization
- Defined in:
- lib/dashbeautiful/organization.rb
Overview
description TODO
Constant Summary collapse
- ATTRIBUTES =
%i[id name url].freeze
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .all(api_key, api: API.new(api_key)) ⇒ Object
- .find_by(attribute, value, api_key, api: API.new(api_key)) ⇒ Object
- .init(organization:, api_key:, api: API.new(api_key)) ⇒ Object
Instance Method Summary collapse
- #api_key ⇒ Object
-
#initialize(api, **attributes) ⇒ Organization
constructor
A new instance of Organization.
- #networks ⇒ Object
- #networks! ⇒ Object
Constructor Details
#initialize(api, **attributes) ⇒ Organization
Returns a new instance of Organization.
30 31 32 33 34 35 |
# File 'lib/dashbeautiful/organization.rb', line 30 def initialize(api, **attributes) @api = api @id = attributes[:id] @name = attributes[:name] @url = attributes[:url] end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
4 5 6 |
# File 'lib/dashbeautiful/organization.rb', line 4 def api @api end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/dashbeautiful/organization.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/dashbeautiful/organization.rb', line 5 def name @name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/dashbeautiful/organization.rb', line 5 def url @url end |
Class Method Details
.all(api_key, api: API.new(api_key)) ⇒ Object
9 10 11 12 13 |
# File 'lib/dashbeautiful/organization.rb', line 9 def self.all(api_key, api: API.new(api_key)) raise ArgumentError, 'api_key is nil. Either initialize Organization or pass a key' if api_key.nil? api.organizations.map { |org| Organization.new(api, **org) } end |
.find_by(attribute, value, api_key, api: API.new(api_key)) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/dashbeautiful/organization.rb', line 15 def self.find_by(attribute, value, api_key, api: API.new(api_key)) all(api_key, api: api).each do |org| return org if org.send(attribute) == value end nil end |
.init(organization:, api_key:, api: API.new(api_key)) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dashbeautiful/organization.rb', line 22 def self.init(organization:, api_key:, api: API.new(api_key)) ATTRIBUTES.each do |attribute| org = find_by(attribute, organization, api_key, api: api) return org unless org.nil? end raise ArgumentError, "Could not find organization: #{organization}" end |
Instance Method Details
#api_key ⇒ Object
42 43 44 |
# File 'lib/dashbeautiful/organization.rb', line 42 def api_key api.key end |
#networks ⇒ Object
46 47 48 |
# File 'lib/dashbeautiful/organization.rb', line 46 def networks @networks ||= api.networks(id).map { |network| Network.create(self, **network) } end |
#networks! ⇒ Object
50 51 52 53 |
# File 'lib/dashbeautiful/organization.rb', line 50 def networks! @networks = nil networks end |