hashid-rails 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.travis.yml +0 -2
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -3
- data/README.md +1 -2
- data/Rakefile +4 -4
- data/hashid-rails.gemspec +22 -16
- data/lib/hashid/rails.rb +9 -20
- data/lib/hashid/rails/configuration.rb +13 -0
- data/lib/hashid/rails/version.rb +1 -1
- metadata +60 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fe325595eeafbc4188f0913be0ac17741e189aa
|
4
|
+
data.tar.gz: b4185d19550070bcf9c0f39b68879143ac63f573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df5fe6370f8361bc180b47af9786012639d5d84a7bebaf921c4da895f54f6bb72cf8193912a82cd7e0d7e00d1fbcd7d8a67be1909d3a905e7536b9596101ad2b
|
7
|
+
data.tar.gz: 83b1355d0319263be80bf7e6e6138800a803fab8eb84114650f03b55b0552a8b55297df579c3b87cfae257b244f335f999fb04c6707bfea8c395cc26ef37b63c
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.6.0 (2017-01-07)
|
4
|
+
- Add Rubocop and adjust styles to be consistent.
|
5
|
+
- Fix issue where finding multiple non-hashids returns an array of nils.
|
6
|
+
- Switch over testing to use SQLite for more accurate db interactions.
|
7
|
+
|
3
8
|
## 0.5.0 (2016-10-15)
|
4
9
|
- Update specs to support Rails 5.x series.
|
5
10
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Hashid Rails
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/hashid-rails.svg)](https://badge.fury.io/rb/hashid-rails)
|
2
3
|
[![Build Status](https://travis-ci.org/jcypret/hashid-rails.svg?branch=master)](https://travis-ci.org/jcypret/hashid-rails)
|
3
4
|
[![Code Climate](https://codeclimate.com/github/jcypret/hashid-rails/badges/gpa.svg)](https://codeclimate.com/github/jcypret/hashid-rails)
|
4
5
|
[![Test Coverage](https://codeclimate.com/github/jcypret/hashid-rails/badges/coverage.svg)](https://codeclimate.com/github/jcypret/hashid-rails/coverage)
|
@@ -29,8 +30,6 @@ Or install it yourself as:
|
|
29
30
|
$ gem install hashid-rails
|
30
31
|
```
|
31
32
|
|
32
|
-
> Note: This gem is not yet compatible with Rails 5.
|
33
|
-
|
34
33
|
## Basic Usage
|
35
34
|
|
36
35
|
Just use `Model#find` passing in the hashid instead of the model id.
|
data/Rakefile
CHANGED
data/hashid-rails.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "hashid/rails/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "hashid-rails"
|
8
8
|
spec.version = Hashid::Rails::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ["Justin Cypret"]
|
10
|
+
spec.email = ["jcypret@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = "Use Hashids in your Rails app models."
|
13
13
|
spec.description = <<-EOM
|
14
14
|
This gem allows you to easily use [Hashids](http://hashids.org/ruby/)
|
15
15
|
in your Rails app. Instead of your models using sequential numbers like 1,
|
@@ -17,18 +17,24 @@ Gem::Specification.new do |spec|
|
|
17
17
|
"5bAyD0LO", and "wz3MZ49l". The database will still use integers under
|
18
18
|
the hood, so this gem can be added or removed at any time.
|
19
19
|
EOM
|
20
|
-
spec.homepage =
|
21
|
-
spec.license =
|
20
|
+
spec.homepage = "https://github.com/jcypret/hashid-rails"
|
21
|
+
spec.license = "MIT"
|
22
22
|
|
23
|
-
spec.files = `git ls-files -z
|
24
|
-
|
23
|
+
spec.files = `git ls-files -z`
|
24
|
+
.split("\x0")
|
25
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
25
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ["lib"]
|
27
29
|
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "rake"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
33
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
34
|
+
spec.add_development_dependency "sqlite3"
|
35
|
+
spec.add_development_dependency "rubocop"
|
36
|
+
spec.add_development_dependency "byebug"
|
31
37
|
|
32
|
-
spec.add_runtime_dependency
|
33
|
-
spec.add_runtime_dependency
|
38
|
+
spec.add_runtime_dependency "activerecord", ">= 4.0"
|
39
|
+
spec.add_runtime_dependency "hashids", "~> 1.0"
|
34
40
|
end
|
data/lib/hashid/rails.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "hashid/rails/version"
|
2
|
+
require "hashid/rails/configuration"
|
3
|
+
require "hashids"
|
4
|
+
require "active_record"
|
4
5
|
|
5
6
|
module Hashid
|
6
7
|
module Rails
|
7
|
-
|
8
8
|
# Get configuration or load defaults
|
9
9
|
def self.configuration
|
10
10
|
@configuration ||= Configuration.new
|
@@ -31,10 +31,9 @@ module Hashid
|
|
31
31
|
def to_param
|
32
32
|
encoded_id
|
33
33
|
end
|
34
|
-
|
34
|
+
alias hashid to_param
|
35
35
|
|
36
36
|
module ClassMethods
|
37
|
-
|
38
37
|
def hashids
|
39
38
|
secret = Hashid::Rails.configuration.secret
|
40
39
|
length = Hashid::Rails.configuration.length
|
@@ -56,14 +55,15 @@ module Hashid
|
|
56
55
|
|
57
56
|
def decode_id(ids)
|
58
57
|
if ids.is_a?(Array)
|
59
|
-
ids.map { |id| hashid_decode(id) }
|
58
|
+
decoded_ids = ids.map { |id| hashid_decode(id) }
|
59
|
+
decoded_ids.any? ? decoded_ids : nil
|
60
60
|
else
|
61
61
|
hashid_decode(ids)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def find(hashid)
|
66
|
-
model_reload? ? super(hashid) : super(
|
66
|
+
model_reload? ? super(hashid) : super(decode_id(hashid) || hashid)
|
67
67
|
end
|
68
68
|
|
69
69
|
def find_by_hashid(hashid)
|
@@ -73,7 +73,7 @@ module Hashid
|
|
73
73
|
private
|
74
74
|
|
75
75
|
def model_reload?
|
76
|
-
caller.any? {|s| s =~ /
|
76
|
+
caller.any? { |s| s =~ %r{ active_record/persistence.*reload } }
|
77
77
|
end
|
78
78
|
|
79
79
|
def hashid_decode(id)
|
@@ -84,17 +84,6 @@ module Hashid
|
|
84
84
|
hashids.encode(id)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
88
|
-
class Configuration
|
89
|
-
attr_accessor :secret, :length, :alphabet
|
90
|
-
|
91
|
-
def initialize
|
92
|
-
@secret = ''
|
93
|
-
@length = 6
|
94
|
-
@alphabet = nil
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
87
|
end
|
99
88
|
end
|
100
89
|
|
data/lib/hashid/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashid-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Cypret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,62 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
- !ruby/object:Gem::Dependency
|
56
112
|
name: activerecord
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +150,7 @@ extra_rdoc_files: []
|
|
94
150
|
files:
|
95
151
|
- ".gitignore"
|
96
152
|
- ".rspec"
|
153
|
+
- ".rubocop.yml"
|
97
154
|
- ".travis.yml"
|
98
155
|
- CHANGELOG.md
|
99
156
|
- Gemfile
|
@@ -104,6 +161,7 @@ files:
|
|
104
161
|
- bin/setup
|
105
162
|
- hashid-rails.gemspec
|
106
163
|
- lib/hashid/rails.rb
|
164
|
+
- lib/hashid/rails/configuration.rb
|
107
165
|
- lib/hashid/rails/version.rb
|
108
166
|
homepage: https://github.com/jcypret/hashid-rails
|
109
167
|
licenses:
|