Class: MR::ReadModel::SetExpression
- Inherits:
-
Object
- Object
- MR::ReadModel::SetExpression
- Defined in:
- lib/mr/read_model/query_expression.rb
Constant Summary collapse
- OPERATOR_SQL =
{ :union => 'UNION'.freeze, :union_all => 'UNION ALL'.freeze, :intersect => 'INTERSECT'.freeze, :intersect_all => 'INTERSECT ALL'.freeze, :except => 'EXCEPT'.freeze, :except_all => 'EXCEPT ALL'.freeze }.freeze
Instance Attribute Summary collapse
-
#operator_sql ⇒ Object
readonly
Returns the value of attribute operator_sql.
-
#read_model_block ⇒ Object
readonly
Returns the value of attribute read_model_block.
Instance Method Summary collapse
- #combine_sql(sql, params = nil) ⇒ Object
-
#initialize(operator, &block) ⇒ SetExpression
constructor
A new instance of SetExpression.
- #read_model_class ⇒ Object
Constructor Details
#initialize(operator, &block) ⇒ SetExpression
Returns a new instance of SetExpression.
152 153 154 155 156 |
# File 'lib/mr/read_model/query_expression.rb', line 152 def initialize(operator, &block) raise ArgumentError, "a block must be provided" unless block @operator_sql = OPERATOR_SQL[operator] @read_model_block = block end |
Instance Attribute Details
#operator_sql ⇒ Object (readonly)
Returns the value of attribute operator_sql.
150 151 152 |
# File 'lib/mr/read_model/query_expression.rb', line 150 def operator_sql @operator_sql end |
#read_model_block ⇒ Object (readonly)
Returns the value of attribute read_model_block.
150 151 152 |
# File 'lib/mr/read_model/query_expression.rb', line 150 def read_model_block @read_model_block end |
Instance Method Details
#combine_sql(sql, params = nil) ⇒ Object
172 173 174 |
# File 'lib/mr/read_model/query_expression.rb', line 172 def combine_sql(sql, params = nil) "#{sql} #{self.operator_sql} #{self.read_model_class.build_sql(params)}" end |
#read_model_class ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/mr/read_model/query_expression.rb', line 158 def read_model_class @read_model_class ||= begin c = Class.new do # TODO - fix circular require require 'mr/read_model' require 'mr/read_model/set_querying' include MR::ReadModel include MR::ReadModel:: end c.class_eval(&self.read_model_block) c end end |