class FPM::Fry::Recipe::Builder
Constants
- NEG_INF
Attributes
keep_modified_files[R]
recipe[R]
@return [FPM::Fry::Recipe]
Public Class Methods
new( variables, options = {} )
click to toggle source
@param [Hash<Symbol,Object>] variables @param [Hash] options @option options [FPM::Fry::Recipe] :recipe (Recipe.new
) @option options [Cabin::Channel] :logger (default cabin channel) @option options [FPM::Fry::Inspector] :inspector
Calls superclass method
FPM::Fry::Recipe::PackageBuilder::new
# File lib/fpm/fry/recipe/builder.rb, line 210 def initialize( variables, options = {} ) recipe = options.fetch(:recipe){ Recipe.new } variables = variables.dup variables.freeze @recipe = recipe @steps = :steps register_default_source_types! super(variables, recipe.packages[0], options) end
Public Instance Methods
add(source, target)
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 241 def add(source, target) recipe.build_mounts << [source, target] end
apt_setup(cmd)
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 245 def apt_setup(cmd) before_dependencies do bash cmd end end
bash( name = nil, code )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 262 def bash( name = nil, code ) if name code = Recipe::Step.new(name, code) end # Don't do this at home case(@steps) when :before_dependencies recipe.before_dependencies_steps << code when :before_build recipe.before_build_steps << code else recipe.steps << code end end
before_build() { || ... }
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 277 def before_build steps, @steps = @steps, :before_build yield ensure @steps = steps end
before_dependencies() { || ... }
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 284 def before_dependencies steps, @steps = @steps, :before_dependencies yield ensure @steps = steps end
build_depends( name , options = {} )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 291 def build_depends( name , options = {} ) name, options = parse_package(name, options) recipe.build_depends[name] = options end
input_hooks()
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 296 def input_hooks recipe.input_hooks end
keep_modified_files!()
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 311 def keep_modified_files! @keep_modified_files = true end
load_file( file )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 220 def load_file( file ) file = File.expand_path(file) begin content = IO.read(file) rescue Errno::ENOENT => e raise NotFound, e end basedir = File.dirname(file) Dir.chdir(basedir) do instance_eval(content,file,0) end end
package(name, &block)
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 300 def package(name, &block) pr = PackageRecipe.new pr.name = name pr.version = package_recipe.version pr.iteration = package_recipe.iteration recipe.packages << pr PackageBuilder.new(variables, pr, logger: logger, inspector: inspector).instance_eval(&block) end
run(*args)
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 251 def run(*args) if args.first.kind_of? Hash options = args.shift else options = {} end command = args.shift name = options.fetch(:name){ [command,*args].select{|c| c[0] != '-' }.join(' ') } bash( name, Shellwords.join([command, *args]) ) end
source( url , options = {} )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 233 def source( url , options = {} ) options = options.merge(logger: logger) source = Source::Patched.decorate(options) do |options| guess_source(url,options).new(url, options) end recipe.source = source end
Protected Instance Methods
guess_source( url, options = {} )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 341 def guess_source( url, options = {} ) if w = options[:with] return source_types.fetch(w){ raise ArgumentError.new("Unknown source type: #{w}") } end scores = source_types.values.uniq\ .select{|klass| klass.respond_to? :guess }\ .group_by{|klass| klass.guess(url) }\ .sort_by{|score,_| score.nil? ? NEG_INF : score } score, klasses = scores.last if score == nil raise Error.new("No source provider found for #{url}.\nMaybe try explicitly setting the type using :with parameter. Valid options are: #{source_types.keys.join(', ')}") end if klasses.size != 1 raise Error.new("Multiple possible source providers found for #{url}: #{klasses.join(', ')}.\nMaybe try explicitly setting the type using :with parameter. Valid options are: #{source_types.keys.join(', ')}") end return klasses.first end
register_default_source_types!()
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 333 def register_default_source_types! register_source_type Source::Git register_source_type Source::Archive register_source_type Source::Dir end
register_source_type( klass )
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 321 def register_source_type( klass ) if !klass.respond_to? :new raise ArgumentError.new("Expected something that responds to :new, got #{klass.inspect}") end source_types[klass.name] = klass if klass.respond_to? :aliases klass.aliases.each do |al| source_types[al] = klass end end end
source_types()
click to toggle source
# File lib/fpm/fry/recipe/builder.rb, line 317 def source_types @source_types ||= {} end