Module: Console::ModelHelper

Included in:
ApplicationTypesController
Defined in:
app/helpers/console/model_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_scale_application_type(type, capabilities) ⇒ Object



68
69
70
# File 'app/helpers/console/model_helper.rb', line 68

def can_scale_application_type(type, capabilities)
  type.scalable? and capabilities.gears_free >= 2
end

#cannot_scale_title(type, capabilities) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'app/helpers/console/model_helper.rb', line 72

def cannot_scale_title(type, capabilities)
  unless can_scale_application_type(type, capabilities)
    if type.scalable?
      "You need at least two free gears to create a scaling application; you are currently using #{capabilities.consumed_gears} out of #{capabilities.max_gears}."
    else
      "This application shares resources and can't be scaled."
    end
  end
end

#cartridge_gear_group_count(group) ⇒ Object



34
35
36
37
# File 'app/helpers/console/model_helper.rb', line 34

def cartridge_gear_group_count(group)
  return 'None' if group.gears.empty?
  "#{group.gears.length} #{group.gear_profile.to_s.humanize.downcase}"
end

#common_tags_for(ary) ⇒ Object



103
104
105
# File 'app/helpers/console/model_helper.rb', line 103

def common_tags_for(ary)
  ary.length < 2 ? [] : ary.inject(nil){ |tags, a| tags ? (a.tags & tags) : a.tags } || []
end

#gear_group_count(gears) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/console/model_helper.rb', line 16

def gear_group_count(gears)
  types = gears.inject({}){ |h,g| h[g.gear_profile.to_s] ||= 0; h[g.gear_profile.to_s] += 1; h }
  return 'None' if types.empty?
  types.keys.sort.map do |k|
    "#{types[k]} #{k.humanize.downcase}"
  end.to_sentence
end

#gear_group_count_title(total_gears) ⇒ Object



39
40
41
# File 'app/helpers/console/model_helper.rb', line 39

def gear_group_count_title(total_gears)
  "OpenShift runs each cartridge inside one or more gears on a server and is allocated a fixed portion of CPU time and memory use."
end

#gear_group_state(states) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'app/helpers/console/model_helper.rb', line 6

def gear_group_state(states)
  css_class = if states.all? {|s| s == :started}
      'state_started'
    elsif states.none? {|s| s == :started}
      'state_stopped'
    end

  (:span, gear_group_states(states), :class => css_class)
end

#gear_group_states(states) ⇒ Object



2
3
4
5
# File 'app/helpers/console/model_helper.rb', line 2

def gear_group_states(states)
  return states[0].to_s.humanize if states.uniq.length == 1
  "#{states.count{ |s| s == :started }}/#{states.length} started"
end

#in_groups_by_tag(ary, tags) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/console/model_helper.rb', line 82

def in_groups_by_tag(ary, tags)
  groups = {}
  other = ary.reject do |t|
    tags.any? do |tag| 
      (groups[tag] ||= []) << t if t.tags.include?(tag)
    end
  end
  groups = tags.map do |tag| 
    types = groups[tag]
    if types
      if types.length < 2
        other.concat(types)
        nil
      else
        [tag, types]
      end
    end
  end.compact
  [groups, other]
end

#scale_from_options(obj, max, max_choices = 20) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/console/model_helper.rb', line 48

def scale_from_options(obj, max, max_choices=20)
  if range = scale_range(obj.supported_scales_from, obj.supported_scales_to, max, max_choices)
    {:as => :select, :collection => range, :include_blank => false}
  else
    {:as => :string}
  end
end

#scale_optionsObject



64
65
66
# File 'app/helpers/console/model_helper.rb', line 64

def scale_options
  [['No scaling',false],['Scale with web traffic',true]]
end

#scale_range(from, to, max, max_choices) ⇒ Object



43
44
45
46
47
# File 'app/helpers/console/model_helper.rb', line 43

def scale_range(from, to, max, max_choices)
  limit = to == -1 ? max : to
  return if limit > max_choices
  (from .. limit).map{ |i| [i.to_s, i] }
end

#scale_to_options(obj, max, max_choices = 20) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/helpers/console/model_helper.rb', line 55

def scale_to_options(obj, max, max_choices=20)
  if range = scale_range(obj.supported_scales_from, obj.supported_scales_to, max, max_choices)
    range << ['All available', -1] if obj.supported_scales_to == -1
    {:as => :select, :collection => range, :include_blank => false}
  else
    {:as => :string, :hint => 'Use -1 to scale to your current account limits'}
  end
end

#web_cartridge_scale_title(cartridge) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/helpers/console/model_helper.rb', line 24

def web_cartridge_scale_title(cartridge)
  if cartridge.current_scale == cartridge.scales_from
    'Your web cartridge is running on the minimum amount of gears and will scale up if needed'
  elsif cartridge.current_scale == cartridge.scales_to
    'Your web cartridge is running on the maximum amount of gears and cannot scale up any further'
  else
    'Your web cartridge is running multiple copies to handle increased web traffic'
  end
end