hashid-rails 0.3.1 → 0.3.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: 7a4447cfc0bb84821762db86b908d7bc61e9e66e
4
- data.tar.gz: 442741b5447703169e9470997eccb5c18a89614d
3
+ metadata.gz: 57c692d5064faea88ae4b6f088c69bdbfd0ab54e
4
+ data.tar.gz: ec1b561f21d8550635dd082c584105c48c19e49c
5
5
  SHA512:
6
- metadata.gz: 3b1dc3aac07f2f898ee5a5cd4c90520491d64c70aa9214aac96ed164aee6b6322bb701debece8328d375b59d6a81cdda764899e4a3b58222834b60b6add7bd41
7
- data.tar.gz: 309b5f40f92347e10cdc9896465f6b26c9c0bdf7c91ac6d2dc19a7855c5b052cce16fdba18cb13c4fb9d7aee3f69624b3dcb66a507e8cdd6bd015ad7fb715e91
6
+ metadata.gz: e021ef31cedc780f17346d4eb282ea318ed572c09dd15577b2158e2668d9042f0dadb8ad5f371507b706a4a4b7324168d462c13cd06f326db844d49dbadc7a42
7
+ data.tar.gz: 4a9fd16a4baa41f920e58d8d26652b35e3daab18899849f2613cfda7cf22cb5f5c33f645d671af1097d2ae34ed225373757307666f24faa95871cf662b4794cd
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.3.0
5
+ - 2.2.0
6
+ - 2.1.0
7
+ - 2.0.0
8
+ addons:
9
+ code_climate:
10
+ repo_token: 561da3bbc224e5217ceba7b8f99d24190d7d65b221570db6cf0949381e4c0c27
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2 (2016-03-30)
4
+ - Multiple ids can be passed to `find` method
5
+
3
6
  ## 0.3.1 (2016-03-10)
4
7
  - Update Rails dependency to work with Rails 4.0 and up.
5
8
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Hashid Rails
2
- [ ![Codeship Status for jcypret/hashid-rails](https://codeship.com/projects/79614b80-93bc-0133-e91e-767635853833/status?branch=master)](https://codeship.com/projects/124848)
2
+ [![Build Status](https://travis-ci.org/jcypret/hashid-rails.svg?branch=master)](https://travis-ci.org/jcypret/hashid-rails)
3
3
  [![Code Climate](https://codeclimate.com/github/jcypret/hashid-rails/badges/gpa.svg)](https://codeclimate.com/github/jcypret/hashid-rails)
4
4
  [![Test Coverage](https://codeclimate.com/github/jcypret/hashid-rails/badges/coverage.svg)](https://codeclimate.com/github/jcypret/hashid-rails/coverage)
5
5
 
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_development_dependency 'bundler', '~> 1.9'
29
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake'
30
30
  spec.add_development_dependency 'rspec', '~> 3.4.0'
31
31
 
32
32
  spec.add_runtime_dependency 'activerecord', '>= 4.0'
@@ -46,23 +46,44 @@ module Hashid
46
46
  Hashids.new(*arguments)
47
47
  end
48
48
 
49
- def encode_id(id)
50
- hashids.encode(id)
49
+ def encode_id(ids)
50
+ if ids.is_a?(Array)
51
+ ids.map { |id| hashid_encode(id) }
52
+ else
53
+ hashid_encode(ids)
54
+ end
51
55
  end
52
56
 
53
- def decode_id(id)
54
- hashids.decode(id.to_s).first
57
+ def decode_id(ids)
58
+ if ids.is_a?(Array)
59
+ ids.map { |id| hashid_decode(id) }
60
+ else
61
+ hashid_decode(ids)
62
+ end
55
63
  end
56
64
 
57
65
  def find(hashid)
58
66
  model_reload? ? super(hashid) : super( decode_id(hashid) || hashid )
59
67
  end
60
68
 
69
+ # Calls `find` with decoded hashid
70
+ def find_by_hashid(hashid)
71
+ find_by!(id: hashid_decode(hashid))
72
+ end
73
+
61
74
  private
62
75
 
63
76
  def model_reload?
64
77
  caller.any? {|s| s =~ /active_record\/persistence.*reload/}
65
78
  end
79
+
80
+ def hashid_decode(id)
81
+ hashids.decode(id.to_s).first
82
+ end
83
+
84
+ def hashid_encode(id)
85
+ hashids.encode(id)
86
+ end
66
87
  end
67
88
 
68
89
  class Configuration
@@ -1,5 +1,5 @@
1
1
  module Hashid
2
2
  module Rails
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Cypret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.9'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,7 @@ extra_rdoc_files: []
94
94
  files:
95
95
  - ".gitignore"
96
96
  - ".rspec"
97
+ - ".travis.yml"
97
98
  - CHANGELOG.md
98
99
  - Gemfile
99
100
  - LICENSE.txt