polymorphic_identity 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/LICENSE +1 -1
- data/README.rdoc +4 -8
- data/Rakefile +18 -16
- data/test/app_root/app/models/article.rb +1 -2
- data/test/app_root/app/models/author.rb +1 -2
- data/test/app_root/app/models/comment.rb +3 -5
- data/test/app_root/app/models/page.rb +1 -2
- data/test/app_root/app/models/user.rb +2 -3
- data/test/unit/polymorphic_identity_test.rb +3 -3
- metadata +16 -20
data/CHANGELOG.rdoc
CHANGED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -28,8 +28,7 @@ knowing the type of model your interacting with. For example, a typical
|
|
28
28
|
polymorphic assocation looks like the following:
|
29
29
|
|
30
30
|
class Tag < ActiveRecord::Base
|
31
|
-
belongs_to :taggable,
|
32
|
-
:polymorphic => true
|
31
|
+
belongs_to :taggable, :polymorphic => true
|
33
32
|
end
|
34
33
|
|
35
34
|
When getting the taggable record, you would normally have to call
|
@@ -45,10 +44,8 @@ class name.
|
|
45
44
|
=== Example
|
46
45
|
|
47
46
|
class Comment < ActiveRecord::Base
|
48
|
-
belongs_to :commentable,
|
49
|
-
|
50
|
-
belongs_to :commenter,
|
51
|
-
:polymorphic => true
|
47
|
+
belongs_to :commentable, :polymorphic => true
|
48
|
+
belongs_to :commenter, :polymorphic => true
|
52
49
|
end
|
53
50
|
|
54
51
|
class Article < ActiveRecord::Base
|
@@ -56,8 +53,7 @@ class name.
|
|
56
53
|
end
|
57
54
|
|
58
55
|
class User < ActiveRecord::Base
|
59
|
-
has_many :comments,
|
60
|
-
:as => :commenter
|
56
|
+
has_many :comments, :as => :commenter
|
61
57
|
end
|
62
58
|
|
63
59
|
c = Comment.find(1) # => #<Tag id: 1, commentable_id: 1, commentable_type: "Article", commenter_id: 1, commenter_type: "User"}>
|
data/Rakefile
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
1
3
|
require 'rake/testtask'
|
2
4
|
require 'rake/rdoctask'
|
3
5
|
require 'rake/gempackagetask'
|
4
|
-
require 'rake/contrib/sshpublisher'
|
5
6
|
|
6
7
|
spec = Gem::Specification.new do |s|
|
7
8
|
s.name = 'polymorphic_identity'
|
8
|
-
s.version = '0.1.
|
9
|
+
s.version = '0.1.1'
|
9
10
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.summary = 'Dynamically generates aliases for polymorphic associations based on their class names'
|
11
|
+
s.summary = 'Dynamically generates aliases for polymorphic ActiveRecord associations based on their class names'
|
12
|
+
s.description = s.summary
|
11
13
|
|
12
14
|
s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
15
|
s.require_path = 'lib'
|
@@ -52,20 +54,27 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
52
54
|
rdoc.options << '--line-numbers' << '--inline-source'
|
53
55
|
rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb')
|
54
56
|
end
|
55
|
-
|
57
|
+
|
58
|
+
desc 'Generate a gemspec file.'
|
59
|
+
task :gemspec do
|
60
|
+
File.open("#{spec.name}.gemspec", 'w') do |f|
|
61
|
+
f.write spec.to_ruby
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
56
65
|
Rake::GemPackageTask.new(spec) do |p|
|
57
66
|
p.gem_spec = spec
|
58
|
-
p.need_tar = true
|
59
|
-
p.need_zip = true
|
60
67
|
end
|
61
68
|
|
62
69
|
desc 'Publish the beta gem.'
|
63
70
|
task :pgem => [:package] do
|
71
|
+
require 'rake/contrib/sshpublisher'
|
64
72
|
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
|
65
73
|
end
|
66
74
|
|
67
75
|
desc 'Publish the API documentation.'
|
68
76
|
task :pdoc => [:rdoc] do
|
77
|
+
require 'rake/contrib/sshpublisher'
|
69
78
|
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
|
70
79
|
end
|
71
80
|
|
@@ -74,15 +83,8 @@ task :publish => [:pgem, :pdoc, :release]
|
|
74
83
|
|
75
84
|
desc 'Publish the release files to RubyForge.'
|
76
85
|
task :release => [:gem, :package] do
|
77
|
-
require '
|
78
|
-
|
79
|
-
ruby_forge = RubyForge.new.configure
|
80
|
-
ruby_forge.login
|
86
|
+
require 'rake/gemcutter'
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
puts "Releasing #{File.basename(file)}..."
|
85
|
-
|
86
|
-
ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
|
87
|
-
end
|
88
|
+
Rake::Gemcutter::Tasks.new(spec)
|
89
|
+
Rake::Task['gem:push'].invoke
|
88
90
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class PolymorphicIdentityTest <
|
3
|
+
class PolymorphicIdentityTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
@comment = Comment.new
|
6
6
|
@comment.commenter_type = 'Article'
|
@@ -19,7 +19,7 @@ class PolymorphicIdentityTest < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class PolymorphicAssociationWithNoValueTest <
|
22
|
+
class PolymorphicAssociationWithNoValueTest < ActiveSupport::TestCase
|
23
23
|
def setup
|
24
24
|
@comment = create_comment(:commentable => nil, :commenter => nil)
|
25
25
|
end
|
@@ -32,7 +32,7 @@ class PolymorphicAssociationWithNoValueTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
class PolymorphicAssociationsWithValueTest <
|
35
|
+
class PolymorphicAssociationsWithValueTest < ActiveSupport::TestCase
|
36
36
|
def setup
|
37
37
|
@author = create_author
|
38
38
|
@article = create_article(:author => @author)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorphic_identity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Dynamically generates aliases for polymorphic ActiveRecord associations based on their class names
|
17
17
|
email: aaron@pluginaweek.org
|
18
18
|
executables: []
|
19
19
|
|
@@ -23,25 +23,19 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- lib/polymorphic_identity.rb
|
26
|
-
- test/factory.rb
|
27
|
-
- test/test_helper.rb
|
28
|
-
- test/unit
|
29
26
|
- test/unit/polymorphic_identity_test.rb
|
30
|
-
- test/app_root
|
31
|
-
- test/app_root/db
|
32
|
-
- test/app_root/db/migrate
|
33
|
-
- test/app_root/db/migrate/004_create_users.rb
|
34
27
|
- test/app_root/db/migrate/005_create_comments.rb
|
35
|
-
- test/app_root/db/migrate/001_create_authors.rb
|
36
|
-
- test/app_root/db/migrate/003_create_pages.rb
|
37
28
|
- test/app_root/db/migrate/002_create_articles.rb
|
38
|
-
- test/app_root/
|
39
|
-
- test/app_root/
|
40
|
-
- test/app_root/
|
41
|
-
- test/app_root/app/models/author.rb
|
42
|
-
- test/app_root/app/models/user.rb
|
29
|
+
- test/app_root/db/migrate/003_create_pages.rb
|
30
|
+
- test/app_root/db/migrate/004_create_users.rb
|
31
|
+
- test/app_root/db/migrate/001_create_authors.rb
|
43
32
|
- test/app_root/app/models/comment.rb
|
33
|
+
- test/app_root/app/models/user.rb
|
34
|
+
- test/app_root/app/models/author.rb
|
44
35
|
- test/app_root/app/models/page.rb
|
36
|
+
- test/app_root/app/models/article.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
- test/factory.rb
|
45
39
|
- CHANGELOG.rdoc
|
46
40
|
- init.rb
|
47
41
|
- LICENSE
|
@@ -49,6 +43,8 @@ files:
|
|
49
43
|
- README.rdoc
|
50
44
|
has_rdoc: true
|
51
45
|
homepage: http://www.pluginaweek.org
|
46
|
+
licenses: []
|
47
|
+
|
52
48
|
post_install_message:
|
53
49
|
rdoc_options: []
|
54
50
|
|
@@ -69,9 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
65
|
requirements: []
|
70
66
|
|
71
67
|
rubyforge_project: pluginaweek
|
72
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.3.5
|
73
69
|
signing_key:
|
74
|
-
specification_version:
|
75
|
-
summary: Dynamically generates aliases for polymorphic associations based on their class names
|
70
|
+
specification_version: 3
|
71
|
+
summary: Dynamically generates aliases for polymorphic ActiveRecord associations based on their class names
|
76
72
|
test_files:
|
77
73
|
- test/unit/polymorphic_identity_test.rb
|