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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 526e0841f450314d3c8d049941ab61275891ed64
4
- data.tar.gz: 75ff98d44c3648286577d9e2feb1d290c043a340
3
+ metadata.gz: 4fe325595eeafbc4188f0913be0ac17741e189aa
4
+ data.tar.gz: b4185d19550070bcf9c0f39b68879143ac63f573
5
5
  SHA512:
6
- metadata.gz: f1cad18e7420750ccc5f92df1cd74ebea98d5f228b2b59d10dd95013e754fb06cc7aaee719be90fc5abff2c085d714517c02f0bc5d294b5ef5b46a2e049d2261
7
- data.tar.gz: 005259636916b84aad080f30295f65bc5529e75b60cdfea28eace0e1f312099f64072dff5f426664e368def2dd0c88a132190bb57cd0a11f36770c672a078794
6
+ metadata.gz: df5fe6370f8361bc180b47af9786012639d5d84a7bebaf921c4da895f54f6bb72cf8193912a82cd7e0d7e00d1fbcd7d8a67be1909d3a905e7536b9596101ad2b
7
+ data.tar.gz: 83b1355d0319263be80bf7e6e6138800a803fab8eb84114650f03b55b0552a8b55297df579c3b87cfae257b244f335f999fb04c6707bfea8c395cc26ef37b63c
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+ Style/IndentArray:
4
+ EnforcedStyle: consistent
5
+ Style/Documentation:
6
+ Enabled: false
7
+ Style/BlockLength:
8
+ Exclude:
9
+ - "*.gemspec"
10
+ - "spec/**/*.rb"
data/.travis.yml CHANGED
@@ -1,8 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.0
5
- - 2.1
6
4
  - 2.2.5
7
5
  - 2.3.1
8
6
  addons:
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
@@ -1,6 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in hashid-rails.gemspec
4
4
  gemspec
5
-
6
- gem 'codeclimate-test-reporter', group: :test, require: nil
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
@@ -1,7 +1,7 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
- task :default => :spec
7
- task :test => :spec
6
+ task default: :spec
7
+ task test: :spec
data/hashid-rails.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'hashid/rails/version'
4
+ require "hashid/rails/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'hashid-rails'
7
+ spec.name = "hashid-rails"
8
8
  spec.version = Hashid::Rails::VERSION
9
- spec.authors = ['Justin Cypret']
10
- spec.email = ['jcypret@gmail.com']
9
+ spec.authors = ["Justin Cypret"]
10
+ spec.email = ["jcypret@gmail.com"]
11
11
 
12
- spec.summary = %q{Use Hashids in your Rails app models.}
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 = 'https://github.com/jcypret/hashid-rails'
21
- spec.license = 'MIT'
20
+ spec.homepage = "https://github.com/jcypret/hashid-rails"
21
+ spec.license = "MIT"
22
22
 
23
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
- spec.bindir = 'exe'
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 = ['lib']
28
+ spec.require_paths = ["lib"]
27
29
 
28
- spec.add_development_dependency 'bundler'
29
- spec.add_development_dependency 'rake'
30
- spec.add_development_dependency 'rspec', '~> 3.4.0'
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 'activerecord', '>= 4.0'
33
- spec.add_runtime_dependency 'hashids', '~> 1.0'
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 'hashid/rails/version'
2
- require 'hashids'
3
- require 'active_record'
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
- alias_method :hashid, :to_param
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( decode_id(hashid) || hashid )
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 =~ /active_record\/persistence.*reload/}
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
 
@@ -0,0 +1,13 @@
1
+ module Hashid
2
+ module Rails
3
+ class Configuration
4
+ attr_accessor :secret, :length, :alphabet
5
+
6
+ def initialize
7
+ @secret = ""
8
+ @length = 6
9
+ @alphabet = nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Hashid
2
2
  module Rails
3
- VERSION = '0.5.0'
3
+ VERSION = "0.6.0".freeze
4
4
  end
5
5
  end
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.5.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: 2016-10-16 00:00:00.000000000 Z
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: