class Schmersion::Formatters::YAML
Constants
- DEFAULT_STRUCTURE
Public Instance Methods
generate(_, version)
click to toggle source
# File lib/schmersion/formatters/yaml.rb, line 12 def generate(_, version) commits = version.commits.sort_by { |c| c.message.description.upcase } commits = commits.each_with_object([]) do |commit, array| next unless include_type?(commit.message.type) array << commit_to_hash(commit) end { 'version' => version.version.to_s, 'commits' => commits }.to_yaml end
insert(part)
click to toggle source
# File lib/schmersion/formatters/yaml.rb, line 27 def insert(part) unless File.file?(@filename) File.write(@filename, DEFAULT_STRUCTURE) end part_as_hash = ::YAML.safe_load(part) existing_yaml = ::YAML.load_file(@filename) existing_yaml = [] unless existing_yaml.is_a?(Array) existing_yaml.prepend(part_as_hash) File.write(@filename, existing_yaml.to_yaml) end
Private Instance Methods
commit_to_hash(commit)
click to toggle source
# File lib/schmersion/formatters/yaml.rb, line 41 def commit_to_hash(commit) { 'ref' => commit.ref, 'date' => commit.date.to_s, 'type' => commit.message.type, 'scope' => commit.message.scope, 'description' => commit.message.description, 'breaking_change' => commit.message.breaking_change?, 'breaking_changes' => commit.message.breaking_changes, 'pull_request_id' => commit.message.pull_request_id, 'footers' => commit.message.footers } end
include_type?(type)
click to toggle source
# File lib/schmersion/formatters/yaml.rb, line 55 def include_type?(type) return true if @options[:types].nil? @options[:types].include(type.to_s) end