Sha256: c44403684f8bdf5d717a7a29e9b6ef238f0740131285dc16a9b375d143298180

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

class Medium < ActiveRecord::Base
  include Authorization
  include Taxonomix

  has_and_belongs_to_many :operatingsystems
  has_many_hosts

  # We need to include $ in this as $arch, $release, can be in this string
  VALID_NFS_PATH=/^([-\w\d\.]+):(\/[\w\d\/\$\.]+)$/
  validates_uniqueness_of :name
  validates_uniqueness_of :path
  validates_presence_of :name, :path
  validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => N_("can't be blank or contain trailing white spaces.")
  validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//,
    :message => _("Only URLs with schema http://, https://, ftp:// or nfs:// are allowed (e.g. nfs://server/vol/dir)")

  validates_format_of :media_path, :config_path, :image_path, :allow_blank => true,
    :with => VALID_NFS_PATH, :message => _("does not appear to be a valid nfs mount path"),
    :if => Proc.new { |m| m.respond_to? :media_path }

  before_destroy EnsureNotUsedBy.new(:hosts)
  # with proc support, default_scope can no longer be chained
  # include all default scoping here
  default_scope lambda {
    with_taxonomy_scope do
      order("LOWER(media.name)")
    end
  }
  scoped_search :on => :name, :complete_value => :true, :default_order => true
  scoped_search :on => :path, :complete_value => :true
  scoped_search :on => :os_family, :rename => "family", :complete_value => :true

  def as_json(options={})
    options ||= {}
    super({:only => [:name, :id]}.merge(options))
  end

  def media_host
    media_path.match(VALID_NFS_PATH)[1]
  end

  def jumpstart_host
    config_path.match(VALID_NFS_PATH)[1]
  end

  def media_dir
    media_path.match(VALID_NFS_PATH)[2]
  end

  def jumpstart_dir
    config_path.match(VALID_NFS_PATH)[2]
  end

  # Write the image path, with a trailing "/" if required
  def image_path= path
    write_attribute :image_path, "#{path}#{"/" unless path =~ /\/$|^$/}"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/app/models/medium.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/app/models/medium.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/app/models/medium.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/app/models/medium.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/app/models/medium.rb