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.



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_idObject (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_idObject (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_uuidObject (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

#subtypeObject (readonly)

Returns the value of attribute subtype.



44
45
46
# File 'lib/ruby_home/identifier_cache.rb', line 44

def subtype
  @subtype
end

#uuidObject (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

.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



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_attributesObject



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