acts_as_inheritance_root 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/MIT-LICENSE +20 -0
- data/README +9 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/acts_as_inheritance_root.gemspec +43 -0
- data/init.rb +1 -0
- data/lib/acts_as_inheritance_root.rb +52 -0
- metadata +62 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Provideal Systems GmbH
|
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
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "acts_as_inheritance_root"
|
9
|
+
gemspec.summary = "Using PostgreSQL table inheritance with Rails"
|
10
|
+
gemspec.email = "info@provideal.net"
|
11
|
+
gemspec.homepage = "http://github.com/provideal/acts_as_inheritance_root"
|
12
|
+
gemspec.authors = ["René Sprotte"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{acts_as_inheritance_root}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ren\303\251 Sprotte"]
|
12
|
+
s.date = %q{2009-12-04}
|
13
|
+
s.email = %q{info@provideal.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"acts_as_inheritance_root.gemspec",
|
24
|
+
"init.rb",
|
25
|
+
"lib/acts_as_inheritance_root.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/provideal/acts_as_inheritance_root}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.5}
|
31
|
+
s.summary = %q{Using PostgreSQL table inheritance with Rails}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
35
|
+
s.specification_version = 3
|
36
|
+
|
37
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
38
|
+
else
|
39
|
+
end
|
40
|
+
else
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'acts_as_inheritance_root'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ActAsInheritanceRoot
|
2
|
+
|
3
|
+
def acts_as_inheritance_root
|
4
|
+
class << self
|
5
|
+
def instantiate_with_clti_support(record)
|
6
|
+
object = instantiate_without_clti_support(record)
|
7
|
+
|
8
|
+
if object.present? and object.respond_to? :instance and object.respond_to? :instance_type and not object.new_record?
|
9
|
+
if self.name != object.instance_type.name
|
10
|
+
object = object.instance
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
return object
|
15
|
+
end
|
16
|
+
alias_method_chain :instantiate, :clti_support
|
17
|
+
end
|
18
|
+
|
19
|
+
send :include, InstanceMethods
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
|
24
|
+
def instance
|
25
|
+
nil unless self.id.present? or self.new_record?
|
26
|
+
|
27
|
+
unless @instance.present?
|
28
|
+
if instance_type.present?
|
29
|
+
@instance = instance_type.find(self.id)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@instance
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def instance_type
|
37
|
+
nil unless self.id.present? or self.new_record?
|
38
|
+
|
39
|
+
unless @instance_type
|
40
|
+
sql = "select p.relname from #{self.class.name.tableize} s, pg_class p where s.id = #{self.id} and s.tableoid = p.oid"
|
41
|
+
res = connection.execute(sql)
|
42
|
+
if res[0]['relname'].present?
|
43
|
+
@instance_type = res[0]['relname'].classify.constantize
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@instance_type
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
ActiveRecord::Base.extend ActAsInheritanceRoot
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_inheritance_root
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Ren\xC3\xA9 Sprotte"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-04 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: info@provideal.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- acts_as_inheritance_root.gemspec
|
31
|
+
- init.rb
|
32
|
+
- lib/acts_as_inheritance_root.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/provideal/acts_as_inheritance_root
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Using PostgreSQL table inheritance with Rails
|
61
|
+
test_files: []
|
62
|
+
|