Project

General

Profile

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

foreman_docker / app / models / docker_registry.rb @ c80f3b10

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

    
6
  attr_accessible :name, :url, :username, :password, :locations, :organizations
7

    
8
  has_many :containers, :foreign_key => "registry_id", :dependent => :destroy
9
  encrypts :password
10

    
11
  attr_accessible :name, :url, :username, :password, :locations, :organizations
12

    
13
  validates_lengths_from_database
14
  validates :name, :presence => true, :uniqueness => true
15
  validates :url,  :presence => true, :uniqueness => true
16

    
17
  scoped_search :on => :name, :complete_value => true
18
  scoped_search :on => :url
19

    
20
  def used_location_ids
21
    Location.joins(:taxable_taxonomies).where(
22
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
23
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
24
  end
25

    
26
  def used_organization_ids
27
    Organization.joins(:taxable_taxonomies).where(
28
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
29
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
30
  end
31

    
32
  def prefixed_url(image_name)
33
    uri = URI(url)
34
    "#{uri.hostname}:#{uri.port}/#{image_name}"
35
  end
36

    
37
  def self.humanize_class_name(_name = nil)
38
    _("Docker/Registry")
39
  end
40
end