scoreable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -3,6 +3,9 @@ module Scoreable
3
3
  module GeneratedMethods; end
4
4
 
5
5
  module ClassMethods
6
+ mattr_accessor :score_receiver
7
+ alias_method "#{Scoreable.score_term}_receiver", :score_receiver
8
+
6
9
  ## Scoreable.score_term = 'score'
7
10
  ## use to configure score generation scheme
8
11
  # Example:
@@ -14,37 +17,49 @@ module Scoreable
14
17
  ## generate_score create: { :score: 5, for: :user, callback: :report_score}
15
18
  ##
16
19
  ## You can configure score for multiple method in single call
17
- ## generate_score update: 4, create: 5, upvote: {score: 5, for: :upvoter}
20
+ ## generate_score update: 4, create: 5, upvote: {score: 5, for: :upvoter}
18
21
  ##
19
22
  def generate_score(args)
20
23
  include Scoreable::Generator::InstanceMethods
21
24
 
22
25
  args.keys.each do |action|
23
- score = args[action]
24
- action = action.to_s
26
+ score_config = args[action]
25
27
 
26
- method_without_score_feature = action+"_without_#{Scoreable.score_term}"
27
- method_with_score_feature = action+"_with_#{Scoreable.score_term}"
28
-
29
- Scoreable::Generator::GeneratedMethods.class_eval do
30
- define_method method_with_score_feature.to_sym do
31
- send method_without_score_feature
32
- log_score 5,action, 'user'
33
- end
28
+ if score_config.is_a? Hash
29
+ score = score_config[Scoreable.score_term.to_sym]
30
+ callback_method = score_config[:callback]
31
+ receivers = score_config[:for]
32
+ else
33
+ callback_method = nil
34
+ receivers = [score_receiver]
35
+ score = score_config
34
36
  end
35
- end
37
+ actions = action.is_a?(Array) ? action : [action.to_s]
36
38
 
37
- include Scoreable::Generator::GeneratedMethods
39
+ actions.each do |action|
40
+ action= action.to_s
41
+ method_without_score_feature = action+"_without_#{Scoreable.score_term}"
42
+ method_with_score_feature = action+"_with_#{Scoreable.score_term}"
38
43
 
39
- args.keys.each do |action|
40
- alias_method_chain action, Scoreable.score_term
44
+ Scoreable::Generator::GeneratedMethods.class_eval do
45
+ define_method method_with_score_feature.to_sym do
46
+ send method_without_score_feature
47
+ receivers.each do |receiver|
48
+ score_obj= log_score score,action, receiver
49
+
50
+ send callback_method,score_obj if callback_method
51
+ end
52
+
53
+
54
+ end
55
+ end
56
+
57
+ include Scoreable::Generator::GeneratedMethods
58
+ alias_method_chain action, Scoreable.score_term
59
+ end
41
60
  end
42
61
  end
43
-
44
62
  alias_method "generate_#{Scoreable.score_term}", :generate_score unless respond_to? "generate_#{Scoreable.score_term}"
45
-
46
- mattr_accessor :score_receiver
47
- mattr_accessor "#{Scoreable.score_term}_receiver"
48
63
  end
49
64
 
50
65
  module InstanceMethods
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scoreable}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Naveed Ahmad}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoreable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &76344800 !ruby/object:Gem::Requirement
16
+ requirement: &70464070 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *76344800
24
+ version_requirements: *70464070
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &76344510 !ruby/object:Gem::Requirement
27
+ requirement: &70463720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.12'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *76344510
35
+ version_requirements: *70463720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &76344160 !ruby/object:Gem::Requirement
38
+ requirement: &70463370 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *76344160
46
+ version_requirements: *70463370
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &76343850 !ruby/object:Gem::Requirement
49
+ requirement: &70463030 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.8.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *76343850
57
+ version_requirements: *70463030
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &76343430 !ruby/object:Gem::Requirement
60
+ requirement: &70462760 !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: *76343430
68
+ version_requirements: *70462760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
- requirement: &76343040 !ruby/object:Gem::Requirement
71
+ requirement: &70462350 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *76343040
79
+ version_requirements: *70462350
80
80
  description: longer description of your gem
81
81
  email: naveedahmada036@gmail.com
82
82
  executables: []
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: 915395293
126
+ hash: 1026594223
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements: