activerecord-postgres-composite-types 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +16 -0
- data/VERSION +1 -1
- data/activerecord-postgres-composite-types.gemspec +4 -5
- data/lib/activerecord-postgres-composite-types.rb +2 -5
- data/lib/activerecord-postgres-composite-types/active_record.rb +4 -0
- data/lib/activerecord-postgres-composite-types/railtie.rb +17 -0
- data/lib/{activerecord-postgres-composite-types/postgres_composite_type.rb → postgres_composite_type.rb} +25 -2
- data/test/composite_types.rb +1 -0
- data/test/helper.rb +1 -2
- data/test/internal/config/database.yml +3 -3
- metadata +4 -5
- data/activerecord-postgres-custom-types.gemspec +0 -91
- data/lib/activerecord-postgres-composite-types/railties.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f1180c2f69bc0bcff969b4d5a0a8fc62ff6c2fd
|
4
|
+
data.tar.gz: 6a94bec2dccd909fa613e66a50eee379dea61298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87be224bc26e25a18ba0a641b2f764da2ff7708c1b17f667f1977cc17f1f75e19dff6996e6e9f6279490b1c8a79b14949af23f5d44cddf528ceaf5bbb455e3b
|
7
|
+
data.tar.gz: cd42315a520c43ea636876e796d99730d848de9069adb0b22beadb0ebf64a6e53bb73ad0fab52f4ce380423762d8ca4459f464026a6d482d1893e9eb4605fb9f
|
data/README.rdoc
CHANGED
@@ -44,10 +44,26 @@ and then
|
|
44
44
|
|
45
45
|
To achieve this goal I only have to define composite type class in a following way:
|
46
46
|
|
47
|
+
require 'postgres_composite_type'
|
47
48
|
class ComplexType < PostgresCompositeType
|
48
49
|
register_type :complex
|
49
50
|
end
|
50
51
|
|
52
|
+
This class must be loaded before any ActiveRecord model is instantializated, but NOT before
|
53
|
+
ActiveRecord is loaded. Load your classes with ActiveRecord hook:
|
54
|
+
|
55
|
+
ActiveSupport.on_load :active_record do
|
56
|
+
require 'complex_type'
|
57
|
+
end
|
58
|
+
|
59
|
+
You can of course put this code in your railtie initializer:
|
60
|
+
|
61
|
+
initialize :complexy_type do
|
62
|
+
ActiveSupport.on_load :active_record do
|
63
|
+
require 'complex_type'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
51
67
|
That's all folks.
|
52
68
|
|
53
69
|
== Contributing to ActiveRecord PostgreSQL Composite Types
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "activerecord-postgres-composite-types"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rafal Bigaj"]
|
12
|
-
s.date = "2014-09-
|
12
|
+
s.date = "2014-09-12"
|
13
13
|
s.description = "This gem adds support to the ActiveRecord (3.x and 4.x) for composite types."
|
14
14
|
s.email = "rafal.bigaj@puzzleflow.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,14 +25,13 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"activerecord-postgres-composite-types.gemspec",
|
28
|
-
"activerecord-postgres-custom-types.gemspec",
|
29
28
|
"lib/activerecord-postgres-composite-types.rb",
|
30
29
|
"lib/activerecord-postgres-composite-types/active_record.rb",
|
31
30
|
"lib/activerecord-postgres-composite-types/active_record_3.rb",
|
32
31
|
"lib/activerecord-postgres-composite-types/active_record_4.rb",
|
33
32
|
"lib/activerecord-postgres-composite-types/composite_type_parser.rb",
|
34
|
-
"lib/activerecord-postgres-composite-types/
|
35
|
-
"lib/
|
33
|
+
"lib/activerecord-postgres-composite-types/railtie.rb",
|
34
|
+
"lib/postgres_composite_type.rb",
|
36
35
|
"test/composite_types.rb",
|
37
36
|
"test/helper.rb",
|
38
37
|
"test/internal/config/database.yml",
|
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require 'active_record/connection_adapters/postgresql_adapter'
|
3
2
|
|
4
3
|
if defined? Rails
|
5
|
-
require "activerecord-postgres-composite-types/
|
4
|
+
require "activerecord-postgres-composite-types/railtie"
|
6
5
|
else
|
7
6
|
ActiveSupport.on_load :active_record do
|
8
7
|
require "activerecord-postgres-composite-types/active_record"
|
8
|
+
require 'postgres_composite_type'
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
12
|
-
require "activerecord-postgres-composite-types/postgres_composite_type"
|
13
|
-
require "activerecord-postgres-composite-types/composite_type_parser"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# = Postgres Composite Types Railtie
|
4
|
+
#
|
5
|
+
# Creates a new railtie to initialize ActiveRecord properly
|
6
|
+
|
7
|
+
class PostgresCompositeTypesRailtie < Rails::Railtie
|
8
|
+
|
9
|
+
initializer 'activerecord-postgres-composite-types' do
|
10
|
+
ActiveSupport.on_load :active_record do
|
11
|
+
require "activerecord-postgres-composite-types/active_record"
|
12
|
+
require 'postgres_composite_type'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
@@ -1,29 +1,52 @@
|
|
1
|
+
require 'activerecord-postgres-composite-types/active_record'
|
2
|
+
|
1
3
|
class PostgresCompositeType
|
2
4
|
include Comparable
|
3
5
|
|
4
6
|
class << self
|
5
|
-
#
|
7
|
+
# The PostgreSQL type name as symbol
|
6
8
|
attr_reader :type
|
7
|
-
#
|
9
|
+
# Column definition read from db schema
|
8
10
|
attr_reader :columns
|
9
11
|
|
12
|
+
# Link PostgreSQL type given by the name with this class.
|
13
|
+
# Usage:
|
14
|
+
#
|
15
|
+
# class ComplexType < PostgresCompositeType
|
16
|
+
# register_type :complex
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @param [Symbol] :type the PostgreSQL type name
|
10
20
|
def register_type(type)
|
11
21
|
@type = type.to_sym
|
12
22
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.register_composite_type_class(self)
|
13
23
|
end
|
14
24
|
|
25
|
+
# Be default the ActiveRecord::Base connection is used when reading type definition.
|
26
|
+
# If you want to use connection linked with another class use this method.
|
27
|
+
# Usage
|
28
|
+
#
|
29
|
+
# class ComplexType < PostgresCompositeType
|
30
|
+
# register_type :complex
|
31
|
+
# use_connection_class MyRecordConnectedToDifferentDB
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @param [Class] :active_record_class the ActiveRecord model class
|
15
35
|
def use_connection_class(active_record_class)
|
16
36
|
@connection_class = active_record_class
|
17
37
|
end
|
18
38
|
|
39
|
+
# :nodoc:
|
19
40
|
def connection
|
20
41
|
(@connection_class || ActiveRecord::Base).connection
|
21
42
|
end
|
22
43
|
|
44
|
+
# :nodoc:
|
23
45
|
def connected?
|
24
46
|
(@connection_class || ActiveRecord::Base).connected?
|
25
47
|
end
|
26
48
|
|
49
|
+
# :nodoc:
|
27
50
|
def initialize_column_definition
|
28
51
|
unless @columns
|
29
52
|
@columns = self.connection.columns(type)
|
data/test/composite_types.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -30,8 +30,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
30
30
|
require 'activerecord-postgres-composite-types'
|
31
31
|
|
32
32
|
ActiveSupport.on_load :active_record do
|
33
|
-
|
34
|
-
require_relative 'composite_types.rb'
|
33
|
+
require_relative 'composite_types'
|
35
34
|
end
|
36
35
|
|
37
36
|
Combustion.path = 'test/internal'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres-composite-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafal Bigaj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -167,14 +167,13 @@ files:
|
|
167
167
|
- Rakefile
|
168
168
|
- VERSION
|
169
169
|
- activerecord-postgres-composite-types.gemspec
|
170
|
-
- activerecord-postgres-custom-types.gemspec
|
171
170
|
- lib/activerecord-postgres-composite-types.rb
|
172
171
|
- lib/activerecord-postgres-composite-types/active_record.rb
|
173
172
|
- lib/activerecord-postgres-composite-types/active_record_3.rb
|
174
173
|
- lib/activerecord-postgres-composite-types/active_record_4.rb
|
175
174
|
- lib/activerecord-postgres-composite-types/composite_type_parser.rb
|
176
|
-
- lib/activerecord-postgres-composite-types/
|
177
|
-
- lib/
|
175
|
+
- lib/activerecord-postgres-composite-types/railtie.rb
|
176
|
+
- lib/postgres_composite_type.rb
|
178
177
|
- test/composite_types.rb
|
179
178
|
- test/helper.rb
|
180
179
|
- test/internal/config/database.yml
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "activerecord-postgres-custom-types"
|
8
|
-
s.version = "0.2.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Rafal Bigaj"]
|
12
|
-
s.date = "2014-09-09"
|
13
|
-
s.description = "This gem adds support to the ActiveRecord (3.x and 4.x) for composite types."
|
14
|
-
s.email = "rafal.bigaj@puzzleflow.com"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"LICENSE.txt",
|
18
|
-
"README.rdoc"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
".document",
|
22
|
-
".travis.yml",
|
23
|
-
"Gemfile",
|
24
|
-
"LICENSE",
|
25
|
-
"LICENSE.txt",
|
26
|
-
"README.rdoc",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"activerecord-postgres-custom-types.gemspec",
|
30
|
-
"lib/activerecord-postgres-composite-types.rb",
|
31
|
-
"lib/activerecord-postgres-composite-types/active_record.rb",
|
32
|
-
"lib/activerecord-postgres-composite-types/active_record_3.rb",
|
33
|
-
"lib/activerecord-postgres-composite-types/active_record_4.rb",
|
34
|
-
"lib/activerecord-postgres-composite-types/composite_type_parser.rb",
|
35
|
-
"lib/activerecord-postgres-composite-types/postgres_composite_type.rb",
|
36
|
-
"lib/activerecord-postgres-composite-types/railties.rb",
|
37
|
-
"test/composite_types.rb",
|
38
|
-
"test/helper.rb",
|
39
|
-
"test/internal/config/database.yml",
|
40
|
-
"test/internal/config/database.yml.travis",
|
41
|
-
"test/internal/db/schema.rb",
|
42
|
-
"test/test_composite_type_class.rb",
|
43
|
-
"test/test_nested_types.rb",
|
44
|
-
"test/test_postgres_composite_types.rb"
|
45
|
-
]
|
46
|
-
s.homepage = "http://github.com/rafalbigaj/activerecord-postgres-custom-types"
|
47
|
-
s.licenses = ["MIT"]
|
48
|
-
s.require_paths = ["lib"]
|
49
|
-
s.rubygems_version = "2.0.3"
|
50
|
-
s.summary = "ActiveRecord composite types support"
|
51
|
-
|
52
|
-
if s.respond_to? :specification_version then
|
53
|
-
s.specification_version = 4
|
54
|
-
|
55
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 3.2.0"])
|
57
|
-
s.add_runtime_dependency(%q<pg>, [">= 0.17.0"])
|
58
|
-
s.add_development_dependency(%q<test-unit>, ["~> 2.1"])
|
59
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
60
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
-
s.add_development_dependency(%q<rake>, ["~> 10.3"])
|
62
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
63
|
-
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
64
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
65
|
-
s.add_development_dependency(%q<combustion>, ["~> 0.5.2"])
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<activerecord>, [">= 3.2.0"])
|
68
|
-
s.add_dependency(%q<pg>, [">= 0.17.0"])
|
69
|
-
s.add_dependency(%q<test-unit>, ["~> 2.1"])
|
70
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
72
|
-
s.add_dependency(%q<rake>, ["~> 10.3"])
|
73
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
74
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
75
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
76
|
-
s.add_dependency(%q<combustion>, ["~> 0.5.2"])
|
77
|
-
end
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<activerecord>, [">= 3.2.0"])
|
80
|
-
s.add_dependency(%q<pg>, [">= 0.17.0"])
|
81
|
-
s.add_dependency(%q<test-unit>, ["~> 2.1"])
|
82
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
83
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
84
|
-
s.add_dependency(%q<rake>, ["~> 10.3"])
|
85
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
86
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
87
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
88
|
-
s.add_dependency(%q<combustion>, ["~> 0.5.2"])
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
|
3
|
-
# = Postgres Composite Types Railtie
|
4
|
-
#
|
5
|
-
# Creates a new railtie to initialize ActiveRecord properly
|
6
|
-
|
7
|
-
class PostgresCompositeTypesRailtie < Rails::Railtie
|
8
|
-
|
9
|
-
initializer 'activerecord-postgres-composite-types' do
|
10
|
-
ActiveSupport.on_load :active_record do
|
11
|
-
require "activerecord-postgres-composite-types/active_record"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|