one_touch 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -4
- data/Rakefile +3 -1
- data/lib/one_touch/core/bridge.rb +83 -0
- data/lib/one_touch/models/active_record_extension.rb +29 -46
- data/lib/one_touch/models/acts_as_favor.rb +13 -16
- data/lib/one_touch/models/as_favor_host.rb +13 -1
- data/lib/one_touch/version.rb +1 -1
- data/lib/one_touch.rb +1 -0
- data/one_touch.gemspec +1 -1
- data/readme.md +15 -13
- data/spec/core/relation_recorder_spec.rb +45 -0
- data/spec/models/as_favor_host_spec.rb +2 -5
- data/spec/spec_helper.rb +0 -6
- metadata +25 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a98a57687f0a2ec6b1dcaac63bafdc44c16134c
|
4
|
+
data.tar.gz: 30dab1a2ccc18f7f79456a16fb7592602bcb49ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29f2f5752cb2a54d169552fdbf29e624f8b8f0dc58fbb88957a206b2b493fdc4de23c4fce90694f909e80a67a67dc7270fbff5f45a88926a18b3315c6b407403
|
7
|
+
data.tar.gz: 009567cdfd4e1b1ea37ddee259e90c4a164ba41cac5b8e5113679b8a1f9728ce56a9e1d346aa8d451962f5c758c08cdad4775fec401c4aab928f359c41ebf3ab
|
data/Gemfile
CHANGED
@@ -7,8 +7,8 @@ gemspec
|
|
7
7
|
gem 'rake'
|
8
8
|
gem 'rspec'
|
9
9
|
gem 'rspec-rails'
|
10
|
-
gem '
|
11
|
-
|
12
|
-
gem 'rails', '3.0
|
13
|
-
gem '
|
10
|
+
gem 'debugger'
|
11
|
+
gem 'rails', '~> 3.2.0'
|
12
|
+
# gem 'rails', '~> 3.1.0'
|
13
|
+
# gem 'rails', '~> 3.0.0'
|
14
14
|
gem 'sqlite3', '~> 1.3.0', :group => :test
|
data/Rakefile
CHANGED
@@ -2,5 +2,7 @@ require 'bundler/gem_tasks'
|
|
2
2
|
|
3
3
|
desc "Running Test"
|
4
4
|
task :test do
|
5
|
-
|
5
|
+
# forgot how to include all spec files
|
6
|
+
system "bundle exec rspec spec/models/*spec.rb --debugger --backtrace --fail-fast"
|
7
|
+
system "bundle exec rspec spec/core/*spec.rb --debugger --backtrace --fail-fast"
|
6
8
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module OneTouch
|
2
|
+
class RelationRecorder
|
3
|
+
@@recorders = []
|
4
|
+
|
5
|
+
# port_group is Hash as {portname: [klass_name, ...]}
|
6
|
+
attr_accessor :bridge_klass, :bridge_class, :port_group
|
7
|
+
def initialize(opts)
|
8
|
+
# loop and set attr as bridge_klass = opts[:bridge_klass]
|
9
|
+
opts.each do |k,v|
|
10
|
+
if respond_to?("#{k}=")
|
11
|
+
send "#{k}=", v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@@recorders << self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(bridge_klass)
|
18
|
+
@@recorders.select {|rr| rr.bridge_klass.to_sym == bridge_klass.to_sym}.first
|
19
|
+
end
|
20
|
+
|
21
|
+
# update an existed instance or create a new instance
|
22
|
+
def self.update_or_new(opts)
|
23
|
+
if rr = find(opts[:bridge_klass])
|
24
|
+
rr.add_new_port(opts[:port_group]) if opts.has_key? :port_group
|
25
|
+
rr.bridge_class ||= opts[:bridge_class] if opts.has_key? :bridge_class
|
26
|
+
rr
|
27
|
+
else
|
28
|
+
new(opts)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# add only one port, make sure pg is {portname: klassname}
|
33
|
+
def add_new_port(pg)
|
34
|
+
portname = pg.keys.first
|
35
|
+
if port_group.has_key? portname
|
36
|
+
self.port_group[portname].concat pg[portname]
|
37
|
+
else
|
38
|
+
self.port_group[portname] = pg[portname]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def portname_of(klass)
|
43
|
+
port_group.select {|k,v| v.include? klass}.keys
|
44
|
+
end
|
45
|
+
|
46
|
+
end # END RelationRecorder
|
47
|
+
|
48
|
+
module PortBuild
|
49
|
+
|
50
|
+
def self.included(base)
|
51
|
+
base.extend ClassMethods
|
52
|
+
end
|
53
|
+
|
54
|
+
module ClassMethods
|
55
|
+
def append_relation(opts={})
|
56
|
+
opts.reverse_merge!(bridge_klass: :Bridge, portname: :host)
|
57
|
+
opts.merge!(port_group: {opts[:portname] => [name.to_sym]})
|
58
|
+
RelationRecorder.update_or_new(opts)
|
59
|
+
define_singleton_method "#{opts[:bridge_klass].underscore}_class" do
|
60
|
+
opts[:bridge_klass].constantize
|
61
|
+
end
|
62
|
+
define_singleton_method "#{opts[:bridge_klass].underscore}_klass" do
|
63
|
+
opts[:bridge_klass]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def portname_on(bridge_klass)
|
69
|
+
(rr = RelationRecorder.find(bridge_klass)) &&
|
70
|
+
rr.portname_of(self.class.name.to_sym)
|
71
|
+
end
|
72
|
+
|
73
|
+
end # END PortBuild
|
74
|
+
|
75
|
+
module Bridge
|
76
|
+
|
77
|
+
def self.included(base)
|
78
|
+
RelationRecorder.update_or_new(bridge_klass: base.name, bridge_class: base)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end # END Bridge
|
83
|
+
end
|
@@ -26,11 +26,11 @@ module OneTouch
|
|
26
26
|
# belongs_to :tag
|
27
27
|
# acts_as_favor :no_default_relations => true
|
28
28
|
def acts_as_favor(opt={})
|
29
|
-
|
29
|
+
include ::OneTouch::Bridge
|
30
30
|
opt.reverse_merge!({:include_host_relation_module => true, :host_class_name => "User", :no_default_relations => false})
|
31
31
|
class_attribute :host_relation_type, :favorable_relation_type, :instance_writer => false
|
32
32
|
|
33
|
-
method_name_of_host_klasses = "host_klasses_for_#{name.underscore}"
|
33
|
+
# method_name_of_host_klasses = "host_klasses_for_#{name.underscore}"
|
34
34
|
|
35
35
|
include ActsAsFavor
|
36
36
|
|
@@ -57,46 +57,47 @@ module OneTouch
|
|
57
57
|
# I should add more files to make here more clear
|
58
58
|
# Some methods should be include first
|
59
59
|
# And others should be include later
|
60
|
-
#
|
61
|
-
#
|
60
|
+
# The following code should be in another file
|
62
61
|
|
63
62
|
if opt[:include_host_relation_module]
|
64
63
|
class_attribute :include_host_relation_module, :instance_writer => false
|
65
64
|
self.include_host_relation_module = true
|
66
|
-
add_host_relation_map(
|
65
|
+
add_host_relation_map(relation_recorder.port_group[:favorable], :be_favors, :host)
|
67
66
|
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
68
|
+
relation_recorder.port_group[:host].each do |klassname|
|
69
|
+
klass = klassname.to_s.constantize
|
70
|
+
klass.after_load_acts_as_favor if klass.respond_to? :after_load_acts_as_favor
|
73
71
|
end
|
74
|
-
end
|
75
72
|
|
73
|
+
end
|
76
74
|
|
77
75
|
# Used in host class
|
78
76
|
# Ex:
|
79
|
-
# as_favor_host :
|
77
|
+
# as_favor_host :bridge_klass => "AClass"
|
80
78
|
#
|
81
79
|
def as_favor_host(opt={})
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
include ::OneTouch::PortBuild
|
81
|
+
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :host)
|
82
|
+
append_relation(opt)
|
83
|
+
# assign_cattr_in_favor_class(:host_klasses,opt)
|
84
|
+
# Programmer Doc
|
85
85
|
# The Name of has_many is stick to favors, to make it changable would cause some query problem
|
86
|
-
# :as => :host can not be configured too, cause in act_as_favor
|
86
|
+
# :as => :host can not be configured too, cause in act_as_favor the relation name was sticked
|
87
87
|
unless opt[:no_default_relations]
|
88
|
-
has_many :favors, :class_name => opt[:
|
88
|
+
has_many :favors, :class_name => opt[:bridge_klass], :as => :host
|
89
89
|
end
|
90
90
|
include AsFavorHost
|
91
91
|
end
|
92
92
|
|
93
|
-
# Used in favorable class
|
93
|
+
# Used in favorable class, so self is a class
|
94
94
|
def as_favorable(opt={})
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
include ::OneTouch::PortBuild
|
96
|
+
opt.reverse_merge!(bridge_klass: "Favor", no_default_relations: false, portname: :favorable)
|
97
|
+
append_relation(opt)
|
98
|
+
# assign_cattr_in_favor_class(:favorable_klasses,opt)
|
98
99
|
unless opt[:no_default_relations]
|
99
|
-
has_many :be_favors, :class_name => opt[:
|
100
|
+
has_many :be_favors, :class_name => opt[:bridge_klass], :as => :favorable
|
100
101
|
end
|
101
102
|
include AsFavorable
|
102
103
|
include HostRelation if favor_class.respond_to? :include_host_relation_module and favor_class.include_host_relation_module = true
|
@@ -105,14 +106,6 @@ module OneTouch
|
|
105
106
|
private
|
106
107
|
|
107
108
|
def add_host_relation_map(favorable_klasses, *two_connection_name)
|
108
|
-
class_attribute :favorable_to_media, :media_to_host, :instance_writer => false
|
109
|
-
unless respond_to? :favorable_klasses
|
110
|
-
class_attribute :favorable_klasses
|
111
|
-
self.favorable_klasses = favorable_klasses
|
112
|
-
end
|
113
|
-
self.favorable_to_media = two_connection_name.first
|
114
|
-
self.media_to_host = two_connection_name[1]
|
115
|
-
|
116
109
|
include Relations
|
117
110
|
self.target_to_media = :be_favors
|
118
111
|
self.media_to_host = :host
|
@@ -123,24 +116,14 @@ module OneTouch
|
|
123
116
|
end
|
124
117
|
end
|
125
118
|
|
126
|
-
# Programmer Doc
|
127
|
-
# To maintain the connection betwwen host, favorable and favor class,
|
128
|
-
# defined class_attribute in their super class AR::Base
|
129
|
-
# I don't know if there is any good solution to not disturb AR::Base
|
130
|
-
def assign_cattr_in_favor_class(cattr_name,opt)
|
131
|
-
class_attribute :favor_klass, :favor_class, :instance_writer => false
|
132
|
-
self.favor_klass = opt[:klass]
|
133
|
-
self.favor_class = favor_klass.constantize
|
134
|
-
|
135
|
-
cattr_name = "#{cattr_name}_for_#{opt[:klass].underscore}".to_sym
|
136
|
-
unless ::ActiveRecord::Base.respond_to? cattr_name
|
137
|
-
::ActiveRecord::Base.class_attribute cattr_name, :instance_writer => false
|
138
|
-
::ActiveRecord::Base.send "#{cattr_name}=", []
|
139
|
-
end
|
140
|
-
(::ActiveRecord::Base.send cattr_name) << self.name.to_sym
|
141
|
-
end
|
142
|
-
|
143
119
|
end # End ClassMethods
|
144
120
|
|
145
121
|
end # ActiveRecordExtension
|
146
122
|
end
|
123
|
+
|
124
|
+
# Programmer Doc
|
125
|
+
# The most difficult is the loading order between host classes,favor class and favorable classes.
|
126
|
+
# For example in host class, some methods must defined after favor class was load.
|
127
|
+
# So if favor class was not load ,these methods define should be skipped and
|
128
|
+
# after favor class was loaded, we should call these method define.
|
129
|
+
# And I thought i should refactor the order design because there must be some duplicated cattr and class method
|
@@ -9,11 +9,13 @@ module OneTouch
|
|
9
9
|
self.cons_context_match = self::CONTEXT_MATCH
|
10
10
|
self.context_relation = self::CONTEXT_RELATION if defined? self::CONTEXT_RELATION
|
11
11
|
|
12
|
-
# Seems there are many hook
|
12
|
+
# Seems there are many hook need to implement, oppose hook, belongs hook ....
|
13
13
|
# All needed hook should be just about relations between contexts
|
14
14
|
# Other hooks should be write by user
|
15
15
|
after_save :context_relation_hook if context_relation.presence
|
16
16
|
|
17
|
+
# TODO
|
18
|
+
# Add I18n support on message
|
17
19
|
validates_inclusion_of :context,:in => cons_context, :message => "%{value} not included in CONTEXT"
|
18
20
|
|
19
21
|
validate :context_should_match_favorable_type
|
@@ -40,7 +42,7 @@ module OneTouch
|
|
40
42
|
# for example,follow_investors retrive all record which context is follow and favorable type is investor
|
41
43
|
# sample output :
|
42
44
|
# scope :focus_tags , where(:favorable_type => "Tag",:context => "focus")
|
43
|
-
# This function seems not useful in real life
|
45
|
+
# This function seems not useful in real life, So comment it
|
44
46
|
#
|
45
47
|
# cons_context_match.each do |context,favorable|
|
46
48
|
# favorable.each do |klass|
|
@@ -49,7 +51,7 @@ module OneTouch
|
|
49
51
|
# end
|
50
52
|
# end
|
51
53
|
|
52
|
-
#
|
54
|
+
# Used in test
|
53
55
|
# But in production, I think it should be run once at init
|
54
56
|
# write how to use it in readme.md
|
55
57
|
def self.context_match_keys_should_belongs_to_context
|
@@ -116,23 +118,17 @@ module OneTouch
|
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
121
|
+
def relation_recorder
|
122
|
+
RelationRecorder.find(self.name)
|
123
|
+
end
|
124
|
+
|
119
125
|
# seems just used for OneTouch::Relations module
|
120
126
|
def host_klasses
|
121
|
-
|
122
|
-
respond_to?(attr) ? send(attr) : []
|
127
|
+
relation_recorder.port_group[:host]
|
123
128
|
end
|
124
129
|
|
125
130
|
def favorable_klasses
|
126
|
-
|
127
|
-
respond_to?(attr) ? send(attr) : []
|
128
|
-
end
|
129
|
-
|
130
|
-
def favorable_to_media
|
131
|
-
:be_favors
|
132
|
-
end
|
133
|
-
|
134
|
-
def media_to_host
|
135
|
-
:host
|
131
|
+
relation_recorder.port_group[:favorable]
|
136
132
|
end
|
137
133
|
|
138
134
|
def build_by_three_elements(h, f, context)
|
@@ -143,6 +139,8 @@ module OneTouch
|
|
143
139
|
|
144
140
|
private
|
145
141
|
|
142
|
+
# TODO
|
143
|
+
# ADD i18n support on error message
|
146
144
|
def host_should_differ_favorable
|
147
145
|
if host_id == favorable_id and host_type == favorable_type
|
148
146
|
errors.add(:favorable_id," can not the same as the host_id when types of host and favorable are the same ")
|
@@ -156,7 +154,6 @@ module OneTouch
|
|
156
154
|
end
|
157
155
|
end
|
158
156
|
|
159
|
-
# TODO: how to reslove two or more hook
|
160
157
|
def context_relation_hook
|
161
158
|
context_relation.each do |key,contexts|
|
162
159
|
if contexts.include? context.to_sym
|
@@ -10,17 +10,26 @@ module OneTouch
|
|
10
10
|
# when User as favorable, defined a method called favorable_context_as, here define another method to distinct the former
|
11
11
|
scope :host_context_as, lambda { |context| joins(:favors).where(favor_class.table_name.to_sym => { :context => context } ) }
|
12
12
|
|
13
|
-
if favor_class.respond_to? :host_relation_type # means favor class has load
|
13
|
+
if favor_class.respond_to? :host_relation_type # means favor class has load model ActsAsFavor
|
14
14
|
build_context_klass_methods
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
19
|
|
20
|
+
# TODO
|
21
|
+
# favor_to(@favorable, focus) could extend to focus_to(@favorable)
|
22
|
+
# favor_to(@favorable, like) could extend to like_to(@favorable)
|
23
|
+
# means add more dynamic methods relies on context
|
24
|
+
# Ex:
|
25
|
+
# User.favor_to(@user1, :follow)
|
26
|
+
# => return guys(an ActiveRelation object) who follows @user1, so you can define fans
|
20
27
|
def favor_to(favorable,context=default_context_in_host)
|
21
28
|
host_context_as(context).merge(Favor.favorable_as favorable)
|
22
29
|
end
|
23
30
|
|
31
|
+
# Programmer Doc
|
32
|
+
# This method is not used in otherwhere
|
24
33
|
def cached_favor_to(favorable,context=default_context_in_host)
|
25
34
|
key = "#{self.name}_favor_to_#{favorable.class.name}_#{favorable.id}_#{context}"
|
26
35
|
Rails.cache.fetch key do
|
@@ -32,6 +41,9 @@ module OneTouch
|
|
32
41
|
build_context_klass_methods
|
33
42
|
end
|
34
43
|
|
44
|
+
# Generate instance methods like
|
45
|
+
# @user.focus_tags
|
46
|
+
# => return a list of tags (ActiveRelation object) that focus by @user
|
35
47
|
def build_context_klass_methods
|
36
48
|
favor_class.cons_context_match.each do |context, klasses|
|
37
49
|
klasses.each do |klass|
|
data/lib/one_touch/version.rb
CHANGED
data/lib/one_touch.rb
CHANGED
data/one_touch.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["raykin"]
|
9
9
|
s.email = ["raykincoldxiao@gmail.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{ It is used for recording
|
11
|
+
s.summary = %q{ It is used for recording relations between resources }
|
12
12
|
s.description = %q{ Make one click operation simple }
|
13
13
|
|
14
14
|
s.rubyforge_project = "one_touch"
|
data/readme.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
### Intro
|
2
2
|
In webapp, many data is generated by just one click like focus someone, dislike some post.This gem make it easy.
|
3
3
|
|
4
|
-
These one click data most
|
5
|
-
|
6
|
-
Version ~> 1.1.0 has a serious bug. Please update to ~> 1.2.0
|
4
|
+
These one click data are most relation data and will be managed in single model in this gem. So we can analyze the relation data easily.
|
7
5
|
|
8
6
|
## Dependency
|
9
|
-
Rails > 3.0
|
10
|
-
|
7
|
+
Rails > 3.0
|
8
|
+
|
9
|
+
Conflict with gem meta_where and squeel.
|
11
10
|
|
12
11
|
## Usage
|
13
12
|
gem install one_touch
|
@@ -36,7 +35,8 @@ The generated relations between them are:
|
|
36
35
|
Favor belongs_to :host, :class_name => "User"; belongs_to :favorable, :polymorphic => true
|
37
36
|
This is default setting.
|
38
37
|
|
39
|
-
You can define the relation by yourself
|
38
|
+
You can define the relation by yourself and also define the favors columns to
|
39
|
+
make them match the relation.
|
40
40
|
|
41
41
|
class Favor
|
42
42
|
belongs_to :host, :polymorphic => true
|
@@ -44,25 +44,28 @@ You can define the relation by yourself.
|
|
44
44
|
acts_as_favor :no_default_relations => true
|
45
45
|
end
|
46
46
|
|
47
|
+
In this case, favors columns are id, host_id, host_type, favorable_id,
|
48
|
+
favorable_type and context.
|
49
|
+
|
47
50
|
Make sure the relation name are host and favorable, they can not be changed
|
48
51
|
|
49
52
|
Or you want Favor model to be another name, Bridge.
|
50
53
|
|
51
54
|
class User
|
52
|
-
as_favor_host :
|
55
|
+
as_favor_host :bridge_klass => :Bridge
|
53
56
|
end
|
54
57
|
|
55
58
|
In short, there are four relation names can not be configured, favors, be_favors, host and favorable.
|
56
|
-
And if you change the Favor model name, make sure it consists in
|
59
|
+
And if you change the Favor model name, make sure it consists in whole applications.
|
57
60
|
|
58
61
|
## Features
|
59
62
|
Favor.add_context and Favor.del_context can add or del favors. Ex:
|
60
63
|
|
61
64
|
# add a record that @host focus on @favorable
|
62
65
|
Favor.add_focus(@host, @favorable)
|
63
|
-
#=> return @favor object, @favor.
|
66
|
+
#=> return @favor object, @favor.valid? returns false if add favor was failed
|
64
67
|
|
65
|
-
####In version 1.3.0, add_focus
|
68
|
+
#### In version 1.3.0, add_focus was changed a little. And a new method add_focus! has added.
|
66
69
|
|
67
70
|
Favor.add_focus!(@host, @favorable)
|
68
71
|
#=> raise exception when add was failed
|
@@ -115,17 +118,16 @@ This means @user1 is more close to @user2 than @user3.Maybe the answers that @us
|
|
115
118
|
Because We create or delete data in one click. No Form Needed.
|
116
119
|
|
117
120
|
### TODO
|
118
|
-
Change the dependency meta_where to squeel and make it support Rails3.1.
|
119
|
-
|
120
121
|
Add cache to favored_by, favor_to.
|
121
122
|
|
122
123
|
Add a generator to make install faster.
|
123
124
|
|
124
125
|
Add another gem to supply view and controller template.
|
125
126
|
|
127
|
+
Add travis support
|
126
128
|
### Abstract Requirement
|
127
129
|
Connect any two resource in one model.
|
128
130
|
I really want to implement this gem as more abstract requirement.That means four relation names can be configured, But's not easy.
|
129
131
|
|
130
132
|
### License
|
131
|
-
MIT
|
133
|
+
MIT
|
@@ -0,0 +1,45 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'one_touch'
|
3
|
+
|
4
|
+
class Bridge; end
|
5
|
+
|
6
|
+
class Favor; end
|
7
|
+
|
8
|
+
class User
|
9
|
+
include OneTouch::PortBuild
|
10
|
+
end
|
11
|
+
|
12
|
+
class Admin; include OneTouch::PortBuild; end
|
13
|
+
|
14
|
+
class Post; end
|
15
|
+
|
16
|
+
class Comment; end
|
17
|
+
|
18
|
+
class Port; end
|
19
|
+
|
20
|
+
User.append_relation(bridge_klass: 'Favor', portname: :host)
|
21
|
+
Admin.append_relation(bridge_klass: 'Favor', portname: :host)
|
22
|
+
|
23
|
+
describe OneTouch::RelationRecorder do
|
24
|
+
|
25
|
+
it "add an instance of RelationRecorder which bridge_klass is 'Favor'" do
|
26
|
+
OneTouch::RelationRecorder.find('Favor').port_group.should eq(host: [:User, :Admin])
|
27
|
+
User.favor_class.should eq(Favor)
|
28
|
+
end
|
29
|
+
|
30
|
+
it " user's port name on Favor is host" do
|
31
|
+
User.new.portname_on(:Favor).should eq([:host])
|
32
|
+
end
|
33
|
+
|
34
|
+
it " host port_group are User and Admin" do
|
35
|
+
OneTouch::RelationRecorder.find(:Favor).port_group[:host].should eq([:User, :Admin])
|
36
|
+
end
|
37
|
+
|
38
|
+
it " add bridge_class when include OneTouch::Bridge into Favor class" do
|
39
|
+
Favor.class_eval do
|
40
|
+
include OneTouch::Bridge
|
41
|
+
end
|
42
|
+
OneTouch::RelationRecorder.find(:Favor).bridge_class.should eq(Favor)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -5,11 +5,8 @@ describe OneTouch::AsFavorHost do
|
|
5
5
|
include OneTouch::LoadTestData
|
6
6
|
context "foo" do
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
foo.should respond_to method_name
|
11
|
-
ActiveRecord::Base.should_not respond_to method_name
|
12
|
-
end
|
8
|
+
it "foo should response to focus_tags" do
|
9
|
+
foo.should respond_to :focus_tags
|
13
10
|
end
|
14
11
|
|
15
12
|
it "should find a favor on afavor" do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,6 @@ require 'rails'
|
|
4
4
|
require 'one_touch'
|
5
5
|
|
6
6
|
require File.join(File.dirname(__FILE__), 'fake_app')
|
7
|
-
# require 'squeel'
|
8
7
|
require 'rspec/rails'
|
9
8
|
require 'models/load_test_data'
|
10
9
|
|
@@ -16,10 +15,6 @@ RSpec.configure do |config|
|
|
16
15
|
#CreateAllTables.down if ActiveRecord::Base.connection.table_exists? 'favors'
|
17
16
|
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'favors'
|
18
17
|
|
19
|
-
# Squeel.configure do |config|
|
20
|
-
# config.load_core_extensions :hash, :symbol
|
21
|
-
# end
|
22
|
-
|
23
18
|
Tag.as_favorable
|
24
19
|
|
25
20
|
User.as_favor_host
|
@@ -33,4 +28,3 @@ RSpec.configure do |config|
|
|
33
28
|
# relation should be in another module
|
34
29
|
end
|
35
30
|
end
|
36
|
-
|
metadata
CHANGED
@@ -1,39 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: one_touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- raykin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>'
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>'
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rails
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>'
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '3.0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>'
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: ' Make one click operation simple '
|
37
42
|
email:
|
38
43
|
- raykincoldxiao@gmail.com
|
39
44
|
executables: []
|
@@ -44,6 +49,7 @@ files:
|
|
44
49
|
- Gemfile
|
45
50
|
- Rakefile
|
46
51
|
- lib/one_touch.rb
|
52
|
+
- lib/one_touch/core/bridge.rb
|
47
53
|
- lib/one_touch/engine.rb
|
48
54
|
- lib/one_touch/models/active_record_extension.rb
|
49
55
|
- lib/one_touch/models/acts_as_favor.rb
|
@@ -57,6 +63,7 @@ files:
|
|
57
63
|
- lib/one_touch/version.rb
|
58
64
|
- one_touch.gemspec
|
59
65
|
- readme.md
|
66
|
+
- spec/core/relation_recorder_spec.rb
|
60
67
|
- spec/fake_app.rb
|
61
68
|
- spec/models/acts_as_favor_spec.rb
|
62
69
|
- spec/models/array_spec.rb
|
@@ -66,27 +73,25 @@ files:
|
|
66
73
|
- spec/spec_helper.rb
|
67
74
|
homepage: ''
|
68
75
|
licenses: []
|
76
|
+
metadata: {}
|
69
77
|
post_install_message:
|
70
78
|
rdoc_options: []
|
71
79
|
require_paths:
|
72
80
|
- lib
|
73
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
82
|
requirements:
|
76
|
-
- -
|
83
|
+
- - '>='
|
77
84
|
- !ruby/object:Gem::Version
|
78
85
|
version: '0'
|
79
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
87
|
requirements:
|
82
|
-
- -
|
88
|
+
- - '>='
|
83
89
|
- !ruby/object:Gem::Version
|
84
90
|
version: '0'
|
85
91
|
requirements: []
|
86
92
|
rubyforge_project: one_touch
|
87
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.0
|
88
94
|
signing_key:
|
89
|
-
specification_version:
|
90
|
-
summary: It is used for recording
|
95
|
+
specification_version: 4
|
96
|
+
summary: It is used for recording relations between resources
|
91
97
|
test_files: []
|
92
|
-
has_rdoc:
|