makit 0.0.99 → 0.0.111

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -0
  3. data/exe/makit +5 -0
  4. data/lib/makit/apache.rb +7 -11
  5. data/lib/makit/cli/build_commands.rb +500 -0
  6. data/lib/makit/cli/generators/base_generator.rb +74 -0
  7. data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
  8. data/lib/makit/cli/generators/generator_factory.rb +49 -0
  9. data/lib/makit/cli/generators/node_generator.rb +50 -0
  10. data/lib/makit/cli/generators/ruby_generator.rb +77 -0
  11. data/lib/makit/cli/generators/rust_generator.rb +50 -0
  12. data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
  13. data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
  14. data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
  15. data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
  16. data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
  17. data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
  18. data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
  19. data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
  20. data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
  21. data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
  22. data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
  23. data/lib/makit/cli/main.rb +48 -19
  24. data/lib/makit/cli/project_commands.rb +868 -0
  25. data/lib/makit/cli/repository_commands.rb +661 -0
  26. data/lib/makit/cli/utility_commands.rb +521 -0
  27. data/lib/makit/command_runner.rb +187 -128
  28. data/lib/makit/commands/compatibility.rb +365 -0
  29. data/lib/makit/commands/factory.rb +359 -0
  30. data/lib/makit/commands/middleware/base.rb +73 -0
  31. data/lib/makit/commands/middleware/cache.rb +248 -0
  32. data/lib/makit/commands/middleware/command_logger.rb +323 -0
  33. data/lib/makit/commands/middleware/unified_logger.rb +243 -0
  34. data/lib/makit/commands/middleware/validator.rb +269 -0
  35. data/lib/makit/commands/request.rb +254 -0
  36. data/lib/makit/commands/result.rb +323 -0
  37. data/lib/makit/commands/runner.rb +317 -0
  38. data/lib/makit/commands/strategies/base.rb +160 -0
  39. data/lib/makit/commands/strategies/synchronous.rb +134 -0
  40. data/lib/makit/commands.rb +24 -3
  41. data/lib/makit/configuration/gitlab_helper.rb +60 -0
  42. data/lib/makit/configuration/project.rb +127 -0
  43. data/lib/makit/configuration/rakefile_helper.rb +43 -0
  44. data/lib/makit/configuration/step.rb +34 -0
  45. data/lib/makit/configuration.rb +14 -0
  46. data/lib/makit/content/default_gitignore.rb +4 -2
  47. data/lib/makit/content/default_rakefile.rb +4 -2
  48. data/lib/makit/content/gem_rakefile.rb +4 -2
  49. data/lib/makit/context.rb +1 -0
  50. data/lib/makit/data.rb +9 -10
  51. data/lib/makit/directories.rb +48 -52
  52. data/lib/makit/directory.rb +38 -52
  53. data/lib/makit/docs/files.rb +5 -10
  54. data/lib/makit/docs/rake.rb +16 -20
  55. data/lib/makit/dotnet/cli.rb +65 -0
  56. data/lib/makit/dotnet/project.rb +153 -0
  57. data/lib/makit/dotnet/solution.rb +38 -0
  58. data/lib/makit/dotnet/solution_classlib.rb +239 -0
  59. data/lib/makit/dotnet/solution_console.rb +264 -0
  60. data/lib/makit/dotnet/solution_maui.rb +354 -0
  61. data/lib/makit/dotnet/solution_wasm.rb +275 -0
  62. data/lib/makit/dotnet/solution_wpf.rb +304 -0
  63. data/lib/makit/dotnet.rb +54 -171
  64. data/lib/makit/email.rb +46 -17
  65. data/lib/makit/environment.rb +22 -19
  66. data/lib/makit/examples/runner.rb +370 -0
  67. data/lib/makit/exceptions.rb +45 -0
  68. data/lib/makit/fileinfo.rb +3 -5
  69. data/lib/makit/files.rb +12 -16
  70. data/lib/makit/gems.rb +40 -39
  71. data/lib/makit/git/cli.rb +54 -0
  72. data/lib/makit/git/repository.rb +90 -0
  73. data/lib/makit/git.rb +44 -91
  74. data/lib/makit/gitlab_runner.rb +0 -1
  75. data/lib/makit/humanize.rb +31 -23
  76. data/lib/makit/indexer.rb +15 -24
  77. data/lib/makit/logging/configuration.rb +305 -0
  78. data/lib/makit/logging/format_registry.rb +84 -0
  79. data/lib/makit/logging/formatters/base.rb +39 -0
  80. data/lib/makit/logging/formatters/console_formatter.rb +127 -0
  81. data/lib/makit/logging/formatters/json_formatter.rb +65 -0
  82. data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
  83. data/lib/makit/logging/formatters/text_formatter.rb +64 -0
  84. data/lib/makit/logging/log_request.rb +115 -0
  85. data/lib/makit/logging/logger.rb +159 -0
  86. data/lib/makit/logging/sinks/base.rb +91 -0
  87. data/lib/makit/logging/sinks/console.rb +72 -0
  88. data/lib/makit/logging/sinks/file_sink.rb +92 -0
  89. data/lib/makit/logging/sinks/structured.rb +129 -0
  90. data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
  91. data/lib/makit/logging.rb +452 -37
  92. data/lib/makit/markdown.rb +18 -18
  93. data/lib/makit/mp/basic_object_mp.rb +5 -4
  94. data/lib/makit/mp/command_mp.rb +5 -5
  95. data/lib/makit/mp/command_request.mp.rb +3 -2
  96. data/lib/makit/mp/project_mp.rb +85 -96
  97. data/lib/makit/mp/string_mp.rb +245 -73
  98. data/lib/makit/nuget.rb +27 -25
  99. data/lib/makit/port.rb +25 -27
  100. data/lib/makit/process.rb +127 -29
  101. data/lib/makit/protoc.rb +27 -24
  102. data/lib/makit/rake/cli.rb +196 -0
  103. data/lib/makit/rake.rb +6 -6
  104. data/lib/makit/ruby/cli.rb +185 -0
  105. data/lib/makit/ruby.rb +25 -0
  106. data/lib/makit/secrets.rb +18 -18
  107. data/lib/makit/serializer.rb +29 -27
  108. data/lib/makit/services/builder.rb +186 -0
  109. data/lib/makit/services/error_handler.rb +226 -0
  110. data/lib/makit/services/repository_manager.rb +229 -0
  111. data/lib/makit/services/validator.rb +112 -0
  112. data/lib/makit/setup/classlib.rb +53 -0
  113. data/lib/makit/setup/gem.rb +250 -0
  114. data/lib/makit/setup/runner.rb +40 -0
  115. data/lib/makit/show.rb +16 -16
  116. data/lib/makit/storage.rb +32 -37
  117. data/lib/makit/symbols.rb +12 -0
  118. data/lib/makit/task_hooks.rb +125 -0
  119. data/lib/makit/task_info.rb +63 -21
  120. data/lib/makit/tasks/at_exit.rb +13 -0
  121. data/lib/makit/tasks/build.rb +18 -0
  122. data/lib/makit/tasks/clean.rb +11 -0
  123. data/lib/makit/tasks/hook_manager.rb +239 -0
  124. data/lib/makit/tasks/init.rb +47 -0
  125. data/lib/makit/tasks/integrate.rb +15 -0
  126. data/lib/makit/tasks/pull_incoming.rb +12 -0
  127. data/lib/makit/tasks/setup.rb +6 -0
  128. data/lib/makit/tasks/sync.rb +11 -0
  129. data/lib/makit/tasks/task_monkey_patch.rb +79 -0
  130. data/lib/makit/tasks.rb +5 -150
  131. data/lib/makit/test_cache.rb +239 -0
  132. data/lib/makit/v1/makit.v1_pb.rb +34 -35
  133. data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
  134. data/lib/makit/version.rb +1 -57
  135. data/lib/makit/wix.rb +23 -23
  136. data/lib/makit/yaml.rb +18 -6
  137. data/lib/makit.rb +2 -261
  138. metadata +109 -145
  139. data/lib/makit/cli/clean.rb +0 -14
  140. data/lib/makit/cli/clone.rb +0 -59
  141. data/lib/makit/cli/init.rb +0 -38
  142. data/lib/makit/cli/make.rb +0 -54
  143. data/lib/makit/cli/new.rb +0 -37
  144. data/lib/makit/cli/nuget_cache.rb +0 -38
  145. data/lib/makit/cli/pull.rb +0 -31
  146. data/lib/makit/cli/setup.rb +0 -71
  147. data/lib/makit/cli/work.rb +0 -21
  148. data/lib/makit/content/default_gitignore.txt +0 -222
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module provides classes for the Makit gem.
4
+ module Makit
5
+ class Git
6
+ # This class provides methods for executing git commands and operations
7
+ # that modify repository state.
8
+ class CLI
9
+ def self.integrate
10
+ return unless Repository.git_repo? && !Repository.detached
11
+
12
+ ## check for unstaged or untracked files
13
+ unstaged_files = `git status --porcelain`.split("\n")
14
+ untracked_files = `git ls-files --others --exclude-standard`.split("\n")
15
+ return unless unstaged_files.length.positive? || untracked_files.length.positive?
16
+
17
+ "git add .".run
18
+ "git commit -m \"integrate\"".run unless Repository.clean?
19
+ end
20
+
21
+ def self.sync
22
+ return unless Repository.git_repo? && !Repository.detached
23
+
24
+ "git pull".try
25
+ "git push origin".try
26
+ "git push origin --tags".try
27
+ end
28
+
29
+ def self.pull
30
+ return unless Repository.git_repo? && !Repository.detached
31
+
32
+ "git pull".try
33
+ end
34
+
35
+ def self.zip_source_files(zipfilename)
36
+ "git archive --format zip --output #{zipfilename} HEAD".run
37
+ end
38
+
39
+ def self.tag(version)
40
+ # only tag if the repo is not read only
41
+ if Repository.read_only?
42
+ puts " cannot tag a read only repo".colorize(:red)
43
+ return
44
+ end
45
+ # check if a tag for the current version already exists
46
+ if `git tag -l v#{version}`.strip.length.positive?
47
+ puts " tag v#{version} already exists".colorize(:red)
48
+ else
49
+ "git tag -a v#{version} -m \"version #{version}\"".run
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module provides classes for the Makit gem.
4
+ module Makit
5
+ class Git
6
+ # This class provides methods for querying git repository state and metadata.
7
+ class Repository
8
+ def self.git_repo?
9
+ Dir.exist? ".git"
10
+ end
11
+
12
+ def self.ci?
13
+ ENV["CI"] == "true"
14
+ end
15
+
16
+ def self.detached
17
+ `git status`.include?("detached")
18
+ end
19
+
20
+ def self.read_only?
21
+ !git_repo? || detached
22
+ end
23
+
24
+ def self.clean?
25
+ `git status --porcelain`.empty?
26
+ end
27
+
28
+ def self.unstaged_files
29
+ `git status --porcelain`.split("\n")
30
+ end
31
+
32
+ def self.untracked_files
33
+ `git ls-files --others --exclude-standard`.split("\n")
34
+ end
35
+
36
+ def self.get_file_infos
37
+ file_infos = []
38
+ file_list = `git ls-files`.split("\n")
39
+ # iterate over the filelist and get the file infos
40
+ file_list.each do |file|
41
+ file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
42
+ rescue StandardError
43
+ next
44
+ end
45
+ file_infos.sort_by!(&:mtime).reverse!
46
+ file_infos
47
+ end
48
+
49
+ def self.get_untracked_file_infos
50
+ file_infos = []
51
+ file_list = `git ls-files --others --exclude-standard`.split("\n")
52
+ file_list.each do |file|
53
+ file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
54
+ rescue StandardError
55
+ next
56
+ end
57
+ file_infos.sort_by!(&:mtime).reverse!
58
+ file_infos
59
+ end
60
+
61
+ def self.branch
62
+ `git branch --show-current`.strip
63
+ end
64
+
65
+ def self.commitsha
66
+ `git rev-parse HEAD`.strip
67
+ end
68
+
69
+ def self.commitmsg
70
+ `git log -1 --pretty=%B`.strip
71
+ end
72
+
73
+ def self.commitdate
74
+ `git log -1 --pretty=%cd`.strip
75
+ end
76
+
77
+ def self.commitauthor
78
+ `git log -1 --pretty=%an`.strip
79
+ end
80
+
81
+ def self.commitemail
82
+ `git log -1 --pretty=%ae`.strip
83
+ end
84
+
85
+ def self.get_remote_url
86
+ `git remote get-url origin`.strip
87
+ end
88
+ end
89
+ end
90
+ end
data/lib/makit/git.rb CHANGED
@@ -1,145 +1,98 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "git/repository"
4
+ require_relative "git/cli"
5
+
3
6
  # This module provides classes for the Makit gem.
4
7
  module Makit
5
- # This class provide methods for working with the system Environment.
8
+ # This class provides a unified interface for git operations.
9
+ # Methods have been organized into Repository (state/metadata) and CLI (commands) classes.
6
10
  #
7
11
  class Git
8
- def self.is_git_repo
9
- Dir.exist? ".git"
12
+ # Delegate repository state and metadata methods to Repository class
13
+ def self.git_repo?
14
+ Repository.git_repo?
10
15
  end
11
16
 
12
- def self.is_ci
13
- ENV["CI"] == "true"
17
+ def self.ci?
18
+ Repository.ci?
14
19
  end
15
20
 
16
21
  def self.detached
17
- `git status`.include?("detached")
22
+ Repository.detached
18
23
  end
19
24
 
20
- def self.is_read_only
21
- !is_git_repo || detached
25
+ def self.read_only?
26
+ Repository.read_only?
22
27
  end
23
28
 
24
- def self.is_clean
25
- `git status --porcelain`.empty?
29
+ def self.clean?
30
+ Repository.clean?
26
31
  end
27
32
 
28
33
  def self.unstaged_files
29
- `git status --porcelain`.split("\n")
34
+ Repository.unstaged_files
30
35
  end
31
36
 
32
37
  def self.untracked_files
33
- `git ls-files --others --exclude-standard`.split("\n")
34
- end
35
-
36
- def self.integrate
37
- if is_git_repo && !detached
38
- ## check for unstaged or untracked files
39
- unstaged_files = `git status --porcelain`.split("\n")
40
- untracked_files = `git ls-files --others --exclude-standard`.split("\n")
41
- if unstaged_files.length > 0 || untracked_files.length > 0
42
- "git add .".run
43
- "git commit -m \"integrate\"".run unless is_clean
44
- end
45
- end
46
- end
47
-
48
- def self.sync
49
- if is_git_repo && !detached
50
- "git pull".try
51
- "git push origin".try
52
- "git push origin --tags".try
53
- end
54
- end
55
-
56
- def self.pull
57
- if is_git_repo && !detached
58
- "git pull".try
59
- end
60
- end
61
-
62
- def self.zip_source_files(zipfilename)
63
- "git archive --format zip --output #{zipfilename} HEAD".run
38
+ Repository.untracked_files
64
39
  end
65
40
 
66
41
  def self.get_file_infos
67
- file_infos = []
68
- file_list = `git ls-files`.split("\n")
69
- # iterate over the filelist and get the file infos
70
- file_list.each do |file|
71
- begin
72
- file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
73
- rescue
74
- next
75
- end
76
- end
77
- file_infos.sort_by! { |info| info.mtime }.reverse!
78
- file_infos
42
+ Repository.get_file_infos
79
43
  end
80
44
 
81
45
  def self.get_untracked_file_infos
82
- #Makit::FileInfo::get_file_infos(`git ls-files --others --exclude=standard`.split("\n")).sort_by! { |info| info.mtime }.reverse!
83
- file_infos = []
84
- file_list = `git ls-files --others --exclude=standard`.split("\n")
85
- file_list.each do |file|
86
- begin
87
- file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
88
- rescue
89
- next
90
- end
91
- end
92
- file_infos.sort_by! { |info| info.mtime }.reverse!
93
- file_infos
94
- # file_infos << FileInfo.new(name: path, mtime: File.mtime(path), size: File.size(path))
95
- # rescue
96
- # next
97
- #ß end
98
- #end
99
- #file_infos.sort_by! { |info| info.mtime }.reverse!
100
- #file_infos
46
+ Repository.get_untracked_file_infos
101
47
  end
102
48
 
103
49
  def self.branch
104
- `git branch --show-current`.strip
50
+ Repository.branch
105
51
  end
106
52
 
107
53
  def self.commitsha
108
- `git rev-parse HEAD`.strip
54
+ Repository.commitsha
109
55
  end
110
56
 
111
57
  def self.commitmsg
112
- `git log -1 --pretty=%B`.strip
58
+ Repository.commitmsg
113
59
  end
114
60
 
115
61
  def self.commitdate
116
- `git log -1 --pretty=%cd`.strip
62
+ Repository.commitdate
117
63
  end
118
64
 
119
65
  def self.commitauthor
120
- `git log -1 --pretty=%an`.strip
66
+ Repository.commitauthor
121
67
  end
122
68
 
123
69
  def self.commitemail
124
- `git log -1 --pretty=%ae`.strip
70
+ Repository.commitemail
125
71
  end
126
72
 
127
73
  def self.get_remote_url
128
- `git remote get-url origin`.strip
74
+ Repository.get_remote_url
75
+ end
76
+
77
+ # Delegate command execution methods to CLI class
78
+ def self.integrate
79
+ CLI.integrate
80
+ end
81
+
82
+ def self.sync
83
+ CLI.sync
84
+ end
85
+
86
+ def self.pull
87
+ CLI.pull
88
+ end
89
+
90
+ def self.zip_source_files(zipfilename)
91
+ CLI.zip_source_files(zipfilename)
129
92
  end
130
93
 
131
94
  def self.tag(version)
132
- # only tag if the repo is not read only
133
- if is_read_only
134
- puts " cannot tag a read only repo".colorize(:red)
135
- return
136
- end
137
- # check if a tag for the current version already exists
138
- if (`git tag -l v#{version}`.strip.length > 0)
139
- puts " tag v#{version} already exists".colorize(:red)
140
- else
141
- "git tag -a v#{version} -m \"version #{version}\"".run
142
- end
95
+ CLI.tag(version)
143
96
  end
144
97
  end
145
98
  end
@@ -12,7 +12,6 @@ module Makit
12
12
  # Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
13
13
  #
14
14
  class GitLabRunner
15
-
16
15
  # Parse the .gitlab-ci.yml file
17
16
  def parse_gitlab_ci_file(file_path)
18
17
  YAML.load_file(file_path)
@@ -2,10 +2,19 @@
2
2
 
3
3
  # This module provides classes for the Makit gem.
4
4
  module Makit
5
+ # Provides utilities for converting data into human-readable formats.
6
+ #
7
+ # This class handles formatting of file sizes, timestamps, durations,
8
+ # and build result summaries for display to users.
9
+ #
10
+ # @example Basic usage
11
+ # Makit::Humanize.get_humanized_size(1024) # => "1.00 KB"
12
+ # Makit::Humanize.get_humanized_duration(3661) # => "1 hour, 1 minute, 1 second"
13
+ #
5
14
  class Humanize
6
15
  def self.get_humanized_size(bytes, precision = 2)
7
- units = ["B", "KB", "MB", "GB", "TB", "PB"]
8
- return "0 B" if bytes == 0
16
+ units = %w[B KB MB GB TB PB]
17
+ return "0 B" if bytes.zero?
9
18
 
10
19
  exp = (Math.log(bytes) / Math.log(1024)).to_i
11
20
  exp = units.size - 1 if exp >= units.size
@@ -16,6 +25,7 @@ module Makit
16
25
 
17
26
  def self.get_humanized_timestamp(timestamp)
18
27
  return timestamp.strftime("%Y-%m-%d %I:%M:%S %p") if timestamp.respond_to?(:strftime)
28
+
19
29
  timestamp.strftime("%Y-%m-%d %H:%M:%S")
20
30
  end
21
31
 
@@ -44,7 +54,7 @@ module Makit
44
54
  def self.get_commands(commands)
45
55
  message = ""
46
56
  commands.each do |command|
47
- message += Makit::Humanize::get_command_details(command)
57
+ message += Makit::Humanize.get_command_details(command)
48
58
  end
49
59
  message
50
60
  end
@@ -62,12 +72,12 @@ module Makit
62
72
  summary += " Arguments: #{command.arguments.join(" ")}\n"
63
73
  summary += " Directory: #{command.directory}\n"
64
74
  summary += " Exit Code: #{command.exit_code}\n"
65
- if command.output.length > 0
75
+ if command.output.length.positive?
66
76
  summary += " Output:\n"
67
77
  summary += indent_string(command.output, 4)
68
78
  summary += "\n"
69
79
  end
70
- if command.error.length > 0
80
+ if command.error.length.positive?
71
81
  summary += " Error:\n"
72
82
  summary += indent_string(command.error, 4)
73
83
  summary += "\n"
@@ -76,7 +86,7 @@ module Makit
76
86
  end
77
87
 
78
88
  def self.indent_string(string, spaces)
79
- string.split("\n").map { |line| " " * spaces + line }.join("\n")
89
+ string.split("\n").map { |line| (" " * spaces) + line }.join("\n")
80
90
  end
81
91
 
82
92
  def self.get_protobuf_timestamp(timestamp)
@@ -95,34 +105,32 @@ module Makit
95
105
  minutes = (seconds_value / 60).to_i
96
106
  seconds = (seconds_value % 60).to_i
97
107
  hours = (minutes / 60).to_i
98
- minutes = minutes % 60
108
+ minutes %= 60
99
109
  days = (hours / 24).to_i
100
- hours = hours % 24
110
+ hours %= 24
101
111
  milliseconds = (seconds_value % 1 * 1000).to_i
102
112
 
103
113
  parts = []
104
- parts << "#{days} days" if days > 0
105
- parts << "#{hours} hours" if hours > 0
106
- if (minutes > 0)
107
- if (minutes == 1)
108
- parts << "1 minute"
114
+ parts << "#{days} days" if days.positive?
115
+ parts << "#{hours} hours" if hours.positive?
116
+ if minutes.positive?
117
+ parts << if minutes == 1
118
+ "1 minute"
109
119
  else
110
- parts << "#{minutes} minutes"
120
+ "#{minutes} minutes"
111
121
  end
112
122
  end
113
- if (seconds > 0)
114
- if (seconds == 1)
115
- parts << "1 second"
123
+ if seconds.positive?
124
+ parts << if seconds == 1
125
+ "1 second"
116
126
  else
117
- parts << "#{seconds} seconds"
127
+ "#{seconds} seconds"
118
128
  end
119
129
  end
120
- #parts << "#{seconds} seconds" if seconds > 0
121
- parts << "#{milliseconds} milliseconds" if milliseconds > 0 && seconds < 1
130
+ # parts << "#{seconds} seconds" if seconds > 0
131
+ parts << "#{milliseconds} milliseconds" if milliseconds.positive? && seconds < 1
122
132
 
123
- if (parts.length == 0)
124
- parts << "0 seconds"
125
- end
133
+ parts << "0 seconds" if parts.empty?
126
134
  parts.join(", ")
127
135
  end
128
136
  end
data/lib/makit/indexer.rb CHANGED
@@ -5,28 +5,23 @@ module Makit
5
5
  # This class provide methods for indexing objects.
6
6
  #
7
7
  class Indexer
8
- attr_accessor :keywords_index # Hash of string key to string[] of keyword
9
- attr_accessor :protoc_json_serializer
8
+ attr_accessor :keywords_index, :protoc_json_serializer # Hash of string key to string[] of keyword
10
9
 
11
10
  def initialize
12
- @keywords_index = Hash.new
13
- @protoc_json_serializer = Makit::Serializer::new(Makit::Proto3Formats::JSON)
11
+ @keywords_index = {}
12
+ @protoc_json_serializer = Makit::Serializer.new(Makit::Proto3Formats::JSON)
14
13
  end
15
14
 
16
15
  def index(key, item)
17
16
  # item must be serializable to json
18
17
  keywords = []
19
18
  hash = JSON.parse(item.to_json)
20
- hash.each do |key, value|
19
+ hash.each_value do |value|
21
20
  value = value.to_s.downcase
22
- if (value.length >= 3 && !keywords.include?(value))
23
- keywords << value
24
- end
21
+ keywords << value if value.length >= 3 && !keywords.include?(value)
25
22
  end
26
23
  keywords.each do |keyword|
27
- if !@keywords_index.key?(keyword)
28
- @keywords_index[keyword] = []
29
- end
24
+ @keywords_index[keyword] = [] unless @keywords_index.key?(keyword)
30
25
  @keywords_index[keyword] << key unless @keywords_index[keyword].include?(key)
31
26
  end
32
27
  end
@@ -34,23 +29,19 @@ module Makit
34
29
  def search(query)
35
30
  keys = []
36
31
  # todo, remove terms less that length of 3
37
- terms = query.downcase.split(" ").reject { |term| term.length < 3 }
38
- keywords_index.each do |key, value| #{|kvp|
39
- if (get_match_count(terms, value) == terms.length)
40
- keys << key
41
- end
32
+ terms = query.downcase.split.reject { |term| term.length < 3 }
33
+ keywords_index.each do |key, value| # {|kvp|
34
+ keys << key if get_match_count(terms, value) == terms.length
42
35
  end
43
36
  keys
44
37
  end
45
38
 
46
39
  def get_match_count(terms, keywords)
47
40
  match_count = 0
48
- terms.each { |term|
49
- if (keywords.include?(term))
50
- match_count += 1
51
- end
52
- }
53
- return match_count
41
+ terms.each do |term|
42
+ match_count += 1 if keywords.include?(term)
43
+ end
44
+ match_count
54
45
  end
55
- end # class Indexer
56
- end # module Makit
46
+ end
47
+ end