@@ -35,7 +35,7 @@ def generate_path(*args)
3535 has_parent = namespace . size > 1 || ( options [ :with_parent ] && @options . parent )
3636
3737 if has_parent
38- parent_class = @options . parent ? @options . parent . class : ZendeskAPI . get_class ( namespace [ 0 ] )
38+ parent_class = @options . parent ? @options . parent . class : ZendeskAPI . const_get ( ZendeskAPI :: Helpers . modulize_string ( namespace [ 0 ] ) )
3939 parent_namespace = build_parent_namespace ( parent_class , instance , options , original_options )
4040 namespace [ 1 ..1 ] = parent_namespace if parent_namespace
4141 namespace [ 0 ] = parent_class . resource_name
@@ -176,8 +176,13 @@ def associated_with(name)
176176 # Represents a parent-to-child association between resources. Options to pass in are: class, path.
177177 # @param [Symbol] resource_name The underlying resource name
178178 # @param [Hash] opts The options to pass to the method definition.
179- def has ( resource_name , class_level_options = { } )
180- klass = get_class ( class_level_options . delete ( :class ) ) || get_class ( resource_name )
179+ def has ( resource_name_or_class , class_level_options = { } )
180+ if klass = class_level_options . delete ( :class )
181+ resource_name = resource_name_or_class
182+ else
183+ klass = resource_name_or_class
184+ resource_name = klass . singular_resource_name
185+ end
181186
182187 class_level_association = {
183188 :class => klass ,
@@ -231,8 +236,13 @@ def has(resource_name, class_level_options = {})
231236 # Represents a parent-to-children association between resources. Options to pass in are: class, path.
232237 # @param [Symbol] resource The underlying resource name
233238 # @param [Hash] opts The options to pass to the method definition.
234- def has_many ( resource_name , class_level_opts = { } )
235- klass = get_class ( class_level_opts . delete ( :class ) ) || get_class ( Inflection . singular ( resource_name . to_s ) )
239+ def has_many ( resource_name_or_class , class_level_opts = { } )
240+ if klass = class_level_opts . delete ( :class )
241+ resource_name = resource_name_or_class
242+ else
243+ klass = resource_name_or_class
244+ resource_name = klass . resource_name
245+ end
236246
237247 class_level_association = {
238248 :class => klass ,
@@ -292,47 +302,6 @@ def has_many(resource_name, class_level_opts = {})
292302 resource
293303 end
294304 end
295-
296- # Allows using has and has_many without having class defined yet
297- # Guesses at Resource, if it's anything else and the class is later
298- # reopened under a different superclass, an error will be thrown
299- def get_class ( resource )
300- return false if resource . nil?
301- res = ZendeskAPI ::Helpers . modulize_string ( resource . to_s )
302-
303- begin
304- const_get ( res )
305- rescue NameError , ArgumentError # ruby raises NameError, rails raises ArgumentError
306- ZendeskAPI . get_class ( resource )
307- end
308- end
309- end
310- end
311-
312- class << self
313- # Make sure Rails' overwriting of const_missing doesn't cause trouble
314- def const_missing ( *args )
315- Object . const_missing ( *args )
316- end
317-
318- # Allows using has and has_many without having class defined yet
319- # Guesses at Resource, if it's anything else and the class is later
320- # reopened under a different superclass, an error will be thrown
321- def get_class ( resource )
322- return false if resource . nil?
323- res = ZendeskAPI ::Helpers . modulize_string ( resource . to_s ) . split ( "::" )
324-
325- begin
326- res [ 1 ..-1 ] . inject ( ZendeskAPI . const_get ( res [ 0 ] ) ) do |iter , k |
327- begin
328- iter . const_get ( k )
329- rescue
330- iter . const_set ( k , Class . new ( Resource ) )
331- end
332- end
333- rescue NameError
334- ZendeskAPI . const_set ( res [ 0 ] , Class . new ( Resource ) )
335- end
336305 end
337306 end
338307end
0 commit comments