pry-helper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.solargraph.yml +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.txt +21 -0
- data/README.md +8 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pry-helper/commands/models.rb +44 -0
- data/lib/pry-helper/commands/table.rb +55 -0
- data/lib/pry-helper/commands/vd.rb +46 -0
- data/lib/pry-helper/commands.rb +6 -0
- data/lib/pry-helper/concerns/global_data_definition.rb +245 -0
- data/lib/pry-helper/concerns/table_data_definition.rb +550 -0
- data/lib/pry-helper/concerns.rb +2 -0
- data/lib/pry-helper/definition.rb +246 -0
- data/lib/pry-helper/ext/active_record/connection_adapters/abstract_mysql_adapter.rb +53 -0
- data/lib/pry-helper/ext/active_record/connection_adapters/postgresql/schema_statements.rb +8 -0
- data/lib/pry-helper/ext/array.rb +168 -0
- data/lib/pry-helper/ext/hash.rb +41 -0
- data/lib/pry-helper/ext/kernel.rb +111 -0
- data/lib/pry-helper/ext/object.rb +22 -0
- data/lib/pry-helper/ext/string.rb +13 -0
- data/lib/pry-helper/ext/time.rb +15 -0
- data/lib/pry-helper/ext.rb +5 -0
- data/lib/pry-helper/id.rb +59 -0
- data/lib/pry-helper/mysqldump.rb +44 -0
- data/lib/pry-helper/vd.rb +42 -0
- data/lib/pry-helper/version.rb +3 -0
- data/lib/pry-helper.rb +20 -0
- data/pry-helper.gemspec +32 -0
- metadata +188 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
module PryHelper
|
2
|
+
class ID
|
3
|
+
@worker_id_bits = 5
|
4
|
+
@data_center_id_bits = 5
|
5
|
+
@max_worker_id = -1 ^ (-1 << @worker_id_bits)
|
6
|
+
@max_data_center_id = -1 ^ (-1 << @data_center_id_bits)
|
7
|
+
|
8
|
+
@sequence_bits = 12
|
9
|
+
@worker_id_shift = @sequence_bits
|
10
|
+
@data_center_id_shift = @sequence_bits + @worker_id_shift
|
11
|
+
@timestamp_left_shift = @sequence_bits + @worker_id_bits + @data_center_id_bits
|
12
|
+
@sequence_mask = -1 ^ (-1 << @sequence_bits)
|
13
|
+
|
14
|
+
@id_epoch = (Time.new(2018, 1, 1, 0, 0, 0).to_f * 1000).to_i
|
15
|
+
@worker_id = 0
|
16
|
+
@data_center_id = 0
|
17
|
+
@sequence = 0
|
18
|
+
|
19
|
+
@last_timestamp = -1
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def long
|
23
|
+
ts = (Time.now.to_f * 1000).to_i
|
24
|
+
if ts < @last_timestamp
|
25
|
+
raise 'Clock moved backwards.'
|
26
|
+
end
|
27
|
+
|
28
|
+
if ts == @last_timestamp
|
29
|
+
@sequence = (@sequence + 1) & @sequence_mask
|
30
|
+
if (@sequence == 0)
|
31
|
+
ts = til_next_millis(@last_timestamp)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@sequence = 0
|
35
|
+
end
|
36
|
+
@last_timestamp = ts
|
37
|
+
|
38
|
+
((ts - @id_epoch) << @timestamp_left_shift) | (@data_center_id << @data_center_id_shift) | (@worker_id << @worker_id_shift) | @sequence
|
39
|
+
end
|
40
|
+
|
41
|
+
def uuid
|
42
|
+
require 'securerandom'
|
43
|
+
SecureRandom.uuid.gsub('-', '')
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def til_next_millis(last_timestamp)
|
49
|
+
ts = (Time.now.to_f * 1000).to_i
|
50
|
+
while ts <= last_timestamp
|
51
|
+
ts = (Time.now.to_f * 1000).to_i
|
52
|
+
end
|
53
|
+
ts
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
::ID = PryHelper::ID
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module PryHelper
|
2
|
+
class Mysqldump
|
3
|
+
|
4
|
+
def initialize(options = nil)
|
5
|
+
options ||= App.connect_options
|
6
|
+
@options = options
|
7
|
+
if options[:socket]
|
8
|
+
port_or_sock = "-S #{options[:socket]}"
|
9
|
+
else
|
10
|
+
port_or_sock = "-P #{options[:port] || 3306}"
|
11
|
+
end
|
12
|
+
@base_dump_cmd = "mysqldump -u %{user} -h %{host} %{port_or_sock} %{password} --skip-lock-tables " % {
|
13
|
+
user: options[:username],
|
14
|
+
host: options[:host],
|
15
|
+
password: options[:password].presence.try { |e| "-p#{e}" } || '',
|
16
|
+
port_or_sock: port_or_sock
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def dump_table(filename, table_name, no_create_table = false)
|
21
|
+
system dump_table_cmd(table_name, no_create_table) + " > #{filename}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def dump_database(filename, no_create_db = false)
|
25
|
+
system dump_database_cmd(no_create_db) + " > #{filename}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def dump_table_cmd(table_name, no_create_table = false)
|
29
|
+
@base_dump_cmd + " " + if no_create_table
|
30
|
+
"--no-create-info #{@options[:database]} #{table_name}"
|
31
|
+
else
|
32
|
+
"--add-drop-table #{@options[:database]} #{table_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump_database_cmd(no_create_db = false)
|
37
|
+
@base_dump_cmd + " " + if no_create_db
|
38
|
+
"--no-create-db --add-drop-database --databases #{@options[:database]}"
|
39
|
+
else
|
40
|
+
"--add-drop-database --add-drop-table --databases #{@options[:database]}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module PryHelper
|
4
|
+
class VD
|
5
|
+
COMMAND = 'vd'
|
6
|
+
|
7
|
+
attr_accessor :rows
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
return unless check_command_installation
|
11
|
+
@rows = []
|
12
|
+
yield self
|
13
|
+
command = "#{COMMAND} -f csv"
|
14
|
+
IO.popen(command, 'w+') do |io|
|
15
|
+
io.puts(csv)
|
16
|
+
io.close_write
|
17
|
+
end
|
18
|
+
print "\033[5 q"
|
19
|
+
end
|
20
|
+
|
21
|
+
def <<(row)
|
22
|
+
rows << row
|
23
|
+
end
|
24
|
+
|
25
|
+
def csv
|
26
|
+
CSV.generate do |csv|
|
27
|
+
rows.each do |row|
|
28
|
+
csv << row
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_command_installation
|
34
|
+
`which #{COMMAND}`
|
35
|
+
if $?.exitstatus != 0
|
36
|
+
puts "Please install vd (visidata) command, see: https://www.visidata.org/"
|
37
|
+
else
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/pry-helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
if Rails.const_defined? 'Console'
|
2
|
+
Pry.hooks.add_hook(:when_started, :pry_helper) do |output, binding, pry|
|
3
|
+
require 'terminal-table'
|
4
|
+
require 'table_print'
|
5
|
+
require 'roo'
|
6
|
+
require 'caxlsx'
|
7
|
+
require 'csv'
|
8
|
+
require "pry-helper/version"
|
9
|
+
require 'pry-helper/id'
|
10
|
+
require 'pry-helper/ext'
|
11
|
+
require "pry-helper/mysqldump"
|
12
|
+
require "pry-helper/vd"
|
13
|
+
require 'pry-helper/definition'
|
14
|
+
require 'pry-helper/commands'
|
15
|
+
PryHelper::Definition.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module PryHelper
|
20
|
+
end
|
data/pry-helper.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'lib/pry-helper/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "pry-helper"
|
5
|
+
spec.version = PryHelper::VERSION
|
6
|
+
spec.authors = ["Liu Xiang"]
|
7
|
+
spec.email = ["liuxiang921@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %{Pry helpers}
|
10
|
+
spec.description = %{Pry helpers}
|
11
|
+
spec.homepage = "https://github.com/lululau/pry-helper"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'activerecord'
|
25
|
+
spec.add_dependency 'activesupport'
|
26
|
+
spec.add_dependency 'pry-doc'
|
27
|
+
spec.add_dependency 'rainbow'
|
28
|
+
spec.add_dependency 'terminal-table'
|
29
|
+
spec.add_dependency 'table_print'
|
30
|
+
spec.add_dependency 'roo'
|
31
|
+
spec.add_dependency 'caxlsx'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Liu Xiang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-doc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rainbow
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: table_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: roo
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: caxlsx
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Pry helpers
|
126
|
+
email:
|
127
|
+
- liuxiang921@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".solargraph.yml"
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/pry-helper.rb
|
143
|
+
- lib/pry-helper/commands.rb
|
144
|
+
- lib/pry-helper/commands/models.rb
|
145
|
+
- lib/pry-helper/commands/table.rb
|
146
|
+
- lib/pry-helper/commands/vd.rb
|
147
|
+
- lib/pry-helper/concerns.rb
|
148
|
+
- lib/pry-helper/concerns/global_data_definition.rb
|
149
|
+
- lib/pry-helper/concerns/table_data_definition.rb
|
150
|
+
- lib/pry-helper/definition.rb
|
151
|
+
- lib/pry-helper/ext.rb
|
152
|
+
- lib/pry-helper/ext/active_record/connection_adapters/abstract_mysql_adapter.rb
|
153
|
+
- lib/pry-helper/ext/active_record/connection_adapters/postgresql/schema_statements.rb
|
154
|
+
- lib/pry-helper/ext/array.rb
|
155
|
+
- lib/pry-helper/ext/hash.rb
|
156
|
+
- lib/pry-helper/ext/kernel.rb
|
157
|
+
- lib/pry-helper/ext/object.rb
|
158
|
+
- lib/pry-helper/ext/string.rb
|
159
|
+
- lib/pry-helper/ext/time.rb
|
160
|
+
- lib/pry-helper/id.rb
|
161
|
+
- lib/pry-helper/mysqldump.rb
|
162
|
+
- lib/pry-helper/vd.rb
|
163
|
+
- lib/pry-helper/version.rb
|
164
|
+
- pry-helper.gemspec
|
165
|
+
homepage: https://github.com/lululau/pry-helper
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: 2.6.0
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubygems_version: 3.3.3
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: Pry helpers
|
188
|
+
test_files: []
|