Project

General

Profile

Download (1.05 KB) Statistics
| Branch: | Tag: | Revision:

foreman-docker / app / models / docker_registry.rb @ 7ff105d1

1
class DockerRegistry < ActiveRecord::Base
2
  include Authorizable
3
  include Taxonomix
4
  include Encryptable
5

    
6
  has_many :containers, :foreign_key => "registry_id", :dependent => :destroy
7
  encrypts :password
8

    
9
  validates_lengths_from_database
10
  validates :name, :presence => true, :uniqueness => true
11
  validates :url,  :presence => true, :uniqueness => true
12

    
13
  scoped_search :on => :name, :complete_value => true
14
  scoped_search :on => :url
15

    
16
  def used_location_ids
17
    Location.joins(:taxable_taxonomies).where(
18
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
19
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
20
  end
21

    
22
  def used_organization_ids
23
    Organization.joins(:taxable_taxonomies).where(
24
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
25
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
26
  end
27

    
28
  def prefixed_url(image_name)
29
    uri = URI(url)
30
    "#{uri.hostname}:#{uri.port}/#{image_name}"
31
  end
32

    
33
  def self.humanize_class_name(_name = nil)
34
    _("Docker/Registry")
35
  end
36
end