diff options
author | Rémy Coutable <remy@rymai.me> | 2016-04-19 11:37:50 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-04-19 11:37:50 +0300 |
commit | 2e9f03e5141368af6075723969fb031d5315e9c0 (patch) | |
tree | e8a299f16fa633c123680dfd409128b9775b32f4 /lib | |
parent | 53a1d705fe536ad373faa77ba1ef5196ff49a98b (diff) |
Define constants only if not defined yet and freeze them
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/file_size_validator.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/file_size_validator.rb b/lib/file_size_validator.rb index 2eae55e534b..7b136c2bbe5 100644 --- a/lib/file_size_validator.rb +++ b/lib/file_size_validator.rb @@ -1,9 +1,9 @@ class FileSizeValidator < ActiveModel::EachValidator - MESSAGES = { is: :wrong_size, minimum: :size_too_small, maximum: :size_too_big }.freeze - CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze + MESSAGES ||= { is: :wrong_size, minimum: :size_too_small, maximum: :size_too_big }.freeze + CHECKS ||= { is: :==, minimum: :>=, maximum: :<= }.freeze - DEFAULT_TOKENIZER = lambda { |value| value.split(//) } - RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long] + DEFAULT_TOKENIZER ||= -> (value) { value.split(//) }.freeze + RESERVED_OPTIONS ||= [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long].freeze def initialize(options) if range = (options.delete(:in) || options.delete(:within)) |