Module: GoldenFleece::Utility
- Included in:
- Model::Normalization, Schema, ValidatorContext, Value
- Defined in:
- lib/golden_fleece/utility.rb
Constant Summary collapse
- FALSE_VALUES =
[false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
Instance Method Summary collapse
- #build_json_path(parent_path, key_name) ⇒ Object
-
#cast_boolean(value) ⇒ Object
Copied from ActiveModel::Type::Boolean github.com/rails/rails/blob/master/activemodel/lib/active_model/type/boolean.rb.
- #deep_stringify_keys(hash) ⇒ Object
- #error_suffix(attribute, path) ⇒ Object
Instance Method Details
#build_json_path(parent_path, key_name) ⇒ Object
5 6 7 |
# File 'lib/golden_fleece/utility.rb', line 5 def build_json_path(parent_path, key_name) "#{parent_path}#{'/' unless parent_path =~ /\/$/}#{key_name}" end |
#cast_boolean(value) ⇒ Object
Copied from ActiveModel::Type::Boolean github.com/rails/rails/blob/master/activemodel/lib/active_model/type/boolean.rb
15 16 17 18 19 20 21 |
# File 'lib/golden_fleece/utility.rb', line 15 def cast_boolean(value) if value == "" || value == nil nil else !FALSE_VALUES.include?(value) end end |
#deep_stringify_keys(hash) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/golden_fleece/utility.rb', line 23 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 |
#error_suffix(attribute, path) ⇒ Object
9 10 11 |
# File 'lib/golden_fleece/utility.rb', line 9 def error_suffix(attribute, path) "'#{path}' on column '#{attribute}'" end |