Class: App

Inherits:
Object
  • Object
show all
Includes:
Comparable, Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_api_key!(key) ⇒ Object


69
70
71
# File 'app/models/app.rb', line 69

def self.find_by_api_key!(key)
  find_by(:api_key => key)
end

.find_by_id!(app_id) ⇒ Object

Mongoid Bug: find(id) on association proxies returns an Enumerator


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

def self.find_by_id!(app_id)
  find app_id
end

Instance Method Details

#<=>(other) ⇒ Object

Compare by number of unresolved errs, then problem counts.


164
165
166
167
168
# File 'app/models/app.rb', line 164

def <=>(other)
  (other.unresolved_count <=> unresolved_count).nonzero? ||
  (other.problem_count <=> problem_count).nonzero? ||
  name <=> other.name
end

#bitbucket_repo?Boolean

Returns:

  • (Boolean)

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

def bitbucket_repo?
  self.bitbucket_repo.present?
end

#bitbucket_urlObject


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

def bitbucket_url
  "https://bitbucket.org/#{bitbucket_repo}" if bitbucket_repo?
end

#bitbucket_url_to_file(file) ⇒ Object


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

def bitbucket_url_to_file(file)
  "#{bitbucket_url}/src/#{repo_branch}/#{file}"
end

#copy_attributes_from(app_id) ⇒ Object

Copy app attributes from another app.


140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/models/app.rb', line 140

def copy_attributes_from(app_id)
  if copy_app = App.where(:_id => app_id).first
    # Copy fields
    (copy_app.fields.keys - %w(_id name created_at updated_at)).each do |k|
      self.send("#{k}=", copy_app.send(k))
    end
    # Clone the embedded objects that can be changed via apps/edit (ignore errs & deploys, etc.)
    %w(watchers issue_tracker notification_service).each do |relation|
      if obj = copy_app.send(relation)
        self.send("#{relation}=", obj.is_a?(Array) ? obj.map(&:clone) : obj.clone)
      end
    end
  end
end

#email_at_noticesObject


170
171
172
# File 'app/models/app.rb', line 170

def email_at_notices
  Errbit::Config.per_app_email_at_notices ? super : Errbit::Config.email_at_notices
end

#emailable?Boolean

Returns:

  • (Boolean)

84
85
86
# File 'app/models/app.rb', line 84

def emailable?
  notify_on_errs? && notification_recipients.any?
end

#find_or_create_err!(attrs) ⇒ Object

Acceps a hash with the following attributes:

  • :error_class - the class of error (required to create a new Problem)

  • :environment - the environment the source app was running in (required to create a new Problem)

  • :fingerprint - a unique value identifying the notice


57
58
59
60
61
62
# File 'app/models/app.rb', line 57

def find_or_create_err!(attrs)
  Err.where(
    :fingerprint => attrs[:fingerprint]
  ).first ||
    problems.create!(attrs.slice(:error_class, :environment)).errs.create!(attrs.slice(:fingerprint, :problem_id))
end

#github_repo?Boolean

Returns:

  • (Boolean)

97
98
99
# File 'app/models/app.rb', line 97

def github_repo?
  self.github_repo.present?
end

#github_urlObject


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

def github_url
  "#{Errbit::Config.github_url}/#{github_repo}" if github_repo?
end

#github_url_to_file(file) ⇒ Object


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

def github_url_to_file(file)
  "#{github_url}/blob/#{repo_branch}/#{file}"
end

#issue_tracker_configured?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'app/models/app.rb', line 122

def issue_tracker_configured?
  !!issue_tracker && !!(issue_tracker.configured?)
end

#last_deploy_atObject


73
74
75
# File 'app/models/app.rb', line 73

def last_deploy_at
  (last_deploy = deploys.last) && last_deploy.created_at
end

#notification_recipientsObject


131
132
133
134
135
136
137
# File 'app/models/app.rb', line 131

def notification_recipients
  if notify_all_users
    (User.all.map(&:email).reject(&:blank?) + watchers.map(&:address)).uniq
  else
    watchers.map(&:address)
  end
end

#notification_service_configured?Boolean

Returns:

  • (Boolean)

126
127
128
# File 'app/models/app.rb', line 126

def notification_service_configured?
  !!(notification_service.class < NotificationService && notification_service.configured?)
end

#notify_on_deploysObject Also known as: notify_on_deploys?


88
89
90
# File 'app/models/app.rb', line 88

def notify_on_deploys
  !(super == false)
end

#notify_on_errsObject Also known as: notify_on_errs?

Legacy apps don't have notify_on_errs and notify_on_deploys params


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

def notify_on_errs
  !(super == false)
end

#problem_countObject


159
160
161
# File 'app/models/app.rb', line 159

def problem_count
  @problem_count ||= problems.count
end

#regenerate_api_key!Object


174
175
176
# File 'app/models/app.rb', line 174

def regenerate_api_key!
  update_attribute(:api_key, SecureRandom.hex)
end

#repo_branchObject


93
94
95
# File 'app/models/app.rb', line 93

def repo_branch
  self.repository_branch.present? ? self.repository_branch : 'master'
end

#unresolved_countObject


155
156
157
# File 'app/models/app.rb', line 155

def unresolved_count
  @unresolved_count ||= problems.unresolved.count
end