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_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #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
# File 'lib/brakeman/tracker/collection.rb', line 9

def initialize name, parent, file_name, src, tracker
  @name = name
  @parent = parent
  @file_name = file_name
  @files = [ file_name ]
  @src = { file_name => src }
  @includes = []
  @methods = { :public => {}, :private => {}, :protected => {} }
  @options = {}
  @tracker = tracker
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



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

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

#add_include(class_name) ⇒ Object



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

def add_include class_name
  @includes << class_name
end

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



47
48
49
# File 'lib/brakeman/tracker/collection.rb', line 47

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

#add_option(name, exp) ⇒ Object



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

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

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

Returns:

  • (Boolean)


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

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



51
52
53
54
55
56
57
# File 'lib/brakeman/tracker/collection.rb', line 51

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

#fileObject



69
70
71
# File 'lib/brakeman/tracker/collection.rb', line 69

def file
  @files.first
end

#get_method(name) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/brakeman/tracker/collection.rb', line 59

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

  nil
end

#methods_publicObject



85
86
87
# File 'lib/brakeman/tracker/collection.rb', line 85

def methods_public
  @methods[:public]
end

#top_lineObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/brakeman/tracker/collection.rb', line 73

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