rggen-core 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/exe/rggen +3 -3
- data/lib/rggen/core.rb +3 -0
- data/lib/rggen/core/builder/builder.rb +10 -14
- data/lib/rggen/core/builder/plugins.rb +59 -0
- data/lib/rggen/core/cli.rb +8 -11
- data/lib/rggen/core/exceptions.rb +3 -0
- data/lib/rggen/core/facets.rb +1 -0
- data/lib/rggen/core/input_base/property.rb +12 -1
- data/lib/rggen/core/options.rb +6 -0
- data/lib/rggen/core/output_base/feature.rb +1 -0
- data/lib/rggen/core/output_base/feature_factory.rb +2 -0
- data/lib/rggen/core/output_base/raise_error.rb +13 -0
- data/lib/rggen/core/printers.rb +3 -3
- data/lib/rggen/core/utility/error_utility.rb +19 -0
- data/lib/rggen/core/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b863029dea0e5088f792bad82e185bf15bd22de39578f7e1d368851ab9d7549
|
4
|
+
data.tar.gz: 5e8714a42f5b385f2373e01bcf7395b0139359c2a6dde6aa22889759edda12d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 953bf54d406360b11bf39a2d5be9be50dffbb139ec9a55b2d0cc8e5405f58e05e047e938bb92cbee866dada08e57000e2675aa3055dfde881d63fbe570e1d24f
|
7
|
+
data.tar.gz: 5ccbf66f592401e5fd3bd3bacf9dcdd883a5744eb7ba684eb6efb70332042efa8b692d2c2e7d07cc3dbbb4b7c95cadc2234d8a6125789ffbb42b8580fa0b4a2e
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/rggen-core.svg)](https://badge.fury.io/rb/rggen-core)
|
2
|
-
[![Build Status](https://travis-ci.
|
2
|
+
[![Build Status](https://travis-ci.com/rggen/rggen-core.svg?branch=master)](https://travis-ci.com/rggen/rggen-core)
|
3
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/53c8e6654c2b5ecb9142/maintainability)](https://codeclimate.com/github/rggen/rggen-core/maintainability)
|
4
4
|
[![codecov](https://codecov.io/gh/rggen/rggen-core/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-core)
|
5
5
|
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rggen_rggen-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=rggen_rggen-core)
|
data/exe/rggen
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
5
|
require 'rggen/core'
|
6
|
-
require 'facets/module/lastname'
|
7
6
|
|
8
7
|
begin
|
9
8
|
cli = RgGen::Core::CLI.new
|
10
9
|
cli.run(ARGV)
|
11
|
-
rescue
|
12
|
-
abort
|
10
|
+
rescue ScriptError, StandardError => e
|
11
|
+
abort RgGen::Core::Utility::ErrorUtility
|
12
|
+
.compose_error_message(e, cli.options[:print_backtrace])
|
13
13
|
end
|
data/lib/rggen/core.rb
CHANGED
@@ -22,6 +22,7 @@ require_relative 'core/utility/code_utility/code_block'
|
|
22
22
|
require_relative 'core/utility/code_utility/source_file'
|
23
23
|
require_relative 'core/utility/code_utility/structure_definition'
|
24
24
|
require_relative 'core/utility/code_utility'
|
25
|
+
require_relative 'core/utility/error_utility'
|
25
26
|
require_relative 'core/utility/regexp_patterns'
|
26
27
|
|
27
28
|
require_relative 'core/exceptions'
|
@@ -78,6 +79,7 @@ require_relative 'core/output_base/template_engine'
|
|
78
79
|
require_relative 'core/output_base/erb_engine'
|
79
80
|
require_relative 'core/output_base/code_generator'
|
80
81
|
require_relative 'core/output_base/file_writer'
|
82
|
+
require_relative 'core/output_base/raise_error'
|
81
83
|
require_relative 'core/output_base/component'
|
82
84
|
require_relative 'core/output_base/component_factory'
|
83
85
|
require_relative 'core/output_base/feature'
|
@@ -91,6 +93,7 @@ require_relative 'core/builder/simple_feature_entry'
|
|
91
93
|
require_relative 'core/builder/list_feature_entry'
|
92
94
|
require_relative 'core/builder/feature_registry'
|
93
95
|
require_relative 'core/builder/category'
|
96
|
+
require_relative 'core/builder/plugins'
|
94
97
|
require_relative 'core/builder/builder'
|
95
98
|
require_relative 'core/builder'
|
96
99
|
|
@@ -7,8 +7,11 @@ module RgGen
|
|
7
7
|
def initialize
|
8
8
|
initialize_component_registries
|
9
9
|
initialize_categories
|
10
|
+
@plugins = Plugins.new
|
10
11
|
end
|
11
12
|
|
13
|
+
attr_reader :plugins
|
14
|
+
|
12
15
|
def input_component_registry(name, &body)
|
13
16
|
component_registry(:input, name, body)
|
14
17
|
end
|
@@ -87,29 +90,22 @@ module RgGen
|
|
87
90
|
RegisterMap.setup(self)
|
88
91
|
end
|
89
92
|
|
90
|
-
def setup(
|
91
|
-
|
92
|
-
if library_module.const_defined?(:VERSION)
|
93
|
-
library_module.const_get(:VERSION)
|
94
|
-
elsif library_module.respond_to?(:version)
|
95
|
-
library_module.version
|
96
|
-
else
|
97
|
-
'0.0.0'
|
98
|
-
end
|
99
|
-
library_module.setup(self)
|
93
|
+
def setup(name, plugin_module, &block)
|
94
|
+
plugins.add(name, plugin_module, block)
|
100
95
|
end
|
101
96
|
|
102
|
-
def
|
103
|
-
|
97
|
+
def activate_plugins
|
98
|
+
plugins.activate(self)
|
104
99
|
end
|
105
100
|
|
106
|
-
def load_setup_file(file)
|
101
|
+
def load_setup_file(file, activation = true)
|
107
102
|
(file.nil? || file.empty?) &&
|
108
103
|
(raise Core::LoadError.new('no setup file is given'))
|
109
104
|
File.readable?(file) ||
|
110
105
|
(raise Core::LoadError.new("cannot load such setup file: #{file}"))
|
111
106
|
RgGen.builder(self)
|
112
107
|
load(file)
|
108
|
+
activation && activate_plugins
|
113
109
|
end
|
114
110
|
|
115
111
|
private
|
@@ -136,7 +132,7 @@ module RgGen
|
|
136
132
|
|
137
133
|
COMPONENT_REGISTRIES = {
|
138
134
|
input: InputComponentRegistry, output: OutputComponentRegistry
|
139
|
-
}
|
135
|
+
}.freeze
|
140
136
|
|
141
137
|
def component_registry(type, name, body)
|
142
138
|
registries = @component_registries[type]
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Builder
|
6
|
+
class Plugin
|
7
|
+
def initialize(name, plugin_module, block)
|
8
|
+
@name = name
|
9
|
+
@version = extract_version(plugin_module)
|
10
|
+
@plugin_module = plugin_module
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
attr_reader :version
|
16
|
+
|
17
|
+
def default_setup(builder)
|
18
|
+
@plugin_module.respond_to?(:default_setup) &&
|
19
|
+
@plugin_module.default_setup(builder)
|
20
|
+
end
|
21
|
+
|
22
|
+
def optional_setup(builder)
|
23
|
+
@block && @plugin_module.instance_exec(builder, &@block)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def extract_version(plugin_module)
|
29
|
+
if plugin_module.const_defined?(:VERSION)
|
30
|
+
plugin_module.const_get(:VERSION)
|
31
|
+
elsif plugin_module.respond_to?(:version)
|
32
|
+
plugin_module.version
|
33
|
+
else
|
34
|
+
'0.0.0'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Plugins
|
40
|
+
def initialize
|
41
|
+
@plugins = []
|
42
|
+
end
|
43
|
+
|
44
|
+
def add(name, plugin_module, block)
|
45
|
+
@plugins << Plugin.new(name, plugin_module, block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def activate(builder)
|
49
|
+
@plugins.each { |plugin| plugin.default_setup(builder) }
|
50
|
+
@plugins.each { |plugin| plugin.optional_setup(builder) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def plugin_versions
|
54
|
+
@plugins.map { |plugin| [plugin.name, plugin.version] }.to_h
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/rggen/core/cli.rb
CHANGED
@@ -4,24 +4,21 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
class CLI
|
6
6
|
def initialize(builder = nil)
|
7
|
-
|
7
|
+
@builder = builder || Builder.create
|
8
|
+
@options = Options.new
|
8
9
|
end
|
9
10
|
|
11
|
+
attr_reader :builder
|
12
|
+
attr_reader :options
|
13
|
+
|
10
14
|
def run(args)
|
11
|
-
options
|
12
|
-
builder
|
13
|
-
runner(options).run(builder, options)
|
15
|
+
options.parse(args)
|
16
|
+
runner.run(builder, options)
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
17
20
|
|
18
|
-
def
|
19
|
-
options = Options.new
|
20
|
-
options.parse(args)
|
21
|
-
options
|
22
|
-
end
|
23
|
-
|
24
|
-
def runner(options)
|
21
|
+
def runner
|
25
22
|
options[:runner] || Generator.new
|
26
23
|
end
|
27
24
|
end
|
data/lib/rggen/core/facets.rb
CHANGED
@@ -66,10 +66,21 @@ module RgGen
|
|
66
66
|
varible_name = "@#{@name[-1] == '?' ? @name[0..-2] : @name}"
|
67
67
|
if feature.instance_variable_defined?(varible_name)
|
68
68
|
feature.instance_variable_get(varible_name)
|
69
|
+
elsif @options.key?(:initial)
|
70
|
+
set_initial_value(feature, varible_name)
|
69
71
|
else
|
70
|
-
@options[:default]
|
72
|
+
evaluate_default_initial_value(feature, @options[:default])
|
71
73
|
end
|
72
74
|
end
|
75
|
+
|
76
|
+
def set_initial_value(feature, varible_name)
|
77
|
+
value = evaluate_default_initial_value(feature, @options[:initial])
|
78
|
+
feature.instance_variable_set(varible_name, value)
|
79
|
+
end
|
80
|
+
|
81
|
+
def evaluate_default_initial_value(feature, value)
|
82
|
+
value.is_a?(Proc) ? feature.instance_exec(&value) : value
|
83
|
+
end
|
73
84
|
end
|
74
85
|
end
|
75
86
|
end
|
data/lib/rggen/core/options.rb
CHANGED
@@ -152,6 +152,12 @@ module RgGen
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
+
Options.add_option(:print_backtrace) do |option|
|
156
|
+
option.long_option '--print-backtrace'
|
157
|
+
option.default false
|
158
|
+
option.description 'Print backtrace when an error occurs'
|
159
|
+
end
|
160
|
+
|
155
161
|
Options.add_option(:version) do |option|
|
156
162
|
option.short_option '-v'
|
157
163
|
option.long_option '--version'
|
data/lib/rggen/core/printers.rb
CHANGED
@@ -29,7 +29,7 @@ module RgGen
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def load_setup_file(builder, file)
|
32
|
-
file.nil? || file.empty? || builder.load_setup_file(file)
|
32
|
+
file.nil? || file.empty? || builder.load_setup_file(file, false)
|
33
33
|
end
|
34
34
|
|
35
35
|
def help_message(builder)
|
@@ -45,8 +45,8 @@ module RgGen
|
|
45
45
|
|
46
46
|
def verbose_version(builder)
|
47
47
|
{ core: Core::VERSION }
|
48
|
-
.merge(builder.
|
49
|
-
.map { |(
|
48
|
+
.merge(builder.plugins.plugin_versions)
|
49
|
+
.map { |(name, version)| " - rggen-#{name} #{version}" }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Utility
|
6
|
+
module ErrorUtility
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def compose_error_message(error, verbose)
|
10
|
+
lines = []
|
11
|
+
lines << "[#{error.class.lastname}] #{error.message}"
|
12
|
+
verbose &&
|
13
|
+
error.backtrace.each { |trace| lines << " #{trace}" }
|
14
|
+
lines.join("\n")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rggen/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rggen-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docile
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/rggen/core/builder/input_component_registry.rb
|
98
98
|
- lib/rggen/core/builder/list_feature_entry.rb
|
99
99
|
- lib/rggen/core/builder/output_component_registry.rb
|
100
|
+
- lib/rggen/core/builder/plugins.rb
|
100
101
|
- lib/rggen/core/builder/simple_feature_entry.rb
|
101
102
|
- lib/rggen/core/cli.rb
|
102
103
|
- lib/rggen/core/configuration.rb
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- lib/rggen/core/output_base/feature.rb
|
137
138
|
- lib/rggen/core/output_base/feature_factory.rb
|
138
139
|
- lib/rggen/core/output_base/file_writer.rb
|
140
|
+
- lib/rggen/core/output_base/raise_error.rb
|
139
141
|
- lib/rggen/core/output_base/template_engine.rb
|
140
142
|
- lib/rggen/core/printers.rb
|
141
143
|
- lib/rggen/core/register_map.rb
|
@@ -156,6 +158,7 @@ files:
|
|
156
158
|
- lib/rggen/core/utility/code_utility/line.rb
|
157
159
|
- lib/rggen/core/utility/code_utility/source_file.rb
|
158
160
|
- lib/rggen/core/utility/code_utility/structure_definition.rb
|
161
|
+
- lib/rggen/core/utility/error_utility.rb
|
159
162
|
- lib/rggen/core/utility/regexp_patterns.rb
|
160
163
|
- lib/rggen/core/version.rb
|
161
164
|
homepage: https://github.com/rggen/rggen-core
|
@@ -184,5 +187,5 @@ requirements: []
|
|
184
187
|
rubygems_version: 3.0.3
|
185
188
|
signing_key:
|
186
189
|
specification_version: 4
|
187
|
-
summary: rggen-core-0.
|
190
|
+
summary: rggen-core-0.13.0
|
188
191
|
test_files: []
|