Module: Milkode::Dbdir

Defined in:
lib/milkode/common/dbdir.rb

Constant Summary collapse

@@milkode_db_dir =
File.expand_path('~/.milkode_db_dir')

Class Method Summary collapse

Class Method Details

.dbdir?(path = '.') ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/milkode/common/dbdir.rb', line 55

def dbdir?(path = '.')
  FileTest.exist? yaml_path(path)
end

.default_dirObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/milkode/common/dbdir.rb', line 31

def default_dir
  path = @@milkode_db_dir

  if (File.exist? path)
    File.read path
  elsif (ENV['MILKODE_DEFAULT_DIR'])
    File.expand_path ENV['MILKODE_DEFAULT_DIR']
  else
    File.expand_path '~/.milkode'
  end
end

.expand_groonga_path(path = '.') ⇒ Object



47
48
49
# File 'lib/milkode/common/dbdir.rb', line 47

def expand_groonga_path(path = '.')
  File.expand_path groonga_path(path)
end

.groonga_path(path = '.') ⇒ Object



43
44
45
# File 'lib/milkode/common/dbdir.rb', line 43

def groonga_path(path = '.')
  (Pathname.new(path) + 'db/milkode.db').to_s
end

.milkode_db_dirObject



16
17
18
# File 'lib/milkode/common/dbdir.rb', line 16

def milkode_db_dir
  @@milkode_db_dir
end

.select_dbdirObject



59
60
61
62
63
64
65
# File 'lib/milkode/common/dbdir.rb', line 59

def select_dbdir
  if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
    '.'
  else
    Dbdir.default_dir
  end
end

.set_milkode_db_dir(dir) ⇒ Object



20
21
22
# File 'lib/milkode/common/dbdir.rb', line 20

def set_milkode_db_dir(dir)
  @@milkode_db_dir = dir
end

.tmp_milkode_db_dir(path) ⇒ Object



24
25
26
27
28
29
# File 'lib/milkode/common/dbdir.rb', line 24

def tmp_milkode_db_dir(path)
  old_path = Dbdir.milkode_db_dir
  Dbdir.set_milkode_db_dir path
  yield
  Dbdir.set_milkode_db_dir old_path
end

.yaml_path(path = '.') ⇒ Object



51
52
53
# File 'lib/milkode/common/dbdir.rb', line 51

def yaml_path(path = '.')
  (Pathname.new(path) + 'milkode.yaml').to_s
end