module Troles::Common::Api::Validation

Public Instance Methods

check_valid_role?(role) click to toggle source

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

# File lib/troles/common/api/validation.rb, line 10
def check_valid_role? role
  return role if valid_roles.include? role.to_sym
  false
end
check_valid_roles?(*roles) click to toggle source

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

# File lib/troles/common/api/validation.rb, line 16
def check_valid_roles? *roles
  valid_roles & roles.to_symbols     
end

Protected Instance Methods

make_valid_role(role) 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/troles/common/api/validation.rb, line 25
def make_valid_role role
  raise ArgumentError, "Role to set must be a Symbol or String" if !role.kind_of_label?
  check_valid_role? role.to_s.alpha_numeric
end
make_valid_roles(*roles) 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/troles/common/api/validation.rb, line 33
def make_valid_roles *roles      
  roles = roles.to_symbols_uniq
  return [] if roles.empty?                
  check_valid_roles? roles.map{|r| r.to_s.alpha_numeric}
end
valid_roles() click to toggle source

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

# File lib/troles/common/api/validation.rb, line 40
def valid_roles
  self.class.troles_config.valid_roles
end