class RailsIbm::Uprofile::Arguments
Public Class Methods
new(options)
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 6 def initialize(options) @options = options end
Public Instance Methods
filter(allowed, options = nil)
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 10 def filter(allowed, options = nil) (options || @options).select {|k,v| allowed.include?(k) } end
validate()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 14 def validate raise SyntaxError.new description: "Invalid Argument. #{DOC_LINK}" if invalid_options raise SyntaxError.new description: "More than one required Argument. #{DOC_LINK}" if multiple raise SyntaxError.new description: "Missing required Argument. #{DOC_LINK}" if missing raise TypeError.new description: "Invalid Argument type. #{DOC_LINK}" if invalid_type || unmatch_type true end
Private Instance Methods
invalid_options()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 54 def invalid_options !@options.is_a? Hash end
invalid_type()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 38 def invalid_type config = { type: Array, value: value } config[:type] = String if @options.include?(:uid) || @options.include?(:email) || @options.include?(:query) !config[:value].is_a?(config[:type]) end
is_valid_email?(email)
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 58 def is_valid_email?(email) (email =~ RailsIbm::Uprofile::EMAIL_REGEX) != nil end
missing()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 29 def missing value == nil end
multiple()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 33 def multiple allowed = %i[uid uids email emails query] @options.keys.select { |k| allowed.include?(k) }.size > 1 end
unmatch_type()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 45 def unmatch_type entry = value entry = value.first if value.is_a? Array return is_valid_email?(entry) if @options.include?(:uid) || @options.include?(:uids) return !is_valid_email?(entry) if @options.include?(:email) || @options.include?(:emails) false end
value()
click to toggle source
# File lib/rails_ibm/uprofile/arguments.rb, line 25 def value @options[:uids] || @options[:emails] || @options[:uid] || @options[:email] || @options[:query] end