emotions 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,51 +2,53 @@ module Emotions
2
2
  module Emotional
3
3
  extend ActiveSupport::Concern
4
4
 
5
- module ClassMethods
6
- def acts_as_emotional
7
- has_many :emotions, as: :emotional, class_name: 'Emotions::Emotion'
5
+ included do
6
+ has_many :emotions, as: :emotional, class_name: 'Emotions::Emotion'
7
+
8
+ Emotions.emotions.each do |emotion|
9
+ define_emotion_methods(emotion)
10
+ end
11
+ end
12
+
13
+ def _emotions_about(emotive)
14
+ self.emotions.where(emotive_id: emotive.id, emotive_type: emotive.class.name)
15
+ end
16
+
17
+ def emotions_about(emotive)
18
+ _emotions_about(emotive).map(&:emotion).map(&:to_sym)
19
+ end
8
20
 
21
+ def express!(emotion, emotive)
22
+ send("#{emotion}_about!", emotive)
23
+ end
24
+
25
+ def no_longer_express!(emotion, emotive)
26
+ send("no_longer_#{emotion}_about!", emotive)
27
+ end
28
+
29
+ module ClassMethods
30
+ def define_emotion_methods(emotion)
9
31
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
10
- def _emotions_about(emotive)
11
- self.emotions.where(emotive_id: emotive.id, emotive_type: emotive.class.name)
32
+ def #{emotion}_about?(emotive)
33
+ #{emotion}_about(emotive).exists?
12
34
  end
13
35
 
14
- def emotions_about(emotive)
15
- _emotions_about(emotive).map(&:emotion).map(&:to_sym)
36
+ def #{emotion}_about?(emotive)
37
+ #{emotion}_about(emotive).exists?
16
38
  end
17
39
 
18
- def express!(emotion, emotive)
19
- send("\#{emotion}_about!", emotive)
40
+ def #{emotion}_about!(emotive)
41
+ #{emotion}_about(emotive).first_or_create!
20
42
  end
21
43
 
22
- def no_longer_express!(emotion, emotive)
23
- send("no_longer_\#{emotion}_about!", emotive)
44
+ def no_longer_#{emotion}_about!(emotive)
45
+ #{emotion}_about(emotive).destroy_all
24
46
  end
25
- RUBY
26
47
 
27
- Emotions.emotions.each do |emotion|
28
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
- def #{emotion}_about?(emotive)
30
- #{emotion}_about(emotive).exists?
31
- end
32
-
33
- def #{emotion}_about?(emotive)
34
- #{emotion}_about(emotive).exists?
35
- end
36
-
37
- def #{emotion}_about!(emotive)
38
- #{emotion}_about(emotive).first_or_create!
39
- end
40
-
41
- def no_longer_#{emotion}_about!(emotive)
42
- #{emotion}_about(emotive).destroy
43
- end
44
-
45
- def #{emotion}_about(emotive)
46
- _emotions_about(emotive).where(emotion: #{emotion.to_s.inspect})
47
- end
48
- RUBY
49
- end
48
+ def #{emotion}_about(emotive)
49
+ _emotions_about(emotive).where(emotion: #{emotion.to_s.inspect})
50
+ end
51
+ RUBY
50
52
  end
51
53
  end
52
54
  end
@@ -2,23 +2,25 @@ module Emotions
2
2
  module Emotive
3
3
  extend ActiveSupport::Concern
4
4
 
5
- module ClassMethods
6
- def acts_as_emotive
7
- has_many :emotions, as: :emotive, class_name: 'Emotions::Emotion'
5
+ included do
6
+ has_many :emotions, as: :emotive, class_name: 'Emotions::Emotion'
7
+
8
+ Emotions.emotions.each do |emotion|
9
+ define_emotion_methods(emotion)
10
+ end
11
+ end
8
12
 
13
+ def emotional_about
14
+ self.emotions.includes(:emotional)
15
+ end
16
+
17
+ module ClassMethods
18
+ def define_emotion_methods(emotion)
9
19
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
10
- def emotional_about
11
- self.emotions.includes(:emotional)
20
+ def #{emotion}_about
21
+ emotional_about.where(emotion: #{emotion.to_s.inspect})
12
22
  end
13
23
  RUBY
14
-
15
- Emotions.emotions.each do |emotion|
16
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
17
- def #{emotion}_about
18
- emotional_about.where(emotion: #{emotion.to_s.inspect})
19
- end
20
- RUBY
21
- end
22
24
  end
23
25
  end
24
26
  end
@@ -5,8 +5,13 @@ module Emotions
5
5
  class Railtie < Rails::Railtie
6
6
  initializer "emotions.active_record" do |app|
7
7
  ActiveSupport.on_load :active_record do
8
- include Emotions::Emotive
9
- include Emotions::Emotional
8
+ def self.acts_as_emotive
9
+ self.send :include, Emotions::Emotive
10
+ end
11
+
12
+ def self.acts_as_emotional
13
+ self.send :include, Emotions::Emotional
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -1,3 +1,3 @@
1
1
  module Emotions
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emotions
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
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-05-20 00:00:00.000000000 Z
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: -16871718108920318
100
+ hash: -4058484285824368663
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -16871718108920318
109
+ hash: -4058484285824368663
110
110
  requirements: []
111
111
  rubyforge_project:
112
112
  rubygems_version: 1.8.23