class Tuya::Config

require 'singleton'

Constants

CONFIG_NAME

include Singleton

Attributes

file[RW]
file_path[RW]
group_name[RW]
path[RW]

Public Class Methods

config_file_path(user) click to toggle source
# 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) click to toggle source
# File lib/tycli/config.rb, line 10
def self.config_path(user)
        "/Users/#{user}/.tuya/"
end
local_config(user) click to toggle source
# 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
new(group_name) click to toggle source
# 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

Public Instance Methods

group_local() click to toggle source
# File lib/tycli/config.rb, line 74
def group_local

end
update_local_config() click to toggle source

create local file

# 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