minimal_feedback 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .DS_Store
20
+ minimal_feedback.sqlite3
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minimal_feedback.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matteo Depalo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MinimalFeedback
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'minimal_feedback'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install minimal_feedback
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/db/.gitkeep ADDED
File without changes
@@ -0,0 +1,27 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record'
4
+
5
+ class MinimalFeedbackGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ desc "Creates migration files required by minimal feedback machine gem."
9
+
10
+ self.source_paths << File.join(File.dirname(__FILE__), 'templates')
11
+
12
+ def self.next_migration_number(path)
13
+ ActiveRecord::Generators::Base.next_migration_number(path)
14
+ end
15
+
16
+ def create_migration_files
17
+ create_migration_file_if_not_exist 'create_msm_states'
18
+ end
19
+
20
+ private
21
+
22
+ def create_migration_file_if_not_exist(file_name)
23
+ unless self.class.migration_exists?(File.dirname(File.expand_path("db/migrate/#{file_name}")), file_name)
24
+ migration_template "#{file_name}.rb", "db/migrate/#{file_name}.rb"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ class CreateMsmStates < ActiveRecord::Migration
2
+ def change
3
+ create_table :mf_feedbacks do |t|
4
+ t.string :type
5
+ t.integer :rating
6
+ t.references :rateable, :polymorphic => true
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_record'
2
+
3
+ module MinimalFeedback
4
+ class Feedback < ActiveRecord::Base
5
+ self.table_name = 'mf_feedbacks'
6
+
7
+ belongs_to :rateable, :polymorphic => true
8
+
9
+ validates :rating, :inclusion => { :in => [1, -1] }
10
+
11
+ def type
12
+ case rating
13
+ when 1
14
+ :positive
15
+ when -1
16
+ :negative
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module MinimalFeedback
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'minimal_feedback/version'
2
+ require 'minimal_feedback/feedback'
3
+ require 'active_support'
4
+
5
+ module MinimalFeedback
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ has_many :feedbacks, :as => :rateable, :class_name => 'MinimalFeedback::Feedback'
10
+
11
+ def give_feedback(type)
12
+ feedback_type = type.to_sym
13
+ case feedback_type
14
+ when :positive
15
+ Feedback.create(:rating => 1) { |f| f.rateable = self }
16
+ when :negative
17
+ Feedback.create(:rating => -1) { |f| f.rateable = self }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minimal_feedback/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "minimal_feedback"
8
+ gem.version = MinimalFeedback::VERSION
9
+ gem.authors = ["Matteo Depalo"]
10
+ gem.email = ["matteodepalo@gmail.com"]
11
+ gem.description = %q{Feedback functionalities for ActiveRecord models}
12
+ gem.summary = %q{Feedback functionalities for ActiveRecord models}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'activerecord'
21
+ gem.add_dependency 'activesupport'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'debugger'
25
+ gem.add_development_dependency 'rake'
26
+ gem.add_development_dependency 'sqlite3'
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'mf_feedbacks'")
4
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'issues'")
5
+ ActiveRecord::Base.connection.create_table(:mf_feedbacks) do |t|
6
+ t.string :type
7
+ t.integer :rating
8
+ t.references :rateable, :polymorphic => true
9
+ t.timestamps
10
+ end
11
+
12
+ ActiveRecord::Base.connection.create_table(:issues)
13
+
14
+ class Issue < ActiveRecord::Base
15
+ include MinimalFeedback
16
+ end
17
+
18
+ describe Issue do
19
+ before(:each) do
20
+ @issue = Issue.create
21
+ end
22
+
23
+ it 'assigns positive feedback' do
24
+ @issue.give_feedback(:positive)
25
+ @issue.feedbacks.first.type.should == :positive
26
+ end
27
+
28
+ it 'assigns negative feedback' do
29
+ @issue.give_feedback(:negative)
30
+ @issue.feedbacks.first.type.should == :negative
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'minimal_feedback'
2
+ require 'debugger'
3
+
4
+ root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
+ ActiveRecord::Base.establish_connection(
6
+ :adapter => "sqlite3",
7
+ :database => "#{root}/db/minimal_feedback.sqlite3"
8
+ )
9
+
10
+ RSpec.configure do |config|
11
+ config.before(:each) do
12
+ ActiveRecord::Base.connection.increment_open_transactions
13
+ ActiveRecord::Base.connection.begin_db_transaction
14
+ end
15
+
16
+ config.after(:each) do
17
+ ActiveRecord::Base.connection.rollback_db_transaction
18
+ ActiveRecord::Base.connection.decrement_open_transactions
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minimal_feedback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matteo Depalo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: debugger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Feedback functionalities for ActiveRecord models
111
+ email:
112
+ - matteodepalo@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - db/.gitkeep
124
+ - lib/generators/minimal_feedback/minimal_feedback_generator.rb
125
+ - lib/generators/minimal_feedback/templates/create_mf_feedbacks.rb
126
+ - lib/minimal_feedback.rb
127
+ - lib/minimal_feedback/feedback.rb
128
+ - lib/minimal_feedback/version.rb
129
+ - minimal_feedback.gemspec
130
+ - spec/minimal_feedback_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: ''
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ segments:
145
+ - 0
146
+ hash: -4218162571524871835
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ segments:
154
+ - 0
155
+ hash: -4218162571524871835
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.24
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Feedback functionalities for ActiveRecord models
162
+ test_files:
163
+ - spec/minimal_feedback_spec.rb
164
+ - spec/spec_helper.rb