aboutsummaryrefslogblamecommitdiffstats
path: root/actionmailer/lib/action_mailer/adv_attr_accessor.rb
blob: 91992ed8396e53655ed3c6a0ab23d04b6c0c8485 (plain) (tree)
1
2
3
4
5
6
7
8
                   
                                 
                                 

                                               

                          
 


                                                       

             



                                                                                     
                
                                  

               


                                                                                                    
         


       
module ActionMailer
  module AdvAttrAccessor #:nodoc:
    def adv_attr_accessor(*names)
      
      # TODO: ActiveSupport::Deprecation.warn()
      names.each do |name|
        ivar = "@#{name}"

        class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1
          def #{name}=(value)
            #{ivar} = value
          end

          def #{name}(*args)
            raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1
            if args.empty?
              #{ivar} if instance_variable_names.include?(#{ivar.inspect})
            else
              #{ivar} = args.first
            end
          end
        ACCESSORS

        self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables)
      end
    end
  end
end