rosa-build/app/models/project_to_repository.rb

35 lines
946 B
Ruby
Raw Normal View History

class ProjectToRepository < ActiveRecord::Base
AUTOSTART_OPTIONS = %w(auto_publish user_id enabled)
belongs_to :project
belongs_to :repository
2011-10-19 14:14:53 +01:00
2014-01-21 04:51:49 +00:00
delegate :path, to: :project
scope :autostart_enabled, -> { where("autostart_options -> 'enabled' = 'true'") }
after_destroy -> { project.destroy_project_from_repository(repository) }, unless: -> { Thread.current[:skip] }
2014-01-21 04:51:49 +00:00
validate :one_project_in_platform_repositories, on: :create
AUTOSTART_OPTIONS.each do |field|
store_accessor :autostart_options, field
end
2014-02-18 19:16:23 +00:00
def enabled?
['true', true].include?(enabled)
end
def auto_publish?
['true', true].include?(auto_publish)
end
protected
def one_project_in_platform_repositories
if Project.joins(repositories: :platform).where('platforms.id = ?', repository.platform_id).by_name(project.name).exists?
errors.add(:base, I18n.t('activerecord.errors.project_to_repository.project'))
end
end
end