Class: Webbynode::Commands::Tasks

Inherits:
Webbynode::Command show all
Defined in:
lib/webbynode/commands/tasks.rb

Constant Summary collapse

TasksPath =

Constants Paths to the webbynode task files

".webbynode/tasks"
BeforePushTasksFile =
".webbynode/tasks/before_push"
AfterPushTasksFile =
".webbynode/tasks/after_push"

Constants inherited from Webbynode::Command

Webbynode::Command::Aliases, Webbynode::Command::CommandError, Webbynode::Command::InvalidCommand, Webbynode::Command::InvalidOption, Webbynode::Command::Settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Webbynode::Command

add_alias, #api, class_for, command, command_class_name, description, for, #gemfile, #git, help, inherited, #io, #no?, #notify, option, #option, #options, options_help, #param, #param_values, parameter, #params, #params_hash, params_help, #pushand, #remote_executor, requires_initialization!, requires_options!, requires_pushed_application!, #run, #server, setting, #settings, summary, summary_help, usage, #validate_initialization, #validate_options, #yes?

Constructor Details

#initialize(*args) ⇒ Tasks

Returns a new instance of Tasks.



18
19
20
21
# File 'lib/webbynode/commands/tasks.rb', line 18

def initialize(*args)
  super
  @session_tasks = Array.new
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/webbynode/commands/tasks.rb', line 5

def action
  @action
end

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/webbynode/commands/tasks.rb', line 5

def command
  @command
end

#session_fileObject

Returns the value of attribute session_file.



5
6
7
# File 'lib/webbynode/commands/tasks.rb', line 5

def session_file
  @session_file
end

#session_tasksObject

Returns the value of attribute session_tasks.



5
6
7
# File 'lib/webbynode/commands/tasks.rb', line 5

def session_tasks
  @session_tasks
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/webbynode/commands/tasks.rb', line 5

def type
  @type
end

Instance Method Details

#ensure_tasks_folderObject

Ensures the presence of the .webbynode/tasks folder Will create the necessary task files when they are not available



60
61
62
63
64
65
# File 'lib/webbynode/commands/tasks.rb', line 60

def ensure_tasks_folder
  io.mkdir('.webbynode/tasks') unless io.directory?(".webbynode/tasks")
  %w[before_push after_push].each do |file|
    io.exec("touch .webbynode/tasks/#{file}") unless io.file_exists?(".webbynode/tasks/#{file}")
  end
end

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/webbynode/commands/tasks.rb', line 23

def execute
  
  # Ensures that the tasks folder (.webbynode/tasks) is present
  # Will create the task files if they are not present
  ensure_tasks_folder

  # Should parse the parameters
  parse_parameters
  
  # Sets the current path, extracted from @type
  set_session_file
  
  # Reads out the currently set tasks
  read_tasks(session_file)
  
  # Initializes either [add], [remove] or [show] depending on user input
  send(action)
  
end

#has_tasks?Boolean

Checks to see if the session_tasks has any tasks

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/webbynode/commands/tasks.rb', line 44

def has_tasks?
  return true unless session_tasks.empty?
  false
end

#read_tasks(file) ⇒ Object

Reads the tasks straight from the specified file and stores them inside (in order) the session_tasks method.



51
52
53
54
55
56
# File 'lib/webbynode/commands/tasks.rb', line 51

def read_tasks(file)
  @session_tasks = []
  io.read_file(file).each_line do |line|
    @session_tasks << line.gsub(/\n/,'') unless line.blank?
  end
end