Module: Liquidize::Helper
- Defined in:
- lib/liquidize/helper.rb
Class Method Summary collapse
-
.activerecord?(object) ⇒ Boolean
Checks if the object is an ActiveRecord class or instance.
-
.decode(dump) ⇒ Object
Decodes dump into the Ruby object rubocop:disable Security/MarshalLoad.
-
.encode(value) ⇒ String
Encodes Ruby object into marshalled dump.
-
.present?(value) ⇒ Boolean
Analogue of the ActiveSupport #present? method.
-
.recursive_stringify_keys(options) ⇒ Hash
Converts all keys to strings.
Class Method Details
.activerecord?(object) ⇒ Boolean
Checks if the object is an ActiveRecord class or instance
43 44 45 46 47 48 49 50 |
# File 'lib/liquidize/helper.rb', line 43 def self.activerecord?(object) return false unless defined?(ActiveRecord) if object.is_a?(Class) object.ancestors.include?(ActiveRecord::Base) else object.class.ancestors.include?(ActiveRecord::Base) end end |
.decode(dump) ⇒ Object
TODO:
Find better alternative to Marshal.load
Decodes dump into the Ruby object rubocop:disable Security/MarshalLoad
28 29 30 |
# File 'lib/liquidize/helper.rb', line 28 def self.decode(dump) Marshal.load(Base64.strict_decode64(dump)) end |
.encode(value) ⇒ String
Encodes Ruby object into marshalled dump
19 20 21 |
# File 'lib/liquidize/helper.rb', line 19 def self.encode(value) Base64.strict_encode64(Marshal.dump(value)) end |
.present?(value) ⇒ Boolean
Analogue of the ActiveSupport #present? method
36 37 38 |
# File 'lib/liquidize/helper.rb', line 36 def self.present?(value) !value.to_s.strip.empty? end |
.recursive_stringify_keys(options) ⇒ Hash
Converts all keys to strings
6 7 8 9 10 11 12 13 14 |
# File 'lib/liquidize/helper.rb', line 6 def self.recursive_stringify_keys() if .is_a?(Hash) .stringify_keys! .each_value { |v| recursive_stringify_keys(v) } elsif .is_a?(Array) .map! { |a| recursive_stringify_keys(a) } end end |