org_tp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.org +40 -1
- data/examples/0110_active_record.rb +9 -0
- data/examples/0130_mongoid.rb +35 -0
- data/examples/0140_tapp.rb +8 -0
- data/lib/org_tp/railtie.rb +6 -0
- data/lib/org_tp/version.rb +1 -1
- data/lib/org_tp.rb +6 -0
- data/spec/active_record_spec.rb +9 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 436ebc9d93cec1c944a3a6bbaecf2e26e86a9995
|
4
|
+
data.tar.gz: 305b3102fae488299d3ef3829635c858b82cbe7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147232d60975fe8a64162bdc690efb925d92d828b40ffb3bae54d2db12aa678311a4fcc78485637918086dceb547d29626824666476b8be0001576f2cec1e640
|
7
|
+
data.tar.gz: 8f8e3fff01ee26c7a21fe6b1f57f5e6c9202af1b1cd4989a4db52e021df80a568d300582e1486a986a2460d42dd5c8fd40907d04e4ff54a08321761e459caa6e
|
data/README.org
CHANGED
@@ -55,7 +55,7 @@ tp :foo
|
|
55
55
|
# >> |-----|
|
56
56
|
#+END_SRC
|
57
57
|
|
58
|
-
*** ActiveRecord
|
58
|
+
*** ActiveRecord and Mongoid
|
59
59
|
|
60
60
|
#+BEGIN_SRC ruby
|
61
61
|
["alice", "bob"].each {|e| User.create!(name: e) }
|
@@ -88,6 +88,18 @@ tp User.first
|
|
88
88
|
# >> |------+-------|
|
89
89
|
#+END_SRC
|
90
90
|
|
91
|
+
**** ActiveRecord::Result
|
92
|
+
|
93
|
+
#+BEGIN_SRC ruby
|
94
|
+
tp ActiveRecord::Base.connection.select_all("SELECT * FROM users")
|
95
|
+
# >> |----+-------|
|
96
|
+
# >> | id | name |
|
97
|
+
# >> |----+-------|
|
98
|
+
# >> | 1 | alice |
|
99
|
+
# >> | 2 | bob |
|
100
|
+
# >> |----+-------|
|
101
|
+
#+END_SRC
|
102
|
+
|
91
103
|
*** How to table as string
|
92
104
|
|
93
105
|
#+BEGIN_SRC ruby
|
@@ -99,3 +111,30 @@ puts [{id: 1, name: "alice"}, {id: 2, name: "bob"}].to_t
|
|
99
111
|
# >> | 2 | bob |
|
100
112
|
# >> |----+-------|
|
101
113
|
#+END_SRC
|
114
|
+
|
115
|
+
*** Global Options
|
116
|
+
|
117
|
+
#+BEGIN_SRC ruby
|
118
|
+
tp OrgTp::Generator.default_options
|
119
|
+
# >> |-------------------+-------|
|
120
|
+
# >> | header | |
|
121
|
+
# >> | vertical | | |
|
122
|
+
# >> | intersection | + |
|
123
|
+
# >> | intersection_both | | |
|
124
|
+
# >> | horizon | - |
|
125
|
+
# >> | padding | |
|
126
|
+
# >> | in_code | UTF-8 |
|
127
|
+
# >> |-------------------+-------|
|
128
|
+
|
129
|
+
tp 1
|
130
|
+
# >> |---|
|
131
|
+
# >> | 1 |
|
132
|
+
# >> |---|
|
133
|
+
|
134
|
+
OrgTp::Generator.default_options[:intersection_both] = "+"
|
135
|
+
|
136
|
+
tp 1
|
137
|
+
# >> +---+
|
138
|
+
# >> | 1 |
|
139
|
+
# >> +---+
|
140
|
+
#+END_SRC
|
@@ -3,6 +3,7 @@ require "active_record"
|
|
3
3
|
require "org_tp"
|
4
4
|
|
5
5
|
ActiveRecord::Base.include(OrgTp::ActiveRecord)
|
6
|
+
|
6
7
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
7
8
|
ActiveRecord::Migration.verbose = false
|
8
9
|
ActiveRecord::Schema.define do
|
@@ -19,6 +20,7 @@ end
|
|
19
20
|
tp User
|
20
21
|
tp User.first
|
21
22
|
tp User.limit(1)
|
23
|
+
tp ActiveRecord::Base.connection.select_all("SELECT * FROM users")
|
22
24
|
# >> |----+-------|
|
23
25
|
# >> | id | name |
|
24
26
|
# >> |----+-------|
|
@@ -35,3 +37,10 @@ tp User.limit(1)
|
|
35
37
|
# >> |----+-------|
|
36
38
|
# >> | 1 | alice |
|
37
39
|
# >> |----+-------|
|
40
|
+
# >> |----+-------|
|
41
|
+
# >> | id | name |
|
42
|
+
# >> |----+-------|
|
43
|
+
# >> | 1 | alice |
|
44
|
+
# >> | 2 | bob |
|
45
|
+
# >> | 3 | carol |
|
46
|
+
# >> |----+-------|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH << "../lib"
|
2
|
+
require "active_record"
|
3
|
+
require "mongoid" # !> method redefined; discarding old as_json
|
4
|
+
require "org_tp"
|
5
|
+
|
6
|
+
Mongo::Logger.logger.level = Logger::INFO
|
7
|
+
Mongoid::Config.connect_to("test")
|
8
|
+
Mongoid::Clients.default.database.drop
|
9
|
+
|
10
|
+
class User
|
11
|
+
include Mongoid::Document
|
12
|
+
field :name, type: String
|
13
|
+
end
|
14
|
+
|
15
|
+
["alice", "bob", "carol"].each { |e| User.create!(name: e) } # !> method redefined; discarding old text_search
|
16
|
+
|
17
|
+
tp User
|
18
|
+
tp User.first
|
19
|
+
tp User.limit(1)
|
20
|
+
# >> |--------------------------+-------|
|
21
|
+
# >> | _id | name |
|
22
|
+
# >> |--------------------------+-------|
|
23
|
+
# >> | 5988562bf6453fd586c8a492 | alice |
|
24
|
+
# >> | 5988562cf6453fd586c8a493 | bob |
|
25
|
+
# >> | 5988562cf6453fd586c8a494 | carol |
|
26
|
+
# >> |--------------------------+-------|
|
27
|
+
# >> |------+--------------------------|
|
28
|
+
# >> | _id | 5988562bf6453fd586c8a492 |
|
29
|
+
# >> | name | alice |
|
30
|
+
# >> |------+--------------------------|
|
31
|
+
# >> |--------------------------+-------|
|
32
|
+
# >> | _id | name |
|
33
|
+
# >> |--------------------------+-------|
|
34
|
+
# >> | 5988562bf6453fd586c8a492 | alice |
|
35
|
+
# >> |--------------------------+-------|
|
data/lib/org_tp/railtie.rb
CHANGED
@@ -3,6 +3,12 @@ module OrgTp
|
|
3
3
|
initializer 'org_tp' do
|
4
4
|
ActiveSupport.on_load(:active_record) do
|
5
5
|
include OrgTp::ActiveRecord
|
6
|
+
|
7
|
+
ActiveRecord::Result.class_eval do
|
8
|
+
def to_t(**options)
|
9
|
+
OrgTp.generate(collect(&:to_h), options)
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
|
8
14
|
if defined?(Mongoid::Document)
|
data/lib/org_tp/version.rb
CHANGED
data/lib/org_tp.rb
CHANGED
@@ -8,6 +8,12 @@ else
|
|
8
8
|
if defined?(ActiveSupport)
|
9
9
|
ActiveSupport.on_load(:active_record) do
|
10
10
|
include OrgTp::ActiveRecord
|
11
|
+
|
12
|
+
ActiveRecord::Result.class_eval do
|
13
|
+
def to_t(**options)
|
14
|
+
OrgTp.generate(collect(&:to_h), options)
|
15
|
+
end
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
if defined?(Mongoid::Document)
|
data/spec/active_record_spec.rb
CHANGED
@@ -33,6 +33,15 @@ EOT
|
|
33
33
|
| id | 1 |
|
34
34
|
| name | 0 |
|
35
35
|
|------+---|
|
36
|
+
EOT
|
37
|
+
|
38
|
+
ActiveRecord::Base.connection.select_all("select * from users").to_t.should == <<~EOT
|
39
|
+
|----+------|
|
40
|
+
| id | name |
|
41
|
+
|----+------|
|
42
|
+
| 1 | 0 |
|
43
|
+
| 2 | 1 |
|
44
|
+
|----+------|
|
36
45
|
EOT
|
37
46
|
end
|
38
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: org_tp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -107,6 +107,8 @@ files:
|
|
107
107
|
- examples/0100_example.rb
|
108
108
|
- examples/0110_active_record.rb
|
109
109
|
- examples/0120_default_options.rb
|
110
|
+
- examples/0130_mongoid.rb
|
111
|
+
- examples/0140_tapp.rb
|
110
112
|
- lib/org_tp.rb
|
111
113
|
- lib/org_tp/core_ext.rb
|
112
114
|
- lib/org_tp/org_tp.rb
|