rails_url_shortener 0.1.1 → 0.1.2
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 +2 -1
- data/app/helpers/rails_url_shortener/urls_helper.rb +17 -9
- data/lib/generators/rails_url_shortener/templates/initializer.rb +1 -0
- data/lib/rails_url_shortener/version.rb +1 -1
- data/lib/rails_url_shortener.rb +4 -0
- metadata +4 -5
- data/app/helpers/rails_url_shortener/application_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4188bfea517eadff5ab16a22796513a39c6d50e3c51d63ad7a2025853299f644
|
4
|
+
data.tar.gz: 7e8ec534b52bc6ecba1f7ba4aab0f5e884a07cd4c208e5bf416ee75340555cf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa940a3781070a35f1d6c681be0616a336230a967aae49fb418a9754847ffabd61e3540494c31bdf87fee71cfc3cd7bee808199b205e8ac8e9147d3f3f69da7
|
7
|
+
data.tar.gz: 85c07e0dd53da09ecb50069cd675c114921632333e5ba9d74daf59cd757ae34dfbe0f633f3aa572e9f8ba0f32ceb91c9a9a9f57ad380203551ef5ae29c0809ae
|
data/README.md
CHANGED
@@ -101,11 +101,12 @@ And finally install the migrations on your project and migrate:
|
|
101
101
|
bin/rails rails_url_shortener:install:migrations db:migrate
|
102
102
|
```
|
103
103
|
|
104
|
-
|
104
|
+
For the configurations generate the initializer whith this:
|
105
105
|
|
106
106
|
```bash
|
107
107
|
rails generate RailsUrlShortener:initializer
|
108
108
|
```
|
109
|
+
**Here is important to configure the host at least if your are not running your app in localhost**
|
109
110
|
|
110
111
|
## Contributing
|
111
112
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module RailsUrlShortener
|
2
2
|
module UrlsHelper
|
3
|
+
##
|
4
|
+
# helper for generate short urls
|
5
|
+
#
|
6
|
+
# this method return a short url or the original url if something is bad
|
7
|
+
# Usage:
|
8
|
+
# short_url("https://tools.ietf.org/search/rfc2616#section-5.3")
|
3
9
|
def short_url(url, owner: nil, key: nil, expires_at: nil, category: nil, url_options: {})
|
10
|
+
# generate
|
4
11
|
url_object = Url.generate(
|
5
12
|
url,
|
6
13
|
owner: owner,
|
@@ -10,17 +17,18 @@ module RailsUrlShortener
|
|
10
17
|
)
|
11
18
|
|
12
19
|
if url_object.errors.empty?
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# options for url_for
|
21
|
+
options = {
|
22
|
+
controller: "rails_url_shortener/urls",
|
23
|
+
action: "show",
|
24
|
+
key: url_object.key,
|
25
|
+
host: RailsUrlShortener.host
|
26
|
+
}.merge(url_options)
|
20
27
|
|
21
|
-
#
|
22
|
-
|
28
|
+
# use helper of this engine
|
29
|
+
RailsUrlShortener::Engine.routes.url_for(options)
|
23
30
|
else
|
31
|
+
# if not saved, return original url
|
24
32
|
url
|
25
33
|
end
|
26
34
|
end
|
@@ -4,6 +4,7 @@ CHARSETS = {
|
|
4
4
|
alphanumcase: ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a
|
5
5
|
}
|
6
6
|
|
7
|
+
RailsUrlShortener.host = "localhost:3000" # the host used for the helper
|
7
8
|
RailsUrlShortener.default_redirect = "/" # where the users are redirect if the link doesn't exists or is expired.
|
8
9
|
RailsUrlShortener.charset = CHARSETS[:alphanumcase] # used for generate the keys, better long.
|
9
10
|
RailsUrlShortener.key_length = 6 # Key length for random generator
|
data/lib/rails_url_shortener.rb
CHANGED
@@ -11,6 +11,10 @@ module RailsUrlShortener
|
|
11
11
|
alphanumcase: ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a
|
12
12
|
}
|
13
13
|
|
14
|
+
##
|
15
|
+
# host for build final url on helper
|
16
|
+
mattr_accessor :host, default: 'test.host'
|
17
|
+
|
14
18
|
##
|
15
19
|
# default redirection url when the key isn't found
|
16
20
|
mattr_accessor :default_redirect, default: '/'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_url_shortener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a-chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -65,7 +65,6 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- app/controllers/rails_url_shortener/urls_controller.rb
|
68
|
-
- app/helpers/rails_url_shortener/application_helper.rb
|
69
68
|
- app/helpers/rails_url_shortener/urls_helper.rb
|
70
69
|
- app/models/rails_url_shortener/application_record.rb
|
71
70
|
- app/models/rails_url_shortener/url.rb
|
@@ -84,9 +83,9 @@ licenses:
|
|
84
83
|
- MIT
|
85
84
|
metadata:
|
86
85
|
bug_tracker_uri: https://www.github.com/a-chacon/rails_url_shortener/issues
|
87
|
-
changelog_uri: https://www.github.com/a-chacon/rails_url_shortener/releases/tag/v0.1.
|
86
|
+
changelog_uri: https://www.github.com/a-chacon/rails_url_shortener/releases/tag/v0.1.2
|
88
87
|
documentation_uri: https://github.com/a-chacon/rails_url_shortener/blob/main/README.md
|
89
|
-
source_code_uri: https://github.com/a-chacon/rails_url_shortener/tree/v0.1.
|
88
|
+
source_code_uri: https://github.com/a-chacon/rails_url_shortener/tree/v0.1.2
|
90
89
|
rubygems_mfa_required: 'true'
|
91
90
|
post_install_message:
|
92
91
|
rdoc_options: []
|