Module: Ufo::TaskDefinition::Context

Includes:
DslEvaluator, Helpers
Included in:
Erb
Defined in:
lib/ufo/task_definition/context.rb

Instance Method Summary collapse

Instance Method Details

#load_contextObject



6
7
8
9
# File 'lib/ufo/task_definition/context.rb', line 6

def load_context
  load_variables
  load_custom_helpers
end

#load_custom_helpersObject



18
19
20
# File 'lib/ufo/task_definition/context.rb', line 18

def load_custom_helpers
  load_helper_files("#{Ufo.root}/.ufo/helpers")
end

#load_helper_files(dir) ⇒ Object

Load custom project helper methods



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ufo/task_definition/context.rb', line 23

def load_helper_files(dir)
  paths = Dir.glob("#{dir}/**/*.rb")
  paths.sort_by! { |p| p.size } # so namespaces are loaded first
  paths.each do |path|
    next unless File.file?(path)

    filename = path.sub(%r{.*/helpers/},'').sub('.rb','')
    module_name = filename.camelize

    # Prepend a period so require works when UFO_ROOT is set to a relative path without a period.
    #   Example: UFO_ROOT=tmp/ufo_project
    first_char = path[0..0]
    path = "./#{path}" unless %w[. /].include?(first_char)

    # Examples:
    #     path:        .ufo/helpers/custom_helper.rb
    #     module_name: CustomHelper
    require path
    self.class.send :include, module_name.constantize
  end
end

#load_variablesObject



11
12
13
14
15
16
# File 'lib/ufo/task_definition/context.rb', line 11

def load_variables
  layers = Ufo::Layering::Layer.new(@task_definition).paths
  layers.each do |layer|
    evaluate_file(layer)
  end
end