Class: Pike::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/pike/tasks/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Task

Constructor



9
10
11
12
13
14
# File 'lib/pike/tasks/task.rb', line 9

def initialize(name, &block)
  @block = block
  @current_env = nil
  @current_params = {}
  @name = name
end

Instance Attribute Details

#current_envObject

Returns the value of attribute current_env.



3
4
5
# File 'lib/pike/tasks/task.rb', line 3

def current_env
  @current_env
end

Instance Method Details

#get_param(key, default = nil) ⇒ Object



59
60
61
62
63
# File 'lib/pike/tasks/task.rb', line 59

def get_param(key, default = nil)
  return @current_params[key] if param_given?(key)
  return default if default
  undef_error(:param, key)
end

#get_var(key, default = nil) ⇒ Object

Called from the DSL to get the value of a varaible



46
47
48
49
50
# File 'lib/pike/tasks/task.rb', line 46

def get_var(key, default = nil)
  return @current_env.get_var(key) if var_given?(key)
  return default if default
  undef_error(:variable, key)
end

#param_given?(key) ⇒ Boolean

Checks if a param with the given key is defined

Returns:

  • (Boolean)


70
71
72
# File 'lib/pike/tasks/task.rb', line 70

def param_given?(key)
  @current_params.include?(key)
end

#run(env, params) ⇒ Object

Call run that task



21
22
23
24
25
26
27
28
29
30
# File 'lib/pike/tasks/task.rb', line 21

def run(env, params)
  log_header

  # Setting @current_params and @current_env
  set_current_params params
  @current_env = env

  # Parse the task block
  DSL::Task.load(self, &@block)
end

#run_task(task) ⇒ Object

Called from the DSL to run another task



37
38
39
# File 'lib/pike/tasks/task.rb', line 37

def run_task(task)
  @current_env.run_task(task)
end

#var_given?(key) ⇒ Boolean

Checks if a variable with the given key is defined

Returns:

  • (Boolean)


79
80
81
# File 'lib/pike/tasks/task.rb', line 79

def var_given?(key)
  (@current_env.get_var(key) != nil)
end