sensible_routes 0.0.4

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: 5b2b6d14f70eb338bdd255790623beca7edf1c78
4
+ data.tar.gz: 6dff7a06c8524339679489b0a13fec5f4100a26c
5
+ SHA512:
6
+ metadata.gz: 58ede276c02d1e49b8113a875f0248681652327b76d145a4d2d8bee97a19ad4b6a0894dfe2929c75a7131d8b2aef4483fd514ce26a6b42666421a34883b0f543
7
+ data.tar.gz: cdc09925a68c5eb1086f6faed37ea39cb11915bd36d790cd79b68168aeeb5a197d50c47d8c3715c196d742b5462353fcab6da390345dfaa4861161309015f155
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .idea
14
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sensible_routes.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,142 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sensible_routes (0.0.2)
5
+ rails (~> 5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ builder (3.2.3)
53
+ concurrent-ruby (1.0.5)
54
+ crass (1.0.4)
55
+ diff-lcs (1.3)
56
+ erubi (1.7.1)
57
+ globalid (0.4.1)
58
+ activesupport (>= 4.2.0)
59
+ i18n (1.0.1)
60
+ concurrent-ruby (~> 1.0)
61
+ loofah (2.2.2)
62
+ crass (~> 1.0.2)
63
+ nokogiri (>= 1.5.9)
64
+ mail (2.7.0)
65
+ mini_mime (>= 0.1.1)
66
+ marcel (0.3.2)
67
+ mimemagic (~> 0.3.2)
68
+ method_source (0.9.0)
69
+ mimemagic (0.3.2)
70
+ mini_mime (1.0.0)
71
+ mini_portile2 (2.3.0)
72
+ minitest (5.11.3)
73
+ nio4r (2.3.1)
74
+ nokogiri (1.8.3)
75
+ mini_portile2 (~> 2.3.0)
76
+ rack (2.0.5)
77
+ rack-test (1.0.0)
78
+ rack (>= 1.0, < 3)
79
+ rails (5.2.0)
80
+ actioncable (= 5.2.0)
81
+ actionmailer (= 5.2.0)
82
+ actionpack (= 5.2.0)
83
+ actionview (= 5.2.0)
84
+ activejob (= 5.2.0)
85
+ activemodel (= 5.2.0)
86
+ activerecord (= 5.2.0)
87
+ activestorage (= 5.2.0)
88
+ activesupport (= 5.2.0)
89
+ bundler (>= 1.3.0)
90
+ railties (= 5.2.0)
91
+ sprockets-rails (>= 2.0.0)
92
+ rails-dom-testing (2.0.3)
93
+ activesupport (>= 4.2.0)
94
+ nokogiri (>= 1.6)
95
+ rails-html-sanitizer (1.0.4)
96
+ loofah (~> 2.2, >= 2.2.2)
97
+ railties (5.2.0)
98
+ actionpack (= 5.2.0)
99
+ activesupport (= 5.2.0)
100
+ method_source
101
+ rake (>= 0.8.7)
102
+ thor (>= 0.18.1, < 2.0)
103
+ rake (10.5.0)
104
+ rspec (3.7.0)
105
+ rspec-core (~> 3.7.0)
106
+ rspec-expectations (~> 3.7.0)
107
+ rspec-mocks (~> 3.7.0)
108
+ rspec-core (3.7.1)
109
+ rspec-support (~> 3.7.0)
110
+ rspec-expectations (3.7.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.7.0)
113
+ rspec-mocks (3.7.0)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.7.0)
116
+ rspec-support (3.7.1)
117
+ sprockets (3.7.2)
118
+ concurrent-ruby (~> 1.0)
119
+ rack (> 1, < 3)
120
+ sprockets-rails (3.2.1)
121
+ actionpack (>= 4.0)
122
+ activesupport (>= 4.0)
123
+ sprockets (>= 3.0.0)
124
+ thor (0.20.0)
125
+ thread_safe (0.3.6)
126
+ tzinfo (1.2.5)
127
+ thread_safe (~> 0.1)
128
+ websocket-driver (0.7.0)
129
+ websocket-extensions (>= 0.1.0)
130
+ websocket-extensions (0.1.3)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ bundler (~> 1.16)
137
+ rake (~> 10.0)
138
+ rspec (~> 3.0)
139
+ sensible_routes!
140
+
141
+ BUNDLED WITH
142
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ArtOfCode-
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Sensible::Routes
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sensible/routes`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sensible-routes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sensible-routes
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sensible-routes.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SensibleRoutes
4
+ VERSION = '0.0.4'
5
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SensibleRoute
4
+ attr_reader :path, :url_details, :parameters, :verb
5
+
6
+ def initialize(rt)
7
+ @parameters = []
8
+
9
+ formatter = rt.path.build_formatter
10
+ parts = []
11
+ matcher = []
12
+
13
+ # Yes, this is a hack. Yes, it will probably break. No, it's not 'temporary'.
14
+ internal = formatter.instance_variable_get :@parts
15
+ internal.each do |part|
16
+ if part.is_a? String
17
+ parts << part
18
+ matcher << part
19
+ elsif part.is_a? ActionDispatch::Journey::Format::Parameter
20
+ parts << ":#{part.name}"
21
+ @parameters << part.name
22
+ matcher << if rt.requirements[part.name.to_sym]
23
+ rt.requirements[part.name.to_sym]
24
+ else
25
+ '[^/]+'
26
+ end
27
+ end
28
+ end
29
+
30
+ @path = parts.join
31
+ @url_details = rt.requirements
32
+ @verb = rt.verb
33
+ @regex = Regexp.new "^#{matcher.join}$"
34
+ end
35
+
36
+ def match?(path)
37
+ @regex.match?(path)
38
+ end
39
+
40
+ def self.hook_rails
41
+ Rails.instance_eval <<EOF
42
+ cache.delete :sensible_routes
43
+
44
+ def self.sensible_routes
45
+ Rails.cache.fetch :sensible_routes do
46
+ routes = SensibleRouteCollection.new
47
+ Rails.application.routes.routes.to_a.each { |r| routes.add(SensibleRoute.new(r)) }
48
+ return routes
49
+ end
50
+ end
51
+ EOF
52
+ end
53
+ end
54
+
55
+ class SensibleRouteCollection
56
+ def initialize(**opts)
57
+ @routes = if opts[:routes]
58
+ opts[:routes]
59
+ else
60
+ []
61
+ end
62
+ end
63
+
64
+ def add(new)
65
+ @routes << new
66
+ end
67
+
68
+ def to_a
69
+ @routes
70
+ end
71
+
72
+ def select(&block)
73
+ self.class.new(routes: @routes.select(&block))
74
+ end
75
+
76
+ def map(&block)
77
+ @routes.map(&block)
78
+ end
79
+
80
+ def each
81
+ @routes.each do |rt|
82
+ yield rt
83
+ end
84
+ self
85
+ end
86
+
87
+ def match_for(path)
88
+ @routes.select { |rt| rt.match?(path) }.first
89
+ end
90
+
91
+ def route_for(**url_details)
92
+ @routes.select { |rt| url_details <= rt.url_details }.first
93
+ end
94
+
95
+ def controller(controller)
96
+ self.class.new(routes: @routes.select { |rt| rt.url_details[:controller] == controller.to_s })
97
+ end
98
+
99
+ def without(*paths)
100
+ routes = paths.map { |p| match_for p }
101
+ self.class.new(routes: @routes - routes)
102
+ end
103
+ end
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sensible_routes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sensible_routes'
8
+ spec.version = SensibleRoutes::VERSION
9
+ spec.authors = ['ArtOfCode-']
10
+ spec.email = ['hello@artofcode.co.uk']
11
+
12
+ spec.summary = 'Simple and comprehensible route introspection library for Rails.'
13
+ spec.homepage = 'https://github.com/ArtOfCode-/sensible-routes'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.16'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+
25
+ spec.add_dependency 'rails', '~> 5'
26
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensible_routes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - ArtOfCode-
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5'
69
+ description:
70
+ email:
71
+ - hello@artofcode.co.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/sensible_routes.rb
83
+ - lib/sensible_routes/version.rb
84
+ - sensible_routes.gemspec
85
+ homepage: https://github.com/ArtOfCode-/sensible-routes
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Simple and comprehensible route introspection library for Rails.
109
+ test_files: []