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

Changeset 4078

Show
Ignore:
Timestamp:
03/28/06 03:06:40 (3 years ago)
Author:
david
Message:

Fixed documentation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/associations.rb

    r4069 r4078  
    1010 
    1111module ActiveRecord 
    12   class HasManyThroughAssociationNotFoundError < ActiveRecordError 
     12  class HasManyThroughAssociationNotFoundError < ActiveRecordError #:nodoc: 
    1313    def initialize(reflection) 
    1414      @reflection = reflection 
     
    2020  end 
    2121 
    22   class HasManyThroughAssociationPolymorphicError < ActiveRecordError 
     22  class HasManyThroughAssociationPolymorphicError < ActiveRecordError #:nodoc: 
    2323    def initialize(owner_class_name, reflection, source_reflection) 
    2424      @owner_class_name  = owner_class_name 
     
    3232  end 
    3333 
    34   class HasManyThroughSourceAssociationNotFoundError < ActiveRecordError 
     34  class HasManyThroughSourceAssociationNotFoundError < ActiveRecordError #:nodoc: 
    3535    def initialize(reflection) 
    3636      @reflection              = reflection 
     
    4545  end 
    4646 
    47   class EagerLoadPolymorphicError < ActiveRecordError 
     47  class EagerLoadPolymorphicError < ActiveRecordError #:nodoc: 
    4848    def initialize(reflection) 
    4949      @reflection = reflection 
  • trunk/activerecord/lib/active_record/base.rb

    r4076 r4078  
    254254    end 
    255255     
    256     def self.reset_subclasses 
     256    def self.reset_subclasses #:nodoc: 
    257257      nonreloadables = [] 
    258258      subclasses.each do |klass| 
     
    562562      end 
    563563 
    564       def reset_table_name 
     564      def reset_table_name #:nodoc: 
    565565        name = "#{table_name_prefix}#{undecorated_table_name(base_class.name)}#{table_name_suffix}" 
    566566        set_table_name(name) 
     
    574574      end 
    575575 
    576       def reset_primary_key 
     576      def reset_primary_key #:nodoc: 
    577577        key = 'id' 
    578578        case primary_key_prefix_type 
     
    593593      # Lazy-set the sequence name to the connection's default.  This method 
    594594      # is only ever called once since set_sequence_name overrides it. 
    595       def sequence_name 
     595      def sequence_name #:nodoc: 
    596596        reset_sequence_name 
    597597      end 
    598598 
    599       def reset_sequence_name 
     599      def reset_sequence_name #:nodoc: 
    600600        default = connection.default_sequence_name(table_name, primary_key) 
    601601        set_sequence_name(default) 
     
    705705      end 
    706706 
     707      # Returns an array of column names as strings. 
    707708      def column_names 
    708709        @column_names ||= columns.map { |column| column.name } 
     
    718719      # and true as the value. This makes it possible to do O(1) lookups in respond_to? to check if a given method for attribute 
    719720      # is available. 
    720       def column_methods_hash 
     721      def column_methods_hash #:nodoc: 
    721722        @dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr| 
    722723          attr_name = attr.to_s 
     
    730731 
    731732      # Contains the names of the generated reader methods. 
    732       def read_methods 
     733      def read_methods #:nodoc: 
    733734        @read_methods ||= Set.new 
    734735      end 
     
    11911192 
    11921193      protected 
    1193         def subclasses 
     1194        def subclasses #:nodoc: 
    11941195          @@subclasses[self] ||= [] 
    11951196          @@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses } 
     
    11971198 
    11981199        # Test whether the given method and optional key are scoped. 
    1199         def scoped?(method, key = nil) 
     1200        def scoped?(method, key = nil) #:nodoc: 
    12001201          if current_scoped_methods && (scope = current_scoped_methods[method]) 
    12011202            !key || scope.has_key?(key) 
     
    12041205 
    12051206        # Retrieve the scope for the given method and optional key. 
    1206         def scope(method, key = nil) 
     1207        def scope(method, key = nil) #:nodoc: 
    12071208          if current_scoped_methods && (scope = current_scoped_methods[method]) 
    12081209            key ? scope[key] : scope 
     
    12261227        end 
    12271228         
    1228         def current_scoped_methods 
     1229        def current_scoped_methods #:nodoc: 
    12291230          scoped_methods.last 
    12301231        end 
     
    12551256 
    12561257        # Returns the name of the class descending directly from ActiveRecord in the inheritance hierarchy. 
    1257         def class_name_of_active_record_descendant(klass) 
     1258        def class_name_of_active_record_descendant(klass) #:nodoc: 
    12581259          klass.base_class.name 
    12591260        end 
     
    12771278        alias_method :sanitize_conditions, :sanitize_sql 
    12781279 
    1279         def replace_bind_variables(statement, values) 
     1280        def replace_bind_variables(statement, values) #:nodoc: 
    12801281          raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size) 
    12811282          bound = values.dup 
     
    12831284        end 
    12841285 
    1285         def replace_named_bind_variables(statement, bind_vars) 
     1286        def replace_named_bind_variables(statement, bind_vars) #:nodoc: 
    12861287          statement.gsub(/:(\w+)/) do 
    12871288            match = $1.to_sym 
     
    12941295        end 
    12951296 
    1296         def quote_bound_value(value) 
     1297        def quote_bound_value(value) #:nodoc: 
    12971298          if (value.respond_to?(:map) && !value.is_a?(String)) 
    12981299            value.map { |v| connection.quote(v) }.join(',') 
     
    13021303        end 
    13031304 
    1304         def raise_if_bind_arity_mismatch(statement, expected, provided) 
     1305        def raise_if_bind_arity_mismatch(statement, expected, provided) #:nodoc: 
    13051306          unless expected == provided 
    13061307            raise PreparedStatementInvalid, "wrong number of bind variables (#{provided} for #{expected}) in: #{statement}" 
     
    13081309        end 
    13091310 
    1310         def extract_options_from_args!(args) 
     1311        def extract_options_from_args!(args) #:nodoc: 
    13111312          args.last.is_a?(Hash) ? args.pop : {} 
    13121313        end 
     
    13151316                               :order, :select, :readonly, :group, :from      ] 
    13161317         
    1317         def validate_find_options(options) 
     1318        def validate_find_options(options) #:nodoc: 
    13181319          options.assert_valid_keys(VALID_FIND_OPTIONS) 
    13191320        end 
    13201321         
    1321         def set_readonly_option!(options) 
     1322        def set_readonly_option!(options) #:nodoc: 
    13221323          # Inherit :readonly from finder scope if set.  Otherwise, 
    13231324          # if :joins is not blank then :readonly defaults to true. 
     
    13311332        end 
    13321333 
    1333         def encode_quoted_value(value) 
     1334        def encode_quoted_value(value) #:nodoc: 
    13341335          quoted_value = connection.quote(value) 
    13351336          quoted_value = "'#{quoted_value[1..-2].gsub(/\'/, "\\\\'")}'" if quoted_value.include?("\\\'") # (for ruby mode) "  
     
    16051606      end 
    16061607 
     1608      # Records loaded through joins with piggy-back attributes will be marked as read only as they cannot be saved and return true to this query. 
    16071609      def readonly? 
    16081610        @readonly == true 
    16091611      end 
    16101612 
    1611       def readonly! 
     1613      def readonly! #:nodoc: 
    16121614        @readonly = true 
    16131615      end 
  • trunk/activerecord/lib/active_record/calculations.rb

    r4069 r4078  
    11module ActiveRecord 
    2   module Calculations 
     2  module Calculations #:nodoc: 
    33    CALCULATIONS_OPTIONS = [:conditions, :joins, :order, :select, :group, :having, :distinct] 
    44    def self.included(base) 
     
    144144 
    145145      protected 
    146       def construct_calculation_sql(aggregate, aggregate_alias, options) 
    147         scope = scope(:find) 
    148         sql  = ["SELECT #{aggregate} AS #{aggregate_alias}"] 
    149         sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group] 
    150         sql << " FROM #{table_name} " 
    151         add_joins!(sql, options, scope) 
    152         add_conditions!(sql, options[:conditions], scope) 
    153         sql << " GROUP BY #{options[:group_field]}" if options[:group] 
    154         sql << " HAVING #{options[:having]}" if options[:group] && options[:having] 
    155         sql << " ORDER BY #{options[:order]}" if options[:order] 
    156         sql.join 
    157       end 
    158  
    159       def execute_simple_calculation(operation, column_name, column, aggregate, aggregate_alias, options) 
    160         value     = connection.select_value(construct_calculation_sql(aggregate, aggregate_alias, options)) 
    161         type_cast_calculated_value(value, column, operation) 
    162       end 
    163  
    164       def execute_grouped_calculation(operation, column_name, column, aggregate, aggregate_alias, options) 
    165         group_attr      = options[:group].to_s 
    166         association     = reflect_on_association(group_attr.to_sym) 
    167         associated      = association && association.macro == :belongs_to # only count belongs_to associations 
    168         group_field     = (associated ? "#{options[:group]}_id" : options[:group]).to_s 
    169         group_alias     = column_alias_for(group_field) 
    170         group_column    = column_for group_field 
    171         sql             = construct_calculation_sql(aggregate, aggregate_alias, options.merge(:group_field => group_field, :group_alias => group_alias)) 
    172         calculated_data = connection.select_all(sql) 
    173  
    174         if association 
    175           key_ids     = calculated_data.collect { |row| row[group_alias] } 
    176           key_records = association.klass.base_class.find(key_ids) 
    177           key_records = key_records.inject({}) { |hsh, r| hsh.merge(r.id => r) } 
    178         end 
    179  
    180         calculated_data.inject(OrderedHash.new) do |all, row| 
    181           key   = associated ? key_records[row[group_alias].to_i] : type_cast_calculated_value(row[group_alias], group_column) 
    182           value = row[aggregate_alias] 
    183           all << [key, type_cast_calculated_value(value, column, operation)] 
    184         end 
    185       end 
     146        def construct_calculation_sql(aggregate, aggregate_alias, options) #:nodoc: 
     147          scope = scope(:find) 
     148          sql  = ["SELECT #{aggregate} AS #{aggregate_alias}"] 
     149          sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group] 
     150          sql << " FROM #{table_name} " 
     151          add_joins!(sql, options, scope) 
     152          add_conditions!(sql, options[:conditions], scope) 
     153          sql << " GROUP BY #{options[:group_field]}" if options[:group] 
     154          sql << " HAVING #{options[:having]}" if options[:group] && options[:having] 
     155          sql << " ORDER BY #{options[:order]}" if options[:order] 
     156          sql.join 
     157        end 
     158 
     159        def execute_simple_calculation(operation, column_name, column, aggregate, aggregate_alias, options) #:nodoc: 
     160          value     = connection.select_value(construct_calculation_sql(aggregate, aggregate_alias, options)) 
     161          type_cast_calculated_value(value, column, operation) 
     162        end 
     163 
     164        def execute_grouped_calculation(operation, column_name, column, aggregate, aggregate_alias, options) #:nodoc: 
     165          group_attr      = options[:group].to_s 
     166          association     = reflect_on_association(group_attr.to_sym) 
     167          associated      = association && association.macro == :belongs_to # only count belongs_to associations 
     168          group_field     = (associated ? "#{options[:group]}_id" : options[:group]).to_s 
     169          group_alias     = column_alias_for(group_field) 
     170          group_column    = column_for group_field 
     171          sql             = construct_calculation_sql(aggregate, aggregate_alias, options.merge(:group_field => group_field, :group_alias => group_alias)) 
     172          calculated_data = connection.select_all(sql) 
     173 
     174          if association 
     175            key_ids     = calculated_data.collect { |row| row[group_alias] } 
     176            key_records = association.klass.base_class.find(key_ids) 
     177            key_records = key_records.inject({}) { |hsh, r| hsh.merge(r.id => r) } 
     178          end 
     179 
     180          calculated_data.inject(OrderedHash.new) do |all, row| 
     181            key   = associated ? key_records[row[group_alias].to_i] : type_cast_calculated_value(row[group_alias], group_column) 
     182            value = row[aggregate_alias] 
     183            all << [key, type_cast_calculated_value(value, column, operation)] 
     184          end 
     185        end 
    186186 
    187187      private 
    188       def validate_calculation_options(operation, options = {}) 
    189         if operation.to_s == 'count' 
    190           options.assert_valid_keys(CALCULATIONS_OPTIONS + [:include]) 
    191         else 
    192           options.assert_valid_keys(CALCULATIONS_OPTIONS) 
    193         end 
    194       end 
    195  
    196       def select_aggregate(operation, column_name, options) 
    197         "#{operation}(#{'DISTINCT ' if options[:distinct]}#{column_name})" 
    198       end 
    199  
    200       # converts a given key to the value that the database adapter returns as 
    201      
    202       #   users.id #=> users_id 
    203       #   sum(id) #=> sum_id 
    204       #   count(distinct users.id) #=> count_distinct_users_id 
    205       #   count(*) #=> count_all 
    206       def column_alias_for(*keys) 
    207         keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_') 
    208       end 
    209  
    210       def column_for(field) 
    211         field_name = field.to_s.split('.').last 
    212         columns.detect { |c| c.name.to_s == field_name } 
    213       end 
    214  
    215       def type_cast_calculated_value(value, column, operation = nil) 
    216         operation = operation.to_s.downcase 
    217         case operation 
    218           when 'count' then value.to_i 
    219           when 'avg'   then value.to_f 
    220           else column ? column.type_cast(value) : value 
    221         end 
    222       end 
     188        def validate_calculation_options(operation, options = {}) 
     189          if operation.to_s == 'count' 
     190            options.assert_valid_keys(CALCULATIONS_OPTIONS + [:include]) 
     191          else 
     192            options.assert_valid_keys(CALCULATIONS_OPTIONS) 
     193          end 
     194        end 
     195 
     196        def select_aggregate(operation, column_name, options) 
     197          "#{operation}(#{'DISTINCT ' if options[:distinct]}#{column_name})" 
     198        end 
     199 
     200        # converts a given key to the value that the database adapter returns as 
     201       
     202        #   users.id #=> users_id 
     203        #   sum(id) #=> sum_id 
     204        #   count(distinct users.id) #=> count_distinct_users_id 
     205        #   count(*) #=> count_all 
     206        def column_alias_for(*keys) 
     207          keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_') 
     208        end 
     209 
     210        def column_for(field) 
     211          field_name = field.to_s.split('.').last 
     212          columns.detect { |c| c.name.to_s == field_name } 
     213        end 
     214 
     215        def type_cast_calculated_value(value, column, operation = nil) 
     216          operation = operation.to_s.downcase 
     217          case operation 
     218            when 'count' then value.to_i 
     219            when 'avg'   then value.to_f 
     220            else column ? column.type_cast(value) : value 
     221          end 
     222        end 
    223223    end 
    224224  end 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb

    r3862 r4078  
    3939      
    4040      # set concurrency support flag (not thread safe, like most of the methods in this file) 
    41       def allow_concurrency=(threaded) 
     41      def allow_concurrency=(threaded) #:nodoc: 
    4242        logger.debug "allow_concurrency=#{threaded}" if logger 
    4343        return if @@allow_concurrency == threaded 
     
    5252      end 
    5353       
    54       def active_connection_name 
     54      def active_connection_name #:nodoc: 
    5555        @active_connection_name ||= 
    5656           if active_connections[name] || @@defined_connections[name] 
     
    6363      end 
    6464 
    65       def clear_active_connection_name 
     65      def clear_active_connection_name #:nodoc: 
    6666        @active_connection_name = nil 
    6767        subclasses.each { |klass| klass.clear_active_connection_name } 
     
    8989 
    9090      # Verify active connections. 
    91       def verify_active_connections! 
     91      def verify_active_connections! #:nodoc: 
    9292        if @@allow_concurrency 
    9393          remove_stale_cached_threads!(@@active_connections) do |name, conn| 
     
    245245 
    246246    # Set the connection for the class. 
    247     def self.connection=(spec) 
     247    def self.connection=(spec) #:nodoc: 
    248248      if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter) 
    249249        active_connections[name] = spec 
     
    258258 
    259259    # connection state logging 
    260     def self.log_connections 
     260    def self.log_connections #:nodoc: 
    261261      if logger 
    262262        logger.info "Defined connections: #{@@defined_connections.inspect}" 
  • trunk/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb

    r4055 r4078  
    4545      # This is preferable to inserting the hard-coded value here, because the insert method 
    4646      # needs to know the id value explicitly. 
    47       alias :attributes_with_quotes_pre_oracle :attributes_with_quotes #:nodoc: 
     47      def attributes_with_quotes_pre_oracle #:nodoc: 
     48        attributes_with_quotes 
     49      end 
     50         
     51 
    4852      def attributes_with_quotes(creating = true) #:nodoc: 
    4953        aq = attributes_with_quotes_pre_oracle creating 
     
    543547    end 
    544548 
    545     class OraObject 
     549    class OraObject #:nodoc: 
    546550      attr_reader :schema, :name 
    547551      def initialize(info) 
  • trunk/activerecord/lib/active_record/locking.rb

    r3822 r4078  
    6161     
    6262    class << self 
    63       def set_locking_column( value=nil, &block
     63      def set_locking_column(value = nil, &block
    6464        define_attr_method :locking_column, value, &block 
    6565      end 
    6666   
    67       def locking_column 
     67      def locking_column #:nodoc: 
    6868        reset_locking_column 
    6969      end 
    7070   
    71       def reset_locking_column 
     71      def reset_locking_column #:nodoc: 
    7272        default = 'lock_version' 
    7373        set_locking_column(default) 
  • trunk/activerecord/lib/active_record/validations.rb

    r4074 r4078  
    77  #     puts invalid.record.errors 
    88  #   end 
    9   class RecordInvalid < ActiveRecordError 
     9  class RecordInvalid < ActiveRecordError #:nodoc: 
    1010    attr_reader :record 
    1111    def initialize(record)