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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5911a157f2063b3ae77afce5727908597d1e41c0c3fcb0934dce7cf88b825946
4
- data.tar.gz: b2e6695f5466e4eec17e23555afdfa30ecd7ec1b56ebb419ae039ddc4b7b605f
3
+ metadata.gz: bd71ce9bce49e1aeb7eab0f90082368e855a4c008f2e16428e5471c2a42db9f4
4
+ data.tar.gz: ddd54c8b5bc72def245c0d580d72914121aca811cda1debb56e81d43f6af1ad6
5
5
  SHA512:
6
- metadata.gz: cdb9ca937aae5ea9e2810099996e9ebbac820893a7f33d3fe6a2da3156f25a8a8f649af2b1ba619f4935d2c53fc3ba2fd1add7dfd09d62c867031442a6bbe49a
7
- data.tar.gz: 20ca4ea74992475d362f3eb9b1edb66a8f871ac5ec0961acba89df8e8deae8a1bfffaa85eafc260651f68edef123fd6e96c20450b62d1348dce23922105dd558
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
- ## 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.
@@ -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
@@ -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
@@ -5,7 +5,7 @@
5
5
  :version: 1.0.0
6
6
  #const_aliases:
7
7
  # - :params_class: 'Processor::Params'
8
- :policy:
8
+ :access_policy:
9
9
  :admin: '*'
10
10
  :coordenacao_aps: '*'
11
11
  :coordenacao_atividade_fisica: '*'
@@ -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.1
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: 2024-11-18 00:00:00.000000000 Z
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.disabled.tt
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.5.23
87
- signing_key:
85
+ rubygems_version: 3.6.3
88
86
  specification_version: 4
89
- summary: New way to organize app features in Rails.
87
+ summary: A different way to organize app features in Rails.
90
88
  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'