module TroleGroups::Api::Validation

Public Instance Methods

check_valid_rolegroup?(rolegroup) click to toggle source

@return [Symbol, false] returns the role if it's valid, false if not

# File lib/trole_groups/api/validation.rb, line 10
def check_valid_rolegroup? rolegroup
  return rolegroup if valid_rolegroups.include? rolegroup.to_sym
  false
end
check_valid_rolegroups?(*rolegroups) click to toggle source

@return [Array<Symbol>] returns the valid roles or empty list if no valid roles

# File lib/trole_groups/api/validation.rb, line 16
def check_valid_rolegroups? *rolegroups
  valid_rolegroups & rolegroups.to_symbols     
end

Protected Instance Methods

make_valid_rolegroup(rolegroup) click to toggle source

Ensures the role is valid @param [Symbol] role name @return [Symbol, false, Error] a valid role name, false if invalid, or Error on some error

# File lib/trole_groups/api/validation.rb, line 25
def make_valid_rolegroup rolegroup
  raise ArgumentError, "Rolegroup to set must be a Symbol or String" if !rolegroup.kind_of_label?
  check_valid_rolegroup? rolegroup.to_s.alpha_numeric
end
make_valid_rolegroups(*rolegroups) click to toggle source

Ensures the role are valid @param [Symbol] list of roles @return [Array<Symbol>] the valid roles from the list of roles given

# File lib/trole_groups/api/validation.rb, line 33
def make_valid_rolegroups *rolegroups      
  rolegroups = rolegroups.to_symbols_uniq
  return [] if rolegroups.empty?                
  check_valid_rolegroups? rolegroups.map{|r| r.to_s.alpha_numeric}
end
valid_rolegroups() click to toggle source

@return [Array<Symbol>] the valid roles of the role subject

# File lib/trole_groups/api/validation.rb, line 40
def valid_rolegroups
  self.class.trolegroups_config.valid_rolegroups
end