Class: Nitpick::Warnings::UnprotectedBlock

Inherits:
SimpleWarning show all
Defined in:
lib/nitpick/warnings/unprotected_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SimpleWarning

discover

Constructor Details

#initialize(*args) ⇒ UnprotectedBlock

Returns a new instance of UnprotectedBlock.



6
7
8
# File 'lib/nitpick/warnings/unprotected_block.rb', line 6

def initialize(*args)
  @condition, @yes_branch, @no_branch = args
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



4
5
6
# File 'lib/nitpick/warnings/unprotected_block.rb', line 4

def condition
  @condition
end

#no_branchObject (readonly)

Returns the value of attribute no_branch.



4
5
6
# File 'lib/nitpick/warnings/unprotected_block.rb', line 4

def no_branch
  @no_branch
end

#yes_branchObject (readonly)

Returns the value of attribute yes_branch.



4
5
6
# File 'lib/nitpick/warnings/unprotected_block.rb', line 4

def yes_branch
  @yes_branch
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
# File 'lib/nitpick/warnings/unprotected_block.rb', line 15

def ==(other)
  yes_branch == other.yes_branch && no_branch == other.no_branch
end

#matches?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/nitpick/warnings/unprotected_block.rb', line 10

def matches?
  # raise "YES: #{yes_branch.inspect}"
  yes_branch =~ s(:yield) && condition !~ s(:fcall, :block_given?)
end

#messageObject



19
20
21
# File 'lib/nitpick/warnings/unprotected_block.rb', line 19

def message
  "A block is being yielded to without a check for block_given?"
end