Class: SmqlToAR::SubBuilder
- Inherits:
-
Array
- Object
- Array
- SmqlToAR::SubBuilder
- Defined in:
- lib/smql_to_ar/query_builder.rb
Instance Attribute Summary collapse
-
#_where ⇒ Object
readonly
Returns the value of attribute _where.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #collect_build_where(indent = nil) ⇒ Object
- #default ⇒ Object
- #default_new(parent) ⇒ Object
-
#initialize(parent, tmp = false) ⇒ SubBuilder
constructor
A new instance of SubBuilder.
- #inspect ⇒ Object
- #new(parent, tmp = false) ⇒ Object
- #optimize! ⇒ Object
- #type_correction! ⇒ Object
Constructor Details
#initialize(parent, tmp = false) ⇒ SubBuilder
Returns a new instance of SubBuilder.
224 225 226 227 |
# File 'lib/smql_to_ar/query_builder.rb', line 224 def initialize parent, tmp = false @parent = parent @parent.where self unless @parend.nil? && tmp end |
Instance Attribute Details
#_where ⇒ Object (readonly)
Returns the value of attribute _where.
221 222 223 |
# File 'lib/smql_to_ar/query_builder.rb', line 221 def _where @_where end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
221 222 223 |
# File 'lib/smql_to_ar/query_builder.rb', line 221 def parent @parent end |
Instance Method Details
#collect_build_where(indent = nil) ⇒ Object
272 273 274 275 |
# File 'lib/smql_to_ar/query_builder.rb', line 272 def collect_build_where indent = nil indent = (indent||0) + 1 collect {|x| "(#{x.respond_to?( :build_where) ? x.build_where( indent) : x.to_s})" } end |
#default ⇒ Object
270 |
# File 'lib/smql_to_ar/query_builder.rb', line 270 def default() SmqlToAR::And end |
#default_new(parent) ⇒ Object
271 |
# File 'lib/smql_to_ar/query_builder.rb', line 271 def default_new( parent) default.new self, parent, false end |
#inspect ⇒ Object
267 268 269 |
# File 'lib/smql_to_ar/query_builder.rb', line 267 def inspect "#{self.class.name.sub( /.*::/, '')}[ #{collect(&:inspect).join ', '}]" end |
#new(parent, tmp = false) ⇒ Object
229 230 231 232 233 |
# File 'lib/smql_to_ar/query_builder.rb', line 229 def new parent, tmp = false super parent, tmp #return parent if self.class == parent.class #super parent end |
#optimize! ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/smql_to_ar/query_builder.rb', line 248 def optimize! ext = [] collect! do |sub| sub = sub.optimize! if sub.kind_of? SubBuilder if self.class == sub.class ext.push *sub nil elsif sub.blank? nil elsif 1 == sub.size sub.first else sub end end.compact! push *ext self end |
#type_correction! ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/smql_to_ar/query_builder.rb', line 237 def type_correction! collect! do |sub| if sub.kind_of? Array sub = default[ *sub] unless sub.respond_to?( :type_correction!) sub.type_correction! end sub end self end |