Module: Allages
- Defined in:
- lib/allages.rb,
lib/allages/config.rb,
lib/allages/railtie.rb,
lib/allages/version.rb,
lib/generators/init_generator.rb,
lib/generators/yaml_generator.rb
Defined Under Namespace
Classes: Configuration, Error, InitGenerator, Railtie, YamlGenerator
Constant Summary
collapse
- META_TEMPLATE =
<<~META
# date: #{Time.now.strftime('%F')}
# dependencies:
# - dependency 1
# - dependency 2
META
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
7
8
9
|
# File 'lib/allages/config.rb', line 7
def self.config
@config
end
|
3
4
5
|
# File 'lib/allages/config.rb', line 3
def self.configure(&block)
yield @config ||= Allages::Configuration.new
end
|
.generate ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/allages.rb', line 16
def generate
sections = []
Dir.glob("#{Allages.config.input_dir}/*").each do |filename|
if File.directory? filename
section = {}
dir = File.basename filename
next if (dir == "Unreleased" && Allages.config.include_unreleased == false)
section[:name] = dir
if File.file? "#{filename}/.meta.yml"
section[:meta] = YAML.load_file "#{filename}/.meta.yml"
end
categories = {}
Dir.glob("#{filename}/*.yml").each do |entry_filename|
next if entry_filename.match? /\.meta\.yml/
entry = YAML.load_file entry_filename
if categories.has_key? entry['type']
categories[entry['type']] << entry
else
categories[entry['type']] = [entry]
end
end
section[:categories] = categories
sections << section
end
end
sections.sort! do |a, b|
if a[:name] == "Unreleased"
-1
elsif b[:name] == "Unreleased"
1
else
a[:name] <=> b[:name]
end
end
markdown = "#{Allages.config.}"
had_previous_section = false
sections.each do |section|
markdown << "\n" if had_previous_section
had_previous_section = true
title = ["## #{section[:name]}"]
if section[:meta]
title << section[:meta]['date'] if section[:meta]['date']
title << "dependencies: #{section[:meta]['dependencies'].to_a.join(', ')}" unless section[:meta]['dependencies'].to_a.empty?
end
markdown << "#{title.join(' - ')}" << "\n"
section[:categories].each do |category, entries|
markdown << "### #{category}\n"
entries.each do |entry|
entry_md = [entry['description']]
entry_md << "issue: #{entry['issue']}" if entry['issue']
entry_md << "dependencies: #{entry['dependencies'].to_a.join(', ')}" unless entry['dependencies'].to_a.empty?
markdown << "- #{entry_md.join(', ')}\n"
end
end
end
if Allages.config.output_file.to_sym == :stdout
puts markdown
else
open(Allages.config.output_file, 'w') do |f|
f.puts markdown
end
end
end
|
.new_entry ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/allages.rb', line 112
def new_entry
types = {
"a" => "Added",
"c" => "Changed",
"f" => "Fixed",
"d" => "Deprecated",
"r" => "Removed",
"s" => "Security"
}
print "Type (a)dded, (c)hanged, (f)ixed, (d)eprecated, (r)emoved, (s)ecurity: "
STDOUT.flush
type = types[STDIN.gets.chomp]
print "Description: "
STDOUT.flush
description = STDIN.gets.chomp
print "Author: "
STDOUT.flush
author = STDIN.gets.chomp
print "Issue: "
STDOUT.flush
issue = STDIN.gets.chomp
print "Dependencies (comma seperated): "
STDOUT.flush
deps = STDIN.gets.chomp.split(',').map{|d| " - #{d.chomp.lstrip}"}.join("\n")
yaml = <<~YAML
date: #{Time.now.strftime('%F')}
type: #{type}
description: #{description}
author: #{author}
issue: #{issue}
dependencies:
#{deps}
YAML
filename = "#{SecureRandom.uuid}.yml"
path = "#{Allages.config.input_dir}/Unreleased/#{filename}"
open("#{path}", 'w') do |f|
f.puts yaml
end
puts "created new unreleased entry #{path}"
end
|
.new_version ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/allages.rb', line 92
def new_version
print "Version name: "
STDOUT.flush
version = STDIN.gets.chomp
dir = "#{Allages.config.input_dir}/#{version}"
if File.directory?(dir)
puts "version already exists"
exit 1
else
FileUtils.mkdir_p(dir)
puts "created directory #{dir} "
end
open("#{dir}/.meta.yml", 'w') do |f|
f.puts META_TEMPLATE
end
end
|
.reset_config ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/allages/config.rb', line 15
def self.reset_config
self.configure do |config|
config.input_dir = 'changelogs'
config.output_file = :stdout
config.include_unreleased = false
config. = <<~END
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
END
end
end
|