rails_current 1.8.0 → 2.2.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
- ZmEzNGM0MmJiYWQxZjFiOWIzMmZlMDEzMjc4NjE5ZWJjZWRiNWQ1ZA==
5
- data.tar.gz: !binary |-
6
- MjQ5YmUxNDk4YjlmZWRkNjQ0NmNmODFlMDQ4YWM0MzY2YzRhOTcxNw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OGE4MWM3MjAzM2ExMTQ4ZjEwYjczYjU3ZjkyZWNmYWYzZWI2ODYyOTUzNjcy
10
- MjBlNTk3MThhY2Y4N2E2N2E1NmY0ZDcyNzg5MGE5ZWUyOTE4MDZiNDRmMmIw
11
- NjU1NWRiN2U1MGU1YjAyZTg3OTkxZGUwYjlmODdiN2U5NDY4M2Y=
12
- data.tar.gz: !binary |-
13
- YjZkYzA5ZWI3MzljZGRmYTgxMGEzM2I2OTNkMzBhNmJmZDlmZWMyMDY2MGU0
14
- MzM4OWI2ZmMyODljNTRjNjE4Mjk4OWRlOTljMWFlNjJhOGNmMTk3NDc5ZTYz
15
- ZGM1MmJmNzgxNTFhYjI4ZDk3NzFjNTAyZGVlYmVkZWEwZDEyNjQ=
2
+ SHA256:
3
+ metadata.gz: dd096f5c6ef3f51bb7c82d1f66ba813955d641d3781dcffaab6c1ad8dbb7d5b5
4
+ data.tar.gz: 2d61359d45c4496c30ce0ec87c7f5a5fda1e170003af08e26853b5cb1ff10de5
5
+ SHA512:
6
+ metadata.gz: 1d7211d22661a811d1cfffa16b39333a8ceee0d235372c927804cb8c2a6137fc2b4ebc9a8a1fc80f501ee836bce58f5ccef3a96a3fbeb90ad7ec30acbc96e8bf
7
+ data.tar.gz: 3707b6e19d80cbca2b9b701cfc01cde7ba1e8d9524229f40a9388f3c39116e9d69dcd4b5c9d2227d1fd4a68eece6677999287f3f6b911f7524b61c99301365fe
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,30 @@ 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
-
41
+ ...
48
42
 
49
- if current_user
43
+ end
50
44
 
51
- ...
52
-
53
- end
45
+ self.current_user = User.find(id)
46
+ ```
54
47
 
55
- self.current_user = User.find(id)
48
+ the `Current` module is cleared out before every request and is thread safe.
56
49
 
50
+ ## INSTALL
57
51
 
58
- the Current module is cleared out before every request and is thread safe.
52
+ ```
53
+ gem install rails_current
59
54
 
60
- --------------------------------
61
- INSTALL
62
- --------------------------------
63
55
 
64
- gem install rails-current
56
+ gem 'rails-current', :require => 'current'
65
57
 
58
+ bundle install
59
+ ```
66
60
 
67
- gem 'rails-current', :require => 'current'
68
- bundle install
data/Rakefile CHANGED
@@ -1,8 +1,11 @@
1
- This.rubyforge_project = 'codeforpeople'
1
+ #This.rubyforge_project = 'codeforpeople'
2
2
  This.author = "Ara T. Howard"
3
3
  This.email = "ara.t.howard@gmail.com"
4
4
  This.homepage = "https://github.com/ahoward/#{ This.lib }"
5
5
 
6
+ task :license do
7
+ open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
8
+ end
6
9
 
7
10
  task :default do
8
11
  puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
@@ -29,7 +32,7 @@ def run_tests!(which = nil)
29
32
 
30
33
  test_rbs.each_with_index do |test_rb, index|
31
34
  testno = index + 1
32
- command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }"
35
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
33
36
 
34
37
  puts
35
38
  say(div, :color => :cyan, :bold => true)
@@ -60,7 +63,7 @@ end
60
63
  task :gemspec do
61
64
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
62
65
  ignore_directories = ['pkg']
63
- ignore_files = ['test/log', 'a.rb'] + Dir['db/*'] + %w'db'
66
+ ignore_files = ['test/log']
64
67
 
65
68
  shiteless =
66
69
  lambda do |list|
@@ -87,9 +90,10 @@ task :gemspec do
87
90
  files = shiteless[Dir::glob("**/**")]
88
91
  executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
89
92
  #has_rdoc = true #File.exist?('doc')
90
- test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
93
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
91
94
  summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
92
95
  description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
+ license = object.respond_to?(:license) ? object.license : "Ruby"
93
97
 
94
98
  if This.extensions.nil?
95
99
  This.extensions = []
@@ -100,7 +104,6 @@ task :gemspec do
100
104
  end
101
105
  extensions = [extensions].flatten.compact
102
106
 
103
- # TODO
104
107
  if This.dependencies.nil?
105
108
  dependencies = []
106
109
  else
@@ -127,6 +130,7 @@ task :gemspec do
127
130
  spec.platform = Gem::Platform::RUBY
128
131
  spec.summary = <%= lib.inspect %>
129
132
  spec.description = <%= description.inspect %>
133
+ spec.license = <%= license.inspect %>
130
134
 
131
135
  spec.files =\n<%= files.sort.pretty_inspect %>
132
136
  spec.executables = <%= executables.inspect %>
@@ -141,7 +145,6 @@ task :gemspec do
141
145
 
142
146
  spec.extensions.push(*<%= extensions.inspect %>)
143
147
 
144
- spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
145
148
  spec.author = <%= This.author.inspect %>
146
149
  spec.email = <%= This.email.inspect %>
147
150
  spec.homepage = <%= This.homepage.inspect %>
@@ -188,8 +191,8 @@ task :readme do
188
191
  end
189
192
 
190
193
  template =
191
- if test(?e, 'readme.erb')
192
- Template{ IO.read('readme.erb') }
194
+ if test(?e, 'README.erb')
195
+ Template{ IO.read('README.erb') }
193
196
  else
194
197
  Template {
195
198
  <<-__
@@ -1,16 +1,22 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Current
4
+ VERSION = '2.2.0'
5
+
4
6
  def Current.version
5
- '1.8.0'
7
+ VERSION
6
8
  end
7
9
 
8
10
  def Current.dependencies
9
11
  {
10
- 'map' => [ 'map' , ' >= 6.0.1' ]
12
+ 'map' => [ 'map', ' ~> 6.0' ]
11
13
  }
12
14
  end
13
15
 
16
+ def Current.description
17
+ "track 'current_user' et all in a tidy, global, and thread-safe fashion for your rails apps"
18
+ end
19
+
14
20
  begin
15
21
  require 'rubygems'
16
22
  rescue LoadError
@@ -149,48 +155,60 @@ module Current
149
155
  case method.to_s
150
156
  when /^current_(.*)$/
151
157
  msg = $1
152
- value = Current.send(msg, *args, &block)
153
-
158
+ Current.send(msg, *args, &block)
154
159
  else
155
160
  super
156
161
  end
157
162
  end
158
163
 
159
164
  def Current.mock_controller(options = {})
160
- require 'rails'
161
- require 'action_controller'
162
- require 'action_dispatch/testing/test_request.rb'
163
- require 'action_dispatch/testing/test_response.rb'
165
+ ensure_rails_application do
166
+ require 'action_controller'
167
+ require 'action_dispatch/testing/test_request.rb'
168
+ require 'action_dispatch/testing/test_response.rb'
164
169
 
165
- default_url_options =
166
- begin
167
- require 'rails_default_url_options'
168
- DefaultUrlOptions
169
- rescue LoadError
170
- options[:default_url_options] || {}
170
+ store = ActiveSupport::Cache::MemoryStore.new
171
+
172
+ controller = mock_controller_class.new
173
+ controller.perform_caching = true
174
+ controller.cache_store = store
175
+
176
+ request = ActionDispatch::TestRequest.create
177
+ response = ActionDispatch::TestResponse.create
178
+
179
+ controller.request = request
180
+ controller.response = response
181
+
182
+ singleton_class =
183
+ class << controller
184
+ self
185
+ end
186
+
187
+ singleton_class.module_eval do
188
+ define_method(:default_url_options) do
189
+ @default_url_options ||= (
190
+ defined?(DefaultUrlOptions) ? DefaultUrlOptions.dup : {}
191
+ )
192
+ end
171
193
  end
172
194
 
173
- ensure_rails_application do
174
- store = ActiveSupport::Cache::MemoryStore.new
175
- controller =
176
- begin
177
- ApplicationController.new
178
- rescue NameError
179
- ActionController::Base.new
180
- end
181
- controller.perform_caching = true
182
- controller.cache_store = store
183
- request = ActionDispatch::TestRequest.new
184
- response = ActionDispatch::TestResponse.new
185
- controller.request = request
186
- controller.response = response
187
- #controller.send(:initialize_template_class, response)
188
- #controller.send(:assign_shortcuts, request, response)
189
- controller.send(:default_url_options).merge!(default_url_options)
190
195
  Current.proxy_for(controller)
191
196
  end
192
197
  end
193
198
 
199
+ def Current.mock_controller_class
200
+ unless const_defined?(:Controller)
201
+ controller_class =
202
+ if defined?(::ApplicationController)
203
+ Class.new(::ApplicationController)
204
+ else
205
+ Class.new(::ActionController::Base)
206
+ end
207
+ const_set(:Controller, controller_class)
208
+ end
209
+ return const_get(:Controller)
210
+ end
211
+
194
212
  def Current.ensure_rails_application(&block)
195
213
  require 'rails' unless defined?(Rails)
196
214
  if Rails.application.nil?
@@ -228,10 +246,6 @@ module Current
228
246
  end
229
247
  end
230
248
 
231
- def Current(*args, &block)
232
- Current.attribute(*args, &block)
233
- end
234
-
235
249
  if defined?(Rails)
236
250
 
237
251
  ##
@@ -245,10 +259,10 @@ if defined?(Rails)
245
259
  ##
246
260
  #
247
261
  module Current
248
- def Current.install_before_filter!
262
+ def Current.install_before_action!
249
263
  if defined?(::ActionController::Base)
250
264
  ::ActionController::Base.module_eval do
251
- prepend_before_filter do |controller|
265
+ prepend_before_action do |controller|
252
266
  Current.clear
253
267
  Current.controller = Current.proxy_for(controller)
254
268
  Current.action = controller ? controller.send(:action_name) : nil
@@ -268,12 +282,12 @@ if defined?(Rails)
268
282
  class Engine < Rails::Engine
269
283
  config.before_initialize do
270
284
  ActiveSupport.on_load(:action_controller) do
271
- Current.install_before_filter!
285
+ Current.install_before_action!
272
286
  end
273
287
  end
274
288
  end
275
289
  else
276
- Current.install_before_filter!
290
+ Current.install_before_action!
277
291
  end
278
292
 
279
293
  end
@@ -0,0 +1,40 @@
1
+ ## rails_current.gemspec
2
+ #
3
+
4
+ Gem::Specification::new do |spec|
5
+ spec.name = "rails_current"
6
+ spec.version = "2.2.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 = "Ruby"
11
+
12
+ spec.files =
13
+ ["README.md",
14
+ "Rakefile",
15
+ "lib",
16
+ "lib/rails_current.rb",
17
+ "rails_current.gemspec",
18
+ "tasks",
19
+ "tasks/default.rake",
20
+ "tasks/this.rb",
21
+ "test",
22
+ "test/rails_current_test.rb",
23
+ "test/testing.rb"]
24
+
25
+ spec.executables = []
26
+
27
+ spec.require_path = "lib"
28
+
29
+ spec.test_files = nil
30
+
31
+
32
+ spec.add_dependency(*["map", " ~> 6.0"])
33
+
34
+
35
+ spec.extensions.push(*[])
36
+
37
+ spec.author = "Ara T. Howard"
38
+ spec.email = "ara.t.howard@gmail.com"
39
+ spec.homepage = "https://github.com/ahoward/rails_current"
40
+ end
@@ -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 == summary ? "#{ 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,5 +1,4 @@
1
-
2
- Testing Current do
1
+ Testing.test Current do
3
2
 
4
3
  ##
5
4
  #
@@ -42,7 +41,7 @@ Testing Current do
42
41
  wa = Queue.new
43
42
  wb = Queue.new
44
43
 
45
- a = Thread.new do
44
+ Thread.new do
46
45
  Thread.current.abort_on_exception = true
47
46
  id = Thread.current.object_id
48
47
  Current.foo = 40
@@ -52,7 +51,7 @@ Testing Current do
52
51
  ra.push( Current.attributes )
53
52
  end
54
53
 
55
- b = Thread.new do
54
+ Thread.new do
56
55
  Thread.current.abort_on_exception = true
57
56
  id = Thread.current.object_id
58
57
  Current.foo = 'forty'
@@ -94,7 +93,7 @@ Testing Current do
94
93
  assert{ c.current_bar == 42.0 }
95
94
 
96
95
  o = assert do
97
- Object.new.tap{|o| o.extend Current }
96
+ Object.new.tap{|o1| o1.extend Current }
98
97
  end
99
98
 
100
99
  assert{ o.current_foo == 42 }
@@ -171,7 +170,7 @@ Testing Current do
171
170
  assert{ Current.attributes =~ {:user => nil, :controller => nil, :action => nil} }
172
171
 
173
172
  assert{ $before_initialize_called }
174
- assert{ $prepend_before_filter_called }
173
+ assert{ $prepend_before_action_called }
175
174
 
176
175
  assert do
177
176
  Current.user = :user
@@ -196,15 +195,19 @@ Testing Current do
196
195
  private
197
196
  def mock_rails!
198
197
  Object.module_eval <<-__
198
+ remove_const :Rails if const_defined? :Rails
199
+ remove_const :ActionController if const_defined? :ActionController
200
+ remove_const :ActionView if const_defined? :ActionView
201
+
199
202
  module Rails
200
203
  end
201
204
 
202
205
  module ActionController
203
206
  class Base
204
- def Base.prepend_before_filter(*args, &block)
207
+ def Base.prepend_before_action(*args, &block)
205
208
  block.call
206
209
  ensure
207
- $prepend_before_filter_called = true
210
+ $prepend_before_action_called = true
208
211
  end
209
212
 
210
213
  def Base.helper(&block)
@@ -243,10 +246,10 @@ private
243
246
 
244
247
  module ActionController
245
248
  class Base
246
- def Base.prepend_before_filter(*args, &block)
249
+ def Base.prepend_before_action(*args, &block)
247
250
  block.call
248
251
  ensure
249
- $prepend_before_filter_called = true
252
+ $prepend_before_action_called = true
250
253
  end
251
254
 
252
255
  def Base.helper(&block)
@@ -272,7 +275,6 @@ private
272
275
  end
273
276
  end
274
277
 
275
-
276
278
  BEGIN {
277
279
  $this = File.expand_path(__FILE__)
278
280
  $root = File.dirname(File.dirname($this))
@@ -1,16 +1,12 @@
1
1
  # -*- encoding : utf-8 -*-
2
- #
3
- require 'test/unit'
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
4
5
 
5
- testdir = File.expand_path(File.dirname(__FILE__))
6
- rootdir = File.dirname(testdir)
7
- libdir = File.join(rootdir, 'lib')
8
6
 
9
- STDOUT.sync = true
10
-
11
- $:.unshift(testdir) unless $:.include?(testdir)
12
- $:.unshift(libdir) unless $:.include?(libdir)
13
- $:.unshift(rootdir) unless $:.include?(rootdir)
7
+ if defined?(Testing)
8
+ Object.send(:remove_const, :Testing)
9
+ end
14
10
 
15
11
  class Testing
16
12
  class Slug < ::String
@@ -36,8 +32,8 @@ class Testing
36
32
  end
37
33
  end
38
34
 
39
- def Testing(*args, &block)
40
- Class.new(::Test::Unit::TestCase) do
35
+ def Testing.test(*args, &block)
36
+ Class.new(::Minitest::Test) do
41
37
 
42
38
  ## class methods
43
39
  #
@@ -103,6 +99,35 @@ def Testing(*args, &block)
103
99
  @cleanup.push(block) if block
104
100
  @cleanup
105
101
  end
102
+
103
+ end
104
+
105
+ def assert_nothing_raised(*args, &block )
106
+ if Module === args.last
107
+ msg = nil
108
+ else
109
+ msg = args.pop
110
+ end
111
+ begin
112
+ line = __LINE__; yield
113
+ rescue MiniTest::Skip
114
+ raise
115
+ rescue Exception => e
116
+ bt = e.backtrace
117
+ as = e.instance_of?(MiniTest::Assertion)
118
+ if as
119
+ ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
120
+ bt.reject! {|ln| ans =~ ln}
121
+ end
122
+ if ((args.empty? && !as) ||
123
+ args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
124
+ msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
125
+ raise MiniTest::Assertion, msg.call, bt
126
+ else
127
+ raise
128
+ end
129
+ end
130
+ nil
106
131
  end
107
132
 
108
133
  ## configure the subclass!
@@ -124,7 +149,7 @@ def Testing(*args, &block)
124
149
  expected = getopt(:expected, options){ missing }
125
150
  actual = getopt(:actual, options){ missing }
126
151
  if expected == missing and actual == missing
127
- actual, expected, *ignored = options.to_a.flatten
152
+ actual, expected, *_ = options.to_a.flatten
128
153
  end
129
154
  expected = expected.call() if expected.respond_to?(:call)
130
155
  actual = actual.call() if actual.respond_to?(:call)
@@ -184,14 +209,3 @@ def Testing(*args, &block)
184
209
  self
185
210
  end
186
211
  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,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_current
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.2.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: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2020-10-23 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: ! 'description: rails_current kicks the ass'
26
+ version: '6.0'
27
+ description: track 'current_user' et all in a tidy, global, and thread-safe fashion
28
+ for your rails apps
28
29
  email: ara.t.howard@gmail.com
29
30
  executables: []
30
31
  extensions: []
@@ -33,10 +34,14 @@ files:
33
34
  - README.md
34
35
  - Rakefile
35
36
  - lib/rails_current.rb
37
+ - rails_current.gemspec
38
+ - tasks/default.rake
39
+ - tasks/this.rb
36
40
  - test/rails_current_test.rb
37
41
  - test/testing.rb
38
42
  homepage: https://github.com/ahoward/rails_current
39
- licenses: []
43
+ licenses:
44
+ - Ruby
40
45
  metadata: {}
41
46
  post_install_message:
42
47
  rdoc_options: []
@@ -44,17 +49,16 @@ require_paths:
44
49
  - lib
45
50
  required_ruby_version: !ruby/object:Gem::Requirement
46
51
  requirements:
47
- - - ! '>='
52
+ - - ">="
48
53
  - !ruby/object:Gem::Version
49
54
  version: '0'
50
55
  required_rubygems_version: !ruby/object:Gem::Requirement
51
56
  requirements:
52
- - - ! '>='
57
+ - - ">="
53
58
  - !ruby/object:Gem::Version
54
59
  version: '0'
55
60
  requirements: []
56
- rubyforge_project: codeforpeople
57
- rubygems_version: 2.0.3
61
+ rubygems_version: 3.0.3
58
62
  signing_key:
59
63
  specification_version: 4
60
64
  summary: rails_current