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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44dc8e634d413b6c736c6335ce19feeb4f9b927bd5f61f8697e9102e16ce79e4
4
- data.tar.gz: 1202b099108a83827a851e594c3511e078f6af61d3b901106e193c0a7a42c6ec
3
+ metadata.gz: 032762276fe5d2c764f71eae665d16e2e4786368c7f154e7bd19be5188a49027
4
+ data.tar.gz: 73b8ceedbcd0abdc5c87c186374c8cfe0db50e0c22d1e645d2c10396ec8c4aa3
5
5
  SHA512:
6
- metadata.gz: 48233713c1b9364591a0d7d782181a9484976242fd7361927e2d8d30f5f0104e4a860a1c66bb7575da6d6e46f7294324e1c8d633fa1285e37bcf1470fe716e0b
7
- data.tar.gz: 7877f7dd188f9f4c3b99d049a0b4b64f0e1b71e5c5daece18fabf107d26df3a69f8bf8170549430f48e300582b8660c2a23ba4e59aa69b6561d762670e3d3c4b
6
+ metadata.gz: cc70e4f11ff7bcfc4f0654d8a3e59ac2ae666e55237dff7d62e408c3c6bba200b22f3e064ea17dc513a94bbd4eacefa8f369d4d79c24d9a9ada857efa00c58af
7
+ data.tar.gz: 34491bfc5588a4bae89f26f889c5863e700f79b926902bb769c3e122082342706252fc41bcf461244bfc82e8f5a5e7dbf1eb4bd3c43d726f1d9fb9f5164170b0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.2.0)
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.2)
23
- activesupport (= 6.0.3.2)
24
- activerecord (6.0.3.2)
25
- activemodel (= 6.0.3.2)
26
- activesupport (= 6.0.3.2)
27
- activesupport (6.0.3.2)
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.1)
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)
@@ -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
@@ -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(ActiveRecord::Base) do
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(ActiveRecord::Base) do
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
@@ -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
@@ -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
- result[sheet_name] = xlsx.sheet(sheet_name).to_a
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
@@ -15,4 +15,8 @@ class Object
15
15
  def jjp
16
16
  puts jj
17
17
  end
18
+
19
+ def a
20
+ [self]
21
+ end
18
22
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.5"
3
3
  end
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.0
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-08-31 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2