one_touch 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/one_touch/models/active_record_extension.rb +12 -4
- data/lib/one_touch/version.rb +1 -1
- data/readme.md +5 -2
- data/spec/models/as_favorable_spec.rb +1 -2
- data/spec/spec_helper.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1e9c970fe307783c8cc7e941ed54907e77389f
|
4
|
+
data.tar.gz: dea7b43a6d018a3dfc74accef7921a57093aadb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fc4641a2881f681b586054b219207b16531849bdfcb15a899d990d84dcbb33f2f5f53e3c0fd50d1e6d4e7e45c5301b6733d3d1275917d5c271bd2c7a3c42ed1
|
7
|
+
data.tar.gz: edc97ca57f82d8934fea42388001adb9d76add63951b72caaf878f5bb933a7eba344c24d4eaa3a9b2240f3992caa904b2f4b8e00ed157b8052ba6c4aece6f77e
|
@@ -59,13 +59,17 @@ module OneTouch
|
|
59
59
|
#
|
60
60
|
def as_favor_host(opt={})
|
61
61
|
include ::OneTouch::PortBuild
|
62
|
-
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :host)
|
62
|
+
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :host, polymorphic: false)
|
63
63
|
append_relation(opt)
|
64
64
|
# Programmer Doc
|
65
65
|
# The Name of has_many is stick to favors, to make it changable would cause some query problem
|
66
66
|
# :as => :host can not be configured too, cause in act_as_favor the relation name was sticked
|
67
67
|
unless opt[:no_default_relations]
|
68
|
-
|
68
|
+
if opt[:polymorphic] == true
|
69
|
+
has_many :favors, :class_name => opt[:bridge_klass], :as => :host
|
70
|
+
else
|
71
|
+
has_many :favors, :class_name => opt[:bridge_klass]
|
72
|
+
end
|
69
73
|
end
|
70
74
|
include AsFavorHost
|
71
75
|
end
|
@@ -73,10 +77,14 @@ module OneTouch
|
|
73
77
|
# Used in favorable class, so self is a class
|
74
78
|
def as_favorable(opt={})
|
75
79
|
include ::OneTouch::PortBuild
|
76
|
-
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :favorable)
|
80
|
+
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :favorable, polymorphic: true)
|
77
81
|
append_relation(opt)
|
78
82
|
unless opt[:no_default_relations]
|
79
|
-
|
83
|
+
if opt[:polymorphic] == true
|
84
|
+
has_many :be_favors, :class_name => opt[:bridge_klass], :as => :favorable
|
85
|
+
else
|
86
|
+
has_many :be_favors, :class_name => opt[:bridge_klass]
|
87
|
+
end
|
80
88
|
end
|
81
89
|
include AsFavorable
|
82
90
|
include HostRelation if favor_class.respond_to? :include_host_relation_module and favor_class.include_host_relation_module
|
data/lib/one_touch/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
### Upgrade warnning
|
2
|
-
|
2
|
+
The loading sequence bug in 2.0.0 was fixed in 2.1.0. Please upgrade to 2.1.0 or stay on ~> 1
|
3
|
+
|
3
4
|
### Intro
|
4
5
|
In webapp, many data is generated by just one click like focus someone, dislike some post.This gem make it easy.
|
5
6
|
|
@@ -23,7 +24,7 @@ Then we define:
|
|
23
24
|
class Favor
|
24
25
|
CONTEXT = Set.new(%w[focus favorite follow agree oppose buy subscribe])
|
25
26
|
CONTEXT_MATCH = { :focus => [:Tag, :Post], :follow => [:User] }
|
26
|
-
acts_as_favor
|
27
|
+
acts_as_favor host_class_name: :User
|
27
28
|
end
|
28
29
|
|
29
30
|
Make sure Favor has defined constants CONTEXT and CONTEXT_MATCH before acts_as_favor.
|
@@ -120,6 +121,8 @@ This means @user1 is more close to @user2 than @user3.Maybe the answers that @us
|
|
120
121
|
Because We create or delete data in one click. No Form Needed.
|
121
122
|
|
122
123
|
### TODO
|
124
|
+
Improve README
|
125
|
+
|
123
126
|
Add cache to favored_by, favor_to.
|
124
127
|
|
125
128
|
Add a generator to make install faster.
|
@@ -38,8 +38,7 @@ describe OneTouch::AsFavorable do
|
|
38
38
|
context Favor do
|
39
39
|
it "build relations should return a hash of relation between favorable and host" do
|
40
40
|
Favor.build_relations.instance_of?(Hash).should be_true
|
41
|
-
|
42
|
-
Favor.build_relations.keys.should include(["favorite", Tag.first]) # means first key
|
41
|
+
Favor.build_relations.keys.should include(["favorite", Tag.first])
|
43
42
|
end
|
44
43
|
|
45
44
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,7 +20,7 @@ def loading_sequence
|
|
20
20
|
puts_marks
|
21
21
|
puts "Loading Sequence 0: favorable -> host -> favor"
|
22
22
|
Tag.as_favorable
|
23
|
-
User.as_favor_host
|
23
|
+
User.as_favor_host polymorphic: true
|
24
24
|
User.as_favorable
|
25
25
|
Favor.acts_as_favor :host_class_name => nil
|
26
26
|
when 1
|
@@ -28,19 +28,19 @@ def loading_sequence
|
|
28
28
|
puts "Loading Sequence 1: favorable -> favor -> host"
|
29
29
|
Tag.as_favorable
|
30
30
|
Favor.acts_as_favor :host_class_name => nil
|
31
|
-
User.as_favor_host
|
31
|
+
User.as_favor_host polymorphic: true
|
32
32
|
User.as_favorable
|
33
33
|
when 2
|
34
34
|
puts_marks
|
35
35
|
puts "Loading Sequence 2: host -> favorable -> favor"
|
36
|
-
User.as_favor_host
|
36
|
+
User.as_favor_host polymorphic: true
|
37
37
|
Tag.as_favorable
|
38
38
|
Favor.acts_as_favor :host_class_name => nil
|
39
39
|
User.as_favorable
|
40
40
|
when 3
|
41
41
|
puts_marks
|
42
42
|
puts "Loading Sequence 3: host -> favor -> favorable"
|
43
|
-
User.as_favor_host
|
43
|
+
User.as_favor_host polymorphic: true
|
44
44
|
Favor.acts_as_favor :host_class_name => nil
|
45
45
|
Tag.as_favorable
|
46
46
|
User.as_favorable
|
@@ -48,7 +48,7 @@ def loading_sequence
|
|
48
48
|
puts_marks
|
49
49
|
puts "Loading Sequence 4: favor -> host -> favorable"
|
50
50
|
Favor.acts_as_favor :host_class_name => nil
|
51
|
-
User.as_favor_host
|
51
|
+
User.as_favor_host polymorphic: true
|
52
52
|
User.as_favorable
|
53
53
|
Tag.as_favorable
|
54
54
|
when 5
|
@@ -56,7 +56,7 @@ def loading_sequence
|
|
56
56
|
puts "Loading Sequence 5: favor -> favorable -> host"
|
57
57
|
Favor.acts_as_favor :host_class_name => nil
|
58
58
|
User.as_favorable
|
59
|
-
User.as_favor_host
|
59
|
+
User.as_favor_host polymorphic: true
|
60
60
|
Tag.as_favorable
|
61
61
|
end
|
62
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: one_touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- raykin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|