kamaze-project 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,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 '../concern'
10
+ require_relative '../helper'
11
+
12
+ # Provides access to helpers
13
+ module Kamaze::Project::Concern::Helper
14
+ protected
15
+
16
+ # @return [Sys::Proc::Helper]
17
+ def helper
18
+ Kamaze::Project::Helper.instance
19
+ end
20
+ end
@@ -0,0 +1,19 @@
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 '../concern'
10
+
11
+ # Provide access to ``mode`` (baed on environment ``PROJECT_MODE``)
12
+ module Kamaze::Project::Concern::Mode
13
+ # Get project mode
14
+ #
15
+ # @return [String]
16
+ def mode
17
+ (ENV['PROJECT_MODE'] || 'production').freeze
18
+ end
19
+ end
@@ -0,0 +1,132 @@
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 '../concern'
10
+
11
+ # Observable provides the methods for managing the associated observers.
12
+ #
13
+ # The observers SHOULD implement a method called ``update``
14
+ # to receive notifications.
15
+ #
16
+ # The observable object MNUST:
17
+ #
18
+ # * call ``#dispatch_event``
19
+ #
20
+ # Sample of use:
21
+ #
22
+ # ```ruby
23
+ # # @abstract
24
+ # class Observable
25
+ # include Kamaze::Project::Concern::Observable
26
+ # end
27
+ #
28
+ # class Subject < Observable
29
+ # attr_accessor :updated_at
30
+ #
31
+ # def update
32
+ # # do something
33
+ # dispatch_event(:after_update)
34
+ # end
35
+ # end
36
+ #
37
+ # class SubjectObserver < Kamaze::Project::Observer
38
+ # observe Subject
39
+ #
40
+ # def after_update(subject)
41
+ # subject.updated_at = Time.now
42
+ # end
43
+ # end
44
+ # ```
45
+ module Kamaze::Project::Concern::Observable
46
+ class << self
47
+ def included(base)
48
+ base.extend(ClassMethods)
49
+ end
50
+ end
51
+
52
+ # Class methods
53
+ module ClassMethods
54
+ # Add observer.
55
+ #
56
+ # @param [Class] observer_class
57
+ # @return [self]
58
+ def add_observer(observer_class, func = :handle_event)
59
+ func = func.to_sym
60
+
61
+ unless observer_class.instance_methods.include?(func)
62
+ m = "#<#{observer_class}> does not respond to `#{func}'"
63
+ raise NoMethodError, m
64
+ end
65
+
66
+ observer_peers[observer_class] = func
67
+
68
+ self
69
+ end
70
+
71
+ # Remove observer, so that it will no longer receive notifications.
72
+ #
73
+ # @param [Class] observer_class
74
+ # @return [self]
75
+ def delete_observer(observer_class)
76
+ observer_peers.delete(observer_class)
77
+
78
+ return self
79
+ end
80
+
81
+ # Remove all observers.
82
+ #
83
+ # @return [self]
84
+ def delete_observers
85
+ observers.clear
86
+
87
+ self
88
+ end
89
+
90
+ protected
91
+
92
+ # @return [Hash]
93
+ def observer_peers
94
+ @observer_peers ||= {}
95
+ end
96
+ end
97
+
98
+ def initialize
99
+ observer_peers_initialize
100
+ end
101
+
102
+ protected
103
+
104
+ # @return [Hash|nil]
105
+ attr_reader :observer_peers
106
+
107
+ # Initialize observers (defined from ``self.class.observer_peers``)
108
+ #
109
+ # @return [self]
110
+ def observer_peers_initialize
111
+ (@observer_peers ||= {}).yield_self do |observer_peers|
112
+ self.class.__send__(:observer_peers).to_h.each do |k, v|
113
+ observer_peers[k.new] = v
114
+ end
115
+ end
116
+
117
+ self
118
+ end
119
+
120
+ # Dispatch given ``event``
121
+ #
122
+ # @param [Symbol|String] event
123
+ # @param [Array<Object>] args
124
+ # @return [self]
125
+ def dispatch_event(event, *args)
126
+ observer_peers.to_h.each do |k, v|
127
+ k.__send__(v, *[event, self].concat(args))
128
+ end
129
+
130
+ self
131
+ end
132
+ end
@@ -0,0 +1,91 @@
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 '../concern'
10
+
11
+ # Concern for Sh
12
+ #
13
+ # This module provides a wrapper around ``Rake::FileUtilsExt.sh()``
14
+ module Kamaze::Project::Concern::Sh
15
+ # @!attribute [rw] shell_runner_last_status
16
+ # @return [Process::Status]
17
+
18
+ class << self
19
+ def included(base)
20
+ base.class_eval <<-"ACCESSORS", __FILE__, __LINE__ + 1
21
+ protected
22
+
23
+ attr_accessor :shell_runner_last_status
24
+
25
+ attr_writer :shell_runner_debug
26
+ ACCESSORS
27
+ end
28
+ end
29
+
30
+ # Denote shell runner is in debug mode.
31
+ #
32
+ # @return [Boolean]
33
+ def shell_runner_debug?
34
+ @shell_runner_debug.nil? ? true : @shell_runner_debug
35
+ end
36
+
37
+ protected
38
+
39
+ # Run given (``cmd``) system command.
40
+ #
41
+ # If multiple arguments are given the command is run directly
42
+ # (without the shell, same semantics as Kernel::exec and Kernel::system).
43
+ #
44
+ # @see [Rake::FileUtilsExt]
45
+ # @see https://github.com/ruby/rake/blob/68ef9140c11d083d8bb7ee5da5b0543e3a7df73d/lib/rake/file_utils.rb#L44
46
+ def sh(*cmd, &block)
47
+ require 'rake'
48
+ require 'rake/file_utils'
49
+
50
+ block ||= create_shell_runner(cmd)
51
+
52
+ ::Rake::FileUtilsExt.sh(*cmd, &block)
53
+ end
54
+
55
+ # Get shell block
56
+ #
57
+ # @param [Array] cmd
58
+ # @return [Proc]
59
+ def create_shell_runner(cmd)
60
+ proc do |ok, status|
61
+ self.shell_runner_last_status = status
62
+
63
+ if !ok and shell_runner_debug?
64
+ # rubocop:disable Layout/IndentHash
65
+ warn("Command failed with status (%<retcode>s):\n# %<command>s" % {
66
+ retcode: status.exitstatus,
67
+ command: debug_cmd(cmd.clone).gsub(/\{\}$/, '')
68
+ })
69
+ # rubocop:enable Layout/IndentHash
70
+ end
71
+ end
72
+ end
73
+
74
+ # Print a debug message
75
+ #
76
+ # @param [Array] cmd
77
+ # @return [String]
78
+ def debug_cmd(cmd)
79
+ options = cmd.last.is_a?(Hash) ? cmd.delete_at(-1) : {}
80
+
81
+ '%<command>s' % {
82
+ command: [
83
+ (cmd[0].is_a?(Hash) ? cmd.delete_at(0) : {}).to_a.map do |v|
84
+ "#{v[0]}=#{Shellwords.shellescape(v[1])}"
85
+ end.join(' '),
86
+ Shellwords.shelljoin(cmd),
87
+ options
88
+ ].join(' ')
89
+ }
90
+ end
91
+ end
@@ -0,0 +1,55 @@
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 '../concern'
10
+
11
+ # Concern tasks
12
+ #
13
+ # Stores tasks to enable and provides method to load them
14
+ module Kamaze::Project::Concern::Tasks
15
+ # Get tasks
16
+ #
17
+ # @return [Array<Symbol>]
18
+ def tasks
19
+ @tasks ||= []
20
+
21
+ @tasks.clone.freeze
22
+ end
23
+
24
+ # Set tasks
25
+ #
26
+ # @param [Array] tasks
27
+ def tasks=(tasks)
28
+ @tasks = (@tasks.to_a + tasks.to_a).map(&:to_s).map do |tn|
29
+ { ':': '/', '-': '_' }.each { |k, v| tn = tn.tr(k.to_s, v) }
30
+
31
+ tn
32
+ end.map(&:to_sym).uniq
33
+ end
34
+
35
+ protected
36
+
37
+ # Load tasks
38
+ #
39
+ # Tasks are loaded only when ``Rake::DSL`` is defined.
40
+ # ``DSL::Definition`` is loaded during tasks loading.
41
+ #
42
+ # @see Kamaze::Project::DSL::Definition
43
+ # @return [self]
44
+ def tasks_load!
45
+ if Kernel.const_defined?('Rake::DSL')
46
+ ns = Pathname.new('kamaze/project')
47
+
48
+ [ns.join('dsl/setup'),
49
+ tasks.map { |task| ns.join("tasks/#{task}") }]
50
+ .flatten.map(&:to_s).each { |req| require req }
51
+ end
52
+
53
+ self
54
+ end
55
+ end
@@ -0,0 +1,27 @@
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 '../concern'
10
+ require_relative '../../project/tools_provider'
11
+
12
+ # Provides access to tools
13
+ #
14
+ # Tools provide an extensibility mechanism
15
+ module Kamaze::Project::Concern::Tools
16
+ # Get tools
17
+ #
18
+ # @return [Hash]
19
+ def tools
20
+ @tools ||= Kamaze::Project::ToolsProvider.new
21
+ end
22
+
23
+ # @param [Hash] tools
24
+ def tools=(tools)
25
+ @tools = self.tools.merge!(tools)
26
+ end
27
+ end
@@ -0,0 +1,58 @@
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 'struct'
11
+
12
+ # Generic config(urator) class
13
+ #
14
+ # @abstract Subclass and override {#defaults} to implement
15
+ class Kamaze::Project::Config
16
+ # @return [Kamaze::Project::Struct]
17
+ attr_reader :attributes
18
+
19
+ def initialize
20
+ @attributes = Kamaze::Project::Struct.new(defaults)
21
+ end
22
+
23
+ # Configure an object (manipulating its properties)
24
+ #
25
+ # @param [Object] configurable
26
+ # @return [Object]
27
+ def configure(configurable)
28
+ to_h.each do |k, v|
29
+ configurable.__send__("#{k}=", v)
30
+ end
31
+
32
+ configurable
33
+ end
34
+
35
+ # @return [Hash]
36
+ def to_h
37
+ attributes.to_h
38
+ end
39
+
40
+ def method_missing(method, *args, &block)
41
+ if respond_to_missing?(method)
42
+ @attributes.public_send(method, *args, &block)
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def respond_to_missing?(method, include_private = false)
49
+ return true if attributes.respond_to?(method, include_private)
50
+
51
+ super(method, include_private)
52
+ end
53
+
54
+ # @return [Hash]
55
+ def defaults
56
+ {}
57
+ end
58
+ end
@@ -0,0 +1,27 @@
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
+ # Object is the default root of all Ruby objects
10
+ #
11
+ # Object inherits from BasicObject
12
+ # which allows creating alternate object hierarchies.
13
+ # Methods on Object are available to all classes
14
+ # (unless explicitly overridden).
15
+ #
16
+ # @see https://ruby-doc.org/core-2.5.0/Object.html
17
+ class Object
18
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
19
+ # Yields self to the block and returns the result of the block.
20
+ #
21
+ # @return [Object]
22
+ # @see https://ruby-doc.org/core-2.5.0/Object.html#method-i-yield_self
23
+ def yield_self
24
+ yield(self)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
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 '../debug'
10
+
11
+ # rubocop:disable Style/Documentation
12
+
13
+ class Object
14
+ private
15
+
16
+ # Print arguments in pretty form
17
+ #
18
+ # @see https://ruby-doc.org/stdlib-2.4.0/libdoc/pp/rdoc/Kernel.html
19
+ # @see https://github.com/topazproject/topaz/blob/master/lib-ruby/pp.rb
20
+ def pp(*objs)
21
+ debug = Kamaze::Project::Debug.new
22
+ objs.each { |obj| debug.dump(obj) }
23
+
24
+ objs.size <= 1 ? objs.first : objs
25
+ end
26
+ end
27
+
28
+ # rubocop:enable Style/Documentation