Class: MysqlInspector::Grep

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_inspector/grep.rb

Defined Under Namespace

Classes: Subset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dump, matchers) ⇒ Grep

Returns a new instance of Grep.



4
5
6
7
8
9
10
# File 'lib/mysql_inspector/grep.rb', line 4

def initialize(dump, matchers)
  @dump = dump
  @matchers = matchers
  @columns = []
  @indices = []
  @constraints = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



12
13
14
# File 'lib/mysql_inspector/grep.rb', line 12

def columns
  @columns
end

#constraintsObject (readonly)

Returns the value of attribute constraints.



14
15
16
# File 'lib/mysql_inspector/grep.rb', line 14

def constraints
  @constraints
end

#indicesObject (readonly)

Returns the value of attribute indices.



13
14
15
# File 'lib/mysql_inspector/grep.rb', line 13

def indices
  @indices
end

Instance Method Details

#any_matches?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mysql_inspector/grep.rb', line 30

def any_matches?
  (columns + indices + constraints).any?
end

#each_tableObject



38
39
40
# File 'lib/mysql_inspector/grep.rb', line 38

def each_table
  tables.each { |t| yield t, in_table(t) }
end

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mysql_inspector/grep.rb', line 16

def execute
  @columns = []
  @indices = []
  @constraints = []
  @dump.tables.each { |table|
    @columns.concat find(table.columns)
    @indices.concat find(table.indices)
    @constraints.concat find(table.constraints)
  }
  @columns.sort!
  @indices.sort!
  @constraints.sort!
end

#in_table(table) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/mysql_inspector/grep.rb', line 48

def in_table(table)
  Subset.new(
    @columns.find_all { |c| c.table == table },
    @indices.find_all { |i| i.table == table },
    @constraints.find_all { |c| c.table == table }
  )
end

#tablesObject



34
35
36
# File 'lib/mysql_inspector/grep.rb', line 34

def tables
  (columns + indices + constraints).map { |x| x.table }.uniq.sort
end