Module: Filecon

Defined in:
lib/filecon.rb,
lib/filecon/version.rb

Defined Under Namespace

Classes: App

Constant Summary collapse

PATH =
File.join(ENV["HOME"], ".config/filecon/")
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.cmd_history_pathObject



20
21
22
# File 'lib/filecon.rb', line 20

def self.cmd_history_path
  File.join(PATH, "cmd_history")
end

.configObject



42
43
44
45
46
47
48
49
# File 'lib/filecon.rb', line 42

def self.config
  config_path = File.join(PATH, "config.yaml")
  if File.exist?(config_path)
    deep_symbolize_keys(YAML.safe_load(File.read(config_path), permitted_classes: [Symbol]))
  else
    {}
  end
end

.deep_symbolize_keys(obj) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/filecon.rb', line 31

def self.deep_symbolize_keys(obj)
  case obj
  when Hash
    obj.each_with_object({}) { |(k, v), h| h[k.to_sym] = deep_symbolize_keys(v) }
  when Array
    obj.map { |v| deep_symbolize_keys(v) }
  else
    obj
  end
end

.dir_history_pathObject



16
17
18
# File 'lib/filecon.rb', line 16

def self.dir_history_path
  File.join(PATH, "dir_history")
end

.setup_configObject



24
25
26
27
28
29
# File 'lib/filecon.rb', line 24

def self.setup_config
  FileUtils.mkpath PATH unless File.exist? PATH
  FileUtils.cp File.join(__dir__, "../config.yaml"), PATH unless File.exist? File.join(PATH, "config.yaml")
  FileUtils.touch dir_history_path
  FileUtils.touch cmd_history_path
end