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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7d2f139259437c81fa94b89b805ad25ff853d15
4
- data.tar.gz: 958528ced0ffc227465f4dab629b90db7f2d3a55
3
+ metadata.gz: 31d294b9797bd43427ef9f88d2d7ee5dfdd37ea2
4
+ data.tar.gz: fa8512d281b431c85e4b4a2804cd2448f7c0946d
5
5
  SHA512:
6
- metadata.gz: 7e5cba7de33072ce2a0d487819b2abae0f1f8ff4a2b90648771a49fa57fca433fec0341661f80c9eef4446f7f6324d844dc25ccafc49bf5966ae2e0f5a72f7d2
7
- data.tar.gz: 0df6b4e8b0f0a1c768bcd78c3ded0e18abaccb218bc84ea19fc32e6eaae1d7a1473437a5177943ae111d055aaca95701db1e3dbb4406de95ef84bc0b0131b84d
6
+ metadata.gz: 55f916ea0782cf9426c9b894f6140baa1f9603a96bf552342b2cf1a9aea58eba9254a54b3606387400bff084fa9c5432e3659dd9ae8c5ab852854f7b20075557
7
+ data.tar.gz: c99c2b7cc34ab974aaf40bf87fb4d78024aec3c6e9daa605a0d834c3c5ce01b6233d153b36d15bf242e00328472e8e56247d22c99e3cecf507f4ead41f9d9040
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
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
@@ -1,3 +1,3 @@
1
1
  module CaishuModel2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
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
- - .gitignore
48
+ - gc.rb
49
49
  - Gemfile
50
- - LICENSE.txt
51
- - README.md
52
50
  - Rakefile
53
51
  - caishu_model2.gemspec
54
- - lib/caishu_model2.rb
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
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
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.
data/lib/caishu_model2.rb DELETED
@@ -1,5 +0,0 @@
1
- require "caishu_model2/version"
2
-
3
- module CaishuModel2
4
- # Your code goes here...
5
- end