lib/voting/models/voting/vote.rb in voting-0.2.0 vs lib/voting/models/voting/vote.rb in voting-0.3.0
- old
+ new
@@ -16,9 +16,15 @@
validates :author_id, uniqueness: {
case_sensitive: false,
scope: %i[author_type resource_id resource_type scopeable_id scopeable_type]
}
+ def status
+ return 'positive' if positive == 1
+
+ negative == 1 ? 'negative' : 'none'
+ end
+
def self.create(author:, resource:, scopeable: nil, value:)
record = find_or_initialize_by(author: author, resource: resource, scopeable: scopeable)
attribute = value.positive? ? :positive : :negative
canceled = record.persisted? && value.abs == record[attribute]