feature_pack 0.6.1 → 0.7.0
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.
- checksums.yaml +4 -4
- data/README.md +68 -71
- data/lib/feature_pack/feature_pack_routes.rb +6 -11
- data/lib/feature_pack/group_controller.rb +1 -1
- data/lib/generators/feature_pack/add_feature/templates/manifest.yaml.tt +1 -1
- data/lib/generators/feature_pack/add_group/add_group_generator.rb +5 -4
- data/lib/generators/feature_pack/add_group/templates/_group_space/manifest.yaml.tt +0 -1
- data/lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.tt +1 -0
- metadata +5 -7
- data/lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.disabled.tt +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd71ce9bce49e1aeb7eab0f90082368e855a4c008f2e16428e5471c2a42db9f4
|
4
|
+
data.tar.gz: ddd54c8b5bc72def245c0d580d72914121aca811cda1debb56e81d43f6af1ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9772f47ad2adf747b7086203a9d8fa4e3d817c80eba21d8a22e978faa11fa1861a5134dceb11364f2748a1ca2f2654d4a3d5d6063d73bbf93f463ba8182a5a3
|
7
|
+
data.tar.gz: 1957dc76a52fc033ba7b8793d2d466fb4465da07c57b066c4ca441d3b5b5b4b3512f8f29272df378ab0b54bc5e7a6bb25a21f72773724552b81c4f0e365ec158
|
data/README.md
CHANGED
@@ -1,94 +1,91 @@
|
|
1
|
-
# Feature Pack
|
2
|
-
Organizes and sets up the architecture of micro-applications within a Rails application, enabling the segregation of code, management, and isolation of functionalities, which can be developed, tested, and maintained independently of each other.
|
1
|
+
# Feature Pack Gem
|
2
|
+
Organizes and sets up the architecture of micro-applications within a Ruby On Rails application, enabling the segregation of code, management, and isolation of functionalities, which can be developed, tested, and maintained independently of each other.
|
3
3
|
|
4
|
+
## Code and Folder Structure
|
4
5
|
|
5
|
-
|
6
|
-
`
|
6
|
+
### Group
|
7
|
+
A group is a collection of related features. Groups are represented as directories in the `app/feature_packs` folder. Each group contains a `_group_space` directory that holds group-level views and JavaScript files. Group directories follow this naming pattern:
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
#### Naming Convention
|
10
|
+
Sample: `group_departments-100100_human_resources`
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
```
|
12
|
+
`group_` prefix is followed by the group identification (required)
|
13
|
+
`departments-100100` between `group_` and class name, exists only for organization purposes. The bounds are `group_` and next underscore `_`
|
14
|
+
`human_resources` class name of the group (required)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
#### Note worthy
|
17
|
+
Group name is the same as the class name. Its used internally in the backend code.
|
18
|
+
The 'Name' within the manifest file (Group.manifest[:name]) is the name to be shown in the user interface.
|
19
19
|
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
# config/application.rb
|
20
|
+
The `_group_space` directory contains:
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
- `views/` - Views of the group
|
23
|
+
#### Common Files in _group_space/views
|
26
24
|
|
27
|
-
|
25
|
+
The `_group_space/views` directory typically contains these common files:
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
```
|
28
|
+
_group_space/views/
|
29
|
+
├── index.html.slim # Default view for the group
|
30
|
+
└── partials/
|
31
|
+
└── _header.html.slim # Base header template for the group
|
32
|
+
└── _footer.html.slim # Base footer template for the group
|
33
|
+
```
|
34
|
+
Can have more views and partials, depending on the defined on `controller.rb` but these are the most common ones.
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
- `javascript/` - Group-level JavaScript modules shared across features
|
37
|
+
- `controller.rb` - Base controller class for the group's features
|
38
|
+
- `routes.rb` - The routes files come with the default `index` action/view.
|
35
39
|
|
36
|
-
|
40
|
+
#### How implement a new Group
|
41
|
+
```
|
42
|
+
rails generate feature_pack:add_gruop <group_name>
|
43
|
+
```
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
load FeaturePack.path.join('feature_pack/controller.rb')
|
45
|
+
### Feature
|
46
|
+
A feature is a single feature that can be added to a group. Feature naming patter is the same of group, but without the `group_` prefix.
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
```
|
48
|
+
#### Feature Routes
|
49
|
+
Every feature has a default route, which is the `index` action/view. If the feature has more than the default `index` action/view, the routes are defined in the `routes.rb` file.
|
46
50
|
|
47
|
-
|
48
|
-
# initializers/feature_pack.rb
|
49
|
-
|
50
|
-
FeaturePack.groups.each do |group|
|
51
|
-
group_module = FeaturePack.const_set(group.name.name.camelize, Module.new)
|
52
|
-
|
53
|
-
%w[Lib AI Jobs].each do |submodule_name|
|
54
|
-
submodule_path = File.join(group.relative_path, '_group_space', submodule_name.downcase)
|
55
|
-
if Dir.exist?(submodule_path)
|
56
|
-
submodule = group_module.const_set(submodule_name, Module.new)
|
57
|
-
Rails.autoloaders.main.push_dir(submodule_path, namespace: submodule)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
group.features.each do |feature|
|
62
|
-
feature_module = group_module.const_set(feature.name.name.camelize, Module.new)
|
63
|
-
Rails.autoloaders.main.push_dir(feature.relative_path, namespace: feature_module)
|
64
|
-
end
|
65
|
-
end
|
51
|
+
#### How implement a new feature
|
66
52
|
```
|
53
|
+
rails generate feature_pack:add_feature <group_name>/<feature_name>
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Helpers
|
67
57
|
|
68
58
|
```ruby
|
69
|
-
#
|
70
|
-
|
71
|
-
|
59
|
+
# Application Helper
|
60
|
+
def feature_pack_group_path(group_name, *params) = send("feature_pack_#{group_name}_path".to_sym, *params)
|
61
|
+
def feature_pack_path(group_name, feature_name, *params) = send("feature_pack_#{group_name}_#{feature_name}_path".to_sym, *params)
|
72
62
|
```
|
73
63
|
|
74
|
-
|
75
|
-
# config/initializers/assets.rb
|
64
|
+
## Helpers
|
76
65
|
|
77
|
-
|
78
|
-
```
|
66
|
+
### Using the `feature_pack_group_path` and `feature_pack_path` Helpers
|
79
67
|
|
80
|
-
|
81
|
-
# config/importmap.rb
|
68
|
+
The `feature_pack_group_path` and `feature_pack_path` helpers are used to generate URLs for specific groups and features within the feature package system.
|
82
69
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
70
|
+
- `feature_pack_group_path(group, *params)`: Generates the path for a specific group. The `group` parameter should be an object representing the desired group. Additional parameters can be passed to specify more details in the URL.
|
71
|
+
|
72
|
+
**Usage example:**
|
73
|
+
```ruby
|
74
|
+
# Assuming `group` is a valid group name in symbol
|
75
|
+
group_url = feature_pack_group_path(:group_name)
|
76
|
+
```
|
88
77
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
- `feature_pack_path(group, feature, *params)`: Generates the path for a specific feature within a group. The `group` and `feature` parameters should be symbols of group and feature name, respectively. Additional parameters can be passed to specify more details in the URL.
|
79
|
+
|
80
|
+
**Usage example:**
|
81
|
+
```ruby
|
82
|
+
# Assuming `group` and `feature` are valid objects
|
83
|
+
feature_url = feature_pack_path(:my_group, :my_feature)
|
84
|
+
```
|
85
|
+
|
86
|
+
These helpers are useful for maintaining consistency and clarity when generating URLs within the application, ensuring that routes are correctly constructed based on the provided group and feature names.
|
87
|
+
|
88
|
+
## Variables
|
89
|
+
Current group and feature are available in the controller (so as in the views too) as `@group` and `@feature` variables.
|
90
|
+
@feature variable is not available in the group controller.
|
91
|
+
@group variable is available in the group controller and in the its features controllers.
|
@@ -1,20 +1,15 @@
|
|
1
1
|
FeaturePack.groups.each do |group|
|
2
|
-
|
3
|
-
|
4
|
-
get group.manifest[:url],
|
5
|
-
to: "#{group.name.name}#index",
|
6
|
-
as: group.name.name
|
2
|
+
scope group.manifest[:url], as: group.name do
|
3
|
+
raise "Group '#{group.name}' routes file not found in #{group.metadata_path}" if group.routes_file.nil?
|
7
4
|
|
8
|
-
|
9
|
-
scope group.manifest[:url] do
|
10
|
-
draw(group.routes_file)
|
11
|
-
end
|
12
|
-
end
|
5
|
+
draw(group.routes_file)
|
13
6
|
end
|
14
7
|
|
15
8
|
namespace group.name, path: group.manifest[:url] do
|
16
9
|
group.features.each do |feature|
|
17
|
-
scope feature.manifest[:url], as: feature.name
|
10
|
+
scope feature.manifest[:url], as: feature.name do
|
11
|
+
raise "Feature '#{feature.name}' routes file not found in #{feature.routes_file}" if feature.routes_file.nil?
|
12
|
+
|
18
13
|
draw(feature.routes_file)
|
19
14
|
end
|
20
15
|
end
|
@@ -9,7 +9,7 @@ class FeaturePack::GroupController < ApplicationController
|
|
9
9
|
|
10
10
|
def set_group
|
11
11
|
group_name = params[:controller].split('/')[1].to_sym
|
12
|
-
@group = FeaturePack.group(group_name)
|
12
|
+
@group = FeaturePack.group(group_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
def set_view_lookup_context_prefix
|
@@ -2,7 +2,6 @@ require 'rails/generators/base'
|
|
2
2
|
require 'rails/generators/named_base'
|
3
3
|
|
4
4
|
class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
|
5
|
-
|
6
5
|
desc 'Adds a new Feature Group'
|
7
6
|
source_root File.expand_path('templates', __dir__)
|
8
7
|
|
@@ -20,9 +19,11 @@ class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
|
|
20
19
|
|
21
20
|
template './_group_space/controller.rb.tt', group_dir.join('_group_space', 'controller.rb')
|
22
21
|
template './_group_space/manifest.yaml.tt', group_dir.join('_group_space', 'manifest.yaml')
|
23
|
-
template './_group_space/routes.rb.
|
22
|
+
template './_group_space/routes.rb.tt', group_dir.join('_group_space', 'routes.rb')
|
24
23
|
template './_group_space/views/index.html.slim.tt', group_dir.join('_group_space', 'views/index.html.slim')
|
25
|
-
template './_group_space/views/partials/_header.html.slim.tt',
|
26
|
-
|
24
|
+
template './_group_space/views/partials/_header.html.slim.tt',
|
25
|
+
group_dir.join('_group_space', 'views/partials/_header.html.slim')
|
26
|
+
template './_group_space/views/partials/_footer.html.slim.tt',
|
27
|
+
group_dir.join('_group_space', 'views/partials/_footer.html.slim')
|
27
28
|
end
|
28
29
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
get '/', to: '<%= name %>#index'
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gedean Dias
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-26 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -60,7 +59,7 @@ files:
|
|
60
59
|
- lib/generators/feature_pack/add_group/add_group_generator.rb
|
61
60
|
- lib/generators/feature_pack/add_group/templates/_group_space/controller.rb.tt
|
62
61
|
- lib/generators/feature_pack/add_group/templates/_group_space/manifest.yaml.tt
|
63
|
-
- lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.
|
62
|
+
- lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.tt
|
64
63
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/index.html.slim.tt
|
65
64
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_footer.html.slim.tt
|
66
65
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_header.html.slim.tt
|
@@ -83,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
82
|
- !ruby/object:Gem::Version
|
84
83
|
version: '0'
|
85
84
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
85
|
+
rubygems_version: 3.6.3
|
88
86
|
specification_version: 4
|
89
|
-
summary:
|
87
|
+
summary: A different way to organize app features in Rails.
|
90
88
|
test_files: []
|