Class: ActionBlocks::SummaryEngine
- Inherits:
-
Object
- Object
- ActionBlocks::SummaryEngine
- Defined in:
- lib/action_blocks/data_engine/summary_engine.rb
Overview
Data Engine
Instance Attribute Summary collapse
-
#joins ⇒ Object
Returns the value of attribute joins.
-
#root_klass ⇒ Object
Returns the value of attribute root_klass.
-
#selects ⇒ Object
Returns the value of attribute selects.
-
#summary_reqs ⇒ Object
Returns the value of attribute summary_reqs.
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(root_klass, user: nil, summary_reqs: []) ⇒ SummaryEngine
constructor
A new instance of SummaryEngine.
- #process ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(root_klass, user: nil, summary_reqs: []) ⇒ SummaryEngine
Returns a new instance of SummaryEngine.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 6 def initialize(root_klass, user: nil, summary_reqs: []) @root_klass = root_klass @tables = {} @user = user @selects = [] @summary_reqs = summary_reqs end |
Instance Attribute Details
#joins ⇒ Object
Returns the value of attribute joins.
4 5 6 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 4 def joins @joins end |
#root_klass ⇒ Object
Returns the value of attribute root_klass.
4 5 6 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 4 def root_klass @root_klass end |
#selects ⇒ Object
Returns the value of attribute selects.
4 5 6 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 4 def selects @selects end |
#summary_reqs ⇒ Object
Returns the value of attribute summary_reqs.
4 5 6 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 4 def summary_reqs @summary_reqs end |
#tables ⇒ Object
Returns the value of attribute tables.
4 5 6 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 4 def tables @tables end |
Instance Method Details
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 17 def process root_table = @root_klass.arel_table.alias(@root_klass.to_s.underscore.pluralize) sub_table = @root_klass.arel_table.alias(['sub', @root_klass.to_s.underscore.pluralize].join('_')) @summary_reqs.each do |summaryreq| select_reqs = [summaryreq[:select_req]] match_reqs = summaryreq[:match_reqs] filter_reqs = summaryreq[:filter_reqs] @fields_engine = ActionBlocks.config[:fields_engine].new( summaryreq[:root_klass], table_alias_prefix: 'sub', select_reqs: select_reqs ) # @selections_engine = SelectionsViaJoinsEngine.new( @selections_engine = ActionBlocks.config[:selections_engine].new( summaryreq[:root_klass], table_alias_prefix: 'sub', selection_match_reqs: match_reqs, selection_filter_reqs: filter_reqs, additional_where: root_table[:id].eq(sub_table[:id]) ) @fields_engine.process @selections_engine.process if ActionBlocks.config[:should_authorize] @authorization_adapter = AuthorizationAdapter.new(engine: @fields_engine, user: @user) @authorization_adapter.process end sub_query = summaryreq[:root_klass] .from([ @fields_engine.froms, @selections_engine.froms, ].flatten.uniq) .select(@fields_engine.selects) .joins([ @selections_engine.ordered_joins, @fields_engine.ordered_joins ].flatten.compact) .where([@selections_engine.wheres, @fields_engine.wheres].flatten.compact.reduce(&:and)) .as(summaryreq[:select_req][:field_name].to_s) @selects << sub_query end end |
#query ⇒ Object
67 68 69 70 |
# File 'lib/action_blocks/data_engine/summary_engine.rb', line 67 def query @root_klass .select(@selects) end |