Class: Workarea::CreateReview
- Inherits:
-
Object
- Object
- Workarea::CreateReview
- Includes:
- ActiveModel::Validations
- Defined in:
- app/services/workarea/create_review.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#review ⇒ Object
readonly
Returns the value of attribute review.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(review, user: nil, params: {}) ⇒ CreateReview
constructor
A new instance of CreateReview.
- #save ⇒ Object
- #verified? ⇒ Boolean
Constructor Details
#initialize(review, user: nil, params: {}) ⇒ CreateReview
Returns a new instance of CreateReview.
19 20 21 22 23 |
# File 'app/services/workarea/create_review.rb', line 19 def initialize(review, user: nil, params: {}) @review = review @user = user @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'app/services/workarea/create_review.rb', line 8 def params @params end |
#review ⇒ Object (readonly)
Returns the value of attribute review.
8 9 10 |
# File 'app/services/workarea/create_review.rb', line 8 def review @review end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'app/services/workarea/create_review.rb', line 8 def user @user end |
Class Method Details
.for(product: nil, user: nil, params: {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/services/workarea/create_review.rb', line 10 def self.for(product: nil, user: nil, params: {}) review = Review.new( product_id: product.try(:id), user_id: user.try(:id) ) new(review, user: user, params: params) end |
Instance Method Details
#save ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/services/workarea/create_review.rb', line 25 def save update_user_attributes update_attributes return false unless valid? review.save.tap { |result| update_review_requests if result } end |
#verified? ⇒ Boolean
33 34 35 |
# File 'app/services/workarea/create_review.rb', line 33 def verified? user_order_ids_with_product.any? end |