Class: SmqlToAR
- Inherits:
-
Object
- Object
- SmqlToAR
- Includes:
- ActiveSupport::Benchmarkable
- Defined in:
- lib/smql_to_ar.rb,
lib/smql_to_ar/query_builder.rb,
lib/smql_to_ar/condition_types.rb
Overview
SmqlToAR - Parser: Converts SMQL to ActiveRecord Copyright © 2011 Denis Knauf
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Modules: ConditionTypes Classes: BuilderError, Column, NonExistingColumnError, NonExistingRelationError, NonExistingSelectableError, OnlyOrderOnBaseError, ParseError, ProtectedColumnError, QueryBuilder, Railtie, SMQLError, SubSMQLError, UnexpectedColOpError, UnexpectedError
Constant Summary collapse
- @@logger =
Logger.new $stdout
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Class Method Summary collapse
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
-
.model_of(model, rel) ⇒ Object
Model der Relation ‘rel` von `model`.
- .to_ar(*params) ⇒ Object
Instance Method Summary collapse
- #ar ⇒ Object
- #build ⇒ Object
-
#initialize(model, query, order = nil) ⇒ SmqlToAR
constructor
A new instance of SmqlToAR.
- #parse ⇒ Object
- #to_ar ⇒ Object
Constructor Details
#initialize(model, query, order = nil) ⇒ SmqlToAR
Returns a new instance of SmqlToAR.
178 179 180 181 182 |
# File 'lib/smql_to_ar.rb', line 178 def initialize model, query, order = nil query = JSON.parse query if query.kind_of? String @model, @query, @logger, @order = model, query, @@logger, order #p model: @model, query: @query end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
158 159 160 |
# File 'lib/smql_to_ar.rb', line 158 def builder @builder end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
158 159 160 |
# File 'lib/smql_to_ar.rb', line 158 def conditions @conditions end |
#logger ⇒ Object
Returns the value of attribute logger.
159 160 161 |
# File 'lib/smql_to_ar.rb', line 159 def logger @logger end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
158 159 160 |
# File 'lib/smql_to_ar.rb', line 158 def model @model end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
158 159 160 |
# File 'lib/smql_to_ar.rb', line 158 def order @order end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
158 159 160 |
# File 'lib/smql_to_ar.rb', line 158 def query @query end |
Class Method Details
.logger ⇒ Object
175 |
# File 'lib/smql_to_ar.rb', line 175 def logger() @@logger end |
.logger=(logger) ⇒ Object
174 |
# File 'lib/smql_to_ar.rb', line 174 def logger=(logger) @@logger = logger end |
.model_of(model, rel) ⇒ Object
Model der Relation ‘rel` von `model`
91 92 93 |
# File 'lib/smql_to_ar.rb', line 91 def self.model_of model, rel model.reflections[ rel.to_sym].andand.klass end |
.to_ar(*params) ⇒ Object
216 217 218 |
# File 'lib/smql_to_ar.rb', line 216 def self.to_ar *params new( *params).to_ar end |
Instance Method Details
#ar ⇒ Object
202 203 204 205 206 |
# File 'lib/smql_to_ar.rb', line 202 def ar @ar ||= benchmark 'SMQL ar' do @builder.to_ar end end |
#build ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/smql_to_ar.rb', line 192 def build benchmark 'SMQL build query' do @builder = QueryBuilder.new @model table = @builder.base_table @conditions.each {|condition| condition.build builder, table } end #p builder: @builder self end |
#parse ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/smql_to_ar.rb', line 184 def parse benchmark 'SMQL parse' do @conditions = ConditionTypes.try_parse @model, @query end #p conditions: @conditions self end |
#to_ar ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/smql_to_ar.rb', line 208 def to_ar benchmark 'SMQL' do parse build ar.tap {|ar| logger.info ar.to_sql } end end |