Class: ReaperMan::PackageList
- Inherits:
-
Object
- Object
- ReaperMan::PackageList
- Defined in:
- lib/reaper-man/package_list.rb,
lib/reaper-man/package_list/deb.rb,
lib/reaper-man/package_list/gem.rb,
lib/reaper-man/package_list/rpm.rb
Overview
Package list for repository
Defined Under Namespace
Classes: Processor
Instance Attribute Summary collapse
-
#content ⇒ Hash
readonly
Content of package list.
-
#init_mtime ⇒ Time
readonly
Package list mtime.
-
#options ⇒ Hash
readonly
Configuration.
-
#path ⇒ String
readonly
Path to list file.
Instance Method Summary collapse
-
#add_package(package) ⇒ Object
Add package to package list file.
-
#initialize(path, args = {}) ⇒ PackageList
constructor
Create new instance.
-
#remove_package(package, version = nil) ⇒ Object
Remove package from the package list file.
-
#serialize ⇒ String
Serialized content.
-
#write! ⇒ Integer
Write contents to package list file.
Constructor Details
#initialize(path, args = {}) ⇒ PackageList
Create new instance
50 51 52 53 54 55 56 57 58 |
# File 'lib/reaper-man/package_list.rb', line 50 def initialize(path, args = {}) if path.nil? || path.empty? raise ArgumentError, "Path is required" end @path = path @options = args.dup @content = Smash.new init_list! end |
Instance Attribute Details
#content ⇒ Hash (readonly)
Returns content of package list.
44 45 46 |
# File 'lib/reaper-man/package_list.rb', line 44 def content @content end |
#init_mtime ⇒ Time (readonly)
Returns package list mtime.
42 43 44 |
# File 'lib/reaper-man/package_list.rb', line 42 def init_mtime @init_mtime end |
#options ⇒ Hash (readonly)
Returns configuration.
40 41 42 |
# File 'lib/reaper-man/package_list.rb', line 40 def @options end |
#path ⇒ String (readonly)
Returns path to list file.
38 39 40 |
# File 'lib/reaper-man/package_list.rb', line 38 def path @path end |
Instance Method Details
#add_package(package) ⇒ Object
Add package to package list file
63 64 65 |
# File 'lib/reaper-man/package_list.rb', line 63 def add_package(package) [package_handler(File.extname(package).tr(".", "")).add(content, package)].flatten.compact end |
#remove_package(package, version = nil) ⇒ Object
Remove package from the package list file
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/reaper-man/package_list.rb', line 71 def remove_package(package, version = nil) ext = File.extname(package).tr(".", "") if ext.empty? ext = %w(deb) # rpm) else ext = [ext] end ext.each do |ext_name| package_handler(ext_name).remove(content, package, version) end end |
#serialize ⇒ String
Returns serialized content.
84 85 86 |
# File 'lib/reaper-man/package_list.rb', line 84 def serialize MultiJson.dump(content) end |
#write! ⇒ Integer
Write contents to package list file
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/reaper-man/package_list.rb', line 91 def write! new_file = !File.exists?(path) File.open(path, File::CREAT | File::RDWR) do |file| file.flock(File::LOCK_EX) if !new_file && init_mtime != file.mtime file.rewind content.deep_merge!( MultiJson.load( file.read ) ) file.rewind end pos = file.write MultiJson.dump(content, :pretty => true) file.truncate(pos) end end |