Module: OSCRuby::ValidationsModule
- Included in:
- QueryModule, QueryResults, ServiceClass
- 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_attributes_request(attributes_request, class_name) ⇒ Object
- .check_client(client) ⇒ Object
- .check_for_id(id) ⇒ Object
- .check_for_names(obj_attrs, class_name) ⇒ Object
- .check_for_parents(obj_attrs) ⇒ Object
- .check_interfaces(empty_arr) ⇒ Object
- .check_object_for_id(obj, class_name) ⇒ Object
- .check_query(query, method_name = "where") ⇒ Object
- .extract_attributes(obj) ⇒ Object
Class Method Details
.attr_hash_exists_and_is_type_of(obj, key, val, class_of_value) ⇒ Object
94 95 96 97 98 |
# File 'lib/osc_ruby/validations_module.rb', line 94 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_attributes_request(attributes_request, class_name) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/osc_ruby/validations_module.rb', line 74 def check_attributes_request(attributes_request,class_name) if attributes_request.empty? raise ArgumentError, "The attributes you are requesting for the #{class_name} object must be specified when using the 'select' method" end end |
.check_client(client) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/osc_ruby/validations_module.rb', line 84 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_for_names(obj_attrs, class_name) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/osc_ruby/validations_module.rb', line 100 def check_for_names(obj_attrs,class_name) if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil? raise ArgumentError, "#{class_name} should at least have one name set" end obj_attrs end |
.check_for_parents(obj_attrs) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/osc_ruby/validations_module.rb', line 112 def check_for_parents(obj_attrs) if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName') obj_attrs[0].delete('parent') end obj_attrs end |
.check_interfaces(empty_arr) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/osc_ruby/validations_module.rb', line 124 def check_interfaces(empty_arr) if empty_arr[0]['adminVisibleInterfaces'].empty? empty_arr[0].delete('adminVisibleInterfaces') end if empty_arr[0]['endUserVisibleInterfaces'].empty? empty_arr[0].delete('endUserVisibleInterfaces') end empty_arr 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, method_name = "where") ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/osc_ruby/validations_module.rb', line 64 def check_query(query,method_name = "where") if query.empty? raise ArgumentError, "A query must be specified when using the '#{method_name}' 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 |