table_format 0.0.7 → 0.0.8
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/lib/table_format.rb +1 -1
- data/lib/table_format/core_ext.rb +20 -20
- data/lib/table_format/generator.rb +3 -3
- data/lib/table_format/railtie.rb +1 -1
- data/lib/table_format/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ecb4e366d0bfd3e4caa23c99eaf7ace891daec7da139485f2cf3de99dc52c81
|
4
|
+
data.tar.gz: 6d666359f1ec0610fa654b85d2593c876c3a51269f766224ced9f1dbc5038a0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37b58297e78496507612c9283a6613482c3cf618543f8f9dd234037e230fe09aac779685d6017955137b57acd4ea6c71d0cdfabac3cd8b40937f72d97a788a1f
|
7
|
+
data.tar.gz: cb033b6dbb6feff4b4fb61a58cca047c8a095f47811830837ccca8180b2abee9b2d58704065cd8747a159bc7739569fbb41468a39cba8f0a02c7a3b34c325c7d
|
data/lib/table_format.rb
CHANGED
@@ -3,36 +3,36 @@ require 'active_support/core_ext/kernel/concern'
|
|
3
3
|
module TableFormat
|
4
4
|
concern :ActiveRecord do
|
5
5
|
class_methods do
|
6
|
-
def to_t(
|
7
|
-
TableFormat.generate(all.collect(&:attributes),
|
6
|
+
def to_t(options = {})
|
7
|
+
TableFormat.generate(all.collect(&:attributes), options)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def to_t(
|
12
|
-
TableFormat.generate(attributes,
|
11
|
+
def to_t(options = {})
|
12
|
+
TableFormat.generate(attributes, options)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
concern :ActiveRecordResult do
|
17
|
-
def to_t(
|
18
|
-
TableFormat.generate(collect(&:to_h),
|
17
|
+
def to_t(options = {})
|
18
|
+
TableFormat.generate(collect(&:to_h), options)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
Object.class_eval do
|
24
|
-
def to_t(
|
24
|
+
def to_t(options = {})
|
25
25
|
case
|
26
26
|
when respond_to?(:to_a)
|
27
27
|
if false
|
28
28
|
if to_a.first.respond_to?(:attributes)
|
29
|
-
return to_a.collect(&:attributes).to_t(
|
29
|
+
return to_a.collect(&:attributes).to_t(options)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
to_a.to_t(
|
33
|
+
to_a.to_t(options)
|
34
34
|
when respond_to?(:to_h)
|
35
|
-
to_h.to_t(
|
35
|
+
to_h.to_t(options)
|
36
36
|
else
|
37
37
|
TableFormat.generate([{self.class.name => self}], **{header: false}.merge(options))
|
38
38
|
end
|
@@ -42,33 +42,33 @@ end
|
|
42
42
|
Kernel.class_eval do
|
43
43
|
private
|
44
44
|
|
45
|
-
def tp(object,
|
45
|
+
def tp(object, options = {})
|
46
46
|
object.tap do
|
47
|
-
table_format(object,
|
47
|
+
table_format(object, options).display
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def table_format(object,
|
52
|
-
object.to_t(
|
51
|
+
def table_format(object, options = {})
|
52
|
+
object.to_t(options)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
Array.class_eval do
|
57
|
-
def to_t(
|
58
|
-
TableFormat.generate(self,
|
57
|
+
def to_t(options = {})
|
58
|
+
TableFormat.generate(self, options)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
Hash.class_eval do
|
63
|
-
def to_t(
|
64
|
-
TableFormat.generate(self,
|
63
|
+
def to_t(options = {})
|
64
|
+
TableFormat.generate(self, options)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
[Symbol, String, Numeric].each do |klass|
|
69
69
|
klass.class_eval do
|
70
|
-
def to_t(
|
71
|
-
TableFormat.generate([{self.class.name => self}],
|
70
|
+
def to_t(options = {})
|
71
|
+
TableFormat.generate([{self.class.name => self}], {header: false}.merge(options))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -19,12 +19,12 @@ module TableFormat
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.generate(
|
23
|
-
Generator.new(
|
22
|
+
def self.generate(rows, options = {})
|
23
|
+
Generator.new(rows, options).generate
|
24
24
|
end
|
25
25
|
|
26
26
|
class Generator
|
27
|
-
def initialize(rows,
|
27
|
+
def initialize(rows, options = {})
|
28
28
|
@options = TableFormat.default_options.merge(options)
|
29
29
|
|
30
30
|
if @options[:markdown]
|
data/lib/table_format/railtie.rb
CHANGED
data/lib/table_format/version.rb
CHANGED