table_structure 0.3.23 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/table_structure.rb +0 -1
- data/lib/table_structure/csv/writer.rb +4 -40
- data/lib/table_structure/iterator.rb +6 -73
- data/lib/table_structure/schema.rb +5 -44
- data/lib/table_structure/schema/dsl/column_converter.rb +0 -13
- data/lib/table_structure/schema/dsl/context_builder.rb +1 -7
- data/lib/table_structure/schema/dsl/row_builder.rb +0 -7
- data/lib/table_structure/table.rb +0 -10
- data/lib/table_structure/version.rb +1 -1
- data/lib/table_structure/writer.rb +6 -51
- metadata +2 -3
- data/lib/table_structure/schema/dsl/option.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea80d58dcf58000e510c71d8eac9960ccb469256df07144c9e7845aec32512aa
|
4
|
+
data.tar.gz: 2ae14c91013b1cd2b84e177f3fd7ebb6948775230f019c5ca3f3c3677b892b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60a40d43594078d7d480e518a2e144d4fda1612ee07b3707e21646ea3f7785ac055de4e9b82509190fe22735c0fb887ee94b74a61536ec7adb102730a7fad28a
|
7
|
+
data.tar.gz: 49d45d82eb9cac83caaac09d1494b8957ac56683cf21a3f11b7f01600b4e0a2174207043ee651f8ce3464f4b0474b5130962690a671977eb55a4efc9d15b892a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -256,6 +256,10 @@ Initialize a table with the schema and render the table:
|
|
256
256
|
<% end %>
|
257
257
|
```
|
258
258
|
|
259
|
+
### Sample with docker
|
260
|
+
|
261
|
+
https://github.com/jsmmr/ruby_table_structure_sample
|
262
|
+
|
259
263
|
### Advanced
|
260
264
|
|
261
265
|
You can add definitions when initializing the schema.
|
@@ -472,10 +476,6 @@ concatenated_schema = (UserTableSchema + PetTableSchema + QuestionTableSchema).n
|
|
472
476
|
merged_schema = UserTableSchema.merge(PetTableSchema, QuestionTableSchema).new(context: context)
|
473
477
|
```
|
474
478
|
|
475
|
-
## Sample with docker
|
476
|
-
|
477
|
-
https://github.com/jsmmr/ruby_table_structure_sample
|
478
|
-
|
479
479
|
## Contributing
|
480
480
|
|
481
481
|
Bug reports and pull requests are welcome on GitHub at https://github.com/jsmmr/ruby_table_structure.
|
data/lib/table_structure.rb
CHANGED
@@ -10,7 +10,6 @@ module TableStructure
|
|
10
10
|
require 'table_structure/schema/dsl/column_converter'
|
11
11
|
require 'table_structure/schema/dsl/column_definition'
|
12
12
|
require 'table_structure/schema/dsl/context_builder'
|
13
|
-
require 'table_structure/schema/dsl/option'
|
14
13
|
require 'table_structure/schema/dsl/row_builder'
|
15
14
|
require 'table_structure/schema/definition/column_converter'
|
16
15
|
require 'table_structure/schema/definition/context_builder'
|
@@ -9,32 +9,19 @@ module TableStructure
|
|
9
9
|
schema,
|
10
10
|
bom: false,
|
11
11
|
csv_options: {},
|
12
|
-
header: { context: nil }
|
13
|
-
**deprecated_options
|
12
|
+
header: { context: nil }
|
14
13
|
)
|
15
|
-
if deprecated_options.key?(:header_omitted)
|
16
|
-
header_omitted = deprecated_options[:header_omitted]
|
17
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
18
|
-
header = !header_omitted
|
19
|
-
end
|
20
|
-
|
21
|
-
if deprecated_options.key?(:header_context)
|
22
|
-
header_context = deprecated_options[:header_context]
|
23
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
24
|
-
header = { context: header_context }
|
25
|
-
end
|
26
|
-
|
27
14
|
require 'csv'
|
28
15
|
|
29
16
|
@options = {
|
30
17
|
bom: bom,
|
31
18
|
csv_options: csv_options
|
32
19
|
}
|
33
|
-
|
20
|
+
inner_options = {
|
34
21
|
header: header
|
35
22
|
}
|
36
23
|
|
37
|
-
@writer = ::TableStructure::Writer.new(schema,
|
24
|
+
@writer = ::TableStructure::Writer.new(schema, **inner_options)
|
38
25
|
end
|
39
26
|
|
40
27
|
def write(
|
@@ -42,35 +29,12 @@ module TableStructure
|
|
42
29
|
to:,
|
43
30
|
bom: @options[:bom],
|
44
31
|
csv_options: @options[:csv_options],
|
45
|
-
**deprecated_options,
|
46
32
|
&block
|
47
33
|
)
|
48
|
-
header = nil
|
49
|
-
|
50
|
-
if deprecated_options.key?(:header)
|
51
|
-
header = deprecated_options[:header]
|
52
|
-
warn '[TableStructure] Specify :header option as an argument for initialize method.'
|
53
|
-
end
|
54
|
-
|
55
|
-
if deprecated_options.key?(:header_omitted)
|
56
|
-
header_omitted = deprecated_options[:header_omitted]
|
57
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
58
|
-
header = !header_omitted
|
59
|
-
end
|
60
|
-
|
61
|
-
if deprecated_options.key?(:header_context)
|
62
|
-
header_context = deprecated_options[:header_context]
|
63
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
64
|
-
header = { context: header_context }
|
65
|
-
end
|
66
|
-
|
67
|
-
inner_options = {}
|
68
|
-
inner_options[:header] = header if header
|
69
|
-
|
70
34
|
to << BOM if bom
|
71
35
|
|
72
36
|
csv = ::CSV.new(to, **csv_options)
|
73
|
-
@writer.write(items, to: csv,
|
37
|
+
@writer.write(items, to: csv, &block)
|
74
38
|
end
|
75
39
|
end
|
76
40
|
end
|
@@ -5,30 +5,8 @@ module TableStructure
|
|
5
5
|
def initialize(
|
6
6
|
schema,
|
7
7
|
header: { context: nil },
|
8
|
-
row_type: :array
|
9
|
-
**deprecated_options
|
8
|
+
row_type: :array
|
10
9
|
)
|
11
|
-
if deprecated_options.key?(:header_omitted)
|
12
|
-
header_omitted = deprecated_options[:header_omitted]
|
13
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
14
|
-
header = !header_omitted
|
15
|
-
end
|
16
|
-
|
17
|
-
if deprecated_options.key?(:header_context)
|
18
|
-
header_context = deprecated_options[:header_context]
|
19
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
20
|
-
header = { context: header_context }
|
21
|
-
end
|
22
|
-
|
23
|
-
if deprecated_options.key?(:result_type)
|
24
|
-
warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
|
25
|
-
row_type = deprecated_options[:result_type]
|
26
|
-
end
|
27
|
-
|
28
|
-
unless schema.is_a?(Schema)
|
29
|
-
raise ::TableStructure::Error, "Must be use Schema. #{schema}"
|
30
|
-
end
|
31
|
-
|
32
10
|
@schema = schema
|
33
11
|
@options = {
|
34
12
|
header: header,
|
@@ -36,48 +14,16 @@ module TableStructure
|
|
36
14
|
}
|
37
15
|
end
|
38
16
|
|
39
|
-
def iterate(
|
40
|
-
items
|
41
|
-
|
42
|
-
&block
|
43
|
-
)
|
44
|
-
header = @options[:header]
|
45
|
-
row_type = @options[:row_type]
|
46
|
-
|
47
|
-
if deprecated_options.key?(:header)
|
48
|
-
header = deprecated_options[:header]
|
49
|
-
warn '[TableStructure] Use :header option on initialize method.'
|
50
|
-
end
|
51
|
-
|
52
|
-
if deprecated_options.key?(:header_omitted)
|
53
|
-
header_omitted = deprecated_options[:header_omitted]
|
54
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
55
|
-
header = !header_omitted
|
56
|
-
end
|
57
|
-
|
58
|
-
if deprecated_options.key?(:header_context)
|
59
|
-
header_context = deprecated_options[:header_context]
|
60
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
61
|
-
header = { context: header_context }
|
62
|
-
end
|
63
|
-
|
64
|
-
if deprecated_options.key?(:row_type)
|
65
|
-
row_type = deprecated_options[:row_type]
|
66
|
-
warn '[TableStructure] Use :row_type option on initialize method.'
|
67
|
-
end
|
68
|
-
|
69
|
-
if deprecated_options.key?(:result_type)
|
70
|
-
warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
|
71
|
-
row_type = deprecated_options[:result_type]
|
17
|
+
def iterate(items, &block)
|
18
|
+
unless items.respond_to?(:each)
|
19
|
+
raise ::TableStructure::Error, "Must be enumerable. #{items}"
|
72
20
|
end
|
73
21
|
|
74
|
-
items = enumerize(items)
|
75
|
-
|
76
22
|
enum =
|
77
23
|
Table::Iterator
|
78
24
|
.new(
|
79
|
-
Table.new(@schema, row_type: row_type),
|
80
|
-
header: header
|
25
|
+
Table.new(@schema, row_type: @options[:row_type]),
|
26
|
+
header: @options[:header]
|
81
27
|
)
|
82
28
|
.iterate(items)
|
83
29
|
|
@@ -90,18 +36,5 @@ module TableStructure
|
|
90
36
|
|
91
37
|
enum
|
92
38
|
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
def enumerize(items)
|
97
|
-
if items.respond_to?(:each)
|
98
|
-
items
|
99
|
-
elsif items.respond_to?(:call)
|
100
|
-
warn "[TableStructure] Use `Enumerator` to wrap items instead of `lambda`. The use of `lambda` has been deprecated. #{items}"
|
101
|
-
Enumerator.new { |y| items.call(y) }
|
102
|
-
else
|
103
|
-
raise ::TableStructure::Error, "Must be enumerable. #{items}"
|
104
|
-
end
|
105
|
-
end
|
106
39
|
end
|
107
40
|
end
|
@@ -6,7 +6,6 @@ module TableStructure
|
|
6
6
|
klass.extend(DSL::ColumnConverter)
|
7
7
|
klass.extend(DSL::ColumnDefinition)
|
8
8
|
klass.extend(DSL::ContextBuilder)
|
9
|
-
klass.extend(DSL::Option)
|
10
9
|
klass.extend(DSL::RowBuilder)
|
11
10
|
klass.extend(ClassMethods)
|
12
11
|
end
|
@@ -36,31 +35,8 @@ module TableStructure
|
|
36
35
|
key_prefix: nil,
|
37
36
|
key_suffix: nil,
|
38
37
|
nil_definitions_ignored: false,
|
39
|
-
**deprecated_options,
|
40
38
|
&block
|
41
39
|
)
|
42
|
-
if deprecated_options.key?(:row_type)
|
43
|
-
raise ::TableStructure::Error, 'Use :row_type option with Table, Writer or Iterator.'
|
44
|
-
end
|
45
|
-
|
46
|
-
if deprecated_options.key?(:result_type)
|
47
|
-
raise ::TableStructure::Error, ':result_type option has been deprecated. Use :row_type option instead.'
|
48
|
-
end
|
49
|
-
|
50
|
-
options =
|
51
|
-
[
|
52
|
-
self.class.options,
|
53
|
-
{
|
54
|
-
name_prefix: name_prefix,
|
55
|
-
name_suffix: name_suffix,
|
56
|
-
key_prefix: key_prefix,
|
57
|
-
key_suffix: key_suffix,
|
58
|
-
nil_definitions_ignored: nil_definitions_ignored
|
59
|
-
},
|
60
|
-
deprecated_options
|
61
|
-
]
|
62
|
-
.reduce({}, &:merge!)
|
63
|
-
|
64
40
|
schema_classes = [self.class]
|
65
41
|
|
66
42
|
if block_given?
|
@@ -82,14 +58,14 @@ module TableStructure
|
|
82
58
|
.reduce({}, &:merge!)
|
83
59
|
.merge(
|
84
60
|
ColumnConverter.create_optional_converters(
|
85
|
-
name_prefix:
|
86
|
-
name_suffix:
|
61
|
+
name_prefix: name_prefix,
|
62
|
+
name_suffix: name_suffix
|
87
63
|
)
|
88
64
|
)
|
89
65
|
|
90
66
|
@key_converter = KeyConverter.new(
|
91
|
-
prefix:
|
92
|
-
suffix:
|
67
|
+
prefix: key_prefix,
|
68
|
+
suffix: key_suffix
|
93
69
|
)
|
94
70
|
|
95
71
|
@row_builders =
|
@@ -104,24 +80,9 @@ module TableStructure
|
|
104
80
|
.new(
|
105
81
|
name,
|
106
82
|
schema_classes.map(&:column_definitions).reduce([], &:concat),
|
107
|
-
{ nil_definitions_ignored:
|
83
|
+
{ nil_definitions_ignored: nil_definitions_ignored }
|
108
84
|
)
|
109
85
|
.compile(@context)
|
110
|
-
|
111
|
-
@options = options
|
112
|
-
end
|
113
|
-
|
114
|
-
def create_table(row_type: :array, **deprecated_options, &block)
|
115
|
-
warn '[TableStructure] `TableStructure::Schema#create_table` has been deprecated. Use `TableStructure::Table.new` instead.'
|
116
|
-
|
117
|
-
options = @options.merge(deprecated_options)
|
118
|
-
|
119
|
-
if options.key?(:result_type)
|
120
|
-
warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
|
121
|
-
options[:row_type] = options[:result_type]
|
122
|
-
end
|
123
|
-
|
124
|
-
::TableStructure::Table.new(self, row_type: options[:row_type] || row_type, &block)
|
125
86
|
end
|
126
87
|
|
127
88
|
def contain_callable?(attribute)
|
@@ -6,23 +6,10 @@ module TableStructure
|
|
6
6
|
module ColumnConverter
|
7
7
|
def column_converter(
|
8
8
|
name,
|
9
|
-
callable = nil,
|
10
9
|
header: true,
|
11
10
|
body: true,
|
12
|
-
**deprecated_options,
|
13
11
|
&block
|
14
12
|
)
|
15
|
-
if deprecated_options.key?(:row)
|
16
|
-
warn '[TableStructure] `:row` option has been deprecated. Use `:body` option instead.'
|
17
|
-
body = deprecated_options[:row]
|
18
|
-
end
|
19
|
-
|
20
|
-
if callable
|
21
|
-
warn "[TableStructure] Use `block` instead of #{callable}."
|
22
|
-
end
|
23
|
-
|
24
|
-
block ||= callable
|
25
|
-
|
26
13
|
column_converters[name] =
|
27
14
|
::TableStructure::Schema::Definition::ColumnConverter.new(
|
28
15
|
header: header,
|
@@ -5,13 +5,7 @@ module TableStructure
|
|
5
5
|
module DSL
|
6
6
|
module ContextBuilder
|
7
7
|
# TODO: Change definition style
|
8
|
-
def context_builder(name,
|
9
|
-
if callable
|
10
|
-
warn "[TableStructure] Use `block` instead of #{callable}."
|
11
|
-
end
|
12
|
-
|
13
|
-
block ||= callable
|
14
|
-
|
8
|
+
def context_builder(name, &block)
|
15
9
|
context_builders[name] =
|
16
10
|
::TableStructure::Schema::Definition::ContextBuilder.new(
|
17
11
|
&block
|
@@ -6,16 +6,9 @@ module TableStructure
|
|
6
6
|
module RowBuilder
|
7
7
|
def row_builder(
|
8
8
|
name,
|
9
|
-
callable = nil,
|
10
9
|
enabled_row_types: %i[array hash],
|
11
10
|
&block
|
12
11
|
)
|
13
|
-
if callable
|
14
|
-
warn "[TableStructure] Use `block` instead of #{callable}."
|
15
|
-
end
|
16
|
-
|
17
|
-
block ||= callable
|
18
|
-
|
19
12
|
row_builders[name] =
|
20
13
|
::TableStructure::Schema::Definition::RowBuilder.new(
|
21
14
|
enabled_row_types: enabled_row_types,
|
@@ -39,16 +39,6 @@ module TableStructure
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def rows(items)
|
43
|
-
warn '[TableStructure] `TableStructure::Table#rows(items)` has been deprecated. Use `TableStructure::Table#body(items)` instead.'
|
44
|
-
body(items)
|
45
|
-
end
|
46
|
-
|
47
|
-
def row(context: nil)
|
48
|
-
warn '[TableStructure] `TableStructure::Table#row(context: ...)` has been deprecated. Use `TableStructure::Table#body(items)` instead.'
|
49
|
-
data(context: context)
|
50
|
-
end
|
51
|
-
|
52
42
|
private
|
53
43
|
|
54
44
|
def data(context: nil)
|
@@ -6,26 +6,8 @@ module TableStructure
|
|
6
6
|
schema,
|
7
7
|
header: { context: nil },
|
8
8
|
method: :<<,
|
9
|
-
row_type: :array
|
10
|
-
**deprecated_options
|
9
|
+
row_type: :array
|
11
10
|
)
|
12
|
-
if deprecated_options.key?(:header_omitted)
|
13
|
-
header_omitted = deprecated_options[:header_omitted]
|
14
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
15
|
-
header = !header_omitted
|
16
|
-
end
|
17
|
-
|
18
|
-
if deprecated_options.key?(:header_context)
|
19
|
-
header_context = deprecated_options[:header_context]
|
20
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
21
|
-
header = { context: header_context }
|
22
|
-
end
|
23
|
-
|
24
|
-
if deprecated_options.key?(:result_type)
|
25
|
-
warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
|
26
|
-
row_type = deprecated_options[:result_type]
|
27
|
-
end
|
28
|
-
|
29
11
|
@schema = schema
|
30
12
|
@options = {
|
31
13
|
header: header,
|
@@ -38,43 +20,16 @@ module TableStructure
|
|
38
20
|
items,
|
39
21
|
to:,
|
40
22
|
method: @options[:method],
|
41
|
-
**deprecated_options,
|
42
23
|
&block
|
43
24
|
)
|
44
|
-
header = @options[:header]
|
45
|
-
row_type = @options[:row_type]
|
46
|
-
|
47
|
-
if deprecated_options.key?(:header)
|
48
|
-
header = deprecated_options[:header]
|
49
|
-
warn '[TableStructure] Use :header option on initialize method.'
|
50
|
-
end
|
51
|
-
|
52
|
-
if deprecated_options.key?(:header_omitted)
|
53
|
-
header_omitted = deprecated_options[:header_omitted]
|
54
|
-
warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
|
55
|
-
header = !header_omitted
|
56
|
-
end
|
57
|
-
|
58
|
-
if deprecated_options.key?(:header_context)
|
59
|
-
header_context = deprecated_options[:header_context]
|
60
|
-
warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
|
61
|
-
header = { context: header_context }
|
62
|
-
end
|
63
|
-
|
64
|
-
if deprecated_options.key?(:row_type)
|
65
|
-
row_type = deprecated_options[:row_type]
|
66
|
-
warn '[TableStructure] Use :row_type option on initialize method.'
|
67
|
-
end
|
68
|
-
|
69
|
-
if deprecated_options.key?(:result_type)
|
70
|
-
warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
|
71
|
-
row_type = deprecated_options[:result_type]
|
72
|
-
end
|
73
|
-
|
74
25
|
output = Output.new(to, method: method)
|
75
26
|
|
76
27
|
Iterator
|
77
|
-
.new(
|
28
|
+
.new(
|
29
|
+
@schema,
|
30
|
+
header: @options[:header],
|
31
|
+
row_type: @options[:row_type]
|
32
|
+
)
|
78
33
|
.iterate(items, &block)
|
79
34
|
.each { |row| output.write(row) }
|
80
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_structure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03
|
11
|
+
date: 2020-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- lib/table_structure/schema/dsl/column_converter.rb
|
91
91
|
- lib/table_structure/schema/dsl/column_definition.rb
|
92
92
|
- lib/table_structure/schema/dsl/context_builder.rb
|
93
|
-
- lib/table_structure/schema/dsl/option.rb
|
94
93
|
- lib/table_structure/schema/dsl/row_builder.rb
|
95
94
|
- lib/table_structure/schema/key_converter.rb
|
96
95
|
- lib/table_structure/schema/row_builder.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TableStructure
|
4
|
-
module Schema
|
5
|
-
module DSL
|
6
|
-
module Option
|
7
|
-
def option(name, value)
|
8
|
-
warn "[TableStructure] The use of `option` DSL has been deprecated. #{caller_locations(1, 1)}"
|
9
|
-
options[name] = value
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def options
|
14
|
-
@__options__ ||= {}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|