emotions 0.2.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3ae5e838c6776b24d5c8f2cfaacc928561feb1d
4
+ data.tar.gz: 68c6d7912a1b2ac6ae002620738d54e9779bb824
5
+ SHA512:
6
+ metadata.gz: 18c67e3d42f3651fc1b93a81bc9929e615baa0f4dac1f28ca29e705c215c9e511c8491cf247cd857ce79b67b7ce5bd434b7f2949f3b4efb62bebe1b606f4bbc4
7
+ data.tar.gz: 04abf2116166994f2e5198b39b12403b9066bac12d208416da9ba345d83c3a84de5e94c87f31e7f98045585c3b2726000681217e363543b09e232a533b3db17e
@@ -5,3 +5,11 @@ rvm:
5
5
  - 1.9.3
6
6
 
7
7
  script: "echo 'DO IT' && bundle exec rake spec"
8
+
9
+ notifications:
10
+ hipchat:
11
+ rooms:
12
+ secure: "a2x/YxxMGECIjhHO8xeTKJy4R1sKEqae/F/Ufg/KJFSuZ86UAraTKTsk8cLzU+pv/G59MxMmaRsMqoT9KhiGpOPILC0p/JlIlSHt39+wkoAxE3t0J0Lf6Ywzk3t7KC2RmyYvhlbEeKIGBYfkf51RdxWa1lHG0/hO6jWlxNnNOTw="
13
+ template:
14
+ - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Build</a>/<a href="%{compare_url}">Changes</a>)'
15
+ format: 'html'
data/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
  <br />
6
6
  Emotions is a Ruby library that allows ActiveRecord records to<br /> express (and hopefully store) emotions about other records.
7
7
  <br /><br />
8
- <a href="https://rubygems.org/gems/emotions"><img src="https://badge.fury.io/rb/emotions.png" /></a>
9
- <a href="https://codeclimate.com/github/mirego/emotions"><img src="https://codeclimate.com/github/mirego/emotions.png" /></a>
10
- <a href="https://travis-ci.org/mirego/emotions"><img src="https://travis-ci.org/mirego/emotions.png?branch=master" /></a>
8
+ <a href="https://rubygems.org/gems/emotions"><img src="http://img.shields.io/gem/v/emotions.svg" /></a>
9
+ <a href="https://codeclimate.com/github/mirego/emotions"><img src="http://img.shields.io/codeclimate/github/mirego/emotions.svg" /></a>
10
+ <a href="https://travis-ci.org/mirego/emotions"><img src="http://img.shields.io/travis/mirego/emotions.svg" /></a>
11
11
  </p>
12
12
 
13
13
  ---
@@ -26,7 +26,7 @@ And then execute:
26
26
  $ bundle
27
27
  ```
28
28
 
29
- Run the migration to add the `emotions` table:
29
+ Run the migration to add the `emotions` table and the `Emotion` model:
30
30
 
31
31
  ```bash
32
32
  $ rails generate emotions:install
@@ -80,9 +80,11 @@ user.sad_about?(picure)
80
80
  # => true
81
81
  ```
82
82
 
83
+ ## Cache counters
84
+
83
85
  Most of the times, you would want to get a quick look at about how many users expressed a certain emotion towards a certain picture. That could be an expensive operation.
84
86
 
85
- However, if the *emotive* record has an `<emotion>_emotions_count` column, Emotions will populate its value with how many users expressed that emotion towards it.
87
+ However, if the *emotive* record has an `<emotion>_emotions_count` column, Emotions will populate its value with how many emotional records expressed that emotion towards it.
86
88
 
87
89
  ```ruby
88
90
  user.happy_about!(picture)
@@ -94,7 +96,7 @@ picture.happy_emotions_count
94
96
  # Quick lookup into the column and returns `1`
95
97
  ```
96
98
 
97
- Same thing for emotional records. If there’s a `happy_emotions_count` column in the `User` model, Emotions will update it each time a record expresses a happy emotion towards another record.
99
+ Same thing for emotional records. If there’s a `<emotion>_emotions_count` column in the emotional model, Emotions will update it each time one of its records expresses that emotion towards another record.
98
100
 
99
101
  ```ruby
100
102
  user.happy_about!(picture)
@@ -112,6 +114,6 @@ user.happy_emotions_count
112
114
 
113
115
  ## About Mirego
114
116
 
115
- Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
117
+ [Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).
116
118
 
117
- We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
119
+ We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
@@ -27,6 +27,10 @@ module Emotions
27
27
  self.send :include, Emotions::Emotional
28
28
  end
29
29
 
30
+ def self.acts_as_emotion
31
+ self.send :include, Emotions::Emotion
32
+ end
33
+
30
34
  def self.emotional?
31
35
  @emotional ||= self.ancestors.include?(Emotions::Emotional)
32
36
  end
@@ -1,23 +1,25 @@
1
1
  module Emotions
2
- class Emotion < ActiveRecord::Base
3
- self.table_name = 'emotions'
4
-
5
- # Validations
6
- validates :emotional, presence: true
7
- validates :emotive, presence: true
8
-
9
- # Custom validations
10
- validate :ensure_valid_emotion_name
11
- validate { ensure_valid_associated_record :emotional }
12
- validate { ensure_valid_associated_record :emotive }
13
-
14
- # Associations
15
- belongs_to :emotional, polymorphic: true
16
- belongs_to :emotive, polymorphic: true
17
-
18
- # Callbacks
19
- after_create :update_emotion_counter
20
- after_destroy :update_emotion_counter
2
+ module Emotion
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # Validations
7
+ validates :emotional, presence: true
8
+ validates :emotive, presence: true
9
+
10
+ # Custom validations
11
+ validate :ensure_valid_emotion_name
12
+ validate { ensure_valid_associated_record :emotional }
13
+ validate { ensure_valid_associated_record :emotive }
14
+
15
+ # Associations
16
+ belongs_to :emotional, polymorphic: true
17
+ belongs_to :emotive, polymorphic: true
18
+
19
+ # Callbacks
20
+ after_create :update_emotion_counter
21
+ after_destroy :update_emotion_counter
22
+ end
21
23
 
22
24
  protected
23
25
 
@@ -3,7 +3,7 @@ module Emotions
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- has_many :emotions, as: :emotional, class_name: 'Emotions::Emotion', dependent: :destroy
6
+ has_many :emotions, as: :emotional, class_name: '::Emotion', dependent: :destroy
7
7
 
8
8
  Emotions.emotions.each do |emotion|
9
9
  define_emotion_methods(emotion)
@@ -3,7 +3,7 @@ module Emotions
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- has_many :emotions, as: :emotive, class_name: 'Emotions::Emotion', dependent: :destroy
6
+ has_many :emotions, as: :emotive, class_name: '::Emotion', dependent: :destroy
7
7
 
8
8
  Emotions.emotions.each do |emotion|
9
9
  define_emotion_methods(emotion)
@@ -1,3 +1,3 @@
1
1
  module Emotions
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3'
3
3
  end
@@ -20,6 +20,10 @@ module Emotions
20
20
  def create_migration_file
21
21
  migration_template 'migration.rb', 'db/migrate/add_emotions.rb'
22
22
  end
23
+
24
+ def create_model_file
25
+ template "model.rb", "app/models/emotion.rb"
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -0,0 +1,3 @@
1
+ class Emotion < ActiveRecord::Base
2
+ acts_as_emotion
3
+ end
@@ -18,7 +18,7 @@ describe Emotions::Emotion do
18
18
 
19
19
  describe :Validations do
20
20
  describe :validate_presence_of_emotional do
21
- subject { described_class.new(emotion: 'happy', emotive: Picture.create) }
21
+ subject { Emotion.new(emotion: 'happy', emotive: Picture.create) }
22
22
  before { subject.valid? }
23
23
 
24
24
  it { should_not be_valid }
@@ -26,7 +26,7 @@ describe Emotions::Emotion do
26
26
  end
27
27
 
28
28
  describe :validate_presence_of_emotive do
29
- subject { described_class.new(emotion: 'happy', emotional: User.create) }
29
+ subject { Emotion.new(emotion: 'happy', emotional: User.create) }
30
30
  before { subject.valid? }
31
31
 
32
32
  it { should_not be_valid }
@@ -34,7 +34,7 @@ describe Emotions::Emotion do
34
34
  end
35
35
 
36
36
  describe :validate_inclusion_of_emotion do
37
- subject { described_class.new(emotion: 'mad', emotional: User.create, emotive: Picture.create) }
37
+ subject { Emotion.new(emotion: 'mad', emotional: User.create, emotive: Picture.create) }
38
38
  before { subject.valid? }
39
39
 
40
40
  it { should_not be_valid }
@@ -42,7 +42,7 @@ describe Emotions::Emotion do
42
42
  end
43
43
 
44
44
  describe :validate_class_of_emotive do
45
- subject { described_class.new(emotion: 'happy', emotional: User.create, emotive: User.create) }
45
+ subject { Emotion.new(emotion: 'happy', emotional: User.create, emotive: User.create) }
46
46
  before { subject.valid? }
47
47
 
48
48
  it { should_not be_valid }
@@ -50,7 +50,7 @@ describe Emotions::Emotion do
50
50
  end
51
51
 
52
52
  describe :validate_class_of_emotional do
53
- subject { described_class.new(emotion: 'happy', emotional: Picture.create, emotive: Picture.create) }
53
+ subject { Emotion.new(emotion: 'happy', emotional: Picture.create, emotive: Picture.create) }
54
54
  before { subject.valid? }
55
55
 
56
56
  it { should_not be_valid }
@@ -62,7 +62,7 @@ describe Emotions::Emotion do
62
62
  describe :update_emotion_counter_on_create do
63
63
  let(:picture) { Picture.create }
64
64
  let(:user) { User.create }
65
- let(:emotion) { described_class.new(emotion: 'happy', emotional: user, emotive: picture) }
65
+ let(:emotion) { Emotion.new(emotion: 'happy', emotional: user, emotive: picture) }
66
66
 
67
67
  before do
68
68
  picture.should_receive(:update_emotion_counter).with('happy').once
@@ -76,7 +76,7 @@ describe Emotions::Emotion do
76
76
  describe :update_emotion_counter_on_destroy do
77
77
  let(:picture) { Picture.create }
78
78
  let(:user) { User.create }
79
- let(:emotion) { described_class.new(emotion: 'happy', emotional: user, emotive: picture) }
79
+ let(:emotion) { Emotion.new(emotion: 'happy', emotional: user, emotive: picture) }
80
80
 
81
81
  before do
82
82
  emotion.save!
@@ -67,7 +67,7 @@ describe Emotions::Emotional do
67
67
  let(:picture) { Picture.create }
68
68
 
69
69
  context 'with valid emotive and emotion' do
70
- it { expect{ user.express! :happy, picture }.to change{ Emotions::Emotion.count }.from(0).to(1) }
70
+ it { expect{ user.express! :happy, picture }.to change{ Emotion.count }.from(0).to(1) }
71
71
  it { expect{ user.express! :happy, picture }.to change{ user.happy_about? picture }.from(false).to(true) }
72
72
  end
73
73
 
@@ -85,7 +85,7 @@ describe Emotions::Emotional do
85
85
  before { user.happy_about!(picture) }
86
86
 
87
87
  context 'with valid emotive and emotion' do
88
- it { expect{ user.no_longer_express! :happy, picture }.to change{ Emotions::Emotion.count }.from(1).to(0) }
88
+ it { expect{ user.no_longer_express! :happy, picture }.to change{ Emotion.count }.from(1).to(0) }
89
89
  it { expect{ user.no_longer_express! :happy, picture }.to change{ user.happy_about? picture }.from(true).to(false) }
90
90
  end
91
91
 
@@ -118,8 +118,7 @@ describe Emotions::Emotional do
118
118
  let(:picture) { Picture.create }
119
119
 
120
120
  context 'with valid emotive' do
121
- it { expect(user.happy_about! picture).to be_instance_of(Emotions::Emotion) }
122
- it { expect{ user.happy_about! picture }.to change{ Emotions::Emotion.count }.from(0).to(1) }
121
+ it { expect{ user.happy_about! picture }.to change{ Emotion.count }.from(0).to(1) }
123
122
  it { expect{ user.happy_about! picture }.to change{ user.happy_about? picture }.from(false).to(true) }
124
123
  end
125
124
 
@@ -133,8 +132,7 @@ describe Emotions::Emotional do
133
132
  let(:picture) { Picture.create }
134
133
 
135
134
  context 'with valid emotive' do
136
- it { expect(user.no_longer_happy_about! picture).to be_instance_of(Emotions::Emotion) }
137
- it { expect{ user.no_longer_happy_about! picture }.to change{ Emotions::Emotion.count }.from(1).to(0) }
135
+ it { expect{ user.no_longer_happy_about! picture }.to change{ Emotion.count }.from(1).to(0) }
138
136
  it { expect{ user.no_longer_happy_about! picture }.to change{ user.happy_about? picture }.from(true).to(false) }
139
137
  end
140
138
 
@@ -22,6 +22,11 @@ RSpec.configure do |config|
22
22
 
23
23
  # Run our migration
24
24
  run_default_migration
25
+
26
+ # Create Emotion model
27
+ spawn_model 'Emotion', ActiveRecord::Base do
28
+ acts_as_emotion
29
+ end
25
30
  end
26
31
 
27
32
  config.after(:each) do
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emotions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: '0.3'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rémi Prévost
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.3'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.3'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '2.13'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '2.13'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: sqlite3
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: '1.3'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: '1.3'
94
83
  description: Emotions is a Ruby library that allows ActiveRecord records to express
@@ -99,9 +88,9 @@ executables: []
99
88
  extensions: []
100
89
  extra_rdoc_files: []
101
90
  files:
102
- - .gitignore
103
- - .rspec
104
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
105
94
  - Gemfile
106
95
  - LICENSE.md
107
96
  - README.md
@@ -117,6 +106,7 @@ files:
117
106
  - lib/generators/emotions/USAGE
118
107
  - lib/generators/emotions/install_generator.rb
119
108
  - lib/generators/emotions/templates/migration.rb
109
+ - lib/generators/emotions/templates/model.rb
120
110
  - spec/emotions/emotion_spec.rb
121
111
  - spec/emotions/emotional_spec.rb
122
112
  - spec/emotions/emotive_spec.rb
@@ -126,33 +116,26 @@ files:
126
116
  homepage: https://github.com/mirego/emotions
127
117
  licenses:
128
118
  - BSD 3-Clause
119
+ metadata: {}
129
120
  post_install_message:
130
121
  rdoc_options: []
131
122
  require_paths:
132
123
  - lib
133
124
  required_ruby_version: !ruby/object:Gem::Requirement
134
- none: false
135
125
  requirements:
136
- - - ! '>='
126
+ - - ">="
137
127
  - !ruby/object:Gem::Version
138
128
  version: '0'
139
- segments:
140
- - 0
141
- hash: 4067111532583262534
142
129
  required_rubygems_version: !ruby/object:Gem::Requirement
143
- none: false
144
130
  requirements:
145
- - - ! '>='
131
+ - - ">="
146
132
  - !ruby/object:Gem::Version
147
133
  version: '0'
148
- segments:
149
- - 0
150
- hash: 4067111532583262534
151
134
  requirements: []
152
135
  rubyforge_project:
153
- rubygems_version: 1.8.23
136
+ rubygems_version: 2.2.2
154
137
  signing_key:
155
- specification_version: 3
138
+ specification_version: 4
156
139
  summary: Emotions is a Ruby library that allows ActiveRecord records to express (and
157
140
  hopefully store) emotions about other records.
158
141
  test_files: