pi_customizer 0.4.0.pre.alpha → 0.5.0.pre.alpha

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/README.md +55 -20
  5. data/Rakefile +6 -5
  6. data/docs/concept.md +0 -18
  7. data/docs/incubation.md +3 -14
  8. data/pi_build_modifier/Gemfile.lock +50 -0
  9. data/pi_build_modifier/lib/pi_build_modifier.rb +4 -7
  10. data/pi_build_modifier/lib/pi_build_modifier/modify/configs.rb +335 -0
  11. data/pi_build_modifier/lib/pi_build_modifier/modify/modifiers.rb +281 -0
  12. data/pi_build_modifier/lib/pi_build_modifier/{locale → modify}/templates/00-debconf.erb +1 -1
  13. data/pi_build_modifier/lib/pi_build_modifier/{boot-files → modify}/templates/07-resize-init.diff.erb +1 -1
  14. data/pi_build_modifier/lib/pi_build_modifier/{net-tweaks → modify}/templates/wpa_supplicant.conf.erb +1 -1
  15. data/pi_build_modifier/lib/pi_build_modifier/{config → utils}/logex.rb +5 -1
  16. data/pi_build_modifier/lib/pi_build_modifier/version.rb +1 -1
  17. data/pi_build_modifier/spec/pi_build_modifier/modify/modify_spec.rb +306 -0
  18. data/pi_build_modifier/spec/pi_build_modifier_spec.rb +3 -3
  19. data/pi_build_modifier/spec/spec_helper.rb +1 -0
  20. data/pi_customizer/Gemfile.lock +47 -0
  21. data/pi_customizer/lib/pi_customizer.rb +15 -9
  22. data/pi_customizer/lib/pi_customizer/build/builder/build_executor.rb +12 -24
  23. data/pi_customizer/lib/pi_customizer/build/builder/builder.rb +17 -13
  24. data/pi_customizer/{spec/pi_customizer/environment/environment_builder_factory_spec.rb → lib/pi_customizer/build/config/build_config.rb} +27 -18
  25. data/pi_customizer/lib/pi_customizer/build/{workspace → config}/local_workspace.rb +8 -8
  26. data/pi_customizer/lib/pi_customizer/build/{workspace → config}/remote_workspace.rb +1 -1
  27. data/pi_customizer/lib/pi_customizer/build/environment/docker/docker.rb +1 -1
  28. data/pi_customizer/lib/pi_customizer/build/environment/environment.rb +1 -1
  29. data/pi_customizer/lib/pi_customizer/build/{builder/start_prepare_execute_builder.rb → environment/environment_factory.rb} +27 -16
  30. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +2 -2
  31. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant.rb +3 -8
  32. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant_file.rb +3 -3
  33. data/pi_customizer/lib/pi_customizer/version.rb +1 -1
  34. data/pi_customizer/lib/pi_customizer/write/image_writer.rb +3 -2
  35. data/pi_customizer/spec/pi_customizer/build/builder/builder_spec.rb +122 -0
  36. data/pi_customizer/spec/pi_customizer/{environment/aws_spec.rb → build/config/build_config_spec.rb} +20 -25
  37. data/pi_customizer/spec/pi_customizer/{workspace/local_workspace_spec.rb → build/config/local_workspace_config_spec.rb} +10 -10
  38. data/pi_customizer/spec/pi_customizer/{workspace → build/config}/remote_workspace_spec.rb +2 -2
  39. data/pi_customizer/spec/pi_customizer/{environment/vagrant/vagrant_spec.rb → build/environment/environment_builder_factory_spec.rb} +17 -13
  40. data/pi_customizer/spec/pi_customizer/{environment → build/environment}/environment_spec.rb +1 -1
  41. data/pi_customizer/spec/pi_customizer/{environment → build/environment}/vagrant/vagrant_file_spec.rb +7 -7
  42. data/pi_customizer/spec/pi_customizer/build/environment/vagrant/vagrant_spec.rb +80 -0
  43. data/pi_customizer/spec/pi_customizer_spec.rb +19 -14
  44. data/pi_customizer/spec/spec_helper.rb +21 -0
  45. data/version.rb +1 -1
  46. metadata +23 -42
  47. data/Vagrantfile +0 -27
  48. data/pi_build_modifier/.gitignore +0 -12
  49. data/pi_build_modifier/lib/pi_build_modifier/boot-files/boot.rb +0 -64
  50. data/pi_build_modifier/lib/pi_build_modifier/locale/locale_debconf.rb +0 -66
  51. data/pi_build_modifier/lib/pi_build_modifier/modifier/erb_mapper.rb +0 -72
  52. data/pi_build_modifier/lib/pi_build_modifier/modifier/mapper.rb +0 -49
  53. data/pi_build_modifier/lib/pi_build_modifier/modifier/pi_modifier.rb +0 -81
  54. data/pi_build_modifier/lib/pi_build_modifier/modifier_task.rb +0 -79
  55. data/pi_build_modifier/lib/pi_build_modifier/net-tweaks/wifi_network.rb +0 -124
  56. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/run_modifier.rb +0 -63
  57. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/ssh.rb +0 -61
  58. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +0 -8
  59. data/pi_build_modifier/lib/pi_build_modifier/system/system_type.rb +0 -84
  60. data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +0 -103
  61. data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +0 -87
  62. data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +0 -105
  63. data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +0 -83
  64. data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +0 -63
  65. data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +0 -91
  66. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +0 -74
  67. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +0 -73
  68. data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +0 -66
  69. data/pi_customizer/lib/pi_customizer/build/builder/prepare_start_execute_builder.rb +0 -43
  70. data/pi_customizer/lib/pi_customizer/build/environment/aws/aws.rb +0 -76
  71. data/pi_customizer/lib/pi_customizer/build/environment/environment_builder_factory.rb +0 -81
  72. data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +0 -64
@@ -1,61 +0,0 @@
1
- # Copyright (c) 2017-2019 Beate Ottenwälder
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
-
21
- require 'fileutils'
22
- require 'pi_build_modifier/modifier/mapper'
23
- require 'pi_build_modifier/sys_tweaks/run_modifier'
24
- require 'pi_build_modifier/config/logex'
25
-
26
- module PiBuildModifier
27
-
28
- class Ssh
29
-
30
- attr_accessor :enable
31
-
32
- attr_reader :template_path, :relative_output_path
33
-
34
- def initialize
35
- @enable = 'enable'
36
- @template_path = File.join(File.dirname(__FILE__), '/templates/ssh.sh.erb').to_s
37
- @relative_output_path = 'stage2/01-sys-tweaks/ssh.sh'
38
- end
39
-
40
- def mapper(workspace)
41
- ERBMapper.new(self, workspace)
42
- end
43
-
44
- def append_line
45
- "#{@relative_output_path}"
46
- end
47
-
48
- def map(json_data)
49
- unless json_data.nil?
50
- @enable = 'disable' if json_data.has_key?('ssh') && json_data['ssh'].has_key?('enabled') && (not json_data['ssh']['enabled'])
51
- else
52
- $logger.error 'Ssh could not be configured: Invalid json data.'
53
- end
54
- end
55
-
56
- def get_binding
57
- binding
58
- end
59
-
60
- end
61
- end
@@ -1,8 +0,0 @@
1
- #!/bin/bash -e
2
-
3
- <% if @enable != 'disable' %>
4
- on_chroot << EOF
5
- systemctl <%= @enable %> ssh
6
- EOF
7
-
8
- <% end %>
@@ -1,84 +0,0 @@
1
- # Copyright (c) 2017-2019 Beate Ottenwälder
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
-
21
- require 'fileutils'
22
- require 'pi_build_modifier/modifier/mapper'
23
-
24
- module PiBuildModifier
25
-
26
- module Type
27
- FULL = 'full'
28
- LITE = 'lite'
29
- end
30
-
31
- class System < Mapper
32
-
33
- attr_reader :name, :type
34
-
35
- def initialize
36
- @name = 'custompi'
37
- @type = Type::FULL
38
- end
39
-
40
- def mapper(workspace)
41
- @workspace = workspace
42
- @relative_output_path = @workspace
43
- self
44
- end
45
-
46
- def map(json_data)
47
- unless json_data.nil?
48
- @name = json_data['system']['name'] if json_data.has_key?('system') && json_data['system'].has_key?('name')
49
- @type = json_data['system']['type'] if json_data.has_key?('system') && json_data['system'].has_key?('type')
50
- else
51
- # TODO: log error
52
- end
53
- end
54
-
55
- def modify
56
- write_name
57
- modify_type
58
- end
59
-
60
- private def modify_type
61
- if @type.nil? || @type == Type::LITE
62
- make_lite
63
- end
64
- end
65
-
66
- private def write_name
67
- FileUtils.mkdir_p "#{@workspace}"
68
- File.open("#{@workspace}/config", 'w') do |file|
69
- file.write("IMG_NAME='#{@name}'")
70
- end
71
- end
72
-
73
- private def make_lite
74
- directory = @workspace
75
- %W(#{directory}/stage3/SKIP #{directory}/stage4/SKIP #{directory}/stage5/SKIP).each do |skip_file|
76
- FileUtils.mkdir_p File.dirname(skip_file)
77
- FileUtils.touch skip_file
78
- end
79
- %W(#{directory}/stage4/EXPORT* #{directory}/stage5/EXPORT*).each do |export_file|
80
- FileUtils.rm_f export_file if File.exist?(export_file)
81
- end
82
- end
83
- end
84
- end
@@ -1,103 +0,0 @@
1
- # Copyright (c) 2017-2019 Beate Ottenwälder
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
-
21
- require_relative '../../spec_helper'
22
- require 'rspec'
23
- require 'fileutils'
24
- require 'pi_build_modifier/boot-files/boot'
25
- require 'pi_build_modifier/modifier/erb_mapper'
26
- require 'pi_build_modifier/modifier/pi_modifier'
27
-
28
- RSpec.describe PiBuildModifier::Boot do
29
-
30
- let(:empty_json_config) {'config_empty.json'}
31
- let(:full_json_config) {'config_full.json'}
32
- let(:disabled_json_config) {'config_disabled.json'}
33
- let(:workspace) {File.dirname(__FILE__) + '/workspace_boot'}
34
-
35
- before(:each) do
36
- FileUtils.mkdir_p workspace
37
- File.open(full_json_config, 'w') {|file| file.write('{ "cgroups": {
38
- "memory" : true
39
- }}')}
40
- File.open(disabled_json_config, 'w') {|file| file.write('{ "cgroups": {
41
- "memory" : false
42
- }}')}
43
- File.open(empty_json_config, 'w') {|file| file.write('{}')}
44
- end
45
-
46
- after(:each) do
47
- FileUtils.rm(empty_json_config)
48
- FileUtils.rm(full_json_config)
49
- FileUtils.rm(disabled_json_config)
50
- FileUtils.rm_rf workspace
51
- end
52
-
53
- it 'should create a cmdline.txt file with all cgroups enabled when they are specified in the resources.json' do
54
- #Given
55
- modifier = PiBuildModifier::PiModifier.new
56
- boot = PiBuildModifier::Boot.new
57
- mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
58
-
59
- #When
60
- modifier.with_json_configuration(full_json_config)
61
- modifier.with_mapper(mapper)
62
- modifier.modify
63
-
64
- #Then
65
- expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
66
- expect(File.read(workspace + '/' + boot.relative_output_path)).to match(/ cgroup_memory=1 /)
67
- end
68
-
69
- it 'should create a cmdline.txt file without cgroups enabled when they are disabled in the resources.json' do
70
- #Given
71
- modifier = PiBuildModifier::PiModifier.new
72
- boot = PiBuildModifier::Boot.new
73
- mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
74
-
75
- #When
76
- modifier.with_json_configuration(disabled_json_config)
77
- modifier.with_mapper(mapper)
78
- modifier.modify
79
-
80
- #Then
81
- expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
82
- expect(File.read(workspace + '/' + boot.relative_output_path)).to_not match(/ cgroup_memory=1 /)
83
-
84
- end
85
-
86
- it 'should create a cmdline.txt file without cgroups enabled when they are not specified' do
87
- #Given
88
- modifier = PiBuildModifier::PiModifier.new
89
- boot = PiBuildModifier::Boot.new
90
- mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
91
-
92
- #When
93
- modifier.with_json_configuration(empty_json_config)
94
- modifier.with_mapper(mapper)
95
- modifier.modify
96
-
97
- #Then
98
- expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
99
- expect(File.read(workspace + '/' + boot.relative_output_path)).to_not match(/ cgroup_memory=1 /)
100
-
101
- end
102
- end
103
-
@@ -1,87 +0,0 @@
1
- # Copyright (c) 2017-2019 Beate Ottenwälder
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
-
21
- require_relative '../../spec_helper'
22
- require 'rspec'
23
- require 'fileutils'
24
- require 'pi_build_modifier/locale/locale_debconf'
25
- require 'pi_build_modifier/sys_tweaks/run_modifier'
26
- require 'pi_build_modifier/modifier/erb_mapper'
27
- require 'pi_build_modifier/modifier/pi_modifier'
28
-
29
-
30
- RSpec.describe PiBuildModifier::Locale do
31
-
32
- let(:empty_json_config) {'config_empty.json'}
33
- let(:json_config) {'config_full.json'}
34
- let(:workspace) {File.dirname(__FILE__) + '/workspace'}
35
-
36
- before(:each) do
37
- FileUtils.mkdir_p workspace
38
- File.open(json_config, 'w') {|file| file.write('{ "locale": {
39
- "gen" : ["aaa", "bbb"],
40
- "sys" : "ccc"
41
- }}')}
42
- File.open(empty_json_config, 'w') {|file| file.write('{}')}
43
- end
44
-
45
- after(:each) do
46
- FileUtils.rm(empty_json_config)
47
- FileUtils.rm(json_config)
48
- FileUtils.rm_rf workspace
49
- end
50
-
51
- # 'en_GB.UTF-8 UTF-8', 'de_DE.UTF-8 UTF-8'
52
-
53
- it 'should create a debconf file' do
54
- #Given
55
-
56
- modifier = PiBuildModifier::PiModifier.new
57
- locale = PiBuildModifier::Locale.new
58
- mapper = PiBuildModifier::ERBMapper.new(locale, workspace)
59
-
60
- #When
61
- modifier.with_json_configuration(json_config)
62
- modifier.with_mapper(mapper)
63
- modifier.modify
64
-
65
- #Then
66
- expect(Pathname.new(workspace + '/' + locale.relative_output_path)).to be_file
67
- expect(File.read(workspace + '/' + locale.relative_output_path)).to match(/aaa, bbb/)
68
- expect(File.read(workspace + '/' + locale.relative_output_path)).to match(/ccc/)
69
- end
70
-
71
- it 'should create a default debconf file' do
72
- #Given
73
- modifier = PiBuildModifier::PiModifier.new
74
- locale = PiBuildModifier::Locale.new
75
- mapper = PiBuildModifier::ERBMapper.new(locale, workspace)
76
-
77
- #When
78
- modifier.with_json_configuration(empty_json_config)
79
- modifier.with_mapper(mapper)
80
- modifier.modify
81
-
82
- #Then
83
- expect(Pathname.new(workspace + '/' + locale.relative_output_path)).to be_file
84
-
85
- end
86
- end
87
-
@@ -1,105 +0,0 @@
1
- # Copyright (c) 2017-2019 Beate Ottenwälder
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
-
21
- require_relative '../../spec_helper'
22
- require 'rspec'
23
- require 'fileutils'
24
- require 'json'
25
- require 'pi_build_modifier/modifier/erb_mapper'
26
- require 'pi_build_modifier/modifier/mapper'
27
-
28
- module PiBuildModifier
29
-
30
- RSpec.describe Mapper do
31
- it 'should implement a method modify' do
32
- expect(Mapper.new(nil)).to respond_to(:modify)
33
- end
34
- it 'should implement a method map' do
35
- expect(Mapper.new(nil)).to respond_to(:map)
36
- end
37
- end
38
-
39
- RSpec.describe ERBMapper do
40
-
41
- let(:test_text) {'Test Text'}
42
- let(:json_path) {'test.json'}
43
- let(:template_path) {'template.erb'}
44
- let(:output_path) {File.dirname(__FILE__) + '/' + 'output.config'}
45
- let(:output_file_name) {'output.config'}
46
-
47
- @json_data = nil
48
-
49
- before do
50
- File.open(json_path, 'w') {|file| file.write('{"test":"%s"}' % [test_text])}
51
- File.open(json_path, 'r+') {|f| @json_data = JSON.parse(f.read)}
52
- File.open(template_path, 'w') {|file| file.write('<%= @test %>')}
53
- end
54
-
55
- after do
56
- FileUtils.rm(json_path)
57
- FileUtils.rm(template_path)
58
- end
59
-
60
- it 'should implement a Mapper' do
61
- expect(ERBMapper.new(TestData.new(template_path, output_file_name), '')).to be_a Mapper
62
- end
63
-
64
- it 'should raise an error when created with invalid data (i.e., the mapped data is nil)' do
65
- expect {ERBMapper.new(nil, '')}.to raise_error
66
- end
67
-
68
- it 'should map a json configuration and an erb template to a config file' do
69
-
70
- #Given
71
- mapper = ERBMapper.new(TestData.new(template_path, output_file_name), File.dirname(__FILE__))
72
-
73
- #When
74
- mapper.map(@json_data)
75
- mapper.modify
76
-
77
- #Then
78
- expect(Pathname.new(output_path)).to be_file
79
- expect(IO.binread(Pathname.new(output_path))).to eq test_text
80
-
81
- #Clean up
82
- FileUtils.rm(output_path)
83
- end
84
- end
85
-
86
- class TestData
87
-
88
- attr_accessor :test
89
- attr_reader :template_path, :relative_output_path
90
-
91
- def initialize(template_path, relative_output_path)
92
- @template_path = template_path
93
- @relative_output_path = relative_output_path
94
- end
95
-
96
- def map(data)
97
- @test = data['test']
98
- end
99
-
100
- def get_binding
101
- binding
102
- end
103
- end
104
-
105
- end