feature_pack 0.1.6 → 0.3.1

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: 281dd30e4d1dfff4a4be468c364b5528c910fd79afb3eec21fd8e9d8436f1fee
4
- data.tar.gz: 25ec88a0b0c8626977687d642954fda17abdd617bdf422fb2c09774c6667341d
3
+ metadata.gz: a358d066012fe6059153050e3887849afec64faf789a3668c696c8606347044c
4
+ data.tar.gz: 27141fe3653ff391a85301d9fcc5ea8676084403d0ad259b06528c22b6fab0ed
5
5
  SHA512:
6
- metadata.gz: 214735c4ec76ee1a6c23f36acda37ab1ec009c10234695390ea6e75a4102bb33522450eb30eea1616a4592c408a21b9e5b2b62efe8a953151346db9ee2edf30c
7
- data.tar.gz: 91e5690231a142beb0abbcd0bef2f745926ca5cb5e113b605703ce974b7ee371ea65535b3bb71ffff6d14250cb50ecfb21de0b8785e96e8332847da7cc06209d
6
+ metadata.gz: 22d7b9a11292d34b1fc5920741ac4e4033dbc1417cb59dd534ff4acd564b34ed46440b9f163aba77b077b70977852b6ad136f3c28363e927e394034b6a3b9f1a
7
+ data.tar.gz: c3b4d00e9a16dd5767a8ce1c79bfc689ddc3b07d2890c52c88d5046c7261a432c318a1d5950600d3bc5ffcc674175f3d54b5a3a919ebe94930777bc8ea53f308
@@ -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_metadata/
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.
@@ -3,7 +3,7 @@ class FeaturePack::Controller < ApplicationController
3
3
  before_action :set_view_lookup_context_prefix
4
4
  before_action :set_layout_paths
5
5
 
6
- def home; end
6
+ def index; end
7
7
 
8
8
  private
9
9
 
@@ -1,9 +1,9 @@
1
1
  FeaturePack.groups.each do |group|
2
2
  unless group.manifest[:namespace_only]
3
- # Default "home" route every group has to have.
3
+ # Default 'index' route every group has to have.
4
4
  get group.manifest[:url],
5
- to: "#{group.name.name}#home",
6
- as: group.name.name
5
+ to: "#{group.name.name}#index",
6
+ as: group.name.name
7
7
 
8
8
  unless group.routes_file.nil?
9
9
  scope group.manifest[:url] do
@@ -14,7 +14,7 @@ FeaturePack.groups.each do |group|
14
14
 
15
15
  namespace group.name, path: group.manifest[:url] do
16
16
  group.features.each do |feature|
17
- scope feature.manifest[:url], as: feature.name.name do
17
+ scope feature.manifest[:url], as: feature.name.name.pluralize do
18
18
  draw(feature.routes_file)
19
19
  end
20
20
  end
@@ -3,8 +3,7 @@ class FeaturePack::GroupController < ApplicationController
3
3
  before_action :set_view_lookup_context_prefix
4
4
  before_action :set_layout_paths
5
5
 
6
- def home
7
- end
6
+ def index; end
8
7
 
9
8
  private
10
9
 
data/lib/feature_pack.rb CHANGED
@@ -17,7 +17,7 @@ module FeaturePack
17
17
  javascript_files_paths
18
18
  ].freeze
19
19
 
20
- def self.setup(features_path:)
20
+ def self.setup(features_path:)
21
21
  raise 'FeaturePack already setup!' if defined?(@@setup_executed_flag)
22
22
 
23
23
  @@path = Pathname.new(__dir__)
@@ -36,7 +36,7 @@ module FeaturePack
36
36
  .map { |js_path| js_path.sub(/^#{Regexp.escape(@@features_path.to_s)}\//, '') }.to_a
37
37
 
38
38
  ATTR_READERS.each { |attr| define_singleton_method(attr) { class_variable_get("@@#{attr}") } }
39
-
39
+
40
40
  @@ignored_paths << @@path.join('feature_pack/feature_pack_routes.rb')
41
41
 
42
42
  # raise "No Groups found in: '#{@@features_path}'" if Dir.glob("#{@@features_path}/[!_]*/").empty?
@@ -49,7 +49,7 @@ module FeaturePack
49
49
  routes_file = File.exist?(File.join(group_path, GROUP_METADATA_DIRECTORY, 'routes.rb')) ? File.join(base_path, GROUP_METADATA_DIRECTORY, 'routes') : nil
50
50
 
51
51
  @@groups_controllers_paths << File.join(group_path, GROUP_METADATA_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('_'),
@@ -66,7 +66,7 @@ module FeaturePack
66
66
  alias_method_name, alias_const_name = alias_data.first
67
67
  group.define_singleton_method(alias_method_name) { "FeaturePack::#{group.name.name.camelize}::#{alias_const_name}".constantize }
68
68
  end
69
-
69
+
70
70
  def group.feature(feature_name) = features.find { |p| p.name.eql?(feature_name) }
71
71
  def group.views_path = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views"
72
72
  def group.view(view_name) = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views/#{view_name}"
@@ -80,16 +80,16 @@ module FeaturePack
80
80
  absolute_path = @@features_path.join(feature_path)
81
81
  relative_path = Pathname.new(feature_path)
82
82
  base_path = File.basename(feature_path, File::SEPARATOR)
83
-
83
+
84
84
  feature_name = base_path.gsub(FEATURE_ID_PATTERN, '').to_sym
85
-
85
+
86
86
  routes_file_path = relative_path.join('routes.rb')
87
87
 
88
88
  # The custom routes file loads before the Rails default routes,
89
89
  # leading to errors like NoMethodError for 'scope'.
90
90
  # Ignoring them is required to prevent these issues.
91
91
  @@ignored_paths << routes_file_path
92
-
92
+
93
93
  # Due to Zeiwerk rules, Controllers have special load process
94
94
  @@features_controllers_paths << relative_path.join(CONTROLLER_FILE_NAME)
95
95
 
@@ -25,7 +25,7 @@ class FeaturePack::AddFeatureGenerator < Rails::Generators::NamedBase
25
25
  template './controller.rb.tt', @feature_dir.join('controller.rb')
26
26
  template './manifest.yaml.tt', @feature_dir.join('manifest.yaml')
27
27
  template './routes.rb.tt', @feature_dir.join('routes.rb')
28
- template './views/home.html.slim.tt', @feature_dir.join('views/home.html.slim')
28
+ template './views/index.html.slim.tt', @feature_dir.join('views/index.html.slim')
29
29
  template './views/partials/_header.html.slim.tt', @feature_dir.join('views/partials/_header.html.slim')
30
30
  template './views/partials/_footer.html.slim.tt', @feature_dir.join('views/partials/_footer.html.slim')
31
31
  template './doc/readme.md.tt', @feature_dir.join('doc/readme.md')
@@ -1,3 +1,3 @@
1
1
  class FeaturePack::<%= @group_class_name %>::<%= @feature_class_name %>Controller < FeaturePack::Controller
2
- # home defined in parent controller
2
+ # index defined in parent controller
3
3
  end
@@ -1 +1 @@
1
- get '/', to: '<%= @feature_name %>#home'
1
+ get '/', to: '<%= @feature_name %>#index'
@@ -0,0 +1,2 @@
1
+ h1 Feature <%= @group_class_name%>::<%=@feature_class_name %> Index
2
+ p = "Find-me at #{__FILE__}"
@@ -21,7 +21,7 @@ class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
21
21
  template './_group_metadata/controller.rb.tt', group_dir.join('_group_metadata', 'controller.rb')
22
22
  template './_group_metadata/manifest.yaml.tt', group_dir.join('_group_metadata', 'manifest.yaml')
23
23
  template './_group_metadata/routes.rb.disabled.tt', group_dir.join('_group_metadata', 'routes.rb.disabled')
24
- template './_group_metadata/views/home.html.slim.tt', group_dir.join('_group_metadata', 'views/home.html.slim')
24
+ template './_group_metadata/views/index.html.slim.tt', group_dir.join('_group_metadata', 'views/index.html.slim')
25
25
  template './_group_metadata/views/partials/_header.html.slim.tt', group_dir.join('_group_metadata', 'views/partials/_header.html.slim')
26
26
  template './_group_metadata/views/partials/_footer.html.slim.tt', group_dir.join('_group_metadata', 'views/partials/_footer.html.slim')
27
27
  end
@@ -1,3 +1,3 @@
1
1
  class FeaturePack::<%= class_name %>Controller < FeaturePack::GroupController
2
- # 'home' already defined in RootGroupController
2
+ # 'index' already defined in RootGroupController
3
3
  end
@@ -1,3 +1,3 @@
1
- # You don't need enable this file if the only action is 'home'
1
+ # You don't need enable this file if the only action is 'index'
2
2
 
3
3
  get '/action-name-url', to: '<%= name %>#action_name'
@@ -0,0 +1,2 @@
1
+ h1 Group <%= class_name%> Index
2
+ p = "Find-me at #{__FILE__}"
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.1.6
4
+ version: 0.3.1
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-08-30 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
@@ -54,7 +55,7 @@ files:
54
55
  - lib/generators/feature_pack/add_group/templates/_group_metadata/controller.rb.tt
55
56
  - lib/generators/feature_pack/add_group/templates/_group_metadata/manifest.yaml.tt
56
57
  - lib/generators/feature_pack/add_group/templates/_group_metadata/routes.rb.disabled.tt
57
- - lib/generators/feature_pack/add_group/templates/_group_metadata/views/home.html.slim.tt
58
+ - lib/generators/feature_pack/add_group/templates/_group_metadata/views/index.html.slim.tt
58
59
  - lib/generators/feature_pack/add_group/templates/_group_metadata/views/partials/_footer.html.slim.tt
59
60
  - lib/generators/feature_pack/add_group/templates/_group_metadata/views/partials/_header.html.slim.tt
60
61
  homepage: https://github.com/gedean/feature_pack
@@ -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.9
80
+ rubygems_version: 3.5.18
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: New way to organize app features in Rails.
@@ -1,2 +0,0 @@
1
- h1 Feature <%= @group_class_name%>::<%=@feature_class_name %> Home
2
- p = "Find-me at #{__FILE__}"
@@ -1,2 +0,0 @@
1
- h1 Group <%= class_name%> Home
2
- p = "Find-me at #{__FILE__}"