Class: Boa::Module

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/boa/module/module.rb

Constant Summary collapse

BASE_PATH =
'Classes/Modules'
FILES =
{
  'DataManager.h'     => 'DataManager',
  'DataManager.m'     => 'DataManager',
  'Interactor.h'      => 'Interactor',
  'Interactor.m'      => 'Interactor',
  'ModuleInterface.h' => 'ModuleInterface',
  'Presenter.h'       => 'Presenter',
  'Presenter.m'       => 'Presenter',
  'ViewInterface.h'   => 'View',
  'ViewController.h'  => 'View',
  'ViewController.m'  => 'View',
  'Wireframe.h'       => 'Wireframe',
  'Wireframe.m'       => 'Wireframe'
}

Instance Method Summary collapse

Instance Method Details

#create(module_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/boa/module/module.rb', line 35

def create(module_name)
  config = invoke('boa:commands:configure', [])

  @module  = module_name
  @author  = config[:author]
  @project = config[:project]
  @date    = Time.now.strftime('%d/%m/%y')

  # copying template files
  FILES.each do |file_name, folder|
    template "templates/#{file_name}", "#{BASE_PATH}/#{@module}/#{folder}/#{@module}#{file_name}"
  end

  # rendering dependencies head
  path = Dir::Tmpname.create('dep') { |path| path }
  template 'templates/DependenciesHead.m', path

  say "\nAdd these lines to the AppDependencies imports:\n\n", :green
  say File.open(path).read + "\n", :yellow

  # rendering dependencies body
  path = Dir::Tmpname.create('dep') { |path| path }
  template 'templates/DependenciesBody.m', path

  say "\nAdd these lines to the AppDependencies#configureDependencies:\n\n", :green
  say File.open(path).read + "\n", :yellow
end

#destroy(module_name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/boa/module/module.rb', line 64

def destroy(module_name)
  @module = module_name

  module_path = "#{BASE_PATH}/#{@module}"

  if File.exists? module_path
    remove_dir module_path if yes?("Really destroy module: #{@module}? [y/N]")
  else
    say "No such module: #{@module}"
  end
end

#listObject



27
28
29
30
31
32
# File 'lib/boa/module/module.rb', line 27

def list
  return unless File.exists? BASE_PATH

  module_names = Dir.entries(BASE_PATH).reject { |d| d == '.' || d == '..' }
  print_table module_names.map.with_index { |m, i| [i+1, m] }
end