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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 964c9390d946bb5229d91c8760689cd5e001b7af1e3182b15e14087488c71a04
4
- data.tar.gz: ee0971582ed1631913c0aa5ba8e43bbe4ecd5159931b9caa7723075363554102
3
+ metadata.gz: 4188bfea517eadff5ab16a22796513a39c6d50e3c51d63ad7a2025853299f644
4
+ data.tar.gz: 7e8ec534b52bc6ecba1f7ba4aab0f5e884a07cd4c208e5bf416ee75340555cf0
5
5
  SHA512:
6
- metadata.gz: 216e49e0c1f9caba3b04fb5cebdcbf524a7525bc5a249031f3d29556fdfd7cff471652500c6b80166085b305087bfb050005140c52dc02f3f4d499d9421d1ec4
7
- data.tar.gz: 194d5777d67c70bd659c227dc03e9b347e21396cf00c732453a74b552b2e8cc2b289e80489528d70376b6f3e5a7b113f40fbd84e458d27e64f2feeeb3311680d
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
- If you want the initializer for configurations do:
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
- # This must be fixed
14
- # the url_for helper must generate the url
15
- # options = {
16
- # controller: "rails_url_shortener_url/urls",
17
- # action: "show",
18
- # key: url.key
19
- # }.merge(url_options)
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
- # url_for(options)
22
- rails_url_shortener_url + url_object.key
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
@@ -1,3 +1,3 @@
1
1
  module RailsUrlShortener
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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.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-13 00:00:00.000000000 Z
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.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.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: []
@@ -1,4 +0,0 @@
1
- module RailsUrlShortener
2
- module ApplicationHelper
3
- end
4
- end