table_format 0.0.7 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.org +26 -0
- data/lib/table_format/core_ext.rb +20 -20
- data/lib/table_format/generator.rb +11 -3
- data/lib/table_format/railtie.rb +1 -1
- data/lib/table_format/version.rb +1 -1
- data/lib/table_format.rb +1 -1
- data/table_format.gemspec +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81a9dcbc3604388174a753a45576b298e6829a52252c569d6305c54038995d5b
|
4
|
+
data.tar.gz: 5cc7171b9e825bdbf83e8fe5a8650e3372287dbd815ad4b000e17dd7b7cf6303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90613bd4d7ac0fc82907f007364d6dc1e541dc04b89b5cc66e3daa9f83f1d18bb088af19595a1ba5dc647e8a43d4d27aecbe28275213a1d7fdfb03ee22051990
|
7
|
+
data.tar.gz: 51bd2542a57f58469784800f79bd6468e2287d590779ea137299d467c7f5f5d07f3d4c69fb5353b8e39e67bbf9e14147f9f302f0f4fc053dec9b21e6b3fbdaa2
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.org
CHANGED
@@ -19,6 +19,32 @@ tp Object.constants.grep(/RUBY_/).map { |e| [e, Object.const_get(e)] }.to_h
|
|
19
19
|
# >> | RUBY_ENGINE_VERSION | 2.5.0 |
|
20
20
|
# >> | RUBY_COPYRIGHT | ruby - Copyright (C) 1993-2017 Yukihiro Matsumoto |
|
21
21
|
# >> |---------------------+------------------------------------------------------------|
|
22
|
+
#+END_SRC
|
23
|
+
|
24
|
+
In the case of Rails
|
25
|
+
|
26
|
+
#+BEGIN_SRC ruby
|
27
|
+
class ApplicationController < ActionController::Base
|
28
|
+
if Rails.env.development?
|
29
|
+
before_action do
|
30
|
+
logger.debug params.to_unsafe_h.to_t(truncate: 40)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
#+END_SRC
|
35
|
+
|
36
|
+
#+BEGIN_SRC shell
|
37
|
+
% cat log/development.log
|
38
|
+
Started POST "/api/xy_master/time_records" for ::1 at 2021-11-18 13:52:25 +0900
|
39
|
+
Processing by Api::XyMaster::TimeRecordsController#create as JSON
|
40
|
+
Parameters: (snip)
|
41
|
+
|-------------+---------------------------------------------|
|
42
|
+
| scope_key | scope_today |
|
43
|
+
| time_record | {"rule_key"=>"rule100t", "spent_sec"=>0,... |
|
44
|
+
| format | json |
|
45
|
+
| controller | api/xy_master/time_records |
|
46
|
+
| action | create |
|
47
|
+
|-------------+---------------------------------------------|
|
22
48
|
#+END_SRC
|
23
49
|
|
24
50
|
** Installation
|
@@ -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
|
@@ -1,4 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Workaround of:
|
4
|
+
# uninitialized constant ActiveSupport::XmlMini::IsolatedExecutionState
|
5
|
+
begin
|
6
|
+
require 'active_support/isolated_execution_state'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
2
10
|
require 'active_support/core_ext/string' # for blank?
|
3
11
|
require 'active_support/core_ext/class/attribute' # for class_attribute
|
4
12
|
require 'kconv'
|
@@ -19,12 +27,12 @@ module TableFormat
|
|
19
27
|
}
|
20
28
|
end
|
21
29
|
|
22
|
-
def self.generate(
|
23
|
-
Generator.new(
|
30
|
+
def self.generate(rows, options = {})
|
31
|
+
Generator.new(rows, options).generate
|
24
32
|
end
|
25
33
|
|
26
34
|
class Generator
|
27
|
-
def initialize(rows,
|
35
|
+
def initialize(rows, options = {})
|
28
36
|
@options = TableFormat.default_options.merge(options)
|
29
37
|
|
30
38
|
if @options[:markdown]
|
data/lib/table_format/railtie.rb
CHANGED
data/lib/table_format/version.rb
CHANGED
data/lib/table_format.rb
CHANGED
data/table_format.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency 'activesupport'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'rspec'
|
27
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ files:
|
|
128
128
|
homepage: https://github.com/akicho8/table_format
|
129
129
|
licenses: []
|
130
130
|
metadata: {}
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options:
|
133
133
|
- "--line-numbers"
|
134
134
|
- "--inline-source"
|
@@ -148,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
-
signing_key:
|
151
|
+
rubygems_version: 3.3.4
|
152
|
+
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: TableFormat shows text table like emacs org-table for easy reading.
|
155
155
|
test_files:
|