Class Core::Controller
In: core/controller.rb
Parent: Object

Context is the provided implementation of the Controller interface.

Methods

Included Modules

Core::ControllerInterface

Public Class methods

=============================================== public methods

[Source]

    # File core/controller.rb, line 34
34:     def initialize(params)
35:       
36:       # init the View
37:       raise ArgumentError.new('You need to define a :view') unless params.key?(:view)
38:       @view = params.fetch(:view)
39:       @view.setup(self)
40:       
41:       # init the Service
42:       @service = Service.new
43:     end

Public Instance methods

TODO: no good

[Source]

     # File core/controller.rb, line 105
105:     def add_note(annotatable_type,annotatable_id,author,category,text)
106:       type = (annotatable_type == :host) ? 'Host' : 'Service'
107:       self.invoke('add', 'add', 'note', type, "#{annotatable_id}",author,category,text )
108:     end

[Source]

     # File core/controller.rb, line 109
109:     def edit_note(note_id,author,category,text)
110:       self.invoke('edit', 'edit', 'note', "#{note_id}",author,category,text )
111:     end

[Source]

    # File core/controller.rb, line 45
45:     def exec() 
46:       @view.run
47:     end

Given a note_id this method searches the model and returns the Note object associated with it.

[Source]

     # File core/controller.rb, line 115
115:     def find_note(note_id)
116:       note = nil
117:           
118:       @service.model.hosts.each do |host|
119:         host.notes.each do |n|
120:           next unless n.uid == note_id
121:           note = n
122:         end
123:         host.services.each do |srv|
124:           srv.notes.each do |n|
125:             next unless n.uid == note_id
126:             note = n
127:           end
128:         end
129:       end
130:       return note
131:     end

[Source]

    # File core/controller.rb, line 49
49:     def invoke(cmd,*args)
50:       # do input validation on cmd agains the list of available services
51:       begin
52:         output = @service.dispatch(cmd, *args)
53:       rescue Errno::ECONNREFUSED
54:         output = "Error while connecting. Is the server running?"
55:         $logger.error{$!.to_s}
56:       rescue Core::DradisQuitApp
57:         output = 'Closing dradis.'
58:         @view.teardown()
59:       rescue
60:         output = "[error] #{$!}"
61:         $logger.error {$@.join("\n\t")}
62:         #@base.textConsole.append "error]\t" + $!
63:         #@base.textConsole.append $!.backtrace.sort.join("\n\t")
64:         #@base.textConsole.append $@.join("\n\t")
65:       end
66:       return output
67:     end

[Source]

    # File core/controller.rb, line 73
73:     def model()
74:       @service.model()
75:     end

TODO: not sure if this is the best way for searching notes

[Source]

     # File core/controller.rb, line 78
 78:     def notes_for(annotatable_type, annotatable_id) 
 79:       notes = []
 80:       
 81:       case annotatable_type
 82:       when :host then
 83:         @controller.model.hosts.each do |host|
 84:           next unless host.id == annotatable_id
 85:           notes = host.notes
 86:           break
 87:         end
 88:       when :service then
 89:         found = false
 90:         @controller.model.hosts.each do |host|
 91:           host.services.each do |service|
 92:             next unless service.id = annotatable_id
 93:             notes = service.notes
 94:             found = true
 95:             break
 96:           end
 97:           break if found
 98:         end
 99:       end      
100:       
101:       notes
102:     end

[Source]

    # File core/controller.rb, line 69
69:     def parse_command(line)
70:       self.invoke(line.split.shift, *line.split)
71:     end

[Source]

     # File core/controller.rb, line 133
133:     def refresh_model()
134:       self.invoke('refresh', 'refresh', "#{self.model.revision}")
135:     end

[Validate]