Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/model/deployable.rb | 101 | 69 | 98.02%
|
97.10%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 # |
2 # Copyright [2011] [Red Hat, Inc.] |
3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at |
7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # |
10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # See the License for the specific language governing permissions and |
14 # limitations under the License. |
15 # |
16 require 'fileutils' |
17 |
18 require 'lib/model/base' |
19 |
20 module ConfigServer |
21 module Model |
22 class Deployable < Base |
23 |
24 EXCLUDED_DIRS = %w{. ..} |
25 |
26 def self.find(uuid) |
27 Deployable.new(uuid) if exists?(uuid) |
28 end |
29 |
30 def self.storage_path(uuid=nil) |
31 path = uuid ? File.join("deployables", uuid) : "deployables" |
32 super path |
33 end |
34 |
35 def self.exists?(uuid) |
36 File.exists?(storage_path uuid) |
37 end |
38 |
39 @uuid = nil |
40 @deployable_dir = nil |
41 |
42 def initialize(uuid) |
43 super() |
44 Deployable.ensure_storage_path |
45 |
46 @uuid = uuid |
47 @deployable_dir = ensure_deployable_dir |
48 self |
49 end |
50 |
51 def add_instance(uuid) |
52 # never actually hold the state of the list of instances |
53 # always pick up the list from the filesystem |
54 instance_dir = Instance.storage_path uuid |
55 if File.directory?(instance_dir) |
56 FileUtils.ln_s(instance_dir, File.join(@deployable_dir.path, uuid)) |
57 end |
58 instance_uuids |
59 end |
60 |
61 def remove_instance(uuid) |
62 delete_path = File.join(@deployable_dir.path, uuid) |
63 File.delete(delete_path) if File.exists?(delete_path) |
64 instance_uuids |
65 end |
66 |
67 def delete! |
68 instance_uuids.each do |instance_uuid| |
69 Instance.delete! instance_uuid |
70 remove_instance instance_uuid |
71 end |
72 FileUtils.rm_rf(@deployable_dir.path) |
73 end |
74 |
75 def instance_uuids |
76 @deployable_dir.entries - EXCLUDED_DIRS |
77 end |
78 |
79 def instances_with_assembly_dependencies(assembly_names) |
80 if not assembly_names.kind_of? Array |
81 assembly_names = [assembly_names] |
82 end |
83 match_string = "['\"](#{assembly_names.join("|")})['\"]" |
84 logger.debug("match_string: #{match_string}") |
85 instance_uuids.select do |uuid| |
86 p = File.join(@deployable_dir.path, uuid, 'required-parameters.xml') |
87 File.open(p) do |f| |
88 not f.grep(/<required-parameter .* assembly=#{match_string}/).empty? |
89 end if File.exists?(p) |
90 end |
91 end |
92 |
93 private |
94 def ensure_deployable_dir |
95 path = Deployable.storage_path @uuid |
96 FileUtils.mkdir_p(path, :mode => 0700) if not File.directory?(path) |
97 Dir.new(path) |
98 end |
99 end |
100 end |
101 end |
Generated on Wed Dec 14 16:00:31 -0500 2011 with rcov 0.9.11