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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15ab624901e8d99ed9e58cea857f00fd2f67e945f4085cc066200df0b99871e3
|
4
|
+
data.tar.gz: f668f7b25440164057a40721b5f4fd0602f8a6c39cf8013b3242fc0be4b1b192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7603073a05401cf7f716bf46aa302467fa5d9be3857fcc32f0712056f92052d16f278e33c2776bff47de2f0b7c70e763209be41040d92cea3af356d81e425b23
|
7
|
+
data.tar.gz: aaa076c94f6e42605c3235eed576460aabaf2da3a88d9072f202cd9abda2c636c2553d7536cb630348e522b0e025e424d9aff8b83750a1e293a18174542d822b
|
@@ -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
|
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.
|
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-
|
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
|