Class: CartridgeTypesController

Inherits:
ConsoleController show all
Defined in:
app/controllers/cartridge_types_controller.rb

Instance Method Summary collapse

Methods inherited from ConsoleController

#active_tab

Methods included from SshkeyAware

#sshkey_uploaded?

Methods included from DomainAware

#domain_is_missing, #user_default_domain

Methods included from CapabilityAware

#user_capabilities

Instance Method Details

#conflicts?(cart_type) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/cartridge_types_controller.rb', line 31

def conflicts?(cart_type)
  t = cart_type

  return false if @installed.nil? || t.conflicts.empty?

  # if this cart can conflict and a conflicting cart is installed
  # add this cart to the conflicted list
  @installed.each { |c| return true if t.conflicts.include? c.name }
  return false
end

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/cartridge_types_controller.rb', line 3

def index
  user_default_domain

  @application = @domain.find_application params[:application_id]
  installed_carts = @application.cartridges

  types = CartridgeType.cached.embedded

  @blocked = []

  @installed, types = types.partition{ |t| installed_carts.any?{ |c| c.name == t.name } }
  @blacklist, types = types.partition{ |t| t.tags.include?(:blacklist) }

  @conflicts, types = types.partition{ |t| conflicts? t }
  @requires, types  = types.partition{ |t| requires? t }

  @installed.sort!; @conflicts.sort!; @requires.sort!
  @carts = types.sort!
end

#requires?(cart_type) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/cartridge_types_controller.rb', line 42

def requires?(cart_type)
  t = cart_type

  return true if @installed.nil? && !t.requires.empty?
  return false if t.requires.empty?

  # if this cart has requirements and the required cart is not
  # installed add this cart to the requires list
  @installed.each { |c| return false if t.requires.include? c.name }
  return true
end

#showObject



23
24
25
26
27
28
29
# File 'app/controllers/cartridge_types_controller.rb', line 23

def show
  user_default_domain
  @application = @domain.find_application params[:application_id]

  @cartridge_type = CartridgeType.cached.find params[:id]
  @cartridge = Cartridge.new :as => current_user
end