feature_pack 0.6.3 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3320e77e931453c8b0aa6557b56f71752dc31bf74894bbd6e3d43219338ce0b2
4
- data.tar.gz: 66a8cffdcb05e69903bded94b3a634fa1bfab66a37e5192ce9f3627704cd1a5f
3
+ metadata.gz: f70a5116de8367b0eecf7c72cbab4762b6c28ded77c2cfd7b0df4369e4d82431
4
+ data.tar.gz: ca02d7cc7f78755908a3adec71641b8740f423cf7eab65d5b2f92c0b1755e861
5
5
  SHA512:
6
- metadata.gz: 0aae33cb5796721c39ee8ed02951592ff754581f0d40f481835f8fc1d98fa7bcc8296478b9dce8107335ecd4653d9d1ead0d19ad6805f024fcd659056f8686ef
7
- data.tar.gz: 07002ee9863ed1db06875d1ff79916367c291dc61419c6bd6605f7b6bcebe6865dc8f2c96c91a5925fc9bbc4d0f214daddfee613b573c5eb6688a5a9ac248e18
6
+ metadata.gz: 8b9ea87e71245fc6d56827d933b4ca32ebd6e1e1a8c144b1ba62ca4a005fce36244414a6c278b4f0ff5e263e73ebc0b71617b09f9fba16816804c4cad7ea3d79
7
+ data.tar.gz: d135218c290abdd63c24c13f5e8944854e4bb186bb1db9982164ac7f52fe19a93e6c6f67e0d07f58d95baeeaf553a32fa021d9053f9513e0a0f40526ac43050c
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
- ## Javascript
6
- `Javascript` must be on the FeaturePack root dir, not inside views dir.
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
- ## Installation
9
- Meanwhile installer isn't done, follow the steps below to install FeaturePack GEM:
9
+ #### Naming Convention
10
+ Sample: `group_departments-100100_human_resources`
10
11
 
11
- ```ruby
12
- # Add feature_pack to Gemfile
13
- gem 'feature_pack'
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
- ```bash
17
- bundle install
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
- Setup loading
21
- ```ruby
22
- # config/application.rb
20
+ The `_group_space` directory contains:
23
21
 
24
- feature_packs_path = Rails.root.join('app/feature_packs')
25
- FeaturePack.setup(features_path: feature_packs_path)
22
+ - `views/` - Views of the group
23
+ #### Common Files in _group_space/views
26
24
 
27
- FeaturePack.ignored_paths.each { |path| Rails.autoloaders.main.ignore(Rails.root.join(path)) }
25
+ The `_group_space/views` directory typically contains these common files:
28
26
 
29
- config.eager_load_paths << FeaturePack.features_path
30
- config.paths['app/views'] << FeaturePack.features_path
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
- config.paths['config/routes'] << (FeaturePack.path.to_s << '/feature_pack')
33
- config.paths['config/routes'] << FeaturePack.features_path
34
- config.assets.paths << FeaturePack.features_path.to_s
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
- Zeitwerk::Loader.eager_load_all
40
+ #### How implement a new Group
41
+ ```
42
+ rails generate feature_pack:add_gruop <group_name>
43
+ ```
37
44
 
38
- config.after_initialize do
39
- load FeaturePack.path.join('feature_pack/group_controller.rb')
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
- FeaturePack.groups_controllers_paths.each { |group_controller_path| load group_controller_path }
43
- FeaturePack.features_controllers_paths.each { |controller_path| load controller_path }
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
- ```ruby
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
- # app/helpers/application_helper.rb
70
- def feature_pack_group_path(group, *params) = send("feature_pack_#{group.name}_path".to_sym, *params)
71
- def feature_pack_path(group, feature, *params) = send("feature_pack_#{group.name}_#{feature.name}_path".to_sym, *params)
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
- ```ruby
75
- # config/initializers/assets.rb
64
+ ## Helpers
76
65
 
77
- Rails.application.config.assets.precompile += FeaturePack.javascript_files_paths
78
- ```
66
+ ### Using the `feature_pack_group_path` and `feature_pack_path` Helpers
79
67
 
80
- ```ruby
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
- FeaturePack.javascript_files_paths.each do |js_file_path|
84
- extensionless_js_file_path = js_file_path.delete_suffix('.js')
85
- pin extensionless_js_file_path, to: extensionless_js_file_path, preload: false
86
- end
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
- ```ruby
90
- # config/routes.rb
91
- namespace :feature_pack, path: nil do
92
- draw :feature_pack_routes
93
- end
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.
data/doc/changelog.md ADDED
@@ -0,0 +1,2 @@
1
+ ## [0.8.0] - 2025-02-09
2
+ - Melhoria no gemspec: uso de variável 'spec', resumo aprimorado, descrição formatada com HEREDOC, substituição de Dir[] por Dir.glob e adição de metadata.
@@ -1,12 +1,16 @@
1
1
  class FeaturePack::Controller < ApplicationController
2
- before_action :set_group_and_feature
3
- before_action :set_view_lookup_context_prefix
4
- before_action :set_layout_paths
2
+ prepend_before_action :setup_feature
5
3
 
6
4
  def index; end
7
5
 
8
6
  private
9
7
 
8
+ def setup_feature
9
+ set_group_and_feature
10
+ set_view_lookup_context_prefix
11
+ set_layout_paths
12
+ end
13
+
10
14
  def set_group_and_feature
11
15
  group_name, feature_name = params['controller'].delete_prefix('feature_pack/').split('/').map(&:to_sym)
12
16
  @group = FeaturePack.group group_name
@@ -14,19 +18,17 @@ class FeaturePack::Controller < ApplicationController
14
18
  end
15
19
 
16
20
  def set_view_lookup_context_prefix
17
- unless lookup_context.prefixes.include?(@feature.views_relative_path)
18
- lookup_context.prefixes.prepend(@feature.views_relative_path)
19
- end
21
+ return if lookup_context.prefixes.include?(@feature.views_relative_path)
22
+
23
+ lookup_context.prefixes.prepend(@feature.views_relative_path)
20
24
  end
21
25
 
22
26
  def set_layout_paths
23
- =begin
24
- Header/Footer Lookup order
25
-
26
- - Feature dir/_partials, if not exists
27
- - Fallback to Group, if not exists
28
- - Fallback to Application's default header/footer
29
- =end
27
+ # Header/Footer Lookup order
28
+ #
29
+ # - Feature dir/_partials, if not exists
30
+ # - Fallback to Group, if not exists
31
+ # - Fallback to Application's default header/footer
30
32
 
31
33
  feature_partials_path = @feature.views_relative_path.join('partials')
32
34
  group_partials_path = @feature.group.views_path.concat('/partials')
@@ -1,20 +1,15 @@
1
1
  FeaturePack.groups.each do |group|
2
- unless group.manifest[:namespace_only]
3
- # Default 'index' route every group has to have.
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
- unless group.routes_file.nil?
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.name.pluralize do
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
@@ -1,32 +1,33 @@
1
1
  class FeaturePack::GroupController < ApplicationController
2
- before_action :set_group
3
- before_action :set_view_lookup_context_prefix
4
- before_action :set_layout_paths
5
-
2
+ prepend_before_action :setup_group
6
3
  def index; end
7
4
 
8
5
  private
9
6
 
7
+ def setup_group
8
+ set_group
9
+ set_view_lookup_context_prefix
10
+ set_layout_paths
11
+ end
12
+
10
13
  def set_group
11
14
  group_name = params[:controller].split('/')[1].to_sym
12
15
  @group = FeaturePack.group(group_name)
13
16
  end
14
17
 
15
18
  def set_view_lookup_context_prefix
16
- unless lookup_context.prefixes.include?(@group.views_path)
17
- lookup_context.prefixes.prepend(@group.views_path)
18
- end
19
+ return if lookup_context.prefixes.include?(@group.views_path)
20
+
21
+ lookup_context.prefixes.prepend(@group.views_path)
19
22
  end
20
23
 
21
24
  def set_layout_paths
22
25
  patials_path = @group.views_path.concat('/partials')
23
26
 
24
- if template_exists?('header', patials_path, true)
25
- @header_layout_path = @group.view('partials/header')
26
- end
27
+ @header_layout_path = @group.view('partials/header') if template_exists?('header', patials_path, true)
28
+
29
+ return unless template_exists?('footer', patials_path, true)
27
30
 
28
- if template_exists?('footer', patials_path, true)
29
- @footer_layout_path = @group.view('partials/footer')
30
- end
31
+ @footer_layout_path = @group.view('partials/footer')
31
32
  end
32
33
  end
@@ -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.disabled.tt', group_dir.join('_group_space', 'routes.rb.disabled')
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', group_dir.join('_group_space', 'views/partials/_header.html.slim')
26
- template './_group_space/views/partials/_footer.html.slim.tt', group_dir.join('_group_space', 'views/partials/_footer.html.slim')
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
@@ -1,3 +1,2 @@
1
1
  name: Group Friendly Name Here
2
2
  url: <%= name.gsub('_', '-') %>
3
- namespace_only: false
@@ -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.6.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-06 00:00:00.000000000 Z
10
+ date: 2025-02-09 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -30,16 +29,17 @@ dependencies:
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
31
  version: '9.0'
33
- description: Organizes and sets up the architecture of micro-applications within a
34
- Rails application, enabling the segregation of code, management, and isolation of
35
- functionalities, which can be developed, tested, and maintained independently of
36
- each other.
32
+ description: |
33
+ Organizes and sets up the architecture of micro-applications within a Rails application,
34
+ enabling segregation, management, and isolation of functionalities, thereby supporting
35
+ independent development, testing, and maintenance.
37
36
  email: gedean.dias@gmail.com
38
37
  executables: []
39
38
  extensions: []
40
39
  extra_rdoc_files: []
41
40
  files:
42
41
  - README.md
42
+ - doc/changelog.md
43
43
  - doc/feature_pack.md
44
44
  - lib/feature_pack.rb
45
45
  - lib/feature_pack/api/controller.rb
@@ -60,15 +60,18 @@ files:
60
60
  - lib/generators/feature_pack/add_group/add_group_generator.rb
61
61
  - lib/generators/feature_pack/add_group/templates/_group_space/controller.rb.tt
62
62
  - lib/generators/feature_pack/add_group/templates/_group_space/manifest.yaml.tt
63
- - lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.disabled.tt
63
+ - lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.tt
64
64
  - lib/generators/feature_pack/add_group/templates/_group_space/views/index.html.slim.tt
65
65
  - lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_footer.html.slim.tt
66
66
  - lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_header.html.slim.tt
67
67
  homepage: https://github.com/gedean/feature_pack
68
68
  licenses:
69
69
  - MIT
70
- metadata: {}
71
- post_install_message: Please check readme file for use instructions.
70
+ metadata:
71
+ bug_tracker_uri: https://github.com/gedean/feature_pack/issues
72
+ source_code_uri: https://github.com/gedean/feature_pack
73
+ changelog_uri: https://github.com/gedean/feature_pack/blob/main/CHANGELOG.MD
74
+ post_install_message: Please check the README file for use instructions.
72
75
  rdoc_options: []
73
76
  require_paths:
74
77
  - lib
@@ -83,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
85
88
  requirements: []
86
- rubygems_version: 3.5.23
87
- signing_key:
89
+ rubygems_version: 3.6.3
88
90
  specification_version: 4
89
- summary: A different way to organize app features in Rails.
91
+ summary: A different approach to organizing Rails app features.
90
92
  test_files: []
@@ -1,3 +0,0 @@
1
- # You don't need enable this file if the only action is 'index'
2
-
3
- get '/action-name-url', to: '<%= name %>#action_name'