Module: Fakturoid::Utils
- Defined in:
- lib/fakturoid/utils.rb
Class Method Summary collapse
- .empty?(string) ⇒ Boolean
- .permit_params(params_hash, *permitted_params) ⇒ Object
- .validate_numerical_id(id) ⇒ Object
- .validate_search_query(query: nil, tags: nil, allow_tags: false) ⇒ Object
Class Method Details
.empty?(string) ⇒ 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
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 && empty?() && empty?(query) raise ArgumentError, "Query or tags parameter is required" elsif ! && empty?(query) raise ArgumentError, "Query parameter is required" end true end |