Parsistence 0.2.0 → 0.2.1
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.
- data/lib/Parsistence/Model.rb +13 -7
- data/lib/Parsistence/version.rb +1 -1
- metadata +1 -1
data/lib/Parsistence/Model.rb
CHANGED
@@ -27,6 +27,9 @@ module Parsistence
|
|
27
27
|
method = method.to_sym
|
28
28
|
if fields.include?(method)
|
29
29
|
return getField(method)
|
30
|
+
elsif fields.map { |f| "#{f}=".include?(method)}
|
31
|
+
method = method.split("=")[0]
|
32
|
+
return setField(method, args.first)
|
30
33
|
elsif relations.include?(method)
|
31
34
|
return getRelation(method)
|
32
35
|
elsif relations.map {|r| "#{r}=".include?(method)}
|
@@ -65,14 +68,14 @@ module Parsistence
|
|
65
68
|
raise "Parsistence Exception: Invalid relation name #{field} for object #{self.class.to_s}"
|
66
69
|
end
|
67
70
|
|
68
|
-
def setRelation(
|
71
|
+
def setRelation(field, value)
|
69
72
|
value = value.PFObject if value.respond_to? :PFObject # unwrap object
|
70
|
-
# return setRelation(
|
73
|
+
# return setRelation(field, value) # This SHOULD work
|
71
74
|
|
72
|
-
relation = @PFObject.relationforKey(
|
75
|
+
relation = @PFObject.relationforKey(field)
|
73
76
|
|
74
|
-
return relation.addObject(value) if relations.include?
|
75
|
-
raise "Parsistence Exception: Invalid relation name #{
|
77
|
+
return relation.addObject(value) if relations.include? field.to_sym
|
78
|
+
raise "Parsistence Exception: Invalid relation name #{field} for object #{self.class.to_s}" unless relations.include? relation.to_sym
|
76
79
|
end
|
77
80
|
|
78
81
|
def attributes
|
@@ -85,8 +88,11 @@ module Parsistence
|
|
85
88
|
|
86
89
|
def attributes=(hashValue)
|
87
90
|
hashValue.each do |k, v|
|
88
|
-
|
89
|
-
|
91
|
+
if self.respond_to? "#{k}="
|
92
|
+
self.send("#{k}=", v)
|
93
|
+
else
|
94
|
+
setField(k, v) unless k.nil?
|
95
|
+
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
data/lib/Parsistence/version.rb
CHANGED