duty_free 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc07e472cca2426a694a59754a83d12b93ad6572530d9b5f584b8aecfbbbacf4
4
- data.tar.gz: 7b160b28ab7e70409ee095d6ba1892fa06d24310ebba4529ae0a5f8c57949673
3
+ metadata.gz: aa24c207ea3302cdd1cb04bf479c8140c63b4854a3ca628cb9a9f2b02ca9db19
4
+ data.tar.gz: 2d01e88512109b271209cb95f5b2b3e8f3b4222fda500e0d5f7b8ab06f6a0c11
5
5
  SHA512:
6
- metadata.gz: 25e0702b19e9e5e810f0632da354060ae15da6207c7af33c930eb5825c2f28046e09a481a49ce95bbce46ddb02cc6dd991d2d2728582335f1260b7153bf28998
7
- data.tar.gz: 0e265c33a7b1611aa8cb5c28edef6632d3f9e1c2adc9c15f644b6757b2229fb22248a0a37589449e97adbea8876e76aa601331b44556f277ea17255ad6af47d0
6
+ metadata.gz: 025a2518dd7b88156e77be76697eeb0480b0a3fe7930fda9d4f2509b4d718e9d17744a6f5fb4ffdf8709ea7a80a0056fdb525d19ade89e3da1af084a9feb7a54
7
+ data.tar.gz: c1fd873299cb7bfca3f265d949c9e7bcc2788b5d2854a92c409ac4c5d7248827f07c4e21c2b353c10115d97201103b3e78dbbd119b2b61ae3b1a2f1659533649
@@ -627,7 +627,6 @@ module DutyFree
627
627
  start = 0
628
628
  trim_prefix = v.titleize[start..-(v.name.length + 2)]
629
629
  trim_prefix << ' ' unless trim_prefix.blank?
630
- binding.pry unless assoc
631
630
  if assoc.belongs_to?
632
631
  klass = Object.const_get(assoc&.class_name)
633
632
  # Try to find a unique item if one is referenced
@@ -97,7 +97,7 @@ module DutyFree
97
97
 
98
98
  # ===================================
99
99
  # Epic require patch
100
- def self._patch_require(module_filename, folder_matcher, search_text, replacement_text, autoload_symbol = nil)
100
+ def self._patch_require(module_filename, folder_matcher, replacements, autoload_symbol = nil, is_bundler = false)
101
101
  mod_name_parts = module_filename.split('.')
102
102
  extension = case mod_name_parts.last
103
103
  when 'rb', 'so', 'o'
@@ -120,10 +120,17 @@ module DutyFree
120
120
  Dir.mkdir(new_part) unless Dir.exist?(new_part)
121
121
  new_part
122
122
  end
123
- if ::DutyFree::Util._write_patched(folder_matcher, module_filename, extension, custom_require_dir, nil, search_text, replacement_text) &&
123
+ if ::DutyFree::Util._write_patched(folder_matcher, module_filename, extension, custom_require_dir, nil, replacements) &&
124
124
  !alp.include?(custom_require_dir)
125
125
  alp.unshift(custom_require_dir)
126
126
  end
127
+ elsif is_bundler
128
+ puts "Bundler hack"
129
+ require 'pry-byebug'
130
+ binding.pry
131
+ x = 5
132
+ # bin_path
133
+ # puts Bundler.require.inspect
127
134
  else
128
135
  unless (require_overrides = ::DutyFree::Util.instance_variable_get(:@_require_overrides))
129
136
  ::DutyFree::Util.instance_variable_set(:@_require_overrides, (require_overrides = {}))
@@ -134,19 +141,19 @@ module DutyFree
134
141
  # then required in place of the original.
135
142
 
136
143
  Kernel.module_exec do
137
- # class << self
138
144
  alias_method :orig_require, :require
139
- # end
140
145
  # To be most faithful to Ruby's normal behaviour, this should look like a public singleton
141
146
  define_method(:require) do |name|
147
+ # %%% Can get a message such as "ActionDispatch::Routing is not missing constant RouteSet! (NameError)"
148
+ # binding.pry if name.start_with?('action_dispatch/routing/route_') # || name == 'active_support/values/time_zone'
142
149
  if (require_override = ::DutyFree::Util.instance_variable_get(:@_require_overrides)[name])
143
- extension, folder_matcher, search_text, replacement_text, autoload_symbol = require_override
150
+ extension, folder_matcher, replacements, autoload_symbol = require_override
144
151
  patched_filename = "/patched_#{name.tr('/', '_')}#{extension}"
145
152
  if $LOADED_FEATURES.find { |f| f.end_with?(patched_filename) }
146
153
  false
147
154
  else
148
155
  is_replaced = false
149
- if (replacement_path = ::DutyFree::Util._write_patched(folder_matcher, name, extension, ::DutyFree::Util._custom_require_dir, patched_filename, search_text, replacement_text))
156
+ if (replacement_path = ::DutyFree::Util._write_patched(folder_matcher, name, extension, ::DutyFree::Util._custom_require_dir, patched_filename, replacements))
150
157
  is_replaced = Kernel.send(:orig_require, replacement_path)
151
158
  elsif replacement_path.nil?
152
159
  puts "Couldn't find #{name} to require it!"
@@ -159,12 +166,13 @@ module DutyFree
159
166
  end
160
167
  end
161
168
  end
162
- require_overrides[module_filename] = [extension, folder_matcher, search_text, replacement_text, autoload_symbol]
169
+ require_overrides[module_filename] = [extension, folder_matcher, replacements, autoload_symbol]
163
170
  end
164
171
  end
165
172
 
166
173
  def self._custom_require_dir
167
174
  unless (custom_require_dir = ::DutyFree::Util.instance_variable_get(:@_custom_require_dir))
175
+ require 'tmpdir'
168
176
  ::DutyFree::Util.instance_variable_set(:@_custom_require_dir, (custom_require_dir = Dir.mktmpdir))
169
177
  # So normal Ruby require will now pick this one up
170
178
  $LOAD_PATH.unshift(custom_require_dir)
@@ -178,11 +186,12 @@ module DutyFree
178
186
 
179
187
  # Returns the full path to the replaced filename, or
180
188
  # false if the file already exists, and nil if it was unable to write anything.
181
- def self._write_patched(folder_matcher, name, extension, dir, patched_filename, search_text, replacement_text)
189
+ def self._write_patched(folder_matcher, name, extension, dir, patched_filename, replacements)
182
190
  # See if our replacement file might already exist for some reason
183
191
  name = +"/#{name}" unless name.start_with?('/')
184
192
  name << extension unless name.end_with?(extension)
185
- return false if File.exist?(replacement_path = "#{dir}#{patched_filename || name}")
193
+ puts (replacement_path = "#{dir}#{patched_filename || name}")
194
+ return false if File.exist?(replacement_path)
186
195
 
187
196
  # Dredge up the original .rb file, doctor it, and then require it instead
188
197
  num_written = nil
@@ -193,9 +202,14 @@ module DutyFree
193
202
  orig_path = "#{path}#{name}"
194
203
  break if path.include?(folder_matcher) && (orig_as = File.open(orig_path))
195
204
  end
196
- if (orig_text = orig_as&.read)
197
- File.open(replacement_path, 'w') do |replacement|
198
- num_written = replacement.write(orig_text.gsub(search_text, replacement_text))
205
+ puts [folder_matcher, name].inspect
206
+ if (updated_text = orig_as&.read)
207
+ File.open(replacement_path, 'w') do |replaced_file|
208
+ replacements = [replacements] unless replacements.first.is_a?(Array)
209
+ replacements.each do |search_text, replacement_text|
210
+ updated_text.gsub!(search_text, replacement_text)
211
+ end
212
+ num_written = replaced_file.write(updated_text)
199
213
  end
200
214
  orig_as.close
201
215
  end
@@ -5,7 +5,7 @@ module DutyFree
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 9
8
+ TINY = 10
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/duty_free.rb CHANGED
@@ -50,15 +50,15 @@ if ActiveRecord.version < ::Gem::Version.new('3.2') &&
50
50
  # Remove circular reference for "now"
51
51
  ::DutyFree::Util._patch_require(
52
52
  'active_support/values/time_zone.rb', '/activesupport',
53
- ' def parse(str, now=now)',
54
- ' def parse(str, now=now())'
53
+ [' def parse(str, now=now)',
54
+ ' def parse(str, now=now())']
55
55
  )
56
56
  # Remove circular reference for "reflection" for ActiveRecord 3.1
57
57
  if ActiveRecord.version >= ::Gem::Version.new('3.1')
58
58
  ::DutyFree::Util._patch_require(
59
59
  'active_record/associations/has_many_association.rb', '/activerecord',
60
- 'reflection = reflection)',
61
- 'reflection = reflection())',
60
+ ['reflection = reflection)',
61
+ 'reflection = reflection())'],
62
62
  :HasManyAssociation # Make sure the path for this guy is available to be autoloaded
63
63
  )
64
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duty_free
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-26 00:00:00.000000000 Z
11
+ date: 2024-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord