Module: ActiveRecord::QueryMethods
- Defined in:
- lib/postgres_with/active_record/relation/query_methods.rb
Defined Under Namespace
Classes: WithChain
Instance Method Summary collapse
- #build_arel_from_array(array) ⇒ Object
- #build_arel_from_hash(with_value) ⇒ Object
- #build_arel_with_extensions(aliases = nil) ⇒ Object (also: #build_arel)
- #with(opts = :chain, *rest) ⇒ Object
-
#with!(opts = :chain, *rest) ⇒ Object
:nodoc:.
Instance Method Details
#build_arel_from_array(array) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 127 def build_arel_from_array(array) unless array.map(&:class).uniq == [Arel::Nodes::As] raise ArgumentError, "Unsupported argument type: #{array} #{array.class}" end array end |
#build_arel_from_hash(with_value) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 106 def build_arel_from_hash(with_value) with_value.map do |name, expression| select = case expression when String Arel::Nodes::SqlLiteral.new("(#{expression})") when ActiveRecord::Relation expression.arel when Arel::SelectManager expression end if name.to_s.start_with?('_materialized_') name = name.gsub('_materialized_', '') table = Arel::Table.new(name) Arel::Nodes::AsMaterialized.new(table, select) else table = Arel::Table.new(name) Arel::Nodes::As.new(table, select) end end end |
#build_arel_with_extensions(aliases = nil) ⇒ Object Also known as: build_arel
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 78 def build_arel_with_extensions(aliases = nil) arel = build_arel_without_extensions(aliases) with_statements = with_values.flat_map do |with_value| case with_value when String Arel::Nodes::SqlLiteral.new(with_value) when Hash build_arel_from_hash(with_value) when Arel::Nodes::As with_value when Array build_arel_from_array(with_value) else raise ArgumentError, "Unsupported argument type: #{with_value} #{with_value.class}" end end unless with_statements.empty? if recursive_value arel.with :recursive, with_statements else arel.with with_statements end end arel end |