Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6396

Show
Ignore:
Timestamp:
03/13/07 02:14:31 (2 years ago)
Author:
bitsweat
Message:

Consistent public/protected/private visibility for chained methods. Closes #7813.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6350 r6396  
    11*SVN* 
     2 
     3* Consistent public/protected/private visibility for chained methods.  #7813 [dcmanges] 
    24 
    35* Prefer MIME constants to strings.  #7707 [Dan Kubb] 
  • trunk/actionpack/lib/action_controller/benchmarking.rb

    r6157 r6396  
    4141    end 
    4242 
    43     def render_with_benchmark(options = nil, deprecated_status = nil, &block) 
    44       unless logger 
    45         render_without_benchmark(options, deprecated_status, &block) 
    46       else 
    47         db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
     43    protected 
     44      def render_with_benchmark(options = nil, deprecated_status = nil, &block) 
     45        unless logger 
     46          render_without_benchmark(options, deprecated_status, &block) 
     47        else 
     48          db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
    4849 
    49         render_output = nil 
    50         @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real 
     50          render_output = nil 
     51          @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real 
    5152 
    52         if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
    53           @db_rt_before_render = db_runtime 
    54           @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime 
    55           @rendering_runtime -= @db_rt_after_render 
     53          if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
     54            @db_rt_before_render = db_runtime 
     55            @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime 
     56            @rendering_runtime -= @db_rt_after_render 
     57          end 
     58 
     59          render_output 
    5660        end 
    57  
    58         render_output 
    59       end 
    60     end     
    61  
    62     def perform_action_with_benchmark 
    63       unless logger 
    64         perform_action_without_benchmark 
    65       else 
    66         runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max 
    67  
    68         log_message  = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" 
    69         log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) 
    70         log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
    71         log_message << " | #{headers["Status"]}" 
    72         log_message << " [#{complete_request_uri rescue "unknown"}]" 
    73  
    74         logger.info(log_message) 
    75         response.headers["X-Runtime"] = sprintf("%.5f", runtime) 
    76       end 
    77     end 
    78  
     61      end     
    7962 
    8063    private 
     64      def perform_action_with_benchmark 
     65        unless logger 
     66          perform_action_without_benchmark 
     67        else 
     68          runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max 
     69 
     70          log_message  = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" 
     71          log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) 
     72          log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 
     73          log_message << " | #{headers["Status"]}" 
     74          log_message << " [#{complete_request_uri rescue "unknown"}]" 
     75 
     76          logger.info(log_message) 
     77          response.headers["X-Runtime"] = sprintf("%.5f", runtime) 
     78        end 
     79      end 
     80 
    8181      def rendering_runtime(runtime) 
    8282        " | Rendering: #{sprintf("%.5f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime * 100) / runtime)}%)" 
  • trunk/actionpack/lib/action_controller/filters.rb

    r5862 r6396  
    616616      end 
    617617 
    618       def perform_action_with_filters 
    619         call_filter(self.class.filter_chain, 0) 
    620       end 
    621  
    622       def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc: 
    623         @before_filter_chain_aborted = false 
    624         process_without_filters(request, response, method, *arguments) 
    625       end 
    626  
    627618      def filter_chain 
    628619        self.class.filter_chain 
     
    655646      end 
    656647 
     648      protected 
     649 
     650        def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc: 
     651          @before_filter_chain_aborted = false 
     652          process_without_filters(request, response, method, *arguments) 
     653        end 
     654 
    657655      private 
     656        def perform_action_with_filters 
     657          call_filter(self.class.filter_chain, 0) 
     658        end 
     659 
    658660        def process_cleanup_with_filters 
    659661          if @before_filter_chain_aborted 
  • trunk/actionpack/lib/action_controller/flash.rb

    r6178 r6396  
    137137 
    138138    module InstanceMethods #:nodoc: 
    139       def assign_shortcuts_with_flash(request, response) #:nodoc: 
    140         assign_shortcuts_without_flash(request, response) 
    141         flash(:refresh) 
    142       end 
     139 
     140      protected 
     141        def reset_session_with_flash 
     142          reset_session_without_flash 
     143          remove_instance_variable(:@_flash) 
     144          flash(:refresh) 
     145        end 
    143146       
    144       def process_cleanup_with_flash 
    145         flash.sweep if @_session 
    146         process_cleanup_without_flash 
    147       end 
    148  
    149       def reset_session_with_flash 
    150         reset_session_without_flash 
    151         remove_instance_variable(:@_flash) 
    152         flash(:refresh) 
    153       end 
    154        
    155       protected  
    156147        # Access the contents of the flash. Use <tt>flash["notice"]</tt> to read a notice you put there or  
    157148        # <tt>flash["notice"] = "hello"</tt> to put a new one. 
     
    178169          flash.keep 
    179170        end 
     171         
     172      private 
     173        def assign_shortcuts_with_flash(request, response) #:nodoc: 
     174          assign_shortcuts_without_flash(request, response) 
     175          flash(:refresh) 
     176        end 
     177     
     178        def process_cleanup_with_flash 
     179          flash.sweep if @_session 
     180          process_cleanup_without_flash 
     181        end 
    180182    end 
    181183  end 
  • trunk/actionpack/lib/action_controller/layout.rb

    r6275 r6396  
    234234    end 
    235235 
    236     def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: 
    237       template_with_options = options.is_a?(Hash) 
    238  
    239       if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) 
    240         assert_existence_of_template_file(layout) 
    241  
    242         options = options.merge :layout => false if template_with_options 
    243         logger.info("Rendering template within #{layout}") if logger 
    244  
    245         if template_with_options 
    246           content_for_layout = render_with_no_layout(options, &block) 
    247           deprecated_status = options[:status] || deprecated_status 
     236    protected 
     237      def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: 
     238        template_with_options = options.is_a?(Hash) 
     239 
     240        if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) 
     241          assert_existence_of_template_file(layout) 
     242 
     243          options = options.merge :layout => false if template_with_options 
     244          logger.info("Rendering template within #{layout}") if logger 
     245 
     246          if template_with_options 
     247            content_for_layout = render_with_no_layout(options, &block) 
     248            deprecated_status = options[:status] || deprecated_status 
     249          else 
     250            content_for_layout = render_with_no_layout(options, deprecated_status, &block) 
     251          end 
     252 
     253          erase_render_results 
     254          add_variables_to_assigns 
     255          @template.instance_variable_set("@content_for_layout", content_for_layout) 
     256          response.layout = layout 
     257          render_text(@template.render_file(layout, true), deprecated_status) 
    248258        else 
    249           content_for_layout = render_with_no_layout(options, deprecated_status, &block) 
    250         end 
    251  
    252         erase_render_results 
    253         add_variables_to_assigns 
    254         @template.instance_variable_set("@content_for_layout", content_for_layout) 
    255         response.layout = layout 
    256         render_text(@template.render_file(layout, true), deprecated_status) 
    257       else 
    258         render_with_no_layout(options, deprecated_status, &block) 
    259       end 
    260     end 
     259          render_with_no_layout(options, deprecated_status, &block) 
     260        end 
     261      end 
    261262 
    262263 
  • trunk/activerecord/CHANGELOG

    r6388 r6396  
    11*SVN* 
     2 
     3* Consistent public/protected/private visibility for chained methods.  #7813 [dcmanges] 
    24 
    35* Oracle: fix quoted primary keys and datetime overflow.  #7798 [Michael Schoen] 
  • trunk/activerecord/lib/active_record/callbacks.rb

    r5018 r6396  
    228228      result 
    229229    end 
     230    private :initialize_with_callbacks 
    230231 
    231232    # Is called _before_ Base.save (regardless of whether it's a create or update save). 
     
    244245      result 
    245246    end 
     247    private :create_or_update_with_callbacks 
    246248 
    247249    # Is called _before_ Base.save on new objects that haven't been saved yet (no record exists). 
     
    256258      result 
    257259    end 
     260    private :create_with_callbacks 
    258261 
    259262    # Is called _before_ Base.save on existing objects that have a record. 
     
    269272      result 
    270273    end 
     274    private :update_with_callbacks 
    271275 
    272276    # Is called _before_ Validations.validate (which is part of the Base.save call). 
  • trunk/activerecord/lib/active_record/locking/optimistic.rb

    r6139 r6396  
    2424    module Optimistic 
    2525      def self.included(base) #:nodoc: 
    26         super 
    2726        base.extend ClassMethods 
    2827 
     
    4241      end 
    4342 
    44       def attributes_from_column_definition_with_lock 
    45         result = attributes_from_column_definition_without_lock 
     43      private 
     44        def attributes_from_column_definition_with_lock 
     45          result = attributes_from_column_definition_without_lock 
    4646         
    47         # If the locking column has no default value set, 
    48         # start the lock version at zero.  Note we can't use 
    49         # locking_enabled? at this point as @attributes may 
    50         # not have been initialized yet 
     47          # If the locking column has no default value set, 
     48          # start the lock version at zero.  Note we can't use 
     49          # locking_enabled? at this point as @attributes may 
     50          # not have been initialized yet 
    5151         
    52         if lock_optimistically && result.include?(self.class.locking_column) 
    53           result[self.class.locking_column] ||= 0 
    54         end 
     52          if lock_optimistically && result.include?(self.class.locking_column) 
     53            result[self.class.locking_column] ||= 0 
     54          end 
    5555         
    56         return result 
    57       end 
    58  
    59       def update_with_lock #:nodoc: 
    60         return update_without_lock unless locking_enabled? 
    61  
    62         lock_col = self.class.locking_column 
    63         previous_value = send(lock_col) 
    64         send(lock_col + '=', previous_value + 1) 
    65  
    66         affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") 
    67           UPDATE #{self.class.table_name} 
    68           SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} 
    69           WHERE #{self.class.primary_key} = #{quote_value(id)} 
    70           AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} 
    71         end_sql 
    72  
    73         unless affected_rows == 1 
    74           raise ActiveRecord::StaleObjectError, "Attempted to update a stale object" 
     56          return result 
    7557        end 
    7658 
    77         return true 
    78       end 
     59        def update_with_lock #:nodoc: 
     60          return update_without_lock unless locking_enabled? 
     61 
     62          lock_col = self.class.locking_column 
     63          previous_value = send(lock_col) 
     64          send(lock_col + '=', previous_value + 1) 
     65 
     66          affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") 
     67            UPDATE #{self.class.table_name} 
     68            SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} 
     69            WHERE #{self.class.primary_key} = #{quote_value(id)} 
     70            AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} 
     71          end_sql 
     72 
     73          unless affected_rows == 1 
     74            raise ActiveRecord::StaleObjectError, "Attempted to update a stale object" 
     75          end 
     76 
     77          return true 
     78        end 
    7979 
    8080      module ClassMethods 
  • trunk/activerecord/lib/active_record/timestamp.rb

    r6051 r6396  
    1919  module Timestamp 
    2020    def self.included(base) #:nodoc: 
    21       super 
    22  
    2321      base.alias_method_chain :create, :timestamps 
    2422      base.alias_method_chain :update, :timestamps 
     
    2826    end 
    2927 
    30     def create_with_timestamps #:nodoc: 
    31       if record_timestamps 
    32         t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 
    33         write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil? 
    34         write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil? 
     28    private 
     29      def create_with_timestamps #:nodoc: 
     30        if record_timestamps 
     31          t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 
     32          write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil? 
     33          write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil? 
    3534 
    36         write_attribute('updated_at', t) if respond_to?(:updated_at) 
    37         write_attribute('updated_on', t) if respond_to?(:updated_on) 
     35          write_attribute('updated_at', t) if respond_to?(:updated_at) 
     36          write_attribute('updated_on', t) if respond_to?(:updated_on) 
     37        end 
     38        create_without_timestamps 
    3839      end 
    39       create_without_timestamps 
    40     end 
    4140 
    42     def update_with_timestamps #:nodoc: 
    43       if record_timestamps 
    44         t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 
    45         write_attribute('updated_at', t) if respond_to?(:updated_at) 
    46         write_attribute('updated_on', t) if respond_to?(:updated_on) 
     41      def update_with_timestamps #:nodoc: 
     42        if record_timestamps 
     43          t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 
     44          write_attribute('updated_at', t) if respond_to?(:updated_at) 
     45          write_attribute('updated_on', t) if respond_to?(:updated_on) 
     46        end 
     47        update_without_timestamps 
    4748      end 
    48       update_without_timestamps 
    49     end 
    5049  end 
    5150end