Module: Textbringer::Recentf
- Defined in:
- lib/textbringer/recentf.rb,
lib/textbringer/recentf/version.rb
Constant Summary collapse
- VERSION =
"1"
Class Attribute Summary collapse
-
.last_added ⇒ Object
Returns the value of attribute last_added.
Class Method Summary collapse
- .add(path) ⇒ Object
- .cleanup ⇒ Object
- .exclude_patterns ⇒ Object
- .file_path ⇒ Object
- .load ⇒ Object
- .max_items ⇒ Object
- .save(list) ⇒ Object
Class Attribute Details
.last_added ⇒ Object
Returns the value of attribute last_added.
17 18 19 |
# File 'lib/textbringer/recentf.rb', line 17 def last_added @last_added end |
Class Method Details
.add(path) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/textbringer/recentf.rb', line 42 def add(path) return if path.nil? || path.empty? path = File.(path) return if exclude_patterns.any? { |pat| pat.match?(path) } return if path == last_added list = load list.delete(path) list.unshift(path) save(list) self.last_added = path end |
.cleanup ⇒ Object
55 56 57 58 59 |
# File 'lib/textbringer/recentf.rb', line 55 def cleanup list = load.select { |f| File.exist?(f) } save(list) list.size end |
.exclude_patterns ⇒ Object
27 28 29 |
# File 'lib/textbringer/recentf.rb', line 27 def exclude_patterns CONFIG[:recentf_exclude_patterns] end |
.file_path ⇒ Object
19 20 21 |
# File 'lib/textbringer/recentf.rb', line 19 def file_path File.(CONFIG[:recentf_file]) end |
.load ⇒ Object
31 32 33 34 |
# File 'lib/textbringer/recentf.rb', line 31 def load return [] unless File.exist?(file_path) File.readlines(file_path, chomp: true) end |
.max_items ⇒ Object
23 24 25 |
# File 'lib/textbringer/recentf.rb', line 23 def max_items CONFIG[:recentf_max_items] end |
.save(list) ⇒ Object
36 37 38 39 40 |
# File 'lib/textbringer/recentf.rb', line 36 def save(list) dir = File.dirname(file_path) FileUtils.mkdir_p(dir) unless File.directory?(dir) File.write(file_path, list.take(max_items).join("\n") + "\n") end |