class DTK::Puppet::ParseStructure

Constants

AttrTypes
TPS

Public Class Methods

create(ast_obj, opts = {}) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 91
def self.create(ast_obj, opts = {})
  new(ast_obj, opts)
end
new(ast_item = nil, _opts = {}) click to toggle source
Calls superclass method
# File lib/dtk_puppet/parse_structure.rb, line 20
def initialize(ast_item = nil, _opts = {})
  return super() if ast_item.nil?
end

Public Instance Methods

calculate_action(type, type_name) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 79
def calculate_action(type, type_name)
  { 'create' => { "puppet_#{type}" => type_name } }
end
config_agent_type() click to toggle source

used in generate_meta

# File lib/dtk_puppet/parse_structure.rb, line 25
def config_agent_type
  :puppet
end
process_attributes(attributes) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 53
def process_attributes(attributes)
  processed_atttibutes = {}
  attributes.each do |attr|
    attr_name = attr['name']
    attr_type = attr['type']
    attr_hash = { attr_name => { 'type' => attr_type } }

    if required = attr['required']
      attr_hash[attr_name].merge!('required' => required)
    end

    processed_atttibutes.merge!(attr_hash)
  end

  processed_atttibutes
end
remove_quotations(str) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 70
def remove_quotations(str)
  if str.starts_with?('"')
    str = str.slice(1..-1)
  end
  if str.ends_with?('"')
    str = str.slice(0..-2)
  end
end
render_hash_form(module_name) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 29
def render_hash_form(module_name)
  rendered_hash = {}

  self[:children].each do |child|
    name       = child['name'].gsub("#{module_name}::", '')
    type       = child['type']
    type_name  = child['name']
    attributes = nil

    attributes = process_attributes(child['attributes']) if child['attributes']
    actions    = calculate_action(type, type_name)

    child_name = name.gsub('::', '_')
    child_hash = { child_name => {} }

    child_hash[child_name].merge!('attributes' => attributes) if attributes
    child_hash[child_name].merge!('actions' => actions)

    rendered_hash.merge!(child_hash)
  end

  rendered_hash
end
string_to_boolean(string) click to toggle source
# File lib/dtk_puppet/parse_structure.rb, line 83
def string_to_boolean(string)
  if string.to_s == 'true'
    true
  elsif string.to_s == 'false'
    false
  end
end