Class: Cany::Recipe

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, inner) ⇒ Recipe

Creates a new instance of this recipe

Parameters:

  • spec (Cany::Specification)

    Specification object

  • inner (Cany::Recipe, nil)

    Inner recipes should should be call between the pre and post actions of this class. Nil means most inner recipes.



29
30
31
32
# File 'lib/cany/recipe.rb', line 29

def initialize(spec, inner)
  @spec = spec
  @inner = inner
end

Instance Attribute Details

#innerObject (readonly)

Returns the value of attribute inner.



34
35
36
# File 'lib/cany/recipe.rb', line 34

def inner
  @inner
end

#specObject (readonly)

Returns the value of attribute spec.



34
35
36
# File 'lib/cany/recipe.rb', line 34

def spec
  @spec
end

Class Method Details

.from_name(name) ⇒ Cany::Recipe?

Looks for the class registered for the given name

Parameters:

  • name (Symbol)

    the name the class is search for

Returns:

  • (Cany::Recipe, nil)

    Returns the found class or nil if no class is registered on this name



21
22
23
# File 'lib/cany/recipe.rb', line 21

def self.from_name(name)
  @@recipes[name]
end

.register_as(name) ⇒ Object

This method should be call in subclasses to register new recipe instances. Cany ignores any recipe subclasses which does not call register_as. If multiple recipes register on the same name the later one will overwrite the earlier one and therefore used by Cany.

Parameters:

  • name (Symbol)

    A ruby symbol as name for the recipe. It should be short and recognizable



11
12
13
14
# File 'lib/cany/recipe.rb', line 11

def self.register_as(name)
  @@recipes ||= {}
  @@recipes[name] = self
end

Instance Method Details

#binaryObject

create binary (package) version of this file (means make install)



124
125
126
# File 'lib/cany/recipe.rb', line 124

def binary
  inner.binary
end

#buildObject

build the program (means ./configure and make)



118
119
120
# File 'lib/cany/recipe.rb', line 118

def build
  inner.build
end

#cleanObject

clean the build directory from all temporary and created files



112
113
114
# File 'lib/cany/recipe.rb', line 112

def clean
  inner.clean
end

#exec(*args) ⇒ Object

Run a command inside the build directory. In most cases it is not needed to call this method directly. Look at the other helper methods.

The method expects as arguments the program name and additional parameters for the program. The arguments can be group with arguments, but must not:

Examples:

exec 'echo', %w(a b)
exec ['echo', 'a', 'b']
exec 'echo', 'a', 'b'


49
50
51
52
# File 'lib/cany/recipe.rb', line 49

def exec(*args)
  puts "   #{args.flatten.join(' ')}"
  system *args.flatten
end

#install(src, dest_dir) ⇒ Object

Install files or directory from the build directory

Parameters:

  • source (String)

    The relative file name to a filename or directory inside the build directory that should be installed/copied into the destination package

  • destination (String)

    The diretory name into that the file or directory should be installed



69
70
71
# File 'lib/cany/recipe.rb', line 69

def install(src, dest_dir)
  exec 'dh_install', src, dest_dir
end

#install_content(filename, content) ⇒ Object

Install a file. The content is passed as argument. This method is designed to be used by recipes to create files dynamically.

Parameters:

  • filename (String)

    The absolute file name for the file inside the package.

  • content (String)

    The file content



78
79
80
81
82
83
# File 'lib/cany/recipe.rb', line 78

def install_content(filename, content)
  FileUtils.mkdir_p File.dirname File.join('debian', spec.name, filename)
  File.open File.join('debian', spec.name, filename), 'w' do |f|
    f.write content
  end
end

#install_dir(path) ⇒ Object

Installs/creates an empty directory

Parameters:

  • path (String)

    The path name



88
89
90
# File 'lib/cany/recipe.rb', line 88

def install_dir(path)
  exec 'dh_installdirs', path
end

Create a file named destination as a link to a file named source



94
95
96
# File 'lib/cany/recipe.rb', line 94

def install_link(source, destination)
  exec 'dh_link', source, destination
end

#rmtree(*args) ⇒ Object

Ensure that the given files or directories are no present. Directories are removed recursively.



101
102
103
104
105
# File 'lib/cany/recipe.rb', line 101

def rmtree(*args)
  args.flatten.each do |path|
    ::FileUtils.remove_entry path if File.exists? path
  end
end

#ruby_bin(*args) ⇒ Object

Run a ruby task (like gem, bundler, rake …)

The method expects as arguments the program name and additional parameters for the program. See exec for more examples



59
60
61
# File 'lib/cany/recipe.rb', line 59

def ruby_bin(*args)
  exec RbConfig.ruby, '-S', *args
end