Class: Burp::Menu

Inherits:
Group
  • Object
show all
Defined in:
app/models/burp/menu.rb

Instance Attribute Summary

Attributes inherited from Group

#children, #id, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Group

#<=>, #all_children, bootstrap_nav, #current?, #current_class, #eql?, #first_link, from_hash, from_yaml, #hash, #links, #to_hash, #to_html, #to_menu, #to_yaml, #update_id

Constructor Details

#initialize(name, options = {}) ⇒ Menu

Returns a new instance of Menu.



4
5
6
7
8
# File 'app/models/burp/menu.rb', line 4

def initialize(name,options = {})
  raise "Name cant be blank" if name.blank?
  self.name = name
  super(name,options)
end

Class Method Details

.allObject



10
11
12
13
14
# File 'app/models/burp/menu.rb', line 10

def self.all
  Dir.glob(Burp.content_directory + "menus/*.yaml").map do |menu_path|
    Menu.find(menu_path.match(/\/(\w*?)\.yaml$/)[1])
  end
end

.countObject



16
17
18
# File 'app/models/burp/menu.rb', line 16

def self.count
  Dir.glob(Burp.content_directory + "menus/*.yaml").length
end

.find(name) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/models/burp/menu.rb', line 20

def self.find(name)
  menu = Menu.new(name)
  if(menu.load)
    menu
  else
    nil
  end
end

Instance Method Details

#loadObject



33
34
35
36
37
38
39
40
41
42
# File 'app/models/burp/menu.rb', line 33

def load
  if File.exist?(path)
    group = Group.from_yaml(File.read(path))
    self.children = group.children
    
    true
  else
    false
  end
end

#saveObject



44
45
46
47
48
49
50
51
52
# File 'app/models/burp/menu.rb', line 44

def save
 raise "Name cant be blank" if name.blank?

 File.open(path,'w') do |file|
   file.write(self.to_yaml)
 end

 Burp::Util.commit("Saved #{self.name}")
end

#to_paramObject



29
30
31
# File 'app/models/burp/menu.rb', line 29

def to_param
  name
end