Class: Docman::Info

Inherits:
Hash
  • Object
show all
Includes:
Context
Defined in:
lib/docman/info.rb

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
# 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']
  @need_rebuild = Hash.new
end

Instance Attribute Details

#need_rebuildObject

Returns the value of attribute need_rebuild.



8
9
10
# File 'lib/docman/info.rb', line 8

def need_rebuild
  @need_rebuild
end

Instance Method Details

#_need_rebuild?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/docman/info.rb', line 62

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']
  return true if (not v['version'].nil? and v['version'] != self.version)
  return true if (not v['version_type'].nil? and v['version_type'] != self.version_type)
  unless v['state'].nil?
    return true if v['state'] != self['state']
  end
  false
end

#commands(type, hook) ⇒ Object



94
95
96
97
98
99
# File 'lib/docman/info.rb', line 94

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



27
28
29
# File 'lib/docman/info.rb', line 27

def describe(type = 'short')
  properties_info(%w(name type build_type))
end

#disabled?Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/docman/info.rb', line 87

def disabled?
  unless self['status'].nil?
    return self['status'] == 'disabled'
  end
  false
end

#environmentObject



101
102
103
# File 'lib/docman/info.rb', line 101

def environment
  self['docroot_config'].deploy_target['environments'][self['state']]
end

#need_rebuild?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/docman/info.rb', line 44

def need_rebuild?
  return @need_rebuild[self['state']] if not @need_rebuild.nil? and @need_rebuild.has_key? self['state'] and not @need_rebuild[self['state']].nil?
  @need_rebuild[self['state']] = _need_rebuild?
  if @need_rebuild[self['state']]
    set_rebuild_recursive(self, true)
  end
  @need_rebuild[self['state']]
end

#set_rebuild_recursive(obj, value) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/docman/info.rb', line 53

def set_rebuild_recursive(obj, value)
  obj.need_rebuild[self['state']] = value
  if obj.has_key?('children')
    obj['children'].each do |info|
      set_rebuild_recursive(info, value)
    end
  end
end

#state=(state) ⇒ Object



83
84
85
# File 'lib/docman/info.rb', line 83

def state=(state)
  self['state'] = state
end

#stored_versionObject



77
78
79
80
81
# File 'lib/docman/info.rb', line 77

def stored_version
  info_filename = File.join(self['full_build_path'], 'info.yaml')
  return false unless File.file?(info_filename)
  YAML::load_file(info_filename)
end

#versionObject



19
20
21
# File 'lib/docman/info.rb', line 19

def version
  self['states'][self['state']].nil? ? nil : self['states'][self['state']]['version']
end

#version_typeObject



23
24
25
# File 'lib/docman/info.rb', line 23

def version_type
  self['states'][self['state']].nil? ? nil : self['states'][self['state']]['type']
end

#write_info(result) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/docman/info.rb', line 31

def write_info(result)
  to_save = {}
  to_save['state'] = self['state']
  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['type'] = self['type']
  to_save['build_type'] = self['build_type']

  File.open(File.join(self['full_build_path'], 'info.yaml'), 'w') {|f| f.write to_save.to_yaml}
  to_save
end