Class: Blaml::MetaArray

Inherits:
MetaNode show all
Defined in:
lib/blaml/meta.rb

Overview

Wraps Array instances with metadata.

Instance Attribute Summary

Attributes inherited from MetaNode

#value

Instance Method Summary collapse

Methods inherited from MetaNode

#==, #initialize, #method_missing, #to_yaml

Constructor Details

This class inherits a constructor from Blaml::MetaNode

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Blaml::MetaNode

Instance Method Details

#metaObject

Returns the child metadata with the most recent change.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/blaml/meta.rb', line 85

def meta
  meta     = nil
  path_key = nil

  @value.each_with_index do |val, i|
    next unless val.respond_to? :meta

    meta = val.meta.dup and path_key = i if !meta ||
      meta && val.meta && val.meta[:updated_at] > meta[:updated_at]
  end

  (meta[:path] ||= []).unshift path_key if meta && path_key

  meta
end

#to_valueObject

Strips MetaNode wrapper from the value and calls to_value on all array elements.



106
107
108
# File 'lib/blaml/meta.rb', line 106

def to_value
  @value.map{|v| v.respond_to?(:to_value) ? v.to_value : v }
end