Sha256: d648fbd39767c1806ec55e6effb360c81d3160140e4c4cecd00c29b07a7d0de0
Contents?: true
Size: 1.64 KB
Versions: 7
Compression:
Stored size: 1.64 KB
Contents
module ValidateUniqComments class Basic < UseCase::Validator target :comments, in: :post validates_uniqueness_of :title end class CustomConditions < UseCase::Validator target :comments, in: :post validates_uniqueness_of :title, conditions: :similar_conditions protected ##################### PROTECTED ####################### def similar_conditions(comment, other_comment) comment.title == other_comment.title && comment.email == other_comment.email end end class CustomScope < UseCase::Validator target :comments, in: :post validates_uniqueness_of :title, scope: :belongs_to_post_id1 protected ##################### PROTECTED ####################### def belongs_to_post_id1(comment) comment.post_id == 1 end end class CustomScopeAndTarget < UseCase::Validator def target context.post.first_two_comments end validates_uniqueness_of :title, scope: :last_two_comments protected ##################### PROTECTED ####################### def last_two_comments(comment) [context.post.comments[-1], context.post.comments[-2]].include?(comment) end end class CustomScopeAndConditions < UseCase::Validator target :comments, in: :post validates_uniqueness_of :title, scope: :belongs_to_post_id1, conditions: :similar_conditions protected ##################### PROTECTED ####################### def similar_conditions(comment, other_comment) comment.title == other_comment.title && comment.email == other_comment.email end def belongs_to_post_id1(comment) comment.post_id == 1 end end end
Version data entries
7 entries across 7 versions & 1 rubygems