feature_pack 0.1.4 → 0.3.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: 48bfeabf660821f1ba14e60c86985bd9082a2075816e7c7d7a046b87d8d979a9
4
- data.tar.gz: 3e634e8304a6b9a24faf0b209c953c2f7dbeaff39dd573c9ea9c24938c1301bf
3
+ metadata.gz: c4d4c06a3ac9cc919e20a0616c0ec7b0d1da2553f43a4c5b140ef7a8bc29147a
4
+ data.tar.gz: 21ae0804c870c884ee4270168327fa81eade33b261bb4adb915f87f49764ca41
5
5
  SHA512:
6
- metadata.gz: fbe55e58df6e1455f1a408c065ae6a1b307750cac4660e00452610b53714acf54853e1bf3f57723e5113b1b0cf27ec9c4e04755ca06284987c776295d2696c5b
7
- data.tar.gz: 7587b5738e9c717a5b3105a19bee9e8d187e1a2e8e036d4c19b08336d6b7f124189df013bd2a4b25036a3132f6681f86cf8b1f54bda6d2ca260036f0f27fbbad
6
+ metadata.gz: a66fab958817fe7391449fe39d04043b9729e3bfc4a40b18e8ad6458e4a2f2c6a7ff863dfb0c8acf5841024bfdb34bb48e79c631c58949d655d1d0ca809fb8ec
7
+ data.tar.gz: bcc1750715d4f4a88587b557bd75e5ed0e3c698fec80a1691942b5ff895ecd3b6041636dd4b325de811d3008551a1244aa10635b5a28e7180a41642a86420b54
@@ -1,14 +1,16 @@
1
1
  class FeaturePack::Controller < ApplicationController
2
- before_action :set_feature
2
+ before_action :set_group_and_feature
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
 
10
- def set_feature
11
- @feature = FeaturePack.feature *params['controller'].delete_prefix('feature_pack/').split('/').map(&:to_sym)
10
+ def set_group_and_feature
11
+ group_name, feature_name = params['controller'].delete_prefix('feature_pack/').split('/').map(&:to_sym)
12
+ @group = FeaturePack.group group_name
13
+ @feature = FeaturePack.feature group_name, feature_name
12
14
  end
13
15
 
14
16
  def set_view_lookup_context_prefix
@@ -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('_'),
@@ -62,6 +62,11 @@ module FeaturePack
62
62
  manifest: YAML.load_file(File.join(group_path, GROUP_METADATA_DIRECTORY, MANIFEST_FILE_NAME)).deep_symbolize_keys
63
63
  )
64
64
 
65
+ group.manifest.fetch(:const_aliases, []).each do |alias_data|
66
+ alias_method_name, alias_const_name = alias_data.first
67
+ group.define_singleton_method(alias_method_name) { "FeaturePack::#{group.name.name.camelize}::#{alias_const_name}".constantize }
68
+ end
69
+
65
70
  def group.feature(feature_name) = features.find { |p| p.name.eql?(feature_name) }
66
71
  def group.views_path = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views"
67
72
  def group.view(view_name) = "#{base_dir}/#{GROUP_METADATA_DIRECTORY}/views/#{view_name}"
@@ -75,16 +80,16 @@ module FeaturePack
75
80
  absolute_path = @@features_path.join(feature_path)
76
81
  relative_path = Pathname.new(feature_path)
77
82
  base_path = File.basename(feature_path, File::SEPARATOR)
78
-
83
+
79
84
  feature_name = base_path.gsub(FEATURE_ID_PATTERN, '').to_sym
80
-
85
+
81
86
  routes_file_path = relative_path.join('routes.rb')
82
87
 
83
88
  # The custom routes file loads before the Rails default routes,
84
89
  # leading to errors like NoMethodError for 'scope'.
85
90
  # Ignoring them is required to prevent these issues.
86
91
  @@ignored_paths << routes_file_path
87
-
92
+
88
93
  # Due to Zeiwerk rules, Controllers have special load process
89
94
  @@features_controllers_paths << relative_path.join(CONTROLLER_FILE_NAME)
90
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
@@ -3,6 +3,8 @@
3
3
  :type: :alert
4
4
  :url: <%= @feature_name.gsub('_', '-') %>
5
5
  :version: 1.0.0
6
+ #const_aliases:
7
+ # - :params_class: 'Processor::Params'
6
8
  :policy:
7
9
  :admin: '*'
8
10
  :coordenacao_aps: '*'
@@ -1 +1 @@
1
- get '/', to: '<%= @feature_name %>#home'
1
+ get '/', to: '<%= @feature_name %>#index'
@@ -1,2 +1,2 @@
1
- h1 Feature <%= @group_class_name%>::<%=@feature_class_name %> Home
1
+ h1 Feature <%= @group_class_name%>::<%=@feature_class_name %> Index
2
2
  p = "Find-me at #{__FILE__}"
@@ -21,14 +21,8 @@ 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
-
28
- # create_file "app/models/#{group_name.underscore}/#{name.underscore}.rb", <<-FILE
29
- # class #{group_name.camelize}::#{name.camelize} < ApplicationRecord
30
- # # Lógicas específicas da feature, como validações e associações
31
- # end
32
- # FILE
33
27
  end
34
28
  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.4
4
+ version: 0.3.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-29 00:00:00.000000000 Z
11
+ date: 2024-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -54,7 +54,7 @@ files:
54
54
  - lib/generators/feature_pack/add_group/templates/_group_metadata/controller.rb.tt
55
55
  - lib/generators/feature_pack/add_group/templates/_group_metadata/manifest.yaml.tt
56
56
  - 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
57
+ - lib/generators/feature_pack/add_group/templates/_group_metadata/views/index.html.slim.tt
58
58
  - lib/generators/feature_pack/add_group/templates/_group_metadata/views/partials/_footer.html.slim.tt
59
59
  - lib/generators/feature_pack/add_group/templates/_group_metadata/views/partials/_header.html.slim.tt
60
60
  homepage: https://github.com/gedean/feature_pack
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.5.9
79
+ rubygems_version: 3.5.18
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: New way to organize app features in Rails.
@@ -1,2 +0,0 @@
1
- h1 Group <%= class_name%> Home
2
- p = "Find-me at #{__FILE__}"