feature_pack 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4d4c06a3ac9cc919e20a0616c0ec7b0d1da2553f43a4c5b140ef7a8bc29147a
4
- data.tar.gz: 21ae0804c870c884ee4270168327fa81eade33b261bb4adb915f87f49764ca41
3
+ metadata.gz: dd18a6901bd123d6449e6570022136ecbd36e473b0cf572f27f6c91f80bd702d
4
+ data.tar.gz: 322a89e29a1e357dd6680f31b30adda1f53fcaf4139a8357bbf855e3a27287ae
5
5
  SHA512:
6
- metadata.gz: a66fab958817fe7391449fe39d04043b9729e3bfc4a40b18e8ad6458e4a2f2c6a7ff863dfb0c8acf5841024bfdb34bb48e79c631c58949d655d1d0ca809fb8ec
7
- data.tar.gz: bcc1750715d4f4a88587b557bd75e5ed0e3c698fec80a1691942b5ff895ecd3b6041636dd4b325de811d3008551a1244aa10635b5a28e7180a41642a86420b54
6
+ metadata.gz: 2efc9f88f00cfdad138a79cab42c1cbda2e10a9147ecf37bbf5991bd024a5eb1cdc7e23f297ed442d2f9f20c5a488d11da714aec7e026f8fdf13a49c74463120
7
+ data.tar.gz: df6e3f3a8635ca73b43caef82c78f6cb1d13c8bc90a249d72ee2c74ddf09e554b9ab68c52ef643658f8cdd1aafea30101ee72cf737285400f4237b7bef877fcb
data/README.md CHANGED
@@ -51,7 +51,7 @@ FeaturePack.groups.each do |group|
51
51
  group_module = FeaturePack.const_set(group.name.name.camelize, Module.new)
52
52
 
53
53
  %w[Lib AI Jobs].each do |submodule_name|
54
- submodule_path = File.join(group.relative_path, '_group_metadata', submodule_name.downcase)
54
+ submodule_path = File.join(group.relative_path, '_group_space', submodule_name.downcase)
55
55
  if Dir.exist?(submodule_path)
56
56
  submodule = group_module.const_set(submodule_name, Module.new)
57
57
  Rails.autoloaders.main.push_dir(submodule_path, namespace: submodule)
@@ -0,0 +1,122 @@
1
+ # FeaturePack Library Documentation
2
+
3
+ ## Overview
4
+
5
+ The `FeaturePack` library is a Ruby module designed to manage and organize feature groups and individual features within a Rails application. It provides a structured way to handle feature-specific routes, controllers, views, and JavaScript files.
6
+
7
+ ## Key Components
8
+
9
+ ### Constants
10
+
11
+ - `GROUP_ID_PATTERN`: Regex pattern for group IDs
12
+ - `FEATURE_ID_PATTERN`: Regex pattern for feature IDs
13
+ - `GROUP_METADATA_DIRECTORY`: Name of the directory containing group metadata
14
+ - `MANIFEST_FILE_NAME`: Name of the manifest file for groups and features
15
+ - `CONTROLLER_FILE_NAME`: Name of the controller file
16
+
17
+ ### Attributes
18
+
19
+ The module defines several read-only attributes:
20
+
21
+ - `path`: Path to the FeaturePack library
22
+ - `features_path`: Path to the features directory
23
+ - `ignored_paths`: Paths to be ignored
24
+ - `groups`: Array of group objects
25
+ - `groups_controllers_paths`: Paths to group controllers
26
+ - `features_controllers_paths`: Paths to feature controllers
27
+ - `javascript_files_paths`: Paths to JavaScript files
28
+
29
+ ## Setup
30
+
31
+ The `setup` method initializes the FeaturePack library:
32
+
33
+ 1. Validates the provided `features_path`
34
+ 2. Sets up ignored paths
35
+ 3. Discovers and initializes groups and features
36
+ 4. Sets up routes and controllers for groups and features
37
+
38
+ ### Usage
39
+
40
+ ```ruby
41
+ FeaturePack.setup(features_path: '/path/to/features')
42
+ ```
43
+
44
+ ## Groups
45
+
46
+ Groups are represented as `OpenStruct` objects with the following properties:
47
+
48
+ - `id`: Unique identifier for the group
49
+ - `name`: Human-readable name of the group
50
+ - `metadata_path`: Path to the group's metadata directory
51
+ - `relative_path`: Relative path to the group directory
52
+ - `base_dir`: Base directory name
53
+ - `routes_file`: Path to the group's routes file (if exists)
54
+ - `features`: Array of feature objects belonging to this group
55
+ - `manifest`: Parsed content of the group's manifest file
56
+
57
+ Groups also have methods for accessing views and JavaScript modules.
58
+
59
+ ## Features
60
+
61
+ Features are represented as `OpenStruct` objects with the following properties:
62
+
63
+ - `id`: Unique identifier for the feature
64
+ - `name`: Human-readable name of the feature
65
+ - `group`: Reference to the parent group object
66
+ - `absolute_path`: Absolute path to the feature directory
67
+ - `relative_path`: Relative path to the feature directory
68
+ - `sub_path`: Sub-path of the feature directory
69
+ - `routes_file_path`: Path to the feature's routes file
70
+ - `routes_file`: Route name for the feature
71
+ - `views_absolute_path`: Absolute path to the feature's views
72
+ - `views_relative_path`: Relative path to the feature's views
73
+ - `javascript_relative_path`: Relative path to the feature's JavaScript files
74
+ - `manifest`: Parsed content of the feature's manifest file
75
+
76
+ Features also have methods for accessing their class name, namespace, views, and JavaScript modules.
77
+
78
+ ## Utility Methods
79
+
80
+ - `FeaturePack.group(group_name)`: Finds a group by name
81
+ - `FeaturePack.feature(group_name, feature_name)`: Finds a feature within a group
82
+
83
+ ## File Structure
84
+
85
+ The library expects the following file structure:
86
+
87
+ ```
88
+ features_path/
89
+ ├── group_name_1/
90
+ │ ├── _group_space/
91
+ │ │ ├── manifest.yaml
92
+ │ │ ├── controller.rb
93
+ │ │ └── routes.rb (optional)
94
+ │ ├── feature_name_1/
95
+ │ │ ├── manifest.yaml
96
+ │ │ ├── controller.rb
97
+ │ │ └── routes.rb
98
+ │ └── feature_name_2/
99
+ │ └── ...
100
+ └── group_name_2/
101
+ └── ...
102
+ ```
103
+
104
+ ## Manifest Files
105
+
106
+ Both groups and features use manifest files (`manifest.yaml`) to store metadata. These files can include `const_aliases` for defining method aliases to constants.
107
+
108
+ ## JavaScript Integration
109
+
110
+ The library automatically discovers and tracks JavaScript files within feature directories, making them accessible through the `javascript_files_paths` attribute.
111
+
112
+ ## Error Handling
113
+
114
+ The library includes basic error handling for invalid or non-existent paths and missing group/feature IDs.
115
+
116
+ ## Limitations and Notes
117
+
118
+ - The library assumes a specific directory structure and naming conventions.
119
+ - It relies on Rails' autoloading capabilities for controllers.
120
+ - Custom routes files for features are ignored to prevent conflicts with Rails' default routing.
121
+
122
+ This documentation provides an overview of the `FeaturePack` library's structure and functionality. For specific implementation details, refer to the inline comments and method definitions in the source code.
@@ -16,7 +16,7 @@ class FeaturePack::Controller < ApplicationController
16
16
  def set_view_lookup_context_prefix
17
17
  unless lookup_context.prefixes.include?(@feature.views_relative_path)
18
18
  lookup_context.prefixes.prepend(@feature.views_relative_path)
19
- end
19
+ end
20
20
  end
21
21
 
22
22
  def set_layout_paths
@@ -30,7 +30,7 @@ class FeaturePack::Controller < ApplicationController
30
30
 
31
31
  feature_partials_path = @feature.views_relative_path.join('partials')
32
32
  group_partials_path = @feature.group.views_path.concat('/partials')
33
-
33
+
34
34
  if template_exists?('header', feature_partials_path, true)
35
35
  @header_layout_path = @feature.view('partials/header')
36
36
  elsif template_exists?('header', group_partials_path, true)
@@ -3,4 +3,4 @@ module FeaturePack::Error
3
3
  end
4
4
  class NoGroup < StandardError
5
5
  end
6
- end
6
+ end
@@ -5,7 +5,7 @@ class FeaturePack::GroupController < ApplicationController
5
5
 
6
6
  def index; end
7
7
 
8
- private
8
+ private
9
9
 
10
10
  def set_group
11
11
  group_name = params[:controller].split('/')[1].to_sym
@@ -20,13 +20,13 @@ class FeaturePack::GroupController < ApplicationController
20
20
 
21
21
  def set_layout_paths
22
22
  patials_path = @group.views_path.concat('/partials')
23
-
23
+
24
24
  if template_exists?('header', patials_path, true)
25
25
  @header_layout_path = @group.view('partials/header')
26
26
  end
27
27
 
28
28
  if template_exists?('footer', patials_path, true)
29
29
  @footer_layout_path = @group.view('partials/footer')
30
- end
30
+ end
31
31
  end
32
32
  end
data/lib/feature_pack.rb CHANGED
@@ -3,7 +3,7 @@ require 'active_support/all'
3
3
  module FeaturePack
4
4
  GROUP_ID_PATTERN = /^group_.*?_/.freeze
5
5
  FEATURE_ID_PATTERN = /^feature_.*?_/.freeze
6
- GROUP_METADATA_DIRECTORY = '_group_metadata'.freeze
6
+ GROUP_SPACE_DIRECTORY = '_group_space'.freeze
7
7
  MANIFEST_FILE_NAME = 'manifest.yaml'.freeze
8
8
  CONTROLLER_FILE_NAME = 'controller.rb'.freeze
9
9
 
@@ -46,20 +46,20 @@ module FeaturePack
46
46
  base_path = File.basename(group_path, File::SEPARATOR)
47
47
 
48
48
  # On route draw call, the extension is ignored
49
- routes_file = File.exist?(File.join(group_path, GROUP_METADATA_DIRECTORY, 'routes.rb')) ? File.join(base_path, GROUP_METADATA_DIRECTORY, 'routes') : nil
49
+ routes_file = File.exist?(File.join(group_path, GROUP_SPACE_DIRECTORY, 'routes.rb')) ? File.join(base_path, GROUP_SPACE_DIRECTORY, 'routes') : nil
50
50
 
51
- @@groups_controllers_paths << File.join(group_path, GROUP_METADATA_DIRECTORY, CONTROLLER_FILE_NAME)
51
+ @@groups_controllers_paths << File.join(group_path, GROUP_SPACE_DIRECTORY, CONTROLLER_FILE_NAME)
52
52
 
53
53
  raise "Group '#{base_path}' does not have a valid ID" if base_path.scan(GROUP_ID_PATTERN).empty?
54
54
  group = OpenStruct.new(
55
55
  id: base_path.scan(GROUP_ID_PATTERN).first.delete_suffix('_'),
56
56
  name: base_path.gsub(GROUP_ID_PATTERN, '').to_sym,
57
- metadata_path: @@features_path.join(group_path, GROUP_METADATA_DIRECTORY),
57
+ metadata_path: @@features_path.join(group_path, GROUP_SPACE_DIRECTORY),
58
58
  relative_path: relative_path,
59
59
  base_dir: File.basename(relative_path, File::SEPARATOR),
60
60
  routes_file: routes_file,
61
61
  features: [],
62
- manifest: YAML.load_file(File.join(group_path, GROUP_METADATA_DIRECTORY, MANIFEST_FILE_NAME)).deep_symbolize_keys
62
+ manifest: YAML.load_file(File.join(group_path, GROUP_SPACE_DIRECTORY, MANIFEST_FILE_NAME)).deep_symbolize_keys
63
63
  )
64
64
 
65
65
  group.manifest.fetch(:const_aliases, []).each do |alias_data|
@@ -68,9 +68,9 @@ module FeaturePack
68
68
  end
69
69
 
70
70
  def group.feature(feature_name) = features.find { |p| p.name.eql?(feature_name) }
71
- def group.views_path = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views"
72
- def group.view(view_name) = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views/#{view_name}"
73
- def group.javascript_module(javascript_file_name) = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/javascript/#{javascript_file_name}"
71
+ def group.views_path = "#{base_dir}/#{GROUP_SPACE_DIRECTORY}/views"
72
+ def group.view(view_name) = "#{base_dir}/#{GROUP_SPACE_DIRECTORY}/views/#{view_name}"
73
+ def group.javascript_module(javascript_file_name) = "#{base_dir}/#{GROUP_SPACE_DIRECTORY}/javascript/#{javascript_file_name}"
74
74
 
75
75
  group
76
76
  end
@@ -121,7 +121,7 @@ module FeaturePack
121
121
  feature.define_singleton_method(alias_method_name) { "#{class_name}::#{alias_const_name}".constantize }
122
122
  end
123
123
 
124
- def feature.view(view_name) = "#{views_relative_path}/#{view_name}"
124
+ def feature.view(view_name) = "#{views_relative_path}/#{view_name}"
125
125
  def feature.javascript_module(javascript_file_name) = "#{javascript_relative_path}/#{javascript_file_name}"
126
126
 
127
127
  group.features << feature
@@ -18,11 +18,11 @@ class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
18
18
  group_id = name.gsub('_', '-') + '-' + '999'
19
19
  group_dir = FeaturePack.features_path.join("group_#{group_id}_#{name}")
20
20
 
21
- template './_group_metadata/controller.rb.tt', group_dir.join('_group_metadata', 'controller.rb')
22
- template './_group_metadata/manifest.yaml.tt', group_dir.join('_group_metadata', 'manifest.yaml')
23
- template './_group_metadata/routes.rb.disabled.tt', group_dir.join('_group_metadata', 'routes.rb.disabled')
24
- template './_group_metadata/views/index.html.slim.tt', group_dir.join('_group_metadata', 'views/index.html.slim')
25
- template './_group_metadata/views/partials/_header.html.slim.tt', group_dir.join('_group_metadata', 'views/partials/_header.html.slim')
26
- template './_group_metadata/views/partials/_footer.html.slim.tt', group_dir.join('_group_metadata', 'views/partials/_footer.html.slim')
21
+ template './_group_space/controller.rb.tt', group_dir.join('_group_space', 'controller.rb')
22
+ 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')
24
+ 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')
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.1'
19
+ version: '7.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.1'
26
+ version: '7.2'
27
27
  description: Organizes and sets up the architecture of micro-applications within a
28
28
  Rails application, enabling the segregation of code, management, and isolation of
29
29
  functionalities, which can be developed, tested, and maintained independently of
@@ -34,6 +34,7 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - README.md
37
+ - doc/feature_pack.md
37
38
  - lib/feature_pack.rb
38
39
  - lib/feature_pack/api/controller.rb
39
40
  - lib/feature_pack/controller.rb
@@ -46,7 +47,7 @@ files:
46
47
  - lib/generators/feature_pack/add_feature/templates/doc/readme.md.tt
47
48
  - lib/generators/feature_pack/add_feature/templates/manifest.yaml.tt
48
49
  - lib/generators/feature_pack/add_feature/templates/routes.rb.tt
49
- - lib/generators/feature_pack/add_feature/templates/views/home.html.slim.tt
50
+ - lib/generators/feature_pack/add_feature/templates/views/index.html.slim.tt
50
51
  - lib/generators/feature_pack/add_feature/templates/views/partials/_footer.html.slim.tt
51
52
  - lib/generators/feature_pack/add_feature/templates/views/partials/_header.html.slim.tt
52
53
  - lib/generators/feature_pack/add_group/USAGE
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  - !ruby/object:Gem::Version
77
78
  version: '0'
78
79
  requirements: []
79
- rubygems_version: 3.5.18
80
+ rubygems_version: 3.5.22
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: New way to organize app features in Rails.