Class: Validation::Rule::DiasporaIdCount
- Inherits:
-
Object
- Object
- Validation::Rule::DiasporaIdCount
- Defined in:
- lib/diaspora_federation/validators/rules/diaspora_id_count.rb
Overview
Rule for validating the number of diaspora* IDs in a string. The evaluated string is split at “;” and the result will be counted.
Instance Attribute Summary collapse
-
#params ⇒ Hash
readonly
This rule must have a
maximum
param.
Instance Method Summary collapse
-
#error_key ⇒ Symbol
The error key for this rule.
-
#initialize(params) ⇒ DiasporaIdCount
constructor
Creates a new rule for a maximum diaspora* ID count validation.
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(params) ⇒ DiasporaIdCount
Creates a new rule for a maximum diaspora* ID count validation
13 14 15 16 17 18 19 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_count.rb', line 13 def initialize(params) unless params.include?(:maximum) && params[:maximum].is_a?(Integer) raise ArgumentError, "A number has to be specified for :maximum" end @params = params end |
Instance Attribute Details
#params ⇒ Hash (readonly)
This rule must have a maximum
param.
8 9 10 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_count.rb', line 8 def params @params end |
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
23 24 25 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_count.rb', line 23 def error_key :diaspora_id_count end |
#valid_value?(value) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_count.rb', line 27 def valid_value?(value) ids = value.split(";") return false unless ids.count <= params[:maximum] ids.each do |id| return false if DiasporaId::DIASPORA_ID.match(id).nil? end true end |