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



21
22
23
24
# File 'lib/pippi/checks/check.rb', line 21

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

#clear_fault(lineno, path) ⇒ Object



33
34
35
# File 'lib/pippi/checks/check.rb', line 33

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

#clear_fault_proc(clz, problem_location) ⇒ Object



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

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



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pippi/checks/check.rb', line 37

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



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

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

#mutator_methods(the_type = Array) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/pippi/checks/check.rb', line 9

def mutator_methods(the_type=Array)
  if the_type == String
    [:insert, :<<]
  else
    [:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!]
  end
end