lib/class_action.rb in class-action-0.0.1 vs lib/class_action.rb in class-action-1.1.0

- old
+ new

@@ -26,12 +26,17 @@ actions.each do |action| action_class = klass || const_get(action.to_s.camelize) raise ArgumentError, "ClassAction does not support anonymous classes" if action_class.name.nil? class_eval <<-RUBY, __FILE__, __LINE__+1 + def _#{action}_action_class + @_class_action ||= #{action_class.name}.new self + end + private :_#{action}_action_class + def #{action} - _execute_class_action :#{action}, #{action_class.name} + _#{action}_action_class._execute end RUBY inject_class_action_mimes action.to_s, action_class end @@ -41,32 +46,32 @@ # Injects the mimes (formats) that the action responds to into the controller # mimes_for_respond_to hash. def inject_class_action_mimes(action, klass) # If no responders or a default responder is given, we don't do anything. - return if klass.responders.empty? || klass.responders.has_key?(:any) + return if klass._responders.empty? || klass._responders.any? { |(mime, _condition), _block| mime == :any } mimes = mimes_for_respond_to.dup # Make sure no extra mimes are allowed for the action. mimes.each do |mime, restrictions| - next if klass.responders.key?(mime) + next if klass._responders.any? { |(m, _codition), _block| m == mime } exclude_class_action_in_mime_type mime, restrictions, action end # Include all action mimes. - klass.responders.each do |mime, _block| + klass._responders.each do |(mime, _condition), _block| mimes[mime] ||= { :only => [] } include_class_action_in_mime_type mime, mimes[mime], action end self.mimes_for_respond_to = mimes end def include_class_action_in_mime_type(mime, restrictions, action) if restrictions && restrictions[:except] && restrictions[:except].include?(action) - logger.warn "Warning: action #{action} (ClassAction) responds to `#{mime}` but it does not accept this mime type" + logger.warn "Warning: action #{action} (ClassAction) responds to `#{mime}` but it does not accept this mime type" if logger elsif restrictions && restrictions[:only] && !restrictions[:only].include?(action) restrictions[:only] << action end end @@ -88,12 +93,11 @@ view_context end private - def _execute_class_action(name, klass) - @_class_action = klass.new(self) - @_class_action._execute + def _class_action + send(:"_#{action_name}_action_class") end end if defined?(AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES) \ No newline at end of file