Skip to content

Commit e983439

Browse files
committed
feat(generator): simplify installation by reducing setup steps
1 parent 812a4e5 commit e983439

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

README.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,37 @@ Here are some of the things you can do with RailsUrlShortener:
2525

2626
## Installation
2727

28-
Follow these steps to install and configure RailsUrlShortener:
28+
Follow these steps to install and configure rails_url_shortener in your Rails application.
2929

30-
1. Add this line to your application's Gemfile:
30+
1. Add the Gem
31+
Add the following line to your application's Gemfile:
3132

3233
```ruby
3334
gem "rails_url_shortener"
3435
```
35-
36-
2. Install the gem by running:
36+
2. Install the Gem
37+
Run the following command to install the gem:
3738

3839
```bash
3940
bundle install
4041
```
41-
42-
3. Install and run the migrations:
43-
44-
```bash
45-
bin/rails rails_url_shortener:install:migrations db:migrate
46-
```
47-
48-
4. Generate the initializer for configuration:
49-
42+
3. Run the Generator
43+
Run the generator to set up the necessary files:
5044
```bash
5145
rails generate rails_url_shortener
5246
```
47+
This will:
48+
✅ Install and run the required migrations
5349

54-
## Usage
55-
56-
1. Mount the engine
57-
58-
Mount the engine on your app adding the next code on your config/routes.rb:
50+
✅ Mount the engine
51+
An entry will be added to the bottom of your config/routes.rb file, mounting the engine at the root of your application.
5952

60-
**If you want to mount this on the root of your app, this should be on the bottom of your routes file.**
53+
✅ Generate an initializer for further configuration`
6154

62-
```ruby
63-
mount RailsUrlShortener::Engine, at: "/"
6455

65-
```
56+
## Usage
6657

67-
2. Generate the short link
58+
1. Generate the short link
6859

6960
And generate the short links like you want:
7061

@@ -80,7 +71,7 @@ short_url("https://www.github.com/a-chacon/rails-url-shortener")
8071
RailsUrlShortener::Url.generate("https://www.github.com/a-chacon/rails-url-shortener")
8172
```
8273

83-
3. Share the short link
74+
2. Share the short link
8475

8576
**Then share the short link to your users or wherever you want.**
8677

lib/generators/rails_url_shortener/rails_url_shortener_generator.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
class RailsUrlShortenerGenerator < Rails::Generators::Base
66
source_root File.expand_path('templates', __dir__)
77

8+
def install_and_run_migrations
9+
rake "rails_url_shortener:install:migrations"
10+
rake "db:migrate"
11+
end
12+
13+
def add_route_to_routes_file
14+
# Mount the engine at the bottom of the routes file in the host application.
15+
inject_into_file 'config/routes.rb', before: /\nend\s*\Z/ do
16+
"\n mount RailsUrlShortener::Engine, at: '/'"
17+
end
18+
end
19+
820
def copy
921
copy_file 'initializer.rb', 'config/initializers/rails_url_shortener.rb'
1022
end

0 commit comments

Comments
 (0)