module Liquidize::Helper
Public Class Methods
activerecord?(object)
click to toggle source
Checks if the object is an ActiveRecord class or instance @param object [Object] any object @return [Boolean] whether it is AR class or instance
# 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)
click to toggle source
Decodes dump into the Ruby object @param dump [String] encoded dump @return [Object] decoded object @todo Find better alternative to Marshal.load rubocop:disable Security/MarshalLoad
# File lib/liquidize/helper.rb, line 28 def self.decode(dump) Marshal.load(Base64.strict_decode64(dump)) end
encode(value)
click to toggle source
Encodes Ruby object into marshalled dump @param value [Object] Ruby object @return [String] encoded dump
# File lib/liquidize/helper.rb, line 19 def self.encode(value) Base64.strict_encode64(Marshal.dump(value)) end
present?(value)
click to toggle source
Analogue of the ActiveSupport present? method @param value [Object] value that should be checked @return [Boolean] whether value is present
# File lib/liquidize/helper.rb, line 36 def self.present?(value) !value.to_s.strip.empty? end
recursive_stringify_keys(options)
click to toggle source
Converts all keys to strings @params options [Hash] hash which keys should be stringified @return [Hash] the same hash with stringified keys
# File lib/liquidize/helper.rb, line 6 def self.recursive_stringify_keys(options) if options.is_a?(Hash) options.stringify_keys! options.each_value { |v| recursive_stringify_keys(v) } elsif options.is_a?(Array) options.map! { |a| recursive_stringify_keys(a) } end options end