Class: FPM::Cookery::Recipe
- Inherits:
-
BaseRecipe
- Object
- BaseRecipe
- FPM::Cookery::Recipe
- Extended by:
- Forwardable, SingleForwardable
- Defined in:
- lib/fpm/cookery/recipe.rb
Direct Known Subclasses
CPANRecipe, DirRecipe, NPMRecipe, PEARRecipe, PythonRecipe, RubyGemRecipe, VirtualenvRecipe
Instance Attribute Summary collapse
-
#sourcedir ⇒ Object
Returns the value of attribute sourcedir.
Attributes included from PathHelper
#installing, #omnibus_installing
Class Method Summary collapse
-
.apply ⇒ Object
Iterates over all of the *_attrs class methods, calling the relevant setter methods for all attributes which return non-
nil
results for.lookup
. - .extracted_source(path = nil) ⇒ Object
- .hiera ⇒ Object
- .source(source = nil, spec = {}) ⇒ Object (also: url)
Instance Method Summary collapse
-
#extract ⇒ Object
Custom source extraction code, must return the extracted source directory.
-
#initialize(defer_application = false) ⇒ Recipe
constructor
A new instance of Recipe.
- #input(config) ⇒ Object
- #source_handler ⇒ Object
- #template(format) ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #to_pretty_json ⇒ Object
Methods inherited from BaseRecipe
architectures, builddir, cachedir, datadir, depends_all, #depends_all, destdir, pkgdir, platform, platforms, targets, tmp_root, workdir
Methods included from InheritableAttr
#attr_rw, #attr_rw_hash, #attr_rw_list, #attr_rw_path, extended, inherit_for, #register_attrs
Methods included from LifecycleHooks
#after_build, #after_dependency_installation, #after_install, #after_package_create, #after_source_download, #after_source_extraction, #before_build, #before_dependency_installation, #before_install, #before_package_create, #before_source_download, #before_source_extraction, #run_lifecycle_hook
Methods included from PathHelper
#bin, #doc, #etc, #include, #info, #installing?, #lib, #libexec, #man, #man1, #man2, #man3, #man4, #man5, #man6, #man7, #man8, #omnibus_installing?, #opt, #prefix, #root, #sbin, #share, #var, #with_trueprefix
Constructor Details
#initialize(defer_application = false) ⇒ Recipe
Returns a new instance of Recipe.
142 143 144 145 146 147 |
# File 'lib/fpm/cookery/recipe.rb', line 142 def initialize(defer_application = false) # Note: this must be called prior to instantiating the +SourceHandler+, # so that +source+ can be picked up if it is defined in a +Hiera+ # # data file. apply unless defer_application end |
Instance Attribute Details
#sourcedir ⇒ Object
Returns the value of attribute sourcedir.
255 256 257 |
# File 'lib/fpm/cookery/recipe.rb', line 255 def sourcedir @sourcedir end |
Class Method Details
.apply ⇒ Object
Iterates over all of the *_attrs class methods, calling the relevant setter methods for all attributes which return non-nil
results for .lookup
. Note: Hiera does not provide access to a structure that represents the merged contents of all data files; interaction with the data must go through one channel, the .lookup
method. That is why we have to iterate over all of these attributes, rather than loading the data files into a hash and then calling only those methods for which a key-value pair is specified.
215 216 217 218 219 220 |
# File 'lib/fpm/cookery/recipe.rb', line 215 def apply scalar_attrs.each { |m| applicator(m) { |r| send(m, r) } } list_attrs.each { |m| applicator(m) { |r| send(m, *r) } } hash_attrs.each { |m| applicator(m) { |r| send(m).merge!(r) } } path_attrs.each { |m| applicator(m) { |r| send("#{m}=", r) } } end |
.extracted_source(path = nil) ⇒ Object
187 188 189 190 |
# File 'lib/fpm/cookery/recipe.rb', line 187 def extracted_source(path = nil) return @extracted_source if path.nil? @extracted_source = path end |
.hiera ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/fpm/cookery/recipe.rb', line 192 def hiera if !defined?(@hiera) or @hiera.nil? begin @hiera = FPM::Cookery::Hiera::Instance.new(self, :config => hiera_config) rescue StandardError => e = "Encountered error loading Hiera: #{e.}" Log.fatal raise Error::ExecutionFailure, end end @hiera end |
.source(source = nil, spec = {}) ⇒ Object Also known as: url
178 179 180 181 182 183 184 |
# File 'lib/fpm/cookery/recipe.rb', line 178 def source(source = nil, spec = {}) #puts "#=> SOURCE: #{@source.inspect}" return @source if source.nil? @source = source @spec = spec @source end |
Instance Method Details
#extract ⇒ Object
Custom source extraction code, must return the extracted source directory.
150 151 152 |
# File 'lib/fpm/cookery/recipe.rb', line 150 def extract nil end |
#input(config) ⇒ Object
134 135 136 |
# File 'lib/fpm/cookery/recipe.rb', line 134 def input(config) FPM::Cookery::Package::Dir.new(self, config) end |
#source_handler ⇒ Object
138 139 140 |
# File 'lib/fpm/cookery/recipe.rb', line 138 def source_handler @source_handler ||= SourceHandler.new(Source.new(source, spec), cachedir, builddir) end |
#template(format) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/fpm/cookery/recipe.rb', line 168 def template(format) renderer = ERB.new(format, nil, '-') renderer.result(binding) rescue NameError, NoMethodError => e = "Error evaluating format string: no attribute `#{e.name}' for recipe" Log.error raise Error::ExecutionFailure, end |
#to_h ⇒ Object
154 155 156 157 158 |
# File 'lib/fpm/cookery/recipe.rb', line 154 def to_h attr_registry.values.flatten.each_with_object({}) do |m, a| a[m] = send(m) unless m == :attr_registry end end |
#to_json ⇒ Object
160 161 162 |
# File 'lib/fpm/cookery/recipe.rb', line 160 def to_json JSON.unparse(to_h) end |
#to_pretty_json ⇒ Object
164 165 166 |
# File 'lib/fpm/cookery/recipe.rb', line 164 def to_pretty_json JSON.pretty_generate(to_h) end |