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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4be814ce4270be283559e44a692760d2769e079176a671d578168332d5b1946
4
- data.tar.gz: 7f8308799c104ed2fdc5ee8bb56fe479b4812c2d626ed896451305ed5dc9da57
3
+ metadata.gz: a5f18ea311aeb3c4f976d97c1b457c8eebefa9226637f80d7bfd0d7ef288099e
4
+ data.tar.gz: 78aaa74f7d64934fb047c012cda6fc8c67904de55bb69db0499569d3973b8388
5
5
  SHA512:
6
- metadata.gz: 06b7cb69df3cf46e2e670be55f43fd205f98697bcae382f6681c84d32bfd92e9ed072a1c696916f9a6da182581bb79c0d93c49c43d6563ffc304daf893bea651
7
- data.tar.gz: 919b7b79693911a6722c5071ed7afa6378c8f8443fef60df011c5ac476153d86610b81ab828ad6088829685a17ad728e809a972bac3973961484a9f1f9989041
6
+ metadata.gz: dded93fc5d32b2d4f28c8270b7c106f9da5a6d187ad53ca3a35d315f24d17dd44dc573cf5125d15d6f9bbad8dceb248944cf68e876398d0eeb1c62fd3d099ce5
7
+ data.tar.gz: 24c97fdb85051959783e89dd156b3361940bc6b8c7bee6752c322b9f63d3c177f5667387f588215f911d3d3a86284127cd40158a1e80e70b2e7e0f4fb87f86d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.14)
4
+ arql (0.1.15)
5
5
  activerecord (~> 6.0.3)
6
6
  activesupport (~> 6.0.3)
7
7
  mysql2 (~> 0.5.3)
@@ -0,0 +1,13 @@
1
+ module Arql::Commands
2
+ module Reconnect
3
+ class << self
4
+ def reconnect
5
+ ActiveRecord::Base.connection.reconnect!
6
+ end
7
+ end
8
+
9
+ Pry.commands.block_command 'reconnect' do
10
+ Reconnect.reconnect
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Arql::Commands
2
+ module Redefine
3
+ class << self
4
+ def redefine
5
+ Arql::Definition.redefine
6
+ end
7
+ end
8
+
9
+ Pry.commands.block_command 'redefine' do
10
+ Redefine.redefine
11
+ end
12
+
13
+ Pry.commands.alias_command 'redef', 'redefine'
14
+ end
15
+ end
data/lib/arql/commands.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'arql/commands/info'
2
2
  require 'arql/commands/models'
3
3
  require 'arql/commands/table'
4
+ require 'arql/commands/reconnect'
5
+ require 'arql/commands/redefine'
4
6
 
5
7
  module Arql::Commands
6
8
  end
@@ -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
- ActiveRecord::InsertAll.new(self, group.map(&:attributes), on_duplicate: on_duplicate).send(:to_sql) + ';'
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
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
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.1.14
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-12 00:00:00.000000000 Z
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