flat_kit 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -2
  3. data/HISTORY.md +15 -0
  4. data/Manifest.txt +21 -26
  5. data/{bin → exe}/fk +2 -1
  6. data/flat_kit.gemspec +33 -0
  7. data/lib/flat_kit/cli.rb +48 -23
  8. data/lib/flat_kit/command/cat.rb +34 -32
  9. data/lib/flat_kit/command/merge.rb +37 -36
  10. data/lib/flat_kit/command/sort.rb +37 -37
  11. data/lib/flat_kit/command/stats.rb +96 -0
  12. data/lib/flat_kit/command.rb +10 -10
  13. data/lib/flat_kit/descendant_tracker.rb +17 -5
  14. data/lib/flat_kit/error.rb +4 -0
  15. data/lib/flat_kit/event_emitter.rb +7 -4
  16. data/lib/flat_kit/field_stats.rb +246 -0
  17. data/lib/flat_kit/field_type/boolean_type.rb +52 -0
  18. data/lib/flat_kit/field_type/date_type.rb +181 -0
  19. data/lib/flat_kit/field_type/float_type.rb +43 -0
  20. data/lib/flat_kit/field_type/guess_type.rb +23 -0
  21. data/lib/flat_kit/field_type/integer_type.rb +36 -0
  22. data/lib/flat_kit/field_type/null_type.rb +39 -0
  23. data/lib/flat_kit/field_type/string_type.rb +24 -0
  24. data/lib/flat_kit/field_type/timestamp_type.rb +48 -0
  25. data/lib/flat_kit/field_type/unknown_type.rb +30 -0
  26. data/lib/flat_kit/field_type.rb +83 -0
  27. data/lib/flat_kit/format.rb +11 -5
  28. data/lib/flat_kit/input/file.rb +11 -9
  29. data/lib/flat_kit/input/io.rb +18 -21
  30. data/lib/flat_kit/input.rb +8 -7
  31. data/lib/flat_kit/internal_node.rb +22 -19
  32. data/lib/flat_kit/jsonl/format.rb +6 -2
  33. data/lib/flat_kit/jsonl/reader.rb +7 -4
  34. data/lib/flat_kit/jsonl/record.rb +16 -19
  35. data/lib/flat_kit/jsonl/writer.rb +25 -18
  36. data/lib/flat_kit/jsonl.rb +8 -4
  37. data/lib/flat_kit/leaf_node.rb +6 -5
  38. data/lib/flat_kit/log_formatter.rb +20 -0
  39. data/lib/flat_kit/logger.rb +12 -19
  40. data/lib/flat_kit/merge.rb +21 -16
  41. data/lib/flat_kit/merge_tree.rb +5 -6
  42. data/lib/flat_kit/output/file.rb +13 -9
  43. data/lib/flat_kit/output/io.rb +40 -35
  44. data/lib/flat_kit/output.rb +12 -7
  45. data/lib/flat_kit/position.rb +18 -0
  46. data/lib/flat_kit/reader.rb +8 -8
  47. data/lib/flat_kit/record.rb +12 -12
  48. data/lib/flat_kit/sentinel_internal_node.rb +6 -5
  49. data/lib/flat_kit/sentinel_leaf_node.rb +4 -1
  50. data/lib/flat_kit/sort.rb +8 -9
  51. data/lib/flat_kit/stat_type/nominal_stats.rb +64 -0
  52. data/lib/flat_kit/stat_type/numerical_stats.rb +120 -0
  53. data/lib/flat_kit/stat_type/ordinal_stats.rb +37 -0
  54. data/lib/flat_kit/stat_type.rb +70 -0
  55. data/lib/flat_kit/stats.rb +64 -0
  56. data/lib/flat_kit/writer.rb +17 -3
  57. data/lib/flat_kit/xsv/format.rb +6 -2
  58. data/lib/flat_kit/xsv/reader.rb +8 -6
  59. data/lib/flat_kit/xsv/record.rb +21 -15
  60. data/lib/flat_kit/xsv/writer.rb +36 -18
  61. data/lib/flat_kit/xsv.rb +7 -4
  62. data/lib/flat_kit.rb +33 -21
  63. metadata +38 -113
  64. data/Rakefile +0 -20
  65. data/tasks/default.rake +0 -242
  66. data/tasks/extension.rake +0 -38
  67. data/tasks/man.rake +0 -7
  68. data/tasks/this.rb +0 -208
  69. data/test/device_dataset.rb +0 -117
  70. data/test/input/test_file.rb +0 -73
  71. data/test/input/test_io.rb +0 -93
  72. data/test/jsonl/test_format.rb +0 -22
  73. data/test/jsonl/test_reader.rb +0 -49
  74. data/test/jsonl/test_record.rb +0 -61
  75. data/test/jsonl/test_writer.rb +0 -68
  76. data/test/output/test_file.rb +0 -60
  77. data/test/output/test_io.rb +0 -104
  78. data/test/test_conversions.rb +0 -45
  79. data/test/test_event_emitter.rb +0 -72
  80. data/test/test_format.rb +0 -24
  81. data/test/test_helper.rb +0 -26
  82. data/test/test_merge.rb +0 -40
  83. data/test/test_merge_tree.rb +0 -64
  84. data/test/test_version.rb +0 -11
  85. data/test/xsv/test_format.rb +0 -22
  86. data/test/xsv/test_reader.rb +0 -61
  87. data/test/xsv/test_record.rb +0 -69
  88. data/test/xsv/test_writer.rb +0 -68
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FlatKit
2
4
  module Xsv
5
+ # Internal: Write that takes flatkit records and writes them to XSV Output
6
+ #
3
7
  class Writer < ::FlatKit::Writer
4
- attr_reader :output
5
- attr_reader :count
6
- attr_reader :fields
8
+ attr_reader :fields, :header_bytes
7
9
 
8
10
  def self.format_name
9
11
  ::FlatKit::Xsv::Format.format_name
@@ -12,29 +14,33 @@ module FlatKit
12
14
  def self.default_csv_options
13
15
  {
14
16
  headers: nil,
15
- write_headers: true
17
+ write_headers: true,
16
18
  }
17
19
  end
18
20
 
19
21
  def initialize(destination:, fields: :auto, **csv_options)
20
22
  super(destination: destination)
21
23
  @fields = fields
22
- @output = ::FlatKit::Output.from(@destination)
23
- @count = 0
24
24
  @we_write_the_header = nil
25
25
  @csv_options = Writer.default_csv_options.dup
26
26
 
27
- if @fields == :auto then
27
+ if @fields == :auto
28
28
  @we_write_the_header = true
29
29
  else
30
- @csv_options.merge!(headers: fields)
30
+ @csv_options[:headers] = fields
31
31
  @we_write_the_header = false
32
32
  end
33
33
 
34
+ @header_bytes = 0
34
35
  @csv_options.merge!(csv_options)
35
36
  @csv = CSV.new(output.io, **@csv_options)
36
37
  end
37
38
 
39
+ # write the record and return the Position the record was written
40
+ #
41
+ # In the case of the header being written automatcially, the Postion returned is the
42
+ # position of the reocrd, not the header
43
+ #
38
44
  def write(record)
39
45
  case record
40
46
  when FlatKit::Xsv::Record
@@ -45,25 +51,37 @@ module FlatKit
45
51
  else
46
52
  raise FlatKit::Error, "Unable to write records of type #{record.class}"
47
53
  end
48
- rescue FlatKit::Error => fe
49
- raise fe
50
- rescue => e
51
- ::FlatKit.logger.error "Error reading jsonl records from #{output.name}: #{e}"
54
+ rescue FlatKit::Error => e
55
+ raise e
56
+ rescue StandardError => e
57
+ ::FlatKit.logger.error "Error writing xsv records to #{output.name}: #{e}"
52
58
  raise ::FlatKit::Error, e
53
59
  end
54
60
 
55
- def close
56
- @output.close
57
- end
58
-
59
61
  private
60
62
 
61
63
  def write_record(record)
62
- if @we_write_the_header && @count == 0 then
64
+ if @we_write_the_header && @count.zero?
63
65
  @csv << record.ordered_fields
66
+ @header_bytes = output.tell
64
67
  end
65
- @count += 1
68
+
69
+ # the index of the record being written is the same as the count of records written so far
70
+ record_index = @count
71
+
72
+ # get the current output stream position to calculate bytes written
73
+ start_offset = output.tell
74
+
66
75
  @csv << record.to_a
76
+
77
+ ending_offset = output.io.tell
78
+ bytes_written = (ending_offset - start_offset)
79
+
80
+ @count += 1
81
+
82
+ @last_position = ::FlatKit::Position.new(index: record_index,
83
+ offset: start_offset,
84
+ bytesize: bytes_written)
67
85
  end
68
86
  end
69
87
  end
data/lib/flat_kit/xsv.rb CHANGED
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FlatKit
4
+ # Internal: Namespace for the xsv file fromat handling
2
5
  module Xsv
3
6
  end
4
7
  end
5
- require 'flat_kit/xsv/record'
6
- require 'flat_kit/xsv/reader'
7
- require 'flat_kit/xsv/writer'
8
- require 'flat_kit/xsv/format'
8
+ require "flat_kit/xsv/record"
9
+ require "flat_kit/xsv/reader"
10
+ require "flat_kit/xsv/writer"
11
+ require "flat_kit/xsv/format"
data/lib/flat_kit.rb CHANGED
@@ -1,24 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Public: Top level namespace for this gem
4
+ #
1
5
  module FlatKit
2
- VERSION = "0.2.0"
6
+ VERSION = "1.0.0"
3
7
  end
4
- require 'flat_kit/error'
5
- require 'flat_kit/logger'
6
- require 'flat_kit/event_emitter'
7
- require 'flat_kit/descendant_tracker'
8
- require 'flat_kit/format'
9
- require 'flat_kit/record'
10
- require 'flat_kit/reader'
11
- require 'flat_kit/writer'
12
- require 'flat_kit/input'
13
- require 'flat_kit/output'
14
- require 'flat_kit/cli'
15
- require 'flat_kit/xsv'
16
- require 'flat_kit/jsonl'
17
- require 'flat_kit/merge'
18
- require 'flat_kit/sort'
8
+ require "flat_kit/error"
9
+ require "flat_kit/descendant_tracker"
10
+ require "flat_kit/log_formatter"
11
+ require "flat_kit/logger"
12
+ require "flat_kit/event_emitter"
13
+
14
+ require "flat_kit/field_type"
15
+ require "flat_kit/format"
16
+ require "flat_kit/position"
17
+ require "flat_kit/record"
18
+ require "flat_kit/reader"
19
+ require "flat_kit/writer"
20
+ require "flat_kit/input"
21
+ require "flat_kit/output"
22
+ require "flat_kit/cli"
23
+ require "flat_kit/xsv"
24
+ require "flat_kit/jsonl"
25
+ require "flat_kit/merge"
26
+ require "flat_kit/sort"
27
+ require "flat_kit/stats"
28
+
29
+ require "flat_kit/stat_type"
30
+ require "flat_kit/field_stats"
19
31
 
20
- require 'flat_kit/merge_tree'
21
- require 'flat_kit/internal_node'
22
- require 'flat_kit/sentinel_internal_node'
23
- require 'flat_kit/sentinel_leaf_node'
24
- require 'flat_kit/leaf_node'
32
+ require "flat_kit/merge_tree"
33
+ require "flat_kit/internal_node"
34
+ require "flat_kit/sentinel_internal_node"
35
+ require "flat_kit/sentinel_leaf_node"
36
+ require "flat_kit/leaf_node"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flat_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2024-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -39,75 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: csv
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.11'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.11'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest-focus
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.2'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.2'
83
- - !ruby/object:Gem::Dependency
84
- name: rdoc
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '6.3'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '6.3'
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.21'
104
- type: :development
47
+ version: '3.3'
48
+ type: :runtime
105
49
  prerelease: false
106
50
  version_requirements: !ruby/object:Gem::Requirement
107
51
  requirements:
108
52
  - - "~>"
109
53
  - !ruby/object:Gem::Version
110
- version: '0.21'
54
+ version: '3.3'
111
55
  description: A library and commandline program for reading, writing, indexing, sorting,
112
56
  and merging CSV, TSV, JSON and other flat-file formats.
113
57
  email: jeremy@copiousfreetime.org
@@ -126,17 +70,29 @@ files:
126
70
  - LICENSE.txt
127
71
  - Manifest.txt
128
72
  - README.md
129
- - Rakefile
130
- - bin/fk
73
+ - exe/fk
74
+ - flat_kit.gemspec
131
75
  - lib/flat_kit.rb
132
76
  - lib/flat_kit/cli.rb
133
77
  - lib/flat_kit/command.rb
134
78
  - lib/flat_kit/command/cat.rb
135
79
  - lib/flat_kit/command/merge.rb
136
80
  - lib/flat_kit/command/sort.rb
81
+ - lib/flat_kit/command/stats.rb
137
82
  - lib/flat_kit/descendant_tracker.rb
138
83
  - lib/flat_kit/error.rb
139
84
  - lib/flat_kit/event_emitter.rb
85
+ - lib/flat_kit/field_stats.rb
86
+ - lib/flat_kit/field_type.rb
87
+ - lib/flat_kit/field_type/boolean_type.rb
88
+ - lib/flat_kit/field_type/date_type.rb
89
+ - lib/flat_kit/field_type/float_type.rb
90
+ - lib/flat_kit/field_type/guess_type.rb
91
+ - lib/flat_kit/field_type/integer_type.rb
92
+ - lib/flat_kit/field_type/null_type.rb
93
+ - lib/flat_kit/field_type/string_type.rb
94
+ - lib/flat_kit/field_type/timestamp_type.rb
95
+ - lib/flat_kit/field_type/unknown_type.rb
140
96
  - lib/flat_kit/format.rb
141
97
  - lib/flat_kit/input.rb
142
98
  - lib/flat_kit/input/file.rb
@@ -148,51 +104,40 @@ files:
148
104
  - lib/flat_kit/jsonl/record.rb
149
105
  - lib/flat_kit/jsonl/writer.rb
150
106
  - lib/flat_kit/leaf_node.rb
107
+ - lib/flat_kit/log_formatter.rb
151
108
  - lib/flat_kit/logger.rb
152
109
  - lib/flat_kit/merge.rb
153
110
  - lib/flat_kit/merge_tree.rb
154
111
  - lib/flat_kit/output.rb
155
112
  - lib/flat_kit/output/file.rb
156
113
  - lib/flat_kit/output/io.rb
114
+ - lib/flat_kit/position.rb
157
115
  - lib/flat_kit/reader.rb
158
116
  - lib/flat_kit/record.rb
159
117
  - lib/flat_kit/sentinel_internal_node.rb
160
118
  - lib/flat_kit/sentinel_leaf_node.rb
161
119
  - lib/flat_kit/sort.rb
120
+ - lib/flat_kit/stat_type.rb
121
+ - lib/flat_kit/stat_type/nominal_stats.rb
122
+ - lib/flat_kit/stat_type/numerical_stats.rb
123
+ - lib/flat_kit/stat_type/ordinal_stats.rb
124
+ - lib/flat_kit/stats.rb
162
125
  - lib/flat_kit/writer.rb
163
126
  - lib/flat_kit/xsv.rb
164
127
  - lib/flat_kit/xsv/format.rb
165
128
  - lib/flat_kit/xsv/reader.rb
166
129
  - lib/flat_kit/xsv/record.rb
167
130
  - lib/flat_kit/xsv/writer.rb
168
- - tasks/default.rake
169
- - tasks/extension.rake
170
- - tasks/man.rake
171
- - tasks/this.rb
172
- - test/device_dataset.rb
173
- - test/input/test_file.rb
174
- - test/input/test_io.rb
175
- - test/jsonl/test_format.rb
176
- - test/jsonl/test_reader.rb
177
- - test/jsonl/test_record.rb
178
- - test/jsonl/test_writer.rb
179
- - test/output/test_file.rb
180
- - test/output/test_io.rb
181
- - test/test_conversions.rb
182
- - test/test_event_emitter.rb
183
- - test/test_format.rb
184
- - test/test_helper.rb
185
- - test/test_merge.rb
186
- - test/test_merge_tree.rb
187
- - test/test_version.rb
188
- - test/xsv/test_format.rb
189
- - test/xsv/test_reader.rb
190
- - test/xsv/test_record.rb
191
- - test/xsv/test_writer.rb
192
131
  homepage: http://github.com/copiousfreetime/flat_kit
193
132
  licenses:
194
133
  - MIT
195
- metadata: {}
134
+ metadata:
135
+ bug_tracker_uri: https://github.com/copiousfreetime/flat_kit/issues
136
+ changelog_uri: https://github.com/copiousfreetime/flat_kit/blob/master/HISTORY.md
137
+ homepage_uri: https://github.com/copiousfreetime/flat_kit
138
+ source_code_uri: https://github.com/copiousfreetime/flat_kit
139
+ label: flat_kit
140
+ rubygems_mfa_required: 'true'
196
141
  post_install_message:
197
142
  rdoc_options:
198
143
  - "--main"
@@ -205,36 +150,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
150
  requirements:
206
151
  - - ">="
207
152
  - !ruby/object:Gem::Version
208
- version: 2.2.2
153
+ version: 3.0.0
209
154
  required_rubygems_version: !ruby/object:Gem::Requirement
210
155
  requirements:
211
156
  - - ">="
212
157
  - !ruby/object:Gem::Version
213
158
  version: '0'
214
159
  requirements: []
215
- rubygems_version: 3.1.2
160
+ rubygems_version: 3.5.9
216
161
  signing_key:
217
162
  specification_version: 4
218
163
  summary: A library and commandline program for reading, writing, indexing, sorting,
219
164
  and merging CSV, TSV, JSON and other flat-file formats.
220
- test_files:
221
- - test/device_dataset.rb
222
- - test/input/test_file.rb
223
- - test/input/test_io.rb
224
- - test/jsonl/test_format.rb
225
- - test/jsonl/test_reader.rb
226
- - test/jsonl/test_record.rb
227
- - test/jsonl/test_writer.rb
228
- - test/output/test_file.rb
229
- - test/output/test_io.rb
230
- - test/test_conversions.rb
231
- - test/test_event_emitter.rb
232
- - test/test_format.rb
233
- - test/test_helper.rb
234
- - test/test_merge.rb
235
- - test/test_merge_tree.rb
236
- - test/test_version.rb
237
- - test/xsv/test_format.rb
238
- - test/xsv/test_reader.rb
239
- - test/xsv/test_record.rb
240
- - test/xsv/test_writer.rb
165
+ test_files: []
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- # vim: syntax=ruby
2
- load 'tasks/this.rb'
3
-
4
- This.name = "flat_kit"
5
- This.author = "Jeremy Hinegardner"
6
- This.email = "jeremy@copiousfreetime.org"
7
- This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
8
-
9
- This.ruby_gemspec do |spec|
10
- spec.add_dependency('oj', '~> 3.0')
11
- spec.add_dependency('optimist', '~> 3.0')
12
-
13
- spec.add_development_dependency( 'rake' , '~> 13.0')
14
- spec.add_development_dependency( 'minitest' , '~> 5.11' )
15
- spec.add_development_dependency( 'minitest-focus' , '~> 1.2' )
16
- spec.add_development_dependency( 'rdoc' , '~> 6.3' )
17
- spec.add_development_dependency( 'simplecov', '~> 0.21')
18
- end
19
-
20
- load 'tasks/default.rake'
data/tasks/default.rake DELETED
@@ -1,242 +0,0 @@
1
- # vim: syntax=ruby
2
- require 'rake/clean'
3
- require 'digest'
4
- #------------------------------------------------------------------------------
5
- # If you want to Develop on this project just run 'rake develop' and you'll
6
- # have all you need to get going. If you want to use bundler for development,
7
- # then run 'rake develop:using_bundler'
8
- #------------------------------------------------------------------------------
9
- namespace :develop do
10
-
11
- # Install all the development and runtime dependencies of this gem using the
12
- # gemspec.
13
- task :default => 'Gemfile' do
14
- require 'rubygems/dependency_installer'
15
- installer = ::Gem::DependencyInstaller.new
16
- puts "Installing bundler..."
17
- installer.install 'bundler'
18
- sh 'bundle install'
19
- puts "\n\nNow run 'rake test'"
20
- end
21
-
22
- # Create a Gemfile that just references the gemspec
23
- file 'Gemfile' => :gemspec do
24
- File.open( "Gemfile", "w+" ) do |f|
25
- f.puts "# DO NOT EDIT - This file is automatically generated"
26
- f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
27
- f.puts 'source "https://rubygems.org"'
28
- f.puts 'gemspec'
29
- end
30
- end
31
- end
32
- desc "Bootstrap development"
33
- task :develop => "develop:default"
34
-
35
- #------------------------------------------------------------------------------
36
- # Minitest - standard TestTask
37
- #------------------------------------------------------------------------------
38
- begin
39
- require 'rake/testtask'
40
- Rake::TestTask.new( :test ) do |t|
41
- t.ruby_opts = %w[ -w ]
42
- t.libs = %w[ lib spec test ]
43
- t.pattern = "{test,spec}/**/{test_*,*_spec}.rb"
44
- end
45
-
46
- task :test_requirements
47
- task :test => :test_requirements
48
- task :default => :test
49
- rescue LoadError
50
- This.task_warning( 'test' )
51
- end
52
-
53
- #------------------------------------------------------------------------------
54
- # RDoc - standard rdoc rake task, although we must make sure to use a more
55
- # recent version of rdoc since it is the one that has 'tomdoc' markup
56
- #------------------------------------------------------------------------------
57
- begin
58
- gem 'rdoc' # otherwise we get the wrong task from stdlib
59
- require 'rdoc/task'
60
- RDoc::Task.new do |t|
61
- t.markup = 'tomdoc'
62
- t.rdoc_dir = 'doc'
63
- t.main = 'README.md'
64
- t.title = "#{This.name} #{This.version}"
65
- t.rdoc_files.include( FileList['*.{rdoc,md,txt}'], FileList['ext/**/*.c'],
66
- FileList['lib/**/*.rb'] )
67
- end
68
- rescue StandardError, LoadError
69
- This.task_warning( 'rdoc' )
70
- end
71
-
72
- #------------------------------------------------------------------------------
73
- # Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
74
- # for the moment only rcov is listed.
75
- #------------------------------------------------------------------------------
76
- begin
77
- require 'simplecov'
78
- desc 'Run tests with code coverage'
79
- task :coverage do
80
- ENV['COVERAGE'] = 'true'
81
- Rake::Task[:test].execute
82
- end
83
- CLOBBER << 'coverage' if File.directory?( 'coverage' )
84
- rescue LoadError
85
- This.task_warning( 'simplecov' )
86
- end
87
-
88
- #------------------------------------------------------------------------------
89
- # Manifest - We want an explicit list of thos files that are to be packaged in
90
- # the gem. Most of this is from Hoe.
91
- #------------------------------------------------------------------------------
92
- namespace 'manifest' do
93
- desc "Check the manifest"
94
- task :check => :clean do
95
- files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
96
- files = files.select{ |f| File.file?( f ) }
97
-
98
- tmp = "Manifest.tmp"
99
- File.open( tmp, 'w' ) do |f|
100
- f.puts files.join("\n")
101
- end
102
-
103
- begin
104
- sh "diff -du Manifest.txt #{tmp}"
105
- ensure
106
- rm tmp
107
- end
108
- puts "Manifest looks good"
109
- end
110
-
111
- desc "Generate the manifest"
112
- task :generate => :clean do
113
- files = %x[ git ls-files ].split("\n").sort
114
- files.reject! { |f| f =~ This.exclude_from_manifest }
115
- File.open( "Manifest.txt", "w" ) do |f|
116
- f.puts files.join("\n")
117
- end
118
- end
119
- end
120
-
121
- #------------------------------------------------------------------------------
122
- # Fixme - look for fixmes and report them
123
- #------------------------------------------------------------------------------
124
- namespace :fixme do
125
- task :default => 'manifest:check' do
126
- This.manifest.each do |file|
127
- next if file == __FILE__
128
- next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
129
- puts "FIXME: Rename #{file}" if file =~ /fixme/i
130
- IO.readlines( file ).each_with_index do |line, idx|
131
- prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
132
- puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
133
- end
134
- end
135
- end
136
-
137
- def fixme_project_root
138
- This.project_path( '../fixme' )
139
- end
140
-
141
- def fixme_project_path( subtree )
142
- fixme_project_root.join( subtree )
143
- end
144
-
145
- def local_fixme_files
146
- This.manifest.select { |p| p =~ %r|^tasks/| }
147
- end
148
-
149
- def outdated_fixme_files
150
- local_fixme_files.select do |local|
151
- upstream = fixme_project_path( local )
152
- upstream.exist? &&
153
- ( Digest::SHA256.file( local ) != Digest::SHA256.file( upstream ) )
154
- end
155
- end
156
-
157
- def fixme_up_to_date?
158
- outdated_fixme_files.empty?
159
- end
160
-
161
- desc "See if the fixme tools are outdated"
162
- task :outdated do
163
- if fixme_up_to_date? then
164
- puts "Fixme files are up to date."
165
- else
166
- outdated_fixme_files.each do |f|
167
- puts "#{f} is outdated"
168
- end
169
- end
170
- end
171
-
172
- desc "Update outdated fixme files"
173
- task :update do
174
- if fixme_up_to_date? then
175
- puts "Fixme files are already up to date."
176
- else
177
- puts "Updating fixme files:"
178
- outdated_fixme_files.each do |local|
179
- upstream = fixme_project_path( local )
180
- puts " * #{local}"
181
- FileUtils.cp( upstream, local )
182
- end
183
- puts "Use your git commands as appropriate."
184
- end
185
- end
186
- end
187
- desc "Look for fixmes and report them"
188
- task :fixme => "fixme:default"
189
-
190
- #------------------------------------------------------------------------------
191
- # Gem Specification
192
- #------------------------------------------------------------------------------
193
- # Really this is only here to support those who use bundler
194
- desc "Build the #{This.name}.gemspec file"
195
- task :gemspec do
196
- File.open( This.gemspec_file, "wb+" ) do |f|
197
- f.puts "# DO NOT EDIT - This file is automatically generated"
198
- f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
199
- f.write This.platform_gemspec.to_ruby
200
- end
201
- end
202
-
203
- # .rbc files from ruby 2.0
204
- CLOBBER << FileList["**/*.rbc"]
205
-
206
- # The standard gem packaging task, everyone has it.
207
- require 'rubygems/package_task'
208
- ::Gem::PackageTask.new( This.platform_gemspec ) do
209
- # nothing
210
- end
211
-
212
- #------------------------------------------------------------------------------
213
- # Release - the steps we go through to do a final release, this is pulled from
214
- # a compbination of mojombo's rakegem, hoe and hoe-git
215
- #
216
- # 1) make sure we are on the main branch
217
- # 2) make sure there are no uncommitted items
218
- # 3) check the manifest and make sure all looks good
219
- # 4) build the gem
220
- # 5) do an empty commit to have the commit message of the version
221
- # 6) tag that commit as the version
222
- # 7) push main
223
- # 8) push the tag
224
- # 7) pus the gem
225
- #------------------------------------------------------------------------------
226
- task :release_check do
227
- unless `git branch` =~ /^\* main/
228
- abort "You must be on the main branch to release!"
229
- end
230
- unless `git status` =~ /^nothing to commit/m
231
- abort "Nope, sorry, you have unfinished business"
232
- end
233
- end
234
-
235
- desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
236
- task :release => [ :release_check, 'manifest:check', :gem ] do
237
- sh "git commit --allow-empty -a -m 'Release #{This.version}'"
238
- sh "git tag -a -m 'v#{This.version}' v#{This.version}"
239
- sh "git push origin main"
240
- sh "git push origin v#{This.version}"
241
- sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
242
- end