class TtlAuto::Record
Attributes
body[R]
defines[R]
Public Class Methods
new(record)
click to toggle source
# File lib/ttlauto/record.rb, line 6 def initialize record @body = record @defines = record['define'] end
Public Instance Methods
description()
click to toggle source
# File lib/ttlauto/record.rb, line 11 def description parse_description @body['description'] end
keyfile?()
click to toggle source
# File lib/ttlauto/record.rb, line 24 def keyfile? @body['define'].any?{|d| d['publickey']} end
replace_macro(templates)
click to toggle source
# File lib/ttlauto/record.rb, line 15 def replace_macro templates templates.each do |tmpl| if tmpl['type'] == "command_macro" target = {"call_templates" => tmpl['name']} @body = replace_iter @body, target, tmpl["commands"] end end end
set_keyfile_path()
click to toggle source
# File lib/ttlauto/record.rb, line 28 def set_keyfile_path @body['define'].each do |d| if d['publickey'] pem = "#{PEM}/#{File.basename(d['publickey'])}" d['publickey'] = depth.times.reduce(pem){|n| File.join('../', n)} log_info d['publickey'] end end end
Private Instance Methods
depth()
click to toggle source
# File lib/ttlauto/record.rb, line 40 def depth @body['category'].count('/') + 1 end
parse_description(obj)
click to toggle source
# File lib/ttlauto/record.rb, line 64 def parse_description obj if obj.class == Array obj.join("\n; ") else obj end end
replace_iter(obj, target, replace)
click to toggle source
# File lib/ttlauto/record.rb, line 44 def replace_iter obj, target, replace if obj.class == Array if obj.include?( target ) return obj.map{|el| if el == target replace else replace_iter el, target, replace end }.flatten else return obj.map{|el| replace_iter el, target, replace } end elsif obj.class == Hash return Hash[obj.map{|k, v| [k, replace_iter(v , target, replace)] }] else return obj end end