Class: PartialKs::Runner
- Inherits:
-
Object
- Object
- PartialKs::Runner
- Defined in:
- lib/partial_ks/runner.rb
Instance Attribute Summary collapse
-
#table_graphs ⇒ Object
readonly
Returns the value of attribute table_graphs.
Instance Method Summary collapse
- #each_generation ⇒ Object
-
#initialize(table_graphs) ⇒ Runner
constructor
A new instance of Runner.
- #report ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(table_graphs) ⇒ Runner
4 5 6 |
# File 'lib/partial_ks/runner.rb', line 4 def initialize(table_graphs) @table_graphs = table_graphs end |
Instance Attribute Details
#table_graphs ⇒ Object (readonly)
Returns the value of attribute table_graphs.
2 3 4 |
# File 'lib/partial_ks/runner.rb', line 2 def table_graphs @table_graphs end |
Instance Method Details
#each_generation ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/partial_ks/runner.rb', line 45 def each_generation return enum_for(:each_generation) unless block_given? generations.each do |generation| yield generation end end |
#report ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/partial_ks/runner.rb', line 35 def report result = [] each_generation.with_index do |generation, depth| generation.each do |table| result << [table.table_name, table.parent_model, table.filter_condition, depth] end end result end |
#run! ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/partial_ks/runner.rb', line 8 def run! each_generation do |generation| tables_to_filter = {} table_names = [] generation.each do |table| table_names << table.table_name filter_config = table.filter_condition if !filter_config.nil? if filter_config.is_a?(ActiveRecord::Relation) || filter_config.respond_to?(:where_sql) only_filter = filter_config.where_sql.to_s.sub("WHERE", "") elsif filter_config.is_a?(String) only_filter = filter_config else only_filter = "#{filter_config.to_s.foreign_key} IN (#{[0, *filter_config.pluck(:id)].join(',')})" end tables_to_filter[table.table_name] = {"only" => only_filter} end end # TODO output only tables_to_filter, depending on how KS handles filters yield tables_to_filter, table_names end end |