ploymorphic_wuid 0.1.0 → 0.2.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/README.rdoc CHANGED
@@ -13,6 +13,7 @@ class CreateWuids < ActiveRecord::Migration
13
13
  create_table :wuids do |t|
14
14
  t.integer :wuidable_id
15
15
  t.string :wuidable_type
16
+ t.integer :reference_to #optional
16
17
  t.timestamps
17
18
  end
18
19
  end
@@ -31,7 +32,7 @@ end
31
32
  in your model
32
33
 
33
34
  class Book < ActiveRecord::Base
34
- acts_as_wuid
35
+ acts_as_wuid
35
36
  end
36
37
 
37
38
  that's all
@@ -46,6 +47,10 @@ end
46
47
 
47
48
  obj.wid
48
49
 
50
+ == advantage
51
+
52
+ acts_as_wuid :acts_as_tree => true
53
+
49
54
  == Note on Patches/Pull Requests
50
55
 
51
56
  * Fork the project.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ gem 'acts_as_tree', '>=0.1.1'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -9,6 +10,7 @@ begin
9
10
  gem.description = %Q{ This is a gem to generate an unique id in your application world.}
10
11
  gem.email = "tim.rubist@gmail.com"
11
12
  gem.homepage = "http://github.com/tteng/ploymorphic_wuid"
13
+ gem.add_development_dependency "acts_as_tree", ">= 0.1.1"
12
14
  gem.authors = ["tim.teng"]
13
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,4 +1,3 @@
1
1
  require 'wuid/ploymorphic_module'
2
2
  require 'wuid/wuid'
3
-
4
3
  ActiveRecord::Base.send :include, PloymorphicModule
@@ -6,9 +6,17 @@ module PloymorphicModule
6
6
 
7
7
  module ClassMethods
8
8
 
9
- def acts_as_wuid
9
+ def acts_as_wuid options={}
10
+ #TODO auto set wuid with conditional hook
10
11
  has_one :wuid, :as => :wuidable, :dependent => :destroy
11
- include PloymorphicModule::InstanceMethods
12
+ if options[:acts_as_tree]
13
+ Wuid.class_eval do
14
+ acts_as_tree :foreign_key => "reference_to"
15
+ end
16
+ include PloymorphicModule::AdvancedInstanceMethods
17
+ else
18
+ include PloymorphicModule::InstanceMethods
19
+ end
12
20
  end
13
21
 
14
22
  end
@@ -25,11 +33,22 @@ module PloymorphicModule
25
33
  end
26
34
 
27
35
  def wid
28
- wuid.id
36
+ self.wuid.id
29
37
  end
30
38
 
31
39
  end
32
40
 
33
- end
41
+ module AdvancedInstanceMethods
42
+
43
+ def wid
44
+ (self.respond_to?(:reference_to) && self.parent) ? self.parent.wid : self.wuid.id
45
+ end
34
46
 
47
+ def wid= id
48
+ w = self.wuild.build :reference_to => id
49
+ w.save
50
+ end
51
+
52
+ end
35
53
 
54
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ploymorphic_wuid}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tim.teng"]
12
- s.date = %q{2010-03-26}
12
+ s.date = %q{2010-03-31}
13
13
  s.description = %q{ This is a gem to generate an unique id in your application world.}
14
14
  s.email = %q{tim.rubist@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
25
25
  "lib/ploymorphic_wuid.rb",
26
26
  "lib/wuid/ploymorphic_module.rb",
27
27
  "lib/wuid/wuid.rb",
28
- "pkg/ploymorphic_wuid-0.1.0.gem",
29
28
  "ploymorphic_wuid.gemspec",
30
29
  "test/helper.rb",
31
30
  "test/test_ploymorphic_wuid.rb"
@@ -45,9 +44,12 @@ Gem::Specification.new do |s|
45
44
  s.specification_version = 3
46
45
 
47
46
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<acts_as_tree>, [">= 0.1.1"])
48
48
  else
49
+ s.add_dependency(%q<acts_as_tree>, [">= 0.1.1"])
49
50
  end
50
51
  else
52
+ s.add_dependency(%q<acts_as_tree>, [">= 0.1.1"])
51
53
  end
52
54
  end
53
55
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - tim.teng
@@ -14,10 +14,23 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-26 00:00:00 +08:00
17
+ date: 2010-03-31 00:00:00 +08:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: acts_as_tree
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 1
31
+ version: 0.1.1
32
+ type: :development
33
+ version_requirements: *id001
21
34
  description: " This is a gem to generate an unique id in your application world."
22
35
  email: tim.rubist@gmail.com
23
36
  executables: []
@@ -36,7 +49,6 @@ files:
36
49
  - lib/ploymorphic_wuid.rb
37
50
  - lib/wuid/ploymorphic_module.rb
38
51
  - lib/wuid/wuid.rb
39
- - pkg/ploymorphic_wuid-0.1.0.gem
40
52
  - ploymorphic_wuid.gemspec
41
53
  - test/helper.rb
42
54
  - test/test_ploymorphic_wuid.rb
Binary file