not_found 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6afbd11e5e4af3aca0659265783f2e7e85f82b59
4
+ data.tar.gz: 32fe012ead59b95166e73fd95b6cdc0927d8322c
5
+ SHA512:
6
+ metadata.gz: 37a46f4ff907576a8e3ec0debb3713a89952ee1bd972a17c8a684e1b179e3eef8257546891d2a5ccf2550319d4a3bb72b9ed1cb1f26fe93d3085a1b6565cecd0
7
+ data.tar.gz: 08bf416b348ea9f7d668570e64846f202e79f504a9373107921e7502c9e8ae0c0496faa715d0c3d79e322304c41aefdae598739cd211eee1599ffb428674a12d
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/db.sqlite3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ before_install: gem install bundler -v 1.10.6
3
+ bundler_args: --without=extras
4
+ script: bundle exec rspec spec
5
+ sudo: false
6
+ gemfile:
7
+ - gemfiles/activerecord-3.0
8
+ - gemfiles/activerecord-4.0
9
+ rvm:
10
+ - '2.2.2'
11
+ - jruby-21mode
12
+ - rbx-2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "bundler", "~> 1.10"
6
+ gem "rake", "~> 10.0"
7
+ gem "rspec"
8
+ gem "sqlite3"
9
+ gem "pry-byebug", platform: "mri"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kris Leech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,113 @@
1
+ # NotFound
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/not_found.png)](http://badge.fury.io/rb/not_found)
4
+ [![Code Climate](https://codeclimate.com/github/krisleech/not_found.png)](https://codeclimate.com/github/krisleech/not_found)
5
+ [![Build Status](https://travis-ci.org/krisleech/not_found.png?branch=master)](https://travis-ci.org/krisleech/not_found)
6
+ [![Coverage Status](https://coveralls.io/repos/krisleech/not_found/badge.png?branch=master)](https://coveralls.io/r/krisleech/not_found?branch=master)
7
+
8
+ Allows you to rescue `ActiveRecord::RecordNotFound` for a specific model.
9
+
10
+ For example if you have a `User` model you can rescue `User::RecordNotFound`.
11
+
12
+ Code which rescue `ActiveRecord::Record` will still work as expected.
13
+
14
+ ## Why?
15
+
16
+ Because a rescue block around code which rescues `ActiveRecord::RecordNotFound`
17
+ might work as expected today, but some time in the future when within that
18
+ block another model ends up raising `ActiveRecord::RecordNotFound` it leads to
19
+ unexpected, or at the very least, behaviour.
20
+
21
+ ## Installation
22
+
23
+ ```ruby
24
+ gem 'not_found'
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Include the mixin for a single model
30
+
31
+ ```ruby
32
+ class User < ActiveRecord::Base
33
+ include NotFound::Mixin
34
+ end
35
+ ```
36
+
37
+ or every model
38
+
39
+ ```ruby
40
+ ActiveRecord::Base.class_eval { include NotFound::Mixin }
41
+ ```
42
+
43
+ and rescue away
44
+
45
+ ```ruby
46
+ begin
47
+ user = User.find(id)
48
+ rescue User::RecordNotFound
49
+ # handle missing user
50
+ end
51
+ ```
52
+
53
+ This lets you handle RecordNotFound for different models seperately.
54
+
55
+ ```ruby
56
+ begin
57
+ user = User.find(id)
58
+ post = Post.find(id)
59
+ rescue User::RecordNotFound
60
+ # handle missing user
61
+ rescue Post::RecordNotFound
62
+ # handle missing post
63
+ end
64
+ ```
65
+
66
+ You can still use `ActiveRecord::RecordNotFound`.
67
+
68
+ ```ruby
69
+ begin
70
+ user = User.find(id)
71
+ post = Post.find(id)
72
+ rescue User::RecordNotFound
73
+ # handle missing user
74
+ rescue ActiveRecord::RecordNotFound
75
+ # handle missing posts and other models
76
+ end
77
+ ```
78
+
79
+ ## Compatibility
80
+
81
+ Tested with MRI 2.x, JRuby and Rubinius.
82
+
83
+ See the [build status](https://travis-ci.org/krisleech/not_found) for details.
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
88
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+
90
+ To install this gem onto your local machine, run `bundle exec rake install`.
91
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
92
+
93
+ ### Running Specs
94
+
95
+ ```
96
+ bundle exec rspec
97
+ ```
98
+
99
+ To run the specs on code changes try [entr](http://entrproject.org/):
100
+
101
+ ```
102
+ ls **/*.rb | entr bundle exec rspec
103
+ ```
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/krisleech/not_found.
108
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
109
+
110
+ ## License
111
+
112
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
113
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,2 @@
1
+ Ensure the backtrace is the same as if ActiveRecord::RecordNotFound was called.
2
+ This might already happen, thanks to `rescue_from` but we need a spec at least.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "not_found"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rspec"
4
+ gem "sqlite3", :platform => :ruby
5
+ gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
6
+ gem 'coveralls', require: false
7
+
8
+ gem 'activerecord', '~> 3.0'
9
+
10
+ gemspec :path => '../'
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rspec"
4
+ gem "sqlite3", :platform => :ruby
5
+ gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
6
+ gem 'coveralls', require: false
7
+
8
+ gem 'activerecord', '~> 4.0'
9
+
10
+ gemspec :path => '../'
@@ -0,0 +1,18 @@
1
+ require "not_found/version"
2
+ require 'active_record'
3
+
4
+ module NotFound
5
+ module Mixin
6
+ def self.included(base)
7
+ base.class_eval do
8
+ include ActiveSupport::Rescuable
9
+
10
+ base.const_set('RecordNotFound', ::ActiveRecord::RecordNotFound)
11
+
12
+ rescue_from ::ActiveRecord::RecordNotFound do |e|
13
+ raise self::RecordNotFound.new(e.message)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module NotFound
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'not_found/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "not_found"
8
+ spec.version = NotFound::VERSION
9
+ spec.authors = ["Kris Leech"]
10
+ spec.email = ["kris.leech@gmail.com"]
11
+
12
+ spec.summary = "Rescue ActiveRecord::RecordNotFound for specific models"
13
+ spec.description = "Rescue ActiveRecord::RecordNotFound for specific models"
14
+ spec.homepage = "https://github.com/krisleech/not_found"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'activerecord'
23
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: not_found
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Rescue ActiveRecord::RecordNotFound for specific models
28
+ email:
29
+ - kris.leech@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - TODO.md
43
+ - bin/console
44
+ - bin/setup
45
+ - gemfiles/activerecord-3.0
46
+ - gemfiles/activerecord-4.0
47
+ - lib/not_found.rb
48
+ - lib/not_found/version.rb
49
+ - not_found.gemspec
50
+ homepage: https://github.com/krisleech/not_found
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.2.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Rescue ActiveRecord::RecordNotFound for specific models
74
+ test_files: []