Class: FPM::Cookery::BaseRecipe

Inherits:
Object
  • Object
show all
Includes:
PathHelper, Utils, FileUtils
Defined in:
lib/fpm/cookery/recipe.rb

Direct Known Subclasses

NPMRecipe, PythonRecipe, Recipe, RubyGemRecipe

Instance Attribute Summary collapse

Attributes included from PathHelper

#installing, #omnibus_installing

Class Method Summary collapse

Instance Method Summary collapse

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(filename, config) ⇒ BaseRecipe

Returns a new instance of BaseRecipe.



99
100
101
102
103
104
105
106
107
# File 'lib/fpm/cookery/recipe.rb', line 99

def initialize(filename, config)
  @filename = Path.new(filename).expand_path
  @config = config

  @workdir = @filename.dirname
  @tmp_root = @config.tmp_root ? Path.new(@config.tmp_root) : @workdir
  @pkgdir = @config.pkg_dir && Path.new(@config.pkg_dir)
  @cachedir = @config.cache_dir && Path.new(@config.cache_dir)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



76
77
78
# File 'lib/fpm/cookery/recipe.rb', line 76

def filename
  @filename
end

Class Method Details

.architectures(archs) ⇒ Object



45
46
47
# File 'lib/fpm/cookery/recipe.rb', line 45

def self.architectures(archs)
  Array(archs).member?(FPM::Cookery::Facts.arch) and block_given? ? yield : false
end

.attr_rw(*attrs) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fpm/cookery/recipe.rb', line 20

def self.attr_rw(*attrs)
  attrs.each do |attr|
    class_eval %Q{
      def self.#{attr}(value = nil)
        value.nil? ? @#{attr} : @#{attr} = value
      end

      def #{attr}
        self.class.#{attr}
      end
    }
  end
end

.attr_rw_list(*attrs) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fpm/cookery/recipe.rb', line 49

def self.attr_rw_list(*attrs)
  attrs.each do |attr|
    class_eval %Q{
      def self.#{attr}(*list)
        @#{attr} ||= []
        @#{attr} << list
        @#{attr}.flatten!
        @#{attr}.uniq!
        @#{attr}
      end

      def #{attr}
        self.class.#{attr}
      end
    }
  end
end

.depends_allObject



83
84
85
# File 'lib/fpm/cookery/recipe.rb', line 83

def depends_all
  (depends + build_depends).uniq
end

.fpm_attributes(args = nil) ⇒ Object

Supports both hash and argument assignment

fpm_attributes[:attr1] = xxxx
fpm_attributes :xxxx=>1, :yyyy=>2


90
91
92
93
94
95
# File 'lib/fpm/cookery/recipe.rb', line 90

def fpm_attributes(args=nil)
  if args.is_a?(Hash)
    @fpm_attributes.merge!(args)
  end
  @fpm_attributes
end

.inherited(klass) ⇒ Object



34
35
36
37
38
39
# File 'lib/fpm/cookery/recipe.rb', line 34

def self.inherited(klass)
  super
  # Apply class data inheritable pattern to @fpm_attributes
  # class variable.
  klass.instance_variable_set(:@fpm_attributes, self.fpm_attributes.dup)
end

.platformObject



79
80
81
# File 'lib/fpm/cookery/recipe.rb', line 79

def platform
  FPM::Cookery::Facts.platform
end

.platforms(valid_platforms) ⇒ Object



41
42
43
# File 'lib/fpm/cookery/recipe.rb', line 41

def self.platforms(valid_platforms)
  Array(valid_platforms).member?(self.platform) and block_given? ? yield : false
end

Instance Method Details

#builddir(path = nil) ⇒ Object



119
# File 'lib/fpm/cookery/recipe.rb', line 119

def builddir(path = nil) (@builddir || tmp_root('tmp-build'))/path   end

#builddir=(value) ⇒ Object



112
# File 'lib/fpm/cookery/recipe.rb', line 112

def builddir=(value) @builddir = Path.new(value) end

#cachedir(path = nil) ⇒ Object



121
# File 'lib/fpm/cookery/recipe.rb', line 121

def cachedir(path = nil) (@cachedir || workdir('cache'))/path       end

#cachedir=(value) ⇒ Object



114
# File 'lib/fpm/cookery/recipe.rb', line 114

def cachedir=(value) @cachedir = Path.new(value) end

#depends_allObject

Resolve dependencies from omnibus package.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fpm/cookery/recipe.rb', line 125

def depends_all
  pkg_depends = self.class.depends_all
  if self.class.omnibus_package
    self.class.omnibus_recipes.each { |omni_recipe|
      recipe_file = File.expand_path(omni_recipe + '.rb', File.dirname(filename))

      Book.instance.load_recipe(recipe_file, config) do |recipe|
        pkg_depends << recipe.depends_all
      end
    }
  end

  pkg_depends.flatten.uniq
end

#destdir(path = nil) ⇒ Object



118
# File 'lib/fpm/cookery/recipe.rb', line 118

def destdir(path = nil)  (@destdir  || tmp_root('tmp-dest'))/path    end

#destdir=(value) ⇒ Object



111
# File 'lib/fpm/cookery/recipe.rb', line 111

def destdir=(value)  @destdir  = Path.new(value) end

#fpm_attributesObject



122
# File 'lib/fpm/cookery/recipe.rb', line 122

def fpm_attributes() self.class.fpm_attributes end

#pkgdir(path = nil) ⇒ Object



120
# File 'lib/fpm/cookery/recipe.rb', line 120

def pkgdir(path = nil)   (@pkgdir   || workdir('pkg'))/path         end

#pkgdir=(value) ⇒ Object



113
# File 'lib/fpm/cookery/recipe.rb', line 113

def pkgdir=(value)   @pkgdir   = Path.new(value) end

#tmp_root(path = nil) ⇒ Object



117
# File 'lib/fpm/cookery/recipe.rb', line 117

def tmp_root(path = nil) @tmp_root/path                              end

#tmp_root=(value) ⇒ Object



110
# File 'lib/fpm/cookery/recipe.rb', line 110

def tmp_root=(value) @tmp_root = Path.new(value) end

#workdir(path = nil) ⇒ Object



116
# File 'lib/fpm/cookery/recipe.rb', line 116

def workdir(path = nil)  @workdir/path                               end

#workdir=(value) ⇒ Object



109
# File 'lib/fpm/cookery/recipe.rb', line 109

def workdir=(value)  @workdir  = Path.new(value) end