Class: Cany::Recipe
- Inherits:
-
Object
- Object
- Cany::Recipe
- Defined in:
- lib/cany/recipe.rb
Direct Known Subclasses
Dpkg::DebHelperRecipe, Cany::Recipes::Bundler, Cany::Recipes::Rails, Cany::Recipes::WebServer
Instance Attribute Summary collapse
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Class Method Summary collapse
-
.from_name(name) ⇒ Cany::Recipe?
Looks for the class registered for the given name.
-
.register_as(name) ⇒ Object
This method should be call in subclasses to register new recipe instances.
Instance Method Summary collapse
-
#binary ⇒ Object
create binary (package) version of this file (means make install).
-
#build ⇒ Object
build the program (means ./configure and make).
-
#clean ⇒ Object
clean the build directory from all temporary and created files.
-
#exec(*args) ⇒ Object
Run a command inside the build directory.
-
#initialize(spec, inner) ⇒ Recipe
constructor
Creates a new instance of this recipe.
-
#install(src, dest_dir) ⇒ Object
Install files or directory from the build directory.
-
#install_content(filename, content) ⇒ Object
Install a file.
-
#install_dir(path) ⇒ Object
Installs/creates an empty directory.
-
#install_link(source, destination) ⇒ Object
Create a file named destination as a link to a file named source.
-
#rmtree(*args) ⇒ Object
Ensure that the given files or directories are no present.
-
#ruby_bin(*args) ⇒ Object
Run a ruby task (like gem, bundler, rake …).
Constructor Details
#initialize(spec, inner) ⇒ Recipe
Creates a new instance of this recipe
29 30 31 32 |
# File 'lib/cany/recipe.rb', line 29 def initialize(spec, inner) @spec = spec @inner = inner end |
Instance Attribute Details
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
34 35 36 |
# File 'lib/cany/recipe.rb', line 34 def inner @inner end |
#spec ⇒ Object (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
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.
11 12 13 14 |
# File 'lib/cany/recipe.rb', line 11 def self.register_as(name) @@recipes ||= {} @@recipes[name] = self end |
Instance Method Details
#binary ⇒ Object
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 |
#build ⇒ Object
build the program (means ./configure and make)
118 119 120 |
# File 'lib/cany/recipe.rb', line 118 def build inner.build end |
#clean ⇒ Object
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:
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
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.
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
88 89 90 |
# File 'lib/cany/recipe.rb', line 88 def install_dir(path) exec 'dh_installdirs', path end |
#install_link(source, destination) ⇒ Object
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 |