Sha256: 6061e5d218dd5716cf9e4dc5c56a3862038967c94cde9ff8f161cc14f6972695
Contents?: true
Size: 873 Bytes
Versions: 1
Compression:
Stored size: 873 Bytes
Contents
module Volt module ModelWrapper # For cretain values, we wrap them to make the behave as a # model. def wrap_value(value, lookup) if value.is_a?(Array) new_array_model(value, @options.merge(parent: self, path: path + lookup)) elsif value.is_a?(Hash) new_model(value, @options.merge(parent: self, path: path + lookup)) else value end end def wrap_values(values, lookup=[]) if values.is_a?(Array) # Coming from an array values.map { |v| wrap_value(v, lookup + [:[]]) } elsif values.is_a?(Hash) pairs = values.map do |k, v| # TODO: We should be able to move wrapping into the method_missing on model path = lookup + [k.to_sym] [k, wrap_value(v, path)] end Hash[pairs] else values end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
volt-0.8.15 | lib/volt/models/model_wrapper.rb |