caishu_model2 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/caishu_model2.gemspec +1 -1
- data/gc.rb +22 -0
- data/lib/caishu_model2/user.rb +30 -0
- data/lib/caishu_model2/version.rb +1 -1
- metadata +4 -5
- data/.gitignore +0 -17
- data/LICENSE.txt +0 -22
- data/lib/caishu_model2.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31d294b9797bd43427ef9f88d2d7ee5dfdd37ea2
|
4
|
+
data.tar.gz: fa8512d281b431c85e4b4a2804cd2448f7c0946d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f916ea0782cf9426c9b894f6140baa1f9603a96bf552342b2cf1a9aea58eba9254a54b3606387400bff084fa9c5432e3659dd9ae8c5ab852854f7b20075557
|
7
|
+
data.tar.gz: c99c2b7cc34ab974aaf40bf87fb4d78024aec3c6e9daa605a0d834c3c5ce01b6233d153b36d15bf242e00328472e8e56247d22c99e3cecf507f4ead41f9d9040
|
data/caishu_model2.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files =
|
16
|
+
spec.files = %w[gc.rb Gemfile Rakefile caishu_model2.gemspec README.md lib/caishu_model2/user.rb lib/caishu_model2/version.rb]
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
data/gc.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
gem 'activerecord', '3.2.17'
|
2
|
+
require 'active_record'
|
3
|
+
gem 'caishu_model','0.0.5'
|
4
|
+
require 'caishu_model'
|
5
|
+
|
6
|
+
# puts File.expand_path(__FILE__)
|
7
|
+
# puts File.dirname(__FILE__)+'/file2'
|
8
|
+
# puts File.join(File.dirname(__FILE__),'file2')
|
9
|
+
# puts File.expand_path('../lib/caishu_model/user.rb', __FILE__)
|
10
|
+
# require File.expand_path('../lib/caishu_model/user.rb', __FILE__)
|
11
|
+
|
12
|
+
|
13
|
+
ActiveRecord::Base.establish_connection(
|
14
|
+
adapter: 'mysql2',
|
15
|
+
pool: 5,
|
16
|
+
database: 'submeter_development',
|
17
|
+
username: 'root',
|
18
|
+
password: 'password'
|
19
|
+
)
|
20
|
+
|
21
|
+
# u = User.setTableName("3").first
|
22
|
+
p @user = User.setTableName(16).where(id: 16).first
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
class User < ActiveRecord::Base
|
3
|
+
|
4
|
+
def self.setTableName(key)
|
5
|
+
self.table_name = self.getTableName(key)
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.getTableName(key)
|
10
|
+
las = Zlib::crc32(key.to_s).to_i.to_s
|
11
|
+
return "users#{las[0]}"
|
12
|
+
end
|
13
|
+
|
14
|
+
before_save do |r|
|
15
|
+
unless r.id
|
16
|
+
r.id = User.next_id
|
17
|
+
end
|
18
|
+
r.class.table_name = User.getTableName(r.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
before_destroy do |r|
|
22
|
+
r.class.table_name = User.getTableName(r.id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.next_id
|
26
|
+
key = 'user_next_id'
|
27
|
+
REDIS.incr(key)
|
28
|
+
REDIS.get(key)
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caishu_model2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- menghuanwd
|
@@ -45,13 +45,12 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .
|
48
|
+
- gc.rb
|
49
49
|
- Gemfile
|
50
|
-
- LICENSE.txt
|
51
|
-
- README.md
|
52
50
|
- Rakefile
|
53
51
|
- caishu_model2.gemspec
|
54
|
-
-
|
52
|
+
- README.md
|
53
|
+
- lib/caishu_model2/user.rb
|
55
54
|
- lib/caishu_model2/version.rb
|
56
55
|
homepage: ''
|
57
56
|
licenses:
|
data/.gitignore
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 menghuanwd
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|