module OsoCloud # @!visibility private module Helpers # @!visibility private def self.extract_value(x) return OsoCloud::Core::Value.new(type: "String", id: x) if x.is_a? String return nil if x.nil? type = (x.type.nil? ? nil : x.type.to_s) id = (x.id.nil? ? nil : x.id.to_s) OsoCloud::Core::Value.new(type: type, id: id) end # @!visibility private def self.extract_arg_query(x) self.extract_value(x) end # @!visibility private def self.param_to_fact(predicate, args) OsoCloud::Core::Fact.new(predicate: predicate, args: args.map { |a| self.extract_value(a) }) end # @!visibility private def self.params_to_facts(facts) facts.map { |predicate, *args| self.param_to_fact(predicate, args) } end def self.from_value(value) if value.id.nil? if value.type.nil? nil else { type: value.type } end else if value.type == "String" value.id else { id: value.id, type: value.type } end end end # @!visibility private def self.to_hash(o) return o.map { |v| self.to_hash(v) } if o.is_a? Array return o if o.instance_variables.empty? hash = {} o.instance_variables.each { |var| v = var.to_s.delete("@") value = o.send(v) hash[v] = self.to_hash(value) } hash end end end