Class: Hue::Config::Application

Inherits:
Abstract
  • Object
show all
Defined in:
lib/hue/config/application.rb

Constant Summary collapse

STRING_BRIDGE_ID =
'bridge_id'
STRING_DEFAULT =
'default'
STRING_ID =
'id'

Instance Attribute Summary collapse

Attributes inherited from Abstract

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#delete, #write

Constructor Details

#initialize(bridge_id, id, name = STRING_DEFAULT, path = self.class.file_path) ⇒ Application

Returns a new instance of Application.



30
31
32
33
34
# File 'lib/hue/config/application.rb', line 30

def initialize(bridge_id, id, name = STRING_DEFAULT, path = self.class.file_path)
  super(name, path)
  @bridge_id = bridge_id
  @id = id
end

Instance Attribute Details

#bridge_idObject (readonly)

Returns the value of attribute bridge_id.



28
29
30
# File 'lib/hue/config/application.rb', line 28

def bridge_id
  @bridge_id
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/hue/config/application.rb', line 28

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/hue/config/application.rb', line 28

def name
  @name
end

Class Method Details

.defaultObject



13
14
15
# File 'lib/hue/config/application.rb', line 13

def self.default
  named(STRING_DEFAULT)
end

.file_pathObject



9
10
11
# File 'lib/hue/config/application.rb', line 9

def self.file_path
  File.join(ENV['HOME'], ".#{Hue.device_type}", 'applications.yml')
end

.named(name) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/hue/config/application.rb', line 17

def self.named(name)
  yaml = read_file(file_path)
  if yaml && named_yaml = yaml[name]
    new(named_yaml[STRING_BRIDGE_ID], named_yaml[STRING_ID], name)
  else
    raise NotFound.new("Config named '#{name}' not found.")
  end
end

Instance Method Details

#==(rhs) ⇒ Object



36
37
38
39
40
# File 'lib/hue/config/application.rb', line 36

def ==(rhs)
  super(rhs) &&
    self.bridge_id == rhs.bridge_id &&
    self.id == rhs.id
end