rails_url_shortener 0.4.0 → 0.6.0
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 +4 -4
- data/README.md +15 -24
- data/app/models/rails_url_shortener/visit.rb +2 -0
- data/lib/generators/rails_url_shortener/rails_url_shortener_generator.rb +16 -0
- data/lib/generators/rails_url_shortener/templates/initializer.rb +1 -0
- data/lib/rails_url_shortener/model.rb +2 -2
- data/lib/rails_url_shortener/version.rb +1 -1
- data/lib/rails_url_shortener.rb +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4cc011facb5faaf918c6259c775e13aa8554c0e2ddc4ae030cc5465c398ef81
|
|
4
|
+
data.tar.gz: 58419048c10c497c28ce6f774cd3925174acb547f6bc5561ed1213b61dd1e278
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63c1963fed3b1bbde71d922c1f1ce57911d51574c0d7c6d8be10a266fca176eb7ce1104935c10d3fee4b3a820a6ca8900ebe0c80686a75a5d8c8ccd46f911029
|
|
7
|
+
data.tar.gz: 0cf6f3ee876c3f24d486e7335a95e6160075626fe5e9ba250cdede81682960a743f973fae46e932867ff6077f170eb335a3f5518713d3685e0117be84325b1e4
|
data/README.md
CHANGED
|
@@ -25,46 +25,37 @@ Here are some of the things you can do with RailsUrlShortener:
|
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
27
27
|
|
|
28
|
-
Follow these steps to install and configure
|
|
28
|
+
Follow these steps to install and configure rails_url_shortener in your Rails application.
|
|
29
29
|
|
|
30
|
-
1. Add
|
|
30
|
+
1. Add the Gem
|
|
31
|
+
Add the following line to your application's Gemfile:
|
|
31
32
|
|
|
32
33
|
```ruby
|
|
33
34
|
gem "rails_url_shortener"
|
|
34
35
|
```
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
2. Install the Gem
|
|
37
|
+
Run the following command to install the gem:
|
|
37
38
|
|
|
38
39
|
```bash
|
|
39
40
|
bundle install
|
|
40
41
|
```
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
50
44
|
```bash
|
|
51
45
|
rails generate rails_url_shortener
|
|
52
46
|
```
|
|
47
|
+
This will:
|
|
48
|
+
✅ Install and run the required migrations
|
|
53
49
|
|
|
54
|
-
|
|
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.
|
|
59
52
|
|
|
60
|
-
|
|
53
|
+
✅ Generate an initializer for further configuration`
|
|
61
54
|
|
|
62
|
-
```ruby
|
|
63
|
-
mount RailsUrlShortener::Engine, at: "/"
|
|
64
55
|
|
|
65
|
-
|
|
56
|
+
## Usage
|
|
66
57
|
|
|
67
|
-
|
|
58
|
+
1. Generate the short link
|
|
68
59
|
|
|
69
60
|
And generate the short links like you want:
|
|
70
61
|
|
|
@@ -80,7 +71,7 @@ short_url("https://www.github.com/a-chacon/rails-url-shortener")
|
|
|
80
71
|
RailsUrlShortener::Url.generate("https://www.github.com/a-chacon/rails-url-shortener")
|
|
81
72
|
```
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
2. Share the short link
|
|
84
75
|
|
|
85
76
|
**Then share the short link to your users or wherever you want.**
|
|
86
77
|
|
|
@@ -35,6 +35,8 @@ module RailsUrlShortener
|
|
|
35
35
|
# Return boolean
|
|
36
36
|
# rubocop:disable Metrics/AbcSize
|
|
37
37
|
def self.parse_and_save(url, request)
|
|
38
|
+
return false unless RailsUrlShortener.save_visits
|
|
39
|
+
|
|
38
40
|
browser(request)
|
|
39
41
|
return false if !RailsUrlShortener.save_bots_visits && @browser.bot?
|
|
40
42
|
|
|
@@ -5,6 +5,22 @@ require 'rails/generators'
|
|
|
5
5
|
class RailsUrlShortenerGenerator < Rails::Generators::Base
|
|
6
6
|
source_root File.expand_path('templates', __dir__)
|
|
7
7
|
|
|
8
|
+
def install_and_run_migrations
|
|
9
|
+
if Rails.env.test?
|
|
10
|
+
puts 'Skipping migrations in test environment'
|
|
11
|
+
else
|
|
12
|
+
rake 'rails_url_shortener:install:migrations'
|
|
13
|
+
rake 'db:migrate'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_route_to_routes_file
|
|
18
|
+
# Mount the engine at the bottom of the routes file in the host application.
|
|
19
|
+
inject_into_file 'config/routes.rb', before: /\nend\s*\Z/ do
|
|
20
|
+
"\n mount RailsUrlShortener::Engine, at: '/'"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
8
24
|
def copy
|
|
9
25
|
copy_file 'initializer.rb', 'config/initializers/rails_url_shortener.rb'
|
|
10
26
|
end
|
|
@@ -12,3 +12,4 @@ RailsUrlShortener.charset = CHARSETS[:alphanumcase] # used for generate the keys
|
|
|
12
12
|
RailsUrlShortener.key_length = 6 # Key length for random generator
|
|
13
13
|
RailsUrlShortener.minimum_key_length = 3 # minimum permited for a key
|
|
14
14
|
RailsUrlShortener.save_bots_visits = false # if save bots visits
|
|
15
|
+
RailsUrlShortener.save_visits = true # if save visits
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module RailsUrlShortener
|
|
2
2
|
module Model
|
|
3
|
-
# rubocop:disable Naming/
|
|
3
|
+
# rubocop:disable Naming/PredicatePrefix
|
|
4
4
|
def has_short_urls
|
|
5
5
|
class_eval do
|
|
6
6
|
has_many :urls, class_name: 'RailsUrlShortener::Url', as: 'owner'
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
|
-
# rubocop:enable Naming/
|
|
9
|
+
# rubocop:enable Naming/PredicatePrefix
|
|
10
10
|
end
|
|
11
11
|
end
|
data/lib/rails_url_shortener.rb
CHANGED
|
@@ -40,6 +40,8 @@ module RailsUrlShortener
|
|
|
40
40
|
# so if you put this configuration like false could lose some visits to your link
|
|
41
41
|
# by default saving all requests
|
|
42
42
|
mattr_accessor :save_bots_visits, default: true
|
|
43
|
+
|
|
44
|
+
mattr_accessor :save_visits, default: true
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
ActiveSupport.on_load(:active_record) do
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_url_shortener
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- a-chacon
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
10
|
+
date: 2025-10-20 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: browser
|
|
@@ -74,9 +74,9 @@ licenses:
|
|
|
74
74
|
- GPL-3.0
|
|
75
75
|
metadata:
|
|
76
76
|
bug_tracker_uri: https://www.github.com/a-chacon/rails-url-shortener/issues
|
|
77
|
-
changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.
|
|
77
|
+
changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.6.0
|
|
78
78
|
documentation_uri: https://github.com/a-chacon/rails-url-shortener/blob/main/README.md
|
|
79
|
-
source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.
|
|
79
|
+
source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.6.0
|
|
80
80
|
rubygems_mfa_required: 'true'
|
|
81
81
|
rdoc_options: []
|
|
82
82
|
require_paths:
|