Class: Puppi::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/puppi/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/puppi/loader.rb', line 4

def data
  @data
end

#datafilesObject (readonly)

Returns the value of attribute datafiles.



4
5
6
# File 'lib/puppi/loader.rb', line 4

def datafiles
  @datafiles
end

#helpersObject (readonly)

Returns the value of attribute helpers.



4
5
6
# File 'lib/puppi/loader.rb', line 4

def helpers
  @helpers
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



4
5
6
# File 'lib/puppi/loader.rb', line 4

def notifications
  @notifications
end

Instance Method Details

#load_all(file_type, puppi_module = nil, notification_method = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppi/loader.rb', line 6

def load_all (file_type, puppi_module = nil, notification_method = nil)  
  if file_type == 'data' and puppi_module != nil
    file_glob = '*_'+puppi_module
  elsif file_type == 'notifications' and notification_method != nil
    file_glob = notification_method + '_*'
  else
    file_glob = '*'
  end
  
  @all = Array.new
  Dir.glob(Puppi::puppidir+'/'+file_type+'/'+file_glob+'.yml').each do |file|
    @all << File.basename(file, '.yml')
  end
  @all
end

#load_datafile(file) ⇒ Object



34
35
36
37
38
# File 'lib/puppi/loader.rb', line 34

def load_datafile file
  @datafiles = load_all('data') unless not @datafiles.nil?
  raise 'Invalid Datafile' unless @datafiles.include? file
  Puppi::Files::Datafile.new(YAML.load(File.read(Puppi::puppidir+"/data/"+file+".yml")))
end

#load_helperfile(helper, action) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppi/loader.rb', line 22

def load_helperfile helper, action
  @helpers = load_all('helpers') unless not @helpers.nil?
  raise 'Invalid Helper' unless @helpers.include? helper
  @helper_content = YAML.load(File.read(Puppi::puppidir+"/helpers/"+helper+".yml"))
  @helper_commands = Array.new
  return nil unless not @helper_content[action.to_sym].nil?
  @helper_content[action.to_sym].each do |command|
    @helper_commands << Puppi::Files::Helper.new(command)
  end
  @helper_commands
end

#load_notification(file) ⇒ Object



40
41
42
43
44
# File 'lib/puppi/loader.rb', line 40

def load_notification file
  @notifications = load_all('notifications') unless not @notifications.nil?
  raise 'Invalid Notification' unless @notifications.include? file
  Puppi::Files::Notification.new(YAML.load(File.read(Puppi::puppidir+"/notifications/"+file+".yml")))
end