arql 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -8
- data/lib/arql/app.rb +2 -1
- data/lib/arql/definition.rb +11 -4
- data/lib/arql/ext/array.rb +12 -2
- data/lib/arql/ext/kernel.rb +4 -1
- data/lib/arql/ext/object.rb +4 -0
- data/lib/arql/repl.rb +2 -2
- data/lib/arql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032762276fe5d2c764f71eae665d16e2e4786368c7f154e7bd19be5188a49027
|
4
|
+
data.tar.gz: 73b8ceedbcd0abdc5c87c186374c8cfe0db50e0c22d1e645d2c10396ec8c4aa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc70e4f11ff7bcfc4f0654d8a3e59ac2ae666e55237dff7d62e408c3c6bba200b22f3e064ea17dc513a94bbd4eacefa8f369d4d79c24d9a9ada857efa00c58af
|
7
|
+
data.tar.gz: 34491bfc5588a4bae89f26f889c5863e700f79b926902bb769c3e122082342706252fc41bcf461244bfc82e8f5a5e7dbf1eb4bd3c43d726f1d9fb9f5164170b0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arql (0.2.
|
4
|
+
arql (0.2.5)
|
5
5
|
activerecord (~> 6.0.3)
|
6
6
|
activesupport (~> 6.0.3)
|
7
7
|
caxlsx (~> 3.0.2)
|
@@ -19,12 +19,12 @@ PATH
|
|
19
19
|
GEM
|
20
20
|
remote: https://rubygems.org/
|
21
21
|
specs:
|
22
|
-
activemodel (6.0.3.
|
23
|
-
activesupport (= 6.0.3.
|
24
|
-
activerecord (6.0.3.
|
25
|
-
activemodel (= 6.0.3.
|
26
|
-
activesupport (= 6.0.3.
|
27
|
-
activesupport (6.0.3.
|
22
|
+
activemodel (6.0.3.3)
|
23
|
+
activesupport (= 6.0.3.3)
|
24
|
+
activerecord (6.0.3.3)
|
25
|
+
activemodel (= 6.0.3.3)
|
26
|
+
activesupport (= 6.0.3.3)
|
27
|
+
activesupport (6.0.3.3)
|
28
28
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
29
|
i18n (>= 0.7, < 2)
|
30
30
|
minitest (~> 5.1)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
method_source (1.0.0)
|
45
45
|
mimemagic (0.3.5)
|
46
46
|
mini_portile2 (2.4.0)
|
47
|
-
minitest (5.14.
|
47
|
+
minitest (5.14.2)
|
48
48
|
mysql2 (0.5.3)
|
49
49
|
net-ssh (6.1.0)
|
50
50
|
net-ssh-gateway (2.0.0)
|
data/lib/arql/app.rb
CHANGED
@@ -4,7 +4,7 @@ module Arql
|
|
4
4
|
class App
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_accessor :log_io, :env, :prompt
|
7
|
+
attr_accessor :log_io, :env, :prompt, :instance
|
8
8
|
|
9
9
|
def config
|
10
10
|
@@effective_config
|
@@ -29,6 +29,7 @@ module Arql
|
|
29
29
|
Connection.open(connect_options)
|
30
30
|
@definition = Definition.new(effective_config)
|
31
31
|
load_initializer!
|
32
|
+
App.instance = self
|
32
33
|
end
|
33
34
|
|
34
35
|
def connect_options
|
data/lib/arql/definition.rb
CHANGED
@@ -87,7 +87,7 @@ module Arql
|
|
87
87
|
table_name.camelize.tap do |const_name|
|
88
88
|
const_name = 'Modul' if const_name == 'Module'
|
89
89
|
const_name = 'Clazz' if const_name == 'Class'
|
90
|
-
Class.new(
|
90
|
+
Class.new(::ArqlModel) do
|
91
91
|
include Arql::Extension
|
92
92
|
self.primary_key = pkey
|
93
93
|
self.table_name = table_name
|
@@ -124,6 +124,8 @@ module Arql
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
App.instance&.load_initializer!
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
@@ -131,12 +133,13 @@ module Arql
|
|
131
133
|
@@options = options
|
132
134
|
@@models = []
|
133
135
|
ActiveRecord::Base.connection.tap do |conn|
|
136
|
+
Object.const_set('ArqlModel', Class.new(ActiveRecord::Base) { self.abstract_class = true })
|
134
137
|
conn.tables.each do |table_name|
|
135
138
|
conn.primary_key(table_name).tap do |pkey|
|
136
139
|
table_name.camelize.tap do |const_name|
|
137
140
|
const_name = 'Modul' if const_name == 'Module'
|
138
141
|
const_name = 'Clazz' if const_name == 'Class'
|
139
|
-
Class.new(
|
142
|
+
Class.new(::ArqlModel) do
|
140
143
|
include Arql::Extension
|
141
144
|
self.primary_key = pkey
|
142
145
|
self.table_name = table_name
|
@@ -176,14 +179,18 @@ module Arql
|
|
176
179
|
end
|
177
180
|
|
178
181
|
::ActiveRecord::Relation.class_eval do
|
179
|
-
def t
|
180
|
-
records.t
|
182
|
+
def t(*attrs, **options)
|
183
|
+
records.t(*attrs, **options)
|
181
184
|
end
|
182
185
|
|
183
186
|
def v
|
184
187
|
records.v
|
185
188
|
end
|
186
189
|
|
190
|
+
def a
|
191
|
+
to_a
|
192
|
+
end
|
193
|
+
|
187
194
|
def write_csv(filename, *fields, **options)
|
188
195
|
records.write_csv(filename, *fields, **options)
|
189
196
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -13,8 +13,18 @@ class Array
|
|
13
13
|
end.join("\n")
|
14
14
|
end
|
15
15
|
|
16
|
-
def t(*attrs)
|
17
|
-
if attrs.present? && present? && first.is_a?(ActiveRecord::Base)
|
16
|
+
def t(*attrs, **options)
|
17
|
+
if (attrs.present? || options.present? && options[:except]) && present? && first.is_a?(ActiveRecord::Base)
|
18
|
+
column_names = first.attribute_names.map(&:to_sym)
|
19
|
+
attrs = attrs.flat_map { |e| e.is_a?(Regexp) ? column_names.grep(e) : e }.uniq
|
20
|
+
if options.present? && options[:except]
|
21
|
+
attrs = column_names if attrs.empty?
|
22
|
+
if options[:except].is_a?(Regexp)
|
23
|
+
attrs.reject! { |e| e =~ options[:except] }
|
24
|
+
else
|
25
|
+
attrs -= [options[:except]].flatten
|
26
|
+
end
|
27
|
+
end
|
18
28
|
puts Terminal::Table.new { |t|
|
19
29
|
t << attrs
|
20
30
|
t << :separator
|
data/lib/arql/ext/kernel.rb
CHANGED
@@ -99,7 +99,10 @@ module Kernel
|
|
99
99
|
def parse_excel(filename)
|
100
100
|
xlsx = Roo::Excelx.new(File.expand_path(filename))
|
101
101
|
xlsx.sheets.each_with_object({}) do |sheet_name, result|
|
102
|
-
|
102
|
+
begin
|
103
|
+
result[sheet_name] = xlsx.sheet(sheet_name).to_a
|
104
|
+
rescue
|
105
|
+
end
|
103
106
|
end
|
104
107
|
end
|
105
108
|
end
|
data/lib/arql/ext/object.rb
CHANGED
data/lib/arql/repl.rb
CHANGED
@@ -25,7 +25,7 @@ module Arql
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def prompt
|
28
|
-
[proc do |obj, nest_level,
|
28
|
+
[proc do |obj, nest_level, pry_instance|
|
29
29
|
if obj == main_object && nest_level == 0
|
30
30
|
nest_level_prompt = ''
|
31
31
|
else
|
@@ -35,7 +35,7 @@ module Arql
|
|
35
35
|
"(#{obj}:#{nest_level})"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
"%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow(App.prompt).yellow, Rainbow('❯').green]
|
38
|
+
"%s#{Rainbow('@').green}%s#{nest_level_prompt} [%d] %s " % [Rainbow('ARQL').red, Rainbow(App.prompt).yellow, pry_instance.input_ring.count, Rainbow('❯').green]
|
39
39
|
end]
|
40
40
|
end
|
41
41
|
end
|
data/lib/arql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|