Class: RubyHome::IdentifierCache

Inherits:
Object
  • Object
show all
Includes:
Persistable
Defined in:
lib/ruby_home/identifier_cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistable

included, #reload, #save

Constructor Details

#initialize(accessory_id:, instance_id:, service_uuid: nil, subtype:, uuid:) ⇒ IdentifierCache

Returns a new instance of IdentifierCache.



40
41
42
43
44
45
46
# File 'lib/ruby_home/identifier_cache.rb', line 40

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_idObject (readonly)

Returns the value of attribute accessory_id.



48
49
50
# File 'lib/ruby_home/identifier_cache.rb', line 48

def accessory_id
  @accessory_id
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



48
49
50
# File 'lib/ruby_home/identifier_cache.rb', line 48

def instance_id
  @instance_id
end

#service_uuidObject (readonly)

Returns the value of attribute service_uuid.



48
49
50
# File 'lib/ruby_home/identifier_cache.rb', line 48

def service_uuid
  @service_uuid
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



48
49
50
# File 'lib/ruby_home/identifier_cache.rb', line 48

def subtype
  @subtype
end

#uuidObject (readonly)

Returns the value of attribute uuid.



48
49
50
# File 'lib/ruby_home/identifier_cache.rb', line 48

def uuid
  @uuid
end

Class Method Details

.allObject



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



20
21
22
# File 'lib/ruby_home/identifier_cache.rb', line 20

def self.create(**attributes)
  new(**attributes).save
end

.find_by(**attributes) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ruby_home/identifier_cache.rb', line 24

def self.find_by(**attributes)
  all.find do |identifier_cache|
    attributes.all? do |key, value|
      identifier_cache.send(key) == value
    end
  end
end

.reloadObject



16
17
18
# File 'lib/ruby_home/identifier_cache.rb', line 16

def self.reload
  @@_instance = nil
end

.where(**attributes) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ruby_home/identifier_cache.rb', line 32

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_attributesObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ruby_home/identifier_cache.rb', line 50

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