Class: Pippi::Checks::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/pippi/checks/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ Check

Returns a new instance of Check.



5
6
7
# File 'lib/pippi/checks/check.rb', line 5

def initialize(ctx)
  @ctx = ctx
end

Instance Attribute Details

#ctxObject

Returns the value of attribute ctx.



3
4
5
# File 'lib/pippi/checks/check.rb', line 3

def ctx
  @ctx
end

Instance Method Details

#add_problemObject



17
18
19
20
# File 'lib/pippi/checks/check.rb', line 17

def add_problem
  problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
  ctx.report.add(Pippi::Problem.new(line_number: problem_location.lineno, file_path: problem_location.path, check_class: self.class))
end

#array_mutator_methodsObject



9
10
11
# File 'lib/pippi/checks/check.rb', line 9

def array_mutator_methods
  [:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!]
end

#clear_fault(lineno, path) ⇒ Object



29
30
31
# File 'lib/pippi/checks/check.rb', line 29

def clear_fault(lineno, path)
  ctx.report.remove(lineno, path, self.class)
end

#clear_fault_proc(clz, problem_location) ⇒ Object



22
23
24
25
26
27
# File 'lib/pippi/checks/check.rb', line 22

def clear_fault_proc(clz, problem_location)
  proc do |*args, &blk|
    clz.clear_fault(problem_location.lineno, problem_location.path)
    super(*args, &blk)
  end
end

#its_ok_watcher_proc(clazz, method_name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pippi/checks/check.rb', line 33

def its_ok_watcher_proc(clazz, method_name)
  proc do |*args, &blk|
    begin
      singleton_class.ancestors.find { |x| x == clazz }.instance_eval { remove_method method_name }
    rescue NameError
      return super(*args, &blk)
    else
      return super(*args, &blk)
    end
  end
end

#method_names_that_indicate_this_is_being_used_as_a_collectionObject



13
14
15
# File 'lib/pippi/checks/check.rb', line 13

def method_names_that_indicate_this_is_being_used_as_a_collection
  [:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!, :collect, :compact, :first, :flatten, :join, :last, :map, :reject, :reverse, :rotate, :select, :shuffle, :slice, :sort, :sort_by, :uniq]
end