Skip to content
This repository

under ruby 1.9.2, .name returns nil for anonymous classes #151

Merged
merged 1 commit into from almost 2 years ago

2 participants

John Hawthorn Steffen Bartsch
John Hawthorn

Inside Authorization::Usage::Disables.usages_by_controller is the line

controllers << obj if obj.ancestors.include?(ActionController::Base) and obj != ActionController::Base and obj.name.demodulize != 'ApplicationController'

Under 1.9.2 and above this raises an exception when there it encounters an anonymous class, where .name returns nil (1.8.7 returns '').

This fix makes all rails 3 tests pass on 1.9.2 and 1.9.3. http://travis-ci.org/#!/jhawthorn/declarative_authorization/builds/2041629

John Hawthorn jhawthorn under ruby 1.9.2, Class.new.name returns nil
Adjust Authorization::Usage::Disables.usages_by_controller to behave the
same as under 1.8.7 when provided an anonymous class rather than
attempting to call .demodularize on nil.
c383b75
Steffen Bartsch stffn merged commit e9e1aff into from
Steffen Bartsch
Owner

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 05, 2012
John Hawthorn jhawthorn under ruby 1.9.2, Class.new.name returns nil
Adjust Authorization::Usage::Disables.usages_by_controller to behave the
same as under 1.8.7 when provided an anonymous class rather than
attempting to call .demodularize on nil.
c383b75
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 3 deletions. Show diff stats Hide diff stats

  1. +4 3 lib/declarative_authorization/maintenance.rb
7 lib/declarative_authorization/maintenance.rb
@@ -60,9 +60,10 @@ def self.usages_by_controller
60 60 end
61 61 rescue Errno::ENOENT
62 62 end
63   - controllers = []
64   - ObjectSpace.each_object(Class) do |obj|
65   - controllers << obj if obj.ancestors.include?(ActionController::Base) and obj != ActionController::Base and obj.name.demodulize != 'ApplicationController'
  63 + controllers = ObjectSpace.each_object(Class).select do |obj|
  64 + obj.ancestors.include?(ActionController::Base) &&
  65 + obj != ActionController::Base &&
  66 + (!obj.name || obj.name.demodulize != 'ApplicationController')
66 67 end
67 68
68 69 controllers.inject({}) do |memo, controller|

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.