Sha256: 293ec43b42b18134ad564998ef135d9b523c432f92024e11d9e7cdf3f9d3822d
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oso-cloud-1.0.1 | lib/oso/helpers.rb |
oso-cloud-1.0.0 | lib/oso/helpers.rb |