Class: TorigoyaKit::Package::ProfileHolder

Inherits:
Object
  • Object
show all
Defined in:
lib/torigoya_kit/package_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(holder_path) ⇒ ProfileHolder



71
72
73
# File 'lib/torigoya_kit/package_utils.rb', line 71

def initialize( holder_path )
  @holder_path = holder_path
end

Class Method Details

.make_profile_name(package_name) ⇒ Object



127
128
129
130
# File 'lib/torigoya_kit/package_utils.rb', line 127

def self.make_profile_name( package_name )
  tag = Tag.new( package_name )
  return "#{tag.name}-#{tag.version}.yml"
end

.save_profile(path, available_profile) ⇒ Object



121
122
123
124
125
# File 'lib/torigoya_kit/package_utils.rb', line 121

def self.save_profile( path, available_profile )
  File.open( path, "w" ) do |f|
    f.write( available_profile.to_yaml )
  end
end

Instance Method Details

#delete_package(package_name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/torigoya_kit/package_utils.rb', line 95

def delete_package( package_name )
  profile_name = self.class.make_profile_name( package_name )
  profile_path = "#{@holder_path}/#{profile_name}"

  if File.exists?( profile_path )
    system( "rm -f #{profile_path}" )
  end

  return profile_path
end

#list_profilesObject



106
107
108
109
110
111
112
113
114
# File 'lib/torigoya_kit/package_utils.rb', line 106

def list_profiles()
  profs = []
  Dir.chdir( @holder_path ) do
    Dir.glob( '*.yml' ).sort_by {|f| File.mtime( f )}.reverse.each do |filename|
      profs << AvailableProfile.load_from_yaml( filename )
    end
  end
  return profs    # sorted old to new
end

#list_tag_and_dateObject



116
117
118
119
# File 'lib/torigoya_kit/package_utils.rb', line 116

def list_tag_and_date()
  profs = list_profiles()
  return profs.map{|e| { tags: Tag.new( e.package_name ), built_date: e.built_date } }
end

#update_package(package_name, built_date) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/torigoya_kit/package_utils.rb', line 75

def update_package( package_name, built_date )
  profile_name = self.class.make_profile_name( package_name )
  profile_path = "#{@holder_path}/#{profile_name}"
  a_profile = AvailableProfile.new( package_name, built_date )

  if File.exists?( profile_path )
    # compare date
    current_profile = AvailableProfile.load_from_yaml( profile_path )
    if a_profile.built_date > current_profile.built_date
      # update information
      self.class.save_profile( profile_path, a_profile )
    end
  else
    # save immediately
    self.class.save_profile( profile_path, a_profile )
  end

  return profile_path
end