Module: SmqlToAR::ConditionTypes

Extended by:
Assertion
Defined in:
lib/smql_to_ar/condition_types.rb

Overview

Alle Subklassen (qualitativ: ConditionTypes::*), die als Superklasse Condition haben,

stellen eine Regel dar,  unter diesen sie das gesuchte Objekt annehmen.

Nimmt eine solche Klasse ein Object nicht an, so wird die naechste Klasse ausprobiert. Es wird in der Reihenfolge abgesucht, in der #constants die Klassen liefert,

wobei angenommen wird,  dass diese nach dem Erstellungszeitpunkt sortiert sind,
aeltere zuerst.

Nimmt eine Klasse ein Objekt an, so soll diese Klasse instanziert werden. Alles weitere siehe Condition.

Defined Under Namespace

Classes: Condition, EqualJoin, Functions, NotIn, NotInRange, Overlaps, Select, StringTimeGreaterThanOrEqual

Constant Summary collapse

InRange =
simple_condition NotInRange, '..', '%s BETWEEN %s AND %s'
NotOverlaps =
simple_condition Overlaps, '<=>', 'NOT (%s, %s) OVERLAPS (%s, %s)'
In =
simple_condition NotIn, '|=', '%s IN (%s)', [Array]
In2 =
simple_condition In, '', nil, [Array]
NotEqual =
simple_condition Condition, '!=', "%s <> %s", [Array, String, Numeric]
NotEqual2 =
simple_condition Condition, '<>', "%s <> %s", [Array, String, Numeric]
GreaterThanOrEqual =
simple_condition Condition, '>=', "%s >= %s", [Array, Numeric]
LesserThanOrEqual =
simple_condition Condition, '<=', "%s <= %s", [Array, Numeric]
StringTimeLesserThanOrEqual =
simple_condition StringTimeGreaterThanOrEqual, '<=', "%s <= %s"
Equal =

class SubEqualJoin < EqualJoin Operator = ‘()’ Expected = [lambda {|x| x.kind_of?( Array) and (1..2).include?( x.length) and x.all?( &it.kind_of?( Hash))}]

def initialize model, cols, val super model, cols, val # sub: model, subquery, sub(condition) @cols.each {|col, sub| sub[ 1..-1] = SmqlToAR.new( col.relation, val).parse, *sub } end

def verify_column col raise_unless col.child?, ConColumnError.new( [:Column], col) end

def sub_equal_join_build builder, table @cols.each do |col, sub| t = table+col.to_a builder.sub_joins t, col, *sub #ap sub: sub sub.each {|x| x.build builder, t } end self end alias build sub_equal_join_build end

simple_condition Condition, '=', "%s = %s", [Array, String, Numeric, Date, Time]
Equal2 =
simple_condition Equal, '', "%s = %s", [String, Numeric, Date, Time]
GreaterThan =
simple_condition Condition, '>', "%s > %s", [Array, Numeric]
StringTimeGreaterThan =
simple_condition StringTimeGreaterThanOrEqual, '>', "%s > %s"
LesserThan =
simple_condition Condition, '<', "%s < %s", [Array, Numeric]
StringTimeLesserThan =
simple_condition StringTimeGreaterThanOrEqual, '<', "%s < %s"
NotIlike =
simple_condition Condition, '!~', "%s NOT ILIKE %s", [Array, String]
Ilike =
simple_condition Condition, '~', "%s ILIKE %s", [Array, String]
Exists =
simple_condition Condition, '', '%s IS NOT NULL', [TrueClass]
NotExists =
simple_condition Condition, '', '%s IS NULL', [FalseClass]
Join =
simple_condition EqualJoin, '', nil, [Hash]
InRange2 =
simple_condition InRange, '', nil, [Range]

Class Method Summary collapse

Methods included from Assertion

raise_if, raise_unless

Class Method Details

.conditions(&e) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smql_to_ar/condition_types.rb', line 39

def conditions &e
	unless block_given?
		r = Enumerator.new( self, :conditions)
		s = self
		r.define_singleton_method :[] do |k|
			s.conditions.select {|c| c::Operator === k }
		end
		return r
	end
	constants.each do |c|
		next  if :Condition == c
		c = const_get c
		next  if Condition === c
		yield c
	end
end

.simple_condition(superclass, op = nil, where = nil, expected = nil) ⇒ Object

Erstellt eine Condition fuer eine Regel.



84
85
86
87
88
89
90
# File 'lib/smql_to_ar/condition_types.rb', line 84

def simple_condition superclass, op = nil, where = nil, expected = nil
	cl = Class.new superclass
	cl.const_set :Operator, op  if op
	cl.const_set :Where, where  if where
	cl.const_set :Expected, expected  if expected
	cl
end

.split_keys(k) ⇒ Object

Ex: ‘givenname|surname|nick’ => [:givenname, :surname, :nick]



35
36
37
# File 'lib/smql_to_ar/condition_types.rb', line 35

def split_keys k
	k.split( '|').collect &:to_sym
end

.try_parse(model, colopvals) ⇒ Object

Alle Regeln parsen. Die Regeln sind in einem Hash der Form => val Ex: Person, “Peter”, “surname=”, “Mueller”



74
75
76
77
78
79
80
81
# File 'lib/smql_to_ar/condition_types.rb', line 74

def try_parse model, colopvals
	colopvals.collect do |colop, val|
		#p :try_parse => { colop: colop, val: val, model: model }
		try_parse_it model, colop, val
	end
rescue SMQLError => e
	raise SubSMQLError.new( colopvals, model, e)
end

.try_parse_it(model, colop, val) ⇒ Object

Eine Regel parsen. Ex: Person, “givenname=”, “Peter”



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/smql_to_ar/condition_types.rb', line 58

def try_parse_it model, colop, val
	r = nil
	#p :try_parse => { :model => model, :colop => colop, :value => val }
	conditions.each do |c|
		raise_unless colop =~ /^(?:\d*:)?(.*?)((?:\W*(?!\])\W)?)$/, UnexpectedColOpError.new( model, colop, val)
		col, op = $1, $2
		col = split_keys( col).collect {|c| Column.new model, c }
		r = c.try_parse model, col, op, val
		break  if r
	end
	raise_unless r, UnexpectedError.new( model, colop, val)
	r
end