Class: FPM::Fry::Recipe::PackageRecipe

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/fry/recipe.rb

Constant Summary collapse

SYNTAX_CHECK_SHELLS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

['/bin/sh','/bin/bash', '/bin/dash']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePackageRecipe

Returns a new instance of PackageRecipe.



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

def initialize
  @name = nil
  @iteration = nil
  @version = '0.0.0'
  @maintainer = nil
  @vendor = nil
  @depends = {}
  @provides = {}
  @conflicts = {}
  @replaces = {}
  @scripts = {
    before_install: [],
    after_install:  [],
    before_remove:  [],
    after_remove:   []
  }
  @output_hooks = []
  @files = []
end

Instance Attribute Details

#conflictsObject

Returns the value of attribute conflicts.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def conflicts
  @conflicts
end

#dependsObject Also known as: dependencies

Returns the value of attribute depends.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def depends
  @depends
end

#filesObject

Returns the value of attribute files.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def files
  @files
end

#iterationObject

Returns the value of attribute iteration.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def iteration
  @iteration
end

#maintainerObject

Returns the value of attribute maintainer.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def maintainer
  @maintainer
end

#nameObject

Returns the value of attribute name.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def name
  @name
end

#output_hooksObject

Returns the value of attribute output_hooks.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def output_hooks
  @output_hooks
end

#providesObject

Returns the value of attribute provides.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def provides
  @provides
end

#recommendsObject

Returns the value of attribute recommends.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def recommends
  @recommends
end

#replacesObject

Returns the value of attribute replaces.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def replaces
  @replaces
end

#scriptsObject

Returns the value of attribute scripts.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def scripts
  @scripts
end

#suggestsObject

Returns the value of attribute suggests.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def suggests
  @suggests
end

#vendorObject

Returns the value of attribute vendor.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version.



27
28
29
# File 'lib/fpm/fry/recipe.rb', line 27

def version
  @version
end

Instance Method Details

#apply_output(package) ⇒ FPM::Package Also known as: apply

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies settings to output package

Parameters:

  • package (FPM::Package)

Returns:

  • (FPM::Package)

    package



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fpm/fry/recipe.rb', line 69

def apply_output( package )
  output_hooks.each{|h| h.call(self, package) }
  package.name = name
  package.version = version
  package.iteration = iteration
  package.maintainer = maintainer if maintainer
  package.vendor = vendor if vendor
  scripts.each do |type, scripts|
    package.scripts[type] = scripts.join("\n") if scripts.any?
  end
  [:dependencies, :conflicts, :replaces, :provides].each do |sym|
    send(sym).each do |name, options|
      constr = Array(options[:constraints])
      if constr.any?
        constr.each do | c |
          package.send(sym) << "#{name} #{c}"
        end
      else
        package.send(sym) << name
      end
    end
  end
  return package
end

#lintArray<String>

Lints the settings for some common problems

Returns:

  • (Array<String>)

    problems



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fpm/fry/recipe.rb', line 101

def lint
  problems = []
  problems << "Name is empty." if name.to_s == ''
  scripts.each do |type,scripts|
    next if scripts.none?
    s = scripts.join("\n")
    if s == ''
      problems << "#{type} script is empty. This will produce broken packages."
      next
    end
    m = /\A#!([^\n]+)\n/.match(s)
    if !m
      problems << "#{type} script doesn't have a valid shebang"
      next
    end
    begin
      args = m[1].shellsplit
    rescue ArgumentError => e
      problems << "#{type} script doesn't have a valid command in shebang"
    end
    if SYNTAX_CHECK_SHELLS.include? args[0]
      begin
        Exec::exec(args[0],'-n', stdin_data: s)
      rescue Exec::Failed => e
        problems << "#{type} script is not valid #{args[0]} code: #{e.stderr.chomp}"
      end
    end
  end
  return problems
end