module SmoothOperator::Serialization

Public Instance Methods

attributes() click to toggle source
# File lib/smooth_operator/serialization.rb, line 9
def attributes; to_hash; end
read_attribute_for_serialization(attribute) click to toggle source
# File lib/smooth_operator/serialization.rb, line 17
def read_attribute_for_serialization(attribute)
  send(attribute)
end
serializable_hash(options = nil) click to toggle source
# File lib/smooth_operator/serialization.rb, line 21
def serializable_hash(options = nil)
  hash = {}
  options ||= {}
  method_names = HelperMethods.method_names(self, options)
  attribute_names = HelperMethods.attribute_names(self, options)

  attribute_names.each do |attribute_name|
    attribute_name, attribute_value = HelperMethods
      .serialize_normal_or_rails_way(self, attribute_name, options)

    hash[attribute_name] = attribute_value
  end

  method_names.each do |method_name|
    hash[method_name.to_s] = HelperMethods.serialize_normal_attribute(send(method_name), method_name, options[method_name])
  end

  hash
end
to_hash(options = nil) click to toggle source
# File lib/smooth_operator/serialization.rb, line 5
def to_hash(options = nil)
  Helpers.symbolyze_keys(serializable_hash(options) || {})
end
to_json(options = nil) click to toggle source
# File lib/smooth_operator/serialization.rb, line 11
def to_json(options = nil)
  require 'json' unless defined? JSON

  JSON(serializable_hash(options) || {})
end