Class: Bwkfanboy::Home

Inherits:
Object
  • Object
show all
Defined in:
lib/bwkfanboy/home.rb

Constant Summary collapse

ROOT =

Home root directory

Pathname.new "#{Dir.home}/.#{Meta::NAME.downcase}"
PLUGINS =
'plugins'
LOGS =
'log'
SYSTEM_PLUGINS =
CliUtils::DIR_LIB_SRC.parent.parent + 'plugins'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = nil) ⇒ Home

Load config & create all required directories.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bwkfanboy/home.rb', line 19

def initialize dir = nil # yield loader, o
  @root = (dir && Pathname(dir)) || ROOT
  @logs = @root + LOGS
  
  CliConfig::DIR_CONFIG.unshift @root
  @conf = CliConfig.new
  @conf[:plugins_path] = [@root + PLUGINS, SYSTEM_PLUGINS]
  @conf.load do |o|
    yield self, o if block_given?
    o.on('-I DIR', 'Include DIR in search for plugins.') {|i|
      @conf[:plugins_path] << Pathname.new(i) if File.directory?(i)
    }
    o.on('--plugins-path', 'Print all searchable directories.') {
      print_plugins_path
      exit EX_OK
    }
  end
  
  print_env
  FileUtils.mkdir_p [@conf[:plugins_path], @logs]
end

Instance Attribute Details

#confObject

Returns the value of attribute conf.



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

def conf
  @conf
end

#logsObject (readonly)

Returns the value of attribute logs.



15
16
17
# File 'lib/bwkfanboy/home.rb', line 15

def logs
  @logs
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/bwkfanboy/home.rb', line 15

def root
  @root
end

Instance Method Details



45
46
47
48
49
50
# File 'lib/bwkfanboy/home.rb', line 45

def print_env
  if @conf[:verbose] >= 2
    puts "Libs dir: #{CliUtils::DIR_LIB_SRC}"
    pp @conf
  end
end


41
42
43
# File 'lib/bwkfanboy/home.rb', line 41

def print_plugins_path
  @conf[:plugins_path].each {|i| puts i }
end