gbc_trestle_modifier 0.1.0 → 0.1.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: fb8167df866980d3daff08fecbf94507b43b6b516cf58044ad638206a281e27c
4
- data.tar.gz: 83616a2e73528ce8f979d14ec9f7252b1da6b5a4061dbd84c1bcba0290f2f566
3
+ metadata.gz: 15ab624901e8d99ed9e58cea857f00fd2f67e945f4085cc066200df0b99871e3
4
+ data.tar.gz: f668f7b25440164057a40721b5f4fd0602f8a6c39cf8013b3242fc0be4b1b192
5
5
  SHA512:
6
- metadata.gz: cf93c14cb231e399359c33ee84e0e2afae0e2486577f48da4f913ee79930dfd0e58e18974550c35f417bb22610183886dd09957461363d6e0c0766753780a67b
7
- data.tar.gz: 776e3ea1d96b761877e10674510a32434feab5e28a4cee7695617c78902bda7725066759320d98cbadcb6a1b68e6e4c73ca3521daffe61c54ec7739de2bbcb91
6
+ metadata.gz: 7603073a05401cf7f716bf46aa302467fa5d9be3857fcc32f0712056f92052d16f278e33c2776bff47de2f0b7c70e763209be41040d92cea3af356d81e425b23
7
+ data.tar.gz: aaa076c94f6e42605c3235eed576460aabaf2da3a88d9072f202cd9abda2c636c2553d7536cb630348e522b0e025e424d9aff8b83750a1e293a18174542d822b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GbcTrestleResourceGenerator
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -0,0 +1,53 @@
1
+ module Gbc
2
+ class ModelInspector
3
+ # Checks if a given model name corresponds to a loaded class and is an ActiveRecord model.
4
+ #
5
+ # @param model_name [String] The name of the model (e.g., "User", "Product").
6
+ # @return [Class, nil] The model class if found and is an ActiveRecord model, otherwise nil.
7
+ def self.find_active_record_model(model_name)
8
+ # Convert model name string to a constant (class)
9
+ model_class = model_name.safe_constantize
10
+
11
+ # Check if the class exists and inherits from ActiveRecord::Base
12
+ if model_class.is_a?(Class) && model_class < ActiveRecord::Base
13
+ return model_class
14
+ else
15
+ puts "Info: Model '#{model_name}' not found or is not an ActiveRecord model."
16
+ return nil
17
+ end
18
+ rescue NameError
19
+ # Handle cases where the constant doesn't exist at all
20
+ puts "Info: Model '#{model_name}' class not defined."
21
+ return nil
22
+ end
23
+
24
+ # Retrieves the database attributes (column names and types) for a given model.
25
+ #
26
+ # @param model_class [Class] The ActiveRecord model class.
27
+ # @return [Hash<String, String>] A hash where keys are column names (String)
28
+ # and values are their database types (String).
29
+ # Returns an empty hash if no attributes are found or an error occurs.
30
+ def self.get_model_database_attributes(model_class)
31
+ unless model_class.is_a?(Class) && model_class < ActiveRecord::Base
32
+ puts "Error: Provided argument is not a valid ActiveRecord model class."
33
+ return {}
34
+ end
35
+
36
+ attributes = {}
37
+ begin
38
+ # `columns` method returns an array of ActiveRecord::ConnectionAdapters::Column objects
39
+ model_class.columns.each do |column|
40
+ attributes[column.name] = column.type.to_s # e.g., "string", "integer", "datetime"
41
+ end
42
+ rescue ActiveRecord::StatementInvalid => e
43
+ puts "Error fetching attributes for #{model_class.name}: #{e.message}"
44
+ puts "This might happen if the database table for the model does not exist yet."
45
+ return {}
46
+ rescue NoMethodError => e
47
+ puts "Error: #{e.message}. Ensure the Rails environment is fully loaded and the model has a table."
48
+ return {}
49
+ end
50
+ attributes
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/generators"
4
- require_relative "model_inspector"
4
+ require_relative "./model_inspector"
5
5
  module Gbc
6
6
  module Trestle
7
7
  class ResourceGenerator < Rails::Generators::Base
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gbc_trestle_modifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-16 00:00:00.000000000 Z
11
+ date: 2025-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trestle
@@ -51,6 +51,7 @@ files:
51
51
  - lib/gbc/trestle/menu_helper.rb
52
52
  - lib/gbc_trestle_modifier.rb
53
53
  - lib/gbc_trestle_modifier/version.rb
54
+ - lib/generators/gbc/trestle/model_inspector.rb
54
55
  - lib/generators/gbc/trestle/resource_generator.rb
55
56
  - lib/generators/gbc/trestle/templates/template_admin.rb.erb
56
57
  - lib/generators/gbc/trestle/templates/template_collection.rb.erb