rails_current 1.9.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTEyNzAzZTc0MGYzOWZhMzc0MjY5ZTY1N2MyOWQ1ZGRkOGFhZDE2NQ==
5
- data.tar.gz: !binary |-
6
- MmE2NzM3YjYxMjIzMTcxM2QzYWZlMTRjYmEyOGM0M2MwNjczMTM5ZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDZlZjA1ZmY4MzIzZTJjMWIxMTg1YmNkZjllYWY0ZGQ4YjdkMjk3NjE3YmFl
10
- NDAyMWJmMDA4ZjhhNjExZDFlNDYwNDFmZTcxMTk5MjZjOThhZDk0NzVlZGIy
11
- OTkyNGNlOGYwMmRhYWRkNDE0YjQzMDJjMWY5NGUwNDYwNWM5OGM=
12
- data.tar.gz: !binary |-
13
- NWM4ODVlMTIzNWU0OTgzMzUzNGQ4NjI0YjkyZDlhZGZjODEzZmIxYzVhNGY5
14
- NjE2ZjNiMzMyMTdiY2NkZDA5YWQ1ZGJiYTZlNjRiZjdkN2U3Mzc0NjUyNDdl
15
- NWQwYzcyNmM5ZjU3YThiYzY3MWU2NzNhYmNkNjRhNzI5YmQyZTU=
2
+ SHA1:
3
+ metadata.gz: 186f701535b7d65d21e71f7d1598a7caeb17f946
4
+ data.tar.gz: 6e51dc1f716e488da848212f0b107728f22b63f5
5
+ SHA512:
6
+ metadata.gz: 9482a45d120991b3380422c515769a286f049d362fcab55561fcd9aea8bd40188d740235fa7eb2dc9f09d61bfa6d260eca583df46342b87284d53c11c165d507
7
+ data.tar.gz: af54cc69dbf1b94c2e71905ae5e802964b8cf3041f982d051e95c36691bb83db2b720be749b417742548a0a47bf411b2c44422061752dbf02aca947532a42dcb
@@ -0,0 +1,8 @@
1
+ Manifest.txt
2
+ README.md
3
+ Rakefile
4
+ lib/rails_current.rb
5
+ tasks/default.rake
6
+ tasks/this.rb
7
+ test/rails_current_test.rb
8
+ test/testing.rb
data/README.md CHANGED
@@ -1,38 +1,29 @@
1
- --------------------------------
2
- NAME
3
- --------------------------------
4
- rails_current
1
+ # rails_current
5
2
 
6
- --------------------------------
7
- DESCRIPTION
8
- --------------------------------
3
+ ## DESCRIPTION
9
4
 
10
- track 'current_user' et all in a tidy, global, and thread-safe fashion.
5
+ track `current_user` et all in a tidy, global, and thread-safe fashion.
11
6
 
12
7
 
13
- --------------------------------
14
- SYNOPSIS
15
- --------------------------------
8
+ ## SYNOPSIS
16
9
 
17
- most rails apps scatter a bunch of @current_foobar vars everywhere. don't do
18
- that. it's fugly. instead, do this.
10
+ most rails apps scatter a bunch of `@current_foobar` vars everywhere. don't do that. it's fugly. instead, do this.
19
11
 
20
- declare the current_XXX variables you'll want tracked. you can pass a block
21
- for lazy computation
12
+ declare the `current_XXX` variables you'll want tracked. you can pass a block for lazy computation
22
13
 
23
- class ApplicationController
14
+ ```
15
+ class ApplicationController
24
16
 
25
- Current(:user){ User.find session[:current_user }
26
- Current(:account)
17
+ Current(:user){ User.find session[:current_user }
18
+ Current(:account)
27
19
 
28
- end
29
-
30
- you can now access the current state two ways
31
-
20
+ end
21
+ ```
32
22
 
33
- 1) globally from anywhere in your code base
34
-
23
+ you can now access the current state two ways
35
24
 
25
+ * globally from anywhere in your code base
26
+ ```
36
27
  if Current.user
37
28
 
38
29
  ...
@@ -40,29 +31,29 @@ SYNOPSIS
40
31
  end
41
32
 
42
33
  Current.user = User.find(id)
34
+ ```
35
+ * using the `current_` methods that are added by including the Current module
36
+ into any class (ActionController::Base and ActionView::Base automatically
37
+ include it)
38
+ ```
39
+ if current_user
43
40
 
44
- 2) or using the current_ methods that are added by including the Current
45
- module into any class (ActionController::Base and ActionView::Base
46
- automatically include it)
47
-
48
-
49
- if current_user
41
+ ...
50
42
 
51
- ...
52
-
53
- end
43
+ end
54
44
 
55
- self.current_user = User.find(id)
45
+ self.current_user = User.find(id)
46
+ ```
56
47
 
48
+ the `Current` module is cleared out before every request and is thread safe.
57
49
 
58
- the Current module is cleared out before every request and is thread safe.
50
+ ## INSTALL
59
51
 
60
- --------------------------------
61
- INSTALL
62
- --------------------------------
52
+ ```
53
+ gem install rails_current
63
54
 
64
- gem install rails-current
65
55
 
56
+ gem 'rails-current', :require => 'current'
57
+ bundle install
58
+ ```
66
59
 
67
- gem 'rails-current', :require => 'current'
68
- bundle install
data/Rakefile CHANGED
@@ -1,394 +1,18 @@
1
- This.rubyforge_project = 'codeforpeople'
2
- This.author = "Ara T. Howard"
3
- This.email = "ara.t.howard@gmail.com"
4
- This.homepage = "https://github.com/ahoward/#{ This.lib }"
1
+ # vim: syntax=ruby
2
+ load 'tasks/this.rb'
5
3
 
6
- task :license do
7
- open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
8
- end
9
-
10
- task :default do
11
- puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
12
- end
13
-
14
- task :test do
15
- run_tests!
16
- end
17
-
18
- namespace :test do
19
- task(:unit){ run_tests!(:unit) }
20
- task(:functional){ run_tests!(:functional) }
21
- task(:integration){ run_tests!(:integration) }
22
- end
23
-
24
- def run_tests!(which = nil)
25
- which ||= '**'
26
- test_dir = File.join(This.dir, "test")
27
- test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
28
- test_rbs = Dir.glob(test_glob).sort
29
-
30
- div = ('=' * 119)
31
- line = ('-' * 119)
32
-
33
- test_rbs.each_with_index do |test_rb, index|
34
- testno = index + 1
35
- command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
36
-
37
- puts
38
- say(div, :color => :cyan, :bold => true)
39
- say("@#{ testno } => ", :bold => true, :method => :print)
40
- say(command, :color => :cyan, :bold => true)
41
- say(line, :color => :cyan, :bold => true)
42
-
43
- system(command)
44
-
45
- say(line, :color => :cyan, :bold => true)
46
-
47
- status = $?.exitstatus
48
-
49
- if status.zero?
50
- say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
51
- say("SUCCESS", :color => :green, :bold => true)
52
- else
53
- say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
54
- say("FAILURE", :color => :red, :bold => true)
55
- end
56
- say(line, :color => :cyan, :bold => true)
57
-
58
- exit(status) unless status.zero?
59
- end
60
- end
61
-
62
-
63
- task :gemspec do
64
- ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
65
- ignore_directories = ['pkg']
66
- ignore_files = ['test/log']
67
-
68
- shiteless =
69
- lambda do |list|
70
- list.delete_if do |entry|
71
- next unless test(?e, entry)
72
- extension = File.basename(entry).split(%r/[.]/).last
73
- ignore_extensions.any?{|ext| ext === extension}
74
- end
75
- list.delete_if do |entry|
76
- next unless test(?d, entry)
77
- dirname = File.expand_path(entry)
78
- ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
79
- end
80
- list.delete_if do |entry|
81
- next unless test(?f, entry)
82
- filename = File.expand_path(entry)
83
- ignore_files.any?{|file| File.expand_path(file) == filename}
84
- end
85
- end
86
-
87
- lib = This.lib
88
- object = This.object
89
- version = This.version
90
- files = shiteless[Dir::glob("**/**")]
91
- executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
92
- #has_rdoc = true #File.exist?('doc')
93
- test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
94
- summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
95
- description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
- license = object.respond_to?(:license) ? object.license : "same as ruby's"
97
-
98
- if This.extensions.nil?
99
- This.extensions = []
100
- extensions = This.extensions
101
- %w( Makefile configure extconf.rb ).each do |ext|
102
- extensions << ext if File.exists?(ext)
103
- end
104
- end
105
- extensions = [extensions].flatten.compact
106
-
107
- if This.dependencies.nil?
108
- dependencies = []
109
- else
110
- case This.dependencies
111
- when Hash
112
- dependencies = This.dependencies.values
113
- when Array
114
- dependencies = This.dependencies
115
- end
116
- end
117
-
118
- template =
119
- if test(?e, 'gemspec.erb')
120
- Template{ IO.read('gemspec.erb') }
121
- else
122
- Template {
123
- <<-__
124
- ## <%= lib %>.gemspec
125
- #
126
-
127
- Gem::Specification::new do |spec|
128
- spec.name = <%= lib.inspect %>
129
- spec.version = <%= version.inspect %>
130
- spec.platform = Gem::Platform::RUBY
131
- spec.summary = <%= lib.inspect %>
132
- spec.description = <%= description.inspect %>
133
- spec.license = <%= license.inspect %>
134
-
135
- spec.files =\n<%= files.sort.pretty_inspect %>
136
- spec.executables = <%= executables.inspect %>
137
-
138
- spec.require_path = "lib"
139
-
140
- spec.test_files = <%= test_files.inspect %>
141
-
142
- <% dependencies.each do |lib_version| %>
143
- spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
144
- <% end %>
145
-
146
- spec.extensions.push(*<%= extensions.inspect %>)
147
-
148
- spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
149
- spec.author = <%= This.author.inspect %>
150
- spec.email = <%= This.email.inspect %>
151
- spec.homepage = <%= This.homepage.inspect %>
152
- end
153
- __
154
- }
155
- end
156
-
157
- Fu.mkdir_p(This.pkgdir)
158
- gemspec = "#{ lib }.gemspec"
159
- open(gemspec, "w"){|fd| fd.puts(template)}
160
- This.gemspec = gemspec
161
- end
162
-
163
- task :gem => [:clean, :gemspec] do
164
- Fu.mkdir_p(This.pkgdir)
165
- before = Dir['*.gem']
166
- cmd = "gem build #{ This.gemspec }"
167
- `#{ cmd }`
168
- after = Dir['*.gem']
169
- gem = ((after - before).first || after.first) or abort('no gem!')
170
- Fu.mv(gem, This.pkgdir)
171
- This.gem = File.join(This.pkgdir, File.basename(gem))
172
- end
173
-
174
- task :readme do
175
- samples = ''
176
- prompt = '~ > '
177
- lib = This.lib
178
- version = This.version
179
-
180
- Dir['sample*/*'].sort.each do |sample|
181
- samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
4
+ This.name = "rails_current"
5
+ This.author = "Ara T. Howard"
6
+ This.email = "ara.t.howard@gmail.com"
7
+ This.homepage = "https://github.com/ahoward/#{ This.name }"
182
8
 
183
- cmd = "cat #{ sample }"
184
- samples << Util.indent(prompt + cmd, 2) << "\n\n"
185
- samples << Util.indent(`#{ cmd }`, 4) << "\n"
9
+ This.ruby_gemspec do |spec|
10
+ spec.add_dependency( 'map', '~> 6.0')
186
11
 
187
- cmd = "ruby #{ sample }"
188
- samples << Util.indent(prompt + cmd, 2) << "\n\n"
12
+ spec.add_development_dependency( 'rake' , '~> 10.1')
13
+ spec.add_development_dependency( 'minitest' , '~> 5.0' )
189
14
 
190
- cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
191
- samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
192
- end
193
-
194
- template =
195
- if test(?e, 'README.erb')
196
- Template{ IO.read('README.erb') }
197
- else
198
- Template {
199
- <<-__
200
- NAME
201
- #{ lib }
202
-
203
- DESCRIPTION
204
-
205
- INSTALL
206
- gem install #{ lib }
207
-
208
- SAMPLES
209
- #{ samples }
210
- __
211
- }
212
- end
213
-
214
- open("README", "w"){|fd| fd.puts template}
215
- end
216
-
217
-
218
- task :clean do
219
- Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
220
- end
221
-
222
-
223
- task :release => [:clean, :gemspec, :gem] do
224
- gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
225
- raise "which one? : #{ gems.inspect }" if gems.size > 1
226
- raise "no gems?" if gems.size < 1
227
-
228
- cmd = "gem push #{ This.gem }"
229
- puts cmd
230
- puts
231
- system(cmd)
232
- abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
233
-
234
- cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
235
- puts cmd
236
- puts
237
- system(cmd)
238
- abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
15
+ spec.licenses = ['Ruby']
239
16
  end
240
17
 
241
-
242
-
243
-
244
-
245
- BEGIN {
246
- # support for this rakefile
247
- #
248
- $VERBOSE = nil
249
-
250
- require 'ostruct'
251
- require 'erb'
252
- require 'fileutils'
253
- require 'rbconfig'
254
- require 'pp'
255
-
256
- # fu shortcut
257
- #
258
- Fu = FileUtils
259
-
260
- # cache a bunch of stuff about this rakefile/environment
261
- #
262
- This = OpenStruct.new
263
-
264
- This.file = File.expand_path(__FILE__)
265
- This.dir = File.dirname(This.file)
266
- This.pkgdir = File.join(This.dir, 'pkg')
267
-
268
- # grok lib
269
- #
270
- lib = ENV['LIB']
271
- unless lib
272
- lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
273
- end
274
- This.lib = lib
275
-
276
- # grok version
277
- #
278
- version = ENV['VERSION']
279
- unless version
280
- require "./lib/#{ This.lib }"
281
- This.name = lib.capitalize
282
- This.object = eval(This.name)
283
- version = This.object.send(:version)
284
- end
285
- This.version = version
286
-
287
- # see if dependencies are export by the module
288
- #
289
- if This.object.respond_to?(:dependencies)
290
- This.dependencies = This.object.dependencies
291
- end
292
-
293
- # we need to know the name of the lib an it's version
294
- #
295
- abort('no lib') unless This.lib
296
- abort('no version') unless This.version
297
-
298
- # discover full path to this ruby executable
299
- #
300
- c = Config::CONFIG
301
- bindir = c["bindir"] || c['BINDIR']
302
- ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
303
- ruby_ext = c['EXEEXT'] || ''
304
- ruby = File.join(bindir, (ruby_install_name + ruby_ext))
305
- This.ruby = ruby
306
-
307
- # some utils
308
- #
309
- module Util
310
- def indent(s, n = 2)
311
- s = unindent(s)
312
- ws = ' ' * n
313
- s.gsub(%r/^/, ws)
314
- end
315
-
316
- def unindent(s)
317
- indent = nil
318
- s.each_line do |line|
319
- next if line =~ %r/^\s*$/
320
- indent = line[%r/^\s*/] and break
321
- end
322
- indent ? s.gsub(%r/^#{ indent }/, "") : s
323
- end
324
- extend self
325
- end
326
-
327
- # template support
328
- #
329
- class Template
330
- def initialize(&block)
331
- @block = block
332
- @template = block.call.to_s
333
- end
334
- def expand(b=nil)
335
- ERB.new(Util.unindent(@template)).result((b||@block).binding)
336
- end
337
- alias_method 'to_s', 'expand'
338
- end
339
- def Template(*args, &block) Template.new(*args, &block) end
340
-
341
- # colored console output support
342
- #
343
- This.ansi = {
344
- :clear => "\e[0m",
345
- :reset => "\e[0m",
346
- :erase_line => "\e[K",
347
- :erase_char => "\e[P",
348
- :bold => "\e[1m",
349
- :dark => "\e[2m",
350
- :underline => "\e[4m",
351
- :underscore => "\e[4m",
352
- :blink => "\e[5m",
353
- :reverse => "\e[7m",
354
- :concealed => "\e[8m",
355
- :black => "\e[30m",
356
- :red => "\e[31m",
357
- :green => "\e[32m",
358
- :yellow => "\e[33m",
359
- :blue => "\e[34m",
360
- :magenta => "\e[35m",
361
- :cyan => "\e[36m",
362
- :white => "\e[37m",
363
- :on_black => "\e[40m",
364
- :on_red => "\e[41m",
365
- :on_green => "\e[42m",
366
- :on_yellow => "\e[43m",
367
- :on_blue => "\e[44m",
368
- :on_magenta => "\e[45m",
369
- :on_cyan => "\e[46m",
370
- :on_white => "\e[47m"
371
- }
372
- def say(phrase, *args)
373
- options = args.last.is_a?(Hash) ? args.pop : {}
374
- options[:color] = args.shift.to_s.to_sym unless args.empty?
375
- keys = options.keys
376
- keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
377
-
378
- color = options[:color]
379
- bold = options.has_key?(:bold)
380
-
381
- parts = [phrase]
382
- parts.unshift(This.ansi[color]) if color
383
- parts.unshift(This.ansi[:bold]) if bold
384
- parts.push(This.ansi[:clear]) if parts.size > 1
385
-
386
- method = options[:method] || :puts
387
-
388
- Kernel.send(method, parts.join)
389
- end
390
-
391
- # always run out of the project dir
392
- #
393
- Dir.chdir(This.dir)
394
- }
18
+ load 'tasks/default.rake'
@@ -1,8 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Current
4
+ VERSION = '2.1.0'
4
5
  def Current.version
5
- '1.9.0'
6
+ VERSION
6
7
  end
7
8
 
8
9
  def Current.dependencies
@@ -153,8 +154,7 @@ module Current
153
154
  case method.to_s
154
155
  when /^current_(.*)$/
155
156
  msg = $1
156
- value = Current.send(msg, *args, &block)
157
-
157
+ Current.send(msg, *args, &block)
158
158
  else
159
159
  super
160
160
  end
@@ -172,8 +172,8 @@ module Current
172
172
  controller.perform_caching = true
173
173
  controller.cache_store = store
174
174
 
175
- request = ActionDispatch::TestRequest.new
176
- response = ActionDispatch::TestResponse.new
175
+ request = ActionDispatch::TestRequest.create({})
176
+ response = ActionDispatch::TestResponse.create({})
177
177
 
178
178
  controller.request = request
179
179
  controller.response = response
@@ -262,10 +262,10 @@ if defined?(Rails)
262
262
  ##
263
263
  #
264
264
  module Current
265
- def Current.install_before_filter!
265
+ def Current.install_before_action!
266
266
  if defined?(::ActionController::Base)
267
267
  ::ActionController::Base.module_eval do
268
- prepend_before_filter do |controller|
268
+ prepend_before_action do |controller|
269
269
  Current.clear
270
270
  Current.controller = Current.proxy_for(controller)
271
271
  Current.action = controller ? controller.send(:action_name) : nil
@@ -285,12 +285,12 @@ if defined?(Rails)
285
285
  class Engine < Rails::Engine
286
286
  config.before_initialize do
287
287
  ActiveSupport.on_load(:action_controller) do
288
- Current.install_before_filter!
288
+ Current.install_before_action!
289
289
  end
290
290
  end
291
291
  end
292
292
  else
293
- Current.install_before_filter!
293
+ Current.install_before_action!
294
294
  end
295
295
 
296
296
  end
@@ -301,4 +301,3 @@ BEGIN {
301
301
  Object.send(:remove_const, :Current) if defined?(::Current)
302
302
  Object.send(:remove_const, :Rails_current) if defined?(::Rails_current)
303
303
  }
304
-
@@ -0,0 +1,227 @@
1
+ # vim: syntax=ruby
2
+ require 'rake/clean'
3
+ require 'digest'
4
+ #------------------------------------------------------------------------------
5
+ # If you want to Develop on this project just run 'rake develop' and you'll
6
+ # have all you need to get going. If you want to use bundler for development,
7
+ # then run 'rake develop:using_bundler'
8
+ #------------------------------------------------------------------------------
9
+ namespace :develop do
10
+
11
+ # Install all the development and runtime dependencies of this gem using the
12
+ # gemspec.
13
+ task :default => 'Gemfile' do
14
+ require 'rubygems/dependency_installer'
15
+ installer = ::Gem::DependencyInstaller.new
16
+ puts "Installing bundler..."
17
+ installer.install 'bundler'
18
+ sh 'bundle install'
19
+ puts "\n\nNow run 'rake test'"
20
+ end
21
+
22
+ # Create a Gemfile that just references the gemspec
23
+ file 'Gemfile' => :gemspec do
24
+ File.open( "Gemfile", "w+" ) do |f|
25
+ f.puts "# DO NOT EDIT - This file is automatically generated"
26
+ f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
27
+ f.puts 'source "https://rubygems.org/"'
28
+ f.puts 'gemspec'
29
+ end
30
+ end
31
+ end
32
+ desc "Boostrap development"
33
+ task :develop => "develop:default"
34
+
35
+ #------------------------------------------------------------------------------
36
+ # Minitest - standard TestTask
37
+ #------------------------------------------------------------------------------
38
+ begin
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new( :test ) do |t|
41
+ t.ruby_opts = %w[ -rubygems ]
42
+ t.libs = %w[ lib spec test ]
43
+ t.pattern = "{test,spec}/**/{test_*,*_spec,*_test}.rb"
44
+ end
45
+
46
+ task :test_requirements
47
+ task :test => :test_requirements
48
+ task :default => :test
49
+ rescue LoadError
50
+ This.task_warning( 'test' )
51
+ end
52
+
53
+ #------------------------------------------------------------------------------
54
+ # RDoc - standard rdoc rake task, although we must make sure to use a more
55
+ # recent version of rdoc since it is the one that has 'tomdoc' markup
56
+ #------------------------------------------------------------------------------
57
+ begin
58
+ gem 'rdoc' # otherwise we get the wrong task from stdlib
59
+ require 'rdoc/task'
60
+ RDoc::Task.new do |t|
61
+ t.markup = 'tomdoc'
62
+ t.rdoc_dir = 'doc'
63
+ t.main = 'README.md'
64
+ t.title = "#{This.name} #{This.version}"
65
+ t.rdoc_files.include( FileList['*.{rdoc,md,txt}'], FileList['ext/**/*.c'],
66
+ FileList['lib/**/*.rb'] )
67
+ end
68
+ rescue StandardError, LoadError
69
+ This.task_warning( 'rdoc' )
70
+ end
71
+
72
+ #------------------------------------------------------------------------------
73
+ # Manifest - We want an explicit list of thos files that are to be packaged in
74
+ # the gem. Most of this is from Hoe.
75
+ #------------------------------------------------------------------------------
76
+ namespace 'manifest' do
77
+ desc "Check the manifest"
78
+ task :check => :clean do
79
+ files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
80
+ files = files.select{ |f| File.file?( f ) }
81
+
82
+ tmp = "Manifest.tmp"
83
+ File.open( tmp, 'w' ) do |f|
84
+ f.puts files.join("\n")
85
+ end
86
+
87
+ begin
88
+ sh "diff -du Manifest.txt #{tmp}"
89
+ ensure
90
+ rm tmp
91
+ end
92
+ puts "Manifest looks good"
93
+ end
94
+
95
+ desc "Generate the manifest"
96
+ task :generate => :clean do
97
+ files = %x[ git ls-files ].split("\n").sort
98
+ files.reject! { |f| f =~ This.exclude_from_manifest }
99
+ File.open( "Manifest.txt", "w" ) do |f|
100
+ f.puts files.join("\n")
101
+ end
102
+ end
103
+ end
104
+
105
+ #------------------------------------------------------------------------------
106
+ # Fixme - look for fixmes and report them
107
+ #------------------------------------------------------------------------------
108
+ namespace :fixme do
109
+ task :default => 'manifest:check' do
110
+ This.manifest.each do |file|
111
+ next if file == __FILE__
112
+ next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
113
+ puts "FIXME: Rename #{file}" if file =~ /fixme/i
114
+ IO.readlines( file ).each_with_index do |line, idx|
115
+ prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
116
+ puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
117
+ end
118
+ end
119
+ end
120
+
121
+ def fixme_project_root
122
+ This.project_path( '../fixme' )
123
+ end
124
+
125
+ def fixme_project_path( subtree )
126
+ fixme_project_root.join( subtree )
127
+ end
128
+
129
+ def local_fixme_files
130
+ This.manifest.select { |p| p =~ %r|^tasks/| }
131
+ end
132
+
133
+ def outdated_fixme_files
134
+ local_fixme_files.select do |local|
135
+ upstream = fixme_project_path( local )
136
+ upstream.exist? &&
137
+ ( Digest::SHA256.file( local ) != Digest::SHA256.file( upstream ) )
138
+ end
139
+ end
140
+
141
+ def fixme_up_to_date?
142
+ outdated_fixme_files.empty?
143
+ end
144
+
145
+ desc "See if the fixme tools are outdated"
146
+ task :outdated => :release_check do
147
+ if fixme_up_to_date? then
148
+ puts "Fixme files are up to date."
149
+ else
150
+ outdated_fixme_files.each do |f|
151
+ puts "#{f} is outdated"
152
+ end
153
+ end
154
+ end
155
+
156
+ desc "Update outdated fixme files"
157
+ task :update => :release_check do
158
+ if fixme_up_to_date? then
159
+ puts "Fixme files are already up to date."
160
+ else
161
+ puts "Updating fixme files:"
162
+ outdated_fixme_files.each do |local|
163
+ upstream = fixme_project_path( local )
164
+ puts " * #{local}"
165
+ FileUtils.cp( upstream, local )
166
+ end
167
+ puts "Use your git commands as appropriate."
168
+ end
169
+ end
170
+ end
171
+ desc "Look for fixmes and report them"
172
+ task :fixme => "fixme:default"
173
+
174
+ #------------------------------------------------------------------------------
175
+ # Gem Specification
176
+ #------------------------------------------------------------------------------
177
+ # Really this is only here to support those who use bundler
178
+ desc "Build the #{This.name}.gemspec file"
179
+ task :gemspec do
180
+ File.open( This.gemspec_file, "wb+" ) do |f|
181
+ f.puts "# DO NOT EDIT - This file is automatically generated"
182
+ f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
183
+ f.write This.platform_gemspec.to_ruby
184
+ end
185
+ end
186
+
187
+ # .rbc files from ruby 2.0
188
+ CLOBBER << FileList["**/*.rbc"]
189
+
190
+ # The standard gem packaging task, everyone has it.
191
+ require 'rubygems/package_task'
192
+ ::Gem::PackageTask.new( This.platform_gemspec ) do
193
+ # nothing
194
+ end
195
+
196
+ #------------------------------------------------------------------------------
197
+ # Release - the steps we go through to do a final release, this is pulled from
198
+ # a compbination of mojombo's rakegem, hoe and hoe-git
199
+ #
200
+ # 1) make sure we are on the master branch
201
+ # 2) make sure there are no uncommitted items
202
+ # 3) check the manifest and make sure all looks good
203
+ # 4) build the gem
204
+ # 5) do an empty commit to have the commit message of the version
205
+ # 6) tag that commit as the version
206
+ # 7) push master
207
+ # 8) push the tag
208
+ # 7) pus the gem
209
+ #------------------------------------------------------------------------------
210
+ task :release_check do
211
+ unless `git branch` =~ /^\* master$/
212
+ abort "You must be on the master branch to release!"
213
+ end
214
+ unless `git status` =~ /^nothing to commit/m
215
+ abort "Nope, sorry, you have unfinished business"
216
+ end
217
+ end
218
+
219
+ desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
220
+ task :release => [ :release_check, 'manifest:check', :gem ] do
221
+ sh "git commit --allow-empty -a -m 'Release #{This.version}'"
222
+ sh "git tag -a -m 'v#{This.version}' v#{This.version}"
223
+ sh "git push origin master"
224
+ sh "git push origin v#{This.version}"
225
+ sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
226
+ end
227
+
@@ -0,0 +1,207 @@
1
+ require 'pathname'
2
+
3
+ # Public: A Class containing all the metadata and utilities needed to manage a
4
+ # ruby project.
5
+ class ThisProject
6
+ # The name of this project
7
+ attr_accessor :name
8
+
9
+ # The author's name
10
+ attr_accessor :author
11
+
12
+ # The email address of the author(s)
13
+ attr_accessor :email
14
+
15
+ # The homepage of this project
16
+ attr_accessor :homepage
17
+
18
+ # The regex of files to exclude from the manifest
19
+ attr_accessor :exclude_from_manifest
20
+
21
+ # The hash of Gem::Specifications keyed' by platform
22
+ attr_accessor :gemspecs
23
+
24
+ # Public: Initialize ThisProject
25
+ #
26
+ # Yields self
27
+ def initialize(&block)
28
+ @exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
29
+ /^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
30
+ /^[^\/]+\.gemspec/,
31
+ /\.(swp|jar|bundle|so|rvmrc|travis.yml)$/,
32
+ /~$/)
33
+ @gemspecs = Hash.new
34
+ yield self if block_given?
35
+ end
36
+
37
+ # Public: return the version of ThisProject
38
+ #
39
+ # Search the ruby files in the project looking for the one that has the
40
+ # version string in it. This does not eval any code in the project, it parses
41
+ # the source code looking for the string.
42
+ #
43
+ # Returns a String version
44
+ def version
45
+ [ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
46
+ path = project_path( v )
47
+ next unless path.exist?
48
+ line = path.read[/^\s*VERSION\s*=\s*.*/]
49
+ if line then
50
+ return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
51
+ end
52
+ end
53
+ end
54
+
55
+ # Internal: Return a section of an RDoc file with the given section name
56
+ #
57
+ # path - the relative path in the project of the file to parse
58
+ # section_name - the section out of the file from which to parse data
59
+ #
60
+ # Retuns the text of the section as an array of paragrphs.
61
+ def section_of( file, section_name )
62
+ re = /^[=#]+ (.*)$/
63
+ sectional = project_path( file )
64
+ parts = sectional.read.split( re )[1..-1]
65
+ parts.map! { |p| p.strip }
66
+
67
+ sections = Hash.new
68
+ Hash[*parts].each do |k,v|
69
+ sections[k] = v.split("\n\n")
70
+ end
71
+ return sections[section_name]
72
+ end
73
+
74
+ # Internal: print out a warning about the give task
75
+ def task_warning( task )
76
+ warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
77
+ end
78
+
79
+ # Internal: Return the full path to the file that is relative to the project
80
+ # root.
81
+ #
82
+ # path - the relative path of the file from the project root
83
+ #
84
+ # Returns the Pathname of the file
85
+ def project_path( *relative_path )
86
+ project_root.join( *relative_path )
87
+ end
88
+
89
+ # Internal: The absolute path of this file
90
+ #
91
+ # Returns the Pathname of this file.
92
+ def this_file_path
93
+ Pathname.new( __FILE__ ).expand_path
94
+ end
95
+
96
+ # Internal: The root directory of this project
97
+ #
98
+ # This is defined as being the directory that is in the path of this project
99
+ # that has the first Rakefile
100
+ #
101
+ # Returns the Pathname of the directory
102
+ def project_root
103
+ this_file_path.ascend do |p|
104
+ rakefile = p.join( 'Rakefile' )
105
+ return p if rakefile.exist?
106
+ end
107
+ end
108
+
109
+ # Internal: Returns the contents of the Manifest.txt file as an array
110
+ #
111
+ # Returns an Array of strings
112
+ def manifest
113
+ manifest_file = project_path( "Manifest.txt" )
114
+ abort "You need a Manifest.txt" unless manifest_file.readable?
115
+ manifest_file.readlines.map { |l| l.strip }
116
+ end
117
+
118
+ # Internal: Return the files that define the extensions
119
+ #
120
+ # Returns an Array
121
+ def extension_conf_files
122
+ manifest.grep( /extconf.rb\Z/ )
123
+ end
124
+
125
+ # Internal: Returns the gemspace associated with the current ruby platform
126
+ def platform_gemspec
127
+ gemspecs.fetch(platform) { This.ruby_gemspec }
128
+ end
129
+
130
+ def core_gemspec
131
+ Gem::Specification.new do |spec|
132
+ spec.name = name
133
+ spec.version = version
134
+ spec.author = author
135
+ spec.email = email
136
+ spec.homepage = homepage
137
+
138
+ spec.summary = summary
139
+ spec.description = description
140
+ spec.license = license
141
+
142
+ spec.files = manifest
143
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
144
+ spec.test_files = spec.files.grep(/^spec/)
145
+
146
+ spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
147
+ spec.rdoc_options = [ "--main" , 'README.md',
148
+ "--markup", "tomdoc" ]
149
+
150
+ spec.required_ruby_version = '>= 2.2.0'
151
+ end
152
+ end
153
+
154
+ # Internal: Return the gemspec for the ruby platform
155
+ def ruby_gemspec( core = core_gemspec, &block )
156
+ yielding_gemspec( 'ruby', core, &block )
157
+ end
158
+
159
+ # Internal: Return the gemspec for the jruby platform
160
+ def java_gemspec( core = core_gemspec, &block )
161
+ yielding_gemspec( 'java', core, &block )
162
+ end
163
+
164
+ # Internal: give an initial spec and a key, create a new gemspec based off of
165
+ # it.
166
+ #
167
+ # This will force the new gemspecs 'platform' to be that of the key, since the
168
+ # only reason you would have multiple gemspecs at this point is to deal with
169
+ # different platforms.
170
+ def yielding_gemspec( key, core )
171
+ spec = gemspecs[key] ||= core.dup
172
+ spec.platform = key
173
+ yield spec if block_given?
174
+ return spec
175
+ end
176
+
177
+ # Internal: Return the platform of ThisProject at the current moment in time.
178
+ def platform
179
+ (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
180
+ end
181
+
182
+ # Internal: Return the DESCRIPTION section of the README.rdoc file
183
+ def description_section
184
+ section_of( 'README.md', 'DESCRIPTION')
185
+ end
186
+
187
+ # Internal: Return the summary text from the README
188
+ def summary
189
+ description_section.first
190
+ end
191
+
192
+ # Internal: Return the full description text from the README
193
+ def description
194
+ description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
195
+ end
196
+
197
+ def license
198
+ "ISC"
199
+ end
200
+
201
+ # Internal: The path to the gemspec file
202
+ def gemspec_file
203
+ project_path( "#{ name }.gemspec" )
204
+ end
205
+ end
206
+
207
+ This = ThisProject.new
@@ -1,3 +1,4 @@
1
+ require 'testing'
1
2
 
2
3
  Testing Current do
3
4
 
@@ -42,7 +43,7 @@ Testing Current do
42
43
  wa = Queue.new
43
44
  wb = Queue.new
44
45
 
45
- a = Thread.new do
46
+ Thread.new do
46
47
  Thread.current.abort_on_exception = true
47
48
  id = Thread.current.object_id
48
49
  Current.foo = 40
@@ -52,7 +53,7 @@ Testing Current do
52
53
  ra.push( Current.attributes )
53
54
  end
54
55
 
55
- b = Thread.new do
56
+ Thread.new do
56
57
  Thread.current.abort_on_exception = true
57
58
  id = Thread.current.object_id
58
59
  Current.foo = 'forty'
@@ -94,7 +95,7 @@ Testing Current do
94
95
  assert{ c.current_bar == 42.0 }
95
96
 
96
97
  o = assert do
97
- Object.new.tap{|o| o.extend Current }
98
+ Object.new.tap{|o1| o1.extend Current }
98
99
  end
99
100
 
100
101
  assert{ o.current_foo == 42 }
@@ -171,7 +172,7 @@ Testing Current do
171
172
  assert{ Current.attributes =~ {:user => nil, :controller => nil, :action => nil} }
172
173
 
173
174
  assert{ $before_initialize_called }
174
- assert{ $prepend_before_filter_called }
175
+ assert{ $prepend_before_action_called }
175
176
 
176
177
  assert do
177
178
  Current.user = :user
@@ -201,10 +202,10 @@ private
201
202
 
202
203
  module ActionController
203
204
  class Base
204
- def Base.prepend_before_filter(*args, &block)
205
+ def Base.prepend_before_action(*args, &block)
205
206
  block.call
206
207
  ensure
207
- $prepend_before_filter_called = true
208
+ $prepend_before_action_called = true
208
209
  end
209
210
 
210
211
  def Base.helper(&block)
@@ -243,10 +244,10 @@ private
243
244
 
244
245
  module ActionController
245
246
  class Base
246
- def Base.prepend_before_filter(*args, &block)
247
+ def Base.prepend_before_action(*args, &block)
247
248
  block.call
248
249
  ensure
249
- $prepend_before_filter_called = true
250
+ $prepend_before_action_called = true
250
251
  end
251
252
 
252
253
  def Base.helper(&block)
@@ -272,7 +273,6 @@ private
272
273
  end
273
274
  end
274
275
 
275
-
276
276
  BEGIN {
277
277
  $this = File.expand_path(__FILE__)
278
278
  $root = File.dirname(File.dirname($this))
@@ -1,16 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
- #
3
- require 'test/unit'
4
-
5
- testdir = File.expand_path(File.dirname(__FILE__))
6
- rootdir = File.dirname(testdir)
7
- libdir = File.join(rootdir, 'lib')
8
-
9
- STDOUT.sync = true
10
-
11
- $:.unshift(testdir) unless $:.include?(testdir)
12
- $:.unshift(libdir) unless $:.include?(libdir)
13
- $:.unshift(rootdir) unless $:.include?(rootdir)
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require 'rails_current'
14
6
 
15
7
  class Testing
16
8
  class Slug < ::String
@@ -37,7 +29,7 @@ class Testing
37
29
  end
38
30
 
39
31
  def Testing(*args, &block)
40
- Class.new(::Test::Unit::TestCase) do
32
+ Class.new(::Minitest::Test) do
41
33
 
42
34
  ## class methods
43
35
  #
@@ -103,6 +95,35 @@ def Testing(*args, &block)
103
95
  @cleanup.push(block) if block
104
96
  @cleanup
105
97
  end
98
+
99
+ end
100
+
101
+ def assert_nothing_raised(*args, &block )
102
+ if Module === args.last
103
+ msg = nil
104
+ else
105
+ msg = args.pop
106
+ end
107
+ begin
108
+ line = __LINE__; yield
109
+ rescue MiniTest::Skip
110
+ raise
111
+ rescue Exception => e
112
+ bt = e.backtrace
113
+ as = e.instance_of?(MiniTest::Assertion)
114
+ if as
115
+ ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
116
+ bt.reject! {|ln| ans =~ ln}
117
+ end
118
+ if ((args.empty? && !as) ||
119
+ args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
120
+ msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
121
+ raise MiniTest::Assertion, msg.call, bt
122
+ else
123
+ raise
124
+ end
125
+ end
126
+ nil
106
127
  end
107
128
 
108
129
  ## configure the subclass!
@@ -124,7 +145,7 @@ def Testing(*args, &block)
124
145
  expected = getopt(:expected, options){ missing }
125
146
  actual = getopt(:actual, options){ missing }
126
147
  if expected == missing and actual == missing
127
- actual, expected, *ignored = options.to_a.flatten
148
+ actual, expected, *_ = options.to_a.flatten
128
149
  end
129
150
  expected = expected.call() if expected.respond_to?(:call)
130
151
  actual = actual.call() if actual.respond_to?(:call)
@@ -184,14 +205,3 @@ def Testing(*args, &block)
184
205
  self
185
206
  end
186
207
  end
187
-
188
-
189
- if $0 == __FILE__
190
-
191
- Testing 'Testing' do
192
- testing('foo'){ assert true }
193
- test{ assert true }
194
- p instance_methods.grep(/test/)
195
- end
196
-
197
- end
metadata CHANGED
@@ -1,64 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_current
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 2.1.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: 2014-09-21 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: map
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.1
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.1
27
- description: track 'current_user' et all in a tidy, global, and thread-safe fashion
28
- for your rails apps
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: track `current_user` et all in a tidy, global, and thread-safe fashion.
29
56
  email: ara.t.howard@gmail.com
30
57
  executables: []
31
58
  extensions: []
32
- extra_rdoc_files: []
59
+ extra_rdoc_files:
60
+ - Manifest.txt
61
+ - README.md
33
62
  files:
63
+ - Manifest.txt
34
64
  - README.md
35
65
  - Rakefile
36
66
  - lib/rails_current.rb
37
- - rails_current.gemspec
67
+ - tasks/default.rake
68
+ - tasks/this.rb
38
69
  - test/rails_current_test.rb
39
70
  - test/testing.rb
40
71
  homepage: https://github.com/ahoward/rails_current
41
72
  licenses:
42
- - same as ruby's
73
+ - Ruby
43
74
  metadata: {}
44
75
  post_install_message:
45
- rdoc_options: []
76
+ rdoc_options:
77
+ - "--main"
78
+ - README.md
79
+ - "--markup"
80
+ - tomdoc
46
81
  require_paths:
47
82
  - lib
48
83
  required_ruby_version: !ruby/object:Gem::Requirement
49
84
  requirements:
50
- - - ! '>='
85
+ - - ">="
51
86
  - !ruby/object:Gem::Version
52
- version: '0'
87
+ version: 2.2.0
53
88
  required_rubygems_version: !ruby/object:Gem::Requirement
54
89
  requirements:
55
- - - ! '>='
90
+ - - ">="
56
91
  - !ruby/object:Gem::Version
57
92
  version: '0'
58
93
  requirements: []
59
- rubyforge_project: codeforpeople
60
- rubygems_version: 2.0.3
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.8
61
96
  signing_key:
62
97
  specification_version: 4
63
- summary: rails_current
98
+ summary: track `current_user` et all in a tidy, global, and thread-safe fashion.
64
99
  test_files: []
@@ -1,38 +0,0 @@
1
- ## rails_current.gemspec
2
- #
3
-
4
- Gem::Specification::new do |spec|
5
- spec.name = "rails_current"
6
- spec.version = "1.9.0"
7
- spec.platform = Gem::Platform::RUBY
8
- spec.summary = "rails_current"
9
- spec.description = "track 'current_user' et all in a tidy, global, and thread-safe fashion for your rails apps"
10
- spec.license = "same as ruby's"
11
-
12
- spec.files =
13
- ["README.md",
14
- "Rakefile",
15
- "lib",
16
- "lib/rails_current.rb",
17
- "rails_current.gemspec",
18
- "test",
19
- "test/rails_current_test.rb",
20
- "test/testing.rb"]
21
-
22
- spec.executables = []
23
-
24
- spec.require_path = "lib"
25
-
26
- spec.test_files = nil
27
-
28
-
29
- spec.add_dependency(*["map", " >= 6.0.1"])
30
-
31
-
32
- spec.extensions.push(*[])
33
-
34
- spec.rubyforge_project = "codeforpeople"
35
- spec.author = "Ara T. Howard"
36
- spec.email = "ara.t.howard@gmail.com"
37
- spec.homepage = "https://github.com/ahoward/rails_current"
38
- end