Skip to content

Commit 8fbf93b

Browse files
committed
fix: improve Rails generator output and conventions
- Remove duplicate timestamps in migration filenames by letting Rails handle them - Follow Rails conventions by omitting default class parameters in acts_as declarations - Replace verbose post-install markdown with concise, colorful terminal output - Add sponsorship information to encourage community support - Update tests to match new generator structure
1 parent 315ba7f commit 8fbf93b

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

docs/guides/rails.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ This approach has one important consequence: **you cannot use `validates :conten
6060
## Setting Up Your Rails Application
6161

6262
### Quick Setup with Generator
63-
6463
{: .d-inline-block }
6564

6665
Available in v1.4.0

lib/generators/ruby_llm/install_generator.rb

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def postgresql?
3636

3737
def acts_as_chat_declaration
3838
acts_as_chat_params = []
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]
39+
if options[:message_model_name] != 'Message'
40+
acts_as_chat_params << "message_class: \"#{options[:message_model_name]}\""
41+
end
42+
if options[:tool_call_model_name] != 'ToolCall'
43+
acts_as_chat_params << "tool_call_class: \"#{options[:tool_call_model_name]}\""
44+
end
4145
if acts_as_chat_params.any?
4246
"acts_as_chat #{acts_as_chat_params.join(', ')}"
4347
else
@@ -47,8 +51,8 @@ def acts_as_chat_declaration
4751

4852
def acts_as_message_declaration
4953
acts_as_message_params = []
50-
acts_as_message_params << "chat_class: \"#{options[:chat_model_name]}\"" if options[:chat_model_name]
51-
if options[:tool_call_model_name]
54+
acts_as_message_params << "chat_class: \"#{options[:chat_model_name]}\"" if options[:chat_model_name] != 'Chat'
55+
if options[:tool_call_model_name] != 'ToolCall'
5256
acts_as_message_params << "tool_call_class: \"#{options[:tool_call_model_name]}\""
5357
end
5458
if acts_as_message_params.any?
@@ -60,7 +64,9 @@ def acts_as_message_declaration
6064

6165
def acts_as_tool_call_declaration
6266
acts_as_tool_call_params = []
63-
acts_as_tool_call_params << "message_class: \"#{options[:message_model_name]}\"" if options[:message_model_name]
67+
if options[:message_model_name] != 'Message'
68+
acts_as_tool_call_params << "message_class: \"#{options[:message_model_name]}\""
69+
end
6470
if acts_as_tool_call_params.any?
6571
"acts_as_tool_call #{acts_as_tool_call_params.join(', ')}"
6672
else
@@ -71,19 +77,18 @@ def acts_as_tool_call_declaration
7177
def create_migration_files
7278
# Create migrations with timestamps to ensure proper order
7379
# First create chats table
74-
timestamp = Time.now.utc
7580
migration_template 'create_chats_migration.rb.tt',
76-
"db/migrate/#{timestamp.strftime('%Y%m%d%H%M%S')}_create_#{options[:chat_model_name].tableize}.rb" # rubocop:disable Layout/LineLength
81+
"db/migrate/create_#{options[:chat_model_name].tableize}.rb"
7782

78-
# Then create tool_calls table with timestamp + 1 second
79-
timestamp += 1
83+
# Then create tool_calls table
84+
sleep 1 # Ensure different timestamp
8085
migration_template 'create_tool_calls_migration.rb.tt',
81-
"db/migrate/#{timestamp.strftime('%Y%m%d%H%M%S')}_create_#{options[:tool_call_model_name].tableize}.rb" # rubocop:disable Layout/LineLength
86+
"db/migrate/create_#{options[:tool_call_model_name].tableize}.rb"
8287

83-
# Finally create messages table with timestamp + 2 seconds
84-
timestamp += 1
88+
# Finally create messages table
89+
sleep 1 # Ensure different timestamp
8590
migration_template 'create_messages_migration.rb.tt',
86-
"db/migrate/#{timestamp.strftime('%Y%m%d%H%M%S')}_create_#{options[:message_model_name].tableize}.rb" # rubocop:disable Layout/LineLength
91+
"db/migrate/create_#{options[:message_model_name].tableize}.rb"
8792
end
8893

8994
def create_model_files
@@ -97,8 +102,19 @@ def create_initializer
97102
end
98103

99104
def show_install_info
100-
content = ERB.new(File.read("#{source_paths.first}/INSTALL_INFO.md.tt")).result(binding)
101-
say content
105+
say "\n ✅ RubyLLM installed!", :green
106+
107+
say "\n Next steps:", :yellow
108+
say ' 1. Run: rails db:migrate'
109+
say ' 2. Set your API keys in config/initializers/ruby_llm.rb'
110+
say " 3. Start chatting: #{options[:chat_model_name]}.create!(model_id: 'gpt-4.1-nano').ask('Hello!')"
111+
112+
say "\n 📚 Full docs: https://rubyllm.com", :cyan
113+
114+
say "\n ❤️ Love RubyLLM?", :magenta
115+
say ' • Sponsor: https://github.com/sponsors/crmne'
116+
say ' • Try Chat with Work: https://chatwithwork.com'
117+
say "\n"
102118
end
103119
end
104120
end

spec/lib/generators/ruby_llm/install_generator_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,35 @@
134134
end
135135
end
136136

137-
describe 'INSTALL_INFO template' do
138-
let(:install_info_content) { File.read(File.join(template_dir, 'INSTALL_INFO.md.tt')) }
137+
describe 'show_install_info method' do
138+
let(:generator_content) { File.read(generator_file) }
139139

140-
it 'has INSTALL_INFO template file' do
141-
expect(File.exist?(File.join(template_dir, 'INSTALL_INFO.md.tt'))).to be(true)
140+
it 'defines show_install_info method' do
141+
expect(generator_content).to include('def show_install_info')
142142
end
143143

144144
it 'includes welcome message' do
145-
expect(install_info_content).to include('RubyLLM Rails Setup Complete')
146-
end
147-
148-
it 'includes setup information' do
149-
expect(install_info_content).to include('Run migrations')
145+
expect(generator_content).to include('RubyLLM installed!')
150146
end
151147

152148
it 'includes migration instructions' do
153-
expect(install_info_content).to include('rails db:migrate')
149+
expect(generator_content).to include('rails db:migrate')
154150
end
155151

156152
it 'includes API configuration instructions' do
157-
expect(install_info_content).to include('Set your API keys')
153+
expect(generator_content).to include('Set your API keys')
154+
end
155+
156+
it 'includes usage example with create! and ask' do
157+
expect(generator_content).to include('.create!(model_id:').and include('.ask(')
158158
end
159159

160-
it 'includes usage examples' do
161-
expect(install_info_content).to include('Start using RubyLLM in your code')
160+
it 'includes documentation link' do
161+
expect(generator_content).to include('https://rubyllm.com')
162162
end
163163

164-
it 'includes streaming response information' do
165-
expect(install_info_content).to include('For streaming responses')
164+
it 'includes sponsorship information' do
165+
expect(generator_content).to include('https://github.com/sponsors/crmne').and include('https://chatwithwork.com')
166166
end
167167
end
168168

0 commit comments

Comments
 (0)