lib/spark_api/models/base.rb in spark_api-1.3.24 vs lib/spark_api/models/base.rb in spark_api-1.3.25
- old
+ new
@@ -127,17 +127,40 @@
def to_param
attributes['Id']
end
+ def to_partial_path
+ "#{underscore(resource_pluralized)}/#{underscore(self.class.name.split('::').last)}"
+ end
+
+ # can be overridden
+ def resource_pluralized
+ resource = self.class.name.split('::').last
+ unless resource.split('').last == "s"
+ resource = resource + "s"
+ end
+ resource
+ end
+
protected
def write_attribute(attribute, value)
attribute = attribute.to_s
unless attributes[attribute] == value
attribute_will_change!(attribute)
attributes[attribute] = value
end
+ end
+
+ private
+
+ def underscore(string)
+ string.to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
end
end
end
end