Class: NestedAttributeReassignable::Helper
- Inherits:
-
Object
- Object
- NestedAttributeReassignable::Helper
- Defined in:
- lib/nested_attribute_reassignable.rb
Class Method Summary collapse
- .has_delete_flag?(hash) ⇒ Boolean
- .has_destroy_flag?(hash) ⇒ Boolean
- .symbolize_keys!(attributes) ⇒ Object
- .truthy?(hash, key) ⇒ Boolean
Class Method Details
.has_delete_flag?(hash) ⇒ Boolean
21 22 23 |
# File 'lib/nested_attribute_reassignable.rb', line 21 def self.has_delete_flag?(hash) truthy?(hash, :_delete) end |
.has_destroy_flag?(hash) ⇒ Boolean
25 26 27 |
# File 'lib/nested_attribute_reassignable.rb', line 25 def self.has_destroy_flag?(hash) truthy?(hash, :_destroy) end |
.symbolize_keys!(attributes) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/nested_attribute_reassignable.rb', line 38 def self.symbolize_keys!(attributes) if attributes.is_a?(Array) return unless attributes[0].respond_to?(:symbolize_keys!) attributes.each { |a| a.symbolize_keys! } else return unless attributes.respond_to?(:symbolize_keys!) attributes.symbolize_keys! end end |
.truthy?(hash, key) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/nested_attribute_reassignable.rb', line 29 def self.truthy?(hash, key) if defined?(Rails) && Rails::VERSION::MAJOR == 5 ActiveRecord::Type::Boolean.new.cast(hash[key]) else value = hash[key] [true, 1, '1', 'true'].include?(value) end end |