route_bound 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f72207b485163d3dfd270b83e1786c637e9069ff
4
+ data.tar.gz: 03b78f750bc521dca0438c6b632f5f54fb718014
5
+ SHA512:
6
+ metadata.gz: a64ff3764abf9228f2336268d89b75d8a4c1e954c2d2db20604eb7b24c9643b363e6b224db13407985a51908068ce0a453eed286b4a6d6ae8c6bf83b91471423
7
+ data.tar.gz: 06f73322114e9799a7e54566323373a19b762b4f1d34bf5c22a4bf27315cd349708edea1f9788b5066c1e0a94489092a4bade7ac4da8a37eb2fbec692f641c71
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Jason Charnes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # RouteBound
2
+ Rails needs some more magic, right? RouteBound is implicit model binding for Ruby on Rails. RouteBound will use a route to try and load a resource for you.
3
+
4
+ This gem is still very young. It was inspired by [Laravel's implicit model binding](https://laravel.com/docs/5.3/routing#route-model-binding).
5
+
6
+ ## Usage
7
+ Implicit model binding will try to load the requested resource for you. In the following example:
8
+
9
+ ```ruby
10
+ # config/routes.rb
11
+ get 'products/:id', to: 'products#show'
12
+ ```
13
+
14
+ ```ruby
15
+ # app/controllers/products_controller.rb
16
+ class ProductsController < ApplicationController
17
+ include RouteBound
18
+
19
+ def show
20
+ end
21
+ end
22
+ ```
23
+
24
+ If you go to `/products/1`, you will have access to `@product` without having to explicitly call `Product.find(params[:id])`. It's already been done for you.
25
+
26
+ If it can't find the resource, it will silently continue on as normal and will log out to the Rails logger.
27
+
28
+ ### Caveats
29
+ These are hopefully just temporary.
30
+ * It doesn't _currently_ work with nested resources
31
+ * It doesn't _currently_ allow you to override the query to load the resource
32
+
33
+ ## Installation
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'route_bound'
38
+ ```
39
+
40
+ And then execute:
41
+ ```bash
42
+ $ bundle
43
+ ```
44
+
45
+ Or install it yourself as:
46
+ ```bash
47
+ $ gem install route_bound
48
+ ```
49
+
50
+ ## Contributing
51
+ Contribution directions go here.
52
+
53
+ ## License
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RouteBound'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,23 @@
1
+ # Implicit model binding for Rails.
2
+ # Include in any ApplicationController instance.
3
+ module RouteBound
4
+ def self.included(base)
5
+ base.before_action :route_bound_find_model
6
+ end
7
+
8
+ def route_bound_find_model
9
+ instance_variable_set("@#{implied_model_name.downcase}", implied_model)
10
+ rescue NameError
11
+ Rails.logger.info("RouteBound unable to find the model #{implied_model_name}")
12
+ end
13
+
14
+ private
15
+
16
+ def implied_model_name
17
+ params[:controller].singularize.capitalize
18
+ end
19
+
20
+ def implied_model
21
+ Object.const_get(implied_model_name).send(:find, params[:id])
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module RouteBound
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :route_bound do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: route_bound
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Charnes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Implicit model binding for Ruby on Rails, based on Laravel's implicit
62
+ model binding.
63
+ email:
64
+ - jason@thecharnes.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - MIT-LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - lib/route_bound.rb
73
+ - lib/route_bound/version.rb
74
+ - lib/tasks/route_band.rake
75
+ homepage: https://github.com/jasoncharnes/route_bound
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Implicit model binding for Ruby on Rails.
99
+ test_files: []