diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-05-14 14:09:49 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-05-14 14:09:49 -0500 |
commit | 3b0e1d90938e3d4c98830e037b3da15b3f736f7f (patch) | |
tree | 6e57d3b855939aa800bcac51647ab6906c13b217 | |
parent | f32b974338cb965a27d521b32304aebd9811a9ba (diff) | |
download | rails-3b0e1d90938e3d4c98830e037b3da15b3f736f7f.tar.gz rails-3b0e1d90938e3d4c98830e037b3da15b3f736f7f.tar.bz2 rails-3b0e1d90938e3d4c98830e037b3da15b3f736f7f.zip |
Prefer string core_ext inflector methods over directly accessing Inflector.
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 102 | ||||
-rw-r--r-- | actionpack/lib/action_controller/caching/sweeping.rb | 6 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 44 | ||||
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 14 |
4 files changed, 83 insertions, 83 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index a3762bf81b..aafa26e79e 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -11,11 +11,11 @@ module ActionMailer #:nodoc: # = Mailer Models # # To use ActionMailer, you need to create a mailer model. - # + # # $ script/generate mailer Notifier # - # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then - # used to set variables to be used in the mail template, to change options on the mail, or + # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then + # used to set variables to be used in the mail template, to change options on the mail, or # to add attachments. # # Examples: @@ -48,7 +48,7 @@ module ActionMailer #:nodoc: # named after each key in the hash containing the value that that key points to. # # So, for example, <tt>body :account => recipient</tt> would result - # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the + # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the # view. # # @@ -57,7 +57,7 @@ module ActionMailer #:nodoc: # Like ActionController, each mailer class has a corresponding view directory # in which each method of the class looks for a template with its name. # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method - # in your mailer model. For example, in the mailer defined above, the template at + # in your mailer model. For example, in the mailer defined above, the template at # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email. # # Variables defined in the model are accessible as instance variables in the view. @@ -71,48 +71,48 @@ module ActionMailer #:nodoc: # # You got a new note! # <%= truncate(note.body, 25) %> - # + # # # = Generating URLs - # + # # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. - # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request, - # so you'll need to provide all of the details needed to generate a URL. + # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request, + # so you'll need to provide all of the details needed to generate a URL. # # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>: - # + # # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %> # # When using named routes you only need to supply the <tt>:host</tt>: - # + # # <%= users_url(:host => "example.com") %> # # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to # generate relative URLs in email messages. # - # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in + # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows: # # ActionMailer::Base.default_url_options[:host] = "example.com" - # + # # This can also be set as a configuration option in <tt>config/environment.rb</tt>: # # config.action_mailer.default_url_options = { :host => "example.com" } # # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because - # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't + # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't # explicitly provided. # # = Sending mail # - # Once a mailer action and template are defined, you can deliver your message or create it and save it + # Once a mailer action and template are defined, you can deliver your message or create it and save it # for delivery later: # # Notifier.deliver_signup_notification(david) # sends the email # mail = Notifier.create_signup_notification(david) # => a tmail object # Notifier.deliver(mail) - # + # # You never instantiate your mailer class. Rather, your delivery instance # methods are automatically wrapped in class methods that start with the word # <tt>deliver_</tt> followed by the name of the mailer method that you would @@ -133,7 +133,7 @@ module ActionMailer #:nodoc: # from "system@example.com" # content_type "text/html" # Here's where the magic happens # end - # end + # end # # # = Multipart email @@ -155,17 +155,17 @@ module ActionMailer #:nodoc: # end # end # end - # + # # Multipart messages can also be used implicitly because ActionMailer will automatically # detect and use multipart templates, where each template is named after the name of the action, followed # by the content type. Each such detected template will be added as separate part to the message. - # + # # For example, if the following templates existed: # * signup_notification.text.plain.erb # * signup_notification.text.html.erb # * signup_notification.text.xml.builder # * signup_notification.text.x-yaml.erb - # + # # Each would be rendered and added as a separate part to the message, # with the corresponding content type. The same body hash is passed to # each template. @@ -191,7 +191,7 @@ module ActionMailer #:nodoc: # a.body = generate_your_pdf_here() # end # end - # end + # end # # # = Configuration options @@ -209,7 +209,7 @@ module ActionMailer #:nodoc: # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here. # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting. # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting. - # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here. + # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here. # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt> # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method @@ -226,10 +226,10 @@ module ActionMailer #:nodoc: # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful # for unit and functional testing. # - # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also + # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also # pick a different charset from inside a method with <tt>@charset</tt>. # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You - # can also pick a different content type from inside a method with <tt>@content_type</tt>. + # can also pick a different content type from inside a method with <tt>@content_type</tt>. # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to "1.0". You # can also pick a different value from inside a method with <tt>@mime_version</tt>. # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates @@ -249,16 +249,16 @@ module ActionMailer #:nodoc: cattr_accessor :template_extensions @@template_extensions = ['erb', 'builder', 'rhtml', 'rxml'] - @@smtp_settings = { - :address => "localhost", - :port => 25, - :domain => 'localhost.localdomain', - :user_name => nil, - :password => nil, + @@smtp_settings = { + :address => "localhost", + :port => 25, + :domain => 'localhost.localdomain', + :user_name => nil, + :password => nil, :authentication => nil } cattr_accessor :smtp_settings - + @@sendmail_settings = { :location => '/usr/sbin/sendmail', :arguments => '-i -t' @@ -270,10 +270,10 @@ module ActionMailer #:nodoc: superclass_delegating_accessor :delivery_method self.delivery_method = :smtp - + @@perform_deliveries = true cattr_accessor :perform_deliveries - + @@deliveries = [] cattr_accessor :deliveries @@ -282,7 +282,7 @@ module ActionMailer #:nodoc: @@default_content_type = "text/plain" cattr_accessor :default_content_type - + @@default_mime_version = "1.0" cattr_accessor :default_mime_version @@ -291,47 +291,47 @@ module ActionMailer #:nodoc: # Specify the BCC addresses for the message adv_attr_accessor :bcc - + # Define the body of the message. This is either a Hash (in which case it # specifies the variables to pass to the template when it is rendered), # or a string, in which case it specifies the actual text of the message. adv_attr_accessor :body - + # Specify the CC addresses for the message. adv_attr_accessor :cc - + # Specify the charset to use for the message. This defaults to the # +default_charset+ specified for ActionMailer::Base. adv_attr_accessor :charset - + # Specify the content type for the message. This defaults to <tt>text/plain</tt> # in most cases, but can be automatically set in some situations. adv_attr_accessor :content_type - + # Specify the from address for the message. adv_attr_accessor :from - + # Specify additional headers to be added to the message. adv_attr_accessor :headers - + # Specify the order in which parts should be sorted, based on content-type. # This defaults to the value for the +default_implicit_parts_order+. adv_attr_accessor :implicit_parts_order - + # Defaults to "1.0", but may be explicitly given if needed. adv_attr_accessor :mime_version - + # The recipient addresses for the message, either as a string (for a single # address) or an array (for multiple addresses). adv_attr_accessor :recipients - + # The date on which the message was sent. If not set (the default), the # header will be set by the delivery agent. adv_attr_accessor :sent_on - + # Specify the subject of the message. adv_attr_accessor :subject - + # Specify the template name to use for current message. This is the "base" # template name, without the extension or directory, and may be used to # have multiple mailer methods share the same template. @@ -347,7 +347,7 @@ module ActionMailer #:nodoc: self.class.mailer_name end end - + def mailer_name=(value) self.class.mailer_name = value end @@ -425,7 +425,7 @@ module ActionMailer #:nodoc: # remain uninitialized (useful when you only need to invoke the "receive" # method, for instance). def initialize(method_name=nil, *parameters) #:nodoc: - create!(method_name, *parameters) if method_name + create!(method_name, *parameters) if method_name end # Initialize the mailer via the given +method_name+. The body will be @@ -511,7 +511,7 @@ module ActionMailer #:nodoc: @content_type ||= @@default_content_type.dup @implicit_parts_order ||= @@default_implicit_parts_order.dup @template ||= method_name - @mailer_name ||= Inflector.underscore(self.class.name) + @mailer_name ||= self.class.name.underscore @parts ||= [] @headers ||= {} @body ||= {} @@ -597,7 +597,7 @@ module ActionMailer #:nodoc: part = (TMail::Mail === p ? p : p.to_mail(self)) m.parts << part end - + if real_content_type =~ /multipart/ ctype_attrs.delete "charset" m.set_content_type(real_content_type, nil, ctype_attrs) @@ -612,7 +612,7 @@ module ActionMailer #:nodoc: mail.ready_to_send sender = mail['return-path'] || mail.from - Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain], + Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| smtp.sendmail(mail.encoded, sender, destinations) end diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb index 3164e14f6f..61559e9ec7 100644 --- a/actionpack/lib/action_controller/caching/sweeping.rb +++ b/actionpack/lib/action_controller/caching/sweeping.rb @@ -28,7 +28,7 @@ module ActionController #:nodoc: # class ListsController < ApplicationController # caches_action :index, :show, :public, :feed # cache_sweeper OpenBar::Sweeper, :only => [ :edit, :destroy, :share ] - # end + # end module Sweeping def self.included(base) #:nodoc: base.extend(ClassMethods) @@ -40,7 +40,7 @@ module ActionController #:nodoc: sweepers.each do |sweeper| ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base) - sweeper_instance = (sweeper.is_a?(Symbol) ? Object.const_get(Inflector.classify(sweeper)) : sweeper).instance + sweeper_instance = (sweeper.is_a?(Symbol) ? Object.const_get(sweeper.to_s.classify) : sweeper).instance if sweeper_instance.is_a?(Sweeper) around_filter(sweeper_instance, :only => configuration[:only]) @@ -94,4 +94,4 @@ module ActionController #:nodoc: end end end -end
\ No newline at end of file +end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ac1a35dc91..5351f55200 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -438,11 +438,11 @@ module ActiveRecord #:nodoc: # adapters for, e.g., your development and test environments. cattr_accessor :schema_format , :instance_writer => false @@schema_format = :ruby - + # Determine whether to store the full constant name including namespace when using STI superclass_delegating_accessor :store_full_sti_class self.store_full_sti_class = false - + class << self # Class methods # Find operates with four different retrieval approaches: # @@ -526,7 +526,7 @@ module ActiveRecord #:nodoc: else find_from_ids(args, options) end end - + # This is an alias for find(:first). You can pass in all the same arguments to this method as you can # to find(:first) def first(*args) @@ -538,13 +538,13 @@ module ActiveRecord #:nodoc: def last(*args) find(:last, *args) end - + # This is an alias for find(:all). You can pass in all the same arguments to this method as you can # to find(:all) def all(*args) find(:all, *args) end - + # # Executes a custom sql query against your database and returns all the results. The results will # be returned as an array with columns requested encapsulated as attributes of the model you call @@ -591,10 +591,10 @@ module ActiveRecord #:nodoc: def exists?(id_or_conditions) connection.select_all( construct_finder_sql( - :select => "#{quoted_table_name}.#{primary_key}", - :conditions => expand_id_conditions(id_or_conditions), + :select => "#{quoted_table_name}.#{primary_key}", + :conditions => expand_id_conditions(id_or_conditions), :limit => 1 - ), + ), "#{name} Exists" ).size > 0 end @@ -620,7 +620,7 @@ module ActiveRecord #:nodoc: # # Creating an Array of new objects using a block, where the block is executed for each object: # User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u| # u.is_admin = false - # end + # end def create(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create(attr, &block) } @@ -1027,9 +1027,9 @@ module ActiveRecord #:nodoc: key = 'id' case primary_key_prefix_type when :table_name - key = Inflector.foreign_key(base_name, false) + key = base_name.to_s.foreign_key(false) when :table_name_with_underscore - key = Inflector.foreign_key(base_name) + key = base_name.to_s.foreign_key end key end @@ -1302,7 +1302,7 @@ module ActiveRecord #:nodoc: scoped_order = reverse_sql_order(scope(:find, :order)) scoped_methods.select { |s| s[:find].update(:order => scoped_order) } end - + find_initial(options.merge({ :order => order })) end @@ -1312,12 +1312,12 @@ module ActiveRecord #:nodoc: s.gsub!(/\s(asc|ASC)$/, ' DESC') elsif s.match(/\s(desc|DESC)$/) s.gsub!(/\s(desc|DESC)$/, ' ASC') - elsif !s.match(/\s(asc|ASC|desc|DESC)$/) + elsif !s.match(/\s(asc|ASC|desc|DESC)$/) s.concat(' DESC') end }.join(',') end - + def find_every(options) include_associations = merge_includes(scope(:find, :include), options[:include]) @@ -1570,8 +1570,8 @@ module ActiveRecord #:nodoc: # Guesses the table name, but does not decorate it with prefix and suffix information. def undecorated_table_name(class_name = base_class.name) - table_name = Inflector.underscore(Inflector.demodulize(class_name)) - table_name = Inflector.pluralize(table_name) if pluralize_table_names + table_name = class_name.to_s.demodulize.underscore + table_name = table_name.pluralize if pluralize_table_names table_name end @@ -1620,7 +1620,7 @@ module ActiveRecord #:nodoc: self.class_eval %{ def self.#{method_id}(*args) guard_protected_attributes = false - + if args[0].is_a?(Hash) guard_protected_attributes = true attributes = args[0].with_indifferent_access @@ -1633,7 +1633,7 @@ module ActiveRecord #:nodoc: set_readonly_option!(options) record = find_initial(options) - + if record.nil? record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) } #{'yield(record) if block_given?'} @@ -2133,14 +2133,14 @@ module ActiveRecord #:nodoc: # We can't use alias_method here, because method 'id' optimizes itself on the fly. (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes end - + # Returns a cache key that can be used to identify this record. Examples: # # Product.new.cache_key # => "products/new" # Product.find(5).cache_key # => "products/5" (updated_at not available) # Person.find(5).cache_key # => "people/5-20071224150000" (updated_at available) def cache_key - case + case when new_record? "#{self.class.name.tableize}/new" when self[:updated_at] @@ -2174,7 +2174,7 @@ module ActiveRecord #:nodoc: # Note: If your model specifies any validations then the method declaration dynamically # changes to: # save(perform_validation=true) - # Calling save(false) saves the model without running validations. + # Calling save(false) saves the model without running validations. # See ActiveRecord::Validations for more information. def save create_or_update @@ -2496,7 +2496,7 @@ module ActiveRecord #:nodoc: # Message class in that example. def ensure_proper_type unless self.class.descends_from_active_record? - write_attribute(self.class.inheritance_column, store_full_sti_class ? self.class.name : Inflector.demodulize(self.class.name)) + write_attribute(self.class.inheritance_column, store_full_sti_class ? self.class.name : self.class.name.demodulize) end end diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 9367ea523d..ac06cdbe43 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -197,20 +197,20 @@ end # class FooTest < ActiveSupport::TestCase # self.use_transactional_fixtures = true # self.use_instantiated_fixtures = false -# +# # fixtures :foos -# +# # def test_godzilla # assert !Foo.find(:all).empty? # Foo.destroy_all # assert Foo.find(:all).empty? # end -# +# # def test_godzilla_aftermath # assert !Foo.find(:all).empty? # end # end -# +# # If you preload your test database with all fixture data (probably in the Rakefile task) and use transactional fixtures, # then you may omit all fixtures declarations in your test cases since all the data's already there and every case rolls back its changes. # @@ -730,7 +730,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) reader.each do |row| data = {} row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip } - self["#{Inflector::underscore(@class_name)}_#{i+=1}"] = Fixture.new(data, model_class) + self["#{@class_name.to_s.underscore}_#{i+=1}"] = Fixture.new(data, model_class) end end @@ -854,14 +854,14 @@ module Test #:nodoc: require_dependency file_name rescue LoadError => e # Let's hope the developer has included it himself - + # Let's warn in case this is a subdependency, otherwise # subdependency error messages are totally cryptic if ActiveRecord::Base.logger ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}") end end - + def require_fixture_classes(table_names = nil) (table_names || fixture_table_names).each do |table_name| file_name = table_name.to_s |