@@ -7,16 +7,16 @@ module RubyLLM
7
7
# Generator for RubyLLM Rails models and migrations
8
8
class InstallGenerator < Rails ::Generators ::Base
9
9
include Rails ::Generators ::Migration
10
- namespace " ruby_llm:install"
10
+ namespace ' ruby_llm:install'
11
11
12
12
source_root File . expand_path ( 'install/templates' , __dir__ )
13
13
14
14
class_option :chat_model_name , type : :string , default : 'Chat' ,
15
- desc : 'Name of the Chat model class'
15
+ desc : 'Name of the Chat model class'
16
16
class_option :message_model_name , type : :string , default : 'Message' ,
17
- desc : 'Name of the Message model class'
17
+ desc : 'Name of the Message model class'
18
18
class_option :tool_call_model_name , type : :string , default : 'ToolCall' ,
19
- desc : 'Name of the ToolCall model class'
19
+ desc : 'Name of the ToolCall model class'
20
20
21
21
desc 'Creates model files for Chat, Message, and ToolCall, and creates migrations for RubyLLM Rails integration'
22
22
@@ -36,58 +36,46 @@ def postgresql?
36
36
37
37
def acts_as_chat_declaration
38
38
acts_as_chat_params = [ ]
39
- if options [ :message_model_name ]
40
- acts_as_chat_params << "message_class: \" #{ options [ :message_model_name ] } \" "
41
- end
42
- if options [ :tool_call_model_name ]
43
- acts_as_chat_params << "tool_call_class: \" #{ options [ :tool_call_model_name ] } \" "
44
- end
39
+ acts_as_chat_params << "message_class: \" #{ options [ :message_model_name ] } \" " if options [ :message_model_name ]
40
+ acts_as_chat_params << "tool_call_class: \" #{ options [ :tool_call_model_name ] } \" " if options [ :tool_call_model_name ]
45
41
if acts_as_chat_params . any?
46
42
"acts_as_chat #{ acts_as_chat_params . join ( ', ' ) } "
47
43
else
48
- " acts_as_chat"
44
+ ' acts_as_chat'
49
45
end
50
46
end
51
47
52
48
def acts_as_message_declaration
53
49
acts_as_message_params = [ ]
54
- if options [ :chat_model_name ]
55
- acts_as_message_params << "chat_class: \" #{ options [ :chat_model_name ] } \" "
56
- end
50
+ acts_as_message_params << "chat_class: \" #{ options [ :chat_model_name ] } \" " if options [ :chat_model_name ]
57
51
if options [ :tool_call_model_name ]
58
52
acts_as_message_params << "tool_call_class: \" #{ options [ :tool_call_model_name ] } \" "
59
53
end
60
54
if acts_as_message_params . any?
61
55
"acts_as_message #{ acts_as_message_params . join ( ', ' ) } "
62
56
else
63
- " acts_as_message"
57
+ ' acts_as_message'
64
58
end
65
59
end
66
60
67
61
def acts_as_tool_call_declaration
68
62
acts_as_tool_call_params = [ ]
69
- if options [ :message_model_name ]
70
- acts_as_tool_call_params << "message_class: \" #{ options [ :message_model_name ] } \" "
71
- end
63
+ acts_as_tool_call_params << "message_class: \" #{ options [ :message_model_name ] } \" " if options [ :message_model_name ]
72
64
if acts_as_tool_call_params . any?
73
65
"acts_as_tool_call #{ acts_as_tool_call_params . join ( ', ' ) } "
74
66
else
75
- " acts_as_tool_call"
67
+ ' acts_as_tool_call'
76
68
end
77
69
end
78
70
79
71
def create_migration_files
80
- # Use a fixed timestamp for testing and to ensure they're sequential
81
- # @migration_number = Time.now.utc.strftime('%Y%m%d%H%M%S')
82
72
migration_template 'create_chats_migration.rb.tt' , "db/migrate/create_#{ options [ :chat_model_name ] . tableize } .rb"
83
73
84
- # Increment timestamp for the next migration
85
- # @migration_number = (@migration_number.to_i + 1).to_s
86
- migration_template 'create_messages_migration.rb.tt' , "db/migrate/create_#{ options [ :message_model_name ] . tableize } .rb"
74
+ migration_template 'create_messages_migration.rb.tt' ,
75
+ "db/migrate/create_#{ options [ :message_model_name ] . tableize } .rb"
87
76
88
- # Increment timestamp again for the final migration
89
- # @migration_number = (@migration_number.to_i + 2).to_s
90
- migration_template 'create_tool_calls_migration.rb.tt' , "db/migrate/create_#{ options [ :tool_call_model_name ] . tableize } .rb"
77
+ migration_template 'create_tool_calls_migration.rb.tt' ,
78
+ "db/migrate/create_#{ options [ :tool_call_model_name ] . tableize } .rb"
91
79
end
92
80
93
81
def create_model_files
0 commit comments