Sha256: 26f971d5af6b5ca7fd19603cae5fd4acc410d14f9a40d73ea05608d5768fa3f0
Contents?: true
Size: 1.29 KB
Versions: 42
Compression:
Stored size: 1.29 KB
Contents
module RestfulResource module Associations def has_many(nested_resource_type) namespace = self.to_s.deconstantize klass_name = "#{nested_resource_type.to_s.singularize.camelize.to_s}" klass_name = "#{namespace}::#{klass_name}" if namespace.present? self.send(:define_method, nested_resource_type) do klass = begin klass_name.safe_constantize rescue NameError nil end klass = RestfulResource::OpenObject if (klass.nil? || !(klass < RestfulResource::OpenObject)) @inner_object.send(nested_resource_type).map { |obj| klass.new(obj) } end end def has_one(nested_resource_type) namespace = self.to_s.deconstantize klass_name = "#{nested_resource_type.to_s.camelize.to_s}" klass_name = "#{namespace}::#{klass_name}" if namespace.present? self.send(:define_method, nested_resource_type) do klass = begin klass_name.safe_constantize rescue NameError nil end klass = RestfulResource::OpenObject if (klass.nil? || !(klass < RestfulResource::OpenObject)) nested_resource = @inner_object.send(nested_resource_type) return nil if nested_resource.nil? klass.new(@inner_object.send(nested_resource_type)) end end end end
Version data entries
42 entries across 42 versions & 1 rubygems