Module: Interest::Blockable::Blocker

Extended by:
ActiveSupport::Concern
Defined in:
lib/interest/blockable/blocker.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#block(blockee, raise_record_invalid = false) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/interest/blockable/blocker.rb', line 22

def block(blockee, raise_record_invalid = false)
  blocking_relationships.create!(blockee: blockee)
rescue ActiveRecord::RecordInvalid => exception
  raise_record_invalid ? (raise exception) : nil
rescue ActiveRecord::RecordNotUnique
  blocking_relationships.find_by(blockee: blockee)
end

#block!(blockee) ⇒ Object



30
31
32
33
34
# File 'lib/interest/blockable/blocker.rb', line 30

def block!(blockee)
  block(blockee, true)
rescue ActiveRecord::RecordInvalid => exception
  raise Interest::Blockable::Rejected.new(exception)
end

#blocking?(blockee) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/interest/blockable/blocker.rb', line 18

def blocking?(blockee)
  blocker_collection_for(blockee).include? blockee
end

#followable?(other) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/interest/blockable/blocker.rb', line 14

def followable?(other)
  super and not (other.blockee? and blocking?(other)) and not (blockee? and other.blocker? and other.blocking? self)
end

#unblock(blockee) ⇒ Object



36
37
38
# File 'lib/interest/blockable/blocker.rb', line 36

def unblock(blockee)
  blocker_collection_for(blockee).delete blockee
end

#valid_blocking_for?(blockee) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/interest/blockable/blocker.rb', line 40

def valid_blocking_for?(blockee)
  not (self == blockee or not blockable?(blockee))
end