module Sources
Constants
- DIRECTORIES
- PASCAL_CASE_REGEX
Public Class Methods
create_sources_map(name)
click to toggle source
# File lib/vipera/sources/sources.rb, line 13 def self.create_sources_map(name) unless name.match(PASCAL_CASE_REGEX) then raise "Invalid module name!" end sources_map = {} DIRECTORIES.each do |directory| case directory when "Data" web_service = self.webservice(name) local_storage = self.localstorage(name) sources_map[directory] = { web_service[0] => web_service[1], local_storage[0] => local_storage[1] } when "Presenter" presenter = self.presenter(name) sources_map[directory] = { presenter[0] => presenter[1] } when "Interactor" interactor = self.interactor(name) sources_map[directory] = { interactor[0] => interactor[1] } when "Protocol" protocols = self.protocols(name) sources_map[directory] = { protocols[0] => protocols[1] } when "Router" router = self.router(name) sources_map[directory] = { router[0] => router[1] } else view = self.view(name) sources_map[directory] = { view[0] => view[1] } end end sources_map end
generate_sources(name, xcodeproj, config, source_map)
click to toggle source
# File lib/vipera/sources/sources.rb, line 57 def self.generate_sources(name, xcodeproj, config, source_map) config_targets = config['targets'] targets = xcodeproj.targets.filter { |tg| config_targets.include? tg.name } target_path = "#{Dir.pwd}/#{config["module-root"]}/#{name}/" if File.exists? target_path then raise "Module already exists!" end # get target group from config group_path = config["module-root"].split '/' target_group = nil group_path.each do |group_name| if target_group == nil filters = xcodeproj.groups.filter { |gp| gp.display_name == group_name } if filters.count >= 1 then target_group = filters[0] else raise "Target group not found!" end else filters = target_group.groups.filter { |gp| gp.display_name == group_name } if filters.count >= 1 then target_group = filters[0] else raise "Target group not found!" end end end target_group = target_group.new_group(name, target_path) Dir.mkdir target_path source_map.each_key { |key_path| key_full_path = target_path + key_path + "/" key_group = target_group.new_group(key_path, key_full_path) Dir.mkdir key_full_path source_map[key_path].each_key { |file_name| file_path = key_full_path + file_name content = source_map[key_path][file_name] File.write file_path, content file = key_group.new_file file_name targets.each do |target| target.add_file_references [file] end } } target_path end
interactor(name)
click to toggle source
# File lib/vipera/sources/interactor.rb, line 2 def self.interactor(name) return "#{name}Interactor.swift", <<~INTERACTOR import UIKit class #{name}Interactor: #{name}InteractorInputProtocol { var presenter: #{name}InteractorOutputProtocol? var localStorage: #{name}LocalStorageInputProtocol? var webService: #{name}WebServiceInputProtocol? } // MARK: WEB_SERVICE -> INTERACTOR extension #{name}Interactor: #{name}WebServiceOutputProtocol { } INTERACTOR end
localstorage(name)
click to toggle source
# File lib/vipera/sources/localstorage.rb, line 2 def self.localstorage(name) return "#{name}LocalStorage.swift", <<~LOCALSTORAGE import Foundation class #{name}LocalStorage: #{name}LocalStorageInputProtocol { } LOCALSTORAGE end
presenter(name)
click to toggle source
# File lib/vipera/sources/presenter.rb, line 2 def self.presenter(name) return "#{name}Presenter.swift", <<~PRESENTER import UIKit class #{name}Presenter: #{name}PresenterProtocol { var view: #{name}ViewProtocol? var interactor: #{name}InteractorInputProtocol? var router: #{name}RouterProtocol? } // MARK: INTERACTOR -> PRESENTER extension #{name}Presenter: #{name}InteractorOutputProtocol { } PRESENTER end
protocols(name)
click to toggle source
# File lib/vipera/sources/protocols.rb, line 2 def self.protocols(name) return "#{name}Protocols.swift", <<~PROTOCOLS import UIKit protocol #{name}ViewProtocol { var presenter: #{name}PresenterProtocol? { get set } // PRESENTER -> VIEW } protocol #{name}PresenterProtocol { var view: #{name}ViewProtocol? { get set } var interactor: #{name}InteractorInputProtocol? { get set } var router: #{name}RouterProtocol? { get set } // VIEW -> PRESENTER } protocol #{name}InteractorInputProtocol { var presenter: #{name}InteractorOutputProtocol? { get set } var localStorage: #{name}LocalStorageInputProtocol? { get set } var webService: #{name}WebServiceInputProtocol? { get set } // PRESENTER -> INTERACTOR } protocol #{name}InteractorOutputProtocol { // INTERACTOR -> PRESENTER } protocol #{name}RouterProtocol { // PRESENTER -> ROUTER static func createModule() -> UIViewController? } protocol #{name}LocalStorageInputProtocol { // INTERACTOR -> LOCALSTORAGE } protocol #{name}WebServiceInputProtocol { var interactor: #{name}WebServiceOutputProtocol? { get set } // INTERACTOR -> WEBSERVICE } protocol #{name}WebServiceOutputProtocol { // WEBSERVICE -> INTERACTOR } PROTOCOLS end
router(name)
click to toggle source
# File lib/vipera/sources/router.rb, line 2 def self.router(name) return "#{name}Router.swift", <<~ROUTER import UIKit class #{name}Router: #{name}RouterProtocol { static func createModule() -> UIViewController? { let navController = // TODO: Set navController guard let view = navController?.children.first as? #{name}ViewController else { return nil } let router: #{name}RouterProtocol = #{name}Router() var presenter: #{name}PresenterProtocol & #{name}InteractorOutputProtocol = #{name}Presenter() var interactor: #{name}InteractorInputProtocol & #{name}WebServiceOutputProtocol = #{name}Interactor() let localStorage: #{name}LocalStorageInputProtocol = #{name}LocalStorage() let webService: #{name}WebServiceInputProtocol = #{name}WebService() view.presenter = presenter presenter.view = view presenter.router = router presenter.interactor = interactor interactor.presenter = presenter interactor.localStorage = localStorage return navController } } ROUTER end
view(name)
click to toggle source
# File lib/vipera/sources/view.rb, line 2 def self.view(name) return "#{name}ViewController.swift", <<~VIEW import UIKit class #{name}ViewController: UIViewController { var presenter: #{name}PresenterProtocol? } // MARK: PRESENTER -> VIEW extension #{name}ViewController: #{name}ViewProtocol { } VIEW end
webservice(name)
click to toggle source
# File lib/vipera/sources/webservice.rb, line 2 def self.webservice(name) return "#{name}WebService.swift", <<~WEBSERVICE import UIKit class #{name}WebService: #{name}WebServiceInputProtocol { var interactor: #{name}WebServiceOutputProtocol? } WEBSERVICE end