Sha256: 099c07cbd862480e4a2766a164eac5b59613649e9ad5b217a11bd7b445885c1c

Contents?: true

Size: 751 Bytes

Versions: 23

Compression:

Stored size: 751 Bytes

Contents

module ModelWrapper
  # For cretain values, we wrap them to make the behave as a
  # model.
  def wrap_value(value, lookup)
    if value.cur.is_a?(Array)
      value = new_array_model(value, @options.merge(parent: self, path: path + lookup))
    elsif value.cur.is_a?(Hash)
      value = new_model(value, @options.merge(parent: self, path: path + lookup))
    end

    return value
  end

  def wrap_values(values, lookup=[])
    if values.cur.is_a?(Array)
      # Coming from an array
      values = values.map {|v| wrap_value(v,lookup + [:[]]) }
    elsif values.cur.is_a?(Hash)
      pairs = values.map do |k,v|
        path = lookup + [k]

        [k, wrap_value(v,path)]
      end

      values = Hash[pairs]
    end

    return values
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
volt-0.7.23 lib/volt/models/model_wrapper.rb
volt-0.7.22 lib/volt/models/model_wrapper.rb
volt-0.7.21 lib/volt/models/model_wrapper.rb
volt-0.7.20 lib/volt/models/model_wrapper.rb
volt-0.7.19 lib/volt/models/model_wrapper.rb
volt-0.7.18 lib/volt/models/model_wrapper.rb
volt-0.7.17 lib/volt/models/model_wrapper.rb
volt-0.7.16 lib/volt/models/model_wrapper.rb
volt-0.7.15 lib/volt/models/model_wrapper.rb
volt-0.7.14 lib/volt/models/model_wrapper.rb
volt-0.7.13 lib/volt/models/model_wrapper.rb
volt-0.7.12 lib/volt/models/model_wrapper.rb
volt-0.7.10 lib/volt/models/model_wrapper.rb
volt-0.7.9 lib/volt/models/model_wrapper.rb
volt-0.7.8 lib/volt/models/model_wrapper.rb
volt-0.7.7 lib/volt/models/model_wrapper.rb
volt-0.7.6 lib/volt/models/model_wrapper.rb
volt-0.7.5 lib/volt/models/model_wrapper.rb
volt-0.7.4 lib/volt/models/model_wrapper.rb
volt-0.7.3 lib/volt/models/model_wrapper.rb