Project

General

Profile

Download (1.16 KB) Statistics
| Branch: | Tag: | Revision:
f8d94608 Amos Benari
class Foreman::ImporterPuppetclass
attr_reader :name, :module, :parameters

5f029ed6 Daniel Lobato
def initialize(opts = { })
f8d94608 Amos Benari
@name = opts["name"] || raise("must provide a puppet class name")
@module = opts["module"]
@parameters = opts["params"] || { }
end

def to_s
da9865b8 Michael Moll
(name && self.module) ? "#{self.module}::#{name}" : name
f8d94608 Amos Benari
end

# for now, equality is based on class name, and not on parameters
def ==(other)
name == other.name && self.module == other.module
end

def parameters?
@parameters.empty?
end

# Auto-detects the best validator type for the given (correctly typed) value.
# JSON and YAML are better undetected, to prevent the simplest strings to match.
5f029ed6 Daniel Lobato
def self.suggest_key_type(value, default = nil, detect_json_or_yaml = false)
f8d94608 Amos Benari
case value
when String
d7c67746 Michael Moll
if detect_json_or_yaml
begin
return "json" if JSON.load value
rescue
return "yaml" if YAML.load value
end
end
f8d94608 Amos Benari
"string"
when TrueClass, FalseClass
"boolean"
when Integer
"integer"
when Float
"real"
when Array
"array"
when Hash
"hash"
else
default
end
end
f4459c11 David Davis
end