Class: DRbQS::Config

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

Defined Under Namespace

Classes: Directory, SSHHost

Constant Summary collapse

DRBQS_CONFIG_DIRECTORY =
'.drbqs'
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
@@home_directory =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  home = self.class.get_home_directory
  @directory = DRbQS::Config::Directory.new(DRBQS_CONFIG_DIRECTORY, :home => home)
  @list = DRbQS::ProcessList.new(File.join(home, DRBQS_CONFIG_DIRECTORY))
  @ssh_host = DRbQS::Config::SSHHost.new(@directory.file_path(HOST_FILE_DIRECTORY))
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



52
53
54
# File 'lib/drbqs/config/config.rb', line 52

def directory
  @directory
end

#listObject (readonly)

Returns the value of attribute list.



52
53
54
# File 'lib/drbqs/config/config.rb', line 52

def list
  @list
end

#ssh_hostObject (readonly)

Returns the value of attribute ssh_host.



52
53
54
# File 'lib/drbqs/config/config.rb', line 52

def ssh_host
  @ssh_host
end

Class Method Details

.get_home_directoryObject



26
27
28
# File 'lib/drbqs/config/config.rb', line 26

def self.get_home_directory
  @@home_directory || ENV['HOME']
end

.set_home_directory(path) ⇒ Object



22
23
24
# File 'lib/drbqs/config/config.rb', line 22

def self.set_home_directory(path)
  @@home_directory = File.expand_path(path)
end

Instance Method Details

#directory_pathObject



61
62
63
# File 'lib/drbqs/config/config.rb', line 61

def directory_path
  @directory.directory
end

#get_acl_fileObject

Return path of ACL file if '.drbqs/acl.txt' exists.



78
79
80
# File 'lib/drbqs/config/config.rb', line 78

def get_acl_file
  @directory.exist?(ACL_DEFAULT_PATH)
end

#get_shell_file_directoryObject



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

def get_shell_file_directory
  @directory.file_path(SHELL_FILE_DIRECTORY)
end

#save_sampleObject



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

def save_sample
  @directory.open(ACL_SAMPLE_PATH, 'w') do |f|
    f.print ACL_SAMPLE
  end
  @directory.open(File.join(HOST_FILE_DIRECTORY, HOST_FILE_SAMPLE_PATH), 'w') do |f|
    f.print HOST_YAML_SAMPLE
  end
  @directory.open(File.join(SHELL_FILE_DIRECTORY, SHELL_BASHRC), 'w') do |f|
    f.print BASHRC_SAMPLE
  end
end