arql 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/arql/commands/reconnect.rb +13 -0
- data/lib/arql/commands/redefine.rb +15 -0
- data/lib/arql/commands.rb +2 -0
- data/lib/arql/definition.rb +54 -1
- data/lib/arql/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f18ea311aeb3c4f976d97c1b457c8eebefa9226637f80d7bfd0d7ef288099e
|
4
|
+
data.tar.gz: 78aaa74f7d64934fb047c012cda6fc8c67904de55bb69db0499569d3973b8388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dded93fc5d32b2d4f28c8270b7c106f9da5a6d187ad53ca3a35d315f24d17dd44dc573cf5125d15d6f9bbad8dceb248944cf68e876398d0eeb1c62fd3d099ce5
|
7
|
+
data.tar.gz: 24c97fdb85051959783e89dd156b3361940bc6b8c7bee6752c322b9f63d3c177f5667387f588215f911d3d3a86284127cd40158a1e80e70b2e7e0f4fb87f86d2
|
data/Gemfile.lock
CHANGED
data/lib/arql/commands.rb
CHANGED
data/lib/arql/definition.rb
CHANGED
@@ -47,7 +47,7 @@ module Arql
|
|
47
47
|
|
48
48
|
def to_sql(records, on_duplicate, batch_size)
|
49
49
|
records.in_groups_of(batch_size, false).map do |group|
|
50
|
-
|
50
|
+
ActiveRecord::InsertAll.new(self, group.map(&:attributes), on_duplicate: on_duplicate).send(:to_sql) + ';'
|
51
51
|
end.join("\n")
|
52
52
|
end
|
53
53
|
end
|
@@ -58,9 +58,62 @@ module Arql
|
|
58
58
|
def models
|
59
59
|
@@models ||= []
|
60
60
|
end
|
61
|
+
|
62
|
+
def redefine
|
63
|
+
options = @@options
|
64
|
+
@@models.each do |model|
|
65
|
+
Object.send :remove_const, model[:model].name.to_sym if model[:model]
|
66
|
+
Object.send :remove_const, model[:abbr].to_sym if model[:abbr]
|
67
|
+
end
|
68
|
+
@@models = []
|
69
|
+
ActiveRecord::Base.connection.tap do |conn|
|
70
|
+
conn.tables.each do |table_name|
|
71
|
+
conn.primary_key(table_name).tap do |pkey|
|
72
|
+
table_name.camelize.tap do |const_name|
|
73
|
+
const_name = 'Modul' if const_name == 'Module'
|
74
|
+
const_name = 'Clazz' if const_name == 'Class'
|
75
|
+
Class.new(ActiveRecord::Base) do
|
76
|
+
include Arql::Extension
|
77
|
+
self.primary_key = pkey
|
78
|
+
self.table_name = table_name
|
79
|
+
self.inheritance_column = nil
|
80
|
+
self.default_timezone = :local
|
81
|
+
if options[:created_at].present?
|
82
|
+
define_singleton_method :timestamp_attributes_for_create do
|
83
|
+
options[:created_at]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if options[:updated_at].present?
|
88
|
+
define_singleton_method :timestamp_attributes_for_update do
|
89
|
+
options[:updated_at]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end.tap do |clazz|
|
93
|
+
Object.const_set(const_name, clazz).tap do |const|
|
94
|
+
const_name.gsub(/[a-z]*/, '').tap do |abbr|
|
95
|
+
unless Object.const_defined?(abbr)
|
96
|
+
Object.const_set abbr, const
|
97
|
+
abbr_const = abbr
|
98
|
+
end
|
99
|
+
|
100
|
+
@@models << {
|
101
|
+
model: const,
|
102
|
+
abbr: abbr_const,
|
103
|
+
table: table_name
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
61
113
|
end
|
62
114
|
|
63
115
|
def initialize(options)
|
116
|
+
@@options = options
|
64
117
|
@@models = []
|
65
118
|
ActiveRecord::Base.connection.tap do |conn|
|
66
119
|
conn.tables.each do |table_name|
|
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.1.
|
4
|
+
version: 0.1.15
|
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-05-
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -175,6 +175,8 @@ files:
|
|
175
175
|
- lib/arql/commands.rb
|
176
176
|
- lib/arql/commands/info.rb
|
177
177
|
- lib/arql/commands/models.rb
|
178
|
+
- lib/arql/commands/reconnect.rb
|
179
|
+
- lib/arql/commands/redefine.rb
|
178
180
|
- lib/arql/commands/table.rb
|
179
181
|
- lib/arql/connection.rb
|
180
182
|
- lib/arql/definition.rb
|