Module: SmqlToAR::ConditionTypes
- 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, Select
Constant Summary collapse
- InRange =
simple_condition NotInRange, '..', "%s BETWEEN %s AND %s"
- In =
simple_condition NotIn, '|=', '%s IN (%s)', [Array]
- In2 =
simple_condition In, '', nil, [Array]
- NotEqual =
simple_condition Condition, /\!=|<>/, "%s <> %s", [Array, String, Numeric]
- GreaterThanOrEqual =
simple_condition Condition, '>=', "%s >= %s", [Array, Numeric]
- LesserThanOrEqual =
simple_condition Condition, '<=', "%s <= %s", [Array, Numeric]
- Equal =
simple_condition Condition, '=', "%s = %s", [Array, String, Numeric]
- Equal2 =
simple_condition Equal, '', "%s = %s", [String, Numeric]
- GreaterThan =
simple_condition Condition, '>', "%s > %s", [Array, Numeric]
- LesserThan =
simple_condition Condition, '<', "%s < %s", [Array, Numeric]
- NotIlike =
simple_condition Condition, '!~', "%s NOT ILIKE %s", [Array, String]
- Ilike =
simple_condition Condition, '~', "%s ILIKE %s", [Array, String]
- Join =
No Operator #######
simple_condition EqualJoin, '', nil, [Hash]
- InRange2 =
simple_condition InRange, '', nil, [Range]
Class Method Summary collapse
-
.simple_condition(superclass, op = nil, where = nil, expected = nil) ⇒ Object
Erstellt eine Condition fuer eine Regel.
-
.split_keys(k) ⇒ Object
Ex: ‘givenname|surname|nick’ => [:givenname, :surname, :nick].
-
.try_parse(model, colopvals) ⇒ Object
Alle Regeln parsen.
-
.try_parse_it(model, colop, val) ⇒ Object
Eine Regel parsen.
Class Method Details
.simple_condition(superclass, op = nil, where = nil, expected = nil) ⇒ Object
Erstellt eine Condition fuer eine Regel.
65 66 67 68 69 70 71 |
# File 'lib/smql_to_ar/condition_types.rb', line 65 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]
30 31 32 |
# File 'lib/smql_to_ar/condition_types.rb', line 30 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”
55 56 57 58 59 60 61 62 |
# File 'lib/smql_to_ar/condition_types.rb', line 55 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”
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smql_to_ar/condition_types.rb', line 36 def try_parse_it model, colop, val r = nil #p :try_parse => { :model => model, :colop => colop, :value => val } constants.each do |c| next if :Condition == c c = const_get c next if Condition === c raise UnexpectedColOpError.new( model, colop, val) unless colop =~ /^(?:\d*:)?(.*?)(\W*)$/ 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 UnexpectedError.new( model, colop, val) unless r r end |