Sha256: f59e5544ffbf4b0587a1a97374cfafd958e350ac3710d5cc10ab5a90ca9a7e7b

Contents?: true

Size: 802 Bytes

Versions: 4

Compression:

Stored size: 802 Bytes

Contents

module GoldenFleece
  module Utility
    FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set

    def build_json_path(parent_path, key_name)
      "#{parent_path}#{'/' unless parent_path =~ /\/$/}#{key_name}"
    end

    def error_suffix(attribute, path)
      "'#{path}' on column '#{attribute}'"
    end

    # Copied from ActiveModel::Type::Boolean
    # https://github.com/rails/rails/blob/master/activemodel/lib/active_model/type/boolean.rb
    def cast_boolean(value)
      if value == ""
        nil
      else
        !FALSE_VALUES.include?(value)
      end
    end

    def deep_stringify_keys(hash)
      hash.reduce({}) { |memo, (key, value)|
        memo[key.to_s] = value.is_a?(Hash) ? deep_stringify_keys(value) : value
        memo
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
golden_fleece-0.1.3 lib/golden_fleece/utility.rb
golden_fleece-0.1.2 lib/golden_fleece/utility.rb
golden_fleece-0.1.1 lib/golden_fleece/utility.rb
golden_fleece-0.1.0 lib/golden_fleece/utility.rb