Class: OpenShift::Component

Inherits:
Model
  • Object
show all
Defined in:
lib/openshift-origin-common/models/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

attr_accessor, attr_reader, attr_writer, #attributes, #attributes=, #deleted?, exclude_attributes, excludes_attributes, gen_uuid, include_attributes, includes_attributes, #new_record?, #persisted?, primary_key, require_update_attributes, requires_update_attributes, #reset_state, #to_xml

Constructor Details

#initialize(name = nil) ⇒ Component

Returns a new instance of Component.



7
8
9
10
# File 'lib/openshift-origin-common/models/component.rb', line 7

def initialize(name=nil)
  self.name = name
  self.generated = false
end

Instance Attribute Details

#dependsObject

Returns the value of attribute depends.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def depends
  @depends
end

#depends_serviceObject

Returns the value of attribute depends_service.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def depends_service
  @depends_service
end

#generatedObject

Returns the value of attribute generated.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def generated
  @generated
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def name
  @name
end

#publish_name_mapObject

Returns the value of attribute publish_name_map.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def publish_name_map
  @publish_name_map
end

#subscribe_name_mapObject

Returns the value of attribute subscribe_name_map.



3
4
5
# File 'lib/openshift-origin-common/models/component.rb', line 3

def subscribe_name_map
  @subscribe_name_map
end

Instance Method Details

#add_publish(publish) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openshift-origin-common/models/component.rb', line 27

def add_publish(publish)
  publish_name_map_will_change!
  publishes_will_change!
  @publish_name_map = {} if @publish_name_map.nil?
  if publish.class == Connector
    @publish_name_map[publish.name] = publish
  else
    key = publish["name"]            
    @publish_name_map[key] = Connector.new
    @publish_name_map[key].attributes=publish
  end
end

#add_subscribe(subscribe) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openshift-origin-common/models/component.rb', line 55

def add_subscribe(subscribe)
  subscribe_name_map_will_change!
  subscribes_will_change!
  @subscribe_name_map = {} if @subscribe_name_map.nil?
  if subscribe.class == Connector
    @subscribe_name_map[subscribe.name] = subscribe
  else        
    key = subscribe["name"]            
    @subscribe_name_map[key] = Connector.new
    @subscribe_name_map[key].attributes=subscribe
  end
end

#from_descriptor(spec_hash = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/openshift-origin-common/models/component.rb', line 68

def from_descriptor(spec_hash = {})
  self.name = spec_hash["Name"] || "default"
  if spec_hash["Publishes"]
    spec_hash["Publishes"].each do |n, p|
      conn = Connector.new(n).from_descriptor(p)
      self.add_publish(conn)
    end
  end
  
  if spec_hash["Subscribes"]
    spec_hash["Subscribes"].each do |n,p|
      conn = Connector.new(n).from_descriptor(p)
      self.add_subscribe(conn)
    end
  end
  
  self.depends = spec_hash["Dependencies"] || []
  self.depends_service = spec_hash["Service-Dependencies"] || []
  
  self
end

#publishes(name = nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/openshift-origin-common/models/component.rb', line 18

def publishes(name=nil)
  @publish_name_map = {} if @publish_name_map.nil?
  if name.nil?
    @publish_name_map.values
  else
    @publish_name_map[name]
  end
end

#publishes=(data) ⇒ Object



12
13
14
15
16
# File 'lib/openshift-origin-common/models/component.rb', line 12

def publishes=(data)
  data.each do |value|
    add_publish(value)
  end
end

#subscribes(name = nil) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/openshift-origin-common/models/component.rb', line 46

def subscribes(name=nil)
  @subscribe_name_map = {} if @subscribe_name_map.nil?
  if name.nil?
    @subscribe_name_map.values
  else
    @subscribe_name_map[name]
  end
end

#subscribes=(data) ⇒ Object



40
41
42
43
44
# File 'lib/openshift-origin-common/models/component.rb', line 40

def subscribes=(data)
  data.each do |value|
    add_subscribe(value)
  end
end

#to_descriptorObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/openshift-origin-common/models/component.rb', line 90

def to_descriptor
  p = {}
  self.publishes.each do |v|
    p[v.name] = v.to_descriptor
  end
  
  s = {}
  self.subscribes.each do |v|
    s[v.name] = v.to_descriptor
  end
  
  h = {}
  h["Publishes"] = p if self.publishes && !self.publishes.empty?
  h["Subscribes"] = s if self.subscribes && !self.subscribes.empty?
  h["Dependencies"] = self.depends if self.depends && !self.depends.empty?
  h["Service-Dependencies"] = self.depends_service if self.depends_service && !self.depends_service.empty?
  h
end