Class: Brakeman::Collection

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/brakeman/tracker/collection.rb

Direct Known Subclasses

Controller, Library, Model, Template

Constant Summary

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #kwsplat?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Constructor Details

#initialize(name, parent, file_name, src, tracker) ⇒ Collection

Returns a new instance of Collection.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/brakeman/tracker/collection.rb', line 9

def initialize name, parent, file_name, src, tracker
  @name = name
  @parent = parent
  @files = []
  @src = {}
  @includes = []
  @methods = { :public => {}, :private => {}, :protected => {} }
  @options = {}
  @tracker = tracker

  add_file file_name, src
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def collection
  @collection
end

#filesObject (readonly)

Returns the value of attribute files.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def files
  @files
end

#includesObject (readonly)

Returns the value of attribute includes.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def includes
  @includes
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def parent
  @parent
end

#srcObject (readonly)

Returns the value of attribute src.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def src
  @src
end

#trackerObject (readonly)

Returns the value of attribute tracker.



7
8
9
# File 'lib/brakeman/tracker/collection.rb', line 7

def tracker
  @tracker
end

Instance Method Details

#add_file(file_name, src) ⇒ Object



34
35
36
37
# File 'lib/brakeman/tracker/collection.rb', line 34

def add_file file_name, src
  @files << file_name unless @files.include? file_name
  @src[file_name] = src
end

#add_include(class_name) ⇒ Object



39
40
41
# File 'lib/brakeman/tracker/collection.rb', line 39

def add_include class_name
  @includes << class_name
end

#add_method(visibility, name, src, file_name) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/brakeman/tracker/collection.rb', line 48

def add_method visibility, name, src, file_name
  if src.node_type == :defs
    name = :"#{src[1]}.#{name}"
  end

  @methods[visibility][name] = { :src => src, :file => file_name }
end

#add_option(name, exp) ⇒ Object



43
44
45
46
# File 'lib/brakeman/tracker/collection.rb', line 43

def add_option name, exp
  @options[name] ||= []
  @options[name] << exp
end

#ancestor?(parent, seen = {}) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/brakeman/tracker/collection.rb', line 22

def ancestor? parent, seen={}
  seen[self.name] = true

  if self.parent == parent or seen[self.parent]
    true
  elsif parent_model = collection[self.parent]
    parent_model.ancestor? parent, seen
  else
    false
  end
end

#each_methodObject



56
57
58
59
60
61
62
# File 'lib/brakeman/tracker/collection.rb', line 56

def each_method
  @methods.each do |_vis, meths|
    meths.each do |name, info|
      yield name, info
    end
  end
end

#fileObject



74
75
76
# File 'lib/brakeman/tracker/collection.rb', line 74

def file
  @files.first
end

#get_method(name) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/brakeman/tracker/collection.rb', line 64

def get_method name
  each_method do |n, info|
    if n == name
      return info
    end
  end

  nil
end

#methods_publicObject



90
91
92
# File 'lib/brakeman/tracker/collection.rb', line 90

def methods_public
  @methods[:public]
end

#top_lineObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/brakeman/tracker/collection.rb', line 78

def top_line
  if sexp? @src[file]
    @src[file].line
  else
    @src.each_value do |source|
      if sexp? source
        return source.line
      end
    end
  end
end