Class: EasyChangelog::Configuration
- Inherits:
-
Object
- Object
- EasyChangelog::Configuration
- Defined in:
- lib/easy_changelog/configuration.rb
Constant Summary collapse
- CONFIG_PATHS =
%w[ ./.easy_changelog.rb ./config/initializers/easy_changelog.rb ./config/easy_changelog.rb ].freeze
Instance Attribute Summary collapse
-
#card_id_normalizer ⇒ Object
Returns the value of attribute card_id_normalizer.
-
#card_id_regex ⇒ Object
readonly
Returns the value of attribute card_id_regex.
-
#cards_url ⇒ Object
Returns the value of attribute cards_url.
-
#changelog_filename ⇒ Object
Returns the value of attribute changelog_filename.
-
#entries_order ⇒ Object
Returns the value of attribute entries_order.
-
#entries_path ⇒ Object
Returns the value of attribute entries_path.
-
#entry_path_format ⇒ Object
readonly
Returns the value of attribute entry_path_format.
-
#entry_row_format ⇒ Object
Returns the value of attribute entry_row_format.
-
#filename_max_length ⇒ Object
Returns the value of attribute filename_max_length.
-
#include_empty_card_id ⇒ Object
Returns the value of attribute include_empty_card_id.
-
#main_branch ⇒ Object
Returns the value of attribute main_branch.
- #release_message_template ⇒ Object
-
#repo_url ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#type_mapping ⇒ Object
Returns the value of attribute type_mapping.
-
#unreleased_header ⇒ Object
Returns the value of attribute unreleased_header.
-
#user_signature ⇒ Object
Returns the value of attribute user_signature.
Instance Method Summary collapse
- #card_regex=(value) ⇒ Object
- #changelog_types ⇒ Object
- #entry_path_match_regexp ⇒ Object
- #entry_path_template ⇒ Object
- #entry_row_match_regexp ⇒ Object
- #entry_row_template ⇒ Object
-
#initialize ⇒ Configuration
constructor
rubocop:disable Metrics/AbcSize.
- #load_config ⇒ Object
- #loose? ⇒ Boolean
- #sections ⇒ Object
Constructor Details
#initialize ⇒ Configuration
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/easy_changelog/configuration.rb', line 22 def initialize @entries_path = 'changelog/' @entries_order = :asc @changelog_filename = 'CHANGELOG.md' @main_branch = 'master' @entry_path_format = '<type>_<name>_<timestamp>.md' @entry_row_format = '* <ref>: <card_ref> <title> (<username>)' @unreleased_header = /## #{Regexp.escape("#{@main_branch} (unreleased)")}/m @user_signature = Regexp.new(format(Regexp.escape('[@%<user>s][]'), user: '([\w-]+)')) @filename_max_length = 50 @type_mapping = { breaking: { title: 'Breaking Changes', level: :major }, feature: { title: 'New features', level: :minor }, fix: { title: 'Bug fixes', level: :patch } } @include_empty_card_id = false @repo_url = ENV.fetch('REPOSITORY_URL', nil) @cards_url = ENV.fetch('CARDS_URL', nil) @card_id_regex = %r{(?<card_id>[^/]+)/(?:.+)} = -> { "## #{EasyChangelog::VERSION} (#{Date.today.iso8601})" } end |
Instance Attribute Details
#card_id_normalizer ⇒ Object
Returns the value of attribute card_id_normalizer.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def card_id_normalizer @card_id_normalizer end |
#card_id_regex ⇒ Object (readonly)
Returns the value of attribute card_id_regex.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def card_id_regex @card_id_regex end |
#cards_url ⇒ Object
Returns the value of attribute cards_url.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def cards_url @cards_url end |
#changelog_filename ⇒ Object
Returns the value of attribute changelog_filename.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def changelog_filename @changelog_filename end |
#entries_order ⇒ Object
Returns the value of attribute entries_order.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def entries_order @entries_order end |
#entries_path ⇒ Object
Returns the value of attribute entries_path.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def entries_path @entries_path end |
#entry_path_format ⇒ Object (readonly)
Returns the value of attribute entry_path_format.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def entry_path_format @entry_path_format end |
#entry_row_format ⇒ Object
Returns the value of attribute entry_row_format.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def entry_row_format @entry_row_format end |
#filename_max_length ⇒ Object
Returns the value of attribute filename_max_length.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def filename_max_length @filename_max_length end |
#include_empty_card_id ⇒ Object
Returns the value of attribute include_empty_card_id.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def include_empty_card_id @include_empty_card_id end |
#main_branch ⇒ Object
Returns the value of attribute main_branch.
8 9 10 |
# File 'lib/easy_changelog/configuration.rb', line 8 def main_branch @main_branch end |
#release_message_template ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/easy_changelog/configuration.rb', line 54 def raise ConfigurationError, 'release_message_template must be set' unless return unless .respond_to?(:call) = .call = "## #{message}" unless .start_with?('## ') end |
#repo_url ⇒ Object
rubocop:enable Metrics/AbcSize
48 49 50 51 52 |
# File 'lib/easy_changelog/configuration.rb', line 48 def repo_url raise ConfigurationError, 'repo_url must be set' unless @repo_url @repo_url end |
#type_mapping ⇒ Object
Returns the value of attribute type_mapping.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def type_mapping @type_mapping end |
#unreleased_header ⇒ Object
Returns the value of attribute unreleased_header.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def unreleased_header @unreleased_header end |
#user_signature ⇒ Object
Returns the value of attribute user_signature.
10 11 12 |
# File 'lib/easy_changelog/configuration.rb', line 10 def user_signature @user_signature end |
Instance Method Details
#card_regex=(value) ⇒ Object
64 65 66 67 68 |
# File 'lib/easy_changelog/configuration.rb', line 64 def card_regex=(value) raise ArgumentError, 'card_regex must be a Regexp' unless value.is_a?(Regexp) @card_regex = value end |
#changelog_types ⇒ Object
109 110 111 112 113 |
# File 'lib/easy_changelog/configuration.rb', line 109 def changelog_types return [] if @type_mapping == :loose @type_mapping.keys end |
#entry_path_match_regexp ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/easy_changelog/configuration.rb', line 121 def entry_path_match_regexp formula = @entry_path_format.gsub(/<(\w+)>/) do |match| matcher = match == '<type>' ? '[^_]' : '.' "(?#{match}#{matcher}+)" end Regexp.new("(?:#{entries_path})?#{formula}") end |
#entry_path_template ⇒ Object
130 131 132 |
# File 'lib/easy_changelog/configuration.rb', line 130 def entry_path_template File.join(entries_path, @entry_path_format.gsub(/<(\w+)>/) { |_match| "%<#{Regexp.last_match(1)}>s" }) end |
#entry_row_match_regexp ⇒ Object
134 135 136 137 138 139 |
# File 'lib/easy_changelog/configuration.rb', line 134 def entry_row_match_regexp with_optional_card_ref = Regexp.escape(@entry_row_format).gsub('<card_ref>\\ ') { |match| "(?:#{match})?" } formula = with_optional_card_ref.gsub(/<(\w+)>/) { |match| "(?#{match}.+)" } Regexp.new(formula) end |
#entry_row_template ⇒ Object
141 142 143 |
# File 'lib/easy_changelog/configuration.rb', line 141 def entry_row_template @entry_row_format.gsub(/<(\w+)>/) { |_match| "%<#{Regexp.last_match(1)}>s" } end |
#load_config ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/easy_changelog/configuration.rb', line 145 def load_config paths = CONFIG_PATHS.map { |file_path| File.(file_path) } path = paths.select { |file_path| File.exist?(file_path) }.first return unless path load(path) end |
#loose? ⇒ Boolean
99 100 101 |
# File 'lib/easy_changelog/configuration.rb', line 99 def loose? @type_mapping == :loose end |
#sections ⇒ Object
115 116 117 118 119 |
# File 'lib/easy_changelog/configuration.rb', line 115 def sections return [''] if @type_mapping == :loose @type_mapping.values.map { |v| v[:title] } end |