Module: OSCRuby::ValidationsModule
- Included in:
- Answer, QueryModule, ServiceProduct
- Defined in:
- lib/osc_ruby/validations_module.rb
Class Method Summary collapse
- .attr_hash_exists_and_is_type_of(obj, key, val, class_of_value) ⇒ Object
- .check_attributes(attributes) ⇒ Object
- .check_client(client) ⇒ Object
- .check_for_id(id) ⇒ Object
- .check_object_for_id(obj, class_name) ⇒ Object
- .check_query(query) ⇒ Object
- .extract_attributes(obj) ⇒ Object
Class Method Details
.attr_hash_exists_and_is_type_of(obj, key, val, class_of_value) ⇒ Object
84 85 86 87 88 |
# File 'lib/osc_ruby/validations_module.rb', line 84 def attr_hash_exists_and_is_type_of(obj,key,val,class_of_value) return obj[0][key][val].nil? || obj[0][key][val].class != class_of_value end |
.check_attributes(attributes) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/osc_ruby/validations_module.rb', line 54 def check_attributes(attributes) if attributes.class != Hash raise ArgumentError, "Attributes must be a hash; please use the appropriate data structure" end end |
.check_client(client) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/osc_ruby/validations_module.rb', line 74 def check_client(client) if client.class != OSCRuby::Client || client.nil? raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings" end end |
.check_for_id(id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/osc_ruby/validations_module.rb', line 30 def check_for_id(id) if id.nil? == true raise ArgumentError, 'ID cannot be nil' elsif id.class != Fixnum raise ArgumentError, 'ID must be an integer' end end |
.check_object_for_id(obj, class_name) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/osc_ruby/validations_module.rb', line 44 def check_object_for_id(obj,class_name) if obj.id.nil? raise ArgumentError, "#{class_name} must have a valid ID set" end end |
.check_query(query) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/osc_ruby/validations_module.rb', line 64 def check_query(query) if query.empty? raise ArgumentError, 'A query must be specified when using the "where" method' end end |
.extract_attributes(obj) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/osc_ruby/validations_module.rb', line 10 def extract_attributes(obj) empty_arr = [{}] obj_vars = obj.instance_variables obj_vars.each do |var| obj_attr = var.to_s.delete("@") obj_attr_val = obj.instance_variable_get(var) empty_arr[0][obj_attr] = obj_attr_val end empty_arr end |