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



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

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

#challenge_limitObject



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

def challenge_limit; @challenge_limit ||= 50; end

#locationObject



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

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

#primary_card_pathObject



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

def primary_card_path; @primary_card_path ||= card_paths[0]; end

#repoObject



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

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

Class Method Details

.open(path) ⇒ Object



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

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

.prepare_defaultObject



62
63
64
65
66
67
68
# File 'lib/ankit/runtime.rb', line 62

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/ankit/runtime.rb', line 41

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

#editor_backupObject



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

def editor_backup
  File.join(self.repo, "last_edited.txt")
end

#journalsObject



37
38
39
# File 'lib/ankit/runtime.rb', line 37

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

#primary_journalObject

Computed parameters



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

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