Class: MR::ReadModel::FromSubqueryExpression
- Inherits:
-
Object
- Object
- MR::ReadModel::FromSubqueryExpression
- Defined in:
- lib/mr/read_model/query_expression.rb
Instance Attribute Summary collapse
-
#subquery_block ⇒ Object
readonly
Returns the value of attribute subquery_block.
Instance Method Summary collapse
- #ar_relation(params = nil) ⇒ Object
- #default_find_attr ⇒ Object
-
#from_subquery ⇒ Object
lazy-build ‘FromSubquery` so its block is not evaluated until the read model `query` method is called, cache it so it doesn’t have to be rebuilt for every ‘query` call.
-
#initialize(&block) ⇒ FromSubqueryExpression
constructor
A new instance of FromSubqueryExpression.
- #record_class ⇒ Object
Constructor Details
#initialize(&block) ⇒ FromSubqueryExpression
Returns a new instance of FromSubqueryExpression.
108 109 110 111 |
# File 'lib/mr/read_model/query_expression.rb', line 108 def initialize(&block) raise ArgumentError, "a block must be provided" unless block @subquery_block = block end |
Instance Attribute Details
#subquery_block ⇒ Object (readonly)
Returns the value of attribute subquery_block.
106 107 108 |
# File 'lib/mr/read_model/query_expression.rb', line 106 def subquery_block @subquery_block end |
Instance Method Details
#ar_relation(params = nil) ⇒ Object
129 130 131 |
# File 'lib/mr/read_model/query_expression.rb', line 129 def ar_relation(params = nil) self.record_class.scoped.from(self.from_subquery.build_sql(params)) end |
#default_find_attr ⇒ Object
124 125 126 127 |
# File 'lib/mr/read_model/query_expression.rb', line 124 def default_find_attr raise NoFindAttrError, "a `find_attr` has to be specified " \ "when using a from subquery" end |
#from_subquery ⇒ Object
lazy-build ‘FromSubquery` so its block is not evaluated until the read model `query` method is called, cache it so it doesn’t have to be rebuilt for every ‘query` call
116 117 118 |
# File 'lib/mr/read_model/query_expression.rb', line 116 def from_subquery @from_subquery ||= FromSubquery.new(&self.subquery_block) end |
#record_class ⇒ Object
120 121 122 |
# File 'lib/mr/read_model/query_expression.rb', line 120 def record_class self.from_subquery.record_class end |