Skip to main content
deleted 29 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

Some comments on your code:

  • MaximumKeep the line length: below 80-100 is ok, more isor the code becomes unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate loginlogic in separate methods.
  • return true: a A return at the end of a code block is neither necessary nor idiomatic.
  • Subjective:[Subjective] I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

In a first refactor, I'd write a more readable case:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

On a second refactor, I'd probably gomove all the way and abstract everthinglogic to separate methods. Now you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate login in separate methods.
  • return true: a return at the end of a code block is neither necessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

In a first refactor, I'd write a more readable case:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

On a second refactor, I'd probably go all the way and abstract everthing to methods. Now you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end

Some comments on your code:

  • Keep the line length below 80-100 or the code becomes unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate logic in methods.
  • A return at the end of a code block is neither necessary nor idiomatic.
  • [Subjective] I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on.

In a first refactor, I'd write a more readable case:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

On a second refactor, I'd probably move all logic to separate methods. Now you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end
added 53 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate login in separate methods.
  • return true: a return at the end of a code block is neither necessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

In a first refactor, I'd write a more readable case:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

Note that that you couldOn a second refactor, I'd probably go all the way and abstract all logiceverthing to methods. ThenNow you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate login in separate methods.
  • return true: a return at the end of a code block is neither necessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

I'd write:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

Note that that you could go all the way and abstract all logic to methods. Then you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate login in separate methods.
  • return true: a return at the end of a code block is neither necessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

In a first refactor, I'd write a more readable case:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

On a second refactor, I'd probably go all the way and abstract everthing to methods. Now you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end
deleted 78 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, this is done by creatingencapsulate login in separate methods that abstract code. At least, the code within if self.template should be abstracted.
  • return true: a return at the end of a code block is neither needednecessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

I'd write:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

Note that that you could go all the way and abstract all logic to methods. Then you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, this is done by creating methods that abstract code. At least, the code within if self.template should be abstracted.
  • return true: a return at the end of a code block is neither needed nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

I'd write:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

Some comments on your code:

  • Maximum line length: 80-100 is ok, more is unreadable.
  • self[:active] == false -> !self[:active]
  • Checks should be terser, encapsulate login in separate methods.
  • return true: a return at the end of a code block is neither necessary nor idiomatic.
  • Subjective: I usually prefer full-fledge conditionals to guards, indentation helps a lot to see what's going on, IMO.

I'd write:

def active?
  case 
  when (!self[:active] && !ignore_column) || suspended || completed_at
    false
  when failed_attempts >= MAX_FAILED_ATTEMPTS
    if suppress_error_emails
      false
    end
      message = "Too many failed attempts for task execution. " + 
        "#{failed_attempts}/#{MAX_FAILED_ATTEMPTS} failed attempts for Task #{id}."
      SystemMailer.error(message: message)
    end
  # ...
  # more conditions here, you get the idea
  # ...
  when template && 
       (status_opted_out? || con_mktg_opted_out? || user_mktg_opted_out?)
    false
  else
    true
  end
end

Note that that you could go all the way and abstract all logic to methods. Then you could write:

def active?
  condition1? && condition2? && ... && conditionN?
end
deleted 201 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading
deleted 30 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading