Class: Docman::Info
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
#log, logger, #logger, #prefix, #properties_info, #with_logging
Constructor Details
#initialize(hash = {}) ⇒ Info
Returns a new instance of Info.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/docman/info.rb', line 10
def initialize(hash = {})
super
hash.each_pair do |k, v|
self[k] = v
end
self['build_type'] = self['docroot_config'].deploy_target['builders'][self['type']]['handler'] unless self['docroot_config'].deploy_target.nil?
@need_rebuild = Hash.new
@changed = Hash.new
@state_name = nil
unless self['docroot_config'].deploy_target.nil?
if self.has_key? 'states'
self['states'].each_pair do |name, state|
if state.has_key?('source') and (not state.has_key?('type') or (state.has_key?('type') and state['type'] == 'external_source'))
if state['source']['type'] == :retrieve_from_repo
@state_name = name
repo = state['source']['repo'] == :project_repo ? self['repo'] : state['source']['repo']
external_state_info = read_yaml_from_file(repo, self['states_path'], state['source']['branch'], state['source']['file'])
state.deep_merge! external_state_info unless external_state_info.nil? or state.nil?
end
end
end
end
end
end
|
Instance Attribute Details
#build_mode ⇒ Object
Returns the value of attribute build_mode.
8
9
10
|
# File 'lib/docman/info.rb', line 8
def build_mode
@build_mode
end
|
#need_rebuild ⇒ Object
Returns the value of attribute need_rebuild.
8
9
10
|
# File 'lib/docman/info.rb', line 8
def need_rebuild
@need_rebuild
end
|
#state_name ⇒ Object
Returns the value of attribute state_name.
8
9
10
|
# File 'lib/docman/info.rb', line 8
def state_name
@state_name
end
|
Instance Method Details
#_need_rebuild? ⇒ Boolean
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/docman/info.rb', line 106
def _need_rebuild?
return true if Docman::Application.instance.force?
return true unless File.directory? self['full_build_path']
v = stored_version
return true unless v
return true if v['type'] != self['type']
return true if v['build_type'] != self['build_type']
@changed[@state_name] = true if (not v['version'].nil? and v['version'] != version)
return true if (not v['version_type'].nil? and v['version_type'] != version_type)
unless v['state'].nil?
@changed[@state_name] = true if v['state'] != @state_name
end
false
end
|
#changed? ⇒ Boolean
78
79
80
81
82
83
84
85
86
|
# File 'lib/docman/info.rb', line 78
def changed?
return @changed[@state_name] if not @changed.nil? and @changed.has_key? @state_name and not @changed[@state_name].nil?
@changed[@state_name] = false
if need_rebuild?
@changed[@state_name] = true
end
@changed[@state_name]
end
|
#commands(type, hook) ⇒ Object
163
164
165
166
167
168
|
# File 'lib/docman/info.rb', line 163
def commands(type, hook)
if self.has_key? 'actions' and self['actions'].has_key? type and self['actions'][type].has_key? hook
return self['actions'][type][hook]
end
[]
end
|
#describe(type = 'short') ⇒ Object
53
54
55
|
# File 'lib/docman/info.rb', line 53
def describe(type = 'short')
properties_info(%w(name type build_type))
end
|
#disabled? ⇒ Boolean
156
157
158
159
160
161
|
# File 'lib/docman/info.rb', line 156
def disabled?
unless self['status'].nil?
return self['status'] == 'disabled'
end
false
end
|
#environment_name ⇒ Object
170
171
172
|
# File 'lib/docman/info.rb', line 170
def environment_name
self['docroot_config'].deploy_target['states'][@state_name] unless self['docroot_config'].deploy_target.nil?
end
|
#info_dir(path = nil) ⇒ Object
127
128
129
130
131
132
|
# File 'lib/docman/info.rb', line 127
def info_dir(path = nil)
File.join(
path.nil? ? self['full_build_path'] : path,
environment_name() == 'local' ? '.docman' : ''
)
end
|
#info_file(path = nil) ⇒ Object
TODO: make default with lazy initialize
135
136
137
|
# File 'lib/docman/info.rb', line 135
def info_file(path = nil)
File.join(info_dir(path), 'info.yaml')
end
|
#info_file_yaml ⇒ Object
139
140
141
142
|
# File 'lib/docman/info.rb', line 139
def info_file_yaml
file = info_file
File.file?(file) ? YAML::load_file(file) : nil
end
|
#need_rebuild? ⇒ Boolean
88
89
90
91
92
93
94
95
|
# File 'lib/docman/info.rb', line 88
def need_rebuild?
return @need_rebuild[@state_name] if not @need_rebuild.nil? and @need_rebuild.has_key? @state_name and not @need_rebuild[@state_name].nil?
@need_rebuild[@state_name] = _need_rebuild?
if @need_rebuild[@state_name]
set_rebuild_recursive(self, true)
end
@need_rebuild[@state_name]
end
|
#read_yaml_from_file(repo, path, version, filename) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/docman/info.rb', line 35
def read_yaml_from_file(repo, path, version, filename)
GitUtil.get(repo, path, 'branch', version, true, 1, true)
filepath = File.join(path, filename)
return YAML::load_file(filepath) if File.file? filepath
nil
rescue StandardError => e
raise "Error in info file: #{filepath}, #{e.message}"
end
|
#set_rebuild_recursive(obj, value) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/docman/info.rb', line 97
def set_rebuild_recursive(obj, value)
obj.need_rebuild[@state_name] = value
if obj.has_key?('children')
obj['children'].each do |info|
set_rebuild_recursive(info, value)
end
end
end
|
#state(options = {}) ⇒ Object
144
145
146
|
# File 'lib/docman/info.rb', line 144
def state(options = {})
states(options)[@state_name]
end
|
#states(options = {}) ⇒ Object
148
149
150
151
152
153
154
|
# File 'lib/docman/info.rb', line 148
def states(options = {})
if options[:type] == 'root' and (self['type'] == 'root_chain' or self['type'] == 'single')
self['root_repo_states']
else
self['states']
end
end
|
#stored_version ⇒ Object
123
124
125
|
# File 'lib/docman/info.rb', line 123
def stored_version
info_file_yaml
end
|
#version(options = {}) ⇒ Object
44
45
46
|
# File 'lib/docman/info.rb', line 44
def version(options = {})
state(options).nil? ? nil : state(options)['version']
end
|
#version_type(options = {}) ⇒ Object
48
49
50
51
|
# File 'lib/docman/info.rb', line 48
def version_type(options = {})
return self['version_type'] if self.key? 'version_type'
return state(options).nil? ? nil : state(options)['type']
end
|
#write_info(result) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/docman/info.rb', line 57
def write_info(result)
to_save = {}
to_save['state'] = @state_name
to_save['version_type'] = self.version_type unless self.version_type.nil?
to_save['version'] = self.version unless self.version.nil?
to_save['result'] = result
to_save['provider'] = self['provider'] unless self['provider'].nil?
to_save['type'] = self['type']
to_save['build_type'] = self['build_type']
FileUtils::mkdir_p info_dir unless File.directory? info_dir
if environment_name() == 'local'
gitignore_file = File.join(info_dir, '.gitignore')
File.open(gitignore_file, 'w') {|f| f.write '*'} unless File.file? gitignore_file
end
File.open(info_file, 'w') {|f| f.write to_save.to_yaml}
to_save
end
|