<commit_before>= protective

In your ActiveRecord models, you used to protect the instances from being destroyed as follows:

  before_destroy :protect_if_has_attachments
  
  def protect_if_has_attachments
    unless attachments.empty?
      errors.add(:base, "Record has attachments and cannot be destroyed")
    end
  end

With +protective+, this is reduced to:

  protect_if :attachments, "Record has attachments and cannot be destroyed"

Of course, you may pass the name of any defined method. If its result evaluates to +present?+, the record is not going to be destroyed. No exception is thrown, but a message is added to the +errors+ object of your model. This may then be used further on.

To use protective, simply add it to your +Gemfile+:

  gem 'protective'


== Copyright

Copyright (c) 2011 <NAME>. See LICENSE.txt for
further details.
<commit_msg>add travis status image<commit_after>= protective

In your ActiveRecord models, you used to protect the instances from being destroyed as follows:

  before_destroy :protect_if_has_attachments
  
  def protect_if_has_attachments
    unless attachments.empty?
      errors.add(:base, "Record has attachments and cannot be destroyed")
    end
  end

With +protective+, this is reduced to:

  protect_if :attachments, "Record has attachments and cannot be destroyed"

Of course, you may pass the name of any defined method. If its result evaluates to +present?+, the record is not going to be destroyed. No exception is thrown, but a message is added to the +errors+ object of your model. This may then be used further on.

To use protective, simply add it to your +Gemfile+:

  gem 'protective'


{<img src="https://secure.travis-ci.org/codez/protective.png" />}[http://travis-ci.org/codez/protective]

== Copyright

Copyright (c) 2011 <NAME>. See LICENSE.txt for
further details.

{'fraction_non_alphanumeric': 0.06948968512486428, 'fraction_numerical': 0.004343105320304018, 'mean_word_length': 4.250712250712251, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1715004', 'n_tokens_mistral': 536, 'n_tokens_neox': 493, 'n_words': 244}