Class: Blueprint

Inherits:
Object
  • Object
show all
Includes:
BlueprintComponents, Utils
Defined in:
lib/blueprint/blueprint.rb

Constant Summary

Constants included from BlueprintComponents

BlueprintComponents::BLUEPRINT_TRANSLATIONS

Instance Method Summary collapse

Methods included from BlueprintComponents

add_child, #aggregate, #definition, #dependency, #no_op, #parameter

Methods included from Utils::ClassMethods

#const_lookup, #const_resolve, #deep_copy, #doodle_caller, #flatten_first_level, #normalize_const, #normalize_keys, #normalize_keys!, #pluralize, #snake_case, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #try

Constructor Details

#initialize(s) ⇒ Blueprint

Returns a new instance of Blueprint.



10
11
12
13
14
15
16
# File 'lib/blueprint/blueprint.rb', line 10

def initialize(s)
  if s.is_a?(Hash)
    @def = s
  else
    @def[:label] = s
  end
end

Instance Method Details

#attributes(attrs) ⇒ Object



55
56
57
# File 'lib/blueprint/blueprint.rb', line 55

def attributes(attrs)
  @def[:attributes] = attrs
end

#outputs(attrs) ⇒ Object



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

def outputs(attrs)
  @def[:output_params] = attrs
end

#provides(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blueprint/blueprint.rb', line 18

def provides(*args)
  opts = args.last.is_a?(Hash) ? args.pop : nil
  s = (@def[:content] = args.pop)
  
  if opts
    @def.merge!(opts)
    
  else
    @def[:content] ||= s
    @def[:script] = "#{s}.sh"
    @def[:email] = "#{s}.markdown" if @def[:item_type] == "readystack"
    @def[:item_type] ||= "stack"
    
  end
  
  (errors ||= []) << "provides requires the blueprint name" if @def.empty?
  (errors ||= []) << "no blueprint name found" unless @def.has_key?(:content)
  (errors ||= []) << "no script found for #{@def[:content]}" unless @def.has_key?(:script)
  
  if @def[:item_type] == "readystack" and not @def[:email]
    (warnings ||= []) << "no email template found for #{@def[:content]}"
  end
  
  puts "Warning: #{warnings * ", "}" if warnings
  raise "Errors: #{errors * ", "}" if errors
end

#requires(req) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/blueprint/blueprint.rb', line 45

def requires(req)
  if req.is_a?(Hash)
    requirement_def = { :group => req[:group], :contains => req[:with] }
  else
    requirement_def = { :group => req, :contains => [req] }
  end
  
  (@def[:dependencies] ||= []) << requirement_def
end

#to_yamlObject



63
64
65
# File 'lib/blueprint/blueprint.rb', line 63

def to_yaml
  stringify_keys(@def, true).to_yaml
end