konmari-routes 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b9791bb9bc8fe9ca5110a18e7f3bb8b873e0f11afed6219671ffc8ad64741c1a
4
+ data.tar.gz: 18ce453574b9ef534e7dd76371ab75ae450688419d55430adee1f88635445fee
5
+ SHA512:
6
+ metadata.gz: e2e8b90a36afef328aba5e4c71cb7bdd2fac3ee97c583c093729fde5aac8a6c9d7c628eab9d5ce0fe04d87ed3115581866823bb48c7551ce6e1ed10cf1c328be
7
+ data.tar.gz: 56659671f65dca804d0eb36911912ed1528b87583ce10ca31724aa1799aaaeef5b2b253e006eff6686b8285e21be522ffe628c17fe9be8bc2185d197b3e1c324
@@ -0,0 +1 @@
1
+ * timothyfstephens
@@ -0,0 +1,20 @@
1
+ name: Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with RSpec
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rspec
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at timothy.f.stephens@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 konmari-routes.gemspec
6
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ konmari-routes (0.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+ yard (0.9.24)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.16)
31
+ konmari-routes!
32
+ rake (~> 10.0)
33
+ rspec (~> 3.0)
34
+ yard
35
+
36
+ BUNDLED WITH
37
+ 1.16.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Timothy Stephens
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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Timothy Stephens
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 THE
21
+ SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Konmari::Routes
2
+
3
+ ![Tests](https://github.com/timothyfstephens/konmari-routes/workflows/Tests/badge.svg)
4
+
5
+ Inspired by thousand-line routes files, KonmariRoutes aims to make routes more manageable by enabling
6
+ a routing structure that mirrors the controller file structure of a standard web application, powered by one guiding principle:
7
+
8
+ Keep only what makes you happy.
9
+
10
+
11
+ This is largely inspired by two articles:
12
+
13
+ - [Keep your rails routes clean and organized](https://blog.lelonek.me/keep-your-rails-routes-clean-and-organized-83e78f2c11f2)
14
+ - [How to split routes.rb into smaller parts](https://blog.arkency.com/2015/02/how-to-split-routes-dot-rb-into-smaller-parts/)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'konmari-routes'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install konmari-routes
31
+
32
+ ## Usage
33
+
34
+ To start using `konmari-routes` you simply need to add a configuration block to your `config/routes.rb` file, outside the standard `routes.draw` block. (Suggest putting at the very top, but bottom works too. Note that where you put it is where the routes will be rendered.)
35
+
36
+ ```
37
+ Konmari::Routes.config do |c|
38
+ c.routes_path = Rails.root.join("config/routes")
39
+ end
40
+ ```
41
+
42
+ This will recursively load all files in `config/routes`, using the folder names to make namespaces for the resources in the files contained in each directory.
43
+
44
+ As a start, it is recommended to just move each top level namespace into on `index.routes` file contained in a folder matching that namespace - you can use any standard `namespace`/`resource`/`etc` block in any file, as long the first line matches the filename.
45
+
46
+ It is also recommended that before/during this process you ensure that you have all routes spec'd properly, as this will provide substantial peace of mind during the transition process, and after all, peace of mind, tranquility, and cleanliness is what we are aiming to acheive.
47
+
48
+ ## Development
49
+
50
+ 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.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/timothyfstephens/konmari-routes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the Konmari::Routes project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/timothyfstephens/konmari-routes/blob/master/CODE_OF_CONDUCT.md).
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "konmari/routes"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,50 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "konmari/routes/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "konmari-routes"
8
+ spec.version = Konmari::Routes::VERSION
9
+ spec.authors = ["Timothy Stephens"]
10
+ spec.email = ["timothy.f.stephens@gmail.com"]
11
+
12
+ spec.summary = %q{Only keep the routes that make you happy}
13
+ spec.description = %q{
14
+ Inspired by thousand-line routes files, KonmariRoutes aims to make routes more manageable by enabling
15
+ a routing structure that mirrors the controller file structure of a standard web application, powered
16
+ by one guiding principle: Keep only what makes you happy. This is largely inspired by two articles:
17
+ https://blog.lelonek.me/keep-your-rails-routes-clean-and-organized-83e78f2c11f2 and
18
+ https://blog.arkency.com/2015/02/how-to-split-routes-dot-rb-into-smaller-parts/
19
+ }
20
+ spec.homepage = "https://github.com/timothyfstephens/konmari-routes"
21
+ spec.license = "MIT"
22
+
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
25
+ if spec.respond_to?(:metadata)
26
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
27
+
28
+ spec.metadata["homepage_uri"] = spec.homepage
29
+ spec.metadata["source_code_uri"] = "https://github.com/timothyfstephens/konmari-routes"
30
+ spec.metadata["changelog_uri"] = "https://github.com/timothyfstephens/konmari-routes/blob/master/CHANGELOG.md"
31
+ else
32
+ raise "RubyGems 2.0 or newer is required to protect against " \
33
+ "public gem pushes."
34
+ end
35
+
36
+ # Specify which files should be added to the gem when it is released.
37
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
38
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
39
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
40
+ end
41
+
42
+ spec.bindir = "exe"
43
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
44
+ spec.require_paths = ["lib"]
45
+
46
+ spec.add_development_dependency "yard"
47
+ spec.add_development_dependency "bundler", "~> 1.16"
48
+ spec.add_development_dependency "rake", "~> 10.0"
49
+ spec.add_development_dependency "rspec", "~> 3.0"
50
+ end
@@ -0,0 +1,18 @@
1
+ require "konmari/routes/version"
2
+ require "konmari/routes/loader"
3
+ require "konmari/routes/rails_reloader"
4
+ require "konmari/routes/configuration"
5
+
6
+ module Konmari
7
+ module Routes
8
+ # (see Konmari::Routes::Loader)
9
+ #
10
+ # In your +config/routes.rb+ file, use this method to configure and then load all routes for the specified application from the provided
11
+ # folder path.
12
+ #
13
+ # @yield [config] The {Konmari::Routes::Configuration} object used to configure the application route drawer.
14
+ def self.config
15
+ Loader.new(Configuration.new.tap { |config| yield config}) if block_given?
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Konmari
2
+ module Routes
3
+ # The configuration object holding the necessary data for {Loader} to do its thing.
4
+ class Configuration
5
+ attr_writer :application
6
+ # @return [Pathname] the folder containing the routing hierarchy to build
7
+ attr_accessor :routes_path
8
+ attr_writer :logger
9
+
10
+ # @return [Logger] the logger to use for debugging purposes (optional, defaults to +Rails.logger+ if using Rails)
11
+ def logger
12
+ @logger || (Object.const_defined?(:Rails) ? Rails.logger : nil)
13
+ end
14
+
15
+ # @return [Application] the application to build these routes for (defaults to +Rails.application+ if using Rails)
16
+ def application
17
+ @application || (Object.const_defined?(:Rails) ? Rails.application : nil)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,156 @@
1
+ module Konmari
2
+ module Routes
3
+ # Given a routes directory, recursively load all routes.
4
+ #
5
+ # Recursively loads all routes in a directory following this algorithm:
6
+ # 1. Load the files in each directory that match PRIORITY_FILES in order listed
7
+ # 2. Load each directory, opening a *new namespace* matching the directory name, and start back at step 1
8
+ # 3. Load all other files in alphabetical order
9
+ #
10
+ # Be aware that any routes will be respected in the order they are loaded
11
+ # Routes files must use extension +.routes+
12
+ #
13
+ # Example file structure:
14
+ # |- routes/
15
+ # | |- index.routes
16
+ # | |- comments.routes
17
+ # | |- users/
18
+ # | |- index.routes
19
+ # | |- friends.routes
20
+ #
21
+ # Analogous routes definitions
22
+ #
23
+ # application.routes.draw do
24
+ # # all index routes
25
+ # # all comments routes (likely a resource, *must* have first code line of `resource/namespace :comments`)
26
+ # namespace :users do
27
+ # # all index routes from `index.routes` file in `users/`
28
+ # # all friends routes from `friends.routes` in `users/`
29
+ # end
30
+ # end
31
+ #
32
+ # The +friends.routes+ file could then be as simple as:
33
+ #
34
+ # # routes/users/friends.routes
35
+ # # NOTE: the resource matches the filename
36
+ # resources :friends, only: [:index, :create, :delete], path: :my_friends # or any other options passed to resource(s)
37
+ #
38
+ # Point being, declaring the namespace is unnecessary. This gives us the _huge_ advantage of being able to have our routes
39
+ # files _exactly_ match the file heirarchy of our controllers. We also have the flexibility, through the prioritized files,
40
+ # to add any other routes we might need without being restrained by the filename constraint.
41
+ #
42
+ class Loader
43
+
44
+ EXPECTED_FILENAME_REGEX = /:(?<fname>.*?)\W/ unless Object.const_defined?(:EXPECTED_FILENAME_REGEX)
45
+ unless Object.const_defined?(:PRIORITY_FILES)
46
+ # The list of filenames which are exempt from the resource name matching rule, and are always loaded first
47
+ # in any directory they are seen in.
48
+ PRIORITY_FILES = [
49
+ :priority,
50
+ :redirects,
51
+ :index
52
+ ].freeze
53
+ end
54
+ private_constant :EXPECTED_FILENAME_REGEX
55
+
56
+ def initialize(config)
57
+ @app = config.application
58
+ @routes_folder = config.routes_path
59
+ @logger = config.logger
60
+ build_routes
61
+ end
62
+
63
+ private
64
+
65
+ def build_routes
66
+ do_router = -> (router) { load_routes(router) }
67
+
68
+ # Something in the scoping in `.draw`
69
+ # doesn't allow us to call load routes directly
70
+ @app.routes.draw { do_router.call(self) }
71
+ end
72
+
73
+ def load_routes(router)
74
+ @router = router
75
+
76
+ return unless @routes_folder&.exist?
77
+
78
+ sorted_children(@routes_folder).each do |path|
79
+ debug "Processing #{path}"
80
+ handle_path(path)
81
+ end
82
+ end
83
+
84
+ def handle_path(base_path)
85
+ if base_path.directory?
86
+ # if its a directory, use the directory name as the namespace
87
+
88
+ ns = base_path.basename.to_s.to_sym
89
+ debug "Adding namespace :#{ns}"
90
+ @router.namespace ns do
91
+ sorted_children(base_path).each do |path|
92
+ handle_path path
93
+ end
94
+ end
95
+ elsif base_path.file?
96
+ process_file base_path
97
+ end
98
+ end
99
+
100
+ def process_file(path)
101
+ routes = File.read path
102
+
103
+ # If its the index file, anything goes
104
+ # Otherwise, get first line that is not a comment
105
+ # or blank, and validate that this file is appropriately named
106
+ unless priority_regex.match(path.basename.to_s)
107
+ first_code_line = routes.split("\n").detect { |l| !l.empty? && !/^\s*#/.match(l) }
108
+
109
+ expected_filename = EXPECTED_FILENAME_REGEX.match(first_code_line)
110
+
111
+ if !expected_filename || !(path.basename.to_s =~ /^#{expected_filename[:fname]}\.routes$/)
112
+ raise FilenameError, "Expected filename to match :#{expected_filename[:fname]} for #{path}"
113
+ end
114
+ end
115
+
116
+ debug "Loaded routes from #{path}"
117
+
118
+ @router.instance_eval routes
119
+ end
120
+
121
+ def sorted_children(folder_path)
122
+ folder_path.children.sort_by do |path|
123
+ if priority_regex =~ path.basename.to_s
124
+ file_index = PRIORITY_FILES.index { |file_name| path.basename.to_s.start_with?(file_name.to_s) }
125
+ "a_#{file_index}_#{path.basename}"
126
+ elsif path.directory?
127
+ "dir_#{path.basename}"
128
+ else
129
+ "file_#{path.basename}"
130
+ end
131
+ end
132
+ end
133
+
134
+ def priority_regex
135
+ @priority_regex ||= /^(#{PRIORITY_FILES.join("|")})\.routes$/
136
+ end
137
+
138
+ def debug(message)
139
+ return unless @logger.respond_to?(:debug)
140
+ @logger.debug message
141
+ end
142
+ end
143
+
144
+ # Raised when a filename does not have the correct extension, or the first detected line of code does not match the filename
145
+ #
146
+ # Eg:
147
+ #
148
+ # # routes/thing/hello.route
149
+ # resource :world
150
+ #
151
+ # would raise this error for two reasons:
152
+ # 1. The extension should be +.routes+
153
+ # 2. The filename should be +world.routes+ or the resource should be +:hello+
154
+ class FilenameError < StandardError; end
155
+ end
156
+ end
@@ -0,0 +1,36 @@
1
+ module Konmari
2
+ module Routes
3
+ # When using Rails, any changes to +config/routes.rb+ are detected by the server when developing and automatically reloaded.
4
+ #
5
+ # In order to mimic this behavior, add {Konmari::Routes::RailsReloader} as middleware in your +development.rb+ file:
6
+ #
7
+ # Rails.application.configure do
8
+ # config.middleware.use Konmari::Routes::RailsReloader
9
+ #
10
+ # ...
11
+ # end
12
+ #
13
+ class RailsReloader
14
+ def initialize(app)
15
+ @app = app
16
+ end
17
+
18
+ def call(env)
19
+ routes_reloader.execute_if_updated
20
+ return *@app.call(env)
21
+ end
22
+
23
+ private
24
+ def routes_reloader
25
+ @routes_reloader ||= ActiveSupport::FileUpdateChecker.new([], rails_routes) do
26
+ Rails.logger.info "Change detected, reloading routes..."
27
+ Rails.application.reload_routes!
28
+ end
29
+ end
30
+
31
+ def rails_routes
32
+ {Rails.root.join("config/routes").to_s => ["routes", "rb"]}
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Konmari
2
+ module Routes
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: konmari-routes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Timothy Stephens
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: "\n Inspired by thousand-line routes files, KonmariRoutes aims to
70
+ make routes more manageable by enabling\n a routing structure that mirrors the
71
+ controller file structure of a standard web application, powered\n by one guiding
72
+ principle: Keep only what makes you happy. This is largely inspired by two articles:\n
73
+ \ https://blog.lelonek.me/keep-your-rails-routes-clean-and-organized-83e78f2c11f2
74
+ and\n https://blog.arkency.com/2015/02/how-to-split-routes-dot-rb-into-smaller-parts/\n
75
+ \ "
76
+ email:
77
+ - timothy.f.stephens@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".github/CODEOWNERS"
83
+ - ".github/workflows/tests.yml"
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - bin/console
94
+ - bin/setup
95
+ - konmari-routes.gemspec
96
+ - lib/konmari/routes.rb
97
+ - lib/konmari/routes/configuration.rb
98
+ - lib/konmari/routes/loader.rb
99
+ - lib/konmari/routes/rails_reloader.rb
100
+ - lib/konmari/routes/version.rb
101
+ homepage: https://github.com/timothyfstephens/konmari-routes
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ homepage_uri: https://github.com/timothyfstephens/konmari-routes
107
+ source_code_uri: https://github.com/timothyfstephens/konmari-routes
108
+ changelog_uri: https://github.com/timothyfstephens/konmari-routes/blob/master/CHANGELOG.md
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.9
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Only keep the routes that make you happy
129
+ test_files: []