Class: DRbQS::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/config.rb

Constant Summary collapse

ACL_SAMPLE =
<<SAMPLE
deny all
allow localhost
allow 127.0.0.1
SAMPLE
HOST_YAML_SAMPLE =
<<SAMPLE
--- 
:dest: [email protected]
:dir:
:shell: bash --noprofile --init-file ~/.drbqs/shell/bashrc
:rvm:
:rvm_init: ~/.rvm/scripts/rvm
:output: 
SAMPLE
BASHRC_SAMPLE =
<<SAMPLE
HISTFILE=$HOME/.drbqs/shell/bash_history
HISTSIZE=10000
HISTFILESIZE=20000
SAMPLE
@@data =
{
  :dir => ENV['HOME'] + '/.drbqs/',
}

Class Method Summary collapse

Class Method Details

.check_directory_createObject



65
66
67
68
69
70
71
72
73
# File 'lib/drbqs/config.rb', line 65

def check_directory_create
  unless File.exist?(@@data[:dir])
    FileUtils.mkdir_p(@@data[:dir])
    FileUtils.chmod(0700, @@data[:dir])
  end
  [get_host_file_directory, get_shell_file_directory].each do |dir|
    make_directory(dir)
  end
end

.get_acl_fileObject



88
89
90
91
92
93
94
# File 'lib/drbqs/config.rb', line 88

def get_acl_file
  path = File.join(@@data[:dir], ACL_DEFAULT_PATH)
  if File.exist?(path)
    return path
  end
  return nil
end

.get_host_file_directoryObject



50
51
52
# File 'lib/drbqs/config.rb', line 50

def get_host_file_directory
  get_path(HOST_FILE_DIRECTORY)
end

.get_path(name) ⇒ Object



41
42
43
# File 'lib/drbqs/config.rb', line 41

def get_path(name)
  File.join(@@data[:dir], name)
end

.get_shell_file_directoryObject



54
55
56
# File 'lib/drbqs/config.rb', line 54

def get_shell_file_directory
  get_path(SHELL_FILE_DIRECTORY)
end

.make_directory(dir) ⇒ Object



58
59
60
61
62
# File 'lib/drbqs/config.rb', line 58

def make_directory(dir)
  unless File.exist?(dir)
    FileUtils.mkdir_p(dir)
  end
end

.output_to_file(path, content) ⇒ Object



75
76
77
78
79
# File 'lib/drbqs/config.rb', line 75

def output_to_file(path, content)
  unless File.exist?(path)
    open(path, 'w') { |f| f.print content }
  end
end

.save_sampleObject



82
83
84
85
86
# File 'lib/drbqs/config.rb', line 82

def save_sample
  output_to_file(get_path(ACL_SAMPLE_PATH), ACL_SAMPLE)
  output_to_file("#{get_host_file_directory}/#{HOST_FILE_SAMPLE_PATH}", HOST_YAML_SAMPLE)
  output_to_file("#{get_shell_file_directory}/#{SHELL_BASHRC}", BASHRC_SAMPLE)
end

.set_directory(dir) ⇒ Object



46
47
48
# File 'lib/drbqs/config.rb', line 46

def set_directory(dir)
  @@data[:dir] = dir
end