pg_space_cadet 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.md +20 -0
- data/README.md +100 -0
- data/lib/space_cadet_active_record_uuid.rb +46 -0
- data/lib/space_cadet_postgresql_hack.rb +18 -0
- data/lib/space_cadet_postgresql_uuid.rb +13 -0
- data/lib/space_cadet_uuid.rb +26 -0
- data/lib/space_cadet_uuid_id.rb +30 -0
- data/lib/space_cadet_wrapper.rb +19 -0
- data/pg_space_cadet.gemspec +37 -0
- data/spec/space_cadet_spec.rb +42 -0
- data/spec/space_cadet_uuid_id_spec.rb +33 -0
- data/spec/support/ar_rspec.rb +36 -0
- data/spec/support/no_should_rspec.rb +9 -0
- data/spec/support/space_cadet.rb +68 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Bardi Einarsson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
pg\_space\_cadet
|
2
|
+
================
|
3
|
+
|
4
|
+
## Summary
|
5
|
+
|
6
|
+
for space cadet augmented ActiveRecord::Base's, ruby ObjectSpace like object\_id's as default ActiveRecord id's based on UUID's
|
7
|
+
|
8
|
+
## Description
|
9
|
+
|
10
|
+
pg\_space\_cadet is a simple hack for postgreSQL and ActiveRecord which provides a uuids table of distributable identities of space cadets -- ActiveRecord::Base instances which use the SpaceCadetWrapper. Each space cadet has a default ActiveRecord id unique in the set of all local space cadets; a space cadet's id is derived from its uuid - UUID's are by design universally distributable.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Note that the version 0.7.2 gem is tested but experimental -- a proof of concept. (It does not use the postgres native uuid type yet. It has not been established whether or not the dependence on the postgreSQL setval function is practical for a production database.)
|
15
|
+
|
16
|
+
require 'space_cadet_wrapper'
|
17
|
+
|
18
|
+
class ChessGame < ActiveRecord::Base
|
19
|
+
|
20
|
+
before_create SpaceCadetWrapper.new
|
21
|
+
before_destroy SpaceCadetWrapper.new # optional
|
22
|
+
...
|
23
|
+
|
24
|
+
end # ChessGame
|
25
|
+
|
26
|
+
class MySpaceCadet < ActiveRecord::Base
|
27
|
+
|
28
|
+
before_create SpaceCadetWrapper.new
|
29
|
+
before_destroy SpaceCadetWrapper.new # optional
|
30
|
+
...
|
31
|
+
|
32
|
+
end # MySpaceCadet
|
33
|
+
|
34
|
+
ChessGame instances are space cadets.
|
35
|
+
|
36
|
+
Before ActiveRecord creates a ChessGame space cadet, it uses postgreSQL's uuid\_generate\_v4 to create a UUID. The lowest 31 bits of the UUID are used to make a shared ActiveRecord default id.
|
37
|
+
|
38
|
+
The uuids table gains a chess\_games row as in:
|
39
|
+
id source_name uuid
|
40
|
+
746042992 my_space_cadets 7770a54c-7f08-4817-877e-43e1ac77b670
|
41
|
+
569967860 chess_games 274ead56-7c8f-4c8d-ad21-35d4a1f904f4
|
42
|
+
The chess\_games table gains a row like:
|
43
|
+
id moves ambiguities move_number ...
|
44
|
+
569967860 e2e4 1 ...
|
45
|
+
|
46
|
+
569967860 == 0x21f904f4 # the 31 low order bits of the UUID
|
47
|
+
|
48
|
+
The (setval) hack, used to force the id's to be the same, uses postgreSQL's setval on the uuids\_id\_seq and the chess\_games\_id\_seq sequences so that ActiveRecord uses (is tricked into using) the 569967860 value as the next id in both tables.
|
49
|
+
|
50
|
+
The result is that id 569967860 is guaranteed to be unique for all space cadets i.e. ChessGame instances, MySpaceCadet instances and other space cadets. Note in the rare event that there is a duplicate id conflict in uuids, a new UUID is tried.
|
51
|
+
|
52
|
+
my_space_cadet = ... # created MySpaceCadet instance
|
53
|
+
uuid = SpaceCadet::Uuid.find(my_space_cadet.id) # my_space_cadet's uuid
|
54
|
+
|
55
|
+
space_cadet_ref = SpaceCadet::Uuid.find_by_uuid(
|
56
|
+
'274ead56-7c8f-4c8d-ad21-35d4a1f904f4')
|
57
|
+
space_cadet_id = space_cadet_ref.id # 569967860
|
58
|
+
space_cadet_source_name = space_cadet_ref.source_name # 'chess_games'
|
59
|
+
chess_game_class = <some function> space_cadet_source_name
|
60
|
+
chess_game = chess_game_class.find(space_cadet_id)
|
61
|
+
'e2e4' == chess_game.moves # true
|
62
|
+
|
63
|
+
## Requirements
|
64
|
+
|
65
|
+
Most likely any recent version of 1.9 ruby works.
|
66
|
+
|
67
|
+
Most likely any version of the pg gem that understands setval for sequences and uuid\_generate\_v4 (after create extension "uuid-ossp") works.
|
68
|
+
|
69
|
+
Most likely any version of the activerecord gem which can use the given pg gem and can be used with require "active\_record" works.
|
70
|
+
|
71
|
+
TODO: JRuby postgreSQL space\_cadets - should be simple
|
72
|
+
|
73
|
+
## Test with rspec ~> 2.11, rspec -fd
|
74
|
+
|
75
|
+
The specs assume that the connection url in spec/support/space\_cadet.rb works.
|
76
|
+
|
77
|
+
The specs assume that the uuids table exists in the postgreSQL database.
|
78
|
+
|
79
|
+
The specs assume that the chess\_games table exists in the postgreSQL database.
|
80
|
+
|
81
|
+
The specs do not update the database (transactions with rollback).
|
82
|
+
|
83
|
+
Note, to prepare the database for testing:
|
84
|
+
irb prompt> load 'spec/support/space_cadet.rb'
|
85
|
+
irb prompt> up
|
86
|
+
irb prompt> exit
|
87
|
+
|
88
|
+
The author uses DbVisualizer 9.0.5 and irb to try out the space cadets.
|
89
|
+
|
90
|
+
Note, to find the gem installation directory:
|
91
|
+
irb prompt> require 'space_cadet_wrapper'
|
92
|
+
irb prompt> $".grep(/pg_space_cadet/)[0]
|
93
|
+
irb prompt> exit
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
Copyright (c) 2013 Bardi Einarsson. Released under the MIT License. See the [LICENSE][license] file for further details.
|
98
|
+
|
99
|
+
[license]: https://github.com/bardibardi/pg_space_cadet/blob/master/LICENSE.md
|
100
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# needs
|
2
|
+
# set_auto_increment conn, source_name, id
|
3
|
+
# uuid = new_uuid conn
|
4
|
+
# id = id_from_uuid uuid, id_bit_count
|
5
|
+
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
module SpaceCadetActiveRecordUuid
|
9
|
+
|
10
|
+
def add_uuid uuid_class, source_name, id, uuid
|
11
|
+
conn = uuid_class.connection
|
12
|
+
table_name = uuid_class.table_name
|
13
|
+
set_auto_increment conn, table_name, id
|
14
|
+
uuid_class.create! do |u|
|
15
|
+
u.source_name = source_name
|
16
|
+
u.uuid = uuid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def id_add_uuid uuid_class, source_name, id_bit_count
|
21
|
+
conn = uuid_class.connection
|
22
|
+
uuid = new_uuid conn
|
23
|
+
id = id_from_uuid uuid, id_bit_count
|
24
|
+
record = nil
|
25
|
+
begin
|
26
|
+
record = add_uuid uuid_class, source_name, id, uuid
|
27
|
+
rescue
|
28
|
+
record = nil
|
29
|
+
end
|
30
|
+
record
|
31
|
+
end
|
32
|
+
|
33
|
+
ID_RETRY_COUNT = 10
|
34
|
+
|
35
|
+
def prepare_create uuid_class, source_name, id_bit_count
|
36
|
+
record = nil
|
37
|
+
retry_count = 0
|
38
|
+
while !record && retry_count < ID_RETRY_COUNT do
|
39
|
+
record = id_add_uuid uuid_class, source_name, id_bit_count
|
40
|
+
end
|
41
|
+
conn = record.class.connection
|
42
|
+
set_auto_increment conn, source_name, record.id
|
43
|
+
end
|
44
|
+
|
45
|
+
end # SpaceCadetActiveRecordUuid
|
46
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# require 'securerandom'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module SpaceCadetPostgresqlHack
|
5
|
+
|
6
|
+
def set_auto_increment conn, table_name, id
|
7
|
+
primary_id_seq = table_name + '_id_seq'
|
8
|
+
conn.execute("select setval('#{primary_id_seq}', #{id - 1});")
|
9
|
+
end
|
10
|
+
|
11
|
+
# create extension "uuid-ossp"
|
12
|
+
def new_uuid conn
|
13
|
+
conn.execute("select uuid_generate_v4() as u")[0]['u']
|
14
|
+
# SecureRandom.uuid
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'space_cadet_uuid'
|
2
|
+
require_relative 'space_cadet_uuid_id'
|
3
|
+
require_relative 'space_cadet_postgresql_hack'
|
4
|
+
require_relative 'space_cadet_active_record_uuid'
|
5
|
+
|
6
|
+
module SpaceCadetUuid
|
7
|
+
|
8
|
+
include SpaceCadetUuidId
|
9
|
+
include SpaceCadetPostgresqlHack
|
10
|
+
include SpaceCadetActiveRecordUuid
|
11
|
+
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module SpaceCadet
|
4
|
+
|
5
|
+
class UuidCore < ActiveRecord::Migration
|
6
|
+
|
7
|
+
def self.up
|
8
|
+
create_table :uuids do |t|
|
9
|
+
t.string :source_name
|
10
|
+
t.string :uuid
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :uuids, :uuid, unique: true
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :uuids
|
18
|
+
end
|
19
|
+
|
20
|
+
end # UuidCore
|
21
|
+
|
22
|
+
class Uuid < ActiveRecord::Base
|
23
|
+
end # Uuid
|
24
|
+
|
25
|
+
end # SpaceCadet
|
26
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SpaceCadetUuidId
|
2
|
+
|
3
|
+
HEX_DIGIT ||= Hash[
|
4
|
+
'0', 0, '1', 1, '2', 2, '3', 3,
|
5
|
+
'4', 4, '5', 5, '6', 6, '7', 7,
|
6
|
+
'8', 8, '9', 9, 'a', 10, 'b', 11,
|
7
|
+
'c', 12, 'd', 13, 'e', 14, 'f', 15
|
8
|
+
].reduce({}, &->(h,p){h[p[0].getbyte(0)] = p[1];h})
|
9
|
+
def num_from_hex_string hex_string
|
10
|
+
hex_string.bytes.reduce(0, &->(num,b){num <<= 4;num += HEX_DIGIT[b]})
|
11
|
+
end
|
12
|
+
|
13
|
+
def high_order_bits_from_hex_string hex_string, bit_count
|
14
|
+
total_bit_count = hex_string.length << 2
|
15
|
+
num = num_from_hex_string hex_string
|
16
|
+
num >> (total_bit_count - bit_count)
|
17
|
+
end
|
18
|
+
|
19
|
+
def low_order_bits_from_hex_string hex_string, bit_count
|
20
|
+
num = num_from_hex_string hex_string
|
21
|
+
num & ((1 << bit_count) - 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
def id_from_uuid uuid, id_bit_count
|
25
|
+
hex_string = uuid[24..-1]
|
26
|
+
low_order_bits_from_hex_string hex_string, id_bit_count
|
27
|
+
end
|
28
|
+
|
29
|
+
end # SpaceCadetUuidId
|
30
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'space_cadet_postgresql_uuid'
|
2
|
+
|
3
|
+
class SpaceCadetWrapper
|
4
|
+
|
5
|
+
include SpaceCadetUuid
|
6
|
+
|
7
|
+
ID_BIT_COUNT = 31
|
8
|
+
|
9
|
+
def before_create record
|
10
|
+
source_name = record.class.table_name
|
11
|
+
prepare_create SpaceCadet::Uuid, source_name, ID_BIT_COUNT
|
12
|
+
end
|
13
|
+
|
14
|
+
def before_destroy record
|
15
|
+
SpaceCadet::Uuid.delete record.id
|
16
|
+
end
|
17
|
+
|
18
|
+
end # SpaceCadetWrapper
|
19
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'pg_space_cadet'
|
3
|
+
s.version = '0.7.2'
|
4
|
+
s.date = '2013-03-21'
|
5
|
+
s.summary = "for space cadet augmented ActiveRecord::Base's, ruby ObjectSpace like object_id's as default ActiveRecord id's based on UUID's"
|
6
|
+
s.description = "pg_space_cadet is a simple hack for postgreSQL and ActiveRecord which provides a uuids table of distributable identities of space cadets -- ActiveRecord::Base instances which use the SpaceCadetWrapper. Each space cadet has a default ActiveRecord id unique in the set of all local space cadets; a space cadet's id is derived from its uuid - UUID's are by design universally distributable."
|
7
|
+
|
8
|
+
s.authors = ['Bardi Einarsson']
|
9
|
+
s.email = ['bardi@hotmail.com']
|
10
|
+
s.homepage = 'https://github.com/bardibardi/pg_space_cadet'
|
11
|
+
s.required_ruby_version = '>= 1.9.2'
|
12
|
+
s.add_dependency('pg')
|
13
|
+
s.add_dependency('activerecord', '>= 3.0')
|
14
|
+
s.add_development_dependency('rspec', '~> 2.11')
|
15
|
+
s.requirements << 'most likely any version of the pg gem that understands setval for sequences and uuid_generate_v4 (after create extension "uuid-ossp")'
|
16
|
+
s.requirements << 'most likely any version of the activerecord gem which can use the given pg gem and can be used with require "active_record"'
|
17
|
+
|
18
|
+
s.files = %w(
|
19
|
+
.gitignore
|
20
|
+
Gemfile
|
21
|
+
LICENSE.md
|
22
|
+
README.md
|
23
|
+
pg_space_cadet.gemspec
|
24
|
+
lib/space_cadet_active_record_uuid.rb
|
25
|
+
lib/space_cadet_postgresql_hack.rb
|
26
|
+
lib/space_cadet_postgresql_uuid.rb
|
27
|
+
lib/space_cadet_uuid.rb
|
28
|
+
lib/space_cadet_uuid_id.rb
|
29
|
+
lib/space_cadet_wrapper.rb
|
30
|
+
spec/space_cadet_spec.rb
|
31
|
+
spec/space_cadet_uuid_id_spec.rb
|
32
|
+
spec/support/ar_rspec.rb
|
33
|
+
spec/support/no_should_rspec.rb
|
34
|
+
spec/support/space_cadet.rb
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'support/ar_rspec'
|
2
|
+
require_relative 'support/space_cadet'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
describe SpaceCadet::Uuid do
|
6
|
+
|
7
|
+
it "should be created" do
|
8
|
+
id, _ = add_chess_game 'e2e4', ''
|
9
|
+
u = SpaceCadet::Uuid.find(id)
|
10
|
+
expect(id).to eq(u.id)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be unique" do
|
14
|
+
duplicate_id, chess_game = add_chess_game 'e2e4', ''
|
15
|
+
u = SpaceCadet::Uuid.find(duplicate_id)
|
16
|
+
duplicate_uuid = u.uuid
|
17
|
+
exception_thrown = nil
|
18
|
+
begin
|
19
|
+
chess_game.add_uuid(SpaceCadet::Uuid.class,
|
20
|
+
'chess_games', duplicate_id, duplicate_uuid)
|
21
|
+
rescue
|
22
|
+
exception_thrown = true
|
23
|
+
end
|
24
|
+
expect(exception_thrown).to eq(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be deleted when parent is destroyed" do
|
28
|
+
id, chess_game = add_chess_game 'e2e4', ''
|
29
|
+
u = SpaceCadet::Uuid.find(id)
|
30
|
+
expect(id).to eq(u.id)
|
31
|
+
chess_game.class.destroy(id)
|
32
|
+
exception_thrown = nil
|
33
|
+
begin
|
34
|
+
u = SpaceCadet::Uuid.find(id)
|
35
|
+
rescue
|
36
|
+
exception_thrown = true
|
37
|
+
end
|
38
|
+
expect(exception_thrown).to eq(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'support/no_should_rspec'
|
2
|
+
require 'space_cadet_uuid_id'
|
3
|
+
|
4
|
+
$idcalc = Object.new.extend SpaceCadetUuidId
|
5
|
+
|
6
|
+
describe SpaceCadetUuidId do
|
7
|
+
|
8
|
+
it "should convert hex chars to digits" do
|
9
|
+
digits = "abcef" * 10
|
10
|
+
eval_value = eval("0x" + digits)
|
11
|
+
value = $idcalc.num_from_hex_string digits
|
12
|
+
expect(value).to eq(eval_value)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get high order bits" do
|
16
|
+
digits = "abcef" * 10
|
17
|
+
value = $idcalc.high_order_bits_from_hex_string digits, 3
|
18
|
+
expect(value).to eq(5)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should get low order bits" do
|
22
|
+
digits = "abcef" * 10
|
23
|
+
value = $idcalc.low_order_bits_from_hex_string digits, 3
|
24
|
+
expect(value).to eq(7)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get uuid low order bits" do
|
28
|
+
uuid = "ef53c3f1-9c4f-46db-9f6c-02c7402ef24a"
|
29
|
+
value = $idcalc.id_from_uuid uuid, 3
|
30
|
+
expect(value).to eq(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# NB: http://iain.nl/testing-activerecord-in-isolation
|
2
|
+
# NB: require 'support/ar_rspec'
|
3
|
+
require_relative 'no_should_rspec'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# Extension to enhance `should have` on AR Model instances. Calls
|
8
|
+
# model.valid? in order to prepare the object's errors object.
|
9
|
+
#
|
10
|
+
# You can also use this to specify the content of the error messages.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# model.should have(:no).errors_on(:attribute)
|
15
|
+
# model.should have(1).error_on(:attribute)
|
16
|
+
# model.should have(n).errors_on(:attribute)
|
17
|
+
#
|
18
|
+
# model.errors_on(:attribute).should include("can't be blank")
|
19
|
+
def errors_on(attribute)
|
20
|
+
self.valid?
|
21
|
+
[self.errors[attribute]].flatten.compact
|
22
|
+
end
|
23
|
+
alias :error_on :errors_on
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
|
28
|
+
config.around do |example|
|
29
|
+
ActiveRecord::Base.transaction do
|
30
|
+
example.run
|
31
|
+
raise ActiveRecord::Rollback
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
def l
|
2
|
+
me = File.expand_path File.basename(__FILE__), File.dirname(__FILE__)
|
3
|
+
result = load me
|
4
|
+
[result, me]
|
5
|
+
end
|
6
|
+
|
7
|
+
require_relative '../../lib/space_cadet_wrapper'
|
8
|
+
|
9
|
+
POSTGRESQL_URL ||= "postgres://postgres:postgres@localhost/postgres"
|
10
|
+
|
11
|
+
CONNECTION_POOL ||= ActiveRecord::Base.establish_connection POSTGRESQL_URL
|
12
|
+
|
13
|
+
END { CONNECTION_POOL.disconnect! }
|
14
|
+
|
15
|
+
class ChessGameCore < ActiveRecord::Migration
|
16
|
+
|
17
|
+
def self.up
|
18
|
+
create_table :chess_games do |t|
|
19
|
+
t.string :moves
|
20
|
+
t.string :ambiguities
|
21
|
+
t.integer :move_number
|
22
|
+
t.integer :is_whites_move
|
23
|
+
t.string :position
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
drop_table :chess_games
|
29
|
+
end
|
30
|
+
|
31
|
+
end # ChessGameCore
|
32
|
+
|
33
|
+
class ChessGame < ActiveRecord::Base
|
34
|
+
|
35
|
+
before_create SpaceCadetWrapper.new
|
36
|
+
before_destroy SpaceCadetWrapper.new
|
37
|
+
|
38
|
+
end # ChessGame
|
39
|
+
|
40
|
+
START_POSITION ||=
|
41
|
+
"a8brb8bnc8bbd8bqe8bkf8bbg8bnh8br" +
|
42
|
+
"a7bpb7bpc7bpd7bpe7bpf7bpg7bph7bp" +
|
43
|
+
"a2wpb2wpc2wpd2wpe2wpf2wpg2wph2wp" +
|
44
|
+
"a1wrb1wnc1wbd1wqe1wkf1wbg1wnh1wr"
|
45
|
+
|
46
|
+
def add_chess_game moves, ambiguities
|
47
|
+
record = nil
|
48
|
+
ChessGame.create! do |g|
|
49
|
+
g.moves = moves
|
50
|
+
g.ambiguities = ambiguities
|
51
|
+
g.move_number = 1
|
52
|
+
g.is_whites_move = 1
|
53
|
+
g.position = START_POSITION
|
54
|
+
record = g
|
55
|
+
end
|
56
|
+
[record.id, record]
|
57
|
+
end
|
58
|
+
|
59
|
+
def up
|
60
|
+
SpaceCadet::UuidCore.up
|
61
|
+
ChessGameCore.up
|
62
|
+
end
|
63
|
+
|
64
|
+
def down
|
65
|
+
ChessGameCore.down
|
66
|
+
SpaceCadet::UuidCore.down
|
67
|
+
end
|
68
|
+
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pg_space_cadet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bardi Einarsson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pg
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.11'
|
62
|
+
description: pg_space_cadet is a simple hack for postgreSQL and ActiveRecord which
|
63
|
+
provides a uuids table of distributable identities of space cadets -- ActiveRecord::Base
|
64
|
+
instances which use the SpaceCadetWrapper. Each space cadet has a default ActiveRecord
|
65
|
+
id unique in the set of all local space cadets; a space cadet's id is derived from
|
66
|
+
its uuid - UUID's are by design universally distributable.
|
67
|
+
email:
|
68
|
+
- bardi@hotmail.com
|
69
|
+
executables: []
|
70
|
+
extensions: []
|
71
|
+
extra_rdoc_files: []
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- LICENSE.md
|
76
|
+
- README.md
|
77
|
+
- pg_space_cadet.gemspec
|
78
|
+
- lib/space_cadet_active_record_uuid.rb
|
79
|
+
- lib/space_cadet_postgresql_hack.rb
|
80
|
+
- lib/space_cadet_postgresql_uuid.rb
|
81
|
+
- lib/space_cadet_uuid.rb
|
82
|
+
- lib/space_cadet_uuid_id.rb
|
83
|
+
- lib/space_cadet_wrapper.rb
|
84
|
+
- spec/space_cadet_spec.rb
|
85
|
+
- spec/space_cadet_uuid_id_spec.rb
|
86
|
+
- spec/support/ar_rspec.rb
|
87
|
+
- spec/support/no_should_rspec.rb
|
88
|
+
- spec/support/space_cadet.rb
|
89
|
+
homepage: https://github.com/bardibardi/pg_space_cadet
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.9.2
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements:
|
108
|
+
- most likely any version of the pg gem that understands setval for sequences and
|
109
|
+
uuid_generate_v4 (after create extension "uuid-ossp")
|
110
|
+
- most likely any version of the activerecord gem which can use the given pg gem and
|
111
|
+
can be used with require "active_record"
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.25
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: for space cadet augmented ActiveRecord::Base's, ruby ObjectSpace like object_id's
|
117
|
+
as default ActiveRecord id's based on UUID's
|
118
|
+
test_files: []
|