acts_as_uuid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in acts_as_uuid.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ActsAsUUID
2
+
3
+ Adds (native) UUID support, including support for primary keys and associations , to your ActiveRecord models. Currently only supports PostgreSQL.
4
+
5
+ Inspired by https://github.com/jashmenn/activeuuid and the lack of PostgreSQL gems that worked.
6
+
7
+ ## Installation
8
+
9
+ Add this to your `Gemfile`:
10
+
11
+ `gem "acts_as_uuid"`
12
+
13
+ You can now set the type `uuid` for any attribute in your models.
14
+
15
+ ## Example: Adding a UUID primary key to your models
16
+
17
+ ### Step 1a: For new models
18
+
19
+ ```ruby
20
+ class AddUUIDPrimaryKeyToEmail < ActiveRecord::Migration
21
+ def self.change
22
+ create_table :emails, :id => false do |t|
23
+ t.uuid :id, :unique => true
24
+ end
25
+ add_index :emails, :id
26
+ end
27
+ end
28
+ ```
29
+
30
+ ### Step 1b: Migrating existing models
31
+
32
+ For existing models just add:
33
+
34
+ ```ruby
35
+ class AddUUIDPrimaryKeyToEmail < ActiveRecord::Migration
36
+ def self.change
37
+ remove_column :emails, :id
38
+ add_column :emails, :id, :uuid
39
+ add_index :emails, :id
40
+ end
41
+ end
42
+ ```
43
+ Keep in mind that after this all your UUIDs will be set to nil.
44
+
45
+ ### Step 2: Extend your model
46
+
47
+ ```ruby
48
+ class Email < ActiveRecord::Base
49
+ include ActsAsUUID
50
+ end
51
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "acts_as_uuid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "acts_as_uuid"
7
+ s.version = ActsAsUuid::VERSION
8
+ s.authors = ["Cristiano Betta"]
9
+ s.email = ["cristiano@emberads.com"]
10
+ s.homepage = "https://github.com/EmberAds/acts_as_uuid"
11
+ s.summary = %q{Allows ActiveRecord to use (native) UUIDs }
12
+ s.description = %q{Allows ActiveRecord to use (native) UUIDs, even as primary keys. Currently only works with PostgreSQL. }
13
+
14
+ s.rubyforge_project = "acts_as_uuid"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "uuid"
24
+ end
@@ -0,0 +1,6 @@
1
+ require "acts_as_uuid/version"
2
+
3
+ module ActsAsUuid
4
+ require "acts_as_uuid/railtie" if defined?(Rails)
5
+ require "acts_as_uuid/acts_as_uuid"
6
+ end
@@ -0,0 +1,11 @@
1
+ module ActsAsUUID
2
+ def self.included klass
3
+ klass.before_create :generate_uuid
4
+ klass.validates :id, :uniqueness => true
5
+ klass.primary_key = :id
6
+ end
7
+
8
+ def generate_uuid
9
+ self.id = UUID.generate
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ require 'acts_as_uuid'
2
+ require 'rails'
3
+
4
+ module ActsAsUUID
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :activeuuid
7
+ initializer "activeuuid.configure_rails_initialization" do
8
+
9
+ module PostgreSQLAdapter
10
+ def native_database_types_with_uuid_support
11
+ a = native_database_types_without_uuid_support
12
+ a[:uuid] = {:name => 'uuid'}
13
+ return a
14
+ end
15
+
16
+ def self.included klass
17
+ klass.alias_method_chain :native_database_types, :uuid_support
18
+ end
19
+ end
20
+
21
+ module PostgreSQLColumn
22
+ def simplified_type_with_uuid_support(field_type)
23
+ if field_type == 'uuid'
24
+ :uuid
25
+ else
26
+ simplified_type_without_uuid_support(field_type)
27
+ end
28
+ end
29
+
30
+ def self.included klass
31
+ klass.alias_method_chain :simplified_type, :uuid_support
32
+ end
33
+ end
34
+
35
+ module TableDefinition
36
+ def uuid *args
37
+ options = args.extract_options!
38
+ column(args[0], 'uuid', options)
39
+ end
40
+ end
41
+
42
+ # Include it all
43
+ if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
44
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition.__send__ :include, ActsAsUUID::Railtie::TableDefinition
45
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.__send__ :include, ActsAsUUID::Railtie::PostgreSQLAdapter
46
+ ActiveRecord::ConnectionAdapters::PostgreSQLColumn.__send__ :include, ActsAsUUID::Railtie::PostgreSQLColumn
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsUuid
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe ActsAsUUID do
4
+
5
+ end
@@ -0,0 +1 @@
1
+ require "acts_as_uuid"
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_uuid
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Cristiano Betta
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: uuid
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: "Allows ActiveRecord to use (native) UUIDs, even as primary keys. Currently only works with PostgreSQL. "
49
+ email:
50
+ - cristiano@emberads.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - README.md
61
+ - Rakefile
62
+ - acts_as_uuid.gemspec
63
+ - lib/acts_as_uuid.rb
64
+ - lib/acts_as_uuid/acts_as_uuid.rb
65
+ - lib/acts_as_uuid/railtie.rb
66
+ - lib/acts_as_uuid/version.rb
67
+ - spec/acts_as_uuid/acts_as_uuid.rb
68
+ - spec/spec_helper.rb
69
+ homepage: https://github.com/EmberAds/acts_as_uuid
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: acts_as_uuid
98
+ rubygems_version: 1.8.15
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Allows ActiveRecord to use (native) UUIDs
102
+ test_files:
103
+ - spec/acts_as_uuid/acts_as_uuid.rb
104
+ - spec/spec_helper.rb