Class: Ankit::Config
- Inherits:
-
Object
- Object
- Ankit::Config
- Defined in:
- lib/ankit/runtime.rb
Constant Summary collapse
- DEFAULT_PATH =
File.("~/.ankit")
Instance Attribute Summary collapse
- #card_paths ⇒ Object
- #challenge_limit ⇒ Object
- #location ⇒ Object
- #primary_card_path ⇒ Object
- #repo ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #card_search_paths ⇒ Object
- #editor_backup ⇒ Object
- #journals ⇒ Object
-
#primary_journal ⇒ Object
Computed parameters.
Instance Attribute Details
#card_paths ⇒ Object
28 |
# File 'lib/ankit/runtime.rb', line 28 def card_paths; @card_paths ||= [File.join(repo, "cards")]; end |
#challenge_limit ⇒ Object
30 |
# File 'lib/ankit/runtime.rb', line 30 def challenge_limit; @challenge_limit ||= 50; end |
#location ⇒ Object
27 |
# File 'lib/ankit/runtime.rb', line 27 def location; @location ||= `hostname`.strip; end |
#primary_card_path ⇒ Object
29 |
# File 'lib/ankit/runtime.rb', line 29 def primary_card_path; @primary_card_path ||= card_paths[0]; end |
#repo ⇒ Object
26 |
# File 'lib/ankit/runtime.rb', line 26 def repo; @repo ||= File.("~/.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_default ⇒ Object
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_paths ⇒ Object
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_backup ⇒ Object
52 53 54 |
# File 'lib/ankit/runtime.rb', line 52 def editor_backup File.join(self.repo, "last_edited.txt") end |
#journals ⇒ Object
37 38 39 |
# File 'lib/ankit/runtime.rb', line 37 def journals Dir.glob(File.join(repo, "*.journal")).sort end |
#primary_journal ⇒ Object
Computed parameters
33 34 35 |
# File 'lib/ankit/runtime.rb', line 33 def primary_journal File.join(repo, "#{location}.journal") end |