Class: Application

Inherits:
RestApi::Base show all
Includes:
AsyncAware
Defined in:
app/models/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AsyncAware

#async, #join, #join!

Methods inherited from RestApi::Base

alias_attribute, aliased_attributes, allow_anonymous?, #as, #as=, #assign_attributes, attr_alters, #attributes=, calculated_attributes, #clone, configuration=, connection, custom_id, delete, #dup, #duplicate_errors, element_path, exception_for_code, find, find_one, get, #get, #has_exit_code?, headers, #initialize, #load, #load_remote_errors, on_exit_code, #raise_on_invalid, remote_errors_for, #remote_results, #save!, #save_with_change_tracking, shared_connection, singleton?, #to_json, translate_api_error, use_patch_on_update?, #valid?

Methods included from ActiveResource::Associations

#belongs_to, #has_many, #has_one

Constructor Details

This class inherits a constructor from RestApi::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RestApi::Base

Class Method Details

.rescue_parent_missing(e, options = nil) ⇒ Object



143
144
145
146
# File 'app/models/application.rb', line 143

def rescue_parent_missing(e, options=nil)
  parent = RestApi::ResourceNotFound.new(Domain.model_name, (options[:params][:domain_id] rescue nil), e.response)
  raise parent if parent.domain_missing?
end

Instance Method Details

#builds?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/application.rb', line 116

def builds?
  building_with.present?
end

#cartridge_gear_groupsObject



66
67
68
# File 'app/models/application.rb', line 66

def cartridge_gear_groups
  @cartridge_gear_groups ||= GearGroup.infer(cartridges, self)
end

#cartridge_namesObject



55
56
57
# File 'app/models/application.rb', line 55

def cartridge_names
  persisted? ? cartridges.map(&:name) : Array(attributes[:cartridges])
end

#cartridgesObject



40
41
42
# File 'app/models/application.rb', line 40

def cartridges
  persisted? ? (@cartridges ||= Cartridge.find(:all, child_options)) : []
end

#cartridges=(arr) ⇒ Object Also known as: cartridge_names=



43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/application.rb', line 43

def cartridges=(arr)
  attributes[:cartridges] = Array(arr).map do |a|
    if a.is_a?(String)
      a
    elsif a.respond_to?(:[])
      a[:name] || a['name']
    else
      a.name
    end
  end
end

#destroy_build_cartridgeObject

FIXME it is assumed that eventually this will be server functionality



121
122
123
124
125
126
127
128
# File 'app/models/application.rb', line 121

def destroy_build_cartridge
  return true if !builds?
  cart = Cartridge.new({:application => self, :as => as, :name => building_with}, true)
  cart.destroy
rescue ActiveResource::ConnectionError => e
  raise unless set_remote_errors(e, true)
  #end.tap{ |success| cart.errors.full_messages.each{ |m| errors.add(:base, m) } unless success }
end

#embeddedObject



104
105
106
# File 'app/models/application.rb', line 104

def embedded
  @attributes[:embedded]
end

#find_cartridge(name) ⇒ Object



36
37
38
# File 'app/models/application.rb', line 36

def find_cartridge(name)
  Cartridge.find name, child_options
end

#framework_nameObject



100
101
102
# File 'app/models/application.rb', line 100

def framework_name
  @framework_name ||= CartridgeType.cached.find(framework, :as => as).display_name rescue framework
end

#gear_groupsObject



63
64
65
# File 'app/models/application.rb', line 63

def gear_groups
  @gear_groups ||= GearGroup.find(:all, child_options)
end

#gear_groups_with_stateObject



70
71
72
73
74
75
76
77
# File 'app/models/application.rb', line 70

def gear_groups_with_state
  async{ @_gear_groups = cartridge_gear_groups }
  async{ @_gear_groups_with_state = gear_groups }
  join!(30)

  @_gear_groups.each{ |g| g.merge_gears(@_gear_groups_with_state) }
  @_gear_groups
end

#gearsObject



60
61
62
# File 'app/models/application.rb', line 60

def gears
  Gear.find :all, child_options
end

#idObject

FIXME provided as legacy support for accessing .name via .id



21
22
23
# File 'app/models/application.rb', line 21

def id #FIXME provided as legacy support for accessing .name via .id
  name
end

#reloadObject



130
131
132
133
134
# File 'app/models/application.rb', line 130

def reload
  @gear_groups = nil
  @cartridge_gear_groups = nil
  super
end

#scale_status_urlObject



112
113
114
# File 'app/models/application.rb', line 112

def scale_status_url
  "#{web_url}haproxy-status/"
end

#scales?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/application.rb', line 108

def scales?
  scale
end

#ssh_stringObject

Helper to return the segment that would be provided for command line calls



93
94
95
96
97
98
# File 'app/models/application.rb', line 93

def ssh_string
  uri = ssh_url
  user = "#{uri.userinfo}@" if uri.userinfo
  port = ":#{uri.port}" if uri.port
  [user,uri.host,port].join
end

#ssh_urlObject

FIXME would prefer this come from REST API



84
85
86
87
88
89
90
# File 'app/models/application.rb', line 84

def ssh_url
  uri = URI.parse(git_url)
  uri.scheme = 'ssh'
  uri.path = ''
  uri.fragment = nil
  uri
end

#web_urlObject



79
80
81
# File 'app/models/application.rb', line 79

def web_url
  app_url
end