hashids_uri 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
  SHA1:
3
- metadata.gz: 6dd66e4364dee24a1c249da3592496b7ffa0e2ce
4
- data.tar.gz: 5b366e40638fc62f9d34132c6cf64b4b2cdedb63
3
+ metadata.gz: 53d72563690a2848294f1bdc7a42bdf820efa41e
4
+ data.tar.gz: b99671e3614e0ecd8fa3590fc92a0ad131f43a5f
5
5
  SHA512:
6
- metadata.gz: b9d8e1027f8229dc5d70df0f2bbb3d3bbec8aed2d84969093d467a0b43e72dee7d43b4630aa10cc004f5cbfa78095c10c14cb0ac36341828cc79a6384c6b133c
7
- data.tar.gz: 71462d177e025118036561c6011a7f407462053309ad7b305e8b81ae1736e8897fbb999ffe05a96a5565aefa4d72eb66d2c18ea26463215ac7d62e4c8179c072
6
+ metadata.gz: ef0248aaf4c2c85809b81137f6b60be9628d6249e846b67502822e6a7a1e4d30a292f8f95621e3b21fc75b50875ad690f9967d956accb3d27b6a62b59a89db68
7
+ data.tar.gz: 7ef6798511f4da6d9e044b0e0756424d4df337e3bc25e3faf6b124aac03bbcbcaf9efbd0347a778f9965179b0ea9acc871d832b48115152b75a4aa6207cf27b0
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
+ [![Build Status](https://travis-ci.org/danieldraper/hashids_uri.svg)](https://travis-ci.org/danieldraper/hashids_uri)
2
+ [![Dependency Status](https://gemnasium.com/danieldraper/hashids_uri.svg)](https://gemnasium.com/danieldraper/hashids_uri)
3
+ [![Code Climate](https://codeclimate.com/github/danieldraper/hashids_uri/badges/gpa.svg)](https://codeclimate.com/github/danieldraper/hashids_uri)
4
+
1
5
  # HashidsUri
2
6
 
3
- HashidsUri allows you to easily use (Hashids)[http://hashids.org/] in your Ruby on Rails URLs via the (Hashids Gem)[https://github.com/peterhellberg/hashids.rb]. You no longer need to expose sequential IDs to your users and you can do all this without changing your primary key to a UUID or some custom database level function.
7
+ HashidsUri allows you to easily use [Hashids](http://hashids.org/) in your Ruby on Rails URLs via the [Hashids Gem](https://github.com/peterhellberg/hashids.rb). You no longer need to expose sequential IDs to your users and you can do all this without changing your primary key to a UUID or some custom database level function.
4
8
 
5
9
  An example URL using HashidsUri
6
10
  ```http
@@ -1,3 +1,3 @@
1
1
  module HashidsUri
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/hashids_uri.rb CHANGED
@@ -3,29 +3,26 @@ require 'active_record'
3
3
 
4
4
  module ActiveRecord
5
5
  module HashidsUri
6
- extend ::ActiveSupport::Concern
7
-
8
- class << self
9
- attr_accessor :salt, :min_length
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ base.send :include, InstanceMethods
10
9
  end
11
10
 
12
11
  module ClassMethods
13
12
  def has_hashids_uri(options = {})
14
- ActiveRecord::HashidsUri.salt = options.fetch(:salt, '')
15
- ActiveRecord::HashidsUri.min_length = options.fetch(:min_length, 6)
13
+ class_attribute :salt, :min_length
16
14
 
17
- include InstanceMethods
15
+ self.salt = options.fetch(:salt, '')
16
+ self.min_length = options.fetch(:min_length, 6)
18
17
  end
19
- end
20
18
 
21
- module ClassMethods
22
19
  def find_by_hash(hash)
23
- find(
24
- ::Hashids.new(
25
- ActiveRecord::HashidsUri.salt,
26
- ActiveRecord::HashidsUri.min_length,
27
- ).decode(hash).first
28
- )
20
+ decoded_id = ::Hashids.new(
21
+ self.salt,
22
+ self.min_length
23
+ ).decode(hash).first
24
+
25
+ find(decoded_id)
29
26
  end
30
27
 
31
28
  def find(*args)
@@ -37,12 +34,24 @@ module ActiveRecord
37
34
  end
38
35
 
39
36
  module InstanceMethods
40
- def to_param
37
+ def salt
38
+ self.class.salt
39
+ end
40
+
41
+ def min_length
42
+ self.class.min_length
43
+ end
44
+
45
+ def hashid
41
46
  ::Hashids.new(
42
- ActiveRecord::HashidsUri.salt,
43
- ActiveRecord::HashidsUri.min_length
47
+ salt,
48
+ min_length
44
49
  ).encode(id)
45
50
  end
51
+
52
+ def to_param
53
+ hashid
54
+ end
46
55
  end
47
56
  end
48
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashids_uri
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
  - Daniel Draper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-02 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord