Class: Foreman::ImporterPuppetclass

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman/importer_puppetclass.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = { }) ⇒ ImporterPuppetclass


4
5
6
7
8
# File 'lib/foreman/importer_puppetclass.rb', line 4

def initialize opts = { }
  @name = opts["name"] || raise("must provide a puppet class name")
  @module     = opts["module"]
  @parameters = opts["params"] || { }
end

Instance Attribute Details

#moduleObject (readonly)

Returns the value of attribute module


2
3
4
# File 'lib/foreman/importer_puppetclass.rb', line 2

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name


2
3
4
# File 'lib/foreman/importer_puppetclass.rb', line 2

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters


2
3
4
# File 'lib/foreman/importer_puppetclass.rb', line 2

def parameters
  @parameters
end

Class Method Details

.suggest_key_type(value, default = nil, detect_json_or_yaml = false) ⇒ Object

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.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/foreman/importer_puppetclass.rb', line 25

def self.suggest_key_type value, default = nil, detect_json_or_yaml = false
  case value
  when String
    begin
      return "json" if JSON.load value
    rescue
      return "yaml" if YAML.load value
    end if detect_json_or_yaml
    "string"
  when TrueClass, FalseClass
    "boolean"
  when Integer
    "integer"
  when Float
    "real"
  when Array
    "array"
  when Hash
    "hash"
  else
    default
  end
end

Instance Method Details

#==(other) ⇒ Object

for now, equality is based on class name, and not on parameters


15
16
17
# File 'lib/foreman/importer_puppetclass.rb', line 15

def ==(other)
  name == other.name && self.module == other.module
end

#parameters?Boolean


19
20
21
# File 'lib/foreman/importer_puppetclass.rb', line 19

def parameters?
  @parameters.empty?
end

#to_sObject


10
11
12
# File 'lib/foreman/importer_puppetclass.rb', line 10

def to_s
  name and self.module ? "#{self.module}::#{name}" : name
end