Class: CartridgeCache

Inherits:
Object
  • Object
show all
Defined in:
app/models/cartridge_cache.rb

Constant Summary collapse

FRAMEWORK_CART_NAMES =

RHEL6 cartridges

[#RHEL6 cartridges
 "python-2.6", "jenkins-1.4", "ruby-1.8", "ruby-1.9",
 "diy-0.1", "php-5.3", "jbossas-7", "jbosseap-6.0", "jbossews-1.0",
 "jbossews-2.0", "perl-5.10", "nodejs-0.6", "zend-5.6",
]

Class Method Summary collapse

Class Method Details

.cartridge_names(cart_type = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/cartridge_cache.rb', line 31

def self.cartridge_names(cart_type=nil)
  cart_names = cartridges.map{|c| c.name}

  if cart_type == 'standalone'
    return cart_names & FRAMEWORK_CART_NAMES
  elsif cart_type == 'embedded'
    return (cart_names - FRAMEWORK_CART_NAMES)
  else
    return cart_names
  end
end

.cartridgesObject



22
23
24
# File 'app/models/cartridge_cache.rb', line 22

def self.cartridges
  get_cached("all_cartridges", :expires_in => 1.day) {OpenShift::ApplicationContainerProxy.find_one().get_available_cartridges}
end

.find_cartridge(capability) ⇒ Object



43
44
45
46
47
48
49
50
# File 'app/models/cartridge_cache.rb', line 43

def self.find_cartridge(capability)
  carts = self.cartridges
  carts.each do |cart|
    return cart if cart.all_capabilities.include?(capability)
    return cart if cart.name == capability
  end
  return nil
end

.get_cached(key, opts = {}) ⇒ Object



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

def self.get_cached(key, opts={})
  unless Rails.configuration.action_controller.perform_caching
    if block_given?
      return yield
    end
  end

  val = Rails.cache.read(key)
  unless val
    if block_given?
      val = yield
      if val
        Rails.cache.write(key, val, opts)
      end
    end
  end

  return val
end