Class: Doing::Changes
Overview
A collection of Changes
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#changes_only ⇒ Object
writeonly
Sets the attribute changes_only.
Instance Method Summary collapse
-
#initialize(lookup: nil, search: nil, changes: false, sort: :desc, prefix: false, only: %i[changed new improved fixed])) ⇒ Changes
constructor
A new instance of Changes.
- #interactive ⇒ Object
- #latest ⇒ Object
- #to_s ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(lookup: nil, search: nil, changes: false, sort: :desc, prefix: false, only: %i[changed new improved fixed])) ⇒ Changes
Returns a new instance of Changes.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/doing/changelog/changes.rb', line 9 def initialize(lookup: nil, search: nil, changes: false, sort: :desc, prefix: false, only: %i[changed new improved fixed]) @changes_only = changes @prefix = prefix @only = only changelog = File.(File.join(File.dirname(__FILE__), '..', '..', '..', 'CHANGELOG.md')) raise 'Error locating changelog' unless File.exist?(changelog) @content = IO.read(changelog) parse_changes(lookup, search) @changes.reverse! if sort == :asc end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
6 7 8 |
# File 'lib/doing/changelog/changes.rb', line 6 def changes @changes end |
#changes_only=(value) ⇒ Object (writeonly)
Sets the attribute changes_only
7 8 9 |
# File 'lib/doing/changelog/changes.rb', line 7 def changes_only=(value) @changes_only = value end |
Instance Method Details
#interactive ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/doing/changelog/changes.rb', line 34 def interactive Doing::Prompt.choose_from(versions, prompt: 'Select a version to see its changelog', sorted: false, fzf_args: [ %(--preview='doing changes --render -l {1}'), '--disabled', '--height=50', '--preview-window="right,70%"' ]) end |
#latest ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/doing/changelog/changes.rb', line 22 def latest if @changes_only @changes[0].changes_only.force_encoding('utf-8') else @changes[0].to_s.force_encoding('utf-8') end end |
#to_s ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/doing/changelog/changes.rb', line 46 def to_s if @changes_only @changes.map(&:changes_only).delete_if(&:empty?).join().gsub(/\n+/, "\n").force_encoding('utf-8') else @changes.map(&:to_s).join("\n\n").force_encoding('utf-8') end end |
#versions ⇒ Object
30 31 32 |
# File 'lib/doing/changelog/changes.rb', line 30 def versions @changes.select { |change| change.entries&.count > 0 }.map { |change| change.version } end |