mongoid-doable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/mongoid/doable.rb +9 -9
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -39,7 +39,7 @@ module Mongoid
39
39
  #
40
40
 
41
41
  def doable(action, options = {})
42
- doer_models[action.to_sym] = (options[:by] || :user).to_s.classify.constantize
42
+ doer_klass_names[action.to_sym] = (options[:by] || :user).to_s.classify
43
43
 
44
44
  action = action.to_s # "like"
45
45
  base_action = (action[-1] == "e" ? action.chop : action) # "lik"
@@ -51,10 +51,10 @@ module Mongoid
51
51
  field field_name, type: Array, default: [], versioned: false # field :likers_ids, type: Array, default: [], versioned: false
52
52
  field counter_field_name, type: Integer, default: 0, versioned: false # field :likers_count, type: Integer, default: 0, versioned: false
53
53
 
54
- define_method "#{doer_action}" do # def likers
55
- klass = self.class.doer_models[action.to_sym] # klass = User
56
- klass.where(:"_id".in => send(field_name)) # klass.where(:likers_ids.in => likers_ids)
57
- end # end
54
+ define_method "#{doer_action}" do # def likers
55
+ klass = self.class.doer_klass_names[action.to_sym].constantize # klass = User
56
+ klass.where(:"_id".in => send(field_name)) # klass.where(:likers_ids.in => likers_ids)
57
+ end # end
58
58
 
59
59
  define_method "#{passive_action}_by?" do |actor| # def liked_by?(actor)
60
60
  return false if actor.blank? # return false if actor.blank?
@@ -93,7 +93,7 @@ module Mongoid
93
93
  field_name = "#{ing_action}_#{target.to_s.pluralize}_ids" # "liking_courses_ids"
94
94
  target_field_name = "#{doer_action}_ids" # "likers_ids"
95
95
  target_counter_name = "#{doer_action}_count" # "likers_count"
96
- klass = (options[:class_name] || target.to_s.classify).constantize # Course
96
+ klass_name = options[:class_name] || target.to_s.classify # "Course"
97
97
 
98
98
  field field_name, type: Array, default: [], versioned: false # field :liking_courses_ids, type Array, default: [], versioned: false
99
99
 
@@ -103,7 +103,7 @@ module Mongoid
103
103
 
104
104
  unless options[:embedded]
105
105
  define_method "#{ing_action}_#{target.to_s.pluralize}" do # def liking_courses
106
- klass.where(:"_id".in => send(field_name)) # Course.where(:liking_courses_ids.in => liking_courses_ids)
106
+ klass_name.constantize.where(:"_id".in => send(field_name)) # Course.where(:liking_courses_ids.in => liking_courses_ids)
107
107
  end # end
108
108
  end
109
109
 
@@ -152,8 +152,8 @@ module Mongoid
152
152
 
153
153
  end
154
154
 
155
- def doer_models # def doer_models
156
- @doer_models ||= {} # @doer_models ||= {}
155
+ def doer_klass_names # def doer_klass_names
156
+ @doer_klass_names ||= {} # @doer_klass_names ||= {}
157
157
  end # end
158
158
 
159
159
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-doable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  segments:
156
156
  - 0
157
- hash: 237706735236724821
157
+ hash: -4458401418309580115
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  none: false
160
160
  requirements: