Module: HackBoxen

Defined in:
lib/hackboxen/utils.rb,
lib/hackboxen/template.rb,
lib/hackboxen/tasks/icss.rb,
lib/hackboxen/tasks/init.rb,
lib/hackboxen/utils/paths.rb,
lib/hackboxen/utils/logging.rb,
lib/hackboxen/tasks/endpoint.rb,
lib/hackboxen/utils/config_validator.rb

Defined Under Namespace

Modules: Logging, Paths Classes: ConfigValidator, Template

Class Method Summary collapse

Class Method Details

.coderootObject



43
44
45
# File 'lib/hackboxen/utils.rb', line 43

def self.coderoot
  WorkingConfig[:coderoot].gsub(/\/$/, '')
end

.currentObject



39
40
41
# File 'lib/hackboxen/utils.rb', line 39

def self.current
  hackbox_root? ? WorkingConfig[:namespace].gsub('.', '/') : Dir.pwd
end

.current_fsObject



30
31
32
33
# File 'lib/hackboxen/utils.rb', line 30

def self.current_fs
  fs = WorkingConfig[:filesystem_scheme] ? WorkingConfig[:filesystem_scheme] : 'file'
  Swineherd::FileSystem.get fs
end

.datarootObject



47
48
49
# File 'lib/hackboxen/utils.rb', line 47

def self.dataroot
  WorkingConfig[:dataroot].gsub(/\/$/, '')
end

.find_root_dirObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hackboxen/utils.rb', line 10

def self.find_root_dir
  start_dir = File.dirname INCLUDING_FILE
  Dir.chdir start_dir
  until hackbox_root? Dir.pwd
    Dir.chdir('..')
    if Dir.pwd == '/'
      puts "Warning: not in a Hackbox base directory"
      return start_dir
    end
  end
  return Dir.pwd
end

.hackbox_root?(dir = Dir.pwd) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/hackboxen/utils.rb', line 23

def self.hackbox_root? dir = Dir.pwd
  %w[ engine config Rakefile ].each do |expected|
    return false unless Dir.entries(dir).include? expected
  end
  true
end

.nameObject



35
36
37
# File 'lib/hackboxen/utils.rb', line 35

def self.name
  hackbox_root? ? Dir.pwd.gsub(/#{coderoot}\/#{current}\//, '') : 'debug'
end

.read_config(cfg) ⇒ Object



58
59
60
# File 'lib/hackboxen/utils.rb', line 58

def self.read_config cfg
  WorkingConfig.read cfg if current_fs.exists?(cfg)
end

.verify_dependenciesObject



52
53
54
55
56
# File 'lib/hackboxen/utils.rb', line 52

def self.verify_dependencies
  %w[ coderoot dataroot namespace ].each do |req|
    raise "Your hackbox config appears to be missing a [#{req}]" unless WorkingConfig[req.to_sym]
  end
end