lib/docman/info.rb in docman-0.0.80 vs lib/docman/info.rb in docman-0.0.81
- old
+ new
@@ -17,11 +17,11 @@
@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')
+ if state.has_key?('source') and (not state.has_key?('type') or state.has_key['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?
@@ -44,11 +44,12 @@
def version(options = {})
state(options).nil? ? nil : state(options)['version']
end
def version_type(options = {})
- state(options).nil? ? nil : state(options)['type']
+ return self['version_type'] if self.key? 'version_type'
+ return state(options).nil? ? nil : state(options)['type']
end
def describe(type = 'short')
properties_info(%w(name type build_type))
end
@@ -57,15 +58,22 @@
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']
- if environment_name() != 'local'
- File.open(File.join(self['full_build_path'], 'info.yaml'), 'w') {|f| f.write to_save.to_yaml}
+ FileUtils::mkdir_p info_dir unless File.directory? info_dir
+
+ # Create local git ignored .docman dir for info file
+ 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}
+ #end
to_save
end
def changed?
#TODO: need refactor
@@ -110,14 +118,28 @@
@changed[@state_name] = true if v['state'] != @state_name
end
false
end
- #TODO: check if info.yaml needed for local state
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)
+ info_file_yaml
+ end
+
+ def info_dir(path = nil)
+ File.join(
+ path.nil? ? self['full_build_path'] : path,
+ environment_name() == 'local' ? '.docman' : ''
+ )
+ end
+
+ # TODO: make default with lazy initialize
+ def info_file(path = nil)
+ File.join(info_dir(path), 'info.yaml')
+ end
+
+ def info_file_yaml
+ file = info_file
+ File.file?(file) ? YAML::load_file(file) : nil
end
def state(options = {})
states(options)[@state_name]
end
\ No newline at end of file