rggen-core 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/exe/rggen +13 -0
- data/lib/rggen/core.rb +101 -0
- data/lib/rggen/core/base/component.rb +54 -0
- data/lib/rggen/core/base/component_factory.rb +84 -0
- data/lib/rggen/core/base/feature.rb +46 -0
- data/lib/rggen/core/base/feature_factory.rb +37 -0
- data/lib/rggen/core/base/hierarchical_accessors.rb +91 -0
- data/lib/rggen/core/base/hierarchical_feature_accessors.rb +83 -0
- data/lib/rggen/core/base/internal_struct.rb +21 -0
- data/lib/rggen/core/base/shared_context.rb +18 -0
- data/lib/rggen/core/builder.rb +13 -0
- data/lib/rggen/core/builder/builder.rb +150 -0
- data/lib/rggen/core/builder/category.rb +116 -0
- data/lib/rggen/core/builder/component_entry.rb +29 -0
- data/lib/rggen/core/builder/component_registry.rb +47 -0
- data/lib/rggen/core/builder/feature_registry.rb +126 -0
- data/lib/rggen/core/builder/input_component_registry.rb +35 -0
- data/lib/rggen/core/builder/list_feature_entry.rb +98 -0
- data/lib/rggen/core/builder/output_component_registry.rb +10 -0
- data/lib/rggen/core/builder/simple_feature_entry.rb +39 -0
- data/lib/rggen/core/cli.rb +29 -0
- data/lib/rggen/core/configuration.rb +19 -0
- data/lib/rggen/core/configuration/component.rb +10 -0
- data/lib/rggen/core/configuration/component_factory.rb +19 -0
- data/lib/rggen/core/configuration/error.rb +16 -0
- data/lib/rggen/core/configuration/feature.rb +13 -0
- data/lib/rggen/core/configuration/feature_factory.rb +11 -0
- data/lib/rggen/core/configuration/hash_loader.rb +15 -0
- data/lib/rggen/core/configuration/json_loader.rb +18 -0
- data/lib/rggen/core/configuration/loader.rb +11 -0
- data/lib/rggen/core/configuration/ruby_loader.rb +15 -0
- data/lib/rggen/core/configuration/yaml_loader.rb +18 -0
- data/lib/rggen/core/core_extensions/casecmp.rb +12 -0
- data/lib/rggen/core/core_extensions/forwardable.rb +12 -0
- data/lib/rggen/core/core_extensions/forwardable_workaround.rb +22 -0
- data/lib/rggen/core/core_extensions/object.rb +14 -0
- data/lib/rggen/core/dsl.rb +30 -0
- data/lib/rggen/core/exceptions.rb +29 -0
- data/lib/rggen/core/facets.rb +7 -0
- data/lib/rggen/core/generator.rb +51 -0
- data/lib/rggen/core/input_base/component.rb +30 -0
- data/lib/rggen/core/input_base/component_factory.rb +88 -0
- data/lib/rggen/core/input_base/feature.rb +130 -0
- data/lib/rggen/core/input_base/feature_factory.rb +80 -0
- data/lib/rggen/core/input_base/input_data.rb +98 -0
- data/lib/rggen/core/input_base/input_matcher.rb +79 -0
- data/lib/rggen/core/input_base/input_value.rb +34 -0
- data/lib/rggen/core/input_base/json_loader.rb +16 -0
- data/lib/rggen/core/input_base/loader.rb +44 -0
- data/lib/rggen/core/input_base/property.rb +76 -0
- data/lib/rggen/core/input_base/verifier.rb +41 -0
- data/lib/rggen/core/input_base/yaml_loader.rb +34 -0
- data/lib/rggen/core/options.rb +181 -0
- data/lib/rggen/core/output_base/code_generator.rb +59 -0
- data/lib/rggen/core/output_base/component.rb +100 -0
- data/lib/rggen/core/output_base/component_factory.rb +35 -0
- data/lib/rggen/core/output_base/erb_engine.rb +21 -0
- data/lib/rggen/core/output_base/feature.rb +147 -0
- data/lib/rggen/core/output_base/feature_factory.rb +13 -0
- data/lib/rggen/core/output_base/file_writer.rb +40 -0
- data/lib/rggen/core/output_base/template_engine.rb +27 -0
- data/lib/rggen/core/printers.rb +53 -0
- data/lib/rggen/core/register_map.rb +21 -0
- data/lib/rggen/core/register_map/component.rb +20 -0
- data/lib/rggen/core/register_map/component_factory.rb +19 -0
- data/lib/rggen/core/register_map/error.rb +16 -0
- data/lib/rggen/core/register_map/feature.rb +22 -0
- data/lib/rggen/core/register_map/feature_factory.rb +11 -0
- data/lib/rggen/core/register_map/hash_loader.rb +47 -0
- data/lib/rggen/core/register_map/input_data.rb +34 -0
- data/lib/rggen/core/register_map/json_loader.rb +18 -0
- data/lib/rggen/core/register_map/loader.rb +15 -0
- data/lib/rggen/core/register_map/ruby_loader.rb +15 -0
- data/lib/rggen/core/register_map/yaml_loader.rb +18 -0
- data/lib/rggen/core/utility/attribute_setter.rb +53 -0
- data/lib/rggen/core/utility/code_utility.rb +64 -0
- data/lib/rggen/core/utility/code_utility/code_block.rb +88 -0
- data/lib/rggen/core/utility/code_utility/line.rb +51 -0
- data/lib/rggen/core/utility/code_utility/source_file.rb +104 -0
- data/lib/rggen/core/utility/code_utility/structure_definition.rb +54 -0
- data/lib/rggen/core/utility/regexp_patterns.rb +38 -0
- data/lib/rggen/core/version.rb +10 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c44b329ade70f9626aa1253139f320a4ff81ee783d09a3bb80801affb7c8d8c
|
4
|
+
data.tar.gz: 43f60a3929c4d631f7d2413ea61358aea4578e73f9da0eac05c45a104be32a0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bdf9421ca6038337d4892aa010dcef2a31095ab910e03d85685cbfb266520cc5eb50c0e19c067607823716f355697a5d78439f1dde7913abc82397ca6efa75f
|
7
|
+
data.tar.gz: db0d6e571511aa07c860e4d2c77fc7fa2aba58d751ab5dde31d724676557745527aba26916fbad6840b26acc14da51b9d8049496c730caef7e11a6f8bde0aec4
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at taichi730@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017-2019 Taichi Ishitani
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/rggen/rggen-core.svg?branch=master)](https://travis-ci.org/rggen/rggen-core)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/53c8e6654c2b5ecb9142/maintainability)](https://codeclimate.com/github/rggen/rggen-core/maintainability)
|
3
|
+
[![codecov](https://codecov.io/gh/rggen/rggen-core/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-core)
|
4
|
+
[![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)
|
5
|
+
|
6
|
+
# RgGen::Core
|
7
|
+
|
8
|
+
RgGen::Core is a core library of RgGen tool and provides features listed below:
|
9
|
+
|
10
|
+
* Structure and APIs for defining properties, parsers and error checkers of configuration file and register map documents
|
11
|
+
* Basic loaders for configuration file and register map documents
|
12
|
+
* Ruby with APIs for description
|
13
|
+
* YAML
|
14
|
+
* JSON
|
15
|
+
* Structure and APIs for defining output file writers
|
16
|
+
* Building RgGen tool up by linking defined above features
|
17
|
+
* The `rggen` executable command
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
During RgGen installation, RgGen::Core will also be installed automatically.
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install rggen
|
25
|
+
```
|
26
|
+
|
27
|
+
If you want to install RgGen::Core only, use the command bewlo:
|
28
|
+
|
29
|
+
```
|
30
|
+
$ gem install rggen-core
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contact
|
34
|
+
|
35
|
+
Feedbacks, bug reports, questions and etc. are wellcome! You can post them by using following ways:
|
36
|
+
|
37
|
+
* [GitHub Issue Tracker](https://github.com/rggen/rggen-core/issues)
|
38
|
+
* [Mail](mailto:taichi730@gmail.com)
|
39
|
+
|
40
|
+
## Copyright & License
|
41
|
+
|
42
|
+
Copyright © 2017-2019 Taichi Ishitani. RgGen::Core is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
|
43
|
+
|
44
|
+
## Code of Conduct
|
45
|
+
|
46
|
+
Everyone interacting in the RgGen project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rggen/rggen-core/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/rggen
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
|
+
require 'rggen/core'
|
6
|
+
require 'facets/module/lastname'
|
7
|
+
|
8
|
+
begin
|
9
|
+
cli = RgGen::Core::CLI.new
|
10
|
+
cli.run(ARGV)
|
11
|
+
rescue OptionParser::ParseError, RgGen::Core::RuntimeError => e
|
12
|
+
abort "[#{e.class.lastname}] #{e.message}"
|
13
|
+
end
|
data/lib/rggen/core.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'docile'
|
4
|
+
require 'erubi'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'forwardable'
|
7
|
+
require 'json'
|
8
|
+
require 'optparse'
|
9
|
+
require 'pathname'
|
10
|
+
require 'singleton'
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
require_relative 'core/version'
|
14
|
+
|
15
|
+
require_relative 'core/facets'
|
16
|
+
require_relative 'core/core_extensions/casecmp'
|
17
|
+
require_relative 'core/core_extensions/object'
|
18
|
+
require_relative 'core/core_extensions/forwardable'
|
19
|
+
|
20
|
+
require_relative 'core/utility/attribute_setter'
|
21
|
+
require_relative 'core/utility/code_utility/line'
|
22
|
+
require_relative 'core/utility/code_utility/code_block'
|
23
|
+
require_relative 'core/utility/code_utility/source_file'
|
24
|
+
require_relative 'core/utility/code_utility/structure_definition'
|
25
|
+
require_relative 'core/utility/code_utility'
|
26
|
+
require_relative 'core/utility/regexp_patterns'
|
27
|
+
|
28
|
+
require_relative 'core/exceptions'
|
29
|
+
|
30
|
+
require_relative 'core/base/internal_struct'
|
31
|
+
require_relative 'core/base/shared_context'
|
32
|
+
require_relative 'core/base/component'
|
33
|
+
require_relative 'core/base/component_factory'
|
34
|
+
require_relative 'core/base/feature'
|
35
|
+
require_relative 'core/base/feature_factory'
|
36
|
+
require_relative 'core/base/hierarchical_accessors'
|
37
|
+
require_relative 'core/base/hierarchical_feature_accessors'
|
38
|
+
|
39
|
+
require_relative 'core/input_base/input_value'
|
40
|
+
require_relative 'core/input_base/input_data'
|
41
|
+
require_relative 'core/input_base/loader'
|
42
|
+
require_relative 'core/input_base/json_loader'
|
43
|
+
require_relative 'core/input_base/yaml_loader'
|
44
|
+
require_relative 'core/input_base/component'
|
45
|
+
require_relative 'core/input_base/component_factory'
|
46
|
+
require_relative 'core/input_base/input_matcher'
|
47
|
+
require_relative 'core/input_base/verifier'
|
48
|
+
require_relative 'core/input_base/property'
|
49
|
+
require_relative 'core/input_base/feature'
|
50
|
+
require_relative 'core/input_base/feature_factory'
|
51
|
+
|
52
|
+
require_relative 'core/configuration/error'
|
53
|
+
require_relative 'core/configuration/component'
|
54
|
+
require_relative 'core/configuration/component_factory'
|
55
|
+
require_relative 'core/configuration/feature'
|
56
|
+
require_relative 'core/configuration/feature_factory'
|
57
|
+
require_relative 'core/configuration/loader'
|
58
|
+
require_relative 'core/configuration/ruby_loader'
|
59
|
+
require_relative 'core/configuration/hash_loader'
|
60
|
+
require_relative 'core/configuration/json_loader'
|
61
|
+
require_relative 'core/configuration/yaml_loader'
|
62
|
+
require_relative 'core/configuration'
|
63
|
+
|
64
|
+
require_relative 'core/register_map/input_data'
|
65
|
+
require_relative 'core/register_map/error'
|
66
|
+
require_relative 'core/register_map/component'
|
67
|
+
require_relative 'core/register_map/component_factory'
|
68
|
+
require_relative 'core/register_map/feature'
|
69
|
+
require_relative 'core/register_map/feature_factory'
|
70
|
+
require_relative 'core/register_map/loader'
|
71
|
+
require_relative 'core/register_map/ruby_loader'
|
72
|
+
require_relative 'core/register_map/hash_loader'
|
73
|
+
require_relative 'core/register_map/json_loader'
|
74
|
+
require_relative 'core/register_map/yaml_loader'
|
75
|
+
require_relative 'core/register_map'
|
76
|
+
|
77
|
+
require_relative 'core/output_base/template_engine'
|
78
|
+
require_relative 'core/output_base/erb_engine'
|
79
|
+
require_relative 'core/output_base/code_generator'
|
80
|
+
require_relative 'core/output_base/file_writer'
|
81
|
+
require_relative 'core/output_base/component'
|
82
|
+
require_relative 'core/output_base/component_factory'
|
83
|
+
require_relative 'core/output_base/feature'
|
84
|
+
require_relative 'core/output_base/feature_factory'
|
85
|
+
|
86
|
+
require_relative 'core/builder/component_entry'
|
87
|
+
require_relative 'core/builder/component_registry'
|
88
|
+
require_relative 'core/builder/input_component_registry'
|
89
|
+
require_relative 'core/builder/output_component_registry'
|
90
|
+
require_relative 'core/builder/simple_feature_entry'
|
91
|
+
require_relative 'core/builder/list_feature_entry'
|
92
|
+
require_relative 'core/builder/feature_registry'
|
93
|
+
require_relative 'core/builder/category'
|
94
|
+
require_relative 'core/builder/builder'
|
95
|
+
require_relative 'core/builder'
|
96
|
+
|
97
|
+
require_relative 'core/printers'
|
98
|
+
require_relative 'core/options'
|
99
|
+
require_relative 'core/dsl'
|
100
|
+
require_relative 'core/generator'
|
101
|
+
require_relative 'core/cli'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Base
|
6
|
+
class Component
|
7
|
+
include SingleForwardable
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
@parent = args.first
|
11
|
+
@children = []
|
12
|
+
@need_children = true
|
13
|
+
@level = (parent && parent.level + 1) || 0
|
14
|
+
@features = {}
|
15
|
+
post_initialize(*args)
|
16
|
+
block_given? && yield(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :parent
|
20
|
+
attr_reader :children
|
21
|
+
attr_reader :level
|
22
|
+
|
23
|
+
def need_children?
|
24
|
+
@need_children
|
25
|
+
end
|
26
|
+
|
27
|
+
def need_no_children
|
28
|
+
@need_children = false
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_child(child)
|
32
|
+
need_children? && (children << child)
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_feature(feature)
|
36
|
+
@features[feature.feature_name] = feature
|
37
|
+
end
|
38
|
+
|
39
|
+
def features
|
40
|
+
@features.values
|
41
|
+
end
|
42
|
+
|
43
|
+
def feature(key)
|
44
|
+
@features[key]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def post_initialize(*argv)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Base
|
6
|
+
class ComponentFactory
|
7
|
+
def initialize
|
8
|
+
@root_factory = false
|
9
|
+
block_given? && yield(self)
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_setter :target_component
|
13
|
+
attr_setter :feature_factories
|
14
|
+
attr_setter :child_factory
|
15
|
+
|
16
|
+
def root_factory
|
17
|
+
@root_factory = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(*args)
|
21
|
+
parent, sources =
|
22
|
+
if root_factory?
|
23
|
+
[nil, preprocess(args)]
|
24
|
+
else
|
25
|
+
[args.first, preprocess(args[1..-1])]
|
26
|
+
end
|
27
|
+
create_component(parent, *sources) do |component|
|
28
|
+
build_component(parent, component, sources)
|
29
|
+
root_factory? && finalize(component)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def root_factory?
|
36
|
+
@root_factory
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_component(parent, component, sources)
|
40
|
+
do_create_features(component, sources)
|
41
|
+
do_create_children(component, sources)
|
42
|
+
post_build(component)
|
43
|
+
parent&.add_child(component)
|
44
|
+
end
|
45
|
+
|
46
|
+
def do_create_features(component, sources)
|
47
|
+
return unless create_features?
|
48
|
+
create_features(component, *sources)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_features?
|
52
|
+
@feature_factories
|
53
|
+
end
|
54
|
+
|
55
|
+
def do_create_children(component, sources)
|
56
|
+
return unless create_children?(component)
|
57
|
+
create_children(component, *sources)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_children?(component)
|
61
|
+
@child_factory && component.need_children?
|
62
|
+
end
|
63
|
+
|
64
|
+
def preprocess(args)
|
65
|
+
args
|
66
|
+
end
|
67
|
+
|
68
|
+
def post_build(_component)
|
69
|
+
end
|
70
|
+
|
71
|
+
def finalize(_component)
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_feature(component, factory, *args)
|
75
|
+
factory.create(component, *args)
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_child(component, *args)
|
79
|
+
@child_factory.create(component, *args)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Base
|
6
|
+
class Feature
|
7
|
+
include InternalStruct
|
8
|
+
extend SharedContext
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def initialize(component, feature_name)
|
12
|
+
@component = component
|
13
|
+
@feature_name = feature_name
|
14
|
+
post_initialize
|
15
|
+
block_given? && yield(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :component
|
19
|
+
attr_reader :feature_name
|
20
|
+
|
21
|
+
class << self
|
22
|
+
private
|
23
|
+
|
24
|
+
def define_helpers(&body)
|
25
|
+
singleton_class.class_exec(&body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def available?(&body)
|
29
|
+
define_method(:available?, &body)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
available? { true }
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def post_initialize
|
38
|
+
end
|
39
|
+
|
40
|
+
def helper
|
41
|
+
self.class
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Base
|
6
|
+
class FeatureFactory
|
7
|
+
extend SharedContext
|
8
|
+
|
9
|
+
def initialize(feature_name)
|
10
|
+
@feature_name = feature_name
|
11
|
+
block_given? && yield(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_setter :target_feature
|
15
|
+
attr_setter :target_features
|
16
|
+
|
17
|
+
def create_feature(component, *args)
|
18
|
+
klass = select_target_feature(*args)
|
19
|
+
klass.new(component, @feature_name) do |feature|
|
20
|
+
feature.available? || break
|
21
|
+
block_given? && yield(feature)
|
22
|
+
component.add_feature(feature)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def select_target_feature(*args)
|
29
|
+
(@target_features && select_feature(*args)) || @target_feature
|
30
|
+
end
|
31
|
+
|
32
|
+
def select_feature(*args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|