Class: Puppet::Util::PTomulik::Package::Ports::Record
- Inherits:
-
Hash
- Object
- Hash
- Puppet::Util::PTomulik::Package::Ports::Record
- Extended by:
- Functions
- Defined in:
- lib/puppet/util/ptomulik/package/ports/record.rb
Overview
extra fields.
Direct Known Subclasses
Class Method Summary collapse
-
.default_fields ⇒ Array
These fields are requested from an underlying search method by default (when user does not specify what fields to request).
-
.deps_for_amend ⇒ Hash
Dependencies between fields.
-
.determine_search_fields(fields, key = nil) ⇒ Array
Determine what fields should be requested from back-end search method in order to be able to generate (with #amend!) all the fields listed in ‘fields`.
-
.std_fields ⇒ Array
These fields may are obtained from search back-end without additional effort (without #amend!).
Instance Method Summary collapse
-
#amend(fields) ⇒ Record
Equivalent to ‘record.dup.amend!(fields)`.
-
#amend!(fields) ⇒ Record
Refine the PortRecord such that it contains specified fields.
-
#if_wants(fields, what, &block) ⇒ Object
For internal use.
-
#if_wants_one_of(fields, what, &block) ⇒ Object
For internal use.
Class Method Details
.default_fields ⇒ Array
The method must be implemented in a subclass.
These fields are requested from an underlying search method by default (when user does not specify what fields to request).
Note that this list may include std_fields plus some extra fields generated by #amend!.
47 48 49 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 47 def self.default_fields raise NotImplementedError, "this method must be implemented in a subclass" end |
.deps_for_amend ⇒ Hash
The method must be implemented in a subclass.
Dependencies between fields.
If we want #amend! to add extra fields to Puppet::Util::PTomulik::Package::Ports::Record we must first ensure that certain fields are requested from the back-end search command when searching ports or packages. For example, when searching ports with ‘make search`, one needs to include `:name` field in the `make search` result in order to determine `:pkgname`, i.e. the search command should be like
`make search -C /usr/ports <filter> display=name,...`
The deps_for_amend returns a hash which describes these dependencies, for example.
{
:pkgname => [:name], # :pkgname depends on :name
:portorigin => [:path] # :portorigin depends on :path
...
}
74 75 76 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 74 def self.deps_for_amend raise NotImplementedError, "this method must be implemented in a subclass" end |
.determine_search_fields(fields, key = nil) ⇒ Array
Determine what fields should be requested from back-end search method in order to be able to generate (with #amend!) all the fields listed in ‘fields`.
This methods makes effective use of deps_for_amend.
99 100 101 102 103 104 105 106 107 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 99 def self.determine_search_fields(fields,key=nil) search_fields = fields & std_fields deps_for_amend.each do |field,deps| search_fields += deps if fields.include?(field) end search_fields << key unless key.nil? or search_fields.include?(key) search_fields.uniq! search_fields end |
.std_fields ⇒ Array
The method must be implemented in a subclass.
These fields may are obtained from search back-end without additional effort (without #amend!).
35 36 37 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 35 def self.std_fields raise NotImplementedError, "this method must be implemented in a subclass" end |
Instance Method Details
#amend(fields) ⇒ Record
Equivalent to ‘record.dup.amend!(fields)`.
See documentation of #amend!.
83 84 85 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 83 def amend(fields) self.dup.amend!(fields) end |
#amend!(fields) ⇒ Record
Refine the PortRecord such that it contains specified fields.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 114 def amend!(fields) # For internal use. def if_wants(fields,what,&block); block.call() if fields.include?(what) end # For internal use. def if_wants_one_of(fields,what,&block) block.call() if not (fields & what).empty? end if self[:portname] and self[:portorigin] if_wants_one_of(fields,[:options_files,:options_file,:options]) do self[:options_files] = self.class.( self[:portname], self.class.(self[:portorigin]) ) if_wants(fields,:options_file) do self[:options_file] = self[:options_files].last end if_wants(fields,:options) do self[:options] = Options.load(self[:options_files]) end end end # filter-out fields not requested by caller self.delete_if{|f,r| not fields.include?(f)} unless fields.equal?(:all) self end |
#if_wants(fields, what, &block) ⇒ Object
For internal use.
116 117 118 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 116 def if_wants(fields,what,&block); block.call() if fields.include?(what) end |
#if_wants_one_of(fields, what, &block) ⇒ Object
For internal use.
120 121 122 |
# File 'lib/puppet/util/ptomulik/package/ports/record.rb', line 120 def if_wants_one_of(fields,what,&block) block.call() if not (fields & what).empty? end |