arel_extensions 1.2.14 → 1.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/arel_extensions/nodes/json.rb +40 -25
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/to_sql.rb +25 -17
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 02ad8f52ee6bfa8b08e534df4aeae8298ee4a6153461940cf7d94f46b6d45209
         | 
| 4 | 
            +
              data.tar.gz: 802365368c4b00f04a7fa553272cdd72de06b7eedd02263df8385a68d85554ac
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bf6eef122b124e6720323ed44fa0e77e2d253c90b80dacd163ba56bbc11390f124b88cb42f57efb36745d6679c1709cb5ed1d7f38109d42502c6d50bfd321912
         | 
| 7 | 
            +
              data.tar.gz: bac8c5ad02b5d8ea867c27be0593ddc61f1631c34a4c3dfc6dd63949aff91a8163a90dcd25a0f12faec12115c3a980cdb2a39edcc8e4adb5408720b5ed9445d8
         | 
| @@ -33,36 +33,51 @@ module ArelExtensions | |
| 33 33 | 
             
                  def initialize *expr
         | 
| 34 34 | 
             
                    @dict =
         | 
| 35 35 | 
             
                      if expr.length == 1
         | 
| 36 | 
            -
                         | 
| 37 | 
            -
                        when JsonNode
         | 
| 38 | 
            -
                          exp.dict
         | 
| 39 | 
            -
                        when Array
         | 
| 40 | 
            -
                          exp.map{|e|
         | 
| 41 | 
            -
                            (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e)
         | 
| 42 | 
            -
                          }
         | 
| 43 | 
            -
                        when Hash
         | 
| 44 | 
            -
                          exp.reduce({}){|acc,v|
         | 
| 45 | 
            -
                            acc[convert_to_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_node(v[1])
         | 
| 46 | 
            -
                            acc
         | 
| 47 | 
            -
                          }
         | 
| 48 | 
            -
                        when String, Numeric, TrueClass, FalseClass
         | 
| 49 | 
            -
                          convert_to_node(exp)
         | 
| 50 | 
            -
                        when NilClass
         | 
| 51 | 
            -
                          Arel.sql('null')
         | 
| 52 | 
            -
                        else
         | 
| 53 | 
            -
                          if (exp.is_a?(Arel::Attributes::Attribute) && type_of_attribute(exp) == :string) \
         | 
| 54 | 
            -
                             || (exp.return_type == :string)
         | 
| 55 | 
            -
                            convert_to_node(exp)
         | 
| 56 | 
            -
                          else
         | 
| 57 | 
            -
                            [convert_to_node(exp)]
         | 
| 58 | 
            -
                          end
         | 
| 59 | 
            -
                        end
         | 
| 36 | 
            +
                        convert_to_json_node(expr.first)
         | 
| 60 37 | 
             
                      else
         | 
| 61 | 
            -
                        expr.map{|e| (e | 
| 38 | 
            +
                        expr.map{|e| convert_to_json_node(e) }
         | 
| 62 39 | 
             
                      end
         | 
| 63 40 | 
             
                    super
         | 
| 64 41 | 
             
                  end
         | 
| 65 42 |  | 
| 43 | 
            +
                  def convert_to_json_node(n)
         | 
| 44 | 
            +
                    case n
         | 
| 45 | 
            +
                    when JsonNode
         | 
| 46 | 
            +
                      n.dict
         | 
| 47 | 
            +
                    when Array
         | 
| 48 | 
            +
                      n.map{|e|
         | 
| 49 | 
            +
                         (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
         | 
| 50 | 
            +
                      }
         | 
| 51 | 
            +
                    when Hash
         | 
| 52 | 
            +
                      n.reduce({}){|acc,v|
         | 
| 53 | 
            +
                        acc[convert_to_json_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_json_node(v[1])
         | 
| 54 | 
            +
                        acc
         | 
| 55 | 
            +
                      }
         | 
| 56 | 
            +
                    when String, Numeric, TrueClass, FalseClass
         | 
| 57 | 
            +
                      convert_to_node(n)
         | 
| 58 | 
            +
                    when Date
         | 
| 59 | 
            +
                      convert_to_node(n.strftime("%Y-%m-%d"))
         | 
| 60 | 
            +
                    when DateTime, Time
         | 
| 61 | 
            +
                      convert_to_node(n.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
         | 
| 62 | 
            +
                    when NilClass
         | 
| 63 | 
            +
                      Arel.sql('null')
         | 
| 64 | 
            +
                    else
         | 
| 65 | 
            +
                      convert_to_node(n)
         | 
| 66 | 
            +
                    end
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  def type_of_node(v)
         | 
| 70 | 
            +
                    if v.is_a?(Arel::Attributes::Attribute)
         | 
| 71 | 
            +
                      self.type_of_attribute(v)
         | 
| 72 | 
            +
                    elsif v.respond_to?(:return_type)
         | 
| 73 | 
            +
                      v.return_type
         | 
| 74 | 
            +
                    elsif v.nil?
         | 
| 75 | 
            +
                      :nil
         | 
| 76 | 
            +
                    else
         | 
| 77 | 
            +
                      :string
         | 
| 78 | 
            +
                    end
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
             | 
| 66 81 | 
             
                end
         | 
| 67 82 |  | 
| 68 83 | 
             
                class JsonMerge < JsonNode
         | 
| @@ -585,6 +585,26 @@ module ArelExtensions | |
| 585 585 | 
             
                    collector
         | 
| 586 586 | 
             
                  end
         | 
| 587 587 |  | 
| 588 | 
            +
                  def json_value(o,v)
         | 
| 589 | 
            +
                    case o.type_of_node(v)
         | 
| 590 | 
            +
                    when :string
         | 
| 591 | 
            +
                      Arel.when(v.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + v.replace('\\','\\\\').replace('"','\"') + '"')
         | 
| 592 | 
            +
                    when :date
         | 
| 593 | 
            +
                      s = v.format('%Y-%m-%d')
         | 
| 594 | 
            +
                      Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
         | 
| 595 | 
            +
                    when :datetime
         | 
| 596 | 
            +
                      s = v.format('%Y-%m-%dT%H:%M:%S')
         | 
| 597 | 
            +
                      Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
         | 
| 598 | 
            +
                    when :time
         | 
| 599 | 
            +
                      s = v.format('%H:%M:%S')
         | 
| 600 | 
            +
                      Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
         | 
| 601 | 
            +
                    when :nil
         | 
| 602 | 
            +
                      Arel::Nodes.build_quoted("null")
         | 
| 603 | 
            +
                    else
         | 
| 604 | 
            +
                      ArelExtensions::Nodes::Cast.new([v, :string]).coalesce("null")
         | 
| 605 | 
            +
                    end
         | 
| 606 | 
            +
                  end
         | 
| 607 | 
            +
             | 
| 588 608 | 
             
                  def visit_ArelExtensions_Nodes_Json o,collector
         | 
| 589 609 | 
             
                    case o.dict
         | 
| 590 610 | 
             
                    when Array
         | 
| @@ -593,11 +613,7 @@ module ArelExtensions | |
| 593 613 | 
             
                        if i != 0
         | 
| 594 614 | 
             
                          res += ', '
         | 
| 595 615 | 
             
                        end
         | 
| 596 | 
            -
                         | 
| 597 | 
            -
                          res = res + '"' + v + '"'
         | 
| 598 | 
            -
                        else
         | 
| 599 | 
            -
                          res += v
         | 
| 600 | 
            -
                        end
         | 
| 616 | 
            +
                        res += json_value(o,v)
         | 
| 601 617 | 
             
                      end
         | 
| 602 618 | 
             
                      res += ']'
         | 
| 603 619 | 
             
                      collector = visit res, collector
         | 
| @@ -607,12 +623,8 @@ module ArelExtensions | |
| 607 623 | 
             
                        if i != 0
         | 
| 608 624 | 
             
                          res += ', '
         | 
| 609 625 | 
             
                        end
         | 
| 610 | 
            -
                        res += Arel::Nodes.build_quoted('"')+k + '": '
         | 
| 611 | 
            -
                         | 
| 612 | 
            -
                          res = res + '"' + v + '"'
         | 
| 613 | 
            -
                        else
         | 
| 614 | 
            -
                          res += v
         | 
| 615 | 
            -
                        end
         | 
| 626 | 
            +
                        res += Arel::Nodes.build_quoted('"') + ArelExtensions::Nodes::Cast.new([k, :string]).coalesce("").replace('\\','\\\\').replace('"','\"') + '": '
         | 
| 627 | 
            +
                        res += json_value(o,v)
         | 
| 616 628 | 
             
                      end
         | 
| 617 629 | 
             
                      res += '}'
         | 
| 618 630 | 
             
                      collector = visit res, collector
         | 
| @@ -633,12 +645,8 @@ module ArelExtensions | |
| 633 645 | 
             
                        if i != 0
         | 
| 634 646 | 
             
                          res = res + ', '
         | 
| 635 647 | 
             
                        end
         | 
| 636 | 
            -
                        kv = Arel::Nodes.build_quoted('"')+k + '": '
         | 
| 637 | 
            -
                         | 
| 638 | 
            -
                          kv = kv + '"' + v + '"'
         | 
| 639 | 
            -
                        else
         | 
| 640 | 
            -
                          kv += v
         | 
| 641 | 
            -
                        end
         | 
| 648 | 
            +
                        kv = Arel::Nodes.build_quoted('"') + ArelExtensions::Nodes::Cast.new([k, :string]).coalesce("").replace('\\','\\\\').replace('"','\"') + '": '
         | 
| 649 | 
            +
                        kv += json_value(o,v)
         | 
| 642 650 | 
             
                        res = res + kv.group_concat(', ', order: Array(orders)).coalesce('')
         | 
| 643 651 | 
             
                      end
         | 
| 644 652 | 
             
                      res = res + '}'
         | 
    
        data/version_v1.rb
    CHANGED
    
    
    
        data/version_v2.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: arel_extensions
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.2. | 
| 4 | 
            +
              version: 1.2.15
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yann Azoury
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2020- | 
| 13 | 
            +
            date: 2020-09-17 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: arel
         |