feature_pack 0.0.5 → 0.0.7

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: bdafad74607b3a61e1783639b1a516875eeb6744e2e6c24a334ad04930036dcb
4
- data.tar.gz: f63ce1ad345185c69e009e507663f082f47c4799d1c286178b9a22ec69e2db06
3
+ metadata.gz: 40810174db4e0624612e8dfa7979635a371faaa60996b99094ca634fca170dda
4
+ data.tar.gz: 3239738c0fc17863242bc29ead5159a43dd04b57ffc2930c158877cee71725f6
5
5
  SHA512:
6
- metadata.gz: 445dbeb6ea88aeab0136cba9c4425c8aefb78126eca729fee511b2503016289e6b65d0c99490017aa971adc411ba0c5ef8473dca944b110c2975c290e5281caf
7
- data.tar.gz: 14598e24f1198f63291fe5cc339ecf659aa51510dc6a34b8f61e9858a398f85a5acbe44030a76335c2b1192a40777fe3a8cfb57f1b06f5c64d7dcaa9611dfb82
6
+ metadata.gz: 7ddd0d2fdf111a39fa11685d752fae9d9aceb607fab96369ea86ae72e9d846df682ba9da58cedca847969afd60bd499094294dec72a3017b3553c0dac2dffdf8
7
+ data.tar.gz: 83ff3aa09bb1cc710a78935554af7b9e5a2daa0e83cc06a42706a386a8f950e41f5f525087b5592e8e7427fa4fc4b3d9715b612af70932199fe25f49f5402c50
@@ -0,0 +1,6 @@
1
+ module FeaturePack::Error
2
+ class NoDataError < StandardError
3
+ end
4
+ class NoGroup < StandardError
5
+ end
6
+ end
data/lib/feature_pack.rb CHANGED
@@ -3,50 +3,61 @@ require 'active_support/all'
3
3
  module FeaturePack
4
4
  GROUP_ID_PATTERN = /^group_.*?_/.freeze
5
5
  FEATURE_ID_PATTERN = /^feature_.*?_/.freeze
6
- RELATIVE_ROOT_PATH = 'app/feature_packs'.freeze
7
6
  GROUP_METADATA_DIRECTORY = '_group_metadata'.freeze
8
7
  MANIFEST_FILE_NAME = 'manifest.yml'.freeze
9
8
  CONTROLLER_FILE_NAME = 'controller.rb'.freeze
10
9
 
11
- ATTR_READERS = %i[core_path absolute_root_path relative_root_path
12
- groups ignored_paths custom_layouts_paths javascript_files_paths
13
- group_controllers_paths controllers_paths].freeze
10
+ ATTR_READERS = %i[
11
+ path
12
+ features_path
13
+ ignored_paths
14
+ groups
15
+ groups_controllers_paths
16
+ features_controllers_paths
17
+ javascript_files_paths
18
+ ].freeze
14
19
 
15
- def self.setup
16
- raise 'FeaturePack already setup!' if defined?(@@relative_root_path)
17
-
18
- @@core_path = Pathname.new(__dir__)
20
+ def self.setup(features_path:)
21
+ raise 'FeaturePack already setup!' if defined?(@@setup_executed_flag)
22
+
23
+ @@path = Pathname.new(__dir__)
24
+ load @@path.join('feature_pack/error.rb')
25
+
26
+ @@features_path = Pathname.new(features_path)
27
+ raise "Invalid features_path: '#{@@features_path}'" if @@features_path.nil?
28
+ raise "Inexistent features_path: '#{@@features_path}'" unless Dir.exist?(@@features_path)
29
+
30
+ @@groups_controllers_paths = []
31
+ @@features_controllers_paths = []
32
+
33
+ @@ignored_paths = Dir.glob("#{@@features_path}/[!]*/")
19
34
 
20
- @@group_controllers_paths = []
21
- @@controllers_paths = []
22
- @@relative_root_path = Pathname.new(RELATIVE_ROOT_PATH)
23
- @@absolute_root_path = Rails.root.join(RELATIVE_ROOT_PATH)
24
- @@ignored_paths = Dir.glob("#{RELATIVE_ROOT_PATH}/[!]*/")
25
- @@javascript_files_paths = Dir.glob("#{@@relative_root_path}/[!_]*/**/*.js")
26
- .map { |js_path| js_path.sub(/^#{Regexp.escape(@@relative_root_path.to_s)}\//, '') }.to_a
35
+ @@javascript_files_paths = Dir.glob("#{@@features_path}/[!_]*/**/*.js")
36
+ .map { |js_path| js_path.sub(/^#{Regexp.escape(@@features_path.to_s)}\//, '') }.to_a
27
37
 
28
- @@custom_layouts_paths = Dir.glob("#{@@relative_root_path}/[!_]*/**/views/layouts")
29
- .map { |layout_path| layout_path.delete_suffix '/layouts' }
38
+ # @@layouts_paths = Dir.glob("#{@@features_path}/[!_]*/**/views/layouts")
39
+ # .map { |layout_path| layout_path.delete_suffix '/layouts' }
30
40
 
31
41
  ATTR_READERS.each { |attr| define_singleton_method(attr) { class_variable_get("@@#{attr}") } }
32
42
 
33
- # load @@core_path.join('feature_pack/error.rb')
34
- @@ignored_paths << @@core_path.join('feature_pack/feature_pack_routes.rb')
43
+ @@ignored_paths << @@path.join('feature_pack/feature_pack_routes.rb')
35
44
 
36
- @@groups = Dir.glob("#{RELATIVE_ROOT_PATH}/[!_]*/").map do |group_path|
45
+ raise "No Groups found in: '#{@@features_path}'" if Dir.glob("#{@@features_path}/[!_]*/").empty?
46
+
47
+ @@groups = Dir.glob("#{@@features_path}/[!_]*/").map do |group_path|
37
48
  relative_path = Pathname.new(group_path)
38
49
  base_path = File.basename(group_path, File::SEPARATOR)
39
50
 
40
51
  # On route draw call, the extension is ignored
41
52
  routes_file = File.exist?(File.join(group_path, GROUP_METADATA_DIRECTORY, 'routes.rb')) ? File.join(base_path, GROUP_METADATA_DIRECTORY, 'routes') : nil
42
53
 
43
- @@group_controllers_paths << File.join(group_path, GROUP_METADATA_DIRECTORY, CONTROLLER_FILE_NAME)
54
+ @@groups_controllers_paths << File.join(group_path, GROUP_METADATA_DIRECTORY, CONTROLLER_FILE_NAME)
44
55
 
45
56
  raise "Group '#{base_path}' does not have a valid ID" if base_path.scan(GROUP_ID_PATTERN).empty?
46
57
  group = OpenStruct.new(
47
58
  id: base_path.scan(GROUP_ID_PATTERN).first.delete_suffix('_'),
48
59
  name: base_path.gsub(GROUP_ID_PATTERN, '').to_sym,
49
- metadata_path: Rails.root.join(group_path, GROUP_METADATA_DIRECTORY),
60
+ metadata_path: @@features_path.join(group_path, GROUP_METADATA_DIRECTORY),
50
61
  relative_path: relative_path,
51
62
  base_dir: File.basename(relative_path, File::SEPARATOR),
52
63
  routes_file: routes_file,
@@ -63,7 +74,7 @@ module FeaturePack
63
74
 
64
75
  @@groups.each do |group|
65
76
  Dir.glob("#{group.relative_path}[!_]*/").each do |feature_path|
66
- absolute_path = Rails.root.join(feature_path)
77
+ absolute_path = @@features_path.join(feature_path)
67
78
  relative_path = Pathname.new(feature_path)
68
79
  base_path = File.basename(feature_path, File::SEPARATOR)
69
80
 
@@ -74,15 +85,18 @@ module FeaturePack
74
85
 
75
86
  routes_file_path = relative_path.join('routes.rb')
76
87
 
77
- # The custom routes file loads before the Rails default routes, leading to errors like NoMethodError for 'scope'. Ignoring them is required to prevent these issues.
88
+ # The custom routes file loads before the Rails default routes,
89
+ # leading to errors like NoMethodError for 'scope'.
90
+ # Ignoring them is required to prevent these issues.
78
91
  @@ignored_paths << routes_file_path
79
92
 
80
93
  # Due to Zeiwerk rules, Controllers have special load process
81
- @@controllers_paths << relative_path.join(CONTROLLER_FILE_NAME)
94
+ @@features_controllers_paths << relative_path.join(CONTROLLER_FILE_NAME)
95
+
82
96
  @@ignored_paths << relative_path.join(CONTROLLER_FILE_NAME)
83
97
 
84
98
  raise "Resource '#{relative_path}' does not have a valid ID" if base_path.scan(FEATURE_ID_PATTERN).empty?
85
- feature_sub_path = relative_path.sub(/^#{Regexp.escape(@@relative_root_path.to_s)}\//, '')
99
+ feature_sub_path = relative_path.sub(/^#{Regexp.escape(@@features_path.to_s)}\//, '')
86
100
  feature = OpenStruct.new(
87
101
  id: base_path.scan(FEATURE_ID_PATTERN).first.delete_suffix('_'),
88
102
  name: feature_name,
@@ -94,7 +108,7 @@ module FeaturePack
94
108
  routes_file: feature_sub_path.join('routes'),
95
109
  # controller_path: relative_path.join('controller'),
96
110
  views_absolute_path: absolute_path.join('views'),
97
- views_relative_path: relative_path.sub(/^#{Regexp.escape(@@relative_root_path.to_s)}\//, '').join('views'),
111
+ views_relative_path: relative_path.sub(/^#{Regexp.escape(@@features_path.to_s)}\//, '').join('views'),
98
112
  class_name: feature_class_name,
99
113
  # FIX-ME
100
114
  #params_class_name: params_class_name,
@@ -108,8 +122,14 @@ module FeaturePack
108
122
  group.features << feature
109
123
  end
110
124
  end
125
+
126
+ @@setup_executed_flag = true
111
127
  end
112
128
 
113
129
  def self.group(group_name) = @@groups.find { |g| g.name.eql?(group_name) }
114
- def self.feature(group_name, feature_name) = group(group_name).feature(feature_name)
115
- end
130
+ def self.feature(group_name, feature_name)
131
+ requested_group = group(group_name)
132
+ return nil if requested_group.nil?
133
+ requested_group.feature(feature_name)
134
+ end
135
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '7.1'
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: '0'
26
+ version: '7.1'
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
@@ -37,13 +37,14 @@ files:
37
37
  - lib/feature_pack.rb
38
38
  - lib/feature_pack/api/controller.rb
39
39
  - lib/feature_pack/controller.rb
40
+ - lib/feature_pack/error.rb
40
41
  - lib/feature_pack/feature_pack_routes.rb
41
42
  - lib/feature_pack/group_controller.rb
42
43
  homepage: https://github.com/gedean/feature_pack
43
44
  licenses:
44
45
  - MIT
45
46
  metadata: {}
46
- post_install_message:
47
+ post_install_message: Please check readme file for use instructions.
47
48
  rdoc_options: []
48
49
  require_paths:
49
50
  - lib