Module: Koi

Defined in:
lib/koi.rb

Defined Under Namespace

Classes: Command, Database, Entity

Constant Summary collapse

Path =
{root: ".koi", db: ".koi/database.yml"}

Class Method Summary collapse

Class Method Details

.init(dir = Dir.pwd) ⇒ Object



10
11
12
13
14
15
# File 'lib/koi.rb', line 10

def self.init dir = Dir.pwd
  unless init?
    FileUtils.mkdir File.join(dir, Path[:root])
    FileUtils.touch File.join(dir, Path[:db])
  end
end

.init!(dir = Dir.pwd) ⇒ Object



17
18
19
20
# File 'lib/koi.rb', line 17

def self.init! dir = Dir.pwd
  FileUtils.rm_rf File.join(dir, Path[:root])
  init dir
end

.init?(dir = root) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.init? dir = root
  File.exist? File.join(dir, Path[:root]) if dir
end

.rootObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/koi.rb', line 36

def self.root
  path = Dir.pwd.split('/').reject {|d| d.empty? }
  (path.size + 1).times do
    if Koi.init? (sub = File.join('/', *path))
      return sub
    end
    path.pop
  end
  return nil
end

.run(*args) ⇒ Object



26
27
28
29
30
# File 'lib/koi.rb', line 26

def self.run *args
  cmd = Command.new(*args)
  cmd[:silent] = true
  cmd.run
end

.versionObject



32
33
34
# File 'lib/koi.rb', line 32

def self.version
  File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
end