Class: Cuboid::OptionGroups::Paths

Inherits:
Cuboid::OptionGroup show all
Defined in:
lib/cuboid/option_groups/paths.rb

Overview

Holds paths to the directories of various system components.

Author:

Constant Summary collapse

TMPDIR_SUFFIX =
'Cuboid_'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cuboid::OptionGroup

#==, attr_accessor, attributes, #attributes, defaults, #defaults, #hash, inherited, #merge, set_defaults, #to_h, #to_hash, #to_rpc_data, #update, #validate

Constructor Details

#initializePaths

Returns a new instance of Paths.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cuboid/option_groups/paths.rb', line 75

def initialize
    @root = self.root_path
    FileUtils.mkdir_p home_path

    @snapshots = self.config['snapshots'] || home_path + 'snapshots/'
    FileUtils.mkdir_p @snapshots

    @reports = self.config['reports'] || home_path + 'reports/'
    FileUtils.mkdir_p @reports

    if ENV['CUBOID_LOGDIR'].to_s != ''
        @logs = "#{ENV['CUBOID_LOGDIR']}/"
    elsif self.config['logs']
        @logs = self.config['logs']
    else
        @logs = "#{home_path}logs/"
        FileUtils.mkdir_p @logs
    end

    @lib         = @root    + 'lib/cuboid/'
    @executables = @lib     + 'processes/executables/'
    @support     = @lib     + 'support/'
    @mixins      = @support + 'mixins/'

    instance_variables.each do |iv|
        defaults[iv.to_s.sub( '@', '' ).to_sym] = instance_variable_get( iv )
    end

    tmpdir
end

Instance Attribute Details

#applicationObject

@return [String]



43
44
45
# File 'lib/cuboid/option_groups/paths.rb', line 43

def application
  @application
end

#componentsString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 57

#executablesString

Returns System processes (instance, agent, browser, etc.).

Returns:

  • (String)

    System processes (instance, agent, browser, etc.).



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cuboid/option_groups/paths.rb', line 75

def initialize
    @root = self.root_path
    FileUtils.mkdir_p home_path

    @snapshots = self.config['snapshots'] || home_path + 'snapshots/'
    FileUtils.mkdir_p @snapshots

    @reports = self.config['reports'] || home_path + 'reports/'
    FileUtils.mkdir_p @reports

    if ENV['CUBOID_LOGDIR'].to_s != ''
        @logs = "#{ENV['CUBOID_LOGDIR']}/"
    elsif self.config['logs']
        @logs = self.config['logs']
    else
        @logs = "#{home_path}logs/"
        FileUtils.mkdir_p @logs
    end

    @lib         = @root    + 'lib/cuboid/'
    @executables = @lib     + 'processes/executables/'
    @support     = @lib     + 'support/'
    @mixins      = @support + 'mixins/'

    instance_variables.each do |iv|
        defaults[iv.to_s.sub( '@', '' ).to_sym] = instance_variable_get( iv )
    end

    tmpdir
end

#libString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 48

#mixinsString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 54

#reportsString

Returns Report storage.

Returns:

  • (String)

    Report storage.



# File 'lib/cuboid/option_groups/paths.rb', line 63

#rootString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 45

#servicesString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 60

#snapshotsString

Returns Snapshot storage.

Returns:

  • (String)

    Snapshot storage.



# File 'lib/cuboid/option_groups/paths.rb', line 67

#supportString

Returns:

  • (String)


# File 'lib/cuboid/option_groups/paths.rb', line 51

Class Method Details

.clear_config_cacheObject



157
158
159
# File 'lib/cuboid/option_groups/paths.rb', line 157

def self.clear_config_cache
    @config = nil
end

.configObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/cuboid/option_groups/paths.rb', line 161

def self.config
    return @config if @config

    if !File.exist?( paths_config_file )
        @config = {}
    else
        @config = YAML.load( IO.read( paths_config_file ) )
    end

    @config.dup.each do |category, dir|
        if dir.to_s.empty?
            @config.delete( category )
            next
        end

        dir = Cuboid.get_long_win32_filename( dir )

        if !Cuboid.windows?
            dir.gsub!( '~', ENV['HOME'] )
        end

        dir << '/' if !dir.end_with?( '/' )

        @config[category] = dir

        FileUtils.mkdir_p dir
    end

    @config
end

.paths_config_fileObject



153
154
155
# File 'lib/cuboid/option_groups/paths.rb', line 153

def self.paths_config_file
    Cuboid.get_long_win32_filename "#{root_path}config/paths.yml"
end

.root_pathString

Returns Root path of the engine.

Returns:

  • (String)

    Root path of the engine.



116
117
118
# File 'lib/cuboid/option_groups/paths.rb', line 116

def self.root_path
    File.expand_path( File.dirname( __FILE__ ) + '/../../..' ) + '/'
end

Instance Method Details

#configObject



149
150
151
# File 'lib/cuboid/option_groups/paths.rb', line 149

def config
    self.class.config
end

#home_pathObject



106
107
108
# File 'lib/cuboid/option_groups/paths.rb', line 106

def home_path
    @home_path ||= "#{ENV['HOME']}/.cuboid/"
end

#os_tmpdirObject



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/cuboid/option_groups/paths.rb', line 120

def os_tmpdir
    return @os_tmpdir if @os_tmpdir

    if config['tmpdir'].to_s.empty?
        # On MS Windows Dir.tmpdir can return the path with a shortname,
        # better avoid that as it can be insonsistent with other paths.
        @os_tmpdir = Cuboid.get_long_win32_filename( Dir.tmpdir )
    else
        @os_tmpdir = Cuboid.get_long_win32_filename( config['tmpdir'] )
    end
end

#root_pathObject



110
111
112
# File 'lib/cuboid/option_groups/paths.rb', line 110

def root_path
    self.class.root_path
end

#tmp_dir_for(pid) ⇒ Object



145
146
147
# File 'lib/cuboid/option_groups/paths.rb', line 145

def tmp_dir_for( pid )
    "#{os_tmpdir}/#{TMPDIR_SUFFIX}#{pid}"
end

#tmpdirObject



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cuboid/option_groups/paths.rb', line 132

def tmpdir
    return @tmpdir if @tmpdir

    dir = tmp_dir_for( Process.pid )

    FileUtils.mkdir_p dir
    at_exit do
        FileUtils.rm_rf dir
    end

    @tmpdir = dir
end