Class: Validation::Rule::DiasporaIdList
- Inherits:
-
Object
- Object
- Validation::Rule::DiasporaIdList
- Defined in:
- lib/diaspora_federation/validators/rules/diaspora_id_list.rb
Overview
Rule for validating the number of diaspora* IDs in a string. The evaluated string is split at “;”.
Instance Attribute Summary collapse
-
#params ⇒ Hash
readonly
This rule can have a
minimum
ormaximum
param.
Instance Method Summary collapse
-
#error_key ⇒ Symbol
The error key for this rule.
-
#initialize(params = {}) ⇒ DiasporaIdList
constructor
Creates a new rule for a diaspora* ID list validation.
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ DiasporaIdList
Creates a new rule for a diaspora* ID list validation
16 17 18 19 20 21 22 23 24 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_list.rb', line 16 def initialize(params={}) %i[minimum maximum].each do |param| if params.include?(param) && !params[param].is_a?(Integer) raise ArgumentError, "The :#{param} needs to be an Integer" end end @params = params end |
Instance Attribute Details
#params ⇒ Hash (readonly)
This rule can have a minimum
or maximum
param.
10 11 12 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_list.rb', line 10 def params @params end |
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
28 29 30 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_list.rb', line 28 def error_key :diaspora_id_list end |
#valid_value?(value) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id_list.rb', line 32 def valid_value?(value) ids = value.split(";") return false if params.include?(:maximum) && ids.count > params[:maximum] return false if params.include?(:minimum) && ids.count < params[:minimum] ids.each do |id| return false if DiasporaId::DIASPORA_ID.match(id).nil? end true end |