lib/yaks/mapper.rb in yaks-0.7.1 vs lib/yaks/mapper.rb in yaks-0.7.2

- old
+ new

@@ -53,9 +53,36 @@ def load_attribute(name) respond_to?(name) ? public_send(name) : object.public_send(name) end alias load_association load_attribute + def expand_uri(uri, expand) + case uri + when nil + return + when Symbol + return load_attribute(uri) + when Method, Proc + return Resolve(uri, self) + end + + template = URITemplate.new(uri) + expand_vars = case expand + when true + template.variables + when false + [] + else + expand + end + + mapping = expand_vars.each_with_object({}) do |name, hsh| + hsh[name] = load_attribute(name) + end + + template.expand_partial(mapping).to_s + end + private def map_attributes(resource) attributes.inject(resource) do |res, attribute| attribute.add_to_resource(res, self, context)