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
47 48 49 50 51 52 |
# File 'lib/reaper-man/package_list.rb', line 47 def initialize(path, args={}) @path = path = args.dup @content = Smash.new init_list! end |
Instance Attribute Details
#content ⇒ Hash (readonly)
Returns content of package list.
41 42 43 |
# File 'lib/reaper-man/package_list.rb', line 41 def content @content end |
#init_mtime ⇒ Time (readonly)
Returns package list mtime.
39 40 41 |
# File 'lib/reaper-man/package_list.rb', line 39 def init_mtime @init_mtime end |
#options ⇒ Hash (readonly)
Returns configuration.
37 38 39 |
# File 'lib/reaper-man/package_list.rb', line 37 def end |
#path ⇒ String (readonly)
Returns path to list file.
35 36 37 |
# File 'lib/reaper-man/package_list.rb', line 35 def path @path end |
Instance Method Details
#add_package(package) ⇒ Object
Add package to package list file
57 58 59 |
# File 'lib/reaper-man/package_list.rb', line 57 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/reaper-man/package_list.rb', line 65 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.
78 79 80 |
# File 'lib/reaper-man/package_list.rb', line 78 def serialize MultiJson.dump(content) end |
#write! ⇒ Integer
Write contents to package list file
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/reaper-man/package_list.rb', line 85 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 |