Class: MR::ReadModel::SubqueryExpression
- Inherits:
-
Object
- Object
- MR::ReadModel::SubqueryExpression
- Defined in:
- lib/mr/read_model/query_expression.rb
Constant Summary collapse
- TYPES =
{ :joins => JoinSubquery }.freeze
Instance Attribute Summary collapse
-
#subquery_args ⇒ Object
readonly
Returns the value of attribute subquery_args.
-
#subquery_block ⇒ Object
readonly
Returns the value of attribute subquery_block.
-
#subquery_type ⇒ Object
(also: #type)
readonly
Returns the value of attribute subquery_type.
Instance Method Summary collapse
- #apply_to(relation, params = nil) ⇒ Object
-
#initialize(type, *args, &block) ⇒ SubqueryExpression
constructor
A new instance of SubqueryExpression.
- #subquery ⇒ Object
Constructor Details
#initialize(type, *args, &block) ⇒ SubqueryExpression
Returns a new instance of SubqueryExpression.
66 67 68 69 70 71 |
# File 'lib/mr/read_model/query_expression.rb', line 66 def initialize(type, *args, &block) raise ArgumentError, "a block must be provided" unless block @subquery_type = type @subquery_args = args @subquery_block = block end |
Instance Attribute Details
#subquery_args ⇒ Object (readonly)
Returns the value of attribute subquery_args.
63 64 65 |
# File 'lib/mr/read_model/query_expression.rb', line 63 def subquery_args @subquery_args end |
#subquery_block ⇒ Object (readonly)
Returns the value of attribute subquery_block.
63 64 65 |
# File 'lib/mr/read_model/query_expression.rb', line 63 def subquery_block @subquery_block end |
#subquery_type ⇒ Object (readonly) Also known as: type
Returns the value of attribute subquery_type.
63 64 65 |
# File 'lib/mr/read_model/query_expression.rb', line 63 def subquery_type @subquery_type end |
Instance Method Details
#apply_to(relation, params = nil) ⇒ Object
80 81 82 |
# File 'lib/mr/read_model/query_expression.rb', line 80 def apply_to(relation, params = nil) relation.send(self.type, self.subquery.build_sql(params)) end |
#subquery ⇒ Object
73 74 75 76 77 78 |
# File 'lib/mr/read_model/query_expression.rb', line 73 def subquery @subquery ||= TYPES[self.subquery_type].new( *self.subquery_args, &self.subquery_block ) end |