diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-10 17:31:33 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-15 15:48:15 +0100 |
commit | e2d4bdb629997036c6ed72d7eb14b95dae6f76cb (patch) | |
tree | 211c5e4cbb7784e04f75ff563ff3f0eb88c3c18e | |
parent | ccd7da2ca592db909e9ea12cf7135945f31ddd01 (diff) |
Privatise uncalled CensorRule methods
Make public api as slim as possible
-rw-r--r-- | app/models/censor_rule.rb | 40 | ||||
-rw-r--r-- | doc/CHANGES.md | 4 |
2 files changed, 23 insertions, 21 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index eda4e23af..499896e54 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -42,26 +42,6 @@ class CensorRule < ActiveRecord::Base :user_id => nil, :public_body_id => nil } } - def require_user_request_or_public_body - if info_request.nil? && user.nil? && public_body.nil? - [:info_request, :user, :public_body].each do |a| - errors.add(a, "Rule must apply to an info request, a user or a body") - end - end - end - - def require_valid_regexp - begin - make_regexp - rescue RegexpError => e - errors.add(:text, e.message) - end - end - - def make_regexp - Regexp.new(text, Regexp::MULTILINE) - end - def apply_to_text!(text) return nil if text.nil? text.gsub!(to_replace, replacement) @@ -84,6 +64,26 @@ class CensorRule < ActiveRecord::Base private + def require_user_request_or_public_body + if info_request.nil? && user.nil? && public_body.nil? + [:info_request, :user, :public_body].each do |a| + errors.add(a, "Rule must apply to an info request, a user or a body") + end + end + end + + def require_valid_regexp + begin + make_regexp + rescue RegexpError => e + errors.add(:text, e.message) + end + end + + def make_regexp + Regexp.new(text, Regexp::MULTILINE) + end + def to_replace regexp? ? make_regexp : text end diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 40834d4d0..7a93f9cb0 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -9,7 +9,9 @@ your theme, you will now have to satisfy the additional validations on the `:replacement`, `:last_edit_comment` and `:last_edit_editor` attributes. * Public body categories will now be stored in the database rather than being read directly from the `lib/public_body_categories_LOCALE` files. Once you have upgraded, run `script/migrate-public-body-categories`to import the contents of the files into the database. All further changes will then need to be made via the administrative interface. You can then remove any `pubic_body_categories_[locale].rb` files from your theme. If your theme has any calls to `PublicBodyCategories` methods outside these files, you should update them to call the corresponding method on `PublicBodyCategory` instead. - +* `CensorRule#require_user_request_or_public_body`, `CensorRule#make_regexp` and + `CensorRule#require_valid_regexp` have become private methods. If you override + them in your theme, ensure they are preceded by the `private` keyword. # Version 0.19 |