minimal_feedback 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,7 +14,7 @@ Run:
14
14
 
15
15
  ```ruby
16
16
  bundle install
17
- rails generate minimal_state_machine
17
+ rails generate minimal_feedback
18
18
  rake db:migrate
19
19
  ```
20
20
 
@@ -52,7 +52,7 @@ issue.feedbacks.last.type
52
52
  => :negative
53
53
  ```
54
54
 
55
- Else if the condition proc returns false when the feedback validation is performed an exception is raised
55
+ If the condition proc returns false when the give_feedback method is called an ActiveRecord invalid exception is raised.
56
56
 
57
57
  ## Contributing
58
58
 
@@ -14,7 +14,7 @@ class MinimalFeedbackGenerator < Rails::Generators::Base
14
14
  end
15
15
 
16
16
  def create_migration_files
17
- create_migration_file_if_not_exist 'create_msm_states'
17
+ create_migration_file_if_not_exist 'create_mf_feedbacks'
18
18
  end
19
19
 
20
20
  private
@@ -24,4 +24,4 @@ class MinimalFeedbackGenerator < Rails::Generators::Base
24
24
  migration_template "#{file_name}.rb", "db/migrate/#{file_name}.rb"
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -1,11 +1,10 @@
1
- class CreateMsmStates < ActiveRecord::Migration
1
+ class CreateMfFeedbacks < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :mf_feedbacks do |t|
4
4
  t.string :type
5
- t.integer :rating
6
5
  t.references :user
7
6
  t.references :rateable, :polymorphic => true
8
7
  t.timestamps
9
8
  end
10
9
  end
11
- end
10
+ end
@@ -1,6 +1,9 @@
1
1
  require 'minimal_feedback/version'
2
- require 'minimal_feedback/feedback'
3
2
  require 'active_support'
3
+ require 'active_record'
4
+ require 'minimal_feedback/feedback'
5
+ require 'minimal_feedback/negative_feedback'
6
+ require 'minimal_feedback/positive_feedback'
4
7
 
5
8
  module MinimalFeedback
6
9
  extend ActiveSupport::Concern
@@ -8,8 +11,6 @@ module MinimalFeedback
8
11
  included do
9
12
  has_many :feedbacks, :as => :rateable, :class_name => 'MinimalFeedback::Feedback'
10
13
 
11
- class InvalidFeedbackError < StandardError; end
12
-
13
14
  cattr_accessor :feedback_condition
14
15
 
15
16
  def self.allow_feedback(options)
@@ -20,20 +21,11 @@ module MinimalFeedback
20
21
  options = args.extract_options!
21
22
  type = args.first.to_sym
22
23
 
23
- feedback = Feedback.new do |f|
24
+ feedback = Feedback.build(:type => type) do |f|
24
25
  f.rateable = self
25
26
  f.user = options[:user]
26
27
  end
27
28
 
28
- case type
29
- when :positive
30
- feedback.rating = 1
31
- when :negative
32
- feedback.rating = -1
33
- else
34
- raise InvalidFeedbackError
35
- end
36
-
37
29
  feedback.save!
38
30
  end
39
31
  end
@@ -1,5 +1,3 @@
1
- require 'active_record'
2
-
3
1
  module MinimalFeedback
4
2
  class Feedback < ActiveRecord::Base
5
3
  self.table_name = 'mf_feedbacks'
@@ -7,20 +5,24 @@ module MinimalFeedback
7
5
  belongs_to :rateable, :polymorphic => true
8
6
  belongs_to :user
9
7
 
10
- validates :rating, :inclusion => { :in => [1, -1] }
11
-
12
8
  validate do
13
9
  if rateable.class.feedback_condition && !rateable.instance_eval(&rateable.class.feedback_condition)
14
10
  errors.add(:base, 'feedback is not allowed')
15
11
  end
16
12
  end
17
13
 
18
- def type
19
- case rating
20
- when 1
21
- :positive
22
- when -1
23
- :negative
14
+ class InvalidFeedbackError < StandardError; end
15
+
16
+ def self.build(options = {}, &block)
17
+ options.assert_valid_keys :type
18
+
19
+ case options[:type]
20
+ when :positive
21
+ PositiveFeedback.new(&block)
22
+ when :negative
23
+ NegativeFeedback.new(&block)
24
+ else
25
+ raise InvalidFeedbackError
24
26
  end
25
27
  end
26
28
  end
@@ -0,0 +1,7 @@
1
+ module MinimalFeedback
2
+ class NegativeFeedback < Feedback
3
+ def type
4
+ :negative
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MinimalFeedback
2
+ class PositiveFeedback < Feedback
3
+ def type
4
+ :positive
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module MinimalFeedback
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimal_feedback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-04 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -125,6 +125,8 @@ files:
125
125
  - lib/generators/minimal_feedback/templates/create_mf_feedbacks.rb
126
126
  - lib/minimal_feedback.rb
127
127
  - lib/minimal_feedback/feedback.rb
128
+ - lib/minimal_feedback/negative_feedback.rb
129
+ - lib/minimal_feedback/positive_feedback.rb
128
130
  - lib/minimal_feedback/version.rb
129
131
  - minimal_feedback.gemspec
130
132
  - spec/minimal_feedback_spec.rb
@@ -143,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
145
  version: '0'
144
146
  segments:
145
147
  - 0
146
- hash: 2275794220295144819
148
+ hash: -4469648509491736839
147
149
  required_rubygems_version: !ruby/object:Gem::Requirement
148
150
  none: false
149
151
  requirements:
@@ -152,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  version: '0'
153
155
  segments:
154
156
  - 0
155
- hash: 2275794220295144819
157
+ hash: -4469648509491736839
156
158
  requirements: []
157
159
  rubyforge_project:
158
160
  rubygems_version: 1.8.24