router_extensions 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
+ SHA256:
3
+ metadata.gz: 3f54aa9a5a8f270f5f19cf5a178f2b3e0f1f8477adee19f2f476871543e425dc
4
+ data.tar.gz: 63b2b877b5809e6c99cc174f11cadc728c903197953ad9961e3769d37331866d
5
+ SHA512:
6
+ metadata.gz: ec97a55b86be14dcb9e54044049e7163afcfcd803e304ff4a4ba2d5aa35a0d6af8dc981f5c6c0b17b302049646489316ec5b781c27b62a51644c213f8318da44
7
+ data.tar.gz: 0eb26f4d733024feb69701a76dfe1e1edcfecb562806462072fd4c5132684675fd299df56e0ad259976c7963119381abe9797f7cd105a72302d01071b706960b
@@ -0,0 +1,20 @@
1
+ Copyright 2020 masarakki
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.
@@ -0,0 +1,68 @@
1
+ # RouterExtension
2
+
3
+ useful extension for rails routes
4
+
5
+ ## Usage
6
+
7
+ ### partial routes
8
+
9
+ you can partialize routes files.
10
+
11
+ config/routes/admin.rb
12
+
13
+ ```ruby
14
+ namespace :admin do
15
+ root to: 'dashboard#index'
16
+ end
17
+ ```
18
+
19
+ config/routes.rb
20
+
21
+ ```
22
+ Rails.application.routes.draw do
23
+ draw :admin
24
+
25
+ resources :users
26
+ ...
27
+ ...
28
+
29
+ end
30
+ ```
31
+
32
+ ### subdomain
33
+
34
+ ```ruby
35
+ Rails.application.routes.draw do
36
+
37
+ subdomain ENV['API_SUBDOMAIN'] do
38
+ namespace :api do
39
+ end
40
+ end
41
+ ```
42
+
43
+ if `ENV['API_SUBDOMAIN']` present, it means `constrains subdomain: ENV['API_SUBDOMAIN'] do`,
44
+ but if not presents, just ignore this line.
45
+
46
+ subdomain configuration becomes effective only when `API_SUBDOMAIN` given,
47
+ so you can easyly ignore when development.
48
+
49
+ ## Installation
50
+
51
+ Add this line to your application's Gemfile:
52
+
53
+ ```ruby
54
+ gem 'router_extension'
55
+ ```
56
+
57
+ And then execute:
58
+ ```bash
59
+ $ bundle
60
+ ```
61
+
62
+ Or install it yourself as:
63
+ ```bash
64
+ $ gem install router_extension
65
+ ```
66
+
67
+ ## License
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'RouterExtension'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ require 'bundler/gem_tasks'
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:spec)
23
+
24
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'router_extensions/version'
4
+ require 'router_extensions/railtie' if defined? Rails
5
+
6
+ module RouterExtensions
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouterExtensions
4
+ module Partialize
5
+ def draw(route_name)
6
+ instance_eval(File.read(Rails.root.join('config/routes', "#{route_name}.rb")))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'router_extensions/partialize'
4
+ require 'router_extensions/subdomain'
5
+
6
+ module RouterExtensions
7
+ class Railtie < ::Rails::Railtie
8
+ initializer 'router_exntesions', after: 'action_dispatch.configure' do
9
+ ActionDispatch::Routing::Mapper.include RouterExtensions::Partialize
10
+ ActionDispatch::Routing::Mapper.include RouterExtensions::Subdomain
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module RouterExtensions
2
+ module Subdomain
3
+ def subdomain(name)
4
+ return yield unless name
5
+
6
+ constraints subdomain: name do
7
+ yield
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouterExtensions
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :router_extension do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: router_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - masarakki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-01 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.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: useful extensions for rails routes
56
+ email:
57
+ - masaki182@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/router_extensions.rb
66
+ - lib/router_extensions/partialize.rb
67
+ - lib/router_extensions/railtie.rb
68
+ - lib/router_extensions/subdomain.rb
69
+ - lib/router_extensions/version.rb
70
+ - lib/tasks/router_extension_tasks.rake
71
+ homepage: https://github.com/masarakki/router_extensions
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.1.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: useful extensions for rails routes
95
+ test_files: []