Class: Yadecli::Service::ModuleService
- Inherits:
-
Object
- Object
- Yadecli::Service::ModuleService
- Defined in:
- lib/yadecli/service/module_service.rb
Overview
module service
Instance Method Summary collapse
-
#initialize ⇒ ModuleService
constructor
A new instance of ModuleService.
-
#install(project_name, module_name, options) ⇒ Object
install the module of a project.
-
#list(project_name) ⇒ Object
list the available modules for the project.
Constructor Details
#initialize ⇒ ModuleService
Returns a new instance of ModuleService.
12 13 14 15 16 |
# File 'lib/yadecli/service/module_service.rb', line 12 def initialize @project_client = Yadecli::Client::ProjectClient.new @module_client = Yadecli::Client::ProjectModuleClient.new @vcs_client = Yadecli::Client::VcsClient.new end |
Instance Method Details
#install(project_name, module_name, options) ⇒ Object
install the module of a project
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yadecli/service/module_service.rb', line 45 def install(project_name, module_name, ) CliUtil.print_header'YadeCli Install Module', ["Going to install module #{module_name} for Yade project #{project_name}", ''] project = @project_client.project_by_name(project_name) project_module = @module_client.module_for_project(project.id, module_name) vcs = @vcs_client.get(project_module.vcsId) if project_module.installed? puts "The module with name #{module_name} is already installed" if [:yes] do_update = true else puts '' prompt = TTY::Prompt.new do_update = prompt.yes?('Do you want to pull the changes for the project? ') end end cmd = TTY::Command.new(output: Yadecli.LOGGER) if do_update cmd_line = 'git pull' cmd.run(cmd_line, chdir: project_module.home) else cmd_line = "git clone #{vcs.url} #{project_module.home}" cmd.run(cmd_line) end end |
#list(project_name) ⇒ Object
list the available modules for the project
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yadecli/service/module_service.rb', line 19 def list(project_name) CliUtil.print_header'YadeCli List Modules', ["This are the available modules for the Yade project #{project_name}", ''] project = @project_client.project_by_name(project_name) puts "Project: #{project.name}".colorize(:mode => :bold) project_modules = @module_client.modules_for_project(project.id) rows = [] project_modules.each do |m| module_name = m.name is_installed = m.installed? git_status = '-' git_status = FileUtil.git_status(m.home) if is_installed rows << [module_name, is_installed, git_status] end table = TTY::Table.new header: ['Module name', 'Installed', 'Git Status'], rows: rows puts table.render(:ascii, padding: [0, 1]) puts '' # puts "You can run 'yadecli module install <project_name> <module_name>' to install the module to the project src directory" # puts '' end |