Skip to main content
added 46 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

A few tips that come into my mind:

  1. extract SunspotExtract Sunspot search logic to a separate class, it's. It's not really usera user's concern: https://github.com/sunspot/sunspot/wiki/Setting-up-classes-for-search-and-indexing.

  2. inlineInline some scopes, i.e.:

    scope :with_dependents, -> { includes(:common_app, :video, :applications, :jobs) }

     scope :with_dependents, -> { includes(:common_app, :video, :applications, :jobs) }
    

(thisThis is actually more readable in my opinion.)

  1. extractExtract password management and encryption to separate class (again, not really userthe user's concern):

    class PasswordManager attr_reader :user

    def initialize(user) @user = user end

    def generate_password user.password = ("a".."z").to_a.sample(8).join("") end end

     class PasswordManager
       attr_reader :user
    
       def initialize(user)
         @user = user
       end
    
       def generate_password
         user.password = ("a".."z").to_a.sample(8).join("")
       end
     end
    

Hope it helps.

few tips that come into my mind:

  1. extract Sunspot search logic to separate class, it's not really user concern: https://github.com/sunspot/sunspot/wiki/Setting-up-classes-for-search-and-indexing

  2. inline some scopes, i.e.:

    scope :with_dependents, -> { includes(:common_app, :video, :applications, :jobs) }

(this is actually more readable in my opinion)

  1. extract password management and encryption to separate class (again not really user concern):

    class PasswordManager attr_reader :user

    def initialize(user) @user = user end

    def generate_password user.password = ("a".."z").to_a.sample(8).join("") end end

Hope it helps.

A few tips that come into my mind:

  1. Extract Sunspot search logic to a separate class. It's not really a user's concern.

  2. Inline some scopes, i.e.:

     scope :with_dependents, -> { includes(:common_app, :video, :applications, :jobs) }
    

(This is actually more readable in my opinion.)

  1. Extract password management and encryption to separate class (again, not really the user's concern):

     class PasswordManager
       attr_reader :user
    
       def initialize(user)
         @user = user
       end
    
       def generate_password
         user.password = ("a".."z").to_a.sample(8).join("")
       end
     end
    
Source Link
rui
  • 416
  • 2
  • 3

few tips that come into my mind:

  1. extract Sunspot search logic to separate class, it's not really user concern: https://github.com/sunspot/sunspot/wiki/Setting-up-classes-for-search-and-indexing

  2. inline some scopes, i.e.:

    scope :with_dependents, -> { includes(:common_app, :video, :applications, :jobs) }

(this is actually more readable in my opinion)

  1. extract password management and encryption to separate class (again not really user concern):

    class PasswordManager attr_reader :user

    def initialize(user) @user = user end

    def generate_password user.password = ("a".."z").to_a.sample(8).join("") end end

Hope it helps.