Class: RubyHome::IdentifierCache
- Inherits:
-
Object
- Object
- RubyHome::IdentifierCache
- Includes:
- Persistable
- Defined in:
- lib/ruby_home/identifier_cache.rb
Instance Attribute Summary collapse
-
#accessory_id ⇒ Object
readonly
Returns the value of attribute accessory_id.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#service_uuid ⇒ Object
readonly
Returns the value of attribute service_uuid.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
- .all ⇒ Object
- .create(**attributes) ⇒ Object
- .find_by(**attributes) ⇒ Object
- .where(**attributes) ⇒ Object
Instance Method Summary collapse
-
#initialize(accessory_id:, instance_id:, service_uuid: nil, subtype:, uuid:) ⇒ IdentifierCache
constructor
A new instance of IdentifierCache.
- #persisted_attributes ⇒ Object
Methods included from Persistable
Constructor Details
#initialize(accessory_id:, instance_id:, service_uuid: nil, subtype:, uuid:) ⇒ IdentifierCache
Returns a new instance of IdentifierCache.
36 37 38 39 40 41 42 |
# File 'lib/ruby_home/identifier_cache.rb', line 36 def initialize(accessory_id:, instance_id:, service_uuid: nil, subtype: , uuid: ) @accessory_id = accessory_id @instance_id = instance_id @subtype = subtype @service_uuid = service_uuid @uuid = uuid end |
Instance Attribute Details
#accessory_id ⇒ Object (readonly)
Returns the value of attribute accessory_id.
44 45 46 |
# File 'lib/ruby_home/identifier_cache.rb', line 44 def accessory_id @accessory_id end |
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
44 45 46 |
# File 'lib/ruby_home/identifier_cache.rb', line 44 def instance_id @instance_id end |
#service_uuid ⇒ Object (readonly)
Returns the value of attribute service_uuid.
44 45 46 |
# File 'lib/ruby_home/identifier_cache.rb', line 44 def service_uuid @service_uuid end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
44 45 46 |
# File 'lib/ruby_home/identifier_cache.rb', line 44 def subtype @subtype end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
44 45 46 |
# File 'lib/ruby_home/identifier_cache.rb', line 44 def uuid @uuid end |
Class Method Details
.all ⇒ Object
9 10 11 12 13 14 |
# File 'lib/ruby_home/identifier_cache.rb', line 9 def self.all raw_items = read || [] raw_items.map do |raw_item| new(**raw_item) end end |
.create(**attributes) ⇒ Object
16 17 18 |
# File 'lib/ruby_home/identifier_cache.rb', line 16 def self.create(**attributes) new(**attributes).save end |
.find_by(**attributes) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ruby_home/identifier_cache.rb', line 20 def self.find_by(**attributes) all.find do |identifier_cache| attributes.all? do |key, value| identifier_cache.send(key) == value end end end |
.where(**attributes) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ruby_home/identifier_cache.rb', line 28 def self.where(**attributes) all.select do |identifier_cache| attributes.all? do |key, value| identifier_cache.send(key) == value end end end |
Instance Method Details
#persisted_attributes ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby_home/identifier_cache.rb', line 46 def persisted_attributes existing_items = self.class.all existing_items << self existing_items.map do |identifier| { accessory_id: identifier.accessory_id, instance_id: identifier.instance_id, subtype: identifier.subtype, service_uuid: identifier.service_uuid, uuid: identifier.uuid, } end end |