acts_as_amico 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -191,7 +191,7 @@ this will cause a ```SystemStackError: stack level too deep``` because acts_as_a
191
191
  the Rails::Object#send method to get the key, and for some reason if the send method even
192
192
  *touches* the string/symbol "name" we get cascaded through the object graph.
193
193
 
194
- ## Documentation
194
+ ## Documentation
195
195
 
196
196
  Acts_as_amico is feature complete with the amico gem. [The Amico API usage page](https://github.com/mettadore/amico/blob/master/API.md)
197
197
  shows a more complete suite of methods. The source for the [Amico relationships module](https://github.com/agoragames/amico/blob/master/lib/amico/relationships.rb)
@@ -6,28 +6,28 @@ module ActsAsAmico
6
6
  end
7
7
 
8
8
  module ClassMethods
9
-
10
9
  def amico_key
11
10
  @amico_key ||= :id
12
11
  end
13
- def amico_key= value
14
- @amico_key = value
15
- end
16
12
 
17
13
  def acts_as_amico *args
18
14
  options = args.extract_options!
19
15
  options.assert_valid_keys(:amico_key)
20
- @amico_key = options[:amico_key] ? options[:amico_key] : :id
16
+ @amico_key = options[:amico_key]
21
17
  include ActsAsAmico::AmicoObject::InstanceMethods
22
18
  end
23
19
  end
24
20
 
25
21
  module InstanceMethods
26
22
 
23
+ def amico_key
24
+ self.send(self.class.amico_key)
25
+ end
26
+
27
27
  def method_missing(sym, *args, &block)
28
28
  if Amico.respond_to? sym
29
- args[0] = args[0].send(args[0].class.amico_key) if not args[0].nil? and args[0].respond_to?(:id)
30
- args.unshift(self.send(self.class.amico_key))
29
+ args[0] = args[0].amico_key if not args[0].nil? and args[0].respond_to?(:amico_key)
30
+ args.unshift(amico_key)
31
31
  if sym.nil?
32
32
  Amico.send(*args, &block)
33
33
  else
@@ -42,21 +42,26 @@ module ActsAsAmico
42
42
  pass_sym_to_amico(sym) || super(sym)
43
43
  end
44
44
 
45
+ def followers options = {}
46
+ key = options[:scope] || Amico.default_scope_key
47
+ Amico.followers(amico_key, options, key)
48
+ end
49
+
45
50
  # Named destructive methods
46
51
  def follow! obj, *args
47
- Amico.follow(self.send(self.class.amico_key), obj.send(obj.class.amico_key), *args)
52
+ Amico.follow(amico_key, obj.amico_key, *args)
48
53
  end
49
54
  def unfollow! obj, *args
50
- Amico.unfollow(self.send(self.class.amico_key), obj.send(obj.class.amico_key), *args)
55
+ Amico.unfollow(amico_key, obj.amico_key, *args)
51
56
  end
52
57
  def accept! obj, *args
53
- Amico.accept(self.send(self.class.amico_key), obj.send(obj.class.amico_key), *args)
58
+ Amico.accept(amico_key, obj.amico_key, *args)
54
59
  end
55
60
  def block! obj, *args
56
- Amico.block(self.send(self.class.amico_key), obj.send(obj.class.amico_key), *args)
61
+ Amico.block(amico_key, obj.amico_key, *args)
57
62
  end
58
63
  def unblock! obj, *args
59
- Amico.unblock(self.send(self.class.amico_key), obj.send(obj.class.amico_key), *args)
64
+ Amico.unblock(amico_key, obj.amico_key, *args)
60
65
  end
61
66
 
62
67
  private
@@ -1,3 +1,3 @@
1
1
  module ActsAsAmico
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -24,14 +24,26 @@ describe ActsAsAmico do
24
24
  @rest_object = RestObject.find(321)
25
25
  end
26
26
 
27
+ it "Should respond to amico_key on the class" do
28
+ RestObject.respond_to?(:amico_key).should be_true
29
+ end
30
+ it "should set the amico_key on the class" do
31
+ RestObject.amico_key.should be(:title)
32
+ end
33
+
27
34
  it "should hold an amico_key" do
28
- @rest_object.class.amico_key.should eq(:title)
35
+ @rest_object.amico_key.should eq("Blah")
29
36
  end
30
37
 
38
+ it "should follow" do
39
+ @usera.follow! @admin, 'admin'
40
+ @usera.following?(@admin, 'admin').should be_true
41
+ @admin.followers(:scope => 'admin').include?(@usera.amico_key.to_s).should be_true
42
+ end
31
43
  it "should allow following an ActiveResource object" do
32
44
  @usera.follow! @rest_object, 'rest_object'
33
- # @usera.following?(@rest_object).should be_true
45
+ @usera.following?(@rest_object, 'rest_object').should be_true
34
46
 
35
- # @rest_object.followers.include?(@usera.id).should be_true
47
+ @rest_object.followers(:scope => 'rest_object').include?(@usera.amico_key.to_s).should be_true
36
48
  end
37
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_amico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70359781092880 !ruby/object:Gem::Requirement
16
+ requirement: &70349693755600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70359781092880
24
+ version_requirements: *70349693755600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: amico
27
- requirement: &70359781091320 !ruby/object:Gem::Requirement
27
+ requirement: &70349693752680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70359781091320
35
+ version_requirements: *70349693752680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70359781106060 !ruby/object:Gem::Requirement
38
+ requirement: &70349693763920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.1.1
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70359781106060
46
+ version_requirements: *70349693763920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &70359781104940 !ruby/object:Gem::Requirement
49
+ requirement: &70349693762520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70359781104940
57
+ version_requirements: *70349693762520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &70359781103180 !ruby/object:Gem::Requirement
60
+ requirement: &70349693761600 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70359781103180
68
+ version_requirements: *70349693761600
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: factory_girl_rails
71
- requirement: &70359781101740 !ruby/object:Gem::Requirement
71
+ requirement: &70349693759660 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70359781101740
79
+ version_requirements: *70349693759660
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fakeweb
82
- requirement: &70359781098780 !ruby/object:Gem::Requirement
82
+ requirement: &70349693757560 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70359781098780
90
+ version_requirements: *70349693757560
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: uuidtools
93
- requirement: &70359781114500 !ruby/object:Gem::Requirement
93
+ requirement: &70349693772320 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70359781114500
101
+ version_requirements: *70349693772320
102
102
  description: Rails injectable Relationships (e.g. friendships) backed by Redis
103
103
  email:
104
104
  - mail@johnmetta.com