Module: Ufo::TaskDefinition::Context
Instance Method Summary collapse
- #load_context ⇒ Object
- #load_custom_helpers ⇒ Object
-
#load_helper_files(dir) ⇒ Object
Load custom project helper methods.
- #load_variables ⇒ Object
Instance Method Details
#load_context ⇒ Object
6 7 8 9 |
# File 'lib/ufo/task_definition/context.rb', line 6 def load_context load_variables load_custom_helpers end |
#load_custom_helpers ⇒ Object
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 |