kelredd-resourceful 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ module Resourceful::Extensions::String
|
|
18
18
|
|
19
19
|
constant = ::Object
|
20
20
|
names.each do |name|
|
21
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) :
|
21
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : raise(NameError.new("uninitialized constant #{self}"))
|
22
22
|
end
|
23
23
|
constant
|
24
24
|
end
|
@@ -29,7 +29,7 @@ module Resourceful::Extensions::String
|
|
29
29
|
|
30
30
|
constant = ::Object
|
31
31
|
names.each do |name|
|
32
|
-
constant = constant.const_get(name, false) ||
|
32
|
+
constant = constant.const_get(name, false) || raise(NameError.new("uninitialized constant #{self}"))
|
33
33
|
end
|
34
34
|
constant
|
35
35
|
end
|
@@ -26,7 +26,7 @@ module Resourceful::Model::ActiverecordAssociations
|
|
26
26
|
define_method(name) do |*args|
|
27
27
|
reload = args.first || false
|
28
28
|
if reload || (assoc_val = instance_variable_get("@#{clean_name}")).nil?
|
29
|
-
klass = class_name.resourceful_constantize
|
29
|
+
klass = class_name.kind_of(::String) ? class_name.resourceful_constantize : class_name
|
30
30
|
raise ArgumentError, "has_many_resourceful :class_name '#{class_name}' is not defined" if klass.nil?
|
31
31
|
unless klass.respond_to?(find_method_name)
|
32
32
|
raise NotImplementedError, "has_many_resourceful expects #{klass} to implement a Findable method named '#{find_method_name}'"
|
@@ -63,11 +63,15 @@ module Resourceful::Model::ActiverecordAssociations
|
|
63
63
|
define_method(name) do |*args|
|
64
64
|
reload = args.first || false
|
65
65
|
if reload || (assoc_val = instance_variable_get("@#{clean_name}")).nil?
|
66
|
-
klass = if
|
67
|
-
|
66
|
+
klass = if class_name.kind_of(::String)
|
67
|
+
if polymorphic
|
68
|
+
self.send("#{clean_name}_type")
|
69
|
+
else
|
70
|
+
class_name
|
71
|
+
end.resourceful_constantize
|
68
72
|
else
|
69
73
|
class_name
|
70
|
-
end
|
74
|
+
end
|
71
75
|
raise ArgumentError, "belongs_to_resourceful :class_name '#{class_name}' is not defined" if klass.nil?
|
72
76
|
unless self.respond_to?(foreign_key_method)
|
73
77
|
raise ArgumentError, "belongs_to_resourceful requires a '#{foreign_key_method}' method defined to return the foreign_key"
|
@@ -21,12 +21,16 @@ module Resourceful::Model
|
|
21
21
|
end
|
22
22
|
def self.get_namespaced_klass(class_name)
|
23
23
|
klass = nil
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
if class_name.kind_of?(::String)
|
25
|
+
@@namespaces.each do |ns|
|
26
|
+
begin
|
27
|
+
klass = "#{ns}::#{class_name}".resourceful_constantize
|
28
|
+
break;
|
29
|
+
rescue Exception => err
|
30
|
+
end
|
29
31
|
end
|
32
|
+
else
|
33
|
+
klass = class_name
|
30
34
|
end
|
31
35
|
klass
|
32
36
|
end
|
@@ -14,7 +14,15 @@ module Resourceful
|
|
14
14
|
associations.each do |association_name|
|
15
15
|
clean_association_name = Resourceful::Model::Base.cleanup_name(association_name.to_s)
|
16
16
|
assoc_data = get_association_data(klass, clean_association_name)
|
17
|
-
assoc_klass = klass.ancestors.include?(Resourceful::Model::Base)
|
17
|
+
assoc_klass = if klass.ancestors.include?(Resourceful::Model::Base)
|
18
|
+
klass.get_namespaced_klass(assoc_data[:class_name])
|
19
|
+
else
|
20
|
+
if assoc_data[:class_name].kind_of?(::String)
|
21
|
+
assoc_data[:class_name].resourceful_constantize
|
22
|
+
else
|
23
|
+
assoc_data[:class_name]
|
24
|
+
end
|
25
|
+
end
|
18
26
|
fk_values = collection.inject([]) {|vals, item| vals << item.send(assoc_data[:foreign_key_method])}
|
19
27
|
fk_results = assoc_klass.send(assoc_data[:find_method_name], :all, {assoc_data[:foreign_key_name] => fk_values}, true)
|
20
28
|
collection.each do |item|
|
data/lib/resourceful/version.rb
CHANGED