Class: Ankit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ankit/runtime.rb

Constant Summary collapse

DEFAULT_PATH =
File.expand_path("~/.ankit")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#card_pathsObject



27
# File 'lib/ankit/runtime.rb', line 27

def card_paths; @card_paths ||= [File.join(repo, "cards")]; end

#locationObject



26
# File 'lib/ankit/runtime.rb', line 26

def location; @location ||= `hostname`.strip; end

#repoObject



25
# File 'lib/ankit/runtime.rb', line 25

def repo; @repo ||= File.expand_path("~/.ankit.d"); end

Class Method Details

.open(path) ⇒ Object



50
51
52
53
54
# File 'lib/ankit/runtime.rb', line 50

def self.open(path)
  config = self.new
  config.instance_eval(File.open(path){ |f| f.read })
  config
end

.prepare_defaultObject



56
57
58
59
60
61
62
# File 'lib/ankit/runtime.rb', line 56

def self.prepare_default
  FileUtils.touch([DEFAULT_PATH]) # TODO: Give same example settings.
  plain = Config.open(DEFAULT_PATH)
  (plain.card_paths + [plain.repo]).each { |p| FileUtils.mkdir_p(p) }
  FileUtils.touch([plain.primary_journal])
  STDOUT.print("Prepared the default setting. You can edit #{DEFAULT_PATH}\n")
end

Instance Method Details

#card_search_pathsObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/ankit/runtime.rb', line 38

def card_search_paths
  paths = self.card_paths.dup
  self.card_paths.each do |path|
    Dir.glob(File.join(path, "*")).each do |f|
      paths.push(f) if File.directory?(f)
    end
  end

  paths.sort
end

#journalsObject



34
35
36
# File 'lib/ankit/runtime.rb', line 34

def journals
  Dir.glob(File.join(repo, "*.journal")).sort
end

#primary_journalObject

Computed parameters



30
31
32
# File 'lib/ankit/runtime.rb', line 30

def primary_journal
  File.join(repo, "#{location}.journal")
end