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
Class Method Summary collapse
Instance Method Summary collapse
- #card_search_paths ⇒ Object
- #journals ⇒ Object
-
#primary_journal ⇒ Object
Computed parameters.
Instance Attribute Details
#card_paths ⇒ Object
27 |
# File 'lib/ankit/runtime.rb', line 27 def card_paths; @card_paths ||= [File.join(repo, "cards")]; end |
#location ⇒ Object
26 |
# File 'lib/ankit/runtime.rb', line 26 def location; @location ||= `hostname`.strip; end |
#repo ⇒ Object
25 |
# File 'lib/ankit/runtime.rb', line 25 def repo; @repo ||= File.("~/.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_default ⇒ Object
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_paths ⇒ Object
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 |
#journals ⇒ Object
34 35 36 |
# File 'lib/ankit/runtime.rb', line 34 def journals Dir.glob(File.join(repo, "*.journal")).sort end |
#primary_journal ⇒ Object
Computed parameters
30 31 32 |
# File 'lib/ankit/runtime.rb', line 30 def primary_journal File.join(repo, "#{location}.journal") end |