rails_default_url_options 1.5.0 → 6.0.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: d4cd442dd369102c6463931394c5ea8011676a361822b096b2d0d2d7222227ff
4
+ data.tar.gz: 3811e6226beac41b4c7a3aadfa18badf922fab5f298401699a9d39d437f64fa5
5
+ SHA512:
6
+ metadata.gz: c0787e3f5993f7a0150e8011aa538b8a0ea5974311806d1763a41129326e95072f9e34f8784c310b0619347165849138caf87a68215d8aea7565955ffc3abe0d
7
+ data.tar.gz: 63735520cc91a62bdf254740dfe88c73403eeda5b05e625be77e29af79c5bab9ca05b5e4baf6b51b6accf84f8047ebcf319d2111954a02108c00c9bf0cc73fc8
data/Rakefile CHANGED
@@ -59,8 +59,8 @@ end
59
59
 
60
60
  task :gemspec do
61
61
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
62
- ignore_directories = ['pkg']
63
- ignore_files = ['test/log', 'a.rb'] + Dir['db/*'] + %w'db'
62
+ ignore_directories = ['pkg', 'db']
63
+ ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db'
64
64
 
65
65
  shiteless =
66
66
  lambda do |list|
@@ -90,6 +90,7 @@ task :gemspec do
90
90
  test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
91
91
  summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
92
92
  description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
93
+ license = object.respond_to?(:license) ? object.license : "Ruby"
93
94
 
94
95
  if This.extensions.nil?
95
96
  This.extensions = []
@@ -127,6 +128,7 @@ task :gemspec do
127
128
  spec.platform = Gem::Platform::RUBY
128
129
  spec.summary = <%= lib.inspect %>
129
130
  spec.description = <%= description.inspect %>
131
+ spec.license = <%= license.inspect %>
130
132
 
131
133
  spec.files =\n<%= files.sort.pretty_inspect %>
132
134
  spec.executables = <%= executables.inspect %>
@@ -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 before_filter. save
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
- # before_filter :configure_default_url_options!
16
+ # before_action :configure_default_url_options!
17
17
  #
18
18
  # protected
19
19
  # def configure_default_url_options!
@@ -24,33 +24,26 @@
24
24
  # with this approach you will always generate absolute links for mailers and,
25
25
  # when those emails are triggered from an http request they will be sent
26
26
  # pointing back to that server. note that this also means emails sent in
27
- # development will correctly point back to http://0.0.0.0:3000, etc.
27
+ # development will correctly point back to http://127.0.0.1:3000, etc.
28
28
 
29
29
  unless defined?(DefaultUrlOptions)
30
30
 
31
- DefaultUrlOptions = (
32
- begin
33
- require 'map'
34
- Map.new
35
- rescue
36
- Hash.new
37
- end
38
- )
31
+ DefaultUrlOptions = Hash.new
39
32
 
40
33
  def DefaultUrlOptions.version
41
- '1.5.0'
34
+ '6.0.0'
42
35
  end
43
36
 
44
37
  def DefaultUrlOptions.dependencies
45
- {
46
- 'map' => [ 'map' , ' >= 6.0.0' ] ,
47
- }
38
+ {}
48
39
  end
49
40
 
50
41
 
51
- def DefaultUrlOptions.configure(request = {})
42
+ def DefaultUrlOptions.configure(request = {}, &block)
52
43
  default_url_options = DefaultUrlOptions
53
44
 
45
+ default_url_options.clear
46
+
54
47
  if request.is_a?(Hash)
55
48
  protocol = request[:protocol] || request['protocol']
56
49
  host = request[:host] || request['host']
@@ -67,9 +60,10 @@ unless defined?(DefaultUrlOptions)
67
60
 
68
61
  normalize!
69
62
 
70
- # force action_mailer to not lick balls
63
+ # force action_mailer to not suck so bad
71
64
  #
72
65
  Rails.configuration.action_mailer.default_url_options = default_url_options
66
+
73
67
  if ActionMailer::Base.respond_to?('default_url_options=')
74
68
  ActionMailer::Base.default_url_options = default_url_options
75
69
  end
@@ -117,11 +111,18 @@ unless defined?(DefaultUrlOptions)
117
111
  delete(:port) if port.to_s == '80'
118
112
  end
119
113
 
120
- if host.to_s =~ /^www\./
121
- self[:host] = host.to_s.gsub(/^www\./, '')
122
- end
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
123
 
124
- keys.each{|key| delete(key) if self[key].nil?}
124
+ self[key.to_s.to_sym] = self.delete(key)
125
+ end
125
126
 
126
127
  self
127
128
  end
@@ -138,49 +139,88 @@ unless defined?(DefaultUrlOptions)
138
139
  DefaultUrlOptions[:port]
139
140
  end
140
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
+
141
153
  def DefaultUrlOptions.to_yaml(*args, &block)
142
154
  Hash.new.update(self).to_yaml(*args, &block)
143
155
  end
144
156
 
157
+ def DefaultUrlOptions.callbacks
158
+ @callbacks ||= []
159
+ end
145
160
  end
146
161
 
147
162
 
148
163
  if defined?(Rails)
149
- ##
150
- #
151
- def DefaultUrlOptions.install_before_filter!
152
- DefaultUrlOptions.configure(
153
- :host => '0.0.0.0',
154
- :port => 3000
155
- ) unless DefaultUrlOptions.configured?
164
+ def DefaultUrlOptions.autoconfigure!(&block)
165
+ unless DefaultUrlOptions.configured?
166
+ DefaultUrlOptions.configure(
167
+ :host => 'localhost',
168
+ :port => 3000
169
+ )
170
+ end
156
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
182
+
183
+ def DefaultUrlOptions.install_before_action!
157
184
  if defined?(::ActionController::Base)
158
185
  ::ActionController::Base.module_eval do
159
- prepend_before_filter do |controller|
160
- unless controller.respond_to?(:configure_default_url_options!)
161
- unless DefaultUrlOptions.configured?
162
- request = controller.send(:request)
186
+ def configure_default_url_options!
187
+ unless DefaultUrlOptions.configured?
188
+ if Rails.env.production?
163
189
  DefaultUrlOptions.configure!(request)
190
+ else
191
+ DefaultUrlOptions.configure(request)
164
192
  end
193
+
194
+ DefaultUrlOptions.callbacks.each do |block|
195
+ block.call
196
+ end
197
+
198
+ DefaultUrlOptions.callbacks.clear
165
199
  end
166
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!)
167
205
  end
168
206
  end
169
207
  end
170
208
 
171
- ##
209
+ =begin
172
210
  #
173
211
  if defined?(Rails::Engine)
174
212
  class Engine < Rails::Engine
175
213
  config.before_initialize do
176
214
  ActiveSupport.on_load(:action_controller) do
177
- DefaultUrlOptions.install_before_filter!
215
+ DefaultUrlOptions.install_before_action!
178
216
  end
179
217
  end
180
218
  end
181
219
  else
182
- DefaultUrlOptions.install_before_filter!
220
+ DefaultUrlOptions.install_before_action!
183
221
  end
222
+ =end
223
+
184
224
  end
185
225
 
186
226
  ::Rails_default_url_options = ::DefaultUrlOptions
@@ -3,10 +3,11 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rails_default_url_options"
6
- spec.version = "1.5.0"
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"
10
+ spec.license = "Ruby"
10
11
 
11
12
  spec.files =
12
13
  ["README.md",
@@ -22,8 +23,6 @@ Gem::Specification::new do |spec|
22
23
  spec.test_files = nil
23
24
 
24
25
 
25
- spec.add_dependency(*["map", " >= 6.0.0"])
26
-
27
26
 
28
27
  spec.extensions.push(*[])
29
28
 
metadata CHANGED
@@ -1,33 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_default_url_options
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
5
- prerelease:
4
+ version: 6.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ara T. Howard
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: map
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 6.0.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 6.0.0
30
- description: ! 'description: rails_default_url_options kicks the ass'
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'description: rails_default_url_options kicks the ass'
31
14
  email: ara.t.howard@gmail.com
32
15
  executables: []
33
16
  extensions: []
@@ -38,27 +21,26 @@ files:
38
21
  - lib/rails_default_url_options.rb
39
22
  - rails_default_url_options.gemspec
40
23
  homepage: https://github.com/ahoward/rails_default_url_options
41
- licenses: []
24
+ licenses:
25
+ - Ruby
26
+ metadata: {}
42
27
  post_install_message:
43
28
  rdoc_options: []
44
29
  require_paths:
45
30
  - lib
46
31
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
32
  requirements:
49
- - - ! '>='
33
+ - - ">="
50
34
  - !ruby/object:Gem::Version
51
35
  version: '0'
52
36
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
37
  requirements:
55
- - - ! '>='
38
+ - - ">="
56
39
  - !ruby/object:Gem::Version
57
40
  version: '0'
58
41
  requirements: []
59
- rubyforge_project: codeforpeople
60
- rubygems_version: 1.8.23
42
+ rubygems_version: 3.0.3
61
43
  signing_key:
62
- specification_version: 3
44
+ specification_version: 4
63
45
  summary: rails_default_url_options
64
46
  test_files: []