Method: OldApiResource::Base.set_class_attributes_upon_load
- Defined in:
- lib/old_api_resource/base.rb
.set_class_attributes_upon_load ⇒ Object
This makes a request to new_element_path
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/old_api_resource/base.rb', line 43 def set_class_attributes_upon_load begin class_data = self.connection.get(self.new_element_path) # Attributes go first if class_data["attributes"] define_attributes *(class_data["attributes"]["public"] || []) define_protected_attributes *(class_data["attributes"]["protected"] || []) end # Then scopes if class_data["scopes"] class_data["scopes"].each do |hash| self.scope hash.first[0], hash.first[1] end end # Then associations if class_data["associations"] class_data["associations"].each do |(key,hash)| hash.each do |assoc_name, | self.send(key, assoc_name, ) end end end # Swallow up any loading errors because the site may be incorrect rescue Exception => e if OldApiResource.raise_missing_definition_error raise e end OldApiResource.logger.warn("#{self}: #{e.}") OldApiResource.logger.debug(e.backtrace.pretty_inspect) return e.respond_to?(:request) ? e.request : nil end end |