Class: Ufo::DSL::TaskDefinition
- Inherits:
-
Object
- Object
- Ufo::DSL::TaskDefinition
- Defined in:
- lib/ufo/dsl/task_definition.rb
Instance Attribute Summary collapse
-
#task_definition_name ⇒ Object
readonly
Returns the value of attribute task_definition_name.
Instance Method Summary collapse
- #build ⇒ Object
- #check_source_path(path) ⇒ Object
-
#helper ⇒ Object
delegate helper method back up to dsl.
-
#initialize(dsl, task_definition_name, options = {}, &block) ⇒ TaskDefinition
constructor
A new instance of TaskDefinition.
-
#source(name) ⇒ Object
at this point instance_eval has been called and source has possibly been called.
- #source_path ⇒ Object
- #template_scope ⇒ Object
- #variables(vars = {}) ⇒ Object
Constructor Details
#initialize(dsl, task_definition_name, options = {}, &block) ⇒ TaskDefinition
Returns a new instance of TaskDefinition.
8 9 10 11 12 13 |
# File 'lib/ufo/dsl/task_definition.rb', line 8 def initialize(dsl, task_definition_name, ={}, &block) @dsl = dsl @task_definition_name = task_definition_name @block = block @options = end |
Instance Attribute Details
#task_definition_name ⇒ Object (readonly)
Returns the value of attribute task_definition_name.
7 8 9 |
# File 'lib/ufo/dsl/task_definition.rb', line 7 def task_definition_name @task_definition_name end |
Instance Method Details
#build ⇒ Object
24 25 26 27 28 |
# File 'lib/ufo/dsl/task_definition.rb', line 24 def build instance_eval(&@block) vars = template_scope.assign_instance_variables RenderMePretty.result(source_path, vars) end |
#check_source_path(path) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ufo/dsl/task_definition.rb', line 56 def check_source_path(path) unless File.exist?(path) friendly_path = path.sub("#{Ufo.root}/", '') puts "ERROR: Could not find the #{friendly_path} template. Are sure it exists? Check where you called source in ufo/task_definitions.rb" exit 1 else puts "#{task_definition_name} template definition using project template: #{path}" unless @options[:mute] end path end |
#helper ⇒ Object
delegate helper method back up to dsl
16 17 18 |
# File 'lib/ufo/dsl/task_definition.rb', line 16 def helper @dsl.helper end |
#source(name) ⇒ Object
at this point instance_eval has been called and source has possibly been called
31 32 33 |
# File 'lib/ufo/dsl/task_definition.rb', line 31 def source(name) @source = name end |
#source_path ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ufo/dsl/task_definition.rb', line 44 def source_path if @source # this means that source has been called path = "#{Ufo.root}/.ufo/templates/#{@source}.json.erb" check_source_path(path) else # default source path path = File.("../../default/templates/main.json.erb", __FILE__) puts "#{task_definition_name} template definition using default template: #{path}" unless @options[:mute] end path end |
#template_scope ⇒ Object
20 21 22 |
# File 'lib/ufo/dsl/task_definition.rb', line 20 def template_scope @template_scope ||= Ufo::TemplateScope.new(helper) end |
#variables(vars = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/ufo/dsl/task_definition.rb', line 35 def variables(vars={}) vars.each do |var,value| if instance_variable_defined?("@#{var}") puts "WARNING: The instance variable @#{var} is already used internally with ufo. Please name you variable another name!" end template_scope.instance_variable_set("@#{var}", value) end end |