not compatible to ruby1.8 now! new: ActiveRecordExtensions
This commit is contained in:
parent
3d922c5e47
commit
7f43e9fb86
|
@ -43,9 +43,9 @@ class SmqlToAR
|
||||||
# Die eigentliche Exception wird in @data[:exception] hinterlegt.
|
# Die eigentliche Exception wird in @data[:exception] hinterlegt.
|
||||||
class SubSMQLError < SMQLError
|
class SubSMQLError < SMQLError
|
||||||
def initialize query, model, exception
|
def initialize query, model, exception
|
||||||
ex = {:class => exception.class, :message => exception.message}
|
ex = {class: exception.class, message: exception.message}
|
||||||
ex[:data] = exception.data if exception.respond_to? :data
|
ex[:data] = exception.data if exception.respond_to? :data
|
||||||
super :query => query, :model => model.to_s, :exception => ex
|
super query: query, model: model.to_s, exception: ex
|
||||||
set_backtrace exception.backtrace
|
set_backtrace exception.backtrace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -55,49 +55,49 @@ class SmqlToAR
|
||||||
# Malformed ColOp
|
# Malformed ColOp
|
||||||
class UnexpectedColOpError < ParseError
|
class UnexpectedColOpError < ParseError
|
||||||
def initialize model, colop, val
|
def initialize model, colop, val
|
||||||
super :got => colop, :val => val, :model => model.to_s
|
super got: colop, val: val, model: model.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class UnexpectedError < ParseError
|
class UnexpectedError < ParseError
|
||||||
def initialize model, colop, val
|
def initialize model, colop, val
|
||||||
super :got => {colop => val}, :model => model.to_s
|
super got: {colop => val}, model: model.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NonExistingSelectableError < SMQLError
|
class NonExistingSelectableError < SMQLError
|
||||||
def initialize got
|
def initialize got
|
||||||
super :got => got
|
super got: got
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NonExistingColumnError < SMQLError
|
class NonExistingColumnError < SMQLError
|
||||||
def initialize expected, got
|
def initialize expected, got
|
||||||
super :expected => expected, :got => got
|
super expected: expected, got: got
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NonExistingRelationError < SMQLError
|
class NonExistingRelationError < SMQLError
|
||||||
def initialize expected, got
|
def initialize expected, got
|
||||||
super :expected => expected, :got => got
|
super expected: expected, got: got
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProtectedColumnError < SMQLError
|
class ProtectedColumnError < SMQLError
|
||||||
def initialize protected_column
|
def initialize protected_column
|
||||||
super :protected_column => protected_column
|
super protected_column: protected_column
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RootOnlyFunctionError < SMQLError
|
class RootOnlyFunctionError < SMQLError
|
||||||
def initialize path
|
def initialize path
|
||||||
super :path => path
|
super path: path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ConColumnError < SMQLError
|
class ConColumnError < SMQLError
|
||||||
def initialize expected, got
|
def initialize expected, got
|
||||||
super :expected => expected, :got => got
|
super expected: expected, got: got
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -243,8 +243,8 @@ class SmqlToAR
|
||||||
refls = model.respond_to?( :reflections) && model.reflections
|
refls = model.respond_to?( :reflections) && model.reflections
|
||||||
refls && refls.each do |name, refl|
|
refls && refls.each do |name, refl|
|
||||||
r[model.name][name] = case refl
|
r[model.name][name] = case refl
|
||||||
when ActiveRecord::Reflection::ThroughReflection then {:macro => refl.macro, :model => refl.klass.name, :through => refl.through_reflection.name}
|
when ActiveRecord::Reflection::ThroughReflection then {macro: refl.macro, model: refl.klass.name, through: refl.through_reflection.name}
|
||||||
when ActiveRecord::Reflection::AssociationReflection then {:macro => refl.macro, :model => refl.klass.name}
|
when ActiveRecord::Reflection::AssociationReflection then {macro: refl.macro, model: refl.klass.name}
|
||||||
else raise "Ups: #{refl.class}"
|
else raise "Ups: #{refl.class}"
|
||||||
end
|
end
|
||||||
models.push refl.klass unless r.keys.include? refl.klass.name
|
models.push refl.klass unless r.keys.include? refl.klass.name
|
||||||
|
@ -293,8 +293,26 @@ class SmqlToAR
|
||||||
lib_dir = File.dirname __FILE__
|
lib_dir = File.dirname __FILE__
|
||||||
fj = lambda {|*a| File.join lib_dir, *a }
|
fj = lambda {|*a| File.join lib_dir, *a }
|
||||||
Object.send :remove_const, :SmqlToAR
|
Object.send :remove_const, :SmqlToAR
|
||||||
load fj.call( 'smql_to_ar.rb')
|
load fj[ 'smql_to_ar.rb']
|
||||||
load fj.call( 'smql_to_ar', 'condition_types.rb')
|
load fj[ 'smql_to_ar', 'condition_types.rb']
|
||||||
load fj.call( 'smql_to_ar', 'query_builder.rb')
|
load fj[ 'smql_to_ar', 'query_builder.rb']
|
||||||
|
end
|
||||||
|
|
||||||
|
module ActiveRecordExtensions
|
||||||
|
def self.included base
|
||||||
|
base.extend ClassMethods
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
def smql *params
|
||||||
|
SmqlToAR.to_ar self, *params
|
||||||
|
end
|
||||||
|
|
||||||
|
def smql_protected
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.send :include, SmqlToAR::ActiveRecordExtensions
|
||||||
|
|
Loading…
Reference in a new issue