forest_admin_agent 1.12.6 → 1.12.8
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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 01f7a58ed14f73ef6090b03b00158a166e57ae8aaffb61049a58dde26c5e52e6
         | 
| 4 | 
            +
              data.tar.gz: 2508a64a6b3842f83aae7a529c1915a19d75f9487e4553b19991a91834f90479
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 928a5f2524d32f014f226f402789cf2d81758685b71f9eabcf9008d494af5d0cbdeb066b953da697fb61df0572a800cf5e05ac658b92c31f7ab79895b40a30a9
         | 
| 7 | 
            +
              data.tar.gz: 6fdf6f47c29362972f113047f2786b81ef0cca82a4a8dd7372d8e8f327811ca4a45f1005b79011b2e0a72c98c2b8b4093ec432be5aa3c79eb033f86f0627b891
         | 
| @@ -12,7 +12,7 @@ module ForestAdminAgent | |
| 12 12 | 
             
                  def self.from_plain_object(collection, filters)
         | 
| 13 13 | 
             
                    if leaf?(filters)
         | 
| 14 14 | 
             
                      operator = filters[:operator].titleize.tr(' ', '_').downcase
         | 
| 15 | 
            -
                      value = parse_value(collection, filters)
         | 
| 15 | 
            +
                      value = parse_value(collection, filters.merge(operator: operator))
         | 
| 16 16 |  | 
| 17 17 | 
             
                      return ConditionTreeLeaf.new(filters[:field], operator, value)
         | 
| 18 18 | 
             
                    end
         | 
| @@ -31,18 +31,52 @@ module ForestAdminAgent | |
| 31 31 |  | 
| 32 32 | 
             
                  def self.parse_value(collection, leaf)
         | 
| 33 33 | 
             
                    schema = Collection.get_field_schema(collection, leaf[:field])
         | 
| 34 | 
            +
                    expected_type = get_expected_type_for_condition(leaf, schema)
         | 
| 34 35 |  | 
| 35 | 
            -
                     | 
| 36 | 
            -
             | 
| 36 | 
            +
                    cast_to_type(leaf[:value], expected_type)
         | 
| 37 | 
            +
                  end
         | 
| 37 38 |  | 
| 38 | 
            -
             | 
| 39 | 
            +
                  def self.get_expected_type_for_condition(leaf, schema)
         | 
| 40 | 
            +
                    operators_expecting_number = [
         | 
| 41 | 
            +
                      Operators::SHORTER_THAN,
         | 
| 42 | 
            +
                      Operators::LONGER_THAN,
         | 
| 43 | 
            +
                      Operators::AFTER_X_HOURS_AGO,
         | 
| 44 | 
            +
                      Operators::BEFORE_X_HOURS_AGO,
         | 
| 45 | 
            +
                      Operators::PREVIOUS_X_DAYS,
         | 
| 46 | 
            +
                      Operators::PREVIOUS_X_DAYS_TO_DATE
         | 
| 47 | 
            +
                    ]
         | 
| 39 48 |  | 
| 40 | 
            -
             | 
| 49 | 
            +
                    return 'Number' if operators_expecting_number.include?(leaf[:operator])
         | 
| 41 50 |  | 
| 42 | 
            -
             | 
| 51 | 
            +
                    if [Operators::IN, Operators::NOT_IN, Operators::INCLUDES_ALL].include?(leaf[:operator])
         | 
| 52 | 
            +
                      return [schema.column_type]
         | 
| 43 53 | 
             
                    end
         | 
| 44 54 |  | 
| 45 | 
            -
                     | 
| 55 | 
            +
                    schema.column_type
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def self.cast_to_type(value, expected_type)
         | 
| 59 | 
            +
                    return value if value.nil?
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    if expected_type.is_a?(Array)
         | 
| 62 | 
            +
                      items = value.is_a?(String) ? value.split(',').map(&:strip) : value
         | 
| 63 | 
            +
                      filter_fn = expected_type[0] == 'Number' ? ->(item) { item.is_a?(Numeric) } : ->(_) { true }
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      return value unless items.is_a?(Array)
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                      return items.map { |item| cast_to_type(item, expected_type[0]) }.select(&filter_fn)
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    case expected_type
         | 
| 71 | 
            +
                    when 'String', 'Dateonly', 'Date'
         | 
| 72 | 
            +
                      value.to_s
         | 
| 73 | 
            +
                    when 'Number'
         | 
| 74 | 
            +
                      value.to_f
         | 
| 75 | 
            +
                    when 'Boolean'
         | 
| 76 | 
            +
                      !%w[false 0 no].include?(value.to_s)
         | 
| 77 | 
            +
                    else
         | 
| 78 | 
            +
                      value
         | 
| 79 | 
            +
                    end
         | 
| 46 80 | 
             
                  end
         | 
| 47 81 |  | 
| 48 82 | 
             
                  def self.leaf?(filters)
         |