Module: Card::Query::Attributes
- Included in:
- Card::Query
- Defined in:
- lib/card/query/attributes.rb
Instance Method Summary collapse
- #complete(val) ⇒ Object
- #extension_type(_val) ⇒ Object
- #found_by(val) ⇒ Object
- #found_by_cards(val) ⇒ Object
- #match(val) ⇒ Object
Instance Method Details
#complete(val) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/card/query/attributes.rb', line 48 def complete val no_plus_card = (val =~ /\+/ ? "" : "and right_id is null") # FIXME: -- this should really be more nuanced -- # it breaks down after one plus add_condition( " lower(#{table_alias}.name) LIKE" \ " lower(#{quote(val.to_s + '%')}) #{no_plus_card}" ) end |
#extension_type(_val) ⇒ Object
59 60 61 62 63 |
# File 'lib/card/query/attributes.rb', line 59 def extension_type _val # DEPRECATED LONG AGO!!! Rails.logger.info "using DEPRECATED extension_type in WQL" interpret right_plus: AccountID end |
#found_by(val) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/card/query/attributes.rb', line 5 def found_by val found_by_cards(val).compact.each do |c| if c && [SearchTypeID, SetID].include?(c.type_id) # FIXME: - move this check to set mods! subquery( c.wql_hash.merge(unjoined: true, context: c.name) ) else raise Card::Error::BadQuery, '"found_by" value must be valid Search, ' \ "but #{c.name} is a #{c.type_name}" end end end |
#found_by_cards(val) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/card/query/attributes.rb', line 21 def found_by_cards val if val.is_a? Hash Query.run val else Array.wrap(val).map do |v| Card.fetch v.to_name.to_absolute(context), new: {} end end end |
#match(val) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/card/query/attributes.rb', line 31 def match val cxn, val = match_prep val val.gsub!(/[^#{Card::Name::OK4KEY_RE}]+/, " ") return nil if val.strip.empty? val_list = val.split(/\s+/).map do |v| name_or_content = [ "replace(#{table_alias}.name,'+',' ')", "#{table_alias}.db_content" ].map do |field| %(#{field} #{cxn.match quote("[[:<:]]#{v}[[:>:]]")}) end "(#{name_or_content.join ' OR '})" end add_condition "(#{val_list.join ' AND '})" end |