Class: Tuya::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/cli/odm/config.rb

Overview

require ‘singleton’

Constant Summary collapse

CONFIG_NAME =

include Singleton

'tuya-cli-public.json'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_name) ⇒ Config

Returns a new instance of Config.



46
47
48
49
50
51
52
53
54
55
# File 'lib/tuya/cli/odm/config.rb', line 46

def initialize(group_name)

	@group_name = group_name
	@system = Tuya::System.instance

	@path = Tuya::Config.config_path @system.user
	@file = CONFIG_NAME
	@file_path = Tuya::Config.config_file_path @system.user

end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



41
42
43
# File 'lib/tuya/cli/odm/config.rb', line 41

def file
  @file
end

#file_pathObject

Returns the value of attribute file_path.



42
43
44
# File 'lib/tuya/cli/odm/config.rb', line 42

def file_path
  @file_path
end

#group_nameObject

Returns the value of attribute group_name.



43
44
45
# File 'lib/tuya/cli/odm/config.rb', line 43

def group_name
  @group_name
end

#pathObject

Returns the value of attribute path.



40
41
42
# File 'lib/tuya/cli/odm/config.rb', line 40

def path
  @path
end

Class Method Details

.config_file_path(user) ⇒ Object



19
20
21
22
23
# File 'lib/tuya/cli/odm/config.rb', line 19

def self.config_file_path(user)
	path = config_path user
	file = CONFIG_NAME
	"#{path}#{file}"
end

.config_path(user) ⇒ Object



15
16
17
# File 'lib/tuya/cli/odm/config.rb', line 15

def self.config_path(user)
	"#{user}/.tuya/"
end

.local_config(user) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tuya/cli/odm/config.rb', line 25

def self.local_config(user)
	path = config_path user
	file = CONFIG_NAME
	file_path = config_file_path user

	if File.exist? file_path
		config_string = File.read(file_path)

		require 'json'
		content = JSON.parse(config_string)

		Tuya::ConfigGroup.new content['group']
	end
end

Instance Method Details

#group_localObject



77
78
79
# File 'lib/tuya/cli/odm/config.rb', line 77

def group_local

end

#update_local_configObject

create local file



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tuya/cli/odm/config.rb', line 58

def update_local_config

	require 'json'

	`mkdir -p #{@path}`

	group_hash = Hash["group"=>@group_name]
	group_json = JSON group_hash

	if File.exist?@file_path
		`rm #{file_path}`
	end

	fh = File.new(@file_path, 'w')
	fh.puts group_json
	fh.close

end