Module: RPM

Defined in:
lib/rpm/gem_version.rb,
lib/rpm.rb,
lib/rpm/c.rb,
lib/rpm/c.rb,
lib/rpm/db.rb,
lib/rpm/file.rb,
lib/rpm/utils.rb,
lib/rpm/compat.rb,
lib/rpm/c/rpmdb.rb,
lib/rpm/c/rpmds.rb,
lib/rpm/c/rpmfi.rb,
lib/rpm/c/rpmio.rb,
lib/rpm/c/rpmps.rb,
lib/rpm/c/rpmtd.rb,
lib/rpm/c/rpmts.rb,
lib/rpm/package.rb,
lib/rpm/problem.rb,
lib/rpm/version.rb,
lib/rpm/c/header.rb,
lib/rpm/c/rpmcli.rb,
lib/rpm/c/rpmlib.rb,
lib/rpm/c/rpmlog.rb,
lib/rpm/c/rpmtag.rb,
lib/rpm/c/rpmprob.rb,
lib/rpm/c/rpmmacro.rb,
lib/rpm/c/rpmtypes.rb,
lib/rpm/dependency.rb,
lib/rpm/transaction.rb,
lib/rpm/c/rpmcallback.rb,
lib/rpm/match_iterator.rb

Overview

The reason this file is gem_version.rb and not version.rb is because it conflicts with the version.rb class

Defined Under Namespace

Modules: C, Utils Classes: CallbackData, ChangeLog, Conflict, DB, Dependency, File, MatchIterator, Obsolete, Package, Problem, Provide, Require, Transaction, Version

Constant Summary collapse

TAG =
RPM::C::Tag
LOG =
RPM::C::Log
SENSE =
RPM::C::Sense
FILE =
RPM::C::FileAttrs
FILE_STATE =
RPM::C::FileState
TRANS_FLAG =
RPM::C::TransFlags
PROB_FILTER =
RPM::C::ProbFilter
MIRE =
RPM::C::RegexpMode
PKG_NAME =
'ruby-rpm'.freeze
GEM_VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.[](name) ⇒ String

Returns value of macro name.

Parameters:

  • name (String)

    Name of the macro

Returns:

  • (String)

    value of macro name



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rpm.rb', line 43

def self.[](name)
  if C::rpm_version_code >= ((4 << 16) + (14 << 8) + (0 << 0))
    obuf = ::FFI::MemoryPointer.new(:pointer, 1)
    sbuf = FFI::MemoryPointer.from_string("%{#{name}}")
    ret = RPM::C.rpmExpandMacros(nil, sbuf, obuf, 0)
    raise if ret < 0

    val = obuf.read_pointer
    val.nil? ? nil : val.read_string
  else
    buffer = ::FFI::MemoryPointer.new(:pointer, 1024)
    buffer.write_string("%{#{name}}")
    ret = RPM::C.expandMacros(nil, nil, buffer, 1024)
    raise if ret < 0

    buffer.read_string
  end
end

.[]=(name, value) ⇒ Object

Setup a macro

Parameters:

  • name (String)

    Name of the macro

  • value (String)

    Value of the macro or nil to delete it



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rpm.rb', line 65

def self.[]=(name, value)
  if value.nil?
    if C::rpm_version_code >= ((4 << 16) + (14 << 8) + (0 << 0))
      RPM::C.rpmPopMacro(nil, name.to_s)
    else
      RPM::C.delMacro(nil, name.to_s)
    end
  else
    if C::rpm_version_code >= ((4 << 16) + (14 << 8) + (0 << 0))
      RPM::C.rpmPushMacro(nil, name.to_s, '', value.to_s, RPM::C::RMIL_DEFAULT)
    else
      RPM::C.addMacro(nil, name.to_s, '', value.to_s, RPM::C::RMIL_DEFAULT)
    end
  end
end

.transaction(root = '/') ⇒ Object

Creates a new transaction and pass it to the given block

Examples:

RPM.transaction do |ts|
   ...
end

Parameters:

  • root (String) (defaults to: '/')

    dir, default ‘/’



33
34
35
36
37
38
39
# File 'lib/rpm.rb', line 33

def self.transaction(root = '/')
  ts = Transaction.new
  ts.root_dir = root
  yield ts
ensure
  ts.ptr.free
end