kamaze-project 1.0.0

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 (106) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +18 -0
  3. data/bin/plop +5 -0
  4. data/lib/kamaze-project.rb +39 -0
  5. data/lib/kamaze/project.rb +155 -0
  6. data/lib/kamaze/project/boot/core_ext.rb +16 -0
  7. data/lib/kamaze/project/boot/listen.rb +38 -0
  8. data/lib/kamaze/project/concern.rb +13 -0
  9. data/lib/kamaze/project/concern/cli.rb +53 -0
  10. data/lib/kamaze/project/concern/cli/with_exit_on_failure.rb +36 -0
  11. data/lib/kamaze/project/concern/env.rb +63 -0
  12. data/lib/kamaze/project/concern/helper.rb +20 -0
  13. data/lib/kamaze/project/concern/mode.rb +19 -0
  14. data/lib/kamaze/project/concern/observable.rb +132 -0
  15. data/lib/kamaze/project/concern/sh.rb +91 -0
  16. data/lib/kamaze/project/concern/tasks.rb +55 -0
  17. data/lib/kamaze/project/concern/tools.rb +27 -0
  18. data/lib/kamaze/project/config.rb +58 -0
  19. data/lib/kamaze/project/core_ext/object.rb +27 -0
  20. data/lib/kamaze/project/core_ext/pp.rb +28 -0
  21. data/lib/kamaze/project/debug.rb +136 -0
  22. data/lib/kamaze/project/dsl.rb +16 -0
  23. data/lib/kamaze/project/dsl/definition.rb +43 -0
  24. data/lib/kamaze/project/dsl/setup.rb +11 -0
  25. data/lib/kamaze/project/helper.rb +63 -0
  26. data/lib/kamaze/project/helper/inflector.rb +44 -0
  27. data/lib/kamaze/project/helper/project.rb +34 -0
  28. data/lib/kamaze/project/helper/project/config.rb +25 -0
  29. data/lib/kamaze/project/observable.rb +20 -0
  30. data/lib/kamaze/project/observer.rb +37 -0
  31. data/lib/kamaze/project/resources/Vagrantfile +128 -0
  32. data/lib/kamaze/project/resources/config/tools.yml +15 -0
  33. data/lib/kamaze/project/struct.rb +34 -0
  34. data/lib/kamaze/project/tasks/cs.rb +23 -0
  35. data/lib/kamaze/project/tasks/cs/control.rb +17 -0
  36. data/lib/kamaze/project/tasks/cs/correct.rb +17 -0
  37. data/lib/kamaze/project/tasks/cs/pre_commit.rb +66 -0
  38. data/lib/kamaze/project/tasks/doc.rb +21 -0
  39. data/lib/kamaze/project/tasks/doc/watch.rb +41 -0
  40. data/lib/kamaze/project/tasks/gem.rb +14 -0
  41. data/lib/kamaze/project/tasks/gem/build.rb +34 -0
  42. data/lib/kamaze/project/tasks/gem/compile.rb +30 -0
  43. data/lib/kamaze/project/tasks/gem/gemspec.rb +20 -0
  44. data/lib/kamaze/project/tasks/gem/install.rb +32 -0
  45. data/lib/kamaze/project/tasks/gem/push.rb +27 -0
  46. data/lib/kamaze/project/tasks/misc/gitignore.rb +29 -0
  47. data/lib/kamaze/project/tasks/shell.rb +17 -0
  48. data/lib/kamaze/project/tasks/sources.rb +6 -0
  49. data/lib/kamaze/project/tasks/sources/license.rb +35 -0
  50. data/lib/kamaze/project/tasks/test.rb +16 -0
  51. data/lib/kamaze/project/tasks/vagrant.rb +71 -0
  52. data/lib/kamaze/project/tasks/version/edit.rb +16 -0
  53. data/lib/kamaze/project/tools.rb +18 -0
  54. data/lib/kamaze/project/tools/base_tool.rb +55 -0
  55. data/lib/kamaze/project/tools/console.rb +48 -0
  56. data/lib/kamaze/project/tools/console/output.rb +120 -0
  57. data/lib/kamaze/project/tools/console/output/buffer.rb +48 -0
  58. data/lib/kamaze/project/tools/gemspec.rb +33 -0
  59. data/lib/kamaze/project/tools/gemspec/builder.rb +99 -0
  60. data/lib/kamaze/project/tools/gemspec/concern.rb +13 -0
  61. data/lib/kamaze/project/tools/gemspec/concern/reading.rb +49 -0
  62. data/lib/kamaze/project/tools/gemspec/packager.rb +67 -0
  63. data/lib/kamaze/project/tools/gemspec/packer.rb +89 -0
  64. data/lib/kamaze/project/tools/gemspec/packer/command.rb +143 -0
  65. data/lib/kamaze/project/tools/gemspec/reader.rb +70 -0
  66. data/lib/kamaze/project/tools/gemspec/reader/decorator.rb +78 -0
  67. data/lib/kamaze/project/tools/gemspec/writer.rb +127 -0
  68. data/lib/kamaze/project/tools/gemspec/writer/dep_gen.rb +61 -0
  69. data/lib/kamaze/project/tools/gemspec/writer/dependency.rb +104 -0
  70. data/lib/kamaze/project/tools/git.rb +95 -0
  71. data/lib/kamaze/project/tools/git/hooks.rb +66 -0
  72. data/lib/kamaze/project/tools/git/hooks/base_hook.rb +33 -0
  73. data/lib/kamaze/project/tools/git/hooks/pre_commit.rb +81 -0
  74. data/lib/kamaze/project/tools/git/status.rb +101 -0
  75. data/lib/kamaze/project/tools/git/status/decorator.rb +39 -0
  76. data/lib/kamaze/project/tools/git/status/file.rb +180 -0
  77. data/lib/kamaze/project/tools/git/status/files_array.rb +39 -0
  78. data/lib/kamaze/project/tools/git/status/index.rb +77 -0
  79. data/lib/kamaze/project/tools/git/status/worktree.rb +19 -0
  80. data/lib/kamaze/project/tools/git/util.rb +35 -0
  81. data/lib/kamaze/project/tools/licenser.rb +197 -0
  82. data/lib/kamaze/project/tools/packager.rb +86 -0
  83. data/lib/kamaze/project/tools/packager/filesystem.rb +178 -0
  84. data/lib/kamaze/project/tools/packager/filesystem/operator.rb +83 -0
  85. data/lib/kamaze/project/tools/packager/filesystem/operator/utils.rb +77 -0
  86. data/lib/kamaze/project/tools/process_locker.rb +106 -0
  87. data/lib/kamaze/project/tools/rspec.rb +115 -0
  88. data/lib/kamaze/project/tools/rubocop.rb +128 -0
  89. data/lib/kamaze/project/tools/rubocop/arguments.rb +19 -0
  90. data/lib/kamaze/project/tools/rubocop/config.rb +43 -0
  91. data/lib/kamaze/project/tools/shell.rb +85 -0
  92. data/lib/kamaze/project/tools/vagrant.rb +182 -0
  93. data/lib/kamaze/project/tools/vagrant/composer.rb +88 -0
  94. data/lib/kamaze/project/tools/vagrant/composer/file.rb +79 -0
  95. data/lib/kamaze/project/tools/vagrant/remote.rb +79 -0
  96. data/lib/kamaze/project/tools/vagrant/shell.rb +102 -0
  97. data/lib/kamaze/project/tools/vagrant/writer.rb +81 -0
  98. data/lib/kamaze/project/tools/yardoc.rb +75 -0
  99. data/lib/kamaze/project/tools/yardoc/file.rb +55 -0
  100. data/lib/kamaze/project/tools/yardoc/watchable.rb +70 -0
  101. data/lib/kamaze/project/tools/yardoc/watcher.rb +106 -0
  102. data/lib/kamaze/project/tools_provider.rb +161 -0
  103. data/lib/kamaze/project/tools_provider/resolver.rb +42 -0
  104. data/lib/kamaze/project/version.rb +104 -0
  105. data/lib/kamaze/project/version.yml +17 -0
  106. metadata +321 -0
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../project'
10
+ require 'tty/screen'
11
+ require 'active_support/inflector'
12
+
13
+ # Provides colored pretty-printer automagically
14
+ #
15
+ # @see http://ruby-doc.org/stdlib-2.0.0/libdoc/pp/rdoc/PP.html
16
+ # @see https://github.com/pry/pry
17
+ class Kamaze::Project::Debug
18
+ def initialize
19
+ @inflector ||= ActiveSupport::Inflector
20
+ @printers = available_printers
21
+ end
22
+
23
+ class << self
24
+ # @return [Boolean]
25
+ def warned?
26
+ @warned || false
27
+ end
28
+
29
+ protected
30
+
31
+ # @return [Boolean]
32
+ attr_accessor :warned
33
+ end
34
+
35
+ # @return [Array<PP>]
36
+ attr_reader :printers
37
+
38
+ # @return [Boolean]
39
+ def warned?
40
+ self.class.warned?
41
+ end
42
+
43
+ # Outputs obj to out in pretty printed format of width columns in width.
44
+ #
45
+ # If out is omitted, ``STDOUT`` is assumed.
46
+ # If width is omitted, ``79`` is assumed.
47
+ #
48
+ # @param [Object] obj
49
+ # @param [IO] out
50
+ # @param [Fixnum] width
51
+ # @see http://ruby-doc.org/stdlib-2.2.0/libdoc/pp/rdoc/PP.html
52
+ def dump(obj, out = $stdout, width = nil)
53
+ width ||= TTY::Screen.width || 79
54
+
55
+ printer_for(out).pp(obj, out, width)
56
+ end
57
+
58
+ # Get printer for given output
59
+ #
60
+ # @param [IO] out
61
+ # @return [PP]
62
+ def printer_for(out)
63
+ out_tty = out.respond_to?(:isatty) and out.isatty
64
+
65
+ printers[out_tty ? 0 : 1]
66
+ end
67
+
68
+ # Get printers
69
+ #
70
+ # First printer SHOULD be the color printer, secund is the default printer
71
+ #
72
+ # @return [Array<PP>]
73
+ def available_printers
74
+ load_printers
75
+
76
+ default = '::PP'
77
+
78
+ [
79
+ proc do
80
+ target = '::Pry::ColorPrinter'
81
+
82
+ Kernel.const_defined?(target) ? target : default
83
+ end.call,
84
+ default
85
+ ].map { |n| inflector.constantize(n) }.freeze
86
+ end
87
+
88
+ protected
89
+
90
+ # @return [Boolean|nil]
91
+ attr_reader :warned
92
+
93
+ # @return [Class]
94
+ attr_reader :inflector
95
+
96
+ # Load printers requirements (on demand)
97
+ #
98
+ # @return [self]
99
+ def load_printers
100
+ Object.const_set('Pry', Class.new) unless Kernel.const_defined?('::Pry')
101
+
102
+ begin
103
+ load_printer_requirements
104
+ rescue LoadError => e
105
+ self.class.__send__('warned=', !!warn_error(e)) unless warned?
106
+ end
107
+
108
+ self
109
+ end
110
+
111
+ # @raise [LoadError]
112
+ # @return [self]
113
+ def load_printer_requirements
114
+ ['pp',
115
+ 'coderay',
116
+ 'pry/pager',
117
+ 'pry/color_printer'].each { |req| require req }
118
+
119
+ self
120
+ end
121
+
122
+ # Display the given exception message (followed by a newline) on STDERR
123
+ #
124
+ # unless warnings are disabled (for example with the -W0 flag).
125
+ #
126
+ # @param [Exception] error
127
+ # @return [Array<String>]
128
+ def warn_error(error)
129
+ formats = { from: caller(1..1).first, mssg: error.message }
130
+ message = '%<from>s: %<mssg>s' % formats
131
+
132
+ warn(message)
133
+
134
+ formats.values
135
+ end
136
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../project'
10
+
11
+ # rubocop:disable Style/Documentation
12
+ class Kamaze::Project
13
+ module DSL
14
+ end
15
+ end
16
+ # rubocop:enable Style/Documentation
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../dsl'
10
+
11
+ # rubocop:disable Style/Documentation
12
+ module Kamaze::Project::DSL
13
+ module Definition
14
+ end
15
+ end
16
+ # rubocop:enable Style/Documentation
17
+
18
+ # ``DSL::Definition`` provides access to ``project`` and ``tools`` methods
19
+ module Kamaze::Project::DSL::Definition
20
+ protected
21
+
22
+ # Get project
23
+ #
24
+ # @return [Kamaze::Project]
25
+ def project
26
+ @project_dsl_stored ||= Kamaze.project
27
+ end
28
+
29
+ # Get tools
30
+ #
31
+ # @return [Kamaze::Project::ToolsProvider]
32
+ def tools
33
+ project.tools
34
+ end
35
+
36
+ private
37
+
38
+ def project_dsl_reset
39
+ @project_dsl_stored = nil
40
+
41
+ self
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative 'definition'
10
+
11
+ self.extend Kamaze::Project::DSL::Definition
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require 'kamaze/project'
10
+ require 'singleton'
11
+
12
+ # Provides access to helper classes
13
+ class Kamaze::Project::Helper
14
+ include ::Singleton
15
+
16
+ class << self
17
+ attr_reader :ns
18
+ end
19
+
20
+ @ns = :'kamaze/project/helper'
21
+
22
+ # @param [String|Symbol] name
23
+ # @return [Object]
24
+ #
25
+ # @raise [NotImplementedError]
26
+ def get(name)
27
+ name = name.to_sym
28
+
29
+ return items[name] if items[name]
30
+
31
+ begin
32
+ @items[name] = inflector.resolve("#{self.class.ns}/#{name}").new
33
+ rescue LoadError
34
+ raise NotImplementedError, "helper not loadable: #{name}"
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ attr_reader :items
41
+
42
+ def initialize
43
+ @items = {
44
+ inflector: proc do
45
+ require "#{self.class.ns}/inflector"
46
+
47
+ Inflector.new
48
+ end.call
49
+ }
50
+
51
+ super
52
+ end
53
+
54
+ # @return [Hash]
55
+ def to_h
56
+ items
57
+ end
58
+
59
+ # @return [Sys::Proc::Helper::Inflector]
60
+ def inflector
61
+ to_h.fetch(:inflector)
62
+ end
63
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require 'kamaze/project/helper'
10
+
11
+ # Inflector built on top of ``Dry::Inflector``
12
+ class Kamaze::Project::Helper::Inflector
13
+ def initialize
14
+ require 'dry/inflector'
15
+
16
+ @inflector = Dry::Inflector.new
17
+ end
18
+
19
+ # Load constant from a loadable/requirable path
20
+ #
21
+ # @param [String] loadable
22
+ # @return [Object]
23
+ def resolve(loadable)
24
+ loadable = loadable.to_s.empty? ? nil : loadable.to_s
25
+
26
+ require loadable
27
+
28
+ @inflector.constantize(@inflector.classify(loadable))
29
+ end
30
+
31
+ def method_missing(method, *args, &block)
32
+ if respond_to_missing?(method)
33
+ @inflector.public_send(method, *args, &block)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def respond_to_missing?(method, include_private = false)
40
+ return true if @inflector.respond_to?(method, include_private)
41
+
42
+ super(method, include_private)
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require 'kamaze/project/helper'
10
+
11
+ # Store last configured project
12
+ #
13
+ # @see Kamaze::Project
14
+ class Kamaze::Project::Helper::Project
15
+ # @return [Kamaze::Project]
16
+ attr_reader :memo
17
+
18
+ # @return [Kamaze::Project]
19
+ def setup(&block)
20
+ @memo = Kamaze::Project.new(&block) if block
21
+ @memo = Kamaze::Project.new if memo.nil? and block.nil?
22
+
23
+ self.memo
24
+ end
25
+
26
+ # Forget stored state
27
+ #
28
+ # return [self]
29
+ def forget
30
+ @memo = nil
31
+
32
+ self
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../project'
10
+ require_relative '../../config'
11
+
12
+ # Config used to configure ``Kamaze::Project``
13
+ #
14
+ # @see Kamaze::Project.initialize
15
+ class Kamaze::Project::Helper::Project::Config < Kamaze::Project::Config
16
+ # @return [Hash]
17
+ def defaults
18
+ {
19
+ tasks: nil,
20
+ name: nil,
21
+ subject: nil,
22
+ tools: {}
23
+ }
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../project'
10
+ require_relative 'concern/observable'
11
+ # implicitely require observer
12
+ require_relative 'observer'
13
+
14
+ # Observable provides the methods for managing the associated observers.
15
+ #
16
+ # @abstract
17
+ # @see Kamaze::Project::Concern::Observable
18
+ class Kamaze::Project::Observable
19
+ include Kamaze::Project::Concern::Observable
20
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
4
+ # License GPLv3+: GNU GPL version 3 or later
5
+ # <http://www.gnu.org/licenses/gpl.html>.
6
+ # This is free software: you are free to change and redistribute it.
7
+ # There is NO WARRANTY, to the extent permitted by law.
8
+
9
+ require_relative '../project'
10
+
11
+ # Observer class
12
+ #
13
+ # @abstract
14
+ # @see Kamaze::Project::Observable
15
+ # @see Kamaze::Project::Concern::Observable
16
+ class Kamaze::Project::Observer
17
+ class << self
18
+ # Subscribe to given class.
19
+ #
20
+ # @param [Class] observed_class
21
+ # @return [self]
22
+ def observe(observed_class, func = nil)
23
+ observed_class.add_observer(*[self, func].compact)
24
+
25
+ self
26
+ end
27
+ end
28
+
29
+ # Callback for observer.
30
+ #
31
+ # @return [self]
32
+ def handle_event(func, *args)
33
+ self.__send__(func, *args) if self.respond_to?(func, true)
34
+
35
+ self
36
+ end
37
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Vagrant CAN NOT cohabitate well with bundler,
4
+ # this bootstrap DOES NOT load any project sources.
5
+ # This file is used as a kind of template.
6
+ # ``boxes`` variable is defined at runtime.
7
+ #
8
+ # @see Kamaze::Project::Tools::Vagrant
9
+
10
+ require 'pp'
11
+ require 'pathname'
12
+
13
+ # requires -----------------------------------------------------------
14
+ requires_from_boxes = lambda do |boxes|
15
+ pwd = ::Pathname.new(Dir.pwd)
16
+
17
+ Array.new.tap do |requires|
18
+ boxes.each do |box, box_config|
19
+ requires.concat(box_config['requires'] || [])
20
+ end
21
+ end.map do |req|
22
+ req = pwd.join(req.to_s).realpath if pwd.join(req.to_s).file?
23
+ require req.to_s
24
+ req
25
+ end
26
+ end
27
+
28
+ # synced folders -----------------------------------------------------
29
+ synced_folders_config = lambda do |config, box_config|
30
+ (box_config['synced_folders'] || []).each do |s|
31
+ folders = s.delete(:folders)
32
+
33
+ config.vm.synced_folder(*folders, **s)
34
+ end
35
+ end
36
+
37
+ # modifyvm config ----------------------------------------------------
38
+ modifyvm_config = lambda do |config, box_config|
39
+ provider = box_config.fetch('provider')
40
+ modifyvm = box_config['modifyvm']
41
+
42
+ (modifyvm || []).each do |c|
43
+ config.vm.provider(provider) do |v|
44
+ c[0] = "--#{c[0]}" if c[0] and c[0].slice(0, 2) != '--'
45
+
46
+ v.customize(['modifyvm', :id] + c.map(&:to_s))
47
+ end
48
+ end
49
+ end
50
+
51
+ # machine config -----------------------------------------------------
52
+ machine_config = lambda do |config, name, box_config, &block|
53
+ config.vm.define name, autostart: false do |machine|
54
+ box, version = box_config.fetch('image').split(':')
55
+ machine.vm.box = box
56
+ machine.vm.box_version = version if version
57
+
58
+ block&.call(machine)
59
+ end
60
+ end
61
+
62
+ # machine networks config ---------------------------------------------
63
+ machine_networks_config = lambda do |machine, box_config|
64
+ (box_config['networks'] || []).each do |c|
65
+ machine.vm.network(*(c[0] || []), **(c[1] || {}))
66
+ end
67
+ end
68
+
69
+ # machine config vm --------------------------------------------------
70
+ # @see https://www.vagrantup.com/docs/vagrantfile/machine_settings.html
71
+ machine_vm_config = lambda do |machine, box_config|
72
+ ['guest', 'hostname', 'communicator'].each do |k|
73
+ next unless box_config.member?(k)
74
+
75
+ box_config.fetch(k).tap do |v|
76
+ machine.vm.public_send("#{k}=", v)
77
+ end
78
+ end
79
+ end
80
+
81
+ # machine provisions -------------------------------------------------
82
+ machine_provisions_config = lambda do |machine, box_config|
83
+ provisions = box_config['provisions']
84
+ (provisions || []).each do |provision|
85
+ type = provision.delete(:type)&.to_s
86
+
87
+ machine.vm.provision(type, **provision)
88
+ end
89
+ end
90
+
91
+ # @see https://github.com/guard/listen/wiki/Duplicate-directory-errors
92
+ #
93
+ # Listen >=2.8
94
+ # patch to silence duplicate directory errors. USE AT YOUR OWN RISK
95
+ if YAML.safe_load(ENV['SILENCE_DUPLICATE_DIRECTORY_ERRORS'].to_s)
96
+ require 'listen'
97
+
98
+ # rubocop:disable all
99
+ if Gem::Version.new(Listen::VERSION) >= Gem::Version.new('2.8.0')
100
+ module Listen
101
+ class Record
102
+ class SymlinkDetector
103
+ def _fail(_, _)
104
+ fail Error, "Don't watch locally-symlinked directory twice"
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ # rubocop:enable all
111
+ end
112
+
113
+ # configure ----------------------------------------------------------
114
+ Vagrant.configure(2) do |config|
115
+ requires_from_boxes.call(boxes)
116
+ boxes.each do |box, box_config|
117
+ next if box_config['disabled']
118
+
119
+ modifyvm_config.call(config, box_config)
120
+ synced_folders_config.call(config, box_config)
121
+
122
+ machine_config.call(config, box, box_config) do |machine|
123
+ machine_networks_config.call(machine, box_config)
124
+ machine_vm_config.call(machine, box_config)
125
+ machine_provisions_config.call(machine, box_config)
126
+ end
127
+ end
128
+ end