rails_default_url_options 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_default_url_options.rb +72 -33
- data/rails_default_url_options.gemspec +1 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4cd442dd369102c6463931394c5ea8011676a361822b096b2d0d2d7222227ff
|
4
|
+
data.tar.gz: 3811e6226beac41b4c7a3aadfa18badf922fab5f298401699a9d39d437f64fa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0787e3f5993f7a0150e8011aa538b8a0ea5974311806d1763a41129326e95072f9e34f8784c310b0619347165849138caf87a68215d8aea7565955ffc3abe0d
|
7
|
+
data.tar.gz: 63735520cc91a62bdf254740dfe88c73403eeda5b05e625be77e29af79c5bab9ca05b5e4baf6b51b6accf84f8047ebcf319d2111954a02108c00c9bf0cc73fc8
|
@@ -7,13 +7,13 @@
|
|
7
7
|
#
|
8
8
|
# 2) dynamically configure these defaults on the first request seen.
|
9
9
|
#
|
10
|
-
# all we require to do this is a smart hash and simple
|
10
|
+
# all we require to do this is a smart hash and simple before_action. save
|
11
11
|
# this file as 'config/intiializers/deafult_url_options.rb' and add this
|
12
12
|
# before filter to your application_controller.rb
|
13
13
|
#
|
14
14
|
# class ApplicationController < ActionController::Base
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# before_action :configure_default_url_options!
|
17
17
|
#
|
18
18
|
# protected
|
19
19
|
# def configure_default_url_options!
|
@@ -31,7 +31,7 @@ unless defined?(DefaultUrlOptions)
|
|
31
31
|
DefaultUrlOptions = Hash.new
|
32
32
|
|
33
33
|
def DefaultUrlOptions.version
|
34
|
-
'
|
34
|
+
'6.0.0'
|
35
35
|
end
|
36
36
|
|
37
37
|
def DefaultUrlOptions.dependencies
|
@@ -39,7 +39,7 @@ unless defined?(DefaultUrlOptions)
|
|
39
39
|
end
|
40
40
|
|
41
41
|
|
42
|
-
def DefaultUrlOptions.configure(request = {})
|
42
|
+
def DefaultUrlOptions.configure(request = {}, &block)
|
43
43
|
default_url_options = DefaultUrlOptions
|
44
44
|
|
45
45
|
default_url_options.clear
|
@@ -60,19 +60,15 @@ unless defined?(DefaultUrlOptions)
|
|
60
60
|
|
61
61
|
normalize!
|
62
62
|
|
63
|
-
# force action_mailer to not
|
63
|
+
# force action_mailer to not suck so bad
|
64
64
|
#
|
65
65
|
Rails.configuration.action_mailer.default_url_options = default_url_options
|
66
|
+
|
66
67
|
if ActionMailer::Base.respond_to?('default_url_options=')
|
67
68
|
ActionMailer::Base.default_url_options = default_url_options
|
68
69
|
end
|
69
70
|
|
70
71
|
default_url_options
|
71
|
-
ensure
|
72
|
-
keys.each do |key|
|
73
|
-
next if key.is_a?(Symbol)
|
74
|
-
self[key.to_s.to_sym] = self.fetch(key)
|
75
|
-
end
|
76
72
|
end
|
77
73
|
|
78
74
|
def DefaultUrlOptions.configure!(request = {})
|
@@ -115,7 +111,18 @@ unless defined?(DefaultUrlOptions)
|
|
115
111
|
delete(:port) if port.to_s == '80'
|
116
112
|
end
|
117
113
|
|
118
|
-
keys.each
|
114
|
+
keys.each do |key|
|
115
|
+
if self[key].nil?
|
116
|
+
delete(key)
|
117
|
+
next
|
118
|
+
end
|
119
|
+
|
120
|
+
if key.is_a?(Symbol)
|
121
|
+
next
|
122
|
+
end
|
123
|
+
|
124
|
+
self[key.to_s.to_sym] = self.delete(key)
|
125
|
+
end
|
119
126
|
|
120
127
|
self
|
121
128
|
end
|
@@ -132,56 +139,88 @@ unless defined?(DefaultUrlOptions)
|
|
132
139
|
DefaultUrlOptions[:port]
|
133
140
|
end
|
134
141
|
|
142
|
+
def DefaultUrlOptions.domain
|
143
|
+
case host
|
144
|
+
when '0.0.0.0', '127.0.0.1'
|
145
|
+
'localhost'
|
146
|
+
when /\A[\d.]+\Z/iomx
|
147
|
+
host
|
148
|
+
else
|
149
|
+
host.split('.').last(2).join('.')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
135
153
|
def DefaultUrlOptions.to_yaml(*args, &block)
|
136
154
|
Hash.new.update(self).to_yaml(*args, &block)
|
137
155
|
end
|
138
156
|
|
157
|
+
def DefaultUrlOptions.callbacks
|
158
|
+
@callbacks ||= []
|
159
|
+
end
|
139
160
|
end
|
140
161
|
|
141
162
|
|
142
163
|
if defined?(Rails)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
164
|
+
def DefaultUrlOptions.autoconfigure!(&block)
|
165
|
+
unless DefaultUrlOptions.configured?
|
166
|
+
DefaultUrlOptions.configure(
|
167
|
+
:host => 'localhost',
|
168
|
+
:port => 3000
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
if block
|
173
|
+
DefaultUrlOptions.callbacks.push(block)
|
174
|
+
end
|
175
|
+
|
176
|
+
DefaultUrlOptions.install_before_action!
|
177
|
+
end
|
178
|
+
|
179
|
+
def DefaultUrlOptions.autoconfigure(&block)
|
180
|
+
DefaultUrlOptions.autoconfigure!(&block)
|
181
|
+
end
|
150
182
|
|
183
|
+
def DefaultUrlOptions.install_before_action!
|
151
184
|
if defined?(::ActionController::Base)
|
152
185
|
::ActionController::Base.module_eval do
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
DefaultUrlOptions.configure(request)
|
164
|
-
end
|
186
|
+
def configure_default_url_options!
|
187
|
+
unless DefaultUrlOptions.configured?
|
188
|
+
if Rails.env.production?
|
189
|
+
DefaultUrlOptions.configure!(request)
|
190
|
+
else
|
191
|
+
DefaultUrlOptions.configure(request)
|
192
|
+
end
|
193
|
+
|
194
|
+
DefaultUrlOptions.callbacks.each do |block|
|
195
|
+
block.call
|
165
196
|
end
|
197
|
+
|
198
|
+
DefaultUrlOptions.callbacks.clear
|
166
199
|
end
|
167
200
|
end
|
201
|
+
|
202
|
+
prepend_before_action = respond_to?(:prepend_before_filter) ? :prepend_before_filter : :prepend_before_action
|
203
|
+
|
204
|
+
send(prepend_before_action, :configure_default_url_options!)
|
168
205
|
end
|
169
206
|
end
|
170
207
|
end
|
171
208
|
|
172
|
-
|
209
|
+
=begin
|
173
210
|
#
|
174
211
|
if defined?(Rails::Engine)
|
175
212
|
class Engine < Rails::Engine
|
176
213
|
config.before_initialize do
|
177
214
|
ActiveSupport.on_load(:action_controller) do
|
178
|
-
DefaultUrlOptions.
|
215
|
+
DefaultUrlOptions.install_before_action!
|
179
216
|
end
|
180
217
|
end
|
181
218
|
end
|
182
219
|
else
|
183
|
-
DefaultUrlOptions.
|
220
|
+
DefaultUrlOptions.install_before_action!
|
184
221
|
end
|
222
|
+
=end
|
223
|
+
|
185
224
|
end
|
186
225
|
|
187
226
|
::Rails_default_url_options = ::DefaultUrlOptions
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "rails_default_url_options"
|
6
|
-
spec.version = "
|
6
|
+
spec.version = "6.0.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "rails_default_url_options"
|
9
9
|
spec.description = "description: rails_default_url_options kicks the ass"
|
@@ -13,7 +13,6 @@ Gem::Specification::new do |spec|
|
|
13
13
|
["README.md",
|
14
14
|
"Rakefile",
|
15
15
|
"lib",
|
16
|
-
"lib/rails_default_url_options",
|
17
16
|
"lib/rails_default_url_options.rb",
|
18
17
|
"rails_default_url_options.gemspec"]
|
19
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_default_url_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'description: rails_default_url_options kicks the ass'
|
14
14
|
email: ara.t.howard@gmail.com
|
@@ -39,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
|
43
|
-
rubygems_version: 2.7.6
|
42
|
+
rubygems_version: 3.0.3
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: rails_default_url_options
|