Class: Domain

Inherits:
OpenShift::UserModel
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/domain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = nil, user = nil) ⇒ Domain

Returns a new instance of Domain.



8
9
10
11
12
# File 'app/models/domain.rb', line 8

def initialize(namespace=nil, user=nil)
  self.user = user
  self.namespace = namespace
  self.uuid = OpenShift::Model.gen_uuid
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'app/models/domain.rb', line 4

def namespace
  @namespace
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'app/models/domain.rb', line 4

def user
  @user
end

#uuidObject

Returns the value of attribute uuid.



4
5
6
# File 'app/models/domain.rb', line 4

def uuid
  @uuid
end

Class Method Details

.find(user, id) ⇒ Object



48
49
50
51
52
53
# File 'app/models/domain.rb', line 48

def self.find(user, id)
  domain = super(user., id)
  domain.user = user if domain
  return nil unless domain
  domain
end

.find_all(user, namespace = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/domain.rb', line 55

def self.find_all(user, namespace=nil)
  domains = super(user.) 
  unless namespace
    user.domains = domains
    return domains
  else
    filtered_domains = nil
    domains.each do |domain|
      if domain.namespace == namespace
        filtered_domains.push(domain)
      end
    end
    return filtered_domains
  end    
end

.get(user, id) ⇒ Object



71
72
73
74
75
76
# File 'app/models/domain.rb', line 71

def self.get(user, id)
  user.domains.each do |domain|
    return domain if domain.namespace == id
  end if user.domains
  return nil
end

.hash_to_obj(hash) ⇒ Object



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

def self.hash_to_obj(hash)
  domain = super(hash)
  domain
end

.namespace_available?(namespace) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.namespace_available?(namespace)
  Rails.logger.debug "Checking to see if namesspace #{namespace} is available"
  dns_service = OpenShift::DnsService.instance
  return dns_service.namespace_available?(namespace)
end

Instance Method Details

#deleteObject



88
89
90
91
92
93
94
95
96
97
# File 'app/models/domain.rb', line 88

def delete
  Rails.logger.debug "Deleting domain #{self.namespace} uuid #{self.uuid}"
  resultIO = ResultIO.new
  delete_dns
  super(user.)
  Rails.logger.debug "notifying the domain observer of domain delete"
  notify_observers(:after_domain_destroy) 
  Rails.logger.debug "done notifying the domain observer"
  resultIO
end

#delete_dnsObject



78
79
80
81
82
83
84
85
86
# File 'app/models/domain.rb', line 78

def delete_dns
  dns_service = OpenShift::DnsService.instance
  begin
    dns_service.deregister_namespace(self.namespace)
    dns_service.publish
  ensure
    dns_service.close
  end
end

#hasAccess?(user) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'app/models/domain.rb', line 32

def hasAccess?(user)
  #TODO 
  #if user.domains.include? self.uuid
    return true
  #end
  #return false
end

#hasFullAccess?(user) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'app/models/domain.rb', line 40

def hasFullAccess?(user)
  #TODO
  #if self.user.login == user.login
    return true
  #end
  #return false
end

#saveObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/domain.rb', line 13

def save
  resultIO = ResultIO.new
  created = false
  if not persisted?
    resultIO.append(create())
    created = true
  else
    resultIO.append(update())
  end

  begin
    super(self.user.)
  rescue
    delete_dns if created
    raise
  end
  resultIO
end