Module: Recipe
- Defined in:
- lib/recipe.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #change_binding(binding) ⇒ Object
- #clean_stack! ⇒ Object
- #cron(title, &block) ⇒ Object
- #cron_append(object) ⇒ Object
- #cron_variable(title, variable) ⇒ Object
- #directory(name, &block) ⇒ Object
- #execute(title, &block) ⇒ Object
- #file(target, &block) ⇒ Object
- #gem_package(name, &block) ⇒ Object
- #git(repository, &block) ⇒ Object
- #hook(target) ⇒ Object
- #include_file(file_type, some_file) ⇒ Object
- #include_recipe(name) ⇒ Object
- #init(binding) ⇒ Object
- #link(source, &block) ⇒ Object
- #load_recipes(recipes_target, list) ⇒ Object
- #node ⇒ Object
- #package(package_name, &block) ⇒ Object
- #remote_file(target, &block) ⇒ Object
- #resource_not_supported(*args) ⇒ Object
- #server_ip_address ⇒ Object
- #service(name, &block) ⇒ Object
- #setup_crontab ⇒ Object
- #stack_append(object) ⇒ Object
- #status ⇒ Object
- #summary ⇒ Object
- #swap_release(release_path, &block) ⇒ Object
- #system_group(groupname, &block) ⇒ Object
- #template(name, &block) ⇒ Object
- #transaction(&block) ⇒ Object
- #user(username, &block) ⇒ Object
- #version(location, &block) ⇒ Object
- #whoami ⇒ Object
Instance Attribute Details
#stack ⇒ Object
Returns the value of attribute stack.
3 4 5 |
# File 'lib/recipe.rb', line 3 def stack @stack end |
Instance Method Details
#change_binding(binding) ⇒ Object
5 6 7 |
# File 'lib/recipe.rb', line 5 def change_binding binding @binding = binding end |
#clean_stack! ⇒ Object
18 19 20 |
# File 'lib/recipe.rb', line 18 def clean_stack! @stack = [] end |
#cron(title, &block) ⇒ Object
95 96 97 |
# File 'lib/recipe.rb', line 95 def cron title, &block cron_append ::Resource::Cron.new(title, &block) end |
#cron_append(object) ⇒ Object
22 23 24 25 |
# File 'lib/recipe.rb', line 22 def cron_append object @cron_jobs << object Output.info 'Cron job detected', object.get_title end |
#cron_variable(title, variable) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/recipe.rb', line 27 def cron_variable title, variable @cron_jobs ||= [] @cron_vars ||= [] @cron_vars << '' @cron_vars << "# #{title}" @cron_vars << variable end |
#directory(name, &block) ⇒ Object
66 67 68 |
# File 'lib/recipe.rb', line 66 def directory name, &block stack_append ::Resource::Directory.new(name, &block) end |
#execute(title, &block) ⇒ Object
79 80 81 |
# File 'lib/recipe.rb', line 79 def execute title, &block stack_append ::Resource::Execute.new(title, &block) end |
#file(target, &block) ⇒ Object
111 112 113 |
# File 'lib/recipe.rb', line 111 def file target, &block stack_append ::Resource::File.new(target, &block) end |
#gem_package(name, &block) ⇒ Object
70 71 72 |
# File 'lib/recipe.rb', line 70 def gem_package name, &block stack_append ::Resource::Gem.new(name, &block) end |
#git(repository, &block) ⇒ Object
91 92 93 |
# File 'lib/recipe.rb', line 91 def git repository, &block stack_append ::Resource::Git.new(repository, &block) end |
#hook(target) ⇒ Object
123 124 125 126 |
# File 'lib/recipe.rb', line 123 def hook target target = status.release_path + "/deploy/#{target}.rb" Resource::Hook.new(target, @binding).run end |
#include_file(file_type, some_file) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/recipe.rb', line 143 def include_file file_type, some_file unless ::File.exist? some_file Output.warn "#{file_type} file not found (skipping)", some_file return end eval(File.read(some_file), @binding) Output.info 'Executable units', stack.size end |
#include_recipe(name) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/recipe.rb', line 132 def include_recipe name @recipes ||= [] if @recipes.include? name Output.warn 'Already loaded recipe with name', name return end @recipes << name Output.info 'Including recipe', name include_file :Recipe, @recipes_target % name end |
#init(binding) ⇒ Object
9 10 11 12 |
# File 'lib/recipe.rb', line 9 def init binding change_binding binding stack end |
#link(source, &block) ⇒ Object
87 88 89 |
# File 'lib/recipe.rb', line 87 def link source, &block stack_append ::Resource::Link.new(source, &block) end |
#load_recipes(recipes_target, list) ⇒ Object
152 153 154 155 156 |
# File 'lib/recipe.rb', line 152 def load_recipes recipes_target, list Output. 'Loading', 'Instantiating recipes...' @recipes_target = recipes_target list.each { |recipe| include_recipe recipe } end |
#package(package_name, &block) ⇒ Object
74 75 76 77 |
# File 'lib/recipe.rb', line 74 def package package_name, &block block = Proc.new {} unless block stack_append ::Resource::Package.new(package_name, &block) end |
#remote_file(target, &block) ⇒ Object
107 108 109 |
# File 'lib/recipe.rb', line 107 def remote_file target, &block stack_append ::Resource::RemoteFile.new(target, &block) end |
#resource_not_supported(*args) ⇒ Object
14 15 16 |
# File 'lib/recipe.rb', line 14 def resource_not_supported *args Output.warn 'Resource not supported', args.inspect end |
#server_ip_address ⇒ Object
179 180 181 |
# File 'lib/recipe.rb', line 179 def server_ip_address (File.exist? 'env/ip') ? File.read('env/ip').chop : 'Unknown ip address' end |
#service(name, &block) ⇒ Object
99 100 101 |
# File 'lib/recipe.rb', line 99 def service name, &block stack_append ::Resource::Service.new(name, &block) end |
#setup_crontab ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/recipe.rb', line 35 def setup_crontab Output.jump Output.info 'Setting up nice cron jobs', 'this is sweeet root crontab!' Output.ruler t = ::Tempfile.new('temporal_crontab') @cron_vars.each do |line| t.puts line end @cron_jobs.each do |resource| t.puts '' t.puts "# #{resource.get_title}" t.puts "#{resource.run}" end t.close system "cat #{t.path} | crontab" system 'crontab -l' t.unlink end |
#stack_append(object) ⇒ Object
58 59 60 |
# File 'lib/recipe.rb', line 58 def stack_append object @stack << object end |
#summary ⇒ Object
158 159 160 161 162 |
# File 'lib/recipe.rb', line 158 def summary Output. 'Printing', 'Execution summary' Output.info 'Total Recipes', node[:recipes].size Output.info 'Total executable stack units', stack.size end |
#swap_release(release_path, &block) ⇒ Object
115 116 117 |
# File 'lib/recipe.rb', line 115 def swap_release release_path, &block stack_append ::Resource::SwapRelease.new(release_path, &block) end |
#system_group(groupname, &block) ⇒ Object
103 104 105 |
# File 'lib/recipe.rb', line 103 def system_group groupname, &block stack_append ::Resource::Group.new(groupname, &block) end |
#template(name, &block) ⇒ Object
62 63 64 |
# File 'lib/recipe.rb', line 62 def template name, &block stack_append ::Resource::Template.new(name, &block) end |
#transaction(&block) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/recipe.rb', line 168 def transaction &block yield rescue => e Output.error 'Rolling back', ' =:D ' raise e end |
#user(username, &block) ⇒ Object
83 84 85 |
# File 'lib/recipe.rb', line 83 def user username, &block stack_append ::Resource::User.new(username, &block) end |
#version(location, &block) ⇒ Object
119 120 121 |
# File 'lib/recipe.rb', line 119 def version location, &block stack_append ::Resource::Version.new(location, &block) end |
#whoami ⇒ Object
175 176 177 |
# File 'lib/recipe.rb', line 175 def whoami (File.exist? 'env/whoami') ? File.read('env/whoami').chop : 'Unknown user' end |