Module: Fakturoid::Utils

Defined in:
lib/fakturoid/utils.rb

Class Method Summary collapse

Class Method Details

.empty?(string) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/fakturoid/utils.rb', line 23

def self.empty?(string)
  string.nil? || string.empty?
end

.permit_params(params_hash, *permitted_params) ⇒ Object



5
6
7
# File 'lib/fakturoid/utils.rb', line 5

def self.permit_params(params_hash, *permitted_params)
  params_hash.select { |param, _value| permitted_params.include?(param.to_sym) }
end

.validate_numerical_id(id) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/fakturoid/utils.rb', line 9

def self.validate_numerical_id(id)
  raise ArgumentError, "Wrong ID given: #{id}" if !id.is_a?(Integer) && !(id.is_a?(String) && id =~ /\A\d+\z/)
  true
end

.validate_search_query(query: nil, tags: nil, allow_tags: false) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/fakturoid/utils.rb', line 14

def self.validate_search_query(query: nil, tags: nil, allow_tags: false)
  if allow_tags && empty?(tags) && empty?(query)
    raise ArgumentError, "Query or tags parameter is required"
  elsif !allow_tags && empty?(query)
    raise ArgumentError, "Query parameter is required"
  end
  true
end