lib/card/query.rb in card-1.18.6 vs lib/card/query.rb in card-1.19.0

- old
+ new

@@ -32,16 +32,16 @@ # - @subqueries - a list of other queries nested within this one # # Each condition is either a SQL-ready string (boo) or an Array in this form: # [ field_string_or_sym, Card::Value::Query object ] class Query - require_dependency 'card/query/clause' - require_dependency 'card/query/value' - require_dependency 'card/query/reference' - require_dependency 'card/query/attributes' - require_dependency 'card/query/sql_statement' - require_dependency 'card/query/join' + require_dependency "card/query/clause" + require_dependency "card/query/value" + require_dependency "card/query/reference" + require_dependency "card/query/attributes" + require_dependency "card/query/sql_statement" + require_dependency "card/query/join" include Clause include Attributes include RelationalAttributes include Interpretation @@ -53,35 +53,39 @@ basic: %w( id name key type_id content left_id right_id creator_id updater_id codename read_rule_id ), relational: %w( type part left right editor_of edited_by last_editor_of last_edited_by creator_of created_by member_of member ), - plus_relational: %w( plus left_plus right_plus ), + plus_relational: %w(plus left_plus right_plus), ref_relational: %w( refer_to referred_to_by link_to linked_to_by include included_by ), - conjunction: %w( and or all any ), - special: %w( found_by not sort match complete extension_type ), - ignore: %w( prepend append view params vars size ) - }.inject({}) { |h, pair| pair[1].each { |v| h[v.to_sym] = pair[0] }; h } + conjunction: %w(and or all any), + special: %w(found_by not sort match complete extension_type), + ignore: %w(prepend append view params vars size) + }.each_with_object({}) do |pair, h| + pair[1].each { |v| h[v.to_sym] = pair[0] } + end CONJUNCTIONS = { any: :or, in: :or, or: :or, all: :and, and: :and }.freeze - MODIFIERS = %w( conj return sort sort_as group dir limit offset ) - .inject({}) { |h, v| h[v.to_sym] = nil; h } + MODIFIERS = %w(conj return sort sort_as group dir limit offset) + .each_with_object({}) { |v, h| h[v.to_sym] = nil } - OPERATORS = %w( != = =~ < > in ~ ).inject({}) { |h, v| h[v] = v; h }.merge({ - eq: '=', gt: '>', lt: '<', match: '~', ne: '!=', 'not in' => nil - }.stringify_keys) + OPERATORS = + %w(!= = =~ < > in ~).each_with_object({}) { |v, h| h[v] = v }.merge( + { + eq: "=", gt: ">", lt: "<", match: "~", ne: "!=", "not in" => nil + }.stringify_keys + ) - DEFAULT_ORDER_DIRS = { update: 'desc', relevance: 'desc' }.freeze + DEFAULT_ORDER_DIRS = { update: "desc", relevance: "desc" }.freeze attr_reader :statement, :mods, :conditions, :comment, :subqueries, :superquery attr_accessor :joins, :table_seq, :unjoined, :conditions_on_join - # Query Execution # By default a query returns card objects. This is accomplished by returning # a card identifier from SQL and then hooking into our caching system (see # Card::Fetch) @@ -115,31 +119,31 @@ end # run the current query # @return array of card objects by default def run - retrn = statement[:return].present? ? statement[:return].to_s : 'card' - if retrn == 'card' - get_results('name').map do |name| + retrn = statement[:return].present? ? statement[:return].to_s : "card" + if retrn == "card" + get_results("name").map do |name| Card.fetch name, new: {} end else get_results retrn end end # @return Integer for :count, otherwise Array of Strings or Integers def get_results retrn rows = run_sql - if retrn == 'name' && (statement[:prepend] || statement[:append]) + if retrn == "name" && (statement[:prepend] || statement[:append]) rows.map do |row| - [statement[:prepend], row['name'], statement[:append]].compact * '+' + [statement[:prepend], row["name"], statement[:append]].compact * "+" end else case retrn - when 'count' then rows.first['count'].to_i - when 'raw' then rows + when "count" then rows.first["count"].to_i + when "raw" then rows when /id$/ then rows.map { |row| row[retrn].to_i } else rows.map { |row| row[retrn] } end end end @@ -171,10 +175,10 @@ def context if !@context.nil? @context else - @context = @superquery ? @superquery.context : '' + @context = @superquery ? @superquery.context : "" end end end end