renogen 0.0.1 → 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -3
  3. data/bin/renogen +2 -58
  4. data/lib/renogen.rb +9 -0
  5. data/lib/renogen/change_log.rb +9 -0
  6. data/lib/renogen/change_log/group.rb +21 -0
  7. data/lib/renogen/change_log/item.rb +60 -0
  8. data/lib/renogen/change_log/model.rb +41 -0
  9. data/lib/renogen/change_log/writer.rb +39 -0
  10. data/lib/renogen/cli.rb +60 -0
  11. data/lib/renogen/cli/param_parser.rb +73 -0
  12. data/lib/renogen/config.rb +35 -0
  13. data/lib/renogen/exceptions.rb +8 -0
  14. data/lib/renogen/exceptions/base.rb +7 -0
  15. data/lib/renogen/exceptions/extraction_stratagy_not_found.rb +20 -0
  16. data/lib/renogen/exceptions/formatter_not_found.rb +20 -0
  17. data/lib/renogen/extraction_stratagies.rb +42 -0
  18. data/lib/renogen/extraction_stratagies/base.rb +29 -0
  19. data/lib/renogen/extraction_stratagies/yaml_file.rb +10 -0
  20. data/lib/renogen/extraction_stratagies/yaml_file/parser.rb +39 -0
  21. data/lib/renogen/extraction_stratagies/yaml_file/provider.rb +24 -0
  22. data/lib/renogen/extraction_stratagies/yaml_file/reader.rb +48 -0
  23. data/lib/renogen/formatters.rb +43 -0
  24. data/lib/renogen/formatters/base.rb +54 -0
  25. data/lib/renogen/formatters/html.rb +47 -0
  26. data/lib/renogen/formatters/markdown.rb +33 -0
  27. data/lib/renogen/formatters/plain_text.rb +33 -0
  28. data/lib/renogen/generator.rb +34 -0
  29. data/lib/renogen/version.rb +3 -0
  30. data/spec/lib/renogen/change_log/group_spec.rb +13 -0
  31. data/spec/lib/renogen/change_log/item_spec.rb +51 -0
  32. data/spec/lib/renogen/change_log/model_spec.rb +36 -0
  33. data/spec/lib/renogen/change_log/writer_spec.rb +8 -0
  34. data/spec/lib/renogen/config_spec.rb +19 -0
  35. data/spec/lib/renogen/exceptions/extraction_stratagy_not_found_spec.rb +13 -0
  36. data/spec/lib/renogen/exceptions/formatter_not_found_spec.rb +13 -0
  37. data/spec/lib/renogen/extraction_stratagies/base_spec.rb +10 -0
  38. data/spec/lib/renogen/extraction_stratagies/yaml_file/parser_spec.rb +24 -0
  39. data/spec/lib/renogen/extraction_stratagies/yaml_file/provider_spec.rb +12 -0
  40. data/spec/lib/renogen/extraction_stratagies/yaml_file/reader_spec.rb +20 -0
  41. data/spec/lib/renogen/formatters/base_spec.rb +21 -0
  42. data/spec/lib/renogen/formatters/html_spec.rb +38 -0
  43. data/spec/lib/renogen/formatters/markdown_spec.rb +29 -0
  44. data/spec/lib/renogen/formatters/plain_text_spec.rb +29 -0
  45. data/spec/lib/renogen_spec.rb +11 -0
  46. data/spec/spec_helper.rb +76 -0
  47. metadata +67 -9
@@ -0,0 +1,35 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+
4
+ module Renogen
5
+ # Stores configuratin values to be used by the libary
6
+ class Config
7
+ include Singleton
8
+ attr_accessor :single_line_format, :input_source, :output_format, :supported_keys, :changelog_path
9
+
10
+
11
+ def initialize
12
+ config_file = load_yaml_config
13
+ self.single_line_format = config_file['single_line_format'] || 'summary (see link)'.freeze
14
+ self.supported_keys = config_file['supported_keys'] || ['identifier', 'link', 'summary'].freeze
15
+ self.input_source = config_file['input_source'] || 'yaml'.freeze
16
+ self.output_format = config_file['output_format'] || 'markdown'.freeze
17
+ self.changelog_path = config_file['changelog_path']
18
+ end
19
+
20
+ def self.configure
21
+ yield instance
22
+ end
23
+
24
+ private
25
+
26
+ def load_yaml_config(config_file_path='.renogen')
27
+ begin
28
+ YAML.load_file(config_file_path)
29
+ rescue
30
+ {}
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,8 @@
1
+ module Renogen
2
+ # Custom exceptions
3
+ module Exceptions
4
+ require 'renogen/exceptions/base'
5
+ require 'renogen/exceptions/extraction_stratagy_not_found'
6
+ require 'renogen/exceptions/formatter_not_found'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Renogen
2
+ module Exceptions
3
+ # super class for shared functionality of all rengeon exceptions
4
+ class Base < StandardError
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Renogen
2
+ module Exceptions
3
+ # Raised when an extraction stratagy for a given key can not be found
4
+ class ExtractionStratagyNotFound < Base
5
+ attr_reader :missing_stratagy
6
+
7
+ def initialize(type)
8
+ @missing_stratagy = type
9
+ super
10
+ end
11
+
12
+ # Friendly error message
13
+ #
14
+ # @return [String]
15
+ def message
16
+ "Error: Unsupported source type '#{missing_stratagy}'"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Renogen
2
+ module Exceptions
3
+ # Raised when an extraction stratagy for a given key can not be found
4
+ class FormatterNotFound < Base
5
+ attr_reader :name
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ super
10
+ end
11
+
12
+ # Friendly error message
13
+ #
14
+ # @return [String]
15
+ def message
16
+ "Error: Unsupported format type '#{name}'"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ module Renogen
2
+ # Contains methods for extracting release notes
3
+ module ExtractionStratagies
4
+
5
+ class << self
6
+
7
+ # Retrieves a stratagy from a given key
8
+ #
9
+ # @param stratagy_type [String] identifier for stratagy
10
+ # @param options [Hash] any options required for stratagy
11
+ # @return [ExtractionStratagies::Base]
12
+ def obtain(stratagy_type, options={})
13
+ stratagy = stratagies[stratagy_type.to_s]
14
+ if stratagy
15
+ stratagy.new(options)
16
+ else
17
+ raise Renogen::Exceptions::ExtractionStratagyNotFound.new(stratagy_type)
18
+ end
19
+ end
20
+
21
+ # Adds a new stratagy class to store
22
+ #
23
+ # @param identifier [Symbol]
24
+ # @param klass [Symbol]
25
+ def add(identifier, klass)
26
+ # raise 'name taken' unless stratagies[name].nil?
27
+ stratagies[identifier.to_s]=klass
28
+ end
29
+
30
+ private
31
+
32
+ def stratagies
33
+ @stratagies ||= {}
34
+ end
35
+ end
36
+
37
+ require'renogen/extraction_stratagies/base'
38
+ require'renogen/extraction_stratagies/yaml_file'
39
+ # require_relative 'extraction_stratagies/github'
40
+ # require_relative 'extraction_stratagies/gitlog'
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ module Renogen
2
+ module ExtractionStratagies
3
+ # Template for all extraction stratagies
4
+ class Base
5
+
6
+ # Adds class with identifier to extraction stratagies
7
+ #
8
+ # @param identifier [String]
9
+ def self.register(identifier)
10
+ Renogen::ExtractionStratagies.add(identifier.to_sym, self)
11
+ end
12
+
13
+ def initialize(options={})
14
+ @changelog ||= ChangeLog::Model.new
15
+ end
16
+
17
+ # Parse changes from source
18
+ #
19
+ # @return [NotImplementedError]
20
+ def extract
21
+ raise NotImplementedError
22
+ end
23
+
24
+ protected
25
+
26
+ attr_reader :changelog
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ module Renogen
2
+ module ExtractionStratagies
3
+ # module for extracting changes from YAML files
4
+ module YamlFile
5
+ require 'renogen/extraction_stratagies/yaml_file/reader'
6
+ require 'renogen/extraction_stratagies/yaml_file/parser'
7
+ require 'renogen/extraction_stratagies/yaml_file/provider'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ module Renogen
2
+ module ExtractionStratagies
3
+ module YamlFile
4
+
5
+ # Reads change data from files in configured directory
6
+ class Parser
7
+ attr_reader :changelog
8
+
9
+ def initialize(options={})
10
+ @changelog = options[:changelog] || ChangeLog::Model.new
11
+ @yaml_file_reader = Reader.new(options['changelog_path'], options)
12
+ end
13
+
14
+ # @return [ChangeLog::Model]
15
+ def parse!
16
+ yaml_file_reader.each_yaml_file do |file|
17
+ parse_file(file)
18
+ end
19
+ changelog
20
+ end
21
+
22
+ protected
23
+
24
+ attr_reader :yaml_file_reader
25
+
26
+ def parse_file(file)
27
+ file.each do |group_name, content|
28
+ changelog.add_change(ChangeLog::Item.new(group_name, content))
29
+ end
30
+ end
31
+
32
+ def config
33
+ Renogen::Config.instance
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ module Renogen
2
+ module ExtractionStratagies
3
+ module YamlFile
4
+
5
+ # Reads change data from files in configured directory
6
+ class Provider < Base
7
+ register :yaml_file
8
+ register :yaml
9
+
10
+ def initialize(options={})
11
+ super
12
+ @yaml_parser = Parser.new(options)
13
+ end
14
+
15
+ # Parse changes from source
16
+ #
17
+ # @return [ChangeLog::Model]
18
+ def extract
19
+ @yaml_parser.parse!
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+
3
+ module Renogen
4
+ module ExtractionStratagies
5
+ module YamlFile
6
+ # Reads the relevant yaml files
7
+ class Reader
8
+ attr_accessor :directory_path, :legacy_version
9
+
10
+ def initialize(directory_path, options={})
11
+ @legacy_version = options['legacy_version']
12
+ @directory_path = directory_path
13
+ @directory_path ||= './change_log/'
14
+ end
15
+
16
+ # @yield [Hash] yaml_file
17
+ def each_yaml_file
18
+ change_directories.each do |file_path|
19
+ yield ::YAML.load_file(file_path)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ # @return [Array]
26
+ def change_directories
27
+ upgrade_versions = legacy_versions.map do |path|
28
+ File.join(path, "*.yml")
29
+ end
30
+ upgrade_versions << File.join(directory_path, 'next', "*.yml")
31
+
32
+ Dir.glob(upgrade_versions)
33
+ end
34
+
35
+ # @return [Array]
36
+ def legacy_versions
37
+ return [] unless legacy_version
38
+ legacy_version.gsub!('v','')
39
+ Dir.glob(File.join(directory_path, '*')).select do |dir|
40
+ dir = dir.split('/').last.gsub('v','').gsub('_','.')
41
+ next if dir == 'next'
42
+ Gem::Version.new(dir) > Gem::Version.new(legacy_version)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ module Renogen
2
+ # Formatters are used to manipulate how the change is output
3
+ #
4
+ # Also has methods to retrive and add a formatters
5
+ module Formatters
6
+
7
+ class << self
8
+ # Retrieves a formatter from a given key
9
+ #
10
+ # @param format_type [String] identifier for formatter
11
+ # @param options [Hash] any options required for formatter
12
+ # @return [Formatter::Base]
13
+ def obtain(format_type, options={})
14
+ formatter = formatters[format_type.to_sym]
15
+ if formatter
16
+ formatter.new(options)
17
+ else
18
+ raise Renogen::Exceptions::FormatterNotFound.new(format_type)
19
+ end
20
+ end
21
+
22
+ # Adds a new formatter class to store
23
+ #
24
+ # @param identifier [Symbol]
25
+ # @param klass [Symbol]
26
+ def add(identifier, klass)
27
+ # TODO raise 'name taken' unless formatters[name].nil?
28
+ formatters[identifier]=klass
29
+ end
30
+
31
+ private
32
+
33
+ def formatters
34
+ @formatters ||= {}
35
+ end
36
+ end
37
+ end
38
+
39
+ require 'renogen/formatters/base'
40
+ require 'renogen/formatters/plain_text'
41
+ require 'renogen/formatters/markdown'
42
+ require 'renogen/formatters/html'
43
+ end
@@ -0,0 +1,54 @@
1
+ module Renogen
2
+ module Formatters
3
+ # Implements a template pattern that forces the implemention of required
4
+ # methods in sub classes
5
+ class Base
6
+ def initialize(options={})
7
+ end
8
+
9
+ # Adds class with identifier to formatters
10
+ #
11
+ # @param identifier [String]
12
+ def self.register(identifier)
13
+ Renogen::Formatters.add(identifier.to_sym, self)
14
+ end
15
+
16
+ # Outputs a line or block of text appearing at the top of the change log.
17
+ #
18
+ # @param header [String]
19
+ # @return [NotImplementedError]
20
+ def write_header(header)
21
+ raise NotImplementedError
22
+ end
23
+
24
+ # Outputs a line or block as a header for a group.
25
+ #
26
+ # @param group [String]
27
+ # @return [NotImplementedError]
28
+ def write_group(group)
29
+ raise NotImplementedError
30
+ end
31
+
32
+ # Outputs a line or block of text appearing after a group.
33
+ #
34
+ # @return [nil]
35
+ def write_group_end
36
+ end
37
+
38
+ # Outputs a line or block as the body for a change.
39
+ #
40
+ # @param change [String]
41
+ # @return [NotImplementedError]
42
+ def write_change(change)
43
+ raise NotImplementedError
44
+ end
45
+
46
+ # Outputs a line or block of text appearing at the bottom of the change log.
47
+ #
48
+ # @param changelog [ChangeLog]
49
+ # @return [nil]
50
+ def write_footer(changelog)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ module Renogen
2
+ module Formatters
3
+ # For formatting a change into html format
4
+ class Html < Base
5
+ register :html
6
+
7
+ # Outputs a line or block of text appearing at the top of the change log.
8
+ #
9
+ # @param header [String]
10
+ # @return [String]
11
+ def write_header(header)
12
+ "<html>\n<h1>#{header}</h1>"
13
+ end
14
+
15
+ # Outputs a line or block as a header for a group.
16
+ #
17
+ # @param group [String]
18
+ # @return [String]
19
+ def write_group(group)
20
+ "<h2>#{group}</h2>\n<ul>"
21
+ end
22
+
23
+ # Outputs a line or block of text appearing after a group.
24
+ #
25
+ # @return [String]
26
+ def write_group_end
27
+ "</ul>"
28
+ end
29
+
30
+ # Outputs a line or block as the body for a change.
31
+ #
32
+ # @param change [String]
33
+ # @return [String]
34
+ def write_change(change)
35
+ " <li>#{change}</li>"
36
+ end
37
+
38
+ # Outputs a line or block of text appearing at the bottom of the change log.
39
+ #
40
+ # @param changelog [ChangeLog]
41
+ # @return [String]
42
+ def write_footer(changelog)
43
+ '</html>'
44
+ end
45
+ end
46
+ end
47
+ end