Module: PuppetX::Puppetlabs::Migration::ModelObject Abstract
- Defined in:
- lib/puppet_x/puppetlabs/migration/model_object.rb
Overview
This module is abstract.
The super class of all elements in the Overview and CatalogDelta models
Instance Method Summary collapse
- #initialize_from_hash(hash) ⇒ Object
-
#to_hash ⇒ Hash<Symbol,Object>
Creates a hash from the persistent instance variables of this object.
Instance Method Details
#initialize_from_hash(hash) ⇒ Object
28 29 30 |
# File 'lib/puppet_x/puppetlabs/migration/model_object.rb', line 28 def initialize_from_hash(hash) hash.each_pair { |k, v| instance_variable_set( :"@#{k}", v)} end |
#to_hash ⇒ Hash<Symbol,Object>
Creates a hash from the persistent instance variables of this object. The keys will be symbols corresponding to the attribute names (without leading ‘@’). The process of creating a hash is recursive in the sens that all ModelObject instances found by traversing the values of the instance variables will be converted too.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/puppet_x/puppetlabs/migration/model_object.rb', line 17 def to_hash hash = {} instance_variables.each do |iv| iv_name = iv.to_s next if iv_name.start_with?(TRANSIENT_PREFIX) val = hashify(instance_variable_get(iv)) hash[:"#{iv_name[1..-1]}"] = val unless val.nil? end hash end |