makit 0.0.35 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/makit/apache.rb +32 -32
  3. data/lib/makit/cli/clean.rb +14 -14
  4. data/lib/makit/cli/clone.rb +59 -59
  5. data/lib/makit/cli/init.rb +38 -38
  6. data/lib/makit/cli/main.rb +33 -33
  7. data/lib/makit/cli/make.rb +54 -54
  8. data/lib/makit/cli/new.rb +37 -37
  9. data/lib/makit/cli/nuget_cache.rb +38 -38
  10. data/lib/makit/cli/pull.rb +31 -31
  11. data/lib/makit/cli/setup.rb +71 -71
  12. data/lib/makit/cli/work.rb +21 -21
  13. data/lib/makit/command_runner.rb +391 -353
  14. data/lib/makit/commands.rb +21 -21
  15. data/lib/makit/content/default_gitignore.rb +5 -5
  16. data/lib/makit/content/default_gitignore.txt +222 -222
  17. data/lib/makit/content/default_rakefile.rb +11 -11
  18. data/lib/makit/content/gem_rakefile.rb +14 -14
  19. data/lib/makit/data.rb +50 -50
  20. data/lib/makit/directories.rb +140 -140
  21. data/lib/makit/directory.rb +184 -184
  22. data/lib/makit/dotnet.rb +156 -156
  23. data/lib/makit/environment.rb +127 -127
  24. data/lib/makit/fileinfo.rb +16 -16
  25. data/lib/makit/files.rb +47 -47
  26. data/lib/makit/git.rb +86 -86
  27. data/lib/makit/gitlab_runner.rb +60 -60
  28. data/lib/makit/humanize.rb +112 -112
  29. data/lib/makit/indexer.rb +56 -0
  30. data/lib/makit/logging.rb +96 -96
  31. data/lib/makit/markdown.rb +75 -75
  32. data/lib/makit/mp/basic_object_mp.rb +16 -16
  33. data/lib/makit/mp/command_request.mp.rb +16 -16
  34. data/lib/makit/mp/project_mp.rb +210 -210
  35. data/lib/makit/mp/string_mp.rb +122 -122
  36. data/lib/makit/nuget.rb +57 -57
  37. data/lib/makit/protoc.rb +104 -104
  38. data/lib/makit/serializer.rb +115 -115
  39. data/lib/makit/show.rb +76 -77
  40. data/lib/makit/storage.rb +131 -131
  41. data/lib/makit/symbols.rb +149 -149
  42. data/lib/makit/tasks.rb +60 -60
  43. data/lib/makit/tree.rb +37 -37
  44. data/lib/makit/v1/makit.v1_pb.rb +33 -33
  45. data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
  46. data/lib/makit/version.rb +12 -12
  47. data/lib/makit/wix.rb +95 -95
  48. data/lib/makit/zip.rb +17 -17
  49. data/lib/makit.rb +267 -267
  50. metadata +4 -5
  51. data/lib/generated/makit/v1/makit.v1_pb.rb +0 -34
  52. data/lib/generated/makit/v1/web/link_pb.rb +0 -20
@@ -1,210 +1,210 @@
1
- # frozen_string_literal: true
2
- require "json"
3
- require "yaml"
4
-
5
- module Makit
6
- module V1
7
- class Project
8
- #def to_yaml
9
- # data = JSON.parse(self.to_pretty_json)
10
- # data.to_yaml.sub(/^---\n/, "")
11
- #end
12
-
13
- def self.create
14
- project = Makit::V1::Project.new
15
- project.set_default_values
16
- project
17
- end
18
-
19
- def open(filename)
20
- other = Makit::Serializer.open(filename, Makit::V1::Project)
21
- #other = Makit::V1::Project::create_from_file(filename)
22
- self.name = other.name
23
- self.git_remote_url = other.git_remote_url
24
- self.dotnet_projects = other.dotnet_projects
25
- self.artifacts = other.artifacts
26
- end
27
-
28
- #def self.create_from_file(filename)
29
- # extension = File.extname(filename)
30
- # case extension
31
- # when ".yml"
32
- # yaml = File.read(filename)
33
- # create_from_yaml(yaml)
34
- # when ".json"
35
- # json = File.read(filename)
36
- # create_from_json(json)
37
- # else
38
- # raise "unsupported file extension: #{extension}"
39
- # end
40
- #end
41
-
42
- #def self.create_from_yaml(yaml)
43
- # json = JSON.pretty_generate(YAML.load(yaml))
44
- # project = Makit::V1::Project.decode_json(json)
45
- # project
46
- #end
47
-
48
- #def self.create_from_json(json)
49
- # project = Makit::V1::Project.decode_json(json)
50
- # project
51
- #end
52
-
53
- def set_default_values
54
- #self.language = "csharp"
55
- #self.primary_artifact_type = "nuget"
56
- if self.git_remote_url.nil? || self.git_remote_url.empty?
57
- self.git_remote_url = `git remote get-url origin`.strip
58
- end
59
- if self.name.nil? || self.name.empty?
60
- if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
61
- self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
62
- else
63
- self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
64
- end
65
- end
66
- self
67
- end
68
-
69
- def get_name(name)
70
- if !self.git_remote_url.nil? && !self.git_remote_url.empty?
71
- is_dotnet = self.git_remote_url.include?("nuget")
72
- if is_dotnet
73
- get_capitalized_name(name)
74
- end
75
- end
76
- name.downcase
77
- end
78
-
79
- def get_capitalized_name(name)
80
- name.split(".").map(&:capitalize).join(".")
81
- end
82
-
83
- def save_as(filename)
84
- Makit::Serializer.save_as(filename, self)
85
- #extension = File.extname(filename)
86
- #case extension
87
- #when ".json"
88
- # File.write(filename, self.to_pretty_json)
89
- #when ".yml"
90
- # File.write(filename, self.to_yaml)
91
- #else
92
- # raise "unsupported file extension: #{extension}"
93
- #end
94
- end
95
-
96
- def with_dotnet_project(template, name, output)
97
- if !self.dotnet_projects.any? { |project| project.output == output }
98
- project = Makit::V1::DotNetProject.new
99
- project.template = template
100
- project.name = name
101
- project.output = output
102
- self.dotnet_projects << project
103
- end
104
- end
105
-
106
- def setup
107
- setup_dotnet_projects
108
- end
109
-
110
- def make
111
- setup_dotnet_projects
112
- make_dotnet_projects
113
-
114
- # verify the artifacts exist
115
- self.artifacts.each do |artifact|
116
- raise "artifact does not exist: #{artifact}" if !File.exist?(artifact)
117
- end
118
- end
119
-
120
- def build
121
- build_dotnet_projects
122
- end
123
-
124
- def test
125
- test_dotnet_projects
126
- end
127
-
128
- def setup_dotnet_projects
129
- if self.dotnet_projects.any?
130
- if (!File.exist?("#{self.name}.sln"))
131
- puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
132
- "dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
133
- else
134
- #puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
135
- end
136
- self.dotnet_projects.each do |project|
137
- add_project = true
138
- if (project.os == "windows" && !Makit::Environment.is_windows?)
139
- add_project = false
140
- end
141
- if (add_project)
142
- Makit::DotNet.new_project(project.template, project.name, project.output)
143
- # add any nuget packages to the project
144
- project_filename = "#{project.output}/#{project.name}.csproj"
145
- project.packages.each { |package|
146
- Makit::DotNet::add_package(project_filename, package)
147
- }
148
- end
149
- end
150
- #Makit::DotNet.new_solution(self.name)
151
- Makit::DotNet.sln_add_projects(self.name)
152
- else
153
- #puts " no dotnet projects found".colorize(:yellow)
154
- end
155
- end
156
-
157
- def make_dotnet_projects
158
- self.dotnet_projects.each do |project|
159
- if (project.os == "windows" && !Makit::Environment.is_windows?)
160
- next
161
- else
162
- project.commands.each do |command|
163
- newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
164
- #newest_file = Makit::Directory::get_newest_file_or_now(project.output)
165
- command_request = Makit::RUNNER::parse_command_request(command)
166
- RUNNER.cache_run(command_request, newest_file_timestamp)
167
- end
168
- end
169
- end
170
- end
171
-
172
- def build_dotnet_projects
173
- self.dotnet_projects.each do |project|
174
- if (project.os == "windows" && !Makit::Environment.is_windows?)
175
- next
176
- else
177
- project.commands.each do |command|
178
- newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
179
- #newest_file = Makit::Directory::get_newest_file_or_now(project.output)
180
- command_request = Makit::RUNNER::parse_command_request(command)
181
- RUNNER.cache_run(command_request, newest_file_timestamp)
182
- end
183
- project.build_args.each do |build_arg|
184
- project_path = File.join(project.output, "#{project.name}.csproj")
185
- Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output)
186
- end
187
- project.publish_args.each do |publish_arg|
188
- project_path = File.join(project.output, "#{project.name}.csproj")
189
- Makit::DotNet.publish(project_path, publish_arg.configuration, publish_arg.output)
190
- end
191
- end
192
- end
193
- end
194
-
195
- def test_dotnet_projects
196
- self.dotnet_projects.each do |project|
197
- if (project.os == "windows" && !Makit::Environment.is_windows?)
198
- next
199
- else
200
- project.test_args.each do |test_args|
201
- project_path = File.join(project.output, "#{project.name}.csproj")
202
- Makit::DotNet.test(project_path, test_args.configuration, test_args.output)
203
- end
204
- #"dotnet test #{project.output} --configuration Release".run
205
- end
206
- end
207
- end
208
- end # class Project
209
- end # module V1
210
- end # module Makit
1
+ # frozen_string_literal: true
2
+ require "json"
3
+ require "yaml"
4
+
5
+ module Makit
6
+ module V1
7
+ class Project
8
+ #def to_yaml
9
+ # data = JSON.parse(self.to_pretty_json)
10
+ # data.to_yaml.sub(/^---\n/, "")
11
+ #end
12
+
13
+ def self.create
14
+ project = Makit::V1::Project.new
15
+ project.set_default_values
16
+ project
17
+ end
18
+
19
+ def open(filename)
20
+ other = Makit::Serializer.open(filename, Makit::V1::Project)
21
+ #other = Makit::V1::Project::create_from_file(filename)
22
+ self.name = other.name
23
+ self.git_remote_url = other.git_remote_url
24
+ self.dotnet_projects = other.dotnet_projects
25
+ self.artifacts = other.artifacts
26
+ end
27
+
28
+ #def self.create_from_file(filename)
29
+ # extension = File.extname(filename)
30
+ # case extension
31
+ # when ".yml"
32
+ # yaml = File.read(filename)
33
+ # create_from_yaml(yaml)
34
+ # when ".json"
35
+ # json = File.read(filename)
36
+ # create_from_json(json)
37
+ # else
38
+ # raise "unsupported file extension: #{extension}"
39
+ # end
40
+ #end
41
+
42
+ #def self.create_from_yaml(yaml)
43
+ # json = JSON.pretty_generate(YAML.load(yaml))
44
+ # project = Makit::V1::Project.decode_json(json)
45
+ # project
46
+ #end
47
+
48
+ #def self.create_from_json(json)
49
+ # project = Makit::V1::Project.decode_json(json)
50
+ # project
51
+ #end
52
+
53
+ def set_default_values
54
+ #self.language = "csharp"
55
+ #self.primary_artifact_type = "nuget"
56
+ if self.git_remote_url.nil? || self.git_remote_url.empty?
57
+ self.git_remote_url = `git remote get-url origin`.strip
58
+ end
59
+ if self.name.nil? || self.name.empty?
60
+ if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
61
+ self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
62
+ else
63
+ self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
64
+ end
65
+ end
66
+ self
67
+ end
68
+
69
+ def get_name(name)
70
+ if !self.git_remote_url.nil? && !self.git_remote_url.empty?
71
+ is_dotnet = self.git_remote_url.include?("nuget")
72
+ if is_dotnet
73
+ get_capitalized_name(name)
74
+ end
75
+ end
76
+ name.downcase
77
+ end
78
+
79
+ def get_capitalized_name(name)
80
+ name.split(".").map(&:capitalize).join(".")
81
+ end
82
+
83
+ def save_as(filename)
84
+ Makit::Serializer.save_as(filename, self)
85
+ #extension = File.extname(filename)
86
+ #case extension
87
+ #when ".json"
88
+ # File.write(filename, self.to_pretty_json)
89
+ #when ".yml"
90
+ # File.write(filename, self.to_yaml)
91
+ #else
92
+ # raise "unsupported file extension: #{extension}"
93
+ #end
94
+ end
95
+
96
+ def with_dotnet_project(template, name, output)
97
+ if !self.dotnet_projects.any? { |project| project.output == output }
98
+ project = Makit::V1::DotNetProject.new
99
+ project.template = template
100
+ project.name = name
101
+ project.output = output
102
+ self.dotnet_projects << project
103
+ end
104
+ end
105
+
106
+ def setup
107
+ setup_dotnet_projects
108
+ end
109
+
110
+ def make
111
+ setup_dotnet_projects
112
+ make_dotnet_projects
113
+
114
+ # verify the artifacts exist
115
+ self.artifacts.each do |artifact|
116
+ raise "artifact does not exist: #{artifact}" if !File.exist?(artifact)
117
+ end
118
+ end
119
+
120
+ def build
121
+ build_dotnet_projects
122
+ end
123
+
124
+ def test
125
+ test_dotnet_projects
126
+ end
127
+
128
+ def setup_dotnet_projects
129
+ if self.dotnet_projects.any?
130
+ if (!File.exist?("#{self.name}.sln"))
131
+ puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
132
+ "dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
133
+ else
134
+ #puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
135
+ end
136
+ self.dotnet_projects.each do |project|
137
+ add_project = true
138
+ if (project.os == "windows" && !Makit::Environment.is_windows?)
139
+ add_project = false
140
+ end
141
+ if (add_project)
142
+ Makit::DotNet.new_project(project.template, project.name, project.output)
143
+ # add any nuget packages to the project
144
+ project_filename = "#{project.output}/#{project.name}.csproj"
145
+ project.packages.each { |package|
146
+ Makit::DotNet::add_package(project_filename, package)
147
+ }
148
+ end
149
+ end
150
+ #Makit::DotNet.new_solution(self.name)
151
+ Makit::DotNet.sln_add_projects(self.name)
152
+ else
153
+ #puts " no dotnet projects found".colorize(:yellow)
154
+ end
155
+ end
156
+
157
+ def make_dotnet_projects
158
+ self.dotnet_projects.each do |project|
159
+ if (project.os == "windows" && !Makit::Environment.is_windows?)
160
+ next
161
+ else
162
+ project.commands.each do |command|
163
+ newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
164
+ #newest_file = Makit::Directory::get_newest_file_or_now(project.output)
165
+ command_request = Makit::RUNNER::parse_command_request(command)
166
+ RUNNER.cache_run(command_request, newest_file_timestamp)
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ def build_dotnet_projects
173
+ self.dotnet_projects.each do |project|
174
+ if (project.os == "windows" && !Makit::Environment.is_windows?)
175
+ next
176
+ else
177
+ project.commands.each do |command|
178
+ newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
179
+ #newest_file = Makit::Directory::get_newest_file_or_now(project.output)
180
+ command_request = Makit::RUNNER::parse_command_request(command)
181
+ RUNNER.cache_run(command_request, newest_file_timestamp)
182
+ end
183
+ project.build_args.each do |build_arg|
184
+ project_path = File.join(project.output, "#{project.name}.csproj")
185
+ Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output)
186
+ end
187
+ project.publish_args.each do |publish_arg|
188
+ project_path = File.join(project.output, "#{project.name}.csproj")
189
+ Makit::DotNet.publish(project_path, publish_arg.configuration, publish_arg.output)
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ def test_dotnet_projects
196
+ self.dotnet_projects.each do |project|
197
+ if (project.os == "windows" && !Makit::Environment.is_windows?)
198
+ next
199
+ else
200
+ project.test_args.each do |test_args|
201
+ project_path = File.join(project.output, "#{project.name}.csproj")
202
+ Makit::DotNet.test(project_path, test_args.configuration, test_args.output)
203
+ end
204
+ #"dotnet test #{project.output} --configuration Release".run
205
+ end
206
+ end
207
+ end
208
+ end # class Project
209
+ end # module V1
210
+ end # module Makit
@@ -1,122 +1,122 @@
1
- # frozen_string_literal: true
2
- require "json"
3
- # monkey patch String class with a run method
4
-
5
- class String
6
- def run(args = nil)
7
- if args.nil?
8
- command = self
9
- Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
10
- else
11
- command = self
12
- request = Makit::RUNNER.parse_args(command)
13
- if args.is_a?(Hash)
14
- args.each do |key, value|
15
- request.send("#{key}=", value)
16
- end
17
- end
18
- Makit::RUNNER.run(request)
19
- end
20
- end
21
-
22
- def try(args = nil)
23
- if args.nil?
24
- command = self
25
- Makit::RUNNER.try(command)
26
- else
27
- command = self
28
- request = Makit::RUNNER.parse_args(command)
29
- if args.is_a?(Hash)
30
- args.each do |key, value|
31
- request.send("#{key}=", value)
32
- end
33
- end
34
- Makit::RUNNER.try(request)
35
- end
36
- end
37
-
38
- def cache_run()
39
- command = self
40
- Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command))
41
- end
42
-
43
- def cache_run(timestamp = nil)
44
- if timestamp.nil?
45
- timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
46
- #timestamp = Makit::Timestamp.now
47
- end
48
-
49
- command = self
50
- Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
51
- end
52
-
53
- # Read a value from a JSON file
54
- # key is a string with the key to read, e.g. "AzureAd.Authority"
55
- def get_json_value(key)
56
- json = File.read(self)
57
- data = JSON.parse(json)
58
-
59
- # key delimiter is '.' so we can access nested keys
60
- key.split(".").each do |k|
61
- data = data[k]
62
- end
63
- data
64
- end
65
-
66
- alias_method :retrieve, :get_json_value
67
-
68
- # Set a value in a JSON file
69
- # key is a string with the key to set, e.g. "AzureAd.Authority"
70
- def set_json_value(key, value)
71
- file = File.read(self)
72
- data = JSON.parse(file)
73
- keys = key.split(".")
74
- current = data
75
-
76
- # Traverse and create any missing keys
77
- keys[0..-2].each do |k|
78
- current[k] ||= {} # Create a new hash if the key doesn't exist
79
- current = current[k]
80
- end
81
-
82
- # Set the value for the final key
83
- current[keys[-1]] = value
84
-
85
- # Write the JSON back to the file
86
- File.write(self, JSON.pretty_generate(data))
87
- end
88
-
89
- # Alias for set_json_value
90
- alias_method :assign, :set_json_value
91
-
92
- def strip_color_codes
93
- # Regular expression to remove ANSI color codes
94
- cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
95
- cleaned_content
96
- end
97
-
98
- def to_lines(max_length = 80, indent_length = 5)
99
- if (self.length <= max_length)
100
- return self
101
- else
102
- indent = " " * indent_length
103
- words = self.split(" ")
104
- lines = []
105
- line = ""
106
- words.each do |word|
107
- if ((line + word).length > max_length)
108
- lines << line
109
- line = indent + word
110
- else
111
- if (line.length == 0)
112
- line = word
113
- else
114
- line += " " + word
115
- end
116
- end
117
- end
118
- lines << line
119
- return lines.join("\n")
120
- end
121
- end
122
- end
1
+ # frozen_string_literal: true
2
+ require "json"
3
+ # monkey patch String class with a run method
4
+
5
+ class String
6
+ def run(args = nil)
7
+ if args.nil?
8
+ command = self
9
+ Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
10
+ else
11
+ command = self
12
+ request = Makit::RUNNER.parse_args(command)
13
+ if args.is_a?(Hash)
14
+ args.each do |key, value|
15
+ request.send("#{key}=", value)
16
+ end
17
+ end
18
+ Makit::RUNNER.run(request)
19
+ end
20
+ end
21
+
22
+ def try(args = nil)
23
+ if args.nil?
24
+ command = self
25
+ Makit::RUNNER.try(command)
26
+ else
27
+ command = self
28
+ request = Makit::RUNNER.parse_args(command)
29
+ if args.is_a?(Hash)
30
+ args.each do |key, value|
31
+ request.send("#{key}=", value)
32
+ end
33
+ end
34
+ Makit::RUNNER.try(request)
35
+ end
36
+ end
37
+
38
+ def cache_run()
39
+ command = self
40
+ Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command))
41
+ end
42
+
43
+ def cache_run(timestamp = nil)
44
+ if timestamp.nil?
45
+ timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
46
+ #timestamp = Makit::Timestamp.now
47
+ end
48
+
49
+ command = self
50
+ Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
51
+ end
52
+
53
+ # Read a value from a JSON file
54
+ # key is a string with the key to read, e.g. "AzureAd.Authority"
55
+ def get_json_value(key)
56
+ json = File.read(self)
57
+ data = JSON.parse(json)
58
+
59
+ # key delimiter is '.' so we can access nested keys
60
+ key.split(".").each do |k|
61
+ data = data[k]
62
+ end
63
+ data
64
+ end
65
+
66
+ alias_method :retrieve, :get_json_value
67
+
68
+ # Set a value in a JSON file
69
+ # key is a string with the key to set, e.g. "AzureAd.Authority"
70
+ def set_json_value(key, value)
71
+ file = File.read(self)
72
+ data = JSON.parse(file)
73
+ keys = key.split(".")
74
+ current = data
75
+
76
+ # Traverse and create any missing keys
77
+ keys[0..-2].each do |k|
78
+ current[k] ||= {} # Create a new hash if the key doesn't exist
79
+ current = current[k]
80
+ end
81
+
82
+ # Set the value for the final key
83
+ current[keys[-1]] = value
84
+
85
+ # Write the JSON back to the file
86
+ File.write(self, JSON.pretty_generate(data))
87
+ end
88
+
89
+ # Alias for set_json_value
90
+ alias_method :assign, :set_json_value
91
+
92
+ def strip_color_codes
93
+ # Regular expression to remove ANSI color codes
94
+ cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
95
+ cleaned_content
96
+ end
97
+
98
+ def to_lines(max_length = 80, indent_length = 5)
99
+ if (self.length <= max_length)
100
+ return self
101
+ else
102
+ indent = " " * indent_length
103
+ words = self.split(" ")
104
+ lines = []
105
+ line = ""
106
+ words.each do |word|
107
+ if ((line + word).length > max_length)
108
+ lines << line
109
+ line = indent + word
110
+ else
111
+ if (line.length == 0)
112
+ line = word
113
+ else
114
+ line += " " + word
115
+ end
116
+ end
117
+ end
118
+ lines << line
119
+ return lines.join("\n")
120
+ end
121
+ end
122
+ end