Class: MysqlInspector::Grep
- Inherits:
-
Object
- Object
- MysqlInspector::Grep
- Defined in:
- lib/mysql_inspector/grep.rb
Defined Under Namespace
Classes: Subset
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
Instance Method Summary collapse
- #any_matches? ⇒ Boolean
- #each_table ⇒ Object
- #execute ⇒ Object
- #in_table(table) ⇒ Object
-
#initialize(dump, matchers) ⇒ Grep
constructor
A new instance of Grep.
- #tables ⇒ Object
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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
12 13 14 |
# File 'lib/mysql_inspector/grep.rb', line 12 def columns @columns end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
14 15 16 |
# File 'lib/mysql_inspector/grep.rb', line 14 def constraints @constraints end |
#indices ⇒ Object (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
30 31 32 |
# File 'lib/mysql_inspector/grep.rb', line 30 def any_matches? (columns + indices + constraints).any? end |
#each_table ⇒ Object
38 39 40 |
# File 'lib/mysql_inspector/grep.rb', line 38 def each_table tables.each { |t| yield t, in_table(t) } end |
#execute ⇒ Object
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 |
#tables ⇒ Object
34 35 36 |
# File 'lib/mysql_inspector/grep.rb', line 34 def tables (columns + indices + constraints).map { |x| x.table }.uniq.sort end |