Module: Pal::ObjectHelpers

Included in:
Pal::Operation::Actions, Pal::Operation::Exporter, Request::Metadata, Request::Runbook
Defined in:
lib/pal/common/object_helpers.rb

Overview

Object helper module

Instance Method Summary collapse

Instance Method Details

#attributes=(hash) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pal/common/object_helpers.rb', line 8

def attributes=(hash)
  hash.each do |key, value|
    send("#{key}=", value)
  rescue NoMethodError
    Pal.logger.warn("Error deserializing object: No property for #{key}")
  end
end

#from_hash(hash) ⇒ Object



22
23
24
25
# File 'lib/pal/common/object_helpers.rb', line 22

def from_hash(hash)
  self.attributes = hash
  self
end

#from_json(json) ⇒ Object



16
17
18
19
20
# File 'lib/pal/common/object_helpers.rb', line 16

def from_json(json)
  return from_hash(json) if json.is_a?(Hash) # Just a guard in case serialisation is done

  from_hash(JSON.parse(json))
end