feature_pack 0.0.5 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/feature_pack/error.rb +6 -0
- data/lib/feature_pack.rb +49 -29
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28795d49c6bb85dd45d936a1181629fd83364011f247097ae4965fddb295e648
|
4
|
+
data.tar.gz: 341b7848ae7679e5a811c681a82e4ac6eeb192be8b6cbe4a8fc875a4b9cac409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beafa89e2177ee8a2e1e6df714b44e3a1eaee51a8735dc97f57b5e4f420998358e2bd5af8b21f9bc0da303ac8e4d618f5abd4ffddeca700f1cc2c7ab980946c3
|
7
|
+
data.tar.gz: f5649a1c5865c94919ba1df6bdaf41c981c21ac0a9a58f838f90f6a6f00ab538bba34b78b74222f5eea899b95b7f5162871df14c90b461147dbc34f3b8c6c189
|
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[
|
12
|
-
|
13
|
-
|
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?(@@
|
17
|
-
|
18
|
-
@@
|
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
|
-
@@
|
21
|
-
|
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
|
-
@@
|
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
|
-
|
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
|
-
@@
|
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
|
-
@@
|
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:
|
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 =
|
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,
|
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
|
-
@@
|
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(@@
|
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(@@
|
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)
|
115
|
-
|
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.
|
4
|
+
version: 0.0.8
|
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: '
|
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: '
|
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
|