Class: Flombe::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/flombe/dsl.rb

Constant Summary collapse

CHEF_METHODS =
%w(cookbook_path sandbox_path file_cache_path file_backup_path json_attribs log_level log_location verbose_logging node_name node_path solo ssl_verify_mode umask recipe_url cache_type cache_options)
BASE_COOKBOOKS =
[File.expand_path('../../../cookbooks', __FILE__)]
FLOMBE_BASE =
"#{ENV['HOME']}/.flombe"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



15
16
17
18
# File 'lib/flombe/dsl.rb', line 15

def initialize
  @config  = {}
  @recipes = {}
end

Class Method Details

.evaluate(flombefile) ⇒ Object



9
10
11
12
13
# File 'lib/flombe/dsl.rb', line 9

def self.evaluate(flombefile)
  builder = new
  builder.instance_eval(File.open(flombefile, "rb") { |f| f.read }, flombefile.to_s, 1)
  builder
end

Instance Method Details

#configObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flombe/dsl.rb', line 20

def config
  cookbooks = @config.delete(:cookbook_path)
  cookbooks = [cookbooks] if cookbooks.kind_of? String
  {
    :file_cache_path  => "#{FLOMBE_BASE}/cache",
    :file_backup_path => "#{FLOMBE_BASE}/backup",
    :sandbox_path     => "#{FLOMBE_BASE}/sandbox",
    :log_level        => :info,
    :log_location     => STDOUT,
    :cookbook_path    => BASE_COOKBOOKS + (cookbooks || []),
    :cache_options    => {:path => "#{FLOMBE_BASE}/cache/checksums", :skip_expires => true}
  }.merge!(@config)
end

#recipe(name, *args) ⇒ Object



51
52
53
54
# File 'lib/flombe/dsl.rb', line 51

def recipe(name, *args)
  options = Hash === args.last ? args.pop : {}
  @recipes[name.to_sym] = options
end

#rubies(rubies, *args) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/flombe/dsl.rb', line 56

def rubies(rubies, *args)
  @recipes[:rvm] = {} unless @recipes.has_key?(:rvm)
  
  rubies = [rubies] if rubies.is_a? String
  @recipes[:rvm][:rubies] = rubies
  
  options = Hash === args.last ? args.pop : {}
  @recipes[:rvm][:default_ruby] = options[:default] unless options[:default].nil?
end

#to_dnaObject



34
35
36
37
38
# File 'lib/flombe/dsl.rb', line 34

def to_dna
  {
    :recipes => @recipes.keys
  }.merge!(@recipes).to_json
end

#to_solo_configObject



40
41
42
43
# File 'lib/flombe/dsl.rb', line 40

def to_solo_config
  template = File.open(File.expand_path('../../../templates/chef_solo.erb', __FILE__), "r") { |f| f.read }
  Erubis::Eruby.new(template).result(:config => config)
end