Class: WtiTasks::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/wti_tasks/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_projectsObject



3
4
5
# File 'lib/wti_tasks/commands.rb', line 3

def self.find_projects
  new.find_projects
end

.pull(*args) ⇒ Object



7
8
9
# File 'lib/wti_tasks/commands.rb', line 7

def self.pull(*args)
  new.pull(*args)
end

.push(*args) ⇒ Object



11
12
13
# File 'lib/wti_tasks/commands.rb', line 11

def self.push(*args)
  new.push(*args)
end

Instance Method Details

#build_command(command, filename) ⇒ Object



57
58
59
# File 'lib/wti_tasks/commands.rb', line 57

def build_command(command, filename)
  "wti #{command} -c #{filename}" << options
end

#file_listObject



27
28
29
# File 'lib/wti_tasks/commands.rb', line 27

def file_list
  Dir.glob '.wti*'
end

#find_projectsObject



15
16
17
# File 'lib/wti_tasks/commands.rb', line 15

def find_projects
  project_names file_list
end

#options(argv = ARGV) ⇒ Object



61
62
63
64
# File 'lib/wti_tasks/commands.rb', line 61

def options(argv = ARGV)
  argv[0] = nil
  argv.join(' ')
end

#project_name(file) ⇒ Object



38
39
40
41
42
# File 'lib/wti_tasks/commands.rb', line 38

def project_name(file)
  file = strip_prefix(file)
  file = rename_default(file)
  file.to_sym
end

#project_names(files) ⇒ Object



31
32
33
34
35
36
# File 'lib/wti_tasks/commands.rb', line 31

def project_names(files)
  files.inject({}) do |result, f|
    result[project_name(f)] = f
    result
  end
end

#pull(filename) ⇒ Object



19
20
21
# File 'lib/wti_tasks/commands.rb', line 19

def pull(filename)
  run_command(:pull, filename)
end

#push(filename) ⇒ Object



23
24
25
# File 'lib/wti_tasks/commands.rb', line 23

def push(filename)
  run_command(:push, filename)
end

#rename_default(file) ⇒ Object



48
49
50
# File 'lib/wti_tasks/commands.rb', line 48

def rename_default(file)
  file == '.wti' ? 'default' : file
end

#run_command(command, filename) ⇒ Object



52
53
54
55
# File 'lib/wti_tasks/commands.rb', line 52

def run_command(command, filename)
  wti_command = build_command command, filename
  `#{wti_command}`
end

#strip_prefix(file) ⇒ Object



44
45
46
# File 'lib/wti_tasks/commands.rb', line 44

def strip_prefix(file)
  file.gsub(/\.wti-/, '')
end