generamba-udf 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +10 -0
  3. data/.gitignore +4 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +17 -0
  6. data/CHANGELOG.md +191 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +62 -0
  10. data/Rakefile +6 -0
  11. data/VISION.md +41 -0
  12. data/bin/console +14 -0
  13. data/bin/generamba +5 -0
  14. data/bin/setup +7 -0
  15. data/docs/2.x/roadmap.md +365 -0
  16. data/generamba-1.6.0.gem +0 -0
  17. data/generamba-2.0.0.gem +0 -0
  18. data/generamba.gemspec +38 -0
  19. data/lib/generamba/cli/cli.rb +16 -0
  20. data/lib/generamba/cli/gen_command.rb +119 -0
  21. data/lib/generamba/cli/setup_command.rb +127 -0
  22. data/lib/generamba/cli/setup_username_command.rb +21 -0
  23. data/lib/generamba/cli/template/template_create_command.rb +40 -0
  24. data/lib/generamba/cli/template/template_group.rb +14 -0
  25. data/lib/generamba/cli/template/template_install_command.rb +21 -0
  26. data/lib/generamba/cli/template/template_list_command.rb +25 -0
  27. data/lib/generamba/cli/template/template_search_command.rb +30 -0
  28. data/lib/generamba/cli/thor_extension.rb +47 -0
  29. data/lib/generamba/cli/version_command.rb +25 -0
  30. data/lib/generamba/code_generation/Rambafile.liquid +44 -0
  31. data/lib/generamba/code_generation/code_module.rb +123 -0
  32. data/lib/generamba/code_generation/content_generator.rb +43 -0
  33. data/lib/generamba/code_generation/module_template.rb +31 -0
  34. data/lib/generamba/code_generation/rambafile_generator.rb +23 -0
  35. data/lib/generamba/configuration/user_preferences.rb +50 -0
  36. data/lib/generamba/constants/constants.rb +12 -0
  37. data/lib/generamba/constants/rambafile_constants.rb +41 -0
  38. data/lib/generamba/constants/rambaspec_constants.rb +22 -0
  39. data/lib/generamba/constants/user_preferences_constants.rb +5 -0
  40. data/lib/generamba/helpers/dependency_checker.rb +54 -0
  41. data/lib/generamba/helpers/gen_command_table_parameters_formatter.rb +41 -0
  42. data/lib/generamba/helpers/module_info_generator.rb +35 -0
  43. data/lib/generamba/helpers/module_validator.rb +85 -0
  44. data/lib/generamba/helpers/print_table.rb +17 -0
  45. data/lib/generamba/helpers/rambafile_validator.rb +18 -0
  46. data/lib/generamba/helpers/template_helper.rb +30 -0
  47. data/lib/generamba/helpers/xcodeproj_helper.rb +262 -0
  48. data/lib/generamba/module_generator.rb +148 -0
  49. data/lib/generamba/template/creator/new_template/Code/Service/service.h.liquid +11 -0
  50. data/lib/generamba/template/creator/new_template/Code/Service/service.m.liquid +13 -0
  51. data/lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
  52. data/lib/generamba/template/creator/new_template/template.rambaspec.liquid +20 -0
  53. data/lib/generamba/template/creator/template_creator.rb +39 -0
  54. data/lib/generamba/template/helpers/catalog_downloader.rb +58 -0
  55. data/lib/generamba/template/helpers/catalog_template_list_helper.rb +23 -0
  56. data/lib/generamba/template/helpers/catalog_template_search_helper.rb +27 -0
  57. data/lib/generamba/template/helpers/catalog_terminator.rb +21 -0
  58. data/lib/generamba/template/helpers/rambaspec_validator.rb +52 -0
  59. data/lib/generamba/template/installer/abstract_installer.rb +9 -0
  60. data/lib/generamba/template/installer/catalog_installer.rb +73 -0
  61. data/lib/generamba/template/installer/local_installer.rb +32 -0
  62. data/lib/generamba/template/installer/remote_installer.rb +50 -0
  63. data/lib/generamba/template/installer/template_installer_factory.rb +22 -0
  64. data/lib/generamba/template/processor/template_declaration.rb +36 -0
  65. data/lib/generamba/template/processor/template_processor.rb +75 -0
  66. data/lib/generamba/tools/string-colorize.rb +23 -0
  67. data/lib/generamba/version.rb +5 -0
  68. data/lib/generamba.rb +16 -0
  69. metadata +288 -0
@@ -0,0 +1,148 @@
1
+ require 'fileutils'
2
+
3
+ require 'generamba/helpers/xcodeproj_helper.rb'
4
+ require 'generamba/helpers/module_info_generator.rb'
5
+
6
+ module Generamba
7
+
8
+ # Responsible for creating the whole code module using information from the CLI
9
+ class ModuleGenerator
10
+
11
+ def generate_module(name, code_module, template)
12
+ # Setting up Xcode objects
13
+ project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
14
+
15
+ # Configuring file paths
16
+ if code_module.project_file_root && code_module.test_file_root
17
+ FileUtils.mkdir_p code_module.project_file_root if code_module.project_file_root
18
+ FileUtils.mkdir_p code_module.test_file_root if code_module.test_file_root
19
+ else
20
+ FileUtils.mkdir_p code_module.project_file_path if code_module.project_file_path
21
+ FileUtils.mkdir_p code_module.test_file_path if code_module.test_file_path
22
+ end
23
+
24
+ FileUtils.mkdir_p code_module.test_unit_path if code_module.test_unit_path
25
+ FileUtils.mkdir_p code_module.test_snapshot_path if code_module.test_snapshot_path
26
+
27
+ # Creating code files
28
+ if code_module.project_targets && code_module.project_group_path && code_module.project_file_path
29
+ puts('Creating code files...')
30
+ process_files_if_needed(template.code_files,
31
+ code_module,
32
+ template,
33
+ project,
34
+ code_module.project_targets,
35
+ code_module.project_group_path,
36
+ code_module.project_file_path,
37
+ code_module.project_file_root)
38
+ end
39
+
40
+ # Creating test files
41
+ if code_module.test_targets && code_module.test_group_path && code_module.test_file_path
42
+ puts('Creating test files...')
43
+ process_files_if_needed(template.test_files,
44
+ code_module,
45
+ template,
46
+ project,
47
+ code_module.test_targets,
48
+ code_module.test_group_path,
49
+ code_module.test_file_path,
50
+ code_module.test_file_root,
51
+ [code_module.project_group_path])
52
+ end
53
+
54
+ # Creating unit test files
55
+ if code_module.test_unit_target && code_module.test_unit_path && code_module.test_unit_testable_import
56
+ puts('Creating unit test files...')
57
+ process_files_if_needed(template.test_unit_files,
58
+ code_module,
59
+ template,
60
+ project,
61
+ [code_module.test_unit_target],
62
+ code_module.test_unit_path,
63
+ code_module.test_unit_path,
64
+ code_module.test_unit_path,
65
+ [code_module.test_unit_path])
66
+ end
67
+
68
+ # Creating snapshot test files
69
+ if code_module.test_snapshot_target && code_module.test_snapshot_path && code_module.test_snapshot_testable_import
70
+ puts('Creating snapshot test files...')
71
+ process_files_if_needed(template.test_snapshot_files,
72
+ code_module,
73
+ template,
74
+ project,
75
+ [code_module.test_snapshot_target],
76
+ code_module.test_snapshot_path,
77
+ code_module.test_snapshot_path,
78
+ code_module.test_snapshot_path,
79
+ [code_module.test_snapshot_path])
80
+ end
81
+
82
+ # Saving the current changes in the Xcode project
83
+ project.save
84
+
85
+ puts 'Module successfully created!'
86
+ puts "Name: #{name}".green
87
+ puts "Project file path: #{code_module.project_file_path}".green if code_module.project_file_path
88
+ puts "Project group path: #{code_module.project_group_path}".green if code_module.project_group_path
89
+ puts "Test file path: #{code_module.test_file_path}".green if code_module.test_file_path
90
+ puts "Test group path: #{code_module.test_group_path}".green if code_module.test_group_path
91
+ end
92
+
93
+ def process_files_if_needed(files, code_module, template, project, targets, group_path, dir_path, root_path, processed_groups = [])
94
+ # It's possible that current project doesn't test targets configured, so it doesn't need to generate tests.
95
+ # The same is for files property - a template can have only test or project files
96
+ if targets.count == 0 || files == nil || files.count == 0 || dir_path == nil || group_path == nil
97
+ return
98
+ end
99
+
100
+ XcodeprojHelper.clear_group(project, targets, group_path, code_module.create_logical_groups) unless processed_groups.include? group_path
101
+ files.each do |file|
102
+ unless file[TEMPLATE_FILE_PATH_KEY]
103
+ directory_name = file[TEMPLATE_NAME_KEY].gsub(/^\/|\/$/, '')
104
+ file_group = dir_path.join(directory_name)
105
+
106
+ FileUtils.mkdir_p root_path
107
+ XcodeprojHelper.add_group_to_project(project, group_path, dir_path, directory_name, code_module.create_logical_groups)
108
+
109
+ next
110
+ end
111
+
112
+ file_group = File.dirname(file[TEMPLATE_NAME_KEY])
113
+ file_group = nil if file_group == '.'
114
+
115
+ module_info = ModuleInfoGenerator.new(code_module)
116
+
117
+ # Generating the content of the code file and it's name
118
+ file_name, file_content = ContentGenerator.create_file(file, module_info.scope, template)
119
+ if code_module.create_logical_groups
120
+ file_path = root_path
121
+ else
122
+ file_path = dir_path
123
+ file_path = file_path.join(file_group) if file_group
124
+ end
125
+
126
+ file_path = file_path.join(file_name) if file_name
127
+
128
+ # Creating the file in the filesystem
129
+ FileUtils.mkdir_p File.dirname(file_path) if !code_module.create_logical_groups
130
+ File.open(file_path, 'w+') do |f|
131
+ f.write(file_content)
132
+ end
133
+
134
+ file_is_resource = file[TEMPLATE_FILE_IS_RESOURCE_KEY]
135
+
136
+ # Creating the file in the Xcode project
137
+ XcodeprojHelper.add_file_to_project_and_targets(project,
138
+ targets,
139
+ group_path,
140
+ dir_path,
141
+ file_group,
142
+ file_name,
143
+ root_path,
144
+ file_is_resource)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,11 @@
1
+ //
2
+ // {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
3
+ // {{ module_info.project_name }}
4
+ //
5
+ // Created by {{ developer.name }} on {{ date }}.
6
+ // Copyright {{ year }} {{ developer.company }}. All rights reserved.
7
+ //
8
+
9
+ @interface {{ prefix }}{{ module_info.name }}Service : NSObject
10
+
11
+ @end
@@ -0,0 +1,13 @@
1
+ //
2
+ // {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
3
+ // {{ module_info.project_name }}
4
+ //
5
+ // Created by {{ developer.name }} on {{ date }}.
6
+ // Copyright {{ year }} {{ developer.company }}. All rights reserved.
7
+ //
8
+
9
+ #import "{{ prefix }}{{ module_info.name }}Service.h"
10
+
11
+ @implementation {{ prefix }}{{ module_info.name }}Service
12
+
13
+ @end
@@ -0,0 +1,35 @@
1
+ //
2
+ // {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
3
+ // {{ module_info.project_name }}
4
+ //
5
+ // Created by {{ developer.name }} on {{ date }}.
6
+ // Copyright {{ year }} {{ developer.company }}. All rights reserved.
7
+ //
8
+
9
+ #import <XCTest/XCTest.h>
10
+
11
+ #import "{{ prefix }}{{ module_info.name }}Service.h"
12
+
13
+ @interface {{ prefix }}{{ module_info.name }}ServiceTests : XCTestCase
14
+
15
+ @property (strong, nonatomic) {{ prefix }}{{ module_info.name }}Service *service;
16
+
17
+ @end
18
+
19
+ @implementation {{ prefix }}{{ module_info.name }}ServiceTests
20
+
21
+ #pragma mark - Test environment setup
22
+
23
+ - (void)setUp {
24
+ [super setUp];
25
+
26
+ self.service = [[{{ prefix }}{{ module_info.name }}Service alloc] init];
27
+ }
28
+
29
+ - (void)tearDown {
30
+ self.service = nil;
31
+
32
+ [super tearDown];
33
+ }
34
+
35
+ @end
@@ -0,0 +1,20 @@
1
+ # Template information section
2
+ name: {{ name }}
3
+ summary: {{ summary }}
4
+ author: {{ author }}
5
+ version: 1.0.0
6
+ license: {{ license }}
7
+
8
+ # The declarations for code files
9
+ code_files:
10
+ - {name: Service/Service.h, path: Code/Service/service.h.liquid}
11
+ - {name: Service/Service.m, path: Code/Service/service.m.liquid}
12
+
13
+ # The declarations for test files
14
+ test_files:
15
+ - {name: Service/ServiceTests.m, path: Tests/Service/service_tests.m.liquid}
16
+
17
+ # Template dependencies
18
+ dependencies:
19
+ {% for dependency in dependencies %}- {{ dependency }}
20
+ {% endfor %}
@@ -0,0 +1,39 @@
1
+ module Generamba
2
+
3
+ # Responsible for generating new .rambaspec files
4
+ class TemplateCreator
5
+
6
+ NEW_TEMPLATE_FOLDER = 'new_template'
7
+ RAMBASPEC_TEMPLATE_NAME = 'template.rambaspec.liquid'
8
+ CODE_FOLDER = 'Code'
9
+ TESTS_FOLDER = 'Tests'
10
+
11
+ # Generates and saves to filesystem a new template with a .rambaspec file and sample code and tests files
12
+ # @param properties [Hash] User-inputted template properties
13
+ #
14
+ # @return [Void]
15
+ def create_template(properties)
16
+ template_dir_path = Pathname.new(File.dirname(__FILE__)).join(NEW_TEMPLATE_FOLDER)
17
+ rambaspec_template_file_path = template_dir_path.join(RAMBASPEC_TEMPLATE_NAME)
18
+ code_file_path = template_dir_path.join(CODE_FOLDER)
19
+ tests_file_path = template_dir_path.join(TESTS_FOLDER)
20
+
21
+ file_source = IO.read(rambaspec_template_file_path)
22
+
23
+ template = Liquid::Template.parse(file_source)
24
+ output = template.render(properties)
25
+
26
+ result_name = properties[TEMPLATE_NAME_KEY] + RAMBASPEC_EXTENSION
27
+ result_dir_path = Pathname.new(properties[TEMPLATE_NAME_KEY])
28
+
29
+ FileUtils.mkdir_p result_dir_path
30
+ FileUtils.cp_r(code_file_path, result_dir_path)
31
+ FileUtils.cp_r(tests_file_path, result_dir_path)
32
+
33
+ File.open(result_dir_path.join(result_name), 'w+') {|f|
34
+ f.write(output)
35
+ }
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ require 'git'
2
+
3
+ module Generamba
4
+
5
+ # Provides the functionality to download template catalogs from the remote repository
6
+ class CatalogDownloader
7
+
8
+ # Updates all of the template catalogs and returns their filepaths.
9
+ # If there is a Rambafile in the current directory, it also updates all of the catalogs specified there.
10
+ #
11
+ # @return [Array] An array of filepaths to downloaded catalogs
12
+ def update_all_catalogs_and_return_filepaths
13
+ does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
14
+
15
+ if does_rambafile_exist
16
+ rambafile = YAML.load_file(RAMBAFILE_NAME)
17
+ catalogs = rambafile[CATALOGS_KEY]
18
+ end
19
+
20
+ terminator = CatalogTerminator.new
21
+ terminator.remove_all_catalogs
22
+
23
+ catalog_paths = [download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)]
24
+
25
+ if catalogs != nil && catalogs.count > 0
26
+ catalogs.each do |catalog_url|
27
+ catalog_name = catalog_url.split('://').last
28
+ catalog_name = catalog_name.gsub('/', '-');
29
+ catalog_paths.push(download_catalog(catalog_name, catalog_url))
30
+ end
31
+ end
32
+ return catalog_paths
33
+ end
34
+
35
+ # Clones a template catalog from a remote repository
36
+ #
37
+ # @param name [String] The name of the template catalog
38
+ # @param url [String] The url of the repository
39
+ #
40
+ # @return [Pathname] A filepath to the downloaded catalog
41
+ def download_catalog(name, url)
42
+ catalogs_local_path = Pathname.new(ENV['HOME'])
43
+ .join(GENERAMBA_HOME_DIR)
44
+ .join(CATALOGS_DIR)
45
+ current_catalog_path = catalogs_local_path
46
+ .join(name)
47
+
48
+ if File.exists?(current_catalog_path)
49
+ g = Git.open(current_catalog_path)
50
+ g.pull
51
+ else
52
+ Git.clone(url, name, :path => catalogs_local_path)
53
+ end
54
+
55
+ return current_catalog_path
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ module Generamba
2
+
3
+ # Provides the functionality to list all of the templates, available in the catalog
4
+ class CatalogTemplateListHelper
5
+
6
+ # Finds out all of the templates located in a catalog
7
+ #
8
+ # @param catalog_path [Pathname] The path to a template catalog
9
+ #
10
+ # @return [Array] An array with template names
11
+ def obtain_all_templates_from_a_catalog(catalog_path)
12
+ template_names = []
13
+ catalog_path.children.select { |child|
14
+ File.directory?(child) && child.split.last.to_s[0] != '.'
15
+ }.map { |template_path|
16
+ template_path.split.last.to_s
17
+ }.each { |template_name|
18
+ template_names.push(template_name)
19
+ }
20
+ return template_names
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Generamba
2
+
3
+ # Provides the functionality to search templates, in catalogs
4
+ class CatalogTemplateSearchHelper
5
+
6
+ # Finds out all of the templates located in a catalog
7
+ #
8
+ # @param catalog_path [Pathname] The path to a template catalog
9
+ #
10
+ # @return [Array] An array with template names
11
+ def search_templates_in_a_catalog(catalog_path, search_term)
12
+ template_names = []
13
+
14
+ catalog_path.children.select { |child|
15
+ File.directory?(child) && child.split.last.to_s[0] != '.'
16
+ }.map { |template_path|
17
+ template_path.split.last.to_s
18
+ }.select { |template_name|
19
+ template_name.include?(search_term)
20
+ }.each { |template_name|
21
+ template_names.push(template_name)
22
+ }
23
+
24
+ return template_names
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Generamba
2
+
3
+ # Provides a functionality to terminate all previously installed catalogs
4
+ #
5
+ # @return [Void]
6
+ class CatalogTerminator
7
+ def remove_all_catalogs
8
+ catalogs_path = Pathname.new(ENV['HOME'])
9
+ .join(GENERAMBA_HOME_DIR)
10
+ .join(CATALOGS_DIR)
11
+ if Dir.exist?(catalogs_path) == false
12
+ FileUtils.mkdir_p catalogs_path
13
+ end
14
+ catalogs_path.children.select { |child|
15
+ child.directory? && child.split.last.to_s[0] != '.'
16
+ }.each { |catalog_path|
17
+ FileUtils.rm_rf(catalog_path)
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ module Generamba
2
+
3
+ # Provides methods that validate .rambaspec file existance and structure
4
+ class RambaspecValidator
5
+
6
+ # Validates the existance of a .rambaspec file for a given template
7
+ #
8
+ # @param template_name [String] The name of the template
9
+ # @param template_path [String] The local filepath to the template
10
+ #
11
+ # @return [Bool]
12
+ def self.validate_spec_existance(template_name, template_path)
13
+ local_spec_path = self.obtain_spec_path(template_name, template_path)
14
+ File.file?(local_spec_path)
15
+ end
16
+
17
+ # Validates the structure of a .rambaspec file for a given template
18
+ #
19
+ # @param template_name [String] The name of the template
20
+ # @param template_path [String] The local filepath to the template
21
+ #
22
+ # @return [Bool]
23
+ def self.validate_spec(template_name, template_path)
24
+ spec_path = self.obtain_spec_path(template_name, template_path)
25
+
26
+ spec_source = IO.read(spec_path)
27
+ spec_template = Liquid::Template.parse(spec_source)
28
+ spec_content = spec_template.render
29
+ spec = YAML.load(spec_content)
30
+
31
+ is_spec_valid =
32
+ spec[TEMPLATE_NAME_KEY] != nil &&
33
+ spec[TEMPLATE_AUTHOR_KEY] != nil &&
34
+ spec[TEMPLATE_VERSION_KEY] != nil &&
35
+ (spec[TEMPLATE_CODE_FILES_KEY] != nil || spec[TEMPLATE_TEST_FILES_KEY] != nil)
36
+ return is_spec_valid
37
+ end
38
+
39
+ private
40
+
41
+ # Returns a filepath for a given .rambaspec filename
42
+ #
43
+ # @param template_name [String] The name of the template
44
+ # @param template_path [String] The local filepath to the template
45
+ #
46
+ # @return [Bool]
47
+ def self.obtain_spec_path(template_name, template_path)
48
+ spec_filename = template_name + RAMBASPEC_EXTENSION
49
+ Pathname.new(template_path).join(spec_filename)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ module Generamba
2
+
3
+ # Abstract template installer class
4
+ class AbstractInstaller
5
+ def install_template(template_declaration)
6
+ raise 'Abstract Method - you should implement it in the concrete subclass'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,73 @@
1
+ require 'generamba/template/installer/abstract_installer.rb'
2
+ require 'generamba/template/helpers/rambaspec_validator.rb'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ module Generamba
7
+
8
+ # Incapsulates the logic of installing Generamba templates from the template catalog
9
+ class CatalogInstaller < AbstractInstaller
10
+ def install_template(template_declaration)
11
+ template_name = template_declaration.name
12
+ puts("Installing #{template_name}...")
13
+
14
+ template_name = template_declaration.name
15
+ catalogs_path = Pathname.new(ENV['HOME'])
16
+ .join(GENERAMBA_HOME_DIR)
17
+ .join(CATALOGS_DIR)
18
+
19
+ catalog_path = catalogs_path.children.select { |child|
20
+ child.directory? && child.split.last.to_s[0] != '.'
21
+ }.select { |catalog_path|
22
+ template_path = browse_catalog_for_a_template(catalog_path, template_name)
23
+ template_path != nil
24
+ }.first
25
+
26
+ if catalog_path == nil
27
+ error_description = "Cannot find #{template_name} in any catalog. Try another name.".red
28
+ puts(error_description)
29
+ return
30
+ end
31
+
32
+ template_path = catalog_path.join(template_name)
33
+ rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_path)
34
+ unless rambaspec_exist
35
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the template catalog #{catalog_path}. Try another name.".red
36
+ puts(error_description)
37
+ return
38
+ end
39
+
40
+ rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_path)
41
+ unless rambaspec_valid
42
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
43
+ puts(error_description)
44
+ return
45
+ end
46
+
47
+ install_path = Pathname.new(TEMPLATES_FOLDER)
48
+ .join(template_name)
49
+ FileUtils.mkdir_p install_path
50
+
51
+ src = template_path.to_s + '/.'
52
+ FileUtils.cp_r(src, install_path)
53
+ end
54
+
55
+ private
56
+
57
+ # Browses a given catalog and returns a template path
58
+ #
59
+ # @param catalog_path [Pathname] A path to a catalog
60
+ # @param template_name [String] A name of the template
61
+ #
62
+ # @return [Pathname] A path to a template, if found
63
+ def browse_catalog_for_a_template(catalog_path, template_name)
64
+ template_path = catalog_path.join(template_name)
65
+
66
+ if Dir.exist?(template_path)
67
+ return template_path
68
+ end
69
+
70
+ return nil
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,32 @@
1
+ require 'generamba/template/installer/abstract_installer.rb'
2
+ require 'generamba/template/helpers/rambaspec_validator.rb'
3
+
4
+ module Generamba
5
+
6
+ # Incapsulates the logic of verifying and installing local templates
7
+ class LocalInstaller < AbstractInstaller
8
+ def install_template(template_declaration)
9
+ template_name = template_declaration.name
10
+ puts("Installing #{template_name}...")
11
+
12
+ local_path = template_declaration.local
13
+ rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, local_path)
14
+
15
+ unless rambaspec_exist
16
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the specified directory. Try another path or name.".red
17
+ raise StandardError.new(error_description)
18
+ end
19
+
20
+ rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, local_path)
21
+ unless rambaspec_valid
22
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
23
+ raise StandardError.new(error_description)
24
+ end
25
+
26
+ install_path = Pathname.new(TEMPLATES_FOLDER)
27
+ .join(template_name)
28
+ FileUtils.mkdir_p install_path
29
+ FileUtils.copy_entry(local_path, install_path)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ require 'generamba/template/installer/abstract_installer.rb'
2
+ require 'generamba/template/helpers/rambaspec_validator.rb'
3
+ require 'git'
4
+ require 'fileutils'
5
+ require 'tmpdir'
6
+
7
+ module Generamba
8
+
9
+ # Incapsulates the logic of fetching remote templates, verifying and installing them
10
+ class RemoteInstaller < AbstractInstaller
11
+ def install_template(template_declaration)
12
+ template_name = template_declaration.name
13
+ puts("Installing #{template_name}...")
14
+
15
+ repo_url = template_declaration.git
16
+ repo_branch = template_declaration.branch
17
+
18
+ temp_path = Dir.tmpdir()
19
+ template_dir = Pathname.new(temp_path).join(template_name)
20
+
21
+ if repo_branch != nil
22
+ Git.export(repo_url, template_name, :branch => repo_branch, :path => temp_path)
23
+ else
24
+ Git.clone(repo_url, template_name, :path => temp_path)
25
+ end
26
+
27
+ template_path = "#{template_dir}"
28
+
29
+ rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_path)
30
+ unless rambaspec_exist
31
+ FileUtils.rm_rf(temp_path)
32
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the root directory of specified repository.".red
33
+ raise StandardError.new(error_description)
34
+ end
35
+
36
+ rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_path)
37
+ unless rambaspec_valid
38
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
39
+ raise StandardError.new(error_description)
40
+ end
41
+
42
+ install_path = Pathname.new(TEMPLATES_FOLDER)
43
+ .join(template_name)
44
+ FileUtils.mkdir_p install_path
45
+ FileUtils.copy_entry(template_path, install_path)
46
+
47
+ FileUtils.rm_rf(temp_path)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ require 'generamba/template/processor/template_declaration'
2
+
3
+ module Generamba
4
+
5
+ # Factory that creates a proper installer for a given template type
6
+ class TemplateInstallerFactory
7
+
8
+ # Provides the appropriate strategy for a given template type
9
+ def installer_for_type(type)
10
+ case type
11
+ when TemplateDeclarationType::LOCAL_TEMPLATE
12
+ return Generamba::LocalInstaller.new
13
+ when TemplateDeclarationType::REMOTE_TEMPLATE
14
+ return Generamba::RemoteInstaller.new
15
+ when TemplateDeclarationType::CATALOG_TEMPLATE
16
+ return Generamba::CatalogInstaller.new
17
+ else
18
+ return nil
19
+ end
20
+ end
21
+ end
22
+ end