Class: Tuya::Config
- Inherits:
-
Object
- Object
- Tuya::Config
- Defined in:
- lib/tycli/config.rb
Overview
require ‘singleton’
Constant Summary collapse
- CONFIG_NAME =
include Singleton
'tuya-cli-public.json'
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#group_name ⇒ Object
Returns the value of attribute group_name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #group_local ⇒ Object
-
#initialize(group_name) ⇒ Config
constructor
A new instance of Config.
-
#update_local_config ⇒ Object
create local file.
Constructor Details
#initialize(group_name) ⇒ Config
Returns a new instance of Config.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tycli/config.rb', line 41 def initialize(group_name) require 'tycli/system' @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
#file ⇒ Object
Returns the value of attribute file.
36 37 38 |
# File 'lib/tycli/config.rb', line 36 def file @file end |
#file_path ⇒ Object
Returns the value of attribute file_path.
37 38 39 |
# File 'lib/tycli/config.rb', line 37 def file_path @file_path end |
#group_name ⇒ Object
Returns the value of attribute group_name.
38 39 40 |
# File 'lib/tycli/config.rb', line 38 def group_name @group_name end |
#path ⇒ Object
Returns the value of attribute path.
35 36 37 |
# File 'lib/tycli/config.rb', line 35 def path @path end |
Class Method Details
.config_file_path(user) ⇒ Object
14 15 16 17 18 |
# File 'lib/tycli/config.rb', line 14 def self.config_file_path(user) path = config_path user file = CONFIG_NAME "#{path}#{file}" end |
.config_path(user) ⇒ Object
10 11 12 |
# File 'lib/tycli/config.rb', line 10 def self.config_path(user) "/Users/#{user}/.tuya/" end |
.local_config(user) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tycli/config.rb', line 20 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_local ⇒ Object
74 75 76 |
# File 'lib/tycli/config.rb', line 74 def group_local end |
#update_local_config ⇒ Object
create local file
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tycli/config.rb', line 55 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 |