Module: Blender::Manifest::Mixer

Defined in:
lib/blender/manifest/mixer.rb

Instance Method Summary collapse

Instance Method Details

#cookbook(cb, version) ⇒ Object

installs cookbook gems if needed and loads them into the environment



3
4
5
6
7
8
9
10
11
# File 'lib/blender/manifest/mixer.rb', line 3

def cookbook(cb, version)
  # skip cookbooks that are unapcked into the /cookbooks/ directory
  return if File.directory?("cookbooks/#{cb}/files") || File.directory?("cookbooks/#{cb}/lib")

  gem cb, version
rescue Gem::LoadError
  system "gem install --no-ri --no-rdoc #{cb} -v#{version}"
  gem cb, version
end

#mix(*recipes) ⇒ Object

mixes recipe module

The purpose is to make the mixing of recipes cleaner and easier on the eyes :) i.e. instead of

require 'foo'
include Blender::Recipes::Foo
require 'bar'
include Blender::Recipes::Bar

you can just

mix :foo, :bar

Parameters:

  • recipes ([String, Symbol, Module])

    to mix



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blender/manifest/mixer.rb', line 24

def mix(*recipes)

  recipes.each do |recipe|

    next if Root.mixed_recipes.include?(recipe)
    Root.mixed_recipes << recipe

    case recipe
    when String, Symbol
      require recipe.to_s
      mixin = "Blender::Recipes::#{recipe.to_s.camelize}".constantize
    when Module
      mixin = recipe
    else
      raise "Expecting String, Symbol or Module. don't know what do do with #{recipe.inspect}"
    end

    puts "MIX: #{mixin}"
    ::Root.send :include, mixin
  end
end