Class: Cfruby::Cfp_ClassList

Inherits:
Hash
  • Object
show all
Includes:
Cfp_ClassAccessor
Defined in:
lib/libcfenjin/cfp_classes.rb

Overview

List of Cfruby classes

Instance Method Summary collapse

Methods included from Cfp_ClassAccessor

#assign, #cfgroup, #dump_classlist, #init_classlist, #isa

Constructor Details

#initialize(defines, undefines) ⇒ Cfp_ClassList

Class list with hostname added automatically



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/libcfenjin/cfp_classes.rb', line 60

def initialize defines, undefines
    @undefines = undefines
	os = Cfruby::OS.get_os()
	@hostname = os.hostname
	# init_classlist --- don't do this, it is a circular        
	add('any',@hostname)
	add(os['name'].downcase,@hostname) if os['name']
	add(os['distribution'].downcase,@hostname) if os['distribution']
	usermanager = os.get_user_manager()
	add(usermanager.get_name(Process.euid()),@hostname)
	add(usermanager.get_group(Process.egid()),@hostname)
    # ---- add classes passed through command line
    defines.each do | d |
      add(d,@hostname)
    end
end

Instance Method Details

#add(clname, name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/libcfenjin/cfp_classes.rb', line 88

def add clname, name
	if clname == nil
		logger.notify(VERBOSE_CRITICAL,"Trying to add nil class with #{name}")
	end
    if !@undefines.include? clname
      cl = findclass(clname)
      cl = addclass(clname) if !cl
      cl.add(name)    
    end
end

#addclass(name) ⇒ Object



81
82
83
84
85
86
# File 'lib/libcfenjin/cfp_classes.rb', line 81

def addclass name
    if !@undefines.include? name
      cl = Cfp_Class.new(name)
      self[name] = cl
    end
end

#dump(logger = nil) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/libcfenjin/cfp_classes.rb', line 123

def dump logger=nil
	classes = []
	each do | item, value |
	  # p [ item,value ]
		classes.push(item) if isa? item
	end
	# p classes
	msg = 'Computer "'+@hostname+'" belongs to classes "'+classes.sort.join(', ')+'"'
	if logger
		logger.notify(VERBOSE_CRITICAL,msg)
	else
		print msg
	end
end

#expand(clname) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/libcfenjin/cfp_classes.rb', line 99

def expand clname
	a = []
	if self[clname]
		self[clname].each do | item, value |
			if self[item]
				# ---- FIXME: recursion - no check for circular references
				item = expand item
			end
			a.push item
		end
	end
	a.flatten
end

#findclass(name) ⇒ Object



77
78
79
# File 'lib/libcfenjin/cfp_classes.rb', line 77

def findclass name
	self[name]
end

#isa?(clname) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
121
# File 'lib/libcfenjin/cfp_classes.rb', line 113

def isa? clname
	# ---- Quick check where hostname is actually checked against
	return true if clname == @hostname
	# ---- Check whether the hostname of the machine is in the (expanded) list
	# print "Expanding #{clname} to "
	a = expand clname
	# p a
	a.include? @hostname
end